// @vitest-environment happy-dom import { readFile } from "node:fs/promises"; import { resolve } from "node:path"; import { pathToFileURL } from "node:url"; import type { Workspace } from "@yaakapp-internal/models"; import type { TemplateFunction } from "@yaakapp-internal/plugins"; import type { Tokens } from "@yaakapp-internal/templates"; import { act, type ReactNode } from "react"; import { createRoot, type Root } from "react-dom/client"; import { afterEach, beforeAll, beforeEach, expect, test, vi } from "vite-plus/test"; import { TemplateFunctionDialog } from "./TemplateFunctionDialog"; interface FormProps { data: Record; onChange: (values: Record) => void; } const mocks = vi.hoisted(() => ({ parse: vi.fn<(text: string) => Tokens>(), print: vi.fn<(tokens: Tokens) => Promise>(), serialize: vi.fn<(tokens: Tokens) => { data: string }>(), preview: vi.fn<({ template }: { template: string }) => { data: string }>(), form: null as FormProps | null, config: { name: "timestamp.format", args: [ { type: "text", name: "date" }, { type: "text", name: "format" }, ], } as TemplateFunction, })); vi.mock("@yaakapp-internal/templates", () => ({ parseTemplate: mocks.parse })); vi.mock("@yaakapp-internal/ui", () => ({ HStack: ({ children }: { children: ReactNode }) =>
{children}
, InlineCode: "code", LoadingIcon: () => null, useDebouncedValue: (value: string) => value, })); vi.mock("../hooks/useActiveWorkspace", () => ({ activeWorkspaceAtom: null })); vi.mock("../hooks/useRenderTemplate", () => ({ useRenderTemplate: mocks.preview })); vi.mock("../hooks/useTemplateFunctionConfig", () => ({ useTemplateFunctionConfig: () => ({ data: mocks.config }), })); vi.mock("../hooks/useTemplateTokensToString", () => ({ templateTokensToString: mocks.print, useTemplateTokensToString: mocks.serialize, })); vi.mock("../lib/dialog", () => ({ showDialog: vi.fn() })); vi.mock("../lib/encryption", () => ({ convertTemplateToInsecure: vi.fn() })); vi.mock("../lib/jotai", () => ({ jotaiStore: { get: vi.fn() } })); vi.mock("../lib/setupOrConfigureEncryption", () => ({ setupOrConfigureEncryption: vi.fn() })); vi.mock("./core/Dialog", () => ({ DialogFooter: () => })); vi.mock("./core/IconButton", () => ({ IconButton: () =>