[Closes #10] Reactive breadcrumbs
This commit is contained in:
parent
6d3cdb560d
commit
a1708317ec
19 changed files with 200 additions and 33 deletions
|
|
@ -166,7 +166,7 @@ describe("SidebarFooter.vue", () => {
|
|||
expect(wrapper.text()).not.toContain("Log out");
|
||||
});
|
||||
|
||||
it("calls navigateTo('/member/auth/logout') when Log out is clicked", async () => {
|
||||
it("calls navigateTo('/auth/logout') when Log out is clicked", async () => {
|
||||
const wrapper = mount(SidebarFooterComponent, {
|
||||
props: { user },
|
||||
global: {
|
||||
|
|
@ -181,10 +181,10 @@ describe("SidebarFooter.vue", () => {
|
|||
expect(logoutItem).toBeDefined();
|
||||
await logoutItem?.trigger("click");
|
||||
|
||||
expect(navigateToMock).toHaveBeenCalledWith("/member/auth/logout");
|
||||
expect(navigateToMock).toHaveBeenCalledWith("/auth/logout");
|
||||
});
|
||||
|
||||
it("calls navigateTo('/member/auth/login') when Log in is clicked", async () => {
|
||||
it("calls navigateTo('/auth/login') when Log in is clicked", async () => {
|
||||
const wrapper = mount(SidebarFooterComponent, {
|
||||
props: { user: null },
|
||||
global: {
|
||||
|
|
@ -199,7 +199,7 @@ describe("SidebarFooter.vue", () => {
|
|||
expect(loginItem).toBeDefined();
|
||||
await loginItem?.trigger("click");
|
||||
|
||||
expect(navigateToMock).toHaveBeenCalledWith("/member/auth/login");
|
||||
expect(navigateToMock).toHaveBeenCalledWith("/auth/login");
|
||||
});
|
||||
|
||||
it("computes initials correctly for single name", () => {
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
import { mount, flushPromises } from "@vue/test-utils";
|
||||
import { describe, it, expect, vi, beforeEach } from "vitest";
|
||||
import CreateAccountPage from "~/pages/member/auth/create-account.vue";
|
||||
import CreateAccountPage from "~/pages/auth/create-account.vue";
|
||||
|
||||
// Mock auth client
|
||||
const authMocks = vi.hoisted(() => ({
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
import { mount, flushPromises } from "@vue/test-utils";
|
||||
import { describe, expect, it, vi, beforeEach, beforeAll, afterAll } from "vitest";
|
||||
import LoginPage from "~/pages/member/auth/login.vue";
|
||||
import LoginPage from "~/pages/auth/login.vue";
|
||||
|
||||
// Mock the auth store
|
||||
const authStoreMocks = vi.hoisted(() => ({
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
import { mount, flushPromises } from "@vue/test-utils";
|
||||
import { describe, expect, it, vi, beforeEach, beforeAll, afterAll } from "vitest";
|
||||
import LogoutPage from "~/pages/member/auth/logout.vue";
|
||||
import LogoutPage from "~/pages/auth/logout.vue";
|
||||
|
||||
// Mock the auth store
|
||||
const mocks = vi.hoisted(() => ({
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
import { describe, expect, it, beforeEach } from "vitest";
|
||||
import { beforeEach, describe, expect, it } from "vitest";
|
||||
import { mount, type VueWrapper } from "@vue/test-utils";
|
||||
import IndexPage from "~/pages/index.vue";
|
||||
|
||||
|
|
|
|||
|
|
@ -18,6 +18,16 @@ Object.defineProperty(global, "import", {
|
|||
writable: true,
|
||||
});
|
||||
|
||||
const breadcrumbStoreMocks = vi.hoisted(() => ({
|
||||
setBreadcrumbs: vi.fn(),
|
||||
addBreadcrumb: vi.fn(),
|
||||
clear: vi.fn(),
|
||||
items: [{ label: "Auth" }, { label: "Create Account", to: "/auth/create-account" }],
|
||||
}));
|
||||
vi.mock("~/stores/breadcrumbs", () => ({
|
||||
useBreadcrumbStore: () => breadcrumbStoreMocks,
|
||||
}));
|
||||
|
||||
config.global.stubs = {
|
||||
NuxtLayout: true,
|
||||
NuxtPage: true,
|
||||
|
|
|
|||
23
tests/shared/utils/auth-client.test.ts
Normal file
23
tests/shared/utils/auth-client.test.ts
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
import { describe, expect, it, vi } from "vitest";
|
||||
|
||||
import { authClient } from "#shared/utils/auth-client";
|
||||
import { createAuthClient } from "better-auth/vue";
|
||||
|
||||
const vars = vi.hoisted(() => ({
|
||||
mockAuthClient: {
|
||||
signIn: vi.fn(),
|
||||
signUp: vi.fn(),
|
||||
signOut: vi.fn(),
|
||||
},
|
||||
}));
|
||||
|
||||
vi.mock("better-auth/vue", () => ({
|
||||
createAuthClient: vi.fn(() => vars.mockAuthClient),
|
||||
}));
|
||||
|
||||
describe("auth-client utility", () => {
|
||||
it("should create and export the auth client", () => {
|
||||
expect(createAuthClient).toHaveBeenCalled();
|
||||
expect(authClient).toBe(vars.mockAuthClient);
|
||||
});
|
||||
});
|
||||
36
tests/shared/utils/env.test.ts
Normal file
36
tests/shared/utils/env.test.ts
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
/* eslint-disable node/no-process-env */
|
||||
import { describe, it, expect, vi, beforeEach, afterEach } from "vitest";
|
||||
import { z } from "zod";
|
||||
|
||||
describe("shared/utils/env", () => {
|
||||
const originalEnv = process.env;
|
||||
|
||||
beforeEach(() => {
|
||||
vi.resetModules();
|
||||
process.env = { ...originalEnv };
|
||||
process.env.NODE_ENV = "test";
|
||||
process.env.DATABASE_URL = "postgres://localhost:5432/db";
|
||||
process.env.BETTER_AUTH_SECRET = "secret";
|
||||
process.env.BETTER_AUTH_URL = "http://localhost:3000";
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
process.env = originalEnv;
|
||||
});
|
||||
|
||||
it("should validate and export variables when all required variables are present", async () => {
|
||||
const env = (await import("#shared/utils/env")).default;
|
||||
|
||||
expect(env).toEqual({
|
||||
NODE_ENV: "test",
|
||||
DATABASE_URL: "postgres://localhost:5432/db",
|
||||
BETTER_AUTH_SECRET: "secret",
|
||||
BETTER_AUTH_URL: "http://localhost:3000",
|
||||
});
|
||||
});
|
||||
|
||||
it("should throw an error if NODE_ENV is missing", async () => {
|
||||
delete process.env.NODE_ENV;
|
||||
await expect(import("#shared/utils/env")).rejects.toThrow(z.ZodError);
|
||||
});
|
||||
});
|
||||
40
tests/stores/breadcrumbs.test.ts
Normal file
40
tests/stores/breadcrumbs.test.ts
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
import { beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import { createPinia, setActivePinia } from "pinia";
|
||||
import { useBreadcrumbStore } from "~/stores/breadcrumbs";
|
||||
|
||||
vi.unmock("~/stores/breadcrumbs");
|
||||
|
||||
describe("useBreadcrumbStore", () => {
|
||||
beforeEach(() => {
|
||||
setActivePinia(createPinia());
|
||||
});
|
||||
|
||||
describe("init", () => {
|
||||
it("should initialize", () => {
|
||||
const store = useBreadcrumbStore();
|
||||
expect(store.items.length).toEqual(0);
|
||||
});
|
||||
|
||||
it("clear should remove all breadcrumbs", () => {
|
||||
const store = useBreadcrumbStore();
|
||||
store.addBreadcrumb({ label: "Test", to: "/test" });
|
||||
store.clear();
|
||||
expect(store.items.length).toEqual(0);
|
||||
});
|
||||
|
||||
it("addBreadcrumb should add a breadcrumb", () => {
|
||||
const store = useBreadcrumbStore();
|
||||
store.addBreadcrumb({ label: "Test", to: "/test" });
|
||||
expect(store.items.length).toEqual(1);
|
||||
});
|
||||
|
||||
it("setBreadcrumbs should set breadcrumbs", () => {
|
||||
const store = useBreadcrumbStore();
|
||||
store.setBreadcrumbs([
|
||||
{ label: "Test", to: "/test" },
|
||||
{ label: "Test 2", to: "/test2" },
|
||||
]);
|
||||
expect(store.items.length).toEqual(2);
|
||||
});
|
||||
});
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue