Skip to content

Commit a04f22d

Browse files
test: add accessibility tests to app-degree-pages
1 parent 0833f25 commit a04f22d

File tree

10 files changed

+153
-14
lines changed

10 files changed

+153
-14
lines changed

Jenkinsfile

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -279,15 +279,9 @@ spec:
279279
)
280280
if (acessibilityTestResults != 0) {
281281
slackSend(
282-
channel: '#prd-uds',
282+
channel: '#prdfam-uds-ci',
283283
color: 'warning',
284-
message: "@uds-developers Action might be needed: ${env.RUN_DISPLAY_URL}"
285-
)
286-
} else {
287-
slackSend(
288-
channel: '#prd-uds',
289-
color: 'warning',
290-
message: "@uds-developers Accessibility Testing, Please Ignore: ${env.RUN_DISPLAY_URL}"
284+
message: "@uds-developers Accessibility tests failed.: ${env.RUN_DISPLAY_URL} \n Pull Branch and run tests locally to see report"
291285
)
292286
}
293287
}

package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
"prebuild": "lerna run build --scope=@asu/unity-react-core && yarn lint",
2020
"postbuild": "lerna run --ignore=@asu/unity-bootstrap-theme docs",
2121
"test": "lerna run test --stream --parallel",
22+
"test:accessibility": "lerna run test:accessibility --parallel",
2223
"test:e2e": "jest",
2324
"prepublish-packages": "node scripts/copy-license.js && node scripts/copy-release-rc.js",
2425
"publish-packages": "yarn prepublish-packages && lerna exec --ignore=@asu/static-site --concurrency 1 -- npx --no-install semantic-release --debug -e semantic-release-monorepo",
@@ -48,6 +49,7 @@
4849
"@commitlint/cli": "^19.7.1",
4950
"@commitlint/config-conventional": "^19.7.1",
5051
"@commitlint/config-lerna-scopes": "^19.7.0",
52+
"@playwright/test": "1.50.1",
5153
"@semantic-release/changelog": "^6.0.3",
5254
"@semantic-release/git": "^10.0.1",
5355
"@siteimprove/alfa-playwright": "^0.78.1",
@@ -86,6 +88,7 @@
8688
"lerna": "^6.4.1",
8789
"mini-css-extract-plugin": "^2.0.0",
8890
"nunjucks": "^3.2.0",
91+
"playwright": "1.50.1",
8992
"prettier": "^2.2.1",
9093
"purgecss-webpack-plugin": "^4.0.3",
9194
"react": "^18.3.1",

