import { mount, flushPromises } from "@vue/test-utils"; import { describe, expect, it, vi, beforeEach, beforeAll, afterAll } from "vitest"; import LogoutPage from "~/pages/auth/logout.vue"; // Mock the auth store const mocks = vi.hoisted(() => ({ init: vi.fn(), signOut: vi.fn(), })); vi.mock("~/stores/auth", () => ({ useAuthStore: () => ({ init: mocks.init, signOut: mocks.signOut, }), })); // Mock UI components vi.mock("@/components/ui/button", () => ({ Button: { template: "", }, })); vi.mock("@/components/ui/card", () => ({ Card: { template: "
" }, CardContent: { template: "
" }, CardDescription: { template: "
" }, CardHeader: { template: "
" }, CardTitle: { template: "
" }, })); vi.mock("@/components/ui/field", () => ({ Field: { template: "
" }, FieldDescription: { template: "
" }, })); describe("LogoutPage", () => { beforeAll(() => { const shouldSuppress = (args: string[]) => { const msg = args.join(" "); return msg.includes(" is an experimental feature"); }; const spyMethods = ["warn", "error", "log", "info"] as const; for (const method of spyMethods) { const original = console[method]; vi.spyOn(console, method).mockImplementation((...args) => { if (shouldSuppress(args)) return; original(...args); }); } }); afterAll(() => { vi.restoreAllMocks(); }); beforeEach(() => { vi.clearAllMocks(); }); it("renders correctly and calls init", async () => { const wrapper = mount({ components: { LogoutPage }, template: "", }); await flushPromises(); expect(mocks.init).toHaveBeenCalled(); expect(wrapper.text()).toContain("Logout"); expect(wrapper.text()).toContain("Are you sure you want to logout?"); expect(wrapper.text()).toContain("Home"); }); it("calls signOut on form submit", async () => { const wrapper = mount({ components: { LogoutPage }, template: "", }); await flushPromises(); const form = wrapper.find("form"); expect(form.exists()).toBe(true); await form.trigger("submit"); expect(mocks.signOut).toHaveBeenCalled(); }); });