|
| 1 | +import { Locator, test } from '@playwright/test' |
| 2 | +import { Context } from '../../Context.ts' |
| 3 | +import { initializePage } from '../../utils/initializePage.ts' |
| 4 | +import { pushState } from '../../utils/historyState.ts' |
| 5 | + |
| 6 | +const a11yPort = '7174' |
| 7 | +const a11yBaseUrl = `http://localhost:${a11yPort}` // accessible data team |
| 8 | +const satisfactionSurveyId = '3BBFzJneqakYoyDu02c2' |
| 9 | +const mainPath = 'docs/app/survey/how-to' |
| 10 | + |
| 11 | +let locator: Locator |
| 12 | + |
| 13 | +test.describe('Survey Accessibility How-To', async () => { |
| 14 | + test('How to add an accessibility menu', async ({ page }) => { |
| 15 | + |
| 16 | + const context = new Context(mainPath, page) |
| 17 | + context.setName('adding-accessibility-menu') |
| 18 | + await initializePage(page, a11yBaseUrl, `/s/edit/survey/${satisfactionSurveyId}/build/compose`) |
| 19 | + |
| 20 | + // ## Adding accessibility menu |
| 21 | + await page.locator('vaadin-grid-tree-toggle > span:nth-child(2)').first().click() |
| 22 | + await page.locator('vaadin-grid-cell-content').filter({ hasText: 'intro 3' }).click() |
| 23 | + |
| 24 | + // ### Step 1: Focus on mardown editor, for instance in the survey introduction |
| 25 | + // add a `<a11y-menu></a11y-menu>` tag in the markdown content to activate the accessibility menu for this item |
| 26 | + |
| 27 | + await page.waitForTimeout(1000) |
| 28 | + locator = page.locator('textarea') |
| 29 | + await context.annotatedScreenshot(locator, 'step-1-focus-on-mardown-editor') |
| 30 | + await locator.click() |
| 31 | + |
| 32 | + |
| 33 | + // ### Step 2: Preview how the accessibility menu will look like for the respondents by clicking on the field "Preview" tab |
| 34 | + |
| 35 | + await page.locator('md-secondary-tab:nth-child(2) > .button > .content').click() |
| 36 | + locator = page.locator('#markdown') |
| 37 | + await context.annotatedScreenshot(locator, 'step-2-preview-accessibility-menu') |
| 38 | + |
| 39 | + }) |
| 40 | + |
| 41 | + |
| 42 | + test('How to activate accessibility modes', async ({ page }) => { |
| 43 | + |
| 44 | + const context = new Context(mainPath, page) |
| 45 | + context.setName('activating-accessibility-modes') |
| 46 | + await initializePage(page, a11yBaseUrl, `/s/edit/survey/${satisfactionSurveyId}/build/behavior`) |
| 47 | + |
| 48 | + // ### Step 1: Navigate to Behavior |
| 49 | + locator = page.getByTestId('page-drawer-menu') |
| 50 | + await context.annotatedScreenshot(locator, 'step-1-navigate-to-form-behaviour') |
| 51 | + |
| 52 | + // Step 2: Enable different accessibility modes |
| 53 | + locator = page.getByRole('listbox', { name: 'Modes Activated' }) |
| 54 | + await context.annotatedScreenshot(locator, 'step-2-form-behaviour') |
| 55 | + |
| 56 | + // Step 3: got back to compose mode and Toggle between the different accessibility modes |
| 57 | + return |
| 58 | + }) |
| 59 | + |
| 60 | + test('How to use Easy Read', async ({ page }) => { |
| 61 | + |
| 62 | + const context = new Context(mainPath, page) |
| 63 | + context.setName('use-easy-read') |
| 64 | + await initializePage(page, a11yBaseUrl, `/s/edit/survey/${satisfactionSurveyId}/build/behavior`) |
| 65 | + |
| 66 | + // ### Step 1: easyread must be enabled in the survey |
| 67 | + context.setName('use-easy-read') |
| 68 | + locator = page.getByRole('listbox', { name: 'Modes Activated' }) |
| 69 | + await context.annotatedScreenshot(locator, 'step-1-easyread-mode-not-activated') |
| 70 | + |
| 71 | + |
| 72 | + // ### Step 2: Activate easyread mode |
| 73 | + await pushState(page, 'compose') |
| 74 | + await page.waitForTimeout(1000) |
| 75 | + locator = page.getByRole('button', { name: 'Easy Read Mode' }) |
| 76 | + await context.annotatedScreenshot(locator, 'step-2-activate-easyread-mode') |
| 77 | + await locator.click() |
| 78 | + |
| 79 | + // ### Step 3: Navigate through the form and add easyread content (e.g. images) when relevant |
| 80 | + await page.getByText('Survey habits', { exact: true }).click() |
| 81 | + await page.getByText('Section 1').click() |
| 82 | + await page.getByText('How many surveys do you run').click() |
| 83 | + await page.waitForTimeout(1500) |
| 84 | + |
| 85 | + locator = page.locator('vaadin-split-layout div').filter({ hasText: 'How many surveys do you run in a typical year? Add Media for Easyread Mode' }) |
| 86 | + |
| 87 | + await context.annotatedScreenshot(locator, 'step-3-add-media-for-easyread-mode') |
| 88 | + |
| 89 | + // items with easyread content have a specific icon in the tree view to easily identify them |
| 90 | + locator = page.locator('vaadin-split-layout div').filter({ hasText: 'Overall Structure Introduction Page Form Survey habits Section 1 Page 1 intro' }) |
| 91 | + await context.annotatedScreenshot(locator, 'step-3-easyread-content-icon') |
| 92 | + |
| 93 | + // ### Step 4 (Optional): amend / simplify the text of the questions and answer options to make them easier to understand for people with cognitive disabilities |
| 94 | + // best practices is to use plain language for all content. |
| 95 | + |
| 96 | + locator = page.getByText('sentiment_neutral sentiment_satisfied label label easyread version for "label"') |
| 97 | + await context.annotatedScreenshot(locator, 'step-4-easyread-version-for-label') |
| 98 | + |
| 99 | + // ### Step 5 (Optional): make some part of the content visible od hidden only for the easy read mode |
| 100 | + // activate the visibility mode |
| 101 | + locator = page.getByRole('button', { name: 'Visibility Mode' }) |
| 102 | + await context.annotatedScreenshot(locator, 'step-5-activate-visibility-mode') |
| 103 | + await locator.click() |
| 104 | + |
| 105 | + // activate the advanced mode |
| 106 | + locator = page.getByText('toggle advanced mode Advanced') |
| 107 | + await context.annotatedScreenshot(locator, 'step-5-toggle-advanced-mode') |
| 108 | + await locator.click() |
| 109 | + |
| 110 | + // activate the easyread-only visibility for a specific field |
| 111 | + locator = page.getByText('Make this field visible for') |
| 112 | + await context.annotatedScreenshot(locator, 'step-5-easyread-only-visibility') |
| 113 | + await locator.click() |
| 114 | + |
| 115 | + |
| 116 | + }) |
| 117 | + |
| 118 | + test('How to use Sign Language', async ({ page }) => { |
| 119 | + |
| 120 | + const context = new Context(mainPath, page) |
| 121 | + context.setName('use-sign-language') |
| 122 | + await initializePage(page, a11yBaseUrl, `/s/edit/survey/${satisfactionSurveyId}/build/behavior`) |
| 123 | + |
| 124 | + // ### Step 1: sign language must be enabled in the survey |
| 125 | + context.setName('use-sign-language') |
| 126 | + locator = page.getByRole('listbox', { name: 'Modes Activated' }) |
| 127 | + await context.annotatedScreenshot(locator, 'step-1-sign-language-mode-not-activated') |
| 128 | + |
| 129 | + |
| 130 | + // ### Step 2: Activate sign language mode |
| 131 | + await pushState(page, 'compose') |
| 132 | + await page.waitForTimeout(1000) |
| 133 | + locator = page.getByRole('button', { name: 'Sign Language Mode' }) |
| 134 | + await context.annotatedScreenshot(locator, 'step-2-activate-sign-language-mode') |
| 135 | + await locator.click() |
| 136 | + |
| 137 | + // ### Step 3: Navigate through the form and add sign language content (e.g. videos) when relevant |
| 138 | + |
| 139 | + await page.getByText('Survey habits', { exact: true }).click() |
| 140 | + await page.getByText('Section 1').click() |
| 141 | + await page.getByText('How many surveys do you run').click() |
| 142 | + await page.waitForTimeout(1000) |
| 143 | + |
| 144 | + |
| 145 | + locator = page.locator('vaadin-split-layout div').filter({ hasText: 'How many surveys do you run in a typical year? Add a Sign Language Video' }) |
| 146 | + |
| 147 | + await context.annotatedScreenshot(locator, 'step-3-add-media-for-sign-language-mode') |
| 148 | + |
| 149 | + // set videoId - which is the youtube videoId |
| 150 | + |
| 151 | + locator = page.getByRole('textbox', { name: 'Enter a youtube video ID' }) |
| 152 | + await context.annotatedScreenshot(locator, 'step-3-set-video-id') |
| 153 | + |
| 154 | + // items with sign language content have a specific icon in the tree view to easily identify them |
| 155 | + locator = page.locator('vaadin-split-layout div').filter({ hasText: 'Overall Structure Introduction Page Form Survey habits Section 1 Page 1 intro' }) |
| 156 | + await context.annotatedScreenshot(locator, 'step-3-sign-language-content-icon') |
| 157 | + |
| 158 | + // ### Step 4 (Advanced): make some part of the content visible or hidden only for the sign language mode |
| 159 | + // activate the visibility mode |
| 160 | + locator = page.getByRole('button', { name: 'Visibility Mode' }) |
| 161 | + await context.annotatedScreenshot(locator, 'step-4-activate-visibility-mode') |
| 162 | + await locator.click() |
| 163 | + |
| 164 | + // activate the advanced mode |
| 165 | + locator = page.getByText('toggle advanced mode Advanced') |
| 166 | + await context.annotatedScreenshot(locator, 'step-4-toggle-advanced-mode') |
| 167 | + await locator.click() |
| 168 | + |
| 169 | + // activate the sign language-only visibility for a specific field |
| 170 | + locator = page.getByText('Make this field visible for') |
| 171 | + await context.annotatedScreenshot(locator, 'step-4-sign-language-only-visibility') |
| 172 | + await locator.click() |
| 173 | + |
| 174 | + }) |
| 175 | + |
| 176 | + test('How to use tooltips', async ({ page }) => { |
| 177 | + const context = new Context(mainPath, page) |
| 178 | + context.setName('use-tooltips') |
| 179 | + await initializePage(page, a11yBaseUrl, `/s/edit/survey/${satisfactionSurveyId}/build/compose`) |
| 180 | + |
| 181 | + // ### Step 1: Simple tooltips (via editor) |
| 182 | + // limitations: can only be used once - difficult to handle localization |
| 183 | + await page.locator('vaadin-grid-tree-toggle > span:nth-child(2)').first().click() |
| 184 | + await page.locator('vaadin-grid-cell-content').filter({ hasText: 'intro 3' }).click() |
| 185 | + |
| 186 | + // ### Step 1: Focus on markdown editor, for instance in the survey introduction |
| 187 | + // add a `<a11y-menu></a11y-menu>` tag in the markdown content to activate the accessibility menu for this item |
| 188 | + await page.waitForTimeout(1000) |
| 189 | + |
| 190 | + await page.getByRole('button', { name: 'add Content', exact: true }).click() |
| 191 | + locator = page.locator('#add-content-menu').getByText('Tooltip', { exact: true }) |
| 192 | + await context.annotatedScreenshot(locator, 'step-1-add-tooltip-via-editor') |
| 193 | + await locator.click() |
| 194 | + |
| 195 | + locator = page.locator('textarea') |
| 196 | + await locator.press('Home') |
| 197 | + await locator.press('Shift+ArrowDown') |
| 198 | + await locator.fill('This would be a tooltip: \n\n <lapp-tooltip term="tootipId" >Tooltip Content</lapp-tooltip>\n') |
| 199 | + |
| 200 | + locator = page.locator('textarea') |
| 201 | + await context.annotatedScreenshot(locator, 'step-1-tooltip-in-markdown-editor') |
| 202 | + await locator.fill('This survey supports a number of accessibility options which can be turned on and off from the menu below.\n\n<a11y-menu ></a11y-menu>\n') |
| 203 | + |
| 204 | + // ### Step 2: create a new term definition |
| 205 | + locator = page.locator('vaadin-grid-cell-content').filter({ hasText: 'Glossary' }) |
| 206 | + await context.annotatedScreenshot(locator, 'step-2-glossary-in-tree-view') |
| 207 | + await locator.click() |
| 208 | + |
| 209 | + locator = page.getByRole('button', { name: 'Add a new Glossary Item' }) |
| 210 | + await context.annotatedScreenshot(locator, 'step-2-add-new-glossary-item') |
| 211 | + await locator.click() |
| 212 | + |
| 213 | + // give a name and a definition |
| 214 | + locator = page.locator('lapp-dialog').getByText('Add a new Glossary Item') |
| 215 | + await context.annotatedScreenshot(locator, 'step-2-add-new-glossary-item-dialog') |
| 216 | + await locator.click() |
| 217 | + |
| 218 | + // ### Step 3: Use the definition |
| 219 | + // reuse the name for the tooltip content and see the definition in the tooltip when hovering over the term in the form |
| 220 | + // <lapp-tooltip term="name" ></lapp-tooltip> |
| 221 | + |
| 222 | + }) |
| 223 | +}) |
0 commit comments