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

test(e2e): add tests for FormControl #5201

Merged
merged 9 commits into from
Nov 1, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
100 changes: 100 additions & 0 deletions e2e/components/FormControl.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
import {test, expect} from '@playwright/test'
import {visit} from '../test-helpers/storybook'
import {themes} from '../test-helpers/themes'

const stories = [
{
title: 'Default',
id: 'components-form-control--default',
},
{
title: 'Custom Required',
id: 'components-form-control-features--custom-required',
},
{
title: 'Disabled Inputs',
id: 'components-form-control-features--disabled-inputs',
},
{
title: 'Form Control with Custom Input',
id: 'components-formcontrol-features--form-control-with-custom-input',
},
{
title: 'Single Input',
id: 'components-formcontrol-features--single-input',
},
{
title: 'Validation Example',
id: 'components-formcontrol-features--validation-example',
},
{
title: 'With Checkbox And Radio Inputs',
id: 'components-formcontrol-features--with-checkbox-and-radio-inputs',
},
{
title: 'With Complex Inputs',
id: 'components-formcontrol-features--with-complex-inputs',
},
{
title: 'With Leading Visual',
id: 'components-formcontrol-features--with-leading-visual',
},
{
title: 'With Select Panel',
id: 'components-formcontrol-features--with-select-panel',
},
{
title: 'With Caption',
id: 'components-formcontrol-features--with-caption',
},
{
title: 'With Hidden Label',
id: 'components-formcontrol-features--with-hidden-label',
},
{
title: 'With Required Indicator',
id: 'components-formcontrol-features--with-required-indicator',
},
{
title: 'With Success Validation',
id: 'components-formcontrol-features--with-success-validation',
},
{
title: 'With Error Validation',
id: 'components-formcontrol-features--with-error-validation',
},
] as const

test.describe('FormControl', () => {
for (const story of stories) {
describe(story.title, () => {

Check failure on line 70 in e2e/components/FormControl.test.ts

View workflow job for this annotation

GitHub Actions / lint

Title must be a string
for (const theme of themes) {
test.describe(theme, () => {
test('default @vrt', async ({page}) => {
await visit(page, {
id: story.id,
globals: {
colorScheme: theme,
},
})

// Default state
expect(await page.screenshot({animations: 'disabled'})).toMatchSnapshot(
`FormControl.${story.title}.${theme}.png`,
)
})

test('axe @aat', async ({page}) => {
await visit(page, {
id: story.id,
globals: {
colorScheme: theme,
},
})
await expect(page).toHaveNoViolations()
})
})
}
})
}
})
38 changes: 38 additions & 0 deletions packages/react/src/FormControl/FormControl.features.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -407,3 +407,41 @@ export const CustomRequired = () => (
</FormControl>
</Box>
)

export const WithCaption = () => (
<FormControl>
<FormControl.Label>Example label</FormControl.Label>
<TextInput />
<FormControl.Caption>Example caption</FormControl.Caption>
</FormControl>
)

export const WithHiddenLabel = () => (
<FormControl>
<FormControl.Label visuallyHidden>Example label</FormControl.Label>
<TextInput />
</FormControl>
)

export const WithRequiredIndicator = () => (
<FormControl required>
<FormControl.Label requiredIndicator>Example label</FormControl.Label>
<TextInput />
</FormControl>
)

export const WithSuccessValidation = () => (
<FormControl required>
<FormControl.Label requiredIndicator>Example label</FormControl.Label>
<TextInput defaultValue="Input value" />
<FormControl.Validation variant="success">Example success validation message</FormControl.Validation>
</FormControl>
)

export const WithErrorValidation = () => (
<FormControl required>
<FormControl.Label requiredIndicator>Example label</FormControl.Label>
<TextInput defaultValue="Input value" />
<FormControl.Validation variant="error">Example error validation message</FormControl.Validation>
</FormControl>
)
Loading