|
1 |
| -import AxeBuilder from '@axe-core/playwright' |
2 | 1 | import { expect, test } from '@playwright/test'
|
3 |
| -import { gotoStory } from '../utils' |
| 2 | +import { gotoStory, testA11yWithAttachedResults } from '../utils' |
4 | 3 |
|
5 | 4 | test.describe('basic variant', () => {
|
6 |
| - test('has avatar image', async ({ page }) => { |
| 5 | + test.beforeEach(async ({ page }) => { |
7 | 6 | await gotoStory('avatar', 'basic', page)
|
8 |
| - |
9 | 7 | await page.getByAltText('avatar').waitFor()
|
10 |
| - |
| 8 | + }) |
| 9 | + test('has avatar image', async ({ page }) => { |
11 | 10 | expect(page.getByAltText('avatar')).toHaveAttribute(
|
12 | 11 | 'src',
|
13 | 12 | 'https://avatars.githubusercontent.com/u/1846056?v=4',
|
14 | 13 | )
|
15 |
| - |
16 | 14 | expect(page).toHaveScreenshot()
|
17 | 15 | })
|
18 | 16 | test('has no a11y violations', async ({ page }, testInfo) => {
|
19 |
| - await gotoStory('avatar', 'basic', page) |
20 |
| - |
21 |
| - await page.getByAltText('avatar').waitFor() |
22 |
| - |
23 |
| - const accessibilityScanResults = await new AxeBuilder({ page }) |
24 |
| - .include('[data-scope="avatar"][data-part="root"]') |
25 |
| - .analyze() |
26 |
| - |
27 |
| - await testInfo.attach('accessibility-scan-results', { |
28 |
| - body: JSON.stringify(accessibilityScanResults, null, 2), |
29 |
| - contentType: 'application/json', |
30 |
| - }) |
31 |
| - |
| 17 | + const accessibilityScanResults = await testA11yWithAttachedResults(page, testInfo, 'avatar') |
32 | 18 | expect(accessibilityScanResults.violations).toEqual([])
|
33 | 19 | })
|
34 | 20 | })
|
35 | 21 |
|
36 | 22 | test.describe('closed variant', () => {
|
37 |
| - test('displays avatar with name', async ({ page }) => { |
| 23 | + test.beforeEach(async ({ page }) => { |
38 | 24 | await gotoStory('avatar', 'closed', page)
|
39 |
| - |
40 | 25 | await page.getByAltText('Christian').waitFor()
|
| 26 | + }) |
| 27 | + test('displays avatar with name', async ({ page }) => { |
41 | 28 | expect(page.getByAltText('Christian')).toHaveAttribute(
|
42 | 29 | 'src',
|
43 | 30 | 'https://avatars.githubusercontent.com/u/1846056?v=4',
|
44 | 31 | )
|
45 | 32 | expect(page).toHaveScreenshot()
|
46 | 33 | })
|
47 | 34 | test('has no a11y violations', async ({ page }, testInfo) => {
|
48 |
| - await gotoStory('avatar', 'closed', page) |
49 |
| - await page.getByAltText('Christian').waitFor() |
50 |
| - |
51 |
| - const accessibilityScanResults = await new AxeBuilder({ page }) |
52 |
| - .include('[data-scope="avatar"][data-part="root"]') |
53 |
| - .analyze() |
54 |
| - |
55 |
| - await testInfo.attach('accessibility-scan-results', { |
56 |
| - body: JSON.stringify(accessibilityScanResults, null, 2), |
57 |
| - contentType: 'application/json', |
58 |
| - }) |
59 |
| - |
| 35 | + const accessibilityScanResults = await testA11yWithAttachedResults(page, testInfo, 'avatar') |
60 | 36 | expect(accessibilityScanResults.violations).toEqual([])
|
61 | 37 | })
|
62 | 38 | })
|
63 | 39 |
|
64 | 40 | test.describe('root-provided variant', () => {
|
65 |
| - test('has avatar image', async ({ page }) => { |
| 41 | + test.beforeEach(async ({ page }) => { |
66 | 42 | await gotoStory('avatar', 'root-provider', page)
|
67 |
| - |
68 | 43 | await page.getByAltText('avatar').waitFor()
|
| 44 | + }) |
| 45 | + test('has avatar image', async ({ page }) => { |
69 | 46 | expect(page.getByAltText('avatar')).toHaveAttribute(
|
70 | 47 | 'src',
|
71 | 48 | 'https://avatars.githubusercontent.com/u/1846056?v=4',
|
72 | 49 | )
|
73 | 50 | expect(page).toHaveScreenshot()
|
74 | 51 | })
|
75 | 52 | test('has no a11y violations', async ({ page }, testInfo) => {
|
76 |
| - await gotoStory('avatar', 'root-provider', page) |
77 |
| - |
78 |
| - await page.getByAltText('avatar').waitFor() |
79 |
| - |
80 |
| - const accessibilityScanResults = await new AxeBuilder({ page }) |
81 |
| - .include('[data-scope="avatar"][data-part="root"]') |
82 |
| - .analyze() |
83 |
| - |
84 |
| - await testInfo.attach('accessibility-scan-results', { |
85 |
| - body: JSON.stringify(accessibilityScanResults, null, 2), |
86 |
| - contentType: 'application/json', |
87 |
| - }) |
88 |
| - |
| 53 | + const accessibilityScanResults = await testA11yWithAttachedResults(page, testInfo, 'avatar') |
89 | 54 | expect(accessibilityScanResults.violations).toEqual([])
|
90 | 55 | })
|
91 | 56 | })
|
0 commit comments