import { afterEach, describe, expect, it, vi, beforeAll, afterAll } from "vitest"; import { mount, flushPromises } from "@vue/test-utils"; import DefaultLayout from "~/layouts/Default.vue"; vi.mock("~/stores/auth", () => ({ useAuthStore: () => ({ init: vi.fn(), user: null, }), })); describe("Default.vue", () => { 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(); }); afterEach(() => { vi.useRealTimers(); }); it("loads without crashing", async () => { const wrapper = mount({ components: { DefaultLayout }, template: "", }); await flushPromises(); // Wait for async setup expect(wrapper.exists()).toBe(true); }); describe("Footer", () => { it("footer is displayed", async () => { const wrapper = mount({ components: { DefaultLayout }, template: "", }); await flushPromises(); const footer = wrapper.find("[data-testid='footer']"); expect(footer.exists()).toBe(true); }); it("footer shows only 2025 when current year is 2025", async () => { vi.useFakeTimers(); vi.setSystemTime(new Date(2025, 0, 1)); const wrapper = mount({ components: { DefaultLayout }, template: "", }); await flushPromises(); const footer = wrapper.find("[data-testid='footer']"); expect(footer.text()).toBe("Glowing Fiesta 2025"); }); it("footer shows range when current year is not 2025", async () => { vi.useFakeTimers(); vi.setSystemTime(new Date(2069, 0, 1)); const wrapper = mount({ components: { DefaultLayout }, template: "", }); await flushPromises(); const footer = wrapper.find("[data-testid='footer']"); expect(footer.text()).toBe("Glowing Fiesta 2025 - 2069"); }); }); });