Skip to content

Commit e8854de

Browse files
committed
Add accessibility tests to the frontend component.
Closes #2934.
1 parent c86a33b commit e8854de

File tree

73 files changed

+1656
-1029
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

73 files changed

+1656
-1029
lines changed

components/frontend/package-lock.json

Lines changed: 180 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

components/frontend/package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,8 @@
6767
"eslint-plugin-react": "^7.37.4",
6868
"eslint-plugin-simple-import-sort": "^12.1.1",
6969
"globals": "^15.14.0",
70+
"jest": "^27.5.1",
71+
"jest-axe": "^9.0.0",
7072
"prettier": "^3.4.2",
7173
"react-scripts": "5.0.1"
7274
},

components/frontend/src/App.test.js

Lines changed: 29 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import history from "history/browser"
55
import * as auth from "./api/auth"
66
import * as fetch_server_api from "./api/fetch_server_api"
77
import App from "./App"
8+
import { expectNoAccessibilityViolations } from "./testUtils"
89
import * as toast from "./widgets/toast"
910

1011
function set_user_in_local_storage(session_expiration_datetime, email) {
@@ -32,46 +33,53 @@ afterEach(() => {
3233
})
3334

3435
it("shows spinner", async () => {
35-
render(<App />)
36+
const { container } = render(<App />)
3637
expect(screen.getAllByLabelText(/Loading/).length).toBe(1)
38+
await expectNoAccessibilityViolations(container)
3739
})
3840

39-
it("sets the user from local storage", () => {
41+
it("sets the user from local storage", async () => {
4042
set_user_in_local_storage("3000-02-23T22:00:50.945Z")
41-
render(<App />)
43+
const { container } = render(<App />)
4244
expect(screen.getAllByText(/admin/).length).toBe(1)
4345
expect(screen.getAllByAltText(/Avatar for admin/).length).toBe(1)
46+
await expectNoAccessibilityViolations(container)
4447
})
4548

46-
it("does not set invalid email addresses", () => {
49+
it("does not set invalid email addresses", async () => {
4750
set_user_in_local_storage("3000-02-23T22:00:50.945Z", "admin at example.org")
48-
render(<App />)
51+
const { container } = render(<App />)
4952
expect(screen.getAllByText(/admin/).length).toBe(1)
5053
expect(screen.queryAllByAltText(/Avatar for admin/).length).toBe(0)
54+
await expectNoAccessibilityViolations(container)
5155
})
5256

53-
it("resets the user when the session is expired on mount", () => {
57+
it("resets the user when the session is expired on mount", async () => {
5458
set_user_in_local_storage("2000-02-23T22:00:50.945Z")
55-
render(<App />)
59+
const { container } = render(<App />)
5660
expect(screen.queryAllByText(/admin/).length).toBe(0)
61+
await expectNoAccessibilityViolations(container)
5762
})
5863

5964
it("resets the user when the user clicks logout", async () => {
6065
set_user_in_local_storage("3000-02-23T22:00:50.945Z")
6166
auth.logout = jest.fn().mockResolvedValue({ ok: true })
62-
render(<App />)
67+
const { container } = render(<App />)
6368
await act(async () => {
6469
fireEvent.click(screen.getByText(/admin/))
70+
await expectNoAccessibilityViolations(container)
6571
})
6672
await act(async () => {
6773
fireEvent.click(screen.getByText(/Logout/))
6874
})
6975
expect(screen.queryAllByText(/admin/).length).toBe(0)
76+
await expectNoAccessibilityViolations(container)
7077
})
7178

72-
async function selectDate() {
79+
async function selectDate(container) {
7380
await act(async () => {
7481
fireEvent.click(screen.getByLabelText("Report date"))
82+
await expectNoAccessibilityViolations(container)
7583
})
7684
await act(async () => {
7785
fireEvent.click(screen.getByRole("button", { name: "Previous month" }))
@@ -82,37 +90,42 @@ async function selectDate() {
8290
}
8391

8492
it("handles a date change", async () => {
85-
render(<App />)
86-
await selectDate()
93+
const { container } = render(<App />)
94+
await selectDate(container)
8795
const expectedDate = dayjs().subtract(1, "month").date(15).toDate().toDateString()
8896
expect(screen.getByLabelText("Report date").textContent).toMatch(expectedDate)
97+
await expectNoAccessibilityViolations(container)
8998
})
9099

91100
it("handles a date change between two dates in the past", async () => {
92101
history.push("/?report_date=2022-03-13")
93-
render(<App />)
94-
await selectDate()
102+
const { container } = render(<App />)
103+
await selectDate(container)
95104
const expectedDate = dayjs().subtract(1, "month").date(15).toDate().toDateString()
96105
expect(screen.getByLabelText("Report date").textContent).toMatch(expectedDate)
106+
await expectNoAccessibilityViolations(container)
97107
})
98108

99-
it("reads the report date query parameter", () => {
109+
it("reads the report date query parameter", async () => {
100110
history.push("/?report_date=2020-03-13")
101-
render(<App />)
111+
const { container } = render(<App />)
102112
const expectedDate = dayjs("2020-03-13").toDate().toDateString()
103113
expect(screen.getByLabelText("Report date").textContent).toMatch(expectedDate)
114+
await expectNoAccessibilityViolations(container)
104115
})
105116

106117
it("handles a date reset", async () => {
107118
history.push("/?report_date=2020-03-13")
108-
render(<App />)
119+
const { container } = render(<App />)
109120
await act(async () => {
110121
fireEvent.click(screen.getByLabelText("Report date"))
122+
await expectNoAccessibilityViolations(container)
111123
})
112124
await act(async () => {
113125
fireEvent.click(screen.getByRole("button", { name: "Today" }))
114126
})
115127
expect(screen.getByLabelText("Report date").textContent).toMatch(/today/)
128+
await expectNoAccessibilityViolations(container)
116129
})
117130

118131
it("handles the nr of measurements event source", async () => {

0 commit comments

Comments
 (0)