-
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.
- Loading branch information
1 parent
04e526a
commit 744d142
Showing
11 changed files
with
388 additions
and
1 deletion.
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
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
78 changes: 78 additions & 0 deletions
78
services/ui-src/src/components/pages/Profile/ProfilePage.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 |
---|---|---|
@@ -0,0 +1,78 @@ | ||
import { fireEvent, render, screen } from "@testing-library/react"; | ||
import { axe } from "jest-axe"; | ||
// components | ||
import { ProfilePage } from "components"; | ||
// utils | ||
import { | ||
mockAdminUserStore, | ||
mockStateUserStore, | ||
RouterWrappedComponent, | ||
} from "utils/testing/setupJest"; | ||
import { useStore } from "utils"; | ||
|
||
const ProfilePageComponent = ( | ||
<RouterWrappedComponent> | ||
<ProfilePage /> | ||
</RouterWrappedComponent> | ||
); | ||
|
||
// MOCKS | ||
|
||
jest.mock("utils/state/useStore"); | ||
const mockedUseStore = useStore as jest.MockedFunction<typeof useStore>; | ||
|
||
// TESTS | ||
|
||
describe("Test ProfilePage for admin users", () => { | ||
beforeEach(() => { | ||
mockedUseStore.mockReturnValue(mockAdminUserStore); | ||
render(ProfilePageComponent); | ||
}); | ||
test("Check that Profile page renders properly", () => { | ||
expect(screen.getByTestId("profile-view")).toBeVisible(); | ||
}); | ||
|
||
test("Check that there is an banner editor button visible", () => { | ||
expect(screen.getByTestId("banner-admin-button")).toBeVisible(); | ||
}); | ||
|
||
test("Check that the state field is set to N/A", () => { | ||
expect(screen.getByText("State")).toBeVisible(); | ||
expect(screen.getByText("N/A")).toBeVisible(); | ||
}); | ||
|
||
test("Check that admin button navigates to /admin on click", () => { | ||
const adminButton = screen.getByTestId("banner-admin-button"); | ||
expect(adminButton).toBeVisible(); | ||
fireEvent.click(adminButton); | ||
expect(window.location.pathname).toEqual("/admin"); | ||
}); | ||
}); | ||
|
||
describe("Test ProfilePage for state users", () => { | ||
beforeEach(() => { | ||
mockedUseStore.mockReturnValue(mockStateUserStore); | ||
render(ProfilePageComponent); | ||
}); | ||
test("Check that Profile page renders properly", () => { | ||
expect(screen.getByTestId("profile-view")).toBeVisible(); | ||
}); | ||
|
||
test("Check that state is visible and set accordingly", () => { | ||
expect(screen.getByText("State")).toBeVisible(); | ||
expect(screen.getByText("MN")).toBeVisible(); | ||
}); | ||
|
||
test("Check that there is not an banner editor button", () => { | ||
expect(screen.queryByText("Banner Editor")).not.toBeInTheDocument(); | ||
}); | ||
}); | ||
|
||
describe("Test ProfilePage accessibility", () => { | ||
it("Should not have basic accessibility issues", async () => { | ||
mockedUseStore.mockReturnValue(mockAdminUserStore); | ||
const { container } = render(ProfilePageComponent); | ||
const results = await axe(container); | ||
expect(results).toHaveNoViolations(); | ||
}); | ||
}); |
80 changes: 80 additions & 0 deletions
80
services/ui-src/src/components/pages/Profile/ProfilePage.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 |
---|---|---|
@@ -0,0 +1,80 @@ | ||
import { useNavigate } from "react-router-dom"; | ||
// components | ||
import { Button, Heading, Link, Text } from "@chakra-ui/react"; | ||
import { PageTemplate, Table } from "components"; | ||
//utils | ||
import { createEmailLink, useStore } from "utils"; | ||
import verbiage from "verbiage/pages/profile"; | ||
|
||
export const ProfilePage = () => { | ||
const navigate = useNavigate(); | ||
|
||
const { email, given_name, family_name, userRole, state, userIsAdmin } = | ||
useStore().user ?? {}; | ||
|
||
const { intro } = verbiage; | ||
|
||
const tableContent = { | ||
caption: "Profile Account Information", | ||
bodyRows: [ | ||
["Email", email!], | ||
["First Name", given_name!], | ||
["Last Name", family_name!], | ||
["Role", userRole!], | ||
["State", state! || "N/A"], | ||
], | ||
}; | ||
|
||
return ( | ||
<PageTemplate sx={sx.layout} data-testid="profile-view"> | ||
<Heading as="h1" sx={sx.headerText}> | ||
{intro.header} | ||
</Heading> | ||
<Text> | ||
{intro.body}{" "} | ||
<Link href={createEmailLink(intro.email)} isExternal> | ||
{intro.email.address} | ||
</Link> | ||
. | ||
</Text> | ||
<Table content={tableContent} variant="striped" sxOverride={sx.table} /> | ||
{userIsAdmin && ( | ||
<Button | ||
sx={sx.adminButton} | ||
onClick={() => navigate("/admin")} | ||
data-testid="banner-admin-button" | ||
> | ||
Banner Editor | ||
</Button> | ||
)} | ||
</PageTemplate> | ||
); | ||
}; | ||
|
||
const sx = { | ||
layout: { | ||
".contentFlex": { | ||
marginTop: "3.5rem", | ||
marginBottom: "5rem !important", | ||
}, | ||
}, | ||
headerText: { | ||
marginBottom: "2rem", | ||
fontSize: "2rem", | ||
fontWeight: "normal", | ||
}, | ||
table: { | ||
marginTop: "2rem", | ||
maxWidth: "100%", | ||
"tr td:first-of-type": { | ||
width: "8rem", | ||
fontWeight: "semibold", | ||
}, | ||
td: { | ||
padding: "0.5rem", | ||
}, | ||
}, | ||
adminButton: { | ||
marginTop: "2rem", | ||
}, | ||
}; |
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,36 @@ | ||
import { render, screen } from "@testing-library/react"; | ||
import { axe } from "jest-axe"; | ||
// utils | ||
import { RouterWrappedComponent } from "utils/testing/setupJest"; | ||
//components | ||
import { Table } from "components"; | ||
|
||
const tableContent = { | ||
caption: "mock caption", | ||
headRow: ["mock header 1", "mock header 2", "mock header 3"], | ||
bodyRows: [], | ||
}; | ||
|
||
const tableComponent = ( | ||
<RouterWrappedComponent> | ||
<Table content={tableContent} variant="striped" /> | ||
</RouterWrappedComponent> | ||
); | ||
|
||
describe("Test Table", () => { | ||
beforeEach(() => { | ||
render(tableComponent); | ||
}); | ||
|
||
test("Table is visible", () => { | ||
expect(screen.getByRole("table")).toBeVisible(); | ||
}); | ||
}); | ||
|
||
describe("Test Table accessibility", () => { | ||
it("Should not have basic accessibility issues", async () => { | ||
const { container } = render(tableComponent); | ||
const results = await axe(container); | ||
expect(results).toHaveNoViolations(); | ||
}); | ||
}); |
Oops, something went wrong.