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