Skip to content

Commit

Permalink
In process of adding lesson quiz tests
Browse files Browse the repository at this point in the history
  • Loading branch information
salemlf committed Oct 26, 2024
1 parent 30749b2 commit 6db4a02
Showing 1 changed file with 54 additions and 2 deletions.
56 changes: 54 additions & 2 deletions src/pages/LessonQuiz.test.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,63 @@
import { act, createTestRouter, TestRoute } from "../testing/test-utils";
import useAssignmentQueueStoreFacade from "../stores/useAssignmentQueueStore/useAssignmentQueueStore.facade";
import useQueueStoreFacade from "../stores/useQueueStore/useQueueStore.facade";
import { generateRandomQueueItems } from "../testing/mocks/data-generators/assignmentQueueGenerator";
import {
act,
createTestRouter,
renderHook,
TestRoute,
screen,
} from "../testing/test-utils";
import { AssignmentQueueItem } from "../types/AssignmentQueueTypes";
import LessonQuiz from "./LessonQuiz";

const mockQueueStore = () => {
renderHook(() => useQueueStoreFacade());
};

const mockLessonQueueStore = (queueItems: AssignmentQueueItem[]) => {
const { result: assignmentQueueResult } = renderHook(() =>
useAssignmentQueueStoreFacade()
);
expect(assignmentQueueResult.current.assignmentQueue).toEqual([]);
act(() =>
assignmentQueueResult.current.setAssignmentQueueData(queueItems, "lesson")
);
};
test("LessonQuiz renders", async () => {
const { baseElement } = await renderComponent(false);
const { baseElement } = await renderComponent();
expect(baseElement).toBeDefined();
});

describe("End quiz dialog", () => {
// TODO: doesn't work, fix
test("Displays dialog on home button click", async () => {
mockQueueStore();
const randomQueueItems = generateRandomQueueItems({
numItems: 10,
areLessons: true,
queueProgressState: "not_started",
});
mockLessonQueueStore(randomQueueItems);

const { user } = await renderComponent(true);

await user.click(
await screen.findByRole("button", {
name: /home page/i,
})
);

const dialog = await screen.findByRole("alertdialog", {
name: /end lesson quiz\?/i,
});

expect(dialog).toBeInTheDocument();

// screen.debug();
});
});

const renderComponent = async (withHomeRoute: boolean = false) => {
const lessonQuizPath = "/lessons/quiz";
const lessonQuizRoute: TestRoute = {
Expand Down

0 comments on commit 6db4a02

Please sign in to comment.