-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(ui): write tests for
Profile
(#786)
* test: write tests for `Profile` * chore: add test for `undefined` states
- Loading branch information
1 parent
01b0a9b
commit d44cd6f
Showing
2 changed files
with
102 additions
and
20 deletions.
There are no files selected for viewing
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
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 |
---|---|---|
@@ -0,0 +1,74 @@ | ||
import { render, screen } from "@testing-library/react"; | ||
import { describe, vi, test, expect } from "vitest"; | ||
import { Profile } from "."; | ||
import * as api from "@/api"; | ||
|
||
vi.mock("@/api", async (importOriginals) => ({ | ||
...((await importOriginals()) as object), | ||
useGetUser: vi.fn(() => ({ | ||
data: { | ||
user: { | ||
"custom:state": "MD,OH,NY", | ||
"custom:cms-roles": "onemac-micro-statesubmitter", | ||
given_name: "George", | ||
family_name: "Harrison", | ||
email: "[email protected]", | ||
}, | ||
}, | ||
})), | ||
})); | ||
|
||
describe("Profile", () => { | ||
test("renders state names", () => { | ||
render(<Profile />); | ||
|
||
const states = screen.getByText("Maryland, Ohio, New York"); | ||
|
||
expect(states).toBeInTheDocument(); | ||
}); | ||
|
||
test("renders nothing if user has no states", () => { | ||
vi.spyOn(api, "useGetUser").mockImplementationOnce(() => ({ | ||
data: { | ||
// @ts-expect-error - avoid mocking whole user object for test | ||
user: { | ||
"custom:state": undefined, | ||
"custom:cms-roles": "onemac-micro-statesubmitter", | ||
given_name: "George", | ||
family_name: "Harrison", | ||
email: "[email protected]", | ||
}, | ||
}, | ||
})); | ||
|
||
render(<Profile />); | ||
|
||
const accessGranted = screen.queryByText("Access Granted"); | ||
|
||
expect(accessGranted).not.toBeInTheDocument(); | ||
}); | ||
|
||
test("renders roles", () => { | ||
render(<Profile />); | ||
|
||
const states = screen.getByText("State Submitter"); | ||
|
||
expect(states).toBeInTheDocument(); | ||
}); | ||
|
||
test("renders full name", () => { | ||
render(<Profile />); | ||
|
||
const states = screen.getByText("George Harrison"); | ||
|
||
expect(states).toBeInTheDocument(); | ||
}); | ||
|
||
test("renders email", () => { | ||
render(<Profile />); | ||
|
||
const states = screen.getByText("[email protected]"); | ||
|
||
expect(states).toBeInTheDocument(); | ||
}); | ||
}); |