Skip to content

Commit 18d7ffa

Browse files
committed
CCM-12666: make tests run in the pipeline
1 parent 37f8596 commit 18d7ffa

File tree

6 files changed

+83
-70
lines changed

6 files changed

+83
-70
lines changed

.github/actions/test-types.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
"accessibility",
33
"api",
44
"event",
5+
"ui-accessibility",
56
"ui-component",
67
"ui-routing-component",
78
"ui-e2e",

scripts/tests/test.mk

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ test-coverage: # Evaluate code coverage from scripts/test/coverage @Testing
2323
test-accessibility: # Run tests from scripts/tests/accessibility.sh @Testing
2424
make _test name="accessibility"
2525

26+
test-ui-accessibility: # Run tests from scripts/tests/ui-accessibility.sh @Testing
27+
make _test name="ui-accessibility"
28+
2629
test-ui-routing-component: # Run tests from scripts/tests/ui-routing-component.sh @Testing
2730
make _test name="ui-routing-component"
2831

@@ -50,6 +53,7 @@ test: # Run all the test tasks @Testing
5053
test-lint \
5154
test-typecheck \
5255
test-coverage \
56+
test-ui-accessibility \
5357
test-ui-component \
5458
test-ui-e2e \
5559
test-api \
@@ -73,6 +77,7 @@ ${VERBOSE}.SILENT: \
7377
test-coverage \
7478
test-lint \
7579
test-typecheck \
80+
test-ui-accessibility \
7681
test-ui-component \
7782
test-api \
7883
test-ui-e2e \

scripts/tests/ui-accessibility.sh

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#!/bin/bash
2+
3+
set -euo pipefail
4+
cd "$(git rev-parse --show-toplevel)"
5+
npx playwright install --with-deps > /dev/null
6+
cd tests/test-team
7+
TEST_EXIT_CODE=0
8+
npm run test:accessibility || TEST_EXIT_CODE=$?
9+
echo "TEST_EXIT_CODE=$TEST_EXIT_CODE"
10+
11+
mkdir -p ../acceptance-test-report
12+
cp -r ./playwright-report ../acceptance-test-report
13+
[[ -e test-results ]] && cp -r ./test-results ../acceptance-test-report
14+
15+
exit $TEST_EXIT_CODE
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import { test as base, Page } from '@playwright/test';
2+
import AxeBuilder from '@axe-core/playwright';
3+
import { TemplateMgmtBasePage } from 'pages/template-mgmt-base-page';
4+
import { expect } from '@playwright/test';
5+
6+
type Analyze = <T extends TemplateMgmtBasePage>(
7+
page: T,
8+
opts?: {
9+
id?: string;
10+
beforeAnalyze?: (page: T) => Promise<void>;
11+
}
12+
) => Promise<void>;
13+
14+
type AccessibilityFixture = {
15+
analyze: Analyze;
16+
};
17+
18+
const makeAxeBuilder = (page: Page) =>
19+
new AxeBuilder({ page }).withTags(['wcag2a', 'wcag2aa']);
20+
21+
export const test = base.extend<AccessibilityFixture>({
22+
analyze: async ({ page }, use) => {
23+
const analyze: Analyze = async (pageUnderTest, opts) => {
24+
const { id, beforeAnalyze } = opts ?? {};
25+
26+
await pageUnderTest.loadPage(id);
27+
28+
if (beforeAnalyze) {
29+
await beforeAnalyze(pageUnderTest);
30+
}
31+
32+
const results = await makeAxeBuilder(page).analyze();
33+
34+
expect(results.violations).toEqual([]);
35+
};
36+
37+
await use(analyze);
38+
},
39+
});

tests/test-team/fixtures/axe-test.ts

Lines changed: 0 additions & 34 deletions
This file was deleted.

tests/test-team/template-mgmt-accessibility/routing/routing.accessibility.spec.ts renamed to tests/test-team/template-mgmt-accessibility/routing.accessibility.spec.ts

Lines changed: 23 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -5,43 +5,30 @@ import {
55
} from 'helpers/auth/cognito-auth-helper';
66
import { RoutingConfigFactory } from 'helpers/factories/routing-config-factory';
77
import { RoutingConfigStorageHelper } from 'helpers/db/routing-config-storage-helper';
8-
import { test, expect } from 'fixtures/axe-test';
8+
import { test } from 'fixtures/accessibility-analyze';
99
import {
1010
RoutingChooseMessageOrderPage,
1111
RoutingCreateMessagePlanPage,
1212
RoutingMessagePlanCampaignIdRequiredPage,
1313
RoutingMessagePlansPage,
1414
} from 'pages/routing';
1515
import { loginAsUser } from 'helpers/auth/login-as-user';
16-
import { TemplateMgmtBasePage } from 'pages/template-mgmt-base-page';
17-
import AxeBuilder from '@axe-core/playwright';
1816

