- Implemented useGridState to manage grid state, including asset selection and loading states. - Created useVirtualGrid to centralize virtualization helpers for improved performance. - Added createVueApp for isolated Vue 3 + Pinia application instances. - Introduced Vite configuration for building the ComfyUI-Majoor-AssetsManager with external dependencies.
93 lines
2.8 KiB
JavaScript
93 lines
2.8 KiB
JavaScript
import { describe, expect, it, vi } from "vitest";
|
|
import { createPinia, setActivePinia } from "pinia";
|
|
|
|
import { createBrowserNavigationController } from "../features/panel/controllers/browserNavigationController.js";
|
|
import { usePanelStore } from "../stores/usePanelStore.js";
|
|
|
|
vi.mock("../app/i18n.js", () => ({
|
|
t: (_key, fallback) => fallback || "",
|
|
}));
|
|
|
|
function createNode() {
|
|
const listeners = new Map();
|
|
return {
|
|
style: { display: "" },
|
|
dataset: {},
|
|
disabled: false,
|
|
children: [],
|
|
className: "",
|
|
textContent: "",
|
|
value: "",
|
|
selectedOptions: [],
|
|
addEventListener(type, handler) {
|
|
const list = listeners.get(type) || [];
|
|
list.push(handler);
|
|
listeners.set(type, list);
|
|
},
|
|
removeEventListener(type, handler) {
|
|
const list = listeners.get(type) || [];
|
|
listeners.set(
|
|
type,
|
|
list.filter((item) => item !== handler),
|
|
);
|
|
},
|
|
dispatchEvent(event) {
|
|
for (const handler of listeners.get(event.type) || []) {
|
|
handler(event);
|
|
}
|
|
},
|
|
appendChild(child) {
|
|
this.children.push(child);
|
|
return child;
|
|
},
|
|
replaceChildren(...nodes) {
|
|
this.children = nodes;
|
|
},
|
|
};
|
|
}
|
|
|
|
describe("browserNavigationController", () => {
|
|
it("syncs navigated folder path into Pinia", async () => {
|
|
globalThis.window = { addEventListener: vi.fn(), removeEventListener: vi.fn() };
|
|
globalThis.document = {
|
|
createElement: () => createNode(),
|
|
};
|
|
setActivePinia(createPinia());
|
|
const panelStore = usePanelStore();
|
|
|
|
const gridContainer = createNode();
|
|
const folderBreadcrumb = createNode();
|
|
const customSelect = createNode();
|
|
const reloadGrid = vi.fn(async () => ({}));
|
|
const onContextChanged = vi.fn();
|
|
|
|
const state = {
|
|
scope: "output",
|
|
customRootId: "",
|
|
currentFolderRelativePath: "",
|
|
};
|
|
|
|
const controller = createBrowserNavigationController({
|
|
state,
|
|
gridContainer,
|
|
folderBreadcrumb,
|
|
customSelect,
|
|
reloadGrid,
|
|
onContextChanged,
|
|
});
|
|
|
|
const unbind = controller.bindGridFolderNavigation();
|
|
gridContainer.dispatchEvent({
|
|
type: "mjr:open-folder-asset",
|
|
detail: { asset: { kind: "folder", filepath: "animals/cats" } },
|
|
});
|
|
|
|
expect(panelStore.currentFolderRelativePath).toBe("animals/cats");
|
|
expect(gridContainer.dataset.mjrSubfolder).toBe("animals/cats");
|
|
expect(reloadGrid).toHaveBeenCalledTimes(1);
|
|
expect(onContextChanged).toHaveBeenCalledTimes(1);
|
|
|
|
unbind();
|
|
});
|
|
});
|