Skip to content
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

test: verify email component #4019

Open
wants to merge 14 commits into
base: jh/verify-email-page
Choose a base branch
from

Conversation

jamdelion
Copy link
Contributor

@jamdelion jamdelion commented Nov 28, 2024

The long-awaited filling in of the test.todos for the verify submission email component!

I have added Mock Service Worker as a package (recommended by react-testing-library as the best way to mock API calls, and something I have worked with before). I'm using here to intercept calls to /download-application-file so I can test behaviour in an error state, and check that files are downloaded without having to do complicated download mocks.

@jamdelion jamdelion changed the base branch from main to jh/verify-email-page November 28, 2024 17:08
Copy link

github-actions bot commented Dec 2, 2024

Pizza

Deployed 445ad21 to https://4019.planx.pizza.

Useful links:

Copy link

github-actions bot commented Jan 6, 2025

🤖 Hasura Change Summary compared a subset of table metadata including permissions:

Tracked Tables (1)

Updated Tables (3)

  • public.flows

  • public.payment_requests permissions:

    insert select update delete
    api / / /
    public /
    4 added column permissions
    insert select update
    api ➕ fee_breakdown ➕ fee_breakdown ➕ fee_breakdown
    public
  • public.teams permissions:

    insert select update delete
    api /
    2 added column permissions
    insert select update
    api ➕ metabase_id ➕ metabase_id

describe("when the VerifySubmissionEmail component renders", () => {
it("displays the email address input", () => {
setup(<VerifySubmissionEmail params={{ sessionId: "1" }} />);

expect(
screen.queryByText("Verify your submission email address"),
Copy link
Contributor Author

@jamdelion jamdelion Jan 7, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

random: found a nice document of dos/donts for react-testing-library: https://kentcdodds.com/blog/common-mistakes-with-react-testing-library#using-query-variants-for-anything-except-checking-for-non-existence

I knew there was one way or another to use queryBy but always forget which way round it is!

@@ -13,10 +14,16 @@ import { vi } from "vitest";
*/
const mockFade = vi.fn(({ children }: FadeProps) => <div>{children}</div>);

vi.mock("@mui/material/Fade", () => ({
vi.doMock("@mui/material/Fade", () => ({
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Errored after I added in the msw beforeEach stuff, so found this solution from https://vitest.dev/api/vi.html#vi-mock

vi.mock is hoisted (in other words, moved) to top of the file. It means that whenever you write it (be it inside beforeEach or test), it will actually be called before that.

This also means that you cannot use any variables inside the factory that are defined outside the factory.

If you need to use variables inside the factory, try vi.doMock. It works the same way but isn't hoisted. Beware that it only mocks subsequent imports.

@jamdelion jamdelion marked this pull request as ready for review January 7, 2025 12:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant