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 <radglob@users.noreply.github.com>
  • Loading branch information
radglob and radglob committed Apr 4, 2023
1 parent bc480e2 commit cdcec7e
Show file tree
Hide file tree
Showing 26 changed files with 209 additions and 6 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()
})
})
}
})
})
79 changes: 79 additions & 0 deletions generated/components.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,21 @@
],
"subcomponents": []
},
<<<<<<< HEAD
"circle_badge": {
"id": "circle_badge",
"name": "CircleBadge",
=======
"circle_octicon": {
"id": "circle_octicon",
"name": "CircleOcticon",
>>>>>>> 7eaad1600 (refactor(CircleBadge): move files into folder, add e2e tests. (#3118))
"status": "alpha",
"a11yReviewed": false,
"stories": [],
"props": [
{
<<<<<<< HEAD
"name": "variant",
"type": "'small' | 'medium' | 'large'",
"defaultValue": "'medium'",
Expand All @@ -52,12 +59,23 @@
"name": "as",
"type": "React.ElementType",
"defaultValue": "\"div\""
=======
"name": "icon",
"type": "Octicon"
},
{
"name": "size",
"defaultValue": "32",
"type": "number",
"description": "Set the width and height of the icon in pixels."
>>>>>>> 7eaad1600 (refactor(CircleBadge): move files into folder, add e2e tests. (#3118))
},
{
"name": "sx",
"type": "SystemStyleObject"
}
],
<<<<<<< HEAD
"subcomponents": [
{
"name": "CircleBadge.Icon",
Expand All @@ -74,6 +92,9 @@
}
}
]
=======
"subcomponents": []
>>>>>>> 7eaad1600 (refactor(CircleBadge): move files into folder, add e2e tests. (#3118))
},
"dialog": {
"id": "dialog",
Expand Down Expand Up @@ -1717,19 +1738,31 @@
}
]
},
<<<<<<< HEAD
"circle_octicon": {
"id": "circle_octicon",
"name": "CircleOcticon",
=======
"circle_badge": {
"id": "circle_badge",
"name": "CircleBadge",
>>>>>>> 7eaad1600 (refactor(CircleBadge): move files into folder, add e2e tests. (#3118))
"status": "alpha",
"a11yReviewed": false,
"stories": [
{
<<<<<<< HEAD
"id": "components-circleocticon--default",
"code": "() => (\n <CircleOcticon\n icon={CheckIcon}\n size={32}\n sx={{\n backgroundColor: 'success.fg',\n color: 'fg.onEmphasis',\n }}\n />\n)"
=======
"id": "components-circlebadge--default",
"code": "() => (\n <CircleBadge>\n <CircleBadge.Icon icon={ZapIcon} />\n </CircleBadge>\n)"
>>>>>>> 7eaad1600 (refactor(CircleBadge): move files into folder, add e2e tests. (#3118))
}
],
"props": [
{
<<<<<<< HEAD
"name": "icon",
"type": "Octicon"
},
Expand All @@ -1738,13 +1771,59 @@
"defaultValue": "32",
"type": "number",
"description": "Set the width and height of the icon in pixels."
=======
"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\""
>>>>>>> 7eaad1600 (refactor(CircleBadge): move files into folder, add e2e tests. (#3118))
},
{
"name": "sx",
"type": "SystemStyleObject"
}
],
<<<<<<< HEAD
"subcomponents": []
=======
"subcomponents": [
{
"name": "CircleBadge.Icon",
"props": [
{
"name": "as",
"type": "React.ElementType",
"defaultValue": "StyledOcticon"
}
],
"passthrough": {
"element": "StyledOcticon",
"url": "/StyledOcticon"
}
}
]
>>>>>>> 7eaad1600 (refactor(CircleBadge): move files into folder, add e2e tests. (#3118))
},
"counter_label": {
"id": "counter_label",
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 @@ -325,6 +325,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 cdcec7e

Please sign in to comment.