Skip to content

Commit a4a12bd

Browse files
Josep Martinsjosepmartins
andauthored
refactor(AvatarPair): move files to folder, add e2e tests and stories (#2906)
* refactor(AvatarPair): move files to folder and add stories * Update generated/components.json * Adjust documentation * test(vrt): update snapshots * Fix index * Remove componentStory --------- Co-authored-by: josepmartins <josepmartins@users.noreply.github.com>
1 parent 46865b8 commit a4a12bd

File tree

37 files changed

+192
-25
lines changed

37 files changed

+192
-25
lines changed

docs/content/AvatarPair.mdx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22
componentId: avatar_pair
33
title: AvatarPair
44
status: Alpha
5-
source: https://github.com/primer/react/blob/main/src/AvatarPair.tsx
5+
source: https://github.com/primer/react/blob/main/src/AvatarPair
66
---
77

8-
import data from '../../src/AvatarPair.docs.json'
8+
import data from '../../src/AvatarPair/AvatarPair.docs.json'
99

1010
```js
1111
import {AvatarPair} from '@primer/react'

e2e/components/AvatarPair.test.ts

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
import {test, expect} from '@playwright/test'
2+
import {visit} from '../test-helpers/storybook'
3+
import {themes} from '../test-helpers/themes'
4+
5+
test.describe('AvatarPair', () => {
6+
test.describe('Default', () => {
7+
for (const theme of themes) {
8+
test.describe(theme, () => {
9+
test('default @vrt', async ({page}) => {
10+
await visit(page, {
11+
id: 'components-avatarpair--default',
12+
globals: {
13+
colorScheme: theme,
14+
},
15+
})
16+
17+
// Default state
18+
expect(await page.screenshot()).toMatchSnapshot(`AvatarPair.Default.${theme}.png`)
19+
})
20+
21+
test('axe @aat', async ({page}) => {
22+
await visit(page, {
23+
id: 'components-avatarpair--default',
24+
globals: {
25+
colorScheme: theme,
26+
},
27+
})
28+
await expect(page).toHaveNoViolations({
29+
rules: {
30+
'color-contrast': {
31+
enabled: theme !== 'dark_dimmed',
32+
},
33+
},
34+
})
35+
})
36+
})
37+
}
38+
})
39+
40+
test.describe('Parent Circle', () => {
41+
for (const theme of themes) {
42+
test.describe(theme, () => {
43+
test('default @vrt', async ({page}) => {
44+
await visit(page, {
45+
id: 'components-avatarpair-features--parent-circle',
46+
globals: {
47+
colorScheme: theme,
48+
},
49+
})
50+
51+
// Default state
52+
expect(await page.screenshot()).toMatchSnapshot(`AvatarPair.Parent Circle.${theme}.png`)
53+
})
54+
55+
test('axe @aat', async ({page}) => {
56+
await visit(page, {
57+
id: 'components-avatarpair-features--parent-circle',
58+
globals: {
59+
colorScheme: theme,
60+
},
61+
})
62+
await expect(page).toHaveNoViolations({
63+
rules: {
64+
'color-contrast': {
65+
enabled: theme !== 'dark_dimmed',
66+
},
67+
},
68+
})
69+
})
70+
})
71+
}
72+
})
73+
74+
test.describe('Parent Square', () => {
75+
for (const theme of themes) {
76+
test.describe(theme, () => {
77+
test('default @vrt', async ({page}) => {
78+
await visit(page, {
79+
id: 'components-avatarpair-features--parent-square',
80+
globals: {
81+
colorScheme: theme,
82+
},
83+
})
84+
85+
// Default state
86+
expect(await page.screenshot()).toMatchSnapshot(`AvatarPair.Parent Square.${theme}.png`)
87+
})
88+
89+
test('axe @aat', async ({page}) => {
90+
await visit(page, {
91+
id: 'components-avatarpair-features--parent-square',
92+
globals: {
93+
colorScheme: theme,
94+
},
95+
})
96+
await expect(page).toHaveNoViolations({
97+
rules: {
98+
'color-contrast': {
99+
enabled: theme !== 'dark_dimmed',
100+
},
101+
},
102+
})
103+
})
104+
})
105+
}
106+
})
107+
})

generated/components.json

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -87,26 +87,6 @@
8787
}
8888
]
8989
},
90-
"avatar_pair": {
91-
"id": "avatar_pair",
92-
"name": "AvatarPair",
93-
"status": "alpha",
94-
"a11yReviewed": false,
95-
"stories": [],
96-
"props": [
97-
{
98-
"name": "children",
99-
"type": "Avatar[]",
100-
"defaultValue": "",
101-
"description": ""
102-
},
103-
{
104-
"name": "sx",
105-
"type": "SystemStyleObject"
106-
}
107-
],
108-
"subcomponents": []
109-
},
11090
"avatar_stack": {
11191
"id": "avatar_stack",
11292
"name": "AvatarStack",
@@ -2220,6 +2200,26 @@
22202200
],
22212201
"subcomponents": []
22222202
},
2203+
"avatar_pair": {
2204+
"id": "avatar_pair",
2205+
"name": "AvatarPair",
2206+
"status": "alpha",
2207+
"a11yReviewed": false,
2208+
"stories": [],
2209+
"props": [
2210+
{
2211+
"name": "children",
2212+
"type": "Avatar[]",
2213+
"defaultValue": "",
2214+
"description": ""
2215+
},
2216+
{
2217+
"name": "sx",
2218+
"type": "SystemStyleObject"
2219+
}
2220+
],
2221+
"subcomponents": []
2222+
},
22232223
"branch_name": {
22242224
"id": "branch_name",
22252225
"name": "BranchName",

script/generate-e2e-tests.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,25 @@ const components = new Map([
9090
],
9191
},
9292
],
93+
[
94+
'AvatarPair',
95+
{
96+
stories: [
97+
{
98+
id: 'components-avatarpair--default',
99+
name: 'Default',
100+
},
101+
{
102+
id: 'components-avatarpair-features--parent-circle',
103+
name: 'Parent Circle',
104+
},
105+
{
106+
id: 'components-avatarpair-features--parent-square',
107+
name: 'Parent Square',
108+
},
109+
],
110+
},
111+
],
93112
[
94113
'BranchName',
95114
{
File renamed without changes.
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import React from 'react'
2+
import {ComponentMeta} from '@storybook/react'
3+
import AvatarPair from './AvatarPair'
4+
import Avatar from '../Avatar'
5+
6+
export default {
7+
title: 'Components/AvatarPair/Features',
8+
component: AvatarPair,
9+
} as ComponentMeta<typeof AvatarPair>
10+
11+
export const ParentCircle = () => (
12+
<AvatarPair>
13+
<Avatar src="https://avatars.githubusercontent.com/u/92997159?v=4" />
14+
<Avatar square src="https://avatars.githubusercontent.com/primer" />
15+
</AvatarPair>
16+
)
17+
18+
export const ParentSquare = () => (
19+
<AvatarPair>
20+
<Avatar square src="https://avatars.githubusercontent.com/primer" />
21+
<Avatar src="https://avatars.githubusercontent.com/u/92997159?v=4" />
22+
</AvatarPair>
23+
)

src/AvatarPair/AvatarPair.stories.tsx

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import React from 'react'
2+
import {ComponentMeta} from '@storybook/react'
3+
import AvatarPair from './AvatarPair'
4+
import Avatar from '../Avatar'
5+
6+
export default {
7+
title: 'Components/AvatarPair',
8+
component: AvatarPair,
9+
} as ComponentMeta<typeof AvatarPair>
10+
11+
export const Default = () => (
12+
<AvatarPair>
13+
<Avatar src="https://avatars.githubusercontent.com/u/92997159?v=4" />
14+
<Avatar src="https://avatars.githubusercontent.com/primer" />
15+
</AvatarPair>
16+
)

src/AvatarPair.tsx renamed to src/AvatarPair/AvatarPair.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import React from 'react'
22
import styled from 'styled-components'
3-
import Avatar, {AvatarProps} from './Avatar'
4-
import {get} from './constants'
5-
import Box, {BoxProps} from './Box'
3+
import Avatar, {AvatarProps} from '../Avatar'
4+
import {get} from '../constants'
5+
import Box, {BoxProps} from '../Box'
66

77
const ChildAvatar = styled(Avatar)`
88
position: absolute;

src/AvatarPair/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export {default, AvatarPairProps} from './AvatarPair'

src/__tests__/storybook.test.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ const ROOT_DIRECTORY = path.resolve(__dirname, '..', '..')
99
const allowlist = [
1010
'ActionList',
1111
'Avatar',
12+
'AvatarPair',
1213
'Breadcrumbs',
1314
'BranchName',
1415
'Button',

0 commit comments

Comments
 (0)