generated from NHSDigital/nhs-notify-repository-template
-
Notifications
You must be signed in to change notification settings - Fork 1
CCM-12666: playwright accessibility tests #755
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
37f8596
CCM-12666: WIP - playwright accessibility tests
bhansell1 18d7ffa
CCM-12666: make tests run in the pipeline
bhansell1 0b9522e
Merge branch 'main' of https://github.com/NHSDigital/nhs-notify-web-t…
bhansell1 3444f25
CCM-12666: config
bhansell1 8c1c53e
CCM-12666: add specific accessibility issue to see tests fail in pipe…
bhansell1 5b20c6c
CCM-12666: add specific accessibility issue to see tests fail in pipe…
bhansell1 06a6290
CCM-12666: revert change
bhansell1 22c91cd
Merge branch 'main' of https://github.com/NHSDigital/nhs-notify-web-t…
bhansell1 faa6227
CCM-12666: add new tests for new pages
bhansell1 5bd23e6
Merge branch 'main' into feature/CCM-12666_playwright-accessibility
harrim91 7689797
Merge branch 'main' of https://github.com/NHSDigital/nhs-notify-web-t…
bhansell1 cf7f92c
CCM-12666: add wcag2aaa standard which includes the heading order vio…
bhansell1 8aee9e6
Merge branch 'feature/CCM-12666_playwright-accessibility' of https://…
bhansell1 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 2 additions & 0 deletions
2
frontend/src/components/forms/ChooseMessageOrder/ChooseMessageOrder.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| #!/bin/bash | ||
|
|
||
| set -euo pipefail | ||
| cd "$(git rev-parse --show-toplevel)" | ||
| npx playwright install --with-deps > /dev/null | ||
| cd tests/test-team | ||
| TEST_EXIT_CODE=0 | ||
| npm run test:accessibility || TEST_EXIT_CODE=$? | ||
| echo "TEST_EXIT_CODE=$TEST_EXIT_CODE" | ||
|
|
||
| mkdir -p ../acceptance-test-report | ||
| cp -r ./playwright-report ../acceptance-test-report | ||
| [[ -e test-results ]] && cp -r ./test-results ../acceptance-test-report | ||
|
|
||
| exit $TEST_EXIT_CODE |
56 changes: 56 additions & 0 deletions
56
tests/test-team/config/accessibility/accessibility.config.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,56 @@ | ||
| import path from 'node:path'; | ||
| import { defineConfig, devices } from '@playwright/test'; | ||
| import baseConfig from '../playwright.config'; | ||
|
|
||
| const buildCommand = [ | ||
| 'INCLUDE_AUTH_PAGES=true', | ||
| 'npm run build && npm run start', | ||
| ].join(' '); | ||
|
|
||
| export default defineConfig({ | ||
| ...baseConfig, | ||
| fullyParallel: true, | ||
| timeout: 60_000, // 30 seconds in the playwright default | ||
| expect: { | ||
| timeout: 10_000, // default is 5 seconds. After creating and previewing sometimes the load is slow on a cold start | ||
| }, | ||
| projects: [ | ||
| { | ||
| name: 'accessibility:setup', | ||
| testMatch: 'ui.setup.ts', | ||
| use: { | ||
| baseURL: 'http://localhost:3000', | ||
| ...devices['Desktop Chrome'], | ||
| headless: true, | ||
| screenshot: 'only-on-failure', | ||
| }, | ||
| }, | ||
| { | ||
| name: 'accessibility', | ||
| testMatch: '*.accessibility.spec.ts', | ||
| use: { | ||
| screenshot: 'only-on-failure', | ||
| baseURL: 'http://localhost:3000', | ||
| ...devices['Desktop Chrome'], | ||
| headless: true, | ||
| storageState: path.resolve(__dirname, '../.auth/user.json'), | ||
| }, | ||
| dependencies: ['accessibility:setup'], | ||
| teardown: 'accessibility:teardown', | ||
| }, | ||
| { | ||
| name: 'accessibility:teardown', | ||
| testMatch: 'ui.teardown.ts', | ||
| }, | ||
| ], | ||
| /* Run your local dev server before starting the tests */ | ||
| webServer: { | ||
| timeout: 4 * 60 * 1000, // 4 minutes | ||
| command: buildCommand, | ||
| cwd: path.resolve(__dirname, '../../../..'), | ||
| url: 'http://localhost:3000/templates/create-and-submit-templates', | ||
| reuseExistingServer: !process.env.CI, | ||
| stderr: 'pipe', | ||
| stdout: 'pipe', | ||
| }, | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,56 @@ | ||
| import { test as base, Page } from '@playwright/test'; | ||
| import AxeBuilder from '@axe-core/playwright'; | ||
| import { TemplateMgmtBasePage } from 'pages/template-mgmt-base-page'; | ||
| import { expect } from '@playwright/test'; | ||
|
|
||
| type Analyze = <T extends TemplateMgmtBasePage>( | ||
| page: T, | ||
| opts?: { | ||
| id?: string; | ||
| beforeAnalyze?: (page: T) => Promise<void>; | ||
| } | ||
| ) => Promise<void>; | ||
|
|
||
| type AccessibilityFixture = { | ||
| analyze: Analyze; | ||
| }; | ||
|
|
||
| const DISABLED_RULES = [ | ||
| /* We don't have control over NHS colours. | ||
| * Axe decides the page is 5.75 ratio and wcag2aaa expects 7:1 | ||
| */ | ||
| 'color-contrast-enhanced', | ||
| ]; | ||
|
|
||
| const makeAxeBuilder = (page: Page) => | ||
| new AxeBuilder({ page }) | ||
| .withTags(['wcag2a', 'wcag2aa', 'wcag2aaa']) | ||
bhansell1 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| .disableRules(DISABLED_RULES); | ||
|
|
||
| export const test = base.extend<AccessibilityFixture>({ | ||
| analyze: async ({ baseURL, page }, use) => { | ||
| const analyze: Analyze = async (pageUnderTest, opts) => { | ||
| const { id, beforeAnalyze } = opts ?? {}; | ||
|
|
||
| await pageUnderTest.loadPage(id); | ||
|
|
||
| if (beforeAnalyze) { | ||
| await beforeAnalyze(pageUnderTest); | ||
| } | ||
|
|
||
| const pageUrlSegment = ( | ||
| pageUnderTest.constructor as typeof TemplateMgmtBasePage | ||
| ).pageUrlSegment; | ||
|
|
||
| await expect(page).toHaveURL( | ||
| new RegExp(`${baseURL}/templates/${pageUrlSegment}(.*)`) // eslint-disable-line security/detect-non-literal-regexp | ||
| ); | ||
|
|
||
| const results = await makeAxeBuilder(page).analyze(); | ||
|
|
||
| expect(results.violations).toEqual([]); | ||
| }; | ||
|
|
||
| await use(analyze); | ||
| }, | ||
| }); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| export * from './campaign-id-required-page'; | ||
| export * from './choose-message-order-page'; | ||
| export * from './choose-templates-page'; | ||
| export * from './create-message-plan-page'; | ||
| export * from './message-plans-page'; | ||
| export * from './invalid-message-plan-page'; |
127 changes: 127 additions & 0 deletions
127
tests/test-team/template-mgmt-accessibility/routing.accessibility.spec.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,127 @@ | ||
| import { | ||
| createAuthHelper, | ||
| TestUser, | ||
| testUsers, | ||
| } from 'helpers/auth/cognito-auth-helper'; | ||
| import { RoutingConfigFactory } from 'helpers/factories/routing-config-factory'; | ||
| import { RoutingConfigStorageHelper } from 'helpers/db/routing-config-storage-helper'; | ||
| import { test } from 'fixtures/accessibility-analyze'; | ||
| import { | ||
| RoutingChooseMessageOrderPage, | ||
| RoutingCreateMessagePlanPage, | ||
| RoutingChooseTemplatesPage, | ||
| RoutingInvalidMessagePlanPage, | ||
| RoutingMessagePlanCampaignIdRequiredPage, | ||
| RoutingMessagePlansPage, | ||
| } from 'pages/routing'; | ||
| import { loginAsUser } from 'helpers/auth/login-as-user'; | ||
| import { randomUUID } from 'node:crypto'; | ||
| import { TemplateFactory } from 'helpers/factories/template-factory'; | ||
| import { TemplateStorageHelper } from 'helpers/db/template-storage-helper'; | ||
|
|
||
| let userWithMultipleCampaigns: TestUser; | ||
| const routingStorageHelper = new RoutingConfigStorageHelper(); | ||
| const templateStorageHelper = new TemplateStorageHelper(); | ||
| const validRoutingConfigId = randomUUID(); | ||
| const messageOrder = 'NHSAPP,EMAIL,SMS,LETTER'; | ||
|
|
||
| test.describe('Routing - Accessibility', () => { | ||
| test.beforeAll(async () => { | ||
| const authHelper = createAuthHelper(); | ||
|
|
||
| const user = await authHelper.getTestUser(testUsers.User1.userId); | ||
|
|
||
| userWithMultipleCampaigns = await authHelper.getTestUser( | ||
| testUsers.UserWithMultipleCampaigns.userId | ||
| ); | ||
|
|
||
| const templateIds = { | ||
| NHSAPP: randomUUID(), | ||
| SMS: randomUUID(), | ||
| LETTER: randomUUID(), | ||
| }; | ||
|
|
||
| const routingConfig = RoutingConfigFactory.createForMessageOrder( | ||
| user, | ||
| messageOrder, | ||
| { | ||
| id: validRoutingConfigId, | ||
| name: 'Test plan with some templates', | ||
| } | ||
| ) | ||
| .addTemplate('NHSAPP', templateIds.NHSAPP) | ||
| .addTemplate('SMS', templateIds.SMS) | ||
| .addTemplate('LETTER', templateIds.LETTER).dbEntry; | ||
|
|
||
| const templates = [ | ||
| TemplateFactory.createNhsAppTemplate( | ||
| templateIds.NHSAPP, | ||
| user, | ||
| 'Test NHS App template' | ||
| ), | ||
| TemplateFactory.createSmsTemplate( | ||
| templateIds.SMS, | ||
| user, | ||
| 'Test SMS template' | ||
| ), | ||
| TemplateFactory.uploadLetterTemplate( | ||
| templateIds.LETTER, | ||
| user, | ||
| 'Test Letter template' | ||
| ), | ||
| ]; | ||
|
|
||
| await routingStorageHelper.seed([routingConfig]); | ||
| await templateStorageHelper.seedTemplateData(templates); | ||
| }); | ||
|
|
||
| test.afterAll(async () => { | ||
| await routingStorageHelper.deleteSeeded(); | ||
| await templateStorageHelper.deleteSeededTemplates(); | ||
| }); | ||
|
|
||
| test('Message plans', async ({ page, analyze }) => | ||
bhansell1 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| analyze(new RoutingMessagePlansPage(page))); | ||
|
|
||
| test('Campaign required', async ({ page, analyze }) => | ||
| analyze(new RoutingMessagePlanCampaignIdRequiredPage(page))); | ||
|
|
||
| test('Invalid message plans', async ({ page, analyze }) => | ||
| analyze(new RoutingInvalidMessagePlanPage(page))); | ||
|
|
||
| test('Choose message order', async ({ page, analyze }) => | ||
| analyze(new RoutingChooseMessageOrderPage(page))); | ||
|
|
||
| test('Choose template', async ({ page, analyze }) => | ||
| analyze(new RoutingChooseTemplatesPage(page), { | ||
| id: validRoutingConfigId, | ||
| })); | ||
|
|
||
| test('Choose message order - error', async ({ page, analyze }) => | ||
| analyze(new RoutingChooseMessageOrderPage(page), { | ||
| beforeAnalyze: (p) => p.clickContinueButton(), | ||
| })); | ||
|
|
||
| test.describe('client has multiple campaigns', () => { | ||
| test.use({ storageState: { cookies: [], origins: [] } }); | ||
|
|
||
| test.beforeEach(async ({ page }) => { | ||
| await loginAsUser(userWithMultipleCampaigns, page); | ||
| }); | ||
|
|
||
| test('Create message plan', async ({ page, analyze }) => | ||
| analyze( | ||
| new RoutingCreateMessagePlanPage(page, { | ||
| messageOrder, | ||
| }) | ||
| )); | ||
|
|
||
| test('Create message plan - error', async ({ page, analyze }) => | ||
| analyze( | ||
| new RoutingCreateMessagePlanPage(page, { | ||
| messageOrder, | ||
| }), | ||
| { beforeAnalyze: (p) => p.clickSubmit() } | ||
| )); | ||
| }); | ||
| }); | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.