-
Notifications
You must be signed in to change notification settings - Fork 6
Create /test/view pages
#1396
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Create /test/view pages
#1396
Changes from 1 commit
Commits
Show all changes
28 commits
Select commit
Hold shift + click to select a range
9971fb1
add `QuizView` page
barna-isaac a8d9a8e
hide `Test Sections` when there aren't any
barna-isaac 69dc490
change breadcrumbs, actionMessage on `QuizView`
barna-isaac 0c35462
clean up redundant tests
barna-isaac eaf12a2
show "Take Test" button
barna-isaac e61fad5
allow navigation between the `view` and `attempt` pages
barna-isaac cb69193
just a style fix
barna-isaac ab5b131
show `Preview` button for teachers and above
barna-isaac 900b1e8
simplify `QuizAttemptFooter`
barna-isaac dc8c6c1
take user to "View Test" from "Practice Tests"
barna-isaac 2671a18
undo change I comitted by accident
barna-isaac ea81ef8
refactor: extract error response from handlers
barna-isaac 0fcd569
prevent overflow on `Take Test` button
barna-isaac a9bc488
`QuizView` works on Ada
barna-isaac ec8a23f
fix spacing
barna-isaac f5eff81
a minor refactor
barna-isaac 44d9f22
Continue on `QuizDoFreeAttempt` allows going back
barna-isaac f61741f
quiz attempt pages always allow navigating back
barna-isaac c9ed9b1
allow backward navigation when previewing
barna-isaac 8786913
extract Quiz page helpers
barna-isaac b0b62c9
apply Ada-specific casing differences
barna-isaac f7c7118
refactor: fix typo in filename
barna-isaac 2710697
fix editing mistake in tooltip text
barna-isaac 93493e1
`IsaacRubricDTO` -> `DetailedQuizSummaryDTO`
barna-isaac 058a720
preserve consistency with API types
barna-isaac a12c43d
simplify QuizAttemptComponent
barna-isaac 93b66da
rename `QuizAttemptComponent`
barna-isaac 2fdd92a
remove `anySections` check in `QuizContents`
barna-isaac File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
barna-isaac marked this conversation as resolved.
Show resolved
Hide resolved
|
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| import React from "react"; | ||
| import {TitleAndBreadcrumb} from "../../elements/TitleAndBreadcrumb"; | ||
| import {myQuizzesCrumbs} from "./QuizAttemptComponent"; | ||
| import {Alert} from "reactstrap"; | ||
| import { getRTKQueryErrorMessage } from "../../../state"; | ||
| import type {FetchBaseQueryError} from "@reduxjs/toolkit/query"; | ||
| import type {SerializedError} from "@reduxjs/toolkit"; | ||
|
|
||
| type Error = FetchBaseQueryError | SerializedError | undefined; | ||
|
|
||
| export const buildErrorComponent = (title: string, heading: string) => function ErrorComponent(error: Error){ | ||
| return <> | ||
| <TitleAndBreadcrumb currentPageTitle={title} intermediateCrumbs={myQuizzesCrumbs} /> | ||
| <Alert color="danger"> | ||
| <h4 className="alert-heading">{heading}</h4> | ||
| <p data-testid="error-message">{getRTKQueryErrorMessage(error).message}</p> | ||
| </Alert> | ||
| </>; | ||
| }; |
This file contains hidden or 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
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| import React from "react"; | ||
| import {useGetQuizRubricQuery} from "../../../state"; | ||
| import {useParams} from "react-router-dom"; | ||
| import {tags} from "../../../services"; | ||
| import {QuizAttemptComponent} from "../../elements/quiz/QuizAttemptComponent"; | ||
| import {Container} from "reactstrap"; | ||
| import {ShowLoadingQuery} from "../../handlers/ShowLoadingQuery"; | ||
| import type { RegisteredUserDTO } from "../../../../IsaacApiTypes"; | ||
| import { buildErrorComponent } from "../../elements/quiz/builErrorComponent"; | ||
|
|
||
| const pageLink = () => ''; | ||
|
|
||
| const pageHelp = <span> View information about this test. </span>; | ||
|
|
||
| const Error = buildErrorComponent("Viewing Test", "There was an error loading that test."); | ||
|
|
||
| export const QuizView = ({user}: {user: RegisteredUserDTO}) => { | ||
| const {quizId} = useParams<{quizId: string}>(); | ||
| const quizRubricQuery = useGetQuizRubricQuery(quizId); | ||
| const attempt = { | ||
| quiz: quizRubricQuery.data && tags.augmentDocWithSubject(quizRubricQuery.data), | ||
| quizId: quizRubricQuery.data?.id, | ||
| }; | ||
|
|
||
| return <Container className={`mb-5 ${attempt?.quiz?.subjectId}`}> | ||
| <ShowLoadingQuery query={quizRubricQuery} ifError={Error}> | ||
| <QuizAttemptComponent preview attempt={attempt} page={null} questions={[]} sections={{}} pageLink={pageLink} pageHelp={pageHelp} user={user} /> | ||
| </ShowLoadingQuery> | ||
| </Container>; | ||
| }; |
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,81 @@ | ||
| import {act, screen} from "@testing-library/react"; | ||
| import {expectH1, expectH4, expectTextInElementWithId, expectTitledSection, expectUrl, renderTestEnvironment, setUrl, waitForLoaded} from "../testUtils"; | ||
| import {mockRubrics} from "../../mocks/data"; | ||
| import {isPhy} from "../../app/services"; | ||
| import type {UserRole} from "../../IsaacApiTypes"; | ||
|
|
||
| describe("QuizView", () => { | ||
| if (!isPhy) { | ||
| return it('does not exist yet', () => {}); | ||
barna-isaac marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| }; | ||
|
|
||
| const rubricId = Object.keys(mockRubrics)[0]; | ||
| const mockRubric = mockRubrics[rubricId]; | ||
|
|
||
| const renderQuizView = async ({role, pathname}: {role: UserRole | "ANONYMOUS", pathname: string}) => { | ||
| await act(async () => renderTestEnvironment({ role })); | ||
| await act(async () => setUrl({ pathname })); | ||
| await waitForLoaded(); | ||
| }; | ||
|
|
||
| it('shows the rubric for the quiz', async () => { | ||
| await renderQuizView({ role: 'STUDENT', pathname: `/test/view/${rubricId}/` }); | ||
| expectH1(mockRubric.title); | ||
| expectTitledSection("Instructions", mockRubric.rubric?.children?.[0].value); | ||
| }); | ||
|
|
||
| it('does not show the Set Test button', async () => { | ||
| await renderQuizView({ role: 'STUDENT', pathname: `/test/view/${rubricId}/` }); | ||
| expect(setTestButton()).toBe(null); | ||
| }); | ||
|
|
||
| it("does not show the edit button", async () => { | ||
| await renderQuizView({ role: 'STUDENT', pathname: `/test/view/${rubricId}/` }); | ||
| expect(editButton()).toBe(null); | ||
| }); | ||
|
|
||
| describe('for teachers', () => { | ||
| it('shows the Set Test button', async () => { | ||
| await renderQuizView({ role: 'TEACHER', pathname: `/test/view/${rubricId}/` }); | ||
| expect(setTestButton()).toBeInTheDocument(); | ||
| }); | ||
|
|
||
| it("does not show the edit button", async () => { | ||
| await renderQuizView({ role: 'TEACHER', pathname: `/test/view/${rubricId}/` }); | ||
| expect(editButton()).toBe(null); | ||
| }); | ||
| }); | ||
|
|
||
| describe('for content editors', () => { | ||
| it('shows the Set Test Button', async () => { | ||
| await renderQuizView({ role: 'CONTENT_EDITOR', pathname: `/test/view/${rubricId}/` }); | ||
| expect(setTestButton()).toBeInTheDocument(); | ||
| }); | ||
|
|
||
| // we'd need canonicalSourceFile for this, which the endpoint doesn't return | ||
| it('does not show the edit button', async () => { | ||
| await renderQuizView({ role: 'CONTENT_EDITOR', pathname: `/test/view/${rubricId}/` }); | ||
| expect(editButton()).toBe(null); | ||
| }); | ||
| }); | ||
|
|
||
| describe('for unregistered users', () => { | ||
| it('redirects to log in', async () => { | ||
| await renderQuizView({ role: 'ANONYMOUS', pathname: '/test/view/some_non_existent_test'}); | ||
| await expectUrl('/login'); | ||
| }); | ||
| }); | ||
|
|
||
| describe('when a quiz does not exist', () => { | ||
| it('shows an error', async () => { | ||
| await renderQuizView({ role: 'STUDENT', pathname: '/test/view/some_non_existent_test'}); | ||
| expectH1('Viewing Test'); | ||
| expectH4('There was an error loading that test.'); | ||
| expectErrorMessage('This test has become unavailable.'); | ||
| }); | ||
| }); | ||
| }); | ||
|
|
||
| const expectErrorMessage = expectTextInElementWithId('error-message'); | ||
| const setTestButton = () => screen.queryByRole('button', {name: "Set Test"}); | ||
| const editButton = () => screen.queryByRole('header', {name: "Published ✎"}); | ||
This file contains hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.