Files
MajoorWaldi-ComfyUI-Majoor-…/ui/tests/scope_controller.vitest.ts
T
Ewald 85a82f130a test: migrate ui/tests from .mjs to .ts
- Rename 132 *.vitest.mjs -> *.vitest.ts
- Rename vitest.setup.mjs -> vitest.setup.ts
- Rename helpers/vitestEnvironment.mjs -> vitestEnvironment.ts
- Delete settings_store.test.mjs (Node test runner, superseded by .vitest.ts)
- Fix .mjs imports in vitest.setup.ts and grid_loader_adaptive_paging.vitest.ts

Config updates:
- vitest.config.mjs: setupFiles, include, coverage.include -> .ts
- tsconfig.test.json: new dedicated config for test files (strict:false)
- knip.json: update project pattern for tests
- package.json: add typecheck:tests script (audit-only)
2026-05-26 13:04:05 +02:00

106 lines
3.9 KiB
TypeScript

import { describe, expect, it, vi } from "vitest";
import { createPinia, setActivePinia } from "pinia";
import { createScopeController } from "../features/panel/controllers/scopeController.js";
import { usePanelStore } from "../stores/usePanelStore.js";
function makeButton(scope) {
const classes = new Set();
return {
dataset: { scope },
style: { display: "" },
classList: {
toggle(name, active) {
if (active) classes.add(name);
else classes.delete(name);
},
has(name) {
return classes.has(name);
},
},
};
}
describe("scopeController similar scope", () => {
it("activates a temporary similar scope and clears it cleanly", async () => {
setActivePinia(createPinia());
const panelStore = usePanelStore();
panelStore.scope = "output";
panelStore.viewScope = "";
panelStore.similarResults = [{ asset_id: 7 }];
panelStore.similarTitle = "Similar to asset #42 (1 results)";
panelStore.similarSourceAssetId = "42";
panelStore.collectionId = "";
panelStore.collectionName = "";
panelStore.currentFolderRelativePath = "";
panelStore.customRootId = "";
const tabButtons = {
tabAll: makeButton("all"),
tabInputs: makeButton("input"),
tabOutputs: makeButton("output"),
tabCustom: makeButton("custom"),
tabSimilar: makeButton("similar"),
};
const state = {
scope: "output",
viewScope: "",
similarResults: [{ asset_id: 7 }],
similarTitle: "Similar to asset #42 (1 results)",
similarSourceAssetId: "42",
collectionId: "",
collectionName: "",
currentFolderRelativePath: "",
customRootId: "",
};
const reloadGrid = vi.fn(async () => {});
const reconcileSelection = vi.fn();
const onChanged = vi.fn();
const onScopeChanged = vi.fn();
const onBeforeReload = vi.fn();
const popovers = { close: vi.fn() };
const customMenuBtn = { style: { display: "" } };
const customPopover = { style: { display: "" } };
const controller = createScopeController({
state,
tabButtons,
customMenuBtn,
customPopover,
popovers,
reloadGrid,
reconcileSelection,
onChanged,
onScopeChanged,
onBeforeReload,
});
controller.setActiveTabStyles();
expect(tabButtons.tabSimilar.style.display).toBe("");
expect(tabButtons.tabOutputs.classList.has("is-active")).toBe(true);
await controller.setScope("similar");
expect(panelStore.viewScope).toBe("similar");
expect(tabButtons.tabSimilar.classList.has("is-active")).toBe(true);
expect(onScopeChanged).not.toHaveBeenCalled();
expect(onBeforeReload).toHaveBeenCalledTimes(1);
expect(reloadGrid).toHaveBeenCalledTimes(1);
await controller.clearSimilarScope({ reload: false });
expect(panelStore.viewScope).toBe("");
expect(panelStore.similarResults).toEqual([]);
expect(panelStore.similarTitle).toBe("");
expect(panelStore.similarSourceAssetId).toBe("");
expect(tabButtons.tabSimilar.style.display).toBe("none");
await controller.setScope("output");
expect(panelStore.scope).toBe("output");
expect(panelStore.collectionId).toBe("");
expect(panelStore.collectionName).toBe("");
expect(panelStore.currentFolderRelativePath).toBe("");
expect(panelStore.similarResults).toEqual([]);
expect(panelStore.similarTitle).toBe("");
expect(panelStore.similarSourceAssetId).toBe("");
expect(reconcileSelection).toHaveBeenCalledTimes(1);
});
});