Use setting control for remediation status

This commit is contained in:
vorotamoroz committed 2026-07-31 10:08:34 +00:00
1 parent 1570136703
commit 50a51bf07e
2 files changed
+11 -13

No files matched your search

@@ -176,8 +176,9 @@ export function panePatches(this: ObsidianLiveSyncSettingTab, paneEl: HTMLElemen
new Setting(paneEl).autoWireToggle("disableCheckingConfigMismatch"); new Setting(paneEl).autoWireToggle("disableCheckingConfigMismatch");
}); });
void addPanel(paneEl, "Remediation").then((paneEl) => { void addPanel(paneEl, "Remediation").then((paneEl) => {
let dateEl: HTMLSpanElement; const setting = new Setting(paneEl);
new Setting(paneEl) const dateEl = setting.controlEl.createSpan();
setting
.addText((text) => { .addText((text) => {
const updateDateText = () => { const updateDateText = () => {
if (this.editingSettings.maxMTimeForReflectEvents == 0) { if (this.editingSettings.maxMTimeForReflectEvents == 0) {
@@ -188,8 +189,6 @@ export function panePatches(this: ObsidianLiveSyncSettingTab, paneEl: HTMLElemen
} }
this.requestUpdate(); this.requestUpdate();
}; };
dateEl = text.inputEl.ownerDocument.createElement("span");
text.inputEl.before(dateEl);
text.inputEl.type = "datetime-local"; text.inputEl.type = "datetime-local";
if (this.editingSettings.maxMTimeForReflectEvents > 0) { if (this.editingSettings.maxMTimeForReflectEvents > 0) {
const date = new Date(this.editingSettings.maxMTimeForReflectEvents); const date = new Date(this.editingSettings.maxMTimeForReflectEvents);
@@ -3,11 +3,8 @@ import { panePatches } from "./PanePatches.ts";
const remediationHarness = vi.hoisted(() => { const remediationHarness = vi.hoisted(() => {
const dateElement = { textContent: "" }; const dateElement = { textContent: "" };
const createElement = vi.fn(() => dateElement); const createSpan = vi.fn(() => dateElement);
const before = vi.fn();
const inputEl = { const inputEl = {
before,
ownerDocument: { createElement },
type: "", type: "",
}; };
const textComponent = { const textComponent = {
@@ -17,8 +14,7 @@ const remediationHarness = vi.hoisted(() => {
}; };
return { return {
before, createSpan,
createElement,
dateElement, dateElement,
inputEl, inputEl,
textComponent, textComponent,
@@ -27,6 +23,10 @@ const remediationHarness = vi.hoisted(() => {
vi.mock("./LiveSyncSetting.ts", () => ({ vi.mock("./LiveSyncSetting.ts", () => ({
LiveSyncSetting: class LiveSyncSetting { LiveSyncSetting: class LiveSyncSetting {
controlEl = {
createSpan: remediationHarness.createSpan,
};
addText(callback: (text: typeof remediationHarness.textComponent) => void): this { addText(callback: (text: typeof remediationHarness.textComponent) => void): this {
callback(remediationHarness.textComponent); callback(remediationHarness.textComponent);
return this; return this;
@@ -54,7 +54,7 @@ afterEach(() => {
}); });
describe("panePatches remediation setting", () => { describe("panePatches remediation setting", () => {
it("creates the status element without appending it to the document", () => { it("creates the status element in the setting control instead of the document", () => {
const hierarchyError = new DOMException( const hierarchyError = new DOMException(
"Failed to execute 'appendChild' on 'Node': Only one element on document allowed.", "Failed to execute 'appendChild' on 'Node': Only one element on document allowed.",
"HierarchyRequestError" "HierarchyRequestError"
@@ -91,8 +91,7 @@ describe("panePatches remediation setting", () => {
} as never } as never
); );
expect(createSpan).not.toHaveBeenCalled(); expect(createSpan).not.toHaveBeenCalled();
expect(remediationHarness.createElement).toHaveBeenCalledWith("span"); expect(remediationHarness.createSpan).toHaveBeenCalledOnce();
expect(remediationHarness.before).toHaveBeenCalledWith(remediationHarness.dateElement);
expect(remediationHarness.dateElement.textContent).toBe("No limit configured"); expect(remediationHarness.dateElement.textContent).toBe("No limit configured");
}); });
}); });