40 lines
1.1 KiB
TypeScript
40 lines
1.1 KiB
TypeScript
import { createPinia, setActivePinia } from "pinia";
|
|
import { beforeEach, describe, expect, vi } from "vitest";
|
|
import * as courseSessions from "../../stores/courseSessions";
|
|
import { expertRequired } from "../guards";
|
|
|
|
describe("Guards", () => {
|
|
afterEach(() => {
|
|
vi.restoreAllMocks();
|
|
});
|
|
|
|
beforeEach(() => {
|
|
// creates a fresh pinia and make it active so it's automatically picked
|
|
// up by any useStore() call without having to pass it to it:
|
|
// `useStore(pinia)`
|
|
setActivePinia(createPinia());
|
|
});
|
|
|
|
it("cannot route to cockpit", () => {
|
|
vi.spyOn(courseSessions, "useCourseSessionsStore").mockReturnValue({
|
|
hasCockpit: false,
|
|
});
|
|
const slug = "test";
|
|
expect(expertRequired({ params: { courseSlug: "test" } })).toEqual(
|
|
`/course/${slug}/learn`
|
|
);
|
|
});
|
|
|
|
it("can route to cockpit", () => {
|
|
vi.spyOn(courseSessions, "useCourseSessionsStore").mockReturnValue({
|
|
hasCockpit: true,
|
|
});
|
|
const to = {
|
|
params: {
|
|
courseSlug: "test",
|
|
},
|
|
};
|
|
expect(expertRequired(to)).toBe(true);
|
|
});
|
|
});
|