-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathgroups.unit.test.ts
More file actions
105 lines (85 loc) · 3.35 KB
/
groups.unit.test.ts
File metadata and controls
105 lines (85 loc) · 3.35 KB
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
import type { RuleMetadata } from 'axe-core';
import { describe, expect, it } from 'vitest';
import type { Group } from '@code-pushup/models';
import { loadAxeRules, transformRulesToGroups } from './transform.js';
describe('transformRulesToGroups', () => {
it('should create WCAG 2.1 Level A and AA groups for "wcag21aa" preset', () => {
const groups = transformRulesToGroups(loadAxeRules('wcag21aa'), 'wcag21aa');
expect(groups).toBeArrayOfSize(2);
expect(groups).toPartiallyContain({
slug: 'wcag21-level-a',
title: 'WCAG 2.1 Level A',
});
expect(groups).toPartiallyContain({
slug: 'wcag21-level-aa',
title: 'WCAG 2.1 Level AA',
});
});
it('should populate group refs with audit references for "wcag21aa" preset', () => {
const groups = transformRulesToGroups(loadAxeRules('wcag21aa'), 'wcag21aa');
expect(groups[0]!.refs).not.toBeEmpty();
expect(groups[1]!.refs).not.toBeEmpty();
});
it('should create WCAG 2.2 Level A and AA groups for "wcag22aa" preset', () => {
const groups = transformRulesToGroups(loadAxeRules('wcag22aa'), 'wcag22aa');
expect(groups).toBeArrayOfSize(2);
expect(groups).toPartiallyContain({
slug: 'wcag22-level-a',
title: 'WCAG 2.2 Level A',
});
expect(groups).toPartiallyContain({
slug: 'wcag22-level-aa',
title: 'WCAG 2.2 Level AA',
});
});
it('should create multiple category groups for "best-practice" preset', () => {
expect(
transformRulesToGroups(loadAxeRules('best-practice'), 'best-practice')
.length,
).toBeGreaterThan(5);
});
it('should format category titles using display names', () => {
const groups = transformRulesToGroups(
loadAxeRules('best-practice'),
'best-practice',
);
expect(groups).toPartiallyContain({ slug: 'aria', title: 'ARIA' });
expect(groups).toPartiallyContain({
slug: 'name-role-value',
title: 'Names & Labels',
});
});
it('should format unknown category titles with title case', () => {
const groups = transformRulesToGroups(
[{ tags: ['cat.some-new-category', 'best-practice'] } as RuleMetadata],
'best-practice',
);
expect(groups).toPartiallyContain({
slug: 'some-new-category',
title: 'Some New Category',
});
});
it('should remove "cat." prefix from category slugs', () => {
const groups = transformRulesToGroups(
loadAxeRules('best-practice'),
'best-practice',
);
expect(groups).toSatisfyAll<Group>(({ slug }) => !/^cat\./.test(slug));
});
it('should include both WCAG 2.2 and category groups for "all" preset', () => {
const groups = transformRulesToGroups(loadAxeRules('all'), 'all');
expect(groups).toPartiallyContain({ slug: 'wcag22-level-a' });
expect(groups).toPartiallyContain({ slug: 'wcag22-level-aa' });
expect(groups).toSatisfyAny(({ slug }) => !slug.startsWith('wcag'));
});
it('should assign equal weight to all audit references within groups', () => {
const groups = transformRulesToGroups(loadAxeRules('wcag21aa'), 'wcag21aa');
expect(groups).toSatisfyAll<Group>(({ refs }) =>
refs.every(({ weight }) => weight === 1),
);
});
it('should filter out empty groups', () => {
const groups = transformRulesToGroups(loadAxeRules('all'), 'all');
expect(groups).toSatisfyAll<Group>(({ refs }) => refs.length > 0);
});
});