@@ -5,6 +5,7 @@ import history from "history/browser"
5
5
import * as auth from "./api/auth"
6
6
import * as fetch_server_api from "./api/fetch_server_api"
7
7
import App from "./App"
8
+ import { expectNoAccessibilityViolations } from "./testUtils"
8
9
import * as toast from "./widgets/toast"
9
10
10
11
function set_user_in_local_storage ( session_expiration_datetime , email ) {
@@ -32,46 +33,53 @@ afterEach(() => {
32
33
} )
33
34
34
35
it ( "shows spinner" , async ( ) => {
35
- render ( < App /> )
36
+ const { container } = render ( < App /> )
36
37
expect ( screen . getAllByLabelText ( / L o a d i n g / ) . length ) . toBe ( 1 )
38
+ await expectNoAccessibilityViolations ( container )
37
39
} )
38
40
39
- it ( "sets the user from local storage" , ( ) => {
41
+ it ( "sets the user from local storage" , async ( ) => {
40
42
set_user_in_local_storage ( "3000-02-23T22:00:50.945Z" )
41
- render ( < App /> )
43
+ const { container } = render ( < App /> )
42
44
expect ( screen . getAllByText ( / a d m i n / ) . length ) . toBe ( 1 )
43
45
expect ( screen . getAllByAltText ( / A v a t a r f o r a d m i n / ) . length ) . toBe ( 1 )
46
+ await expectNoAccessibilityViolations ( container )
44
47
} )
45
48
46
- it ( "does not set invalid email addresses" , ( ) => {
49
+ it ( "does not set invalid email addresses" , async ( ) => {
47
50
set_user_in_local_storage ( "3000-02-23T22:00:50.945Z" , "admin at example.org" )
48
- render ( < App /> )
51
+ const { container } = render ( < App /> )
49
52
expect ( screen . getAllByText ( / a d m i n / ) . length ) . toBe ( 1 )
50
53
expect ( screen . queryAllByAltText ( / A v a t a r f o r a d m i n / ) . length ) . toBe ( 0 )
54
+ await expectNoAccessibilityViolations ( container )
51
55
} )
52
56
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 ( ) => {
54
58
set_user_in_local_storage ( "2000-02-23T22:00:50.945Z" )
55
- render ( < App /> )
59
+ const { container } = render ( < App /> )
56
60
expect ( screen . queryAllByText ( / a d m i n / ) . length ) . toBe ( 0 )
61
+ await expectNoAccessibilityViolations ( container )
57
62
} )
58
63
59
64
it ( "resets the user when the user clicks logout" , async ( ) => {
60
65
set_user_in_local_storage ( "3000-02-23T22:00:50.945Z" )
61
66
auth . logout = jest . fn ( ) . mockResolvedValue ( { ok : true } )
62
- render ( < App /> )
67
+ const { container } = render ( < App /> )
63
68
await act ( async ( ) => {
64
69
fireEvent . click ( screen . getByText ( / a d m i n / ) )
70
+ await expectNoAccessibilityViolations ( container )
65
71
} )
66
72
await act ( async ( ) => {
67
73
fireEvent . click ( screen . getByText ( / L o g o u t / ) )
68
74
} )
69
75
expect ( screen . queryAllByText ( / a d m i n / ) . length ) . toBe ( 0 )
76
+ await expectNoAccessibilityViolations ( container )
70
77
} )
71
78
72
- async function selectDate ( ) {
79
+ async function selectDate ( container ) {
73
80
await act ( async ( ) => {
74
81
fireEvent . click ( screen . getByLabelText ( "Report date" ) )
82
+ await expectNoAccessibilityViolations ( container )
75
83
} )
76
84
await act ( async ( ) => {
77
85
fireEvent . click ( screen . getByRole ( "button" , { name : "Previous month" } ) )
@@ -82,37 +90,42 @@ async function selectDate() {
82
90
}
83
91
84
92
it ( "handles a date change" , async ( ) => {
85
- render ( < App /> )
86
- await selectDate ( )
93
+ const { container } = render ( < App /> )
94
+ await selectDate ( container )
87
95
const expectedDate = dayjs ( ) . subtract ( 1 , "month" ) . date ( 15 ) . toDate ( ) . toDateString ( )
88
96
expect ( screen . getByLabelText ( "Report date" ) . textContent ) . toMatch ( expectedDate )
97
+ await expectNoAccessibilityViolations ( container )
89
98
} )
90
99
91
100
it ( "handles a date change between two dates in the past" , async ( ) => {
92
101
history . push ( "/?report_date=2022-03-13" )
93
- render ( < App /> )
94
- await selectDate ( )
102
+ const { container } = render ( < App /> )
103
+ await selectDate ( container )
95
104
const expectedDate = dayjs ( ) . subtract ( 1 , "month" ) . date ( 15 ) . toDate ( ) . toDateString ( )
96
105
expect ( screen . getByLabelText ( "Report date" ) . textContent ) . toMatch ( expectedDate )
106
+ await expectNoAccessibilityViolations ( container )
97
107
} )
98
108
99
- it ( "reads the report date query parameter" , ( ) => {
109
+ it ( "reads the report date query parameter" , async ( ) => {
100
110
history . push ( "/?report_date=2020-03-13" )
101
- render ( < App /> )
111
+ const { container } = render ( < App /> )
102
112
const expectedDate = dayjs ( "2020-03-13" ) . toDate ( ) . toDateString ( )
103
113
expect ( screen . getByLabelText ( "Report date" ) . textContent ) . toMatch ( expectedDate )
114
+ await expectNoAccessibilityViolations ( container )
104
115
} )
105
116
106
117
it ( "handles a date reset" , async ( ) => {
107
118
history . push ( "/?report_date=2020-03-13" )
108
- render ( < App /> )
119
+ const { container } = render ( < App /> )
109
120
await act ( async ( ) => {
110
121
fireEvent . click ( screen . getByLabelText ( "Report date" ) )
122
+ await expectNoAccessibilityViolations ( container )
111
123
} )
112
124
await act ( async ( ) => {
113
125
fireEvent . click ( screen . getByRole ( "button" , { name : "Today" } ) )
114
126
} )
115
127
expect ( screen . getByLabelText ( "Report date" ) . textContent ) . toMatch ( / t o d a y / )
128
+ await expectNoAccessibilityViolations ( container )
116
129
} )
117
130
118
131
it ( "handles the nr of measurements event source" , async ( ) => {
0 commit comments