Skip to content

Commit

Permalink
refactor(Avatar): move files to folder, add e2e tests and stories (#2904
Browse files Browse the repository at this point in the history
)

* refactor(Avatar): move files to folder and add stories

* Update generated/components.json

* Adjust source and data in docs

* Add e2e tests

* test(vrt): update snapshots

* Opt the component into storybook tests

* Add e2e test

* test(vrt): update snapshots

---------

Co-authored-by: josepmartins <josepmartins@users.noreply.github.com>
  • Loading branch information
Josep Martins and josepmartins committed Feb 17, 2023
1 parent 6db8c8a commit 55a1ce5
Show file tree
Hide file tree
Showing 38 changed files with 250 additions and 38 deletions.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions docs/content/Avatar.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
title: Avatar
status: Alpha
componentId: avatar
source: https://github.com/primer/react/blob/main/src/Avatar.tsx
source: https://github.com/primer/react/blob/main/src/Avatar
---

import data from '../../src/Avatar.docs.json'
import data from '../../src/Avatar/Avatar.docs.json'

import {Avatar, Box} from '@primer/react'

Expand Down
2 changes: 1 addition & 1 deletion docs/content/Flash.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
componentId: flash
title: Flash
status: Alpha
source: https://github.com/primer/react/blob/main/src/Flash.tsx
source: https://github.com/primer/react/blob/main/src/Flash
---

import data from '../../src/Flash/Flash.docs.json'
Expand Down
107 changes: 107 additions & 0 deletions e2e/components/Avatar.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
import {test, expect} from '@playwright/test'
import {visit} from '../test-helpers/storybook'
import {themes} from '../test-helpers/themes'

test.describe('Avatar', () => {
test.describe('Default', () => {
for (const theme of themes) {
test.describe(theme, () => {
test('default @vrt', async ({page}) => {
await visit(page, {
id: 'components-avatar--default',
globals: {
colorScheme: theme,
},
})

// Default state
expect(await page.screenshot()).toMatchSnapshot(`Avatar.Default.${theme}.png`)
})

test('axe @aat', async ({page}) => {
await visit(page, {
id: 'components-avatar--default',
globals: {
colorScheme: theme,
},
})
await expect(page).toHaveNoViolations({
rules: {
'color-contrast': {
enabled: theme !== 'dark_dimmed',
},
},
})
})
})
}
})

test.describe('Size', () => {
for (const theme of themes) {
test.describe(theme, () => {
test('default @vrt', async ({page}) => {
await visit(page, {
id: 'components-avatar-features--size',
globals: {
colorScheme: theme,
},
})

// Default state
expect(await page.screenshot()).toMatchSnapshot(`Avatar.Size.${theme}.png`)
})

test('axe @aat', async ({page}) => {
await visit(page, {
id: 'components-avatar-features--size',
globals: {
colorScheme: theme,
},
})
await expect(page).toHaveNoViolations({
rules: {
'color-contrast': {
enabled: theme !== 'dark_dimmed',
},
},
})
})
})
}
})

test.describe('Square', () => {
for (const theme of themes) {
test.describe(theme, () => {
test('default @vrt', async ({page}) => {
await visit(page, {
id: 'components-avatar-features--square',
globals: {
colorScheme: theme,
},
})

// Default state
expect(await page.screenshot()).toMatchSnapshot(`Avatar.Square.${theme}.png`)
})

test('axe @aat', async ({page}) => {
await visit(page, {
id: 'components-avatar-features--square',
globals: {
colorScheme: theme,
},
})
await expect(page).toHaveNoViolations({
rules: {
'color-contrast': {
enabled: theme !== 'dark_dimmed',
},
},
})
})
})
}
})
})
64 changes: 32 additions & 32 deletions generated/components.json
Original file line number Diff line number Diff line change
Expand Up @@ -87,38 +87,6 @@
}
]
},
"avatar": {
"id": "avatar",
"name": "Avatar",
"status": "alpha",
"a11yReviewed": false,
"stories": [],
"props": [
{
"name": "alt",
"type": "string",
"defaultValue": "''",
"description": "Provide alt text when the avatar is used without a name next to it."
},
{
"name": "size",
"type": "number",
"defaultValue": "20",
"description": "The size of the avatar in pixels."
},
{
"name": "square",
"type": "boolean",
"defaultValue": "false",
"description": "If true, the avatar will be square instead of circular."
},
{
"name": "sx",
"type": "SystemStyleObject"
}
],
"subcomponents": []
},
"avatar_pair": {
"id": "avatar_pair",
"name": "AvatarPair",
Expand Down Expand Up @@ -2220,6 +2188,38 @@
}
]
},
"avatar": {
"id": "avatar",
"name": "Avatar",
"status": "alpha",
"a11yReviewed": false,
"stories": [],
"props": [
{
"name": "alt",
"type": "string",
"defaultValue": "''",
"description": "Provide alt text when the avatar is used without a name next to it."
},
{
"name": "size",
"type": "number",
"defaultValue": "20",
"description": "The size of the avatar in pixels."
},
{
"name": "square",
"type": "boolean",
"defaultValue": "false",
"description": "If true, the avatar will be square instead of circular."
},
{
"name": "sx",
"type": "SystemStyleObject"
}
],
"subcomponents": []
},
"branch_name": {
"id": "branch_name",
"name": "BranchName",
Expand Down
19 changes: 19 additions & 0 deletions script/generate-e2e-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,25 @@ const components = new Map([
],
},
],
[
'Avatar',
{
stories: [
{
id: 'components-avatar--default',
name: 'Default',
},
{
id: 'components-avatar-features--size',
name: 'Size',
},
{
id: 'components-avatar-features--square',
name: 'Square',
},
],
},
],
[
'BranchName',
{
Expand Down
File renamed without changes.
27 changes: 27 additions & 0 deletions src/Avatar/Avatar.features.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import React from 'react'
import {ComponentMeta} from '@storybook/react'
import Avatar from './Avatar'

export default {
title: 'Components/Avatar/Features',
component: Avatar,
} as ComponentMeta<typeof Avatar>

export const Square = () => <Avatar square src="https://avatars.githubusercontent.com/primer" />

export const Size = () => (
<div>
<Avatar size={4} src="https://avatars.githubusercontent.com/u/92997159?v=4" />
<Avatar size={8} src="https://avatars.githubusercontent.com/u/92997159?v=4" />
<Avatar size={12} src="https://avatars.githubusercontent.com/u/92997159?v=4" />
<Avatar size={16} src="https://avatars.githubusercontent.com/u/92997159?v=4" />
<Avatar size={20} src="https://avatars.githubusercontent.com/u/92997159?v=4" />
<Avatar size={24} src="https://avatars.githubusercontent.com/u/92997159?v=4" />
<Avatar size={28} src="https://avatars.githubusercontent.com/u/92997159?v=4" />
<Avatar size={32} src="https://avatars.githubusercontent.com/u/92997159?v=4" />
<Avatar size={40} src="https://avatars.githubusercontent.com/u/92997159?v=4" />
<Avatar size={48} src="https://avatars.githubusercontent.com/u/92997159?v=4" />
<Avatar size={56} src="https://avatars.githubusercontent.com/u/92997159?v=4" />
<Avatar size={64} src="https://avatars.githubusercontent.com/u/92997159?v=4" />
</div>
)
57 changes: 57 additions & 0 deletions src/Avatar/Avatar.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import React from 'react'
import {ComponentMeta, ComponentStory} from '@storybook/react'
import Avatar from './Avatar'

export default {
title: 'Components/Avatar',
component: Avatar,
} as ComponentMeta<typeof Avatar>

export const Default = () => <Avatar src="https://avatars.githubusercontent.com/u/92997159?v=4" />

export const Playground: ComponentStory<typeof Avatar> = args => (
<Avatar src="https://avatars.githubusercontent.com/u/92997159?v=4" {...args} />
)

Playground.args = {
size: '20',
}

Playground.argTypes = {
alt: {
controls: false,
table: {
disable: true,
},
},
ref: {
controls: false,
table: {
disable: true,
},
},
forwardedAs: {
controls: false,
table: {
disable: true,
},
},
sx: {
controls: false,
table: {
disable: true,
},
},
as: {
controls: false,
table: {
disable: true,
},
},
theme: {
controls: false,
table: {
disable: true,
},
},
}
6 changes: 3 additions & 3 deletions src/Avatar.tsx → src/Avatar/Avatar.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import styled from 'styled-components'
import {get} from './constants'
import sx, {SxProp} from './sx'
import {ComponentProps} from './utils/types'
import {get} from '../constants'
import sx, {SxProp} from '../sx'
import {ComponentProps} from '../utils/types'

type StyledAvatarProps = {
/** Sets the width and height of the avatar. */
Expand Down
1 change: 1 addition & 0 deletions src/Avatar/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export {default, AvatarProps} from './Avatar'
1 change: 1 addition & 0 deletions src/__tests__/storybook.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ const ROOT_DIRECTORY = path.resolve(__dirname, '..', '..')
// TODO: Remove this allowlist when all components use the new story format
const allowlist = [
'ActionList',
'Avatar',
'Breadcrumbs',
'BranchName',
'Button',
Expand Down

0 comments on commit 55a1ce5

Please sign in to comment.