-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2810 from oaknational/feat/PUPIL-967/PUPIL-1033/p…
…rintable-results-page feat(printable): create style printable results page
- Loading branch information
Showing
15 changed files
with
633 additions
and
249 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
120 changes: 119 additions & 1 deletion
120
src/__tests__/pages/pupils/lessons/[lessonSlug]/results/[attemptId]/printable.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,125 @@ | ||
import CanonicalResultsPage from "@/pages/pupils/lessons/[lessonSlug]/results/[attemptId]/printable"; | ||
import React from "react"; | ||
import { useOakPupil } from "@oaknational/oak-pupil-client"; | ||
import { screen, waitFor } from "@testing-library/react"; | ||
import { oakDefaultTheme, OakThemeProvider } from "@oaknational/oak-components"; | ||
|
||
import CanonicalResultsPage, { | ||
CanonicalResultsPrintablePageProps, | ||
getStaticProps, | ||
InnerRender, | ||
} from "@/pages/pupils/lessons/[lessonSlug]/results/[attemptId]/printable"; | ||
import curriculumApi2023 from "@/node-lib/curriculum-api-2023/__mocks__/index"; | ||
import { lessonBrowseDataFixture } from "@/node-lib/curriculum-api-2023/fixtures/lessonBrowseData.fixture"; | ||
import { lessonContentFixture } from "@/node-lib/curriculum-api-2023/fixtures/lessonContent.fixture"; | ||
import OakError from "@/errors/OakError"; | ||
import renderWithTheme from "@/__tests__/__helpers__/renderWithTheme"; | ||
|
||
const mockProps: CanonicalResultsPrintablePageProps = { | ||
browseData: lessonBrowseDataFixture({}), | ||
content: lessonContentFixture({}), | ||
attemptId: "attemptId", | ||
}; | ||
jest.mock("@oaknational/oak-pupil-client", () => ({ | ||
...jest.requireActual("@oaknational/oak-pupil-client"), | ||
useOakPupil: jest.fn().mockReturnValue({ | ||
getAttempt: jest.fn(), | ||
}), | ||
})); | ||
|
||
jest.mock("@/components/PupilViews/PupilResults", () => ({ | ||
PupilViewsResults: () => <div>attemptDataRendered</div>, | ||
})); | ||
|
||
describe("CanonicalResultsPage", () => { | ||
it("should render", () => { | ||
expect(CanonicalResultsPage).toBeTruthy(); | ||
}); | ||
describe("innner render", () => { | ||
it("should render loading state if no attempt data", () => { | ||
const { getByText } = renderWithTheme( | ||
<OakThemeProvider theme={oakDefaultTheme}> | ||
<InnerRender {...mockProps} /> | ||
</OakThemeProvider>, | ||
); | ||
expect(getByText("Loading lesson results...")).toBeInTheDocument(); | ||
}); | ||
it("should render PupilViewsResults if attempt data", async () => { | ||
const mockAttemptData = { attemptData: "attemptData" }; | ||
(useOakPupil as jest.Mock).mockReturnValue({ | ||
getAttempt: jest.fn().mockResolvedValue(mockAttemptData), | ||
}); | ||
renderWithTheme( | ||
<OakThemeProvider theme={oakDefaultTheme}> | ||
<InnerRender {...mockProps} /> | ||
</OakThemeProvider>, | ||
); | ||
expect(screen.getByText("Loading lesson results...")).toBeInTheDocument(); | ||
await waitFor(() => { | ||
expect( | ||
screen.queryByText("Loading lesson results..."), | ||
).not.toBeInTheDocument(); | ||
expect(screen.getByText("attemptDataRendered")).toBeInTheDocument(); | ||
}); | ||
}); | ||
}); | ||
|
||
// }); | ||
describe("pages/pupils/lessons/[lessonSlug]/results/[attemptId]/printable", () => { | ||
describe("getStaticProps", () => { | ||
it("Should call API:pupilLessonQuery", async () => { | ||
await getStaticProps({ | ||
params: { | ||
lessonSlug: "lessonSlug", | ||
attemptId: "attemptId", | ||
}, | ||
}); | ||
|
||
expect(curriculumApi2023.pupilLessonQuery).toHaveBeenCalledWith({ | ||
lessonSlug: "lessonSlug", | ||
}); | ||
}); | ||
|
||
it("should return props", async () => { | ||
const curriculumData = { | ||
browseData: lessonBrowseDataFixture({ | ||
isLegacy: true, | ||
unitSlug: "test-unit-slug", | ||
}), | ||
content: lessonContentFixture({}), | ||
}; | ||
|
||
(curriculumApi2023.pupilLessonQuery as jest.Mock).mockResolvedValueOnce( | ||
curriculumData, | ||
); | ||
|
||
const res = (await getStaticProps({ | ||
params: { | ||
lessonSlug: "lessonSlug", | ||
attemptId: "attemptId", | ||
}, | ||
})) as { | ||
props: CanonicalResultsPrintablePageProps; | ||
}; | ||
|
||
expect(res.props.browseData).toEqual(curriculumData.browseData); | ||
expect(res.props.content).toEqual(curriculumData.content); | ||
}); | ||
|
||
it("should return 404 if lesson not found", async () => { | ||
(curriculumApi2023.pupilLessonQuery as jest.Mock).mockRejectedValueOnce( | ||
new OakError({ code: "curriculum-api/not-found" }), | ||
); | ||
const res = await getStaticProps({ | ||
params: { | ||
lessonSlug: "lessonSlug", | ||
attemptId: "attemptId", | ||
}, | ||
}); | ||
|
||
expect(res).toEqual({ | ||
notFound: true, | ||
}); | ||
}); | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.