Skip to content

Commit

Permalink
refactor(CircleBadge): move files into folder, add e2e tests. (#3118)
Browse files Browse the repository at this point in the history
* Reorganize CircleBadge, add e2e tests.

* Update generated/components.json

* test(vrt): update snapshots

* Update docs reference.

---------

Co-authored-by: radglob <[email protected]>
  • Loading branch information
radglob and radglob authored Apr 4, 2023
1 parent 8b5307d commit 7eaad16
Show file tree
Hide file tree
Showing 26 changed files with 191 additions and 62 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.
2 changes: 1 addition & 1 deletion docs/content/CircleBadge.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ status: Alpha
source: https://github.com/primer/react/blob/main/src/CircleBadge.tsx
---

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

```js
import {CircleBadge} from '@primer/react'
Expand Down
61 changes: 61 additions & 0 deletions e2e/components/CircleBadge.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import {test, expect} from '@playwright/test'
import {visit} from '../test-helpers/storybook'
import {themes} from '../test-helpers/themes'

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

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

test('axe @aat', async ({page}) => {
await visit(page, {
id: 'components-circlebadge--default',
globals: {
colorScheme: theme,
},
})
await expect(page).toHaveNoViolations()
})
})
}
})

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

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

test('axe @aat', async ({page}) => {
await visit(page, {
id: 'components-circlebadge--playground',
globals: {
colorScheme: theme,
},
})
await expect(page).toHaveNoViolations()
})
})
}
})
})
117 changes: 61 additions & 56 deletions generated/components.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,62 +19,6 @@
],
"subcomponents": []
},
"circle_badge": {
"id": "circle_badge",
"name": "CircleBadge",
"status": "alpha",
"a11yReviewed": false,
"stories": [],
"props": [
{
"name": "variant",
"type": "'small' | 'medium' | 'large'",
"defaultValue": "'medium'",
"description": "Creates a smaller or larger badge. Has no effect if the `size` prop is set"
},
{
"name": "size",
"type": "number",
"defaultValue": "",
"description": "Sets the size of the badge in pixels. Overrides the `variant` prop when set"
},
{
"name": "inline",
"type": "boolean",
"defaultValue": "false",
"description": "Styles the badge to `display: inline`"
},
{
"name": "ref",
"type": "React.RefObject<HTMLDivElement>"
},
{
"name": "as",
"type": "React.ElementType",
"defaultValue": "\"div\""
},
{
"name": "sx",
"type": "SystemStyleObject"
}
],
"subcomponents": [
{
"name": "CircleBadge.Icon",
"props": [
{
"name": "as",
"type": "React.ElementType",
"defaultValue": "StyledOcticon"
}
],
"passthrough": {
"element": "StyledOcticon",
"url": "/StyledOcticon"
}
}
]
},
"circle_octicon": {
"id": "circle_octicon",
"name": "CircleOcticon",
Expand Down Expand Up @@ -1741,6 +1685,67 @@
}
]
},
"circle_badge": {
"id": "circle_badge",
"name": "CircleBadge",
"status": "alpha",
"a11yReviewed": false,
"stories": [
{
"id": "components-circlebadge--default",
"code": "() => (\n <CircleBadge>\n <CircleBadge.Icon icon={ZapIcon} />\n </CircleBadge>\n)"
}
],
"props": [
{
"name": "variant",
"type": "'small' | 'medium' | 'large'",
"defaultValue": "'medium'",
"description": "Creates a smaller or larger badge. Has no effect if the `size` prop is set"
},
{
"name": "size",
"type": "number",
"defaultValue": "",
"description": "Sets the size of the badge in pixels. Overrides the `variant` prop when set"
},
{
"name": "inline",
"type": "boolean",
"defaultValue": "false",
"description": "Styles the badge to `display: inline`"
},
{
"name": "ref",
"type": "React.RefObject<HTMLDivElement>"
},
{
"name": "as",
"type": "React.ElementType",
"defaultValue": "\"div\""
},
{
"name": "sx",
"type": "SystemStyleObject"
}
],
"subcomponents": [
{
"name": "CircleBadge.Icon",
"props": [
{
"name": "as",
"type": "React.ElementType",
"defaultValue": "StyledOcticon"
}
],
"passthrough": {
"element": "StyledOcticon",
"url": "/StyledOcticon"
}
}
]
},
"counter_label": {
"id": "counter_label",
"name": "CounterLabel",
Expand Down
15 changes: 15 additions & 0 deletions script/generate-e2e-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,21 @@ const components = new Map([
],
},
],
[
'CircleBadge',
{
stories: [
{
id: 'components-circlebadge--default',
name: 'Default',
},
{
id: 'components-circlebadge--playground',
name: 'Playground',
},
],
},
],
[
'CounterLabel',
{
Expand Down
File renamed without changes.
47 changes: 47 additions & 0 deletions src/CircleBadge/CircleBadge.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import React from 'react'
import {Meta, ComponentStory} from '@storybook/react'
import CircleBadge from './CircleBadge'
import {ZapIcon} from '@primer/octicons-react'

export default {
title: 'Components/CircleBadge',
component: CircleBadge,
} as Meta<typeof CircleBadge>

export const Default = () => (
<CircleBadge>
<CircleBadge.Icon icon={ZapIcon} />
</CircleBadge>
)

export const Playground: ComponentStory<typeof CircleBadge> = args => (
<CircleBadge {...args}>
<CircleBadge.Icon icon={ZapIcon} />
</CircleBadge>
)

Playground.args = {
variant: 'medium',
size: null,
inline: false,
as: 'div',
}

Playground.argTypes = {
variant: {
control: {
type: 'radio',
},
options: ['small', 'medium', 'large'],
},
size: {
control: {
type: 'number',
},
},
inline: {
control: {
type: 'boolean',
},
},
}
10 changes: 5 additions & 5 deletions src/CircleBadge.tsx → src/CircleBadge/CircleBadge.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import styled from 'styled-components'
import {get} from './constants'
import StyledOcticon from './StyledOcticon'
import sx, {SxProp} from './sx'
import isNumeric from './utils/isNumeric'
import {ComponentProps} from './utils/types'
import {get} from '../constants'
import StyledOcticon from '../StyledOcticon'
import sx, {SxProp} from '../sx'
import isNumeric from '../utils/isNumeric'
import {ComponentProps} from '../utils/types'

const variantSizes = {
small: 56,
Expand Down
1 change: 1 addition & 0 deletions src/CircleBadge/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export {default, CircleBadgeProps, CircleBadgeIconProps} from './CircleBadge'

0 comments on commit 7eaad16

Please sign in to comment.