Files
MajoorWaldi-ComfyUI-Majoor-…/js/tests/dialogs.vitest.mjs
T
MajoorWaldi dc72be0139 feat: enhance JS testing and linting setup
- Added coverage reporting for Vitest with configuration in vitest.config.mjs
- Updated package.json to include new scripts for JS coverage, linting, and formatting
- Modified run_quality_gate.py to allow skipping ESLint and Prettier checks
- Introduced .prettierrc for consistent code formatting
- Created .prettierignore to exclude specific files and directories from formatting
2026-03-28 14:14:28 +01:00

52 lines
1.7 KiB
JavaScript

import { beforeEach, describe, expect, it, vi } from "vitest";
const getExtensionDialogApi = vi.fn(() => null);
const getComfyApp = vi.fn(() => null);
vi.mock("../app/comfyApiBridge.js", () => ({
getComfyApp,
getExtensionDialogApi,
}));
vi.mock("../app/i18n.js", () => ({
t: (_key, fallback) => fallback,
}));
beforeEach(() => {
vi.resetModules();
vi.clearAllMocks();
getExtensionDialogApi.mockReturnValue(null);
getComfyApp.mockReturnValue(null);
globalThis.window = {
confirm: vi.fn(() => true),
prompt: vi.fn(() => "fallback"),
alert: vi.fn(),
};
globalThis.document = {
createElement: vi.fn(() => ({ style: {}, appendChild: vi.fn(), setAttribute: vi.fn() })),
};
});
describe("dialogs", () => {
it("uses extension dialog confirm/prompt first", async () => {
getExtensionDialogApi.mockReturnValue({
confirm: vi.fn(async () => true),
prompt: vi.fn(async () => "native-value"),
});
const mod = await import("../app/dialogs.js");
await expect(mod.comfyConfirm("Delete?")).resolves.toBe(true);
await expect(mod.comfyPrompt("Name", "x")).resolves.toBe("native-value");
expect(window.confirm).not.toHaveBeenCalled();
expect(window.prompt).not.toHaveBeenCalled();
});
it("falls back to window dialogs when no native surface exists", async () => {
const mod = await import("../app/dialogs.js");
await expect(mod.comfyConfirm("Delete?")).resolves.toBe(true);
await expect(mod.comfyPrompt("Name", "x")).resolves.toBe("fallback");
expect(window.confirm).toHaveBeenCalled();
expect(window.prompt).toHaveBeenCalled();
});
});