aboutsummaryrefslogtreecommitdiff
path: root/tests/e2e/a11y.spec.ts
blob: 7ff49813e5f014c830aad8652006bd1d1ddcae5b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import { test, expect } from '@playwright/test';
import AxeBuilder from '@axe-core/playwright';

test.describe('Should not have any automatically detectable accessibility issues @a11y', () => {
    test.describe('while not logged in', () => {
        const pages = [
            ['on homepage', 'index.php?cancel_login=1'],
            ['on login page', 'index.php?again=yes'],
            ['on password forgotten page', 'dispatch.php/new_password?cancel_login=1'],
        ];

        pages.forEach(async ([title, url]) =>
            test(title, async ({ page, baseURL }) => {
                await page.goto(url);
                const accessibilityScanResults = await analyze(page);
                expect(accessibilityScanResults.violations).toEqual([]);
            })
        );
    });

    test.describe('while logged in as author', () => {
        const autorFile = 'tests/e2e/.auth/autor.json';
        test.use({ storageState: autorFile });

        const pages = [
            ['on start page', 'dispatch.php/start'],
            ['on profile page', 'dispatch.php/profile/index'],
            ['on my courses page', 'dispatch.php/courses'],
        ];

        pages.forEach(async ([title, url]) =>
            test(title, async ({ page, baseURL }) => {
                await page.goto(url);
                const accessibilityScanResults = await analyze(page);
                expect(accessibilityScanResults.violations).toEqual([]);
            })
        );
    });
});

function analyze(page) {
    return new AxeBuilder({ page }).analyze();
}