packages/app-degree-pages/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
"scripts": {
2727
"lint": "eslint --fix 'src/**/*.{js,jsx,ts,tsx}' --ignore-path ../../.eslintignore",
2828
"test": "vitest --watch=false",
29+
"test:accessibility": "playwright test",
2930
"test-update-snapshot": "yarn test -- -u",
3031
"e2e-ci": "concurrently --kill-others \"yarn storybook\" \"yarn cy:run\"",
3132
"e2e": "yarn cy:open",
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import { defineConfig } from '@playwright/test';
2+
3+
export default defineConfig({
4+
testDir: './tests',
5+
testMatch: /.*\.spec\.m?js$/,
6+
timeout: 30000,
7+
workers: process.env.CI ? 2 : 1,
8+
webServer: {
9+
command: 'yarn storybook',
10+
port: 9010,
11+
reuseExistingServer: !process.env.CI,
12+
},
13+
use: {
14+
baseURL: 'http://localhost:9010',
15+
trace: 'on-first-retry',
16+
},
17+
projects: [
18+
{
19+
name: 'chromium',
20+
use: { browserName: 'chromium', headless: false },
21+
},
22+
],
23+
});
Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
import { test, expect } from "@playwright/test";
2+
import { Audit, Logging, Rules } from "@siteimprove/alfa-test-utils";
3+
import { Playwright } from "@siteimprove/alfa-playwright";
4+
import path from "path";
5+
import fs from "fs";
6+
import { storiesToTest } from "./stories-to-test.mjs";
7+
import searchPageJsonData from "../__mocks__/data/degree-search.json" assert { type: "json" };
8+
import detailPageJsonData from "../__mocks__/data/degree-search-detail.json" assert { type: "json" };
9+
10+
const STORYBOOK_URL = "http://localhost:9010";
11+
12+
const reportDir = path.join(process.cwd(), "accessibility-reports");
13+
if (!fs.existsSync(reportDir)) {
14+
fs.mkdirSync(reportDir, { recursive: true });
15+
}
16+
17+
const timestamp = new Date().toISOString().replace(/:/g, "-");
18+
19+
test.describe("Storybook Accessibility Tests with Siteimprove", () => {
20+
21+
test(`Component ${storiesToTest[0]} should pass accessibility tests`, async ({ page }) => {
22+
await page.route("**/api/**", route => {
23+
route.fulfill({
24+
status: 200,
25+
contentType: "application/json",
26+
body: JSON.stringify(detailPageJsonData),
27+
});
28+
});
29+
const storyId = storiesToTest[0];
30+
const encodedStoryId = encodeURIComponent(storyId);
31+
const storyUrl = `${STORYBOOK_URL}/iframe.html?id=${encodedStoryId}&viewMode=story`;
32+
33+
await page.goto(storyUrl);
34+
await page.waitForTimeout(2000);
35+
36+
const document = await page.evaluateHandle(() => window.document);
37+
const alfaPage = await Playwright.toPage(document);
38+
39+
const alfaResult = await Audit.run(alfaPage, {
40+
rules: { include: Rules.wcag21aaFilter },
41+
});
42+
43+
await page.screenshot({
44+
fullPage: true,
45+
path: path.join(reportDir, `screenshot-${storyId}-${timestamp}.png`),
46+
});
47+
48+
Logging.fromAudit(alfaResult).print();
49+
50+
const failingRules = alfaResult.resultAggregates.filter(
51+
aggregate => aggregate.failed > 0
52+
);
53+
54+
if (!process.env.CI) {
55+
const reportFilePath = path.join(reportDir, `siteimprove-report-${storyId}-${timestamp}.json`);
56+
fs.writeFileSync(
57+
reportFilePath,
58+
JSON.stringify(Logging.fromAudit(alfaResult).toJSON(), null, 2)
59+
);
60+
console.log(`Saved detailed JSON report to: ${reportFilePath}`);
61+
}
62+
63+
expect(failingRules.size,
64+
`Found ${failingRules.size} accessibility rule violations in ${storyId}`
65+
).toBe(0);
66+
});
67+
68+
test(`Component ${storiesToTest[1]} should pass accessibility tests`, async ({ page }) => {
69+
// await page.route("**/api/**", route => {
70+
// route.fulfill({
71+
// status: 200,
72+
// contentType: "application/json",
73+
// body: JSON.stringify(searchPageJsonData),
74+
// })
75+
// });
76+
const storyId = storiesToTest[1];
77+
const encodedStoryId = encodeURIComponent(storyId);
78+
const storyUrl = `${STORYBOOK_URL}/iframe.html?id=${encodedStoryId}&viewMode=story`;
79+
80+
await page.goto(storyUrl);
81+
await page.waitForTimeout(2000);
82+
83+
const document = await page.evaluateHandle(() => window.document);
84+
const alfaPage = await Playwright.toPage(document);
85+
86+
const alfaResult = await Audit.run(alfaPage, {
87+
rules: { include: Rules.wcag21aaFilter },
88+
});
89+
90+
await page.screenshot({
91+
fullPage: true,
92+
path: path.join(reportDir, `screenshot-${storyId}-${timestamp}.png`),
93+
});
94+
95+
Logging.fromAudit(alfaResult).print();
96+
97+
const failingRules = alfaResult.resultAggregates.filter(
98+
aggregate => aggregate.failed > 0
99+
);
100+
101+
if (!process.env.CI) {
102+
const reportFilePath = path.join(reportDir, `siteimprove-report-${storyId}-${timestamp}.json`);
103+
fs.writeFileSync(
104+
reportFilePath,
105+
JSON.stringify(Logging.fromAudit(alfaResult).toJSON(), null, 2)
106+
);
107+
console.log(`Saved detailed JSON report to: ${reportFilePath}`);
108+
}
109+
110+
expect(failingRules.size,
111+
`Found ${failingRules.size} accessibility rule violations in ${storyId}`
112+
).toBe(0);
113+
});
114+
});
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
export const storiesToTest = [
2+
"program-detail-page--default",
3+
"program-listing-page--default"
4+
];

packages/unity-react-core/package.json

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@
5555
"@babel/plugin-transform-runtime": "^7.19.6",
5656
"@babel/preset-env": "^7.20.2",
5757
"@fortawesome/fontawesome-free": "^5.15.3",
58-
"@playwright/test": "1.50.1",
5958
"@storybook/addon-a11y": "^8.5.4",
6059
"@storybook/addon-essentials": "^8.5.4",
6160
"@storybook/addon-interactions": "^8.5.4",
@@ -100,7 +99,6 @@
10099
"jsdoc": "4",
101100
"jsdom": "^24.0.0",
102101
"jsdom-screenshot": "^4.0.0",
103-
"playwright": "1.50.1",
104102
"plop": "2.7.6",
105103
"postcss": "^8.4.19",
106104
"prettier": "^2.8.1",

packages/unity-react-core/playwright.config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ export default defineConfig({
44
testDir: './tests',
55
testMatch: /.*\.spec\.m?js$/,
66
timeout: 30000,
7+
workers: process.env.CI ? 2 : 1,
78
webServer: {
89
command: 'yarn storybook',
910
port: 9200,

packages/unity-react-core/tests/accessibility.spec.mjs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,8 @@ test.describe("Storybook Accessibility Tests with Siteimprove", () => {
121121
url: storyUrl,
122122
error: error.message,
123123
});
124+
} finally {
125+
await context.close();
124126
}
125127
}
126128

@@ -151,7 +153,6 @@ test.describe("Storybook Accessibility Tests with Siteimprove", () => {
151153
} else {
152154
console.log("No accessibility violations found! 🎉");
153155
}
154-
},
155-
{ timeout: 30000 }
156+
}
156157
);
157158
});

yarn.lock

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -681,7 +681,6 @@ __metadata:
681681
"@babel/preset-env": "npm:^7.20.2"
682682
"@fortawesome/fontawesome-free": "npm:^5.15.3"
683683
"@glidejs/glide": "npm:~3.6.2"
684-
"@playwright/test": "npm:1.50.1"
685684
"@storybook/addon-a11y": "npm:^8.5.4"
686685
"@storybook/addon-essentials": "npm:^8.5.4"
687686
"@storybook/addon-interactions": "npm:^8.5.4"
@@ -729,7 +728,6 @@ __metadata:
729728
jsdom: "npm:^24.0.0"
730729
jsdom-screenshot: "npm:^4.0.0"
731730
phone-fns: "npm:^3.2.3"
732-
playwright: "npm:1.50.1"
733731
plop: "npm:2.7.6"
734732
postcss: "npm:^8.4.19"
735733
prettier: "npm:^2.8.1"
@@ -12338,6 +12336,7 @@ __metadata:
1233812336
"@commitlint/cli": "npm:^19.7.1"
1233912337
"@commitlint/config-conventional": "npm:^19.7.1"
1234012338
"@commitlint/config-lerna-scopes": "npm:^19.7.0"
12339+
"@playwright/test": "npm:1.50.1"
1234112340
"@semantic-release/changelog": "npm:^6.0.3"
1234212341
"@semantic-release/git": "npm:^10.0.1"
1234312342
"@siteimprove/alfa-playwright": "npm:^0.78.1"
@@ -12376,6 +12375,7 @@ __metadata:
1237612375
lerna: "npm:^6.4.1"
1237712376
mini-css-extract-plugin: "npm:^2.0.0"
1237812377
nunjucks: "npm:^3.2.0"
12378+
playwright: "npm:1.50.1"
1237912379
prettier: "npm:^2.2.1"
1238012380
purgecss-webpack-plugin: "npm:^4.0.3"
1238112381
react: "npm:^18.3.1"

0 commit comments

Comments
 (0)