-
Notifications
You must be signed in to change notification settings - Fork 118
Expand file tree
/
Copy patha11y-question-inputs.spec.ts
More file actions
264 lines (209 loc) Β· 8.55 KB
/
a11y-question-inputs.spec.ts
File metadata and controls
264 lines (209 loc) Β· 8.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
/**
* SPDX-FileCopyrightText: 2026 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
import { expect, mergeTests } from '@playwright/test'
import { test as formTest } from '../support/fixtures/form.ts'
import { test as appNavigationTest } from '../support/fixtures/navigation.ts'
import { test as randomUserTest } from '../support/fixtures/random-user.ts'
import { test as topBarTest } from '../support/fixtures/topBar.ts'
import { QuestionType } from '../support/sections/QuestionType.ts'
import { FormsView } from '../support/sections/TopBarSection.ts'
const test = mergeTests(randomUserTest, appNavigationTest, formTest, topBarTest)
test.beforeEach(async ({ page }) => {
await page.goto('apps/forms', { waitUntil: 'networkidle' })
await page.waitForURL(/apps\/forms\/$/)
})
test.describe('Accessibility: aria attributes on question inputs', () => {
test('Short answer with description has aria-labelledby and aria-describedby', async ({
appNavigation,
form,
topBar,
page,
}) => {
await appNavigation.clickNewForm()
await form.fillTitle('Test form')
await form.addQuestion(QuestionType.ShortAnswer)
const questions = await form.getQuestions()
await questions[0].fillTitle('My question')
await questions[0].fillDescription('Some context')
await topBar.toggleView(FormsView.View)
const question = page.getByRole('listitem', { name: /Question number 1/ })
const input = question.getByRole('textbox')
await expect(input).toHaveAttribute('aria-labelledby', 'q1_title')
await expect(input).toHaveAttribute('aria-describedby', 'q1_desc')
await expect(page.getByRole('heading', { name: 'My question' })).toHaveId(
'q1_title',
)
await expect(page.locator('#q1_desc')).toContainText('Some context')
})
test('Short answer without description has aria-labelledby but no aria-describedby', async ({
appNavigation,
form,
topBar,
page,
}) => {
await appNavigation.clickNewForm()
await form.fillTitle('Test form')
await form.addQuestion(QuestionType.ShortAnswer)
const questions = await form.getQuestions()
await questions[0].fillTitle('My question')
await topBar.toggleView(FormsView.View)
const question = page.getByRole('listitem', { name: /Question number 1/ })
const input = question.getByRole('textbox')
await expect(input).toHaveAttribute('aria-labelledby', 'q1_title')
await expect(input).not.toHaveAttribute('aria-describedby')
})
test('Checkboxes fieldset with description has aria-labelledby and aria-describedby', async ({
appNavigation,
form,
topBar,
page,
}) => {
await appNavigation.clickNewForm()
await form.fillTitle('Test form')
await form.addQuestion(QuestionType.Checkboxes)
const questions = await form.getQuestions()
await questions[0].fillTitle('My checkbox question')
await questions[0].fillDescription('Pick one or more')
await questions[0].addAnswer('Option 1')
await topBar.toggleView(FormsView.View)
const question = page.getByRole('listitem', { name: /Question number 1/ })
const fieldset = question.getByRole('group').first()
await expect(fieldset).toHaveAttribute('aria-labelledby', 'q1_title')
await expect(fieldset).toHaveAttribute('aria-describedby', 'q1_desc')
})
test('Long answer with description has aria-labelledby and aria-describedby', async ({
appNavigation,
form,
topBar,
page,
}) => {
await appNavigation.clickNewForm()
await form.fillTitle('Test form')
await form.addQuestion(QuestionType.LongAnswer)
const questions = await form.getQuestions()
await questions[0].fillTitle('My long question')
await questions[0].fillDescription('Please elaborate')
await topBar.toggleView(FormsView.View)
const question = page.getByRole('listitem', { name: /Question number 1/ })
const textarea = question.getByRole('textbox')
await expect(textarea).toHaveAttribute('aria-labelledby', 'q1_title')
await expect(textarea).toHaveAttribute('aria-describedby', 'q1_desc')
await expect(
page.getByRole('heading', { name: 'My long question' }),
).toHaveId('q1_title')
await expect(page.locator('#q1_desc')).toContainText('Please elaborate')
})
test('Dropdown with description has aria-describedby', async ({
appNavigation,
form,
topBar,
page,
}) => {
await appNavigation.clickNewForm()
await form.fillTitle('Test form')
await form.addQuestion(QuestionType.Dropdown)
const questions = await form.getQuestions()
await questions[0].fillTitle('My dropdown question')
await questions[0].fillDescription('Choose an option')
await questions[0].addAnswer('Option 1')
await topBar.toggleView(FormsView.View)
const question = page.getByRole('listitem', { name: /Question number 1/ })
const group = question.getByRole('group').first()
await expect(group).toHaveAttribute('aria-labelledby', 'q1_title')
await expect(group).toHaveAttribute('aria-describedby', 'q1_desc')
await expect(
page.getByRole('heading', { name: 'My dropdown question' }),
).toHaveId('q1_title')
await expect(page.locator('#q1_desc')).toContainText('Choose an option')
})
test('Date question with description has aria-labelledby and aria-describedby', async ({
appNavigation,
form,
topBar,
page,
}) => {
await appNavigation.clickNewForm()
await form.fillTitle('Test form')
await form.addQuestion(QuestionType.Date)
const questions = await form.getQuestions()
await questions[0].fillTitle('My date question')
await questions[0].fillDescription('Pick a date')
await topBar.toggleView(FormsView.View)
const question = page.getByRole('listitem', { name: /Question number 1/ })
const group = question.getByRole('group').first()
await expect(group).toHaveAttribute('aria-labelledby', 'q1_title')
await expect(group).toHaveAttribute('aria-describedby', 'q1_desc')
await expect(
page.getByRole('heading', { name: 'My date question' }),
).toHaveId('q1_title')
await expect(page.locator('#q1_desc')).toContainText('Pick a date')
})
test('Linear scale question with description has aria-labelledby and aria-describedby', async ({
appNavigation,
form,
topBar,
page,
}) => {
await appNavigation.clickNewForm()
await form.fillTitle('Test form')
await form.addQuestion(QuestionType.LinearScale)
const questions = await form.getQuestions()
await questions[0].fillTitle('Rate your experience')
await questions[0].fillDescription('From 1 to 5')
await topBar.toggleView(FormsView.View)
const question = page.getByRole('listitem', { name: /Question number 1/ })
const fieldset = question.getByRole('group').first()
await expect(fieldset).toHaveAttribute('aria-labelledby', 'q1_title')
await expect(fieldset).toHaveAttribute('aria-describedby', 'q1_desc')
await expect(
page.getByRole('heading', { name: 'Rate your experience' }),
).toHaveId('q1_title')
await expect(page.locator('#q1_desc')).toContainText('From 1 to 5')
})
test('File question with description has aria-labelledby and aria-describedby', async ({
appNavigation,
form,
topBar,
page,
}) => {
await appNavigation.clickNewForm()
await form.fillTitle('Test form')
await form.addQuestion(QuestionType.File)
const questions = await form.getQuestions()
await questions[0].fillTitle('My file question')
await questions[0].fillDescription('Upload your file')
await topBar.toggleView(FormsView.View)
const question = page.getByRole('listitem', { name: /Question number 1/ })
const group = question.getByRole('group').first()
await expect(group).toHaveAttribute('aria-labelledby', 'q1_title')
await expect(group).toHaveAttribute('aria-describedby', 'q1_desc')
await expect(
page.getByRole('heading', { name: 'My file question' }),
).toHaveId('q1_title')
await expect(page.locator('#q1_desc')).toContainText('Upload your file')
})
test('Color question with description has aria-labelledby and aria-describedby', async ({
appNavigation,
form,
topBar,
page,
}) => {
await appNavigation.clickNewForm()
await form.fillTitle('Test form')
await form.addQuestion(QuestionType.Color)
const questions = await form.getQuestions()
await questions[0].fillTitle('My color question')
await questions[0].fillDescription('Pick a color')
await topBar.toggleView(FormsView.View)
const question = page.getByRole('listitem', { name: /Question number 1/ })
const group = question.getByRole('group').first()
await expect(group).toHaveAttribute('aria-labelledby', 'q1_title')
await expect(group).toHaveAttribute('aria-describedby', 'q1_desc')
await expect(
page.getByRole('heading', { name: 'My color question' }),
).toHaveId('q1_title')
await expect(page.locator('#q1_desc')).toContainText('Pick a color')
})
})