Skip to content

Commit

Permalink
test(e2e): add tests for FormControl (#5201)
Browse files Browse the repository at this point in the history
* test(e2e): add tests for FormControl

* test: prefix describe with test

* chore: update story id

* test(vrt): update snapshots

* fix(FormControl.Caption): update color when disabled

* chore: add changeset

* test(vrt): update snapshots

* chore: remove unused imports

---------

Co-authored-by: Josh Black <joshblack@users.noreply.github.com>
  • Loading branch information
joshblack and joshblack authored Nov 1, 2024
1 parent d349cfc commit 29a9770
Show file tree
Hide file tree
Showing 149 changed files with 157 additions and 16 deletions.
5 changes: 5 additions & 0 deletions .changeset/nice-shoes-fail.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@primer/react": patch
---

Update the foreground color for FormControl.Caption to use the control tokens when disabled
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.
104 changes: 104 additions & 0 deletions e2e/components/FormControl.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
import {test, expect} from '@playwright/test'
import {visit} from '../test-helpers/storybook'
import {themes} from '../test-helpers/themes'

const stories = [
{
title: 'Default',
id: 'components-formcontrol--default',
},
{
title: 'Custom Required',
id: 'components-formcontrol-features--custom-required',
},
{
title: 'Disabled Inputs',
id: 'components-formcontrol-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 Caption And Disabled',
id: 'components-formcontrol-features--with-caption-and-disabled',
},
{
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) {
test.describe(story.title, () => {
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()
})
})
}
})
}
})
46 changes: 46 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,49 @@ 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 WithCaptionAndDisabled = () => (
<FormControl disabled>
<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>
)
13 changes: 1 addition & 12 deletions packages/react/src/FormControl/FormControl.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,21 +1,10 @@
import React, {useState} from 'react'
import type {Meta} from '@storybook/react'
import {BaseStyles, Box, Checkbox, FormControl, TextInput, TextInputWithTokens, ThemeProvider, theme} from '..'
import {Box, Checkbox, FormControl, TextInput, TextInputWithTokens} from '..'
import type {FormValidationStatus} from '../utils/types/FormValidationStatus'

export default {
title: 'Components/FormControl',
decorators: [
Story => {
return (
<ThemeProvider theme={theme}>
<BaseStyles>
<Story />
</BaseStyles>
</ThemeProvider>
)
},
],
argTypes: {
disabled: {
type: 'boolean',
Expand Down
5 changes: 1 addition & 4 deletions packages/react/src/internal/components/InputCaption.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,9 @@ type Props = {

const InputCaption: React.FC<React.PropsWithChildren<Props>> = ({children, disabled, id, sx}) => (
<Text
color={disabled ? 'fg.subtle' : 'fg.muted'}
display="block"
fontSize={0}
id={id}
sx={{
color: disabled ? 'fg.subtle' : 'fg.muted',
color: disabled ? 'var(--control-fgColor-disabled)' : 'var(--fgColor-muted)',
display: 'block',
fontSize: 0,
...sx,
Expand Down

0 comments on commit 29a9770

Please sign in to comment.