Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor(LabelGroup): add files to folder, add storybook and e2e tests. #3131

Merged
merged 3 commits into from
Apr 6, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/content/LabelGroup.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ status: Alpha
componentId: label_group
---

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

## Example

Expand Down
61 changes: 61 additions & 0 deletions e2e/components/LabelGroup.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('LabelGroup', () => {
test.describe('Default', () => {
for (const theme of themes) {
test.describe(theme, () => {
test('default @vrt', async ({page}) => {
await visit(page, {
id: 'components-labelgroup--default',
globals: {
colorScheme: theme,
},
})

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

test('axe @aat', async ({page}) => {
await visit(page, {
id: 'components-labelgroup--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-labelgroup--playground',
globals: {
colorScheme: theme,
},
})

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

test('axe @aat', async ({page}) => {
await visit(page, {
id: 'components-labelgroup--playground',
globals: {
colorScheme: theme,
},
})
await expect(page).toHaveNoViolations()
})
})
}
})
})
33 changes: 19 additions & 14 deletions generated/components.json
Original file line number Diff line number Diff line change
Expand Up @@ -97,20 +97,6 @@
}
]
},
"label_group": {
"id": "label_group",
"name": "LabelGroup",
"status": "alpha",
"a11yReviewed": false,
"stories": [],
"props": [
{
"name": "sx",
"type": "SystemStyleObject"
}
],
"subcomponents": []
},
"overlay": {
"id": "overlay",
"name": "Overlay",
Expand Down Expand Up @@ -2352,6 +2338,25 @@
],
"subcomponents": []
},
"label_group": {
"id": "label_group",
"name": "LabelGroup",
"status": "alpha",
"a11yReviewed": false,
"stories": [
{
"id": "components-labelgroup--default",
"code": "() => (\n <LabelGroup>\n <Label>Default label</Label>\n <Label variant=\"danger\">\n Label with background indicating a closed PR state\n </Label>\n <Label variant=\"primary\">Default outline label</Label>\n </LabelGroup>\n)"
}
],
"props": [
{
"name": "sx",
"type": "SystemStyleObject"
}
],
"subcomponents": []
},
"link": {
"id": "link",
"name": "Link",
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 @@ -596,6 +596,21 @@ const components = new Map([
],
},
],
[
'LabelGroup',
{
stories: [
{
id: 'components-labelgroup--default',
name: 'Default',
},
{
id: 'components-labelgroup--playground',
name: 'Playground',
},
],
},
],
[
'Link',
{
Expand Down
File renamed without changes.
34 changes: 34 additions & 0 deletions src/LabelGroup/LabelGroup.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import React from 'react'
import {Meta, ComponentStory} from '@storybook/react'
import LabelGroup from './LabelGroup'
import Label from '../Label'

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

export const Default = () => (
<LabelGroup>
<Label>Default label</Label>
<Label variant="danger">Label with background indicating a closed PR state</Label>
<Label variant="primary">Default outline label</Label>
</LabelGroup>
)

export const Playground: ComponentStory<typeof LabelGroup> = args => (
<LabelGroup {...args}>
<Label>Default label</Label>
<Label variant="danger">Label with background indicating a closed PR state</Label>
<Label variant="primary">Default outline label</Label>
</LabelGroup>
)

Playground.argTypes = {
sx: {
controls: false,
table: {
disable: true,
},
},
}
6 changes: 3 additions & 3 deletions src/LabelGroup.tsx → src/LabelGroup/LabelGroup.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'

const LabelGroup = styled.span<SxProp>`
& * {
Expand Down
1 change: 1 addition & 0 deletions src/LabelGroup/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export {default, LabelGroupProps} from './LabelGroup'