GF-6, #8 Added auth.
Some checks failed
Production PR / QA Tests (pull_request) Failing after 13s

This commit is contained in:
Liviu Burcusel 2026-01-07 09:54:06 +01:00
parent e8818d6eaa
commit 10e4363cbd
Signed by: liviu
GPG key ID: 6CDB37A4AD2C610C
60 changed files with 4855 additions and 160 deletions

View file

@ -1,5 +1,5 @@
import { mount } from "@vue/test-utils";
import { describe, expect, it, vi } from "vitest";
import { mount, flushPromises } from "@vue/test-utils";
import { describe, expect, it, vi, beforeAll, afterAll } from "vitest";
import SidebarLayout from "~/layouts/default/Sidebar.vue";
import { ref } from "vue";
import type * as SidebarUI from "~/components/ui/sidebar";
@ -8,6 +8,20 @@ const { useSidebarMock } = vi.hoisted(() => ({
useSidebarMock: vi.fn(),
}));
// ... (existing mocks)
vi.mock("~/stores/auth", () => ({
useAuthStore: () => ({
user: {
name: "Liviu",
email: "x.liviu@gmail.com",
image: "avatar.png",
},
signOut: vi.fn(),
init: vi.fn(),
}),
}));
// Mock the UI components and hook
vi.mock("~/components/ui/sidebar", async (importOriginal) => {
const actual = await importOriginal<typeof SidebarUI>();
@ -99,6 +113,7 @@ vi.mock("lucide-vue-next", () => {
CreditCard: MockIcon,
BookOpen: MockIcon,
HandCoins: MockIcon,
LogIn: MockIcon,
LogOut: MockIcon,
Settings2: MockIcon,
Sparkles: MockIcon,
@ -107,7 +122,26 @@ vi.mock("lucide-vue-next", () => {
});
describe("SidebarLayout", () => {
it("renders the header correctly", () => {
beforeAll(() => {
const shouldSuppress = (args: string[]) => {
const msg = args.join(" ");
return msg.includes("<Suspense> 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();
});
it("renders the header correctly", async () => {
useSidebarMock.mockReturnValue({
isMobile: ref(false),
state: ref("expanded"),
@ -115,17 +149,41 @@ describe("SidebarLayout", () => {
setOpenMobile: vi.fn(),
});
const wrapper = mount(SidebarLayout, {
props: {
collapsible: "icon",
const wrapper = mount({
components: { SidebarLayout },
template: "<Suspense><SidebarLayout v-bind='props' /></Suspense>",
setup() {
return {
props: {
collapsible: "icon",
},
};
},
});
await flushPromises();
expect(wrapper.text()).toContain("Glowing Fiesta");
expect(wrapper.text()).toContain("v1.0.0");
});
it("renders sidebar content correctly", () => {
const wrapper = mount(SidebarLayout);
it("renders sidebar content correctly", async () => {
const user = {
name: "Liviu",
email: "x.liviu@gmail.com",
image: "avatar.png",
id: "123",
emailVerified: true,
createdAt: new Date(),
updatedAt: new Date(),
};
const wrapper = mount({
components: { SidebarLayout },
template: "<Suspense><SidebarLayout :user='user' /></Suspense>",
setup() {
return { user };
},
});
await flushPromises();
const text = wrapper.text();
// Navigation groups
@ -144,24 +202,31 @@ describe("SidebarLayout", () => {
expect(text).toContain("Get Started");
});
it("does not render icon if item.icon is missing", () => {
const wrapper = mount(SidebarLayout, {
props: {
navItems: [
{
title: "No Icon Item",
url: "#",
items: [],
it("does not render icon if item.icon is missing", async () => {
const wrapper = mount({
components: { SidebarLayout },
template: "<Suspense><SidebarLayout v-bind='props' /></Suspense>",
setup() {
return {
props: {
navItems: [
{
title: "No Icon Item",
url: "#",
items: [],
},
],
},
],
};
},
});
await flushPromises();
expect(wrapper.text()).toContain("No Icon Item");
expect(wrapper.find('[data-testid="sidebar-icon"]').exists()).toBe(false);
});
it("renders correctly in mobile view", () => {
it("renders correctly in mobile view", async () => {
useSidebarMock.mockReturnValue({
isMobile: ref(true),
state: ref("expanded"),
@ -169,7 +234,24 @@ describe("SidebarLayout", () => {
setOpenMobile: vi.fn(),
});
const wrapper = mount(SidebarLayout);
const user = {
name: "Liviu",
email: "x.liviu@gmail.com",
image: "avatar.png",
id: "123",
emailVerified: true,
createdAt: new Date(),
updatedAt: new Date(),
};
const wrapper = mount({
components: { SidebarLayout },
template: "<Suspense><SidebarLayout :user='user' /></Suspense>",
setup() {
return { user };
},
});
await flushPromises();
// When isMobile is true, it renders a Sheet.
// Since we mocked Sheet components as simple divs with slots, the content should still be present.