1917
let user: TestUser;
2018
let userWithMultipleCampaigns: TestUser;
2119

2220
const routingStorageHelper = new RoutingConfigStorageHelper();
2321

24-
async function run<T extends TemplateMgmtBasePage>(
25-
page: T,
26-
makeAxeBuilder: () => AxeBuilder,
27-
fn?: (page: T) => Promise<void>
28-
) {
29-
await page.loadPage();
30-
if (fn) {
31-
await fn(page);
32-
}
33-
const results = await makeAxeBuilder().analyze();
34-
expect(results.violations).toEqual([]);
35-
}
36-
3722
test.describe('Routing - Accessibility', () => {
3823
test.beforeAll(async () => {
3924
const authHelper = createAuthHelper();
4025

4126
user = await authHelper.getTestUser(testUsers.User1.userId);
27+
4228
userWithMultipleCampaigns = await authHelper.getTestUser(
4329
testUsers.UserWithMultipleCampaigns.userId
4430
);
31+
4532
await routingStorageHelper.seed([
4633
RoutingConfigFactory.create(user).dbEntry,
4734
]);
@@ -51,42 +38,42 @@ test.describe('Routing - Accessibility', () => {
5138
await routingStorageHelper.deleteSeeded();
5239
});
5340

54-
test('Message plans', async ({ page, makeAxeBuilder }) =>
55-
run(new RoutingMessagePlansPage(page), makeAxeBuilder));
41+
test('Message plans', async ({ page, analyze }) =>
42+
analyze(new RoutingMessagePlansPage(page)));
5643

57-
test('Campaign required', async ({ page, makeAxeBuilder }) =>
58-
run(new RoutingMessagePlanCampaignIdRequiredPage(page), makeAxeBuilder));
44+
test('Campaign required', async ({ page, analyze }) =>
45+
analyze(new RoutingMessagePlanCampaignIdRequiredPage(page)));
5946

60-
test('Choose message order', async ({ page, makeAxeBuilder }) =>
61-
run(new RoutingChooseMessageOrderPage(page), makeAxeBuilder));
47+
test('Choose message order', async ({ page, analyze }) =>
48+
analyze(new RoutingChooseMessageOrderPage(page)));
6249

63-
test('Choose message order - error', async ({ page, makeAxeBuilder }) =>
64-
run(new RoutingChooseMessageOrderPage(page), makeAxeBuilder, (p) =>
65-
p.clickContinueButton()
66-
));
50+
test('Choose message order - error', async ({ page, analyze }) =>
51+
analyze(new RoutingChooseMessageOrderPage(page), {
52+
beforeAnalyze: (p) => p.clickContinueButton(),
53+
}));
6754

6855
test.describe('client has multiple campaigns', () => {
56+
const messageOrder = 'NHSAPP,EMAIL,SMS,LETTER';
57+
6958
test.use({ storageState: { cookies: [], origins: [] } });
7059

7160
test.beforeEach(async ({ page }) => {
7261
await loginAsUser(userWithMultipleCampaigns, page);
7362
});
7463

75-
test('Create message plan', async ({ page, makeAxeBuilder }) =>
76-
run(
64+
test('Create message plan', async ({ page, analyze }) =>
65+
analyze(
7766
new RoutingCreateMessagePlanPage(page, {
78-
messageOrder: 'NHSAPP,EMAIL,SMS,LETTER',
79-
}),
80-
makeAxeBuilder
67+
messageOrder,
68+
})
8169
));
8270

83-
test('Create message plan - error', async ({ page, makeAxeBuilder }) =>
84-
run(
71+
test('Create message plan - error', async ({ page, analyze }) =>
72+
analyze(
8573
new RoutingCreateMessagePlanPage(page, {
86-
messageOrder: 'NHSAPP,EMAIL,SMS,LETTER',
74+
messageOrder,
8775
}),
88-
makeAxeBuilder,
89-
(p) => p.clickSubmit()
76+
{ beforeAnalyze: (p) => p.clickSubmit() }
9077
));
9178
});
9279
});

0 commit comments

Comments
 (0)