Files
obsidian-livesync/src/features/ConfigSync/PluginTerms.unit.spec.ts
T
Immick f1746fa4b8 fix(customisation-sync): hide identical items with "Hide not applicable items"
The checkbox only toggled a CSS class for rows labelled "All the same or
non-existent", while `hideNotApplicable`, which filters the offered
devices by whether their copy can be applied, was hard-coded to false.
Items present on another device therefore stayed visible even when every
copy was the same.

Drive `hideNotApplicable` from the checkbox, so the comparison only runs
while it is on, and pass it to the reactive update so toggling it
re-evaluates the rows. The term selection moves into PluginTerms.ts so it
can be unit-tested.

Fixes #1193
2026-09-15 22:03:51 +03:00

55 lines
2.0 KiB
TypeScript

import { describe, expect, it, vi } from "vitest";
import type { IPluginDataExDisplay } from "./CmdConfigSync.ts";
import { selectSourceTerms } from "./PluginTerms.ts";
const copyOn = (term: string) => ({ term, files: [] }) as unknown as IPluginDataExDisplay;
const list = [copyOn("desktop"), copyOn("phone"), copyOn("tablet")];
const differsOn =
(...terms: string[]) =>
(_local: IPluginDataExDisplay | undefined, remote: IPluginDataExDisplay | undefined) =>
Promise.resolve(terms.includes(remote?.term ?? ""));
describe("selectSourceTerms", () => {
it("offers every other device without comparing copies by default", async () => {
const canApplyFrom = vi.fn(differsOn());
const terms = await selectSourceTerms(
list,
"desktop",
{ isMaintenanceMode: false, hideNotApplicable: false },
canApplyFrom
);
expect(terms).toEqual(["phone", "tablet"]);
expect(canApplyFrom).not.toHaveBeenCalled();
});
it("offers every device, including this one, in maintenance mode", async () => {
const terms = await selectSourceTerms(
list,
"desktop",
{ isMaintenanceMode: true, hideNotApplicable: true },
differsOn()
);
expect(terms).toEqual(["desktop", "phone", "tablet"]);
});
it("leaves out devices whose copy is the same when hiding items that are not applicable", async () => {
const terms = await selectSourceTerms(
list,
"desktop",
{ isMaintenanceMode: false, hideNotApplicable: true },
differsOn("tablet")
);
expect(terms).toEqual(["tablet"]);
});
it("offers no source for an item that is the same on every device", async () => {
const terms = await selectSourceTerms(
list,
"desktop",
{ isMaintenanceMode: false, hideNotApplicable: true },
differsOn()
);
expect(terms).toEqual([]);
});
});