|
| 1 | +/** |
| 2 | + * SPDX-FileCopyrightText: 2025 Nextcloud GmbH and Nextcloud contributors |
| 3 | + * SPDX-License-Identifier: AGPL-3.0-or-later |
| 4 | + */ |
| 5 | + |
| 6 | +import { mergeTests } from '@playwright/test' |
| 7 | +import { test as accessibilityTest, expect } from '../support/fixtures/accessibility' |
| 8 | +import { test as editorTest } from '../support/fixtures/editor' |
| 9 | +import { test as uploadFileTest } from '../support/fixtures/upload-file' |
| 10 | +import { |
| 11 | + formatViolations, |
| 12 | + getAccessibilitySummary, |
| 13 | +} from '../support/utils/accessibility' |
| 14 | + |
| 15 | +const test = mergeTests(accessibilityTest, editorTest, uploadFileTest) |
| 16 | + |
| 17 | +test.describe('Editor Accessibility', () => { |
| 18 | + test('should not have automatically detectable accessibility violations on the full page', async ({ |
| 19 | + page, |
| 20 | + open, |
| 21 | + makeAxeBuilder, |
| 22 | + }, testInfo) => { |
| 23 | + await open() |
| 24 | + |
| 25 | + // Wait for the editor to be fully loaded |
| 26 | + await page.waitForSelector('.text-editor', { state: 'visible' }) |
| 27 | + |
| 28 | + // Run the accessibility scan |
| 29 | + const accessibilityScanResults = await makeAxeBuilder().analyze() |
| 30 | + |
| 31 | + // Attach the full scan results for debugging |
| 32 | + await testInfo.attach('accessibility-scan-results', { |
| 33 | + body: JSON.stringify(accessibilityScanResults, null, 2), |
| 34 | + contentType: 'application/json', |
| 35 | + }) |
| 36 | + |
| 37 | + // Attach a summary for quick overview |
| 38 | + const summary = getAccessibilitySummary(accessibilityScanResults) |
| 39 | + await testInfo.attach('accessibility-summary', { |
| 40 | + body: JSON.stringify(summary, null, 2), |
| 41 | + contentType: 'application/json', |
| 42 | + }) |
| 43 | + |
| 44 | + // Expect no violations |
| 45 | + expect( |
| 46 | + accessibilityScanResults.violations, |
| 47 | + formatViolations(accessibilityScanResults), |
| 48 | + ).toEqual([]) |
| 49 | + }) |
| 50 | + |
| 51 | + test('should not have accessibility violations in the editor content area', async ({ |
| 52 | + page, |
| 53 | + open, |
| 54 | + makeAxeBuilder, |
| 55 | + editor, |
| 56 | + }, testInfo) => { |
| 57 | + await open() |
| 58 | + await editor.type('Test content') |
| 59 | + |
| 60 | + // Wait for the editor to be ready |
| 61 | + await page.waitForSelector('.text-editor', { state: 'visible' }) |
| 62 | + |
| 63 | + // Scan only the editor content area |
| 64 | + const accessibilityScanResults = await makeAxeBuilder() |
| 65 | + .include('.text-editor') |
| 66 | + .analyze() |
| 67 | + |
| 68 | + await testInfo.attach('editor-content-scan-results', { |
| 69 | + body: JSON.stringify(accessibilityScanResults, null, 2), |
| 70 | + contentType: 'application/json', |
| 71 | + }) |
| 72 | + |
| 73 | + expect( |
| 74 | + accessibilityScanResults.violations, |
| 75 | + formatViolations(accessibilityScanResults), |
| 76 | + ).toEqual([]) |
| 77 | + }) |
| 78 | + |
| 79 | + test('should not have accessibility violations in the menu bar', async ({ |
| 80 | + page, |
| 81 | + open, |
| 82 | + makeAxeBuilder, |
| 83 | + }, testInfo) => { |
| 84 | + await open() |
| 85 | + |
| 86 | + // Wait for the menu bar to be visible |
| 87 | + await page.waitForSelector('.text-menubar', { state: 'visible' }) |
| 88 | + |
| 89 | + // Scan only the menu bar |
| 90 | + const accessibilityScanResults = await makeAxeBuilder() |
| 91 | + .include('.text-menubar') |
| 92 | + .analyze() |
| 93 | + |
| 94 | + await testInfo.attach('menubar-scan-results', { |
| 95 | + body: JSON.stringify(accessibilityScanResults, null, 2), |
| 96 | + contentType: 'application/json', |
| 97 | + }) |
| 98 | + |
| 99 | + expect( |
| 100 | + accessibilityScanResults.violations, |
| 101 | + formatViolations(accessibilityScanResults), |
| 102 | + ).toEqual([]) |
| 103 | + }) |
| 104 | + |
| 105 | + test('should have proper keyboard navigation support', async ({ |
| 106 | + page, |
| 107 | + open, |
| 108 | + makeAxeBuilder, |
| 109 | + }, testInfo) => { |
| 110 | + await open() |
| 111 | + |
| 112 | + // Wait for the editor to be fully loaded |
| 113 | + await page.waitForSelector('.text-editor', { state: 'visible' }) |
| 114 | + |
| 115 | + // Check for keyboard-specific accessibility issues |
| 116 | + const accessibilityScanResults = await makeAxeBuilder() |
| 117 | + // Focus on keyboard accessibility rules (WCAG only, not best-practice) |
| 118 | + .withTags(['wcag2a', 'wcag2aa', 'wcag21a', 'wcag21aa']) |
| 119 | + .analyze() |
| 120 | + |
| 121 | + await testInfo.attach('keyboard-navigation-scan-results', { |
| 122 | + body: JSON.stringify(accessibilityScanResults, null, 2), |
| 123 | + contentType: 'application/json', |
| 124 | + }) |
| 125 | + |
| 126 | + // Check that interactive elements are keyboard accessible |
| 127 | + expect( |
| 128 | + accessibilityScanResults.violations, |
| 129 | + formatViolations(accessibilityScanResults), |
| 130 | + ).toEqual([]) |
| 131 | + }) |
| 132 | + |
| 133 | + test('should have proper ARIA labels on interactive elements', async ({ |
| 134 | + page, |
| 135 | + open, |
| 136 | + makeAxeBuilder, |
| 137 | + editor, |
| 138 | + }, testInfo) => { |
| 139 | + await open() |
| 140 | + |
| 141 | + // Open a menu to check its accessibility |
| 142 | + const boldButton = editor.getMenu('Bold') |
| 143 | + await expect(boldButton).toBeVisible() |
| 144 | + |
| 145 | + // Wait for all menu items to be rendered |
| 146 | + await page.waitForSelector('[role="button"], button', { state: 'attached' }) |
| 147 | + |
| 148 | + // Scan for ARIA-related issues |
| 149 | + const accessibilityScanResults = await makeAxeBuilder() |
| 150 | + .withTags(['wcag2a', 'wcag2aa', 'wcag21a', 'wcag21aa']) |
| 151 | + .analyze() |
| 152 | + |
| 153 | + await testInfo.attach('aria-labels-scan-results', { |
| 154 | + body: JSON.stringify(accessibilityScanResults, null, 2), |
| 155 | + contentType: 'application/json', |
| 156 | + }) |
| 157 | + |
| 158 | + expect( |
| 159 | + accessibilityScanResults.violations, |
| 160 | + formatViolations(accessibilityScanResults), |
| 161 | + ).toEqual([]) |
| 162 | + }) |
| 163 | + |
| 164 | + test('should maintain accessibility after text formatting', async ({ |
| 165 | + page, |
| 166 | + open, |
| 167 | + makeAxeBuilder, |
| 168 | + editor, |
| 169 | + }, testInfo) => { |
| 170 | + await open() |
| 171 | + |
| 172 | + // Type some text and format it |
| 173 | + await editor.type('Format me') |
| 174 | + const CtrlOrCmd = process.platform === 'darwin' ? 'Meta' : 'Control' |
| 175 | + await editor.content.press(CtrlOrCmd + '+a') |
| 176 | + await editor.getMenu('Bold').click() |
| 177 | + await editor.getMenu('Italic').click() |
| 178 | + |
| 179 | + // Wait for formatting to be applied |
| 180 | + await page.waitForSelector('strong', { state: 'attached' }) |
| 181 | + await page.waitForSelector('em', { state: 'attached' }) |
| 182 | + |
| 183 | + // Scan after formatting operations |
| 184 | + const accessibilityScanResults = await makeAxeBuilder() |
| 185 | + .include('.text-editor') |
| 186 | + .analyze() |
| 187 | + |
| 188 | + await testInfo.attach('formatted-content-scan-results', { |
| 189 | + body: JSON.stringify(accessibilityScanResults, null, 2), |
| 190 | + contentType: 'application/json', |
| 191 | + }) |
| 192 | + |
| 193 | + expect( |
| 194 | + accessibilityScanResults.violations, |
| 195 | + formatViolations(accessibilityScanResults), |
| 196 | + ).toEqual([]) |
| 197 | + }) |
| 198 | +}) |
0 commit comments