From 50a51bf07eb85f19991581ec7c0942be82335d6c Mon Sep 17 00:00:00 2001 From: vorotamoroz Date: Fri, 31 Jul 2026 10:08:34 +0000 Subject: [PATCH] Use setting control for remediation status --- .../features/SettingDialogue/PanePatches.ts | 7 +++---- .../SettingDialogue/PanePatches.unit.spec.ts | 17 ++++++++--------- 2 files changed, 11 insertions(+), 13 deletions(-) diff --git a/src/modules/features/SettingDialogue/PanePatches.ts b/src/modules/features/SettingDialogue/PanePatches.ts index 4a2ed985..8f03e061 100644 --- a/src/modules/features/SettingDialogue/PanePatches.ts +++ b/src/modules/features/SettingDialogue/PanePatches.ts @@ -176,8 +176,9 @@ export function panePatches(this: ObsidianLiveSyncSettingTab, paneEl: HTMLElemen new Setting(paneEl).autoWireToggle("disableCheckingConfigMismatch"); }); void addPanel(paneEl, "Remediation").then((paneEl) => { - let dateEl: HTMLSpanElement; - new Setting(paneEl) + const setting = new Setting(paneEl); + const dateEl = setting.controlEl.createSpan(); + setting .addText((text) => { const updateDateText = () => { if (this.editingSettings.maxMTimeForReflectEvents == 0) { @@ -188,8 +189,6 @@ export function panePatches(this: ObsidianLiveSyncSettingTab, paneEl: HTMLElemen } this.requestUpdate(); }; - dateEl = text.inputEl.ownerDocument.createElement("span"); - text.inputEl.before(dateEl); text.inputEl.type = "datetime-local"; if (this.editingSettings.maxMTimeForReflectEvents > 0) { const date = new Date(this.editingSettings.maxMTimeForReflectEvents); diff --git a/src/modules/features/SettingDialogue/PanePatches.unit.spec.ts b/src/modules/features/SettingDialogue/PanePatches.unit.spec.ts index f489b054..60f29b84 100644 --- a/src/modules/features/SettingDialogue/PanePatches.unit.spec.ts +++ b/src/modules/features/SettingDialogue/PanePatches.unit.spec.ts @@ -3,11 +3,8 @@ import { panePatches } from "./PanePatches.ts"; const remediationHarness = vi.hoisted(() => { const dateElement = { textContent: "" }; - const createElement = vi.fn(() => dateElement); - const before = vi.fn(); + const createSpan = vi.fn(() => dateElement); const inputEl = { - before, - ownerDocument: { createElement }, type: "", }; const textComponent = { @@ -17,8 +14,7 @@ const remediationHarness = vi.hoisted(() => { }; return { - before, - createElement, + createSpan, dateElement, inputEl, textComponent, @@ -27,6 +23,10 @@ const remediationHarness = vi.hoisted(() => { vi.mock("./LiveSyncSetting.ts", () => ({ LiveSyncSetting: class LiveSyncSetting { + controlEl = { + createSpan: remediationHarness.createSpan, + }; + addText(callback: (text: typeof remediationHarness.textComponent) => void): this { callback(remediationHarness.textComponent); return this; @@ -54,7 +54,7 @@ afterEach(() => { }); 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( "Failed to execute 'appendChild' on 'Node': Only one element on document allowed.", "HierarchyRequestError" @@ -91,8 +91,7 @@ describe("panePatches remediation setting", () => { } as never ); expect(createSpan).not.toHaveBeenCalled(); - expect(remediationHarness.createElement).toHaveBeenCalledWith("span"); - expect(remediationHarness.before).toHaveBeenCalledWith(remediationHarness.dateElement); + expect(remediationHarness.createSpan).toHaveBeenCalledOnce(); expect(remediationHarness.dateElement.textContent).toBe("No limit configured"); }); });