import { flushPromises, mount, type VueWrapper } from "@vue/test-utils"; import { afterEach, beforeEach, describe, expect, test, vi } from "vitest"; import { ref, type Ref } from "vue"; import GroupAIPromptEditor from "./GroupAIPromptEditor.vue"; import type { AIPromptsOut } from "~/lib/api/types/group"; const wrappers: VueWrapper[] = []; const mocks = vi.hoisted(() => ({ prompts: null as unknown as Ref, refresh: vi.fn(), save: vi.fn(), reset: vi.fn(), })); vi.mock("~/composables/use-ai-providers", () => ({ useAIPrompts: () => ({ prompts: mocks.prompts, loading: ref(false), refresh: mocks.refresh, save: mocks.save, reset: mocks.reset, }), })); vi.mock("~/composables/use-toast", () => ({ alert: { success: vi.fn(), error: vi.fn() }, })); const PROMPT_NAME = "recipes.build-recipe"; const DEFAULT_CONTENT = "Mealie's built-in prompt"; function promptsOut(overrides: Partial = {}): AIPromptsOut { return { globalInstructions: null, prompts: [{ name: PROMPT_NAME, isSystem: false, defaultContent: DEFAULT_CONTENT, mode: null, content: null, defaultChanged: false, ...overrides, }], }; } async function mountEditor(initial: AIPromptsOut = promptsOut()) { mocks.prompts = ref(initial); const wrapper = mount(GroupAIPromptEditor, { global: { mocks: { $globals: { icons: { alert: "alert" } }, }, stubs: { AppLoader: { template: "
" }, BaseCardSectionTitle: { template: "
" }, BaseButton: { props: { disabled: Boolean, save: Boolean }, template: "