diff --git a/.changeset/early-eels-shake.md b/.changeset/early-eels-shake.md new file mode 100644 index 0000000000..9358627528 --- /dev/null +++ b/.changeset/early-eels-shake.md @@ -0,0 +1,5 @@ +--- +"@rocket.chat/fuselage": minor +--- + +feat(fuselage): new `InputBox` small variant diff --git a/packages/fuselage/src/components/EmailInput/EmailInput.spec.tsx b/packages/fuselage/src/components/EmailInput/EmailInput.spec.tsx index fb1bd27aa1..849c54dc15 100644 --- a/packages/fuselage/src/components/EmailInput/EmailInput.spec.tsx +++ b/packages/fuselage/src/components/EmailInput/EmailInput.spec.tsx @@ -1,5 +1,6 @@ import { composeStories } from '@storybook/testing-react'; import { render } from '@testing-library/react'; +import { axe } from 'jest-axe'; import React from 'react'; import * as stories from './EmailInput.stories'; @@ -8,6 +9,14 @@ const { Default } = composeStories(stories); describe('[EmailInput Component]', () => { it('renders without crashing', () => { - render(); + const tree = render(); + expect(tree.baseElement).toMatchSnapshot(); + }); + + it('%s should have no a11y violations', async () => { + const { container } = render(); + + const results = await axe(container); + expect(results).toHaveNoViolations(); }); }); diff --git a/packages/fuselage/src/components/EmailInput/EmailInput.stories.tsx b/packages/fuselage/src/components/EmailInput/EmailInput.stories.tsx index 40116efe15..964a85fade 100644 --- a/packages/fuselage/src/components/EmailInput/EmailInput.stories.tsx +++ b/packages/fuselage/src/components/EmailInput/EmailInput.stories.tsx @@ -27,13 +27,13 @@ export default { } as ComponentMeta; const Template: ComponentStory = (args) => ( - + ); export const Default: ComponentStory = Template.bind({}); export const WithIconAddon: ComponentStory = () => ( - } /> + } /> ); export const Invalid: ComponentStory = Template.bind({}); @@ -59,28 +59,54 @@ WithValue.args = { }; export const States: ComponentStory = () => ( - {} }} - xAxis={{ - 'default': {}, - 'with placeholder': { placeholder: 'Placeholder' }, - 'with value': { value: 'support@rocket.chat' }, - 'with icon': { - addon: , - value: 'support@rocket.chat', - }, - }} - yAxis={{ - 'default': {}, - 'hover': { className: 'hover' }, - 'active': { className: 'active' }, - 'focus': { className: 'focus' }, - 'disabled': { disabled: true }, - 'errored': { error: 'Error' }, - 'errored + hover': { className: 'hover', error: 'Error' }, - 'errored + active': { className: 'active', error: 'Error' }, - 'errored + focus': { className: 'focus', error: 'Error' }, - }} - /> + <> + {}, 'aria-label': 'email' }} + xAxis={{ + 'default': {}, + 'with placeholder': { placeholder: 'Placeholder' }, + 'with value': { value: 'support@rocket.chat' }, + 'with icon': { + addon: , + value: 'support@rocket.chat', + }, + }} + yAxis={{ + 'default': {}, + 'hover': { className: 'hover' }, + 'active': { className: 'active' }, + 'focus': { className: 'focus' }, + 'disabled': { disabled: true }, + 'errored': { error: 'Error' }, + 'errored + hover': { className: 'hover', error: 'Error' }, + 'errored + active': { className: 'active', error: 'Error' }, + 'errored + focus': { className: 'focus', error: 'Error' }, + }} + /> + {}, 'small': true, 'aria-label': 'email' }} + xAxis={{ + 'small': {}, + 'with placeholder': { placeholder: 'Placeholder' }, + 'with value': { value: 'support@rocket.chat' }, + 'with icon': { + addon: , + value: 'support@rocket.chat', + }, + }} + yAxis={{ + 'small': {}, + 'hover': { className: 'hover' }, + 'active': { className: 'active' }, + 'focus': { className: 'focus' }, + 'disabled': { disabled: true }, + 'errored': { error: 'Error' }, + 'errored + hover': { className: 'hover', error: 'Error' }, + 'errored + active': { className: 'active', error: 'Error' }, + 'errored + focus': { className: 'focus', error: 'Error' }, + }} + /> + ); diff --git a/packages/fuselage/src/components/EmailInput/__snapshots__/EmailInput.spec.tsx.snap b/packages/fuselage/src/components/EmailInput/__snapshots__/EmailInput.spec.tsx.snap new file mode 100644 index 0000000000..f0627fbbda --- /dev/null +++ b/packages/fuselage/src/components/EmailInput/__snapshots__/EmailInput.spec.tsx.snap @@ -0,0 +1,14 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`[EmailInput Component] renders without crashing 1`] = ` + +
+ +
+ +`; diff --git a/packages/fuselage/src/components/InputBox/InputBox.spec.tsx b/packages/fuselage/src/components/InputBox/InputBox.spec.tsx index fa45915f2b..12c293dc80 100644 --- a/packages/fuselage/src/components/InputBox/InputBox.spec.tsx +++ b/packages/fuselage/src/components/InputBox/InputBox.spec.tsx @@ -1,14 +1,22 @@ +import { composeStories } from '@storybook/testing-react'; import { render } from '@testing-library/react'; +import { axe } from 'jest-axe'; import React from 'react'; -import { InputBox } from '.'; +import * as stories from './InputBox.stories'; + +const { Default } = composeStories(stories); describe('[InputBox Component]', () => { - it('renders InputBox without crashing', () => { - render(); + it('renders without crashing', () => { + const tree = render(); + expect(tree.baseElement).toMatchSnapshot(); }); - it('renders InputBox.Skeleton without crashing', () => { - render(); + it('%s should have no a11y violations', async () => { + const { container } = render(); + + const results = await axe(container); + expect(results).toHaveNoViolations(); }); }); diff --git a/packages/fuselage/src/components/InputBox/InputBox.stories.tsx b/packages/fuselage/src/components/InputBox/InputBox.stories.tsx index ff8ba77d15..012ee29523 100644 --- a/packages/fuselage/src/components/InputBox/InputBox.stories.tsx +++ b/packages/fuselage/src/components/InputBox/InputBox.stories.tsx @@ -9,7 +9,7 @@ import { import type { ComponentStory, ComponentMeta } from '@storybook/react'; import React from 'react'; -import { Icon, InputBox } from '../..'; +import { Icon, InputBox, Box } from '../..'; export default { title: 'Inputs/InputBox', @@ -34,7 +34,7 @@ export default { } as ComponentMeta; const Template: ComponentStory = (args) => ( - + ); export const Default: ComponentStory = Template.bind({}); @@ -87,3 +87,26 @@ export const Skeleton: ComponentStory = () => ( ); Skeleton.storyName = 'InputBox.Skeleton'; + +export const SmallVariants: ComponentStory = () => ( + + + } + aria-label='Search' + /> + +); +SmallVariants.args = { + placeholder: 'Search', + small: true, + onChange: action('change'), +}; diff --git a/packages/fuselage/src/components/InputBox/InputBox.styles.scss b/packages/fuselage/src/components/InputBox/InputBox.styles.scss index f8a8a9ce32..871485ab45 100644 --- a/packages/fuselage/src/components/InputBox/InputBox.styles.scss +++ b/packages/fuselage/src/components/InputBox/InputBox.styles.scss @@ -193,6 +193,31 @@ } } + &__wrapper:has(.rcx-input-box--small) { + align-items: center; + + min-width: lengths.size(112); + max-height: lengths.size(28); + padding: lengths.padding(4) lengths.padding(16); + } + + &--small { + @include typography.use-font-scale(c1); + + &:not(.rcx-input-box--undecorated) { + @extend %input; + min-width: lengths.size(112); + + min-height: lengths.size(28); + padding: lengths.padding(4) lengths.padding(16); + + &:invalid, + &.invalid { + @extend %input--invalid; + } + } + } + @include with-colors( $color: $input-colors-color, $placeholder-color: $input-colors-placeholder-color, @@ -241,6 +266,10 @@ .rcx-input-box__wrapper > & { width: lengths.size(none); min-width: lengths.size(none); + + &--small { + padding: lengths.padding(none); + } } } diff --git a/packages/fuselage/src/components/InputBox/InputBox.tsx b/packages/fuselage/src/components/InputBox/InputBox.tsx index 0345313b60..b7ebc8c3da 100644 --- a/packages/fuselage/src/components/InputBox/InputBox.tsx +++ b/packages/fuselage/src/components/InputBox/InputBox.tsx @@ -23,6 +23,7 @@ type InputBoxProps = ComponentProps & { error?: string; placeholder?: string; placeholderVisible?: boolean; + small?: boolean; type: | 'button' | 'checkbox' @@ -69,6 +70,7 @@ export const InputBox = forwardRef(function InputBox( multiple, placeholderVisible, type = 'text', + small, onChange, ...props }: InputBoxProps, @@ -140,6 +142,7 @@ export const InputBox = forwardRef(function InputBox( rcx-input-box--multiple={multiple} rcx-input-box--placeholder-visible={placeholderVisible} rcx-input-box--type={type} + rcx-input-box--small={small} {...props} /> ); @@ -173,6 +176,7 @@ export const InputBox = forwardRef(function InputBox( rcx-input-box--placeholder-visible={placeholderVisible} rcx-input-box--type={type} rcx-input-box--undecorated + rcx-input-box--small={small} {...props} /> diff --git a/packages/fuselage/src/components/InputBox/__snapshots__/InputBox.spec.tsx.snap b/packages/fuselage/src/components/InputBox/__snapshots__/InputBox.spec.tsx.snap new file mode 100644 index 0000000000..8842b48a93 --- /dev/null +++ b/packages/fuselage/src/components/InputBox/__snapshots__/InputBox.spec.tsx.snap @@ -0,0 +1,15 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`[InputBox Component] renders without crashing 1`] = ` + +
+ +
+ +`; diff --git a/packages/fuselage/src/components/NumberInput/NumberInput.spec.tsx b/packages/fuselage/src/components/NumberInput/NumberInput.spec.tsx index 88264ab948..5146e5df1d 100644 --- a/packages/fuselage/src/components/NumberInput/NumberInput.spec.tsx +++ b/packages/fuselage/src/components/NumberInput/NumberInput.spec.tsx @@ -1,10 +1,22 @@ +import { composeStories } from '@storybook/testing-react'; import { render } from '@testing-library/react'; +import { axe } from 'jest-axe'; import React from 'react'; -import { NumberInput } from '.'; +import * as stories from './NumberInput.stories'; + +const { Default } = composeStories(stories); describe('[NumberInput Component]', () => { it('renders without crashing', () => { - render(); + const tree = render(); + expect(tree.baseElement).toMatchSnapshot(); + }); + + it('%s should have no a11y violations', async () => { + const { container } = render(); + + const results = await axe(container); + expect(results).toHaveNoViolations(); }); }); diff --git a/packages/fuselage/src/components/NumberInput/NumberInput.stories.tsx b/packages/fuselage/src/components/NumberInput/NumberInput.stories.tsx index 03fd7db447..a69a01fbc7 100644 --- a/packages/fuselage/src/components/NumberInput/NumberInput.stories.tsx +++ b/packages/fuselage/src/components/NumberInput/NumberInput.stories.tsx @@ -33,7 +33,7 @@ export default { } as ComponentMeta; const Template: ComponentStory = (args) => ( - + ); export const Default: ComponentStory = Template.bind({}); @@ -60,25 +60,54 @@ WithPlaceholder.args = { }; export const States: ComponentStory = () => ( - {} }} - xAxis={{ - 'default': {}, - 'with placeholder': { placeholder: 'Placeholder' }, - 'with value': { value: 1024 }, - 'with icon': { addon: , value: 1024 }, - }} - yAxis={{ - 'default': {}, - 'hover': { className: 'hover' }, - 'active': { className: 'active' }, - 'focus': { className: 'focus' }, - 'disabled': { disabled: true }, - 'errored': { error: 'Error' }, - 'errored + hover': { className: 'hover', error: 'Error' }, - 'errored + active': { className: 'active', error: 'Error' }, - 'errored + focus': { className: 'focus', error: 'Error' }, - }} - /> + <> + {}, 'aria-label': 'number' }} + xAxis={{ + 'default': {}, + 'with placeholder': { placeholder: 'Placeholder' }, + 'with value': { value: 1024 }, + 'with icon': { + addon: , + value: 1024, + }, + }} + yAxis={{ + 'default': {}, + 'hover': { className: 'hover' }, + 'active': { className: 'active' }, + 'focus': { className: 'focus' }, + 'disabled': { disabled: true }, + 'errored': { error: 'Error' }, + 'errored + hover': { className: 'hover', error: 'Error' }, + 'errored + active': { className: 'active', error: 'Error' }, + 'errored + focus': { className: 'focus', error: 'Error' }, + }} + /> + {}, 'small': true, 'aria-label': 'number' }} + xAxis={{ + 'small': {}, + 'with placeholder': { placeholder: 'Placeholder' }, + 'with value': { value: 1024 }, + 'with icon': { + addon: , + value: 1024, + }, + }} + yAxis={{ + 'small': {}, + 'hover': { className: 'hover' }, + 'active': { className: 'active' }, + 'focus': { className: 'focus' }, + 'disabled': { disabled: true }, + 'errored': { error: 'Error' }, + 'errored + hover': { className: 'hover', error: 'Error' }, + 'errored + active': { className: 'active', error: 'Error' }, + 'errored + focus': { className: 'focus', error: 'Error' }, + }} + /> + ); diff --git a/packages/fuselage/src/components/NumberInput/__snapshots__/NumberInput.spec.tsx.snap b/packages/fuselage/src/components/NumberInput/__snapshots__/NumberInput.spec.tsx.snap new file mode 100644 index 0000000000..0e71bc5018 --- /dev/null +++ b/packages/fuselage/src/components/NumberInput/__snapshots__/NumberInput.spec.tsx.snap @@ -0,0 +1,14 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`[NumberInput Component] renders without crashing 1`] = ` + +
+ +
+ +`; diff --git a/packages/fuselage/src/components/PasswordInput/PasswordInput.spec.tsx b/packages/fuselage/src/components/PasswordInput/PasswordInput.spec.tsx index d33439159b..6253e6099c 100644 --- a/packages/fuselage/src/components/PasswordInput/PasswordInput.spec.tsx +++ b/packages/fuselage/src/components/PasswordInput/PasswordInput.spec.tsx @@ -1,10 +1,22 @@ +import { composeStories } from '@storybook/testing-react'; import { render } from '@testing-library/react'; +import { axe } from 'jest-axe'; import React from 'react'; -import PasswordInput from '.'; +import * as stories from './PasswordInput.stories'; + +const { Default } = composeStories(stories); describe('[PasswordInput Component]', () => { it('renders without crashing', () => { - render(); + const tree = render(); + expect(tree.baseElement).toMatchSnapshot(); + }); + + it('%s should have no a11y violations', async () => { + const { container } = render(); + + const results = await axe(container); + expect(results).toHaveNoViolations(); }); }); diff --git a/packages/fuselage/src/components/PasswordInput/PasswordInput.stories.tsx b/packages/fuselage/src/components/PasswordInput/PasswordInput.stories.tsx index b00d0f399d..815c4b700d 100644 --- a/packages/fuselage/src/components/PasswordInput/PasswordInput.stories.tsx +++ b/packages/fuselage/src/components/PasswordInput/PasswordInput.stories.tsx @@ -1,50 +1,84 @@ +import type { ComponentMeta, ComponentStory } from '@storybook/react'; import React from 'react'; import { Icon, PasswordInput } from '../..'; -import PropsVariation from '../../.storybook/PropsVariation'; +import { PropsVariationSection } from '../../../.storybook/helpers'; export default { title: 'Inputs/PasswordInput', component: PasswordInput, parameters: { jest: ['PasswordInput.spec.tsx'] }, -}; +} as ComponentMeta; -export const Default = () => ; +export const Default: ComponentStory = () => ( + +); -export const WithValue = () => ; +export const WithValue = () => ( + +); export const WithIconAddon = () => ( - } /> + } /> ); -export const Invalid = () => ; +export const Invalid = () => ( + +); -export const Disabled = () => ; +export const Disabled = () => ; export const WithPlaceholder = () => ( - + ); export const States = () => ( - undefined }} - xAxis={{ - 'default': {}, - 'with placeholder': { placeholder: 'Placeholder' }, - 'with value': { value: 'Value' }, - 'with icon': { addon: , value: 'Value' }, - }} - yAxis={{ - 'default': {}, - 'hover': { className: 'hover' }, - 'active': { className: 'active' }, - 'focus': { className: 'focus' }, - 'disabled': { disabled: true }, - 'errored': { error: 'Error' }, - 'errored + hover': { className: 'hover', error: 'Error' }, - 'errored + active': { className: 'active', error: 'Error' }, - 'errored + focus': { className: 'focus', error: 'Error' }, - }} - /> + <> + undefined, 'aria-label': 'password' }} + xAxis={{ + 'default': {}, + 'with placeholder': { placeholder: 'Placeholder' }, + 'with value': { value: 'Value' }, + 'with icon': { addon: , value: 'Value' }, + }} + yAxis={{ + 'default': {}, + 'hover': { className: 'hover' }, + 'active': { className: 'active' }, + 'focus': { className: 'focus' }, + 'disabled': { disabled: true }, + 'errored': { error: 'Error' }, + 'errored + hover': { className: 'hover', error: 'Error' }, + 'errored + active': { className: 'active', error: 'Error' }, + 'errored + focus': { className: 'focus', error: 'Error' }, + }} + /> + undefined, + 'small': true, + 'aria-label': 'password', + }} + xAxis={{ + 'small': {}, + 'with placeholder': { placeholder: 'Placeholder' }, + 'with value': { value: 'Value' }, + 'with icon': { addon: , value: 'Value' }, + }} + yAxis={{ + 'small': {}, + 'hover': { className: 'hover' }, + 'active': { className: 'active' }, + 'focus': { className: 'focus' }, + 'disabled': { disabled: true }, + 'errored': { error: 'Error' }, + 'errored + hover': { className: 'hover', error: 'Error' }, + 'errored + active': { className: 'active', error: 'Error' }, + 'errored + focus': { className: 'focus', error: 'Error' }, + }} + /> + ); diff --git a/packages/fuselage/src/components/PasswordInput/__snapshots__/PasswordInput.spec.tsx.snap b/packages/fuselage/src/components/PasswordInput/__snapshots__/PasswordInput.spec.tsx.snap new file mode 100644 index 0000000000..64c9b1847a --- /dev/null +++ b/packages/fuselage/src/components/PasswordInput/__snapshots__/PasswordInput.spec.tsx.snap @@ -0,0 +1,28 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`[PasswordInput Component] renders without crashing 1`] = ` + +
+ +
+ +`; diff --git a/packages/fuselage/src/components/SearchInput/SearchInput.spec.tsx b/packages/fuselage/src/components/SearchInput/SearchInput.spec.tsx index f514dd320f..0a18c85bcb 100644 --- a/packages/fuselage/src/components/SearchInput/SearchInput.spec.tsx +++ b/packages/fuselage/src/components/SearchInput/SearchInput.spec.tsx @@ -1,10 +1,22 @@ +import { composeStories } from '@storybook/testing-react'; import { render } from '@testing-library/react'; +import { axe } from 'jest-axe'; import React from 'react'; -import { SearchInput } from '.'; +import * as stories from './SearchInput.stories'; + +const { Default } = composeStories(stories); describe('[SearchInput Component]', () => { it('renders without crashing', () => { - render(); + const tree = render(); + expect(tree.baseElement).toMatchSnapshot(); + }); + + it('%s should have no a11y violations', async () => { + const { container } = render(); + + const results = await axe(container); + expect(results).toHaveNoViolations(); }); }); diff --git a/packages/fuselage/src/components/SearchInput/SearchInput.stories.tsx b/packages/fuselage/src/components/SearchInput/SearchInput.stories.tsx index 1d116af033..d4878cda45 100644 --- a/packages/fuselage/src/components/SearchInput/SearchInput.stories.tsx +++ b/packages/fuselage/src/components/SearchInput/SearchInput.stories.tsx @@ -33,7 +33,7 @@ export default { } as ComponentMeta; const Template: ComponentStory = (args) => ( - + ); export const Default: ComponentStory = Template.bind({}); @@ -67,28 +67,54 @@ WithValue.args = { }; export const States: ComponentStory = () => ( - {} }} - xAxis={{ - 'default': {}, - 'with placeholder': { placeholder: 'Placeholder' }, - 'with value': { value: 'Value' }, - 'with icon': { - addon: , - value: 'Value', - }, - }} - yAxis={{ - 'default': {}, - 'hover': { className: 'hover' }, - 'active': { className: 'active' }, - 'focus': { className: 'focus' }, - 'disabled': { disabled: true }, - 'errored': { error: 'Error' }, - 'errored + hover': { className: 'hover', error: 'Error' }, - 'errored + active': { className: 'active', error: 'Error' }, - 'errored + focus': { className: 'focus', error: 'Error' }, - }} - /> + <> + {}, 'aria-label': 'search' }} + xAxis={{ + 'default': {}, + 'with placeholder': { placeholder: 'Placeholder' }, + 'with value': { value: 'Value' }, + 'with icon': { + addon: , + value: 'Value', + }, + }} + yAxis={{ + 'default': {}, + 'hover': { className: 'hover' }, + 'active': { className: 'active' }, + 'focus': { className: 'focus' }, + 'disabled': { disabled: true }, + 'errored': { error: 'Error' }, + 'errored + hover': { className: 'hover', error: 'Error' }, + 'errored + active': { className: 'active', error: 'Error' }, + 'errored + focus': { className: 'focus', error: 'Error' }, + }} + /> + {}, 'small': true, 'aria-label': 'search' }} + xAxis={{ + 'small': {}, + 'with placeholder': { placeholder: 'Placeholder' }, + 'with value': { value: 'Value' }, + 'with icon': { + addon: , + value: 'Value', + }, + }} + yAxis={{ + 'small': {}, + 'hover': { className: 'hover' }, + 'active': { className: 'active' }, + 'focus': { className: 'focus' }, + 'disabled': { disabled: true }, + 'errored': { error: 'Error' }, + 'errored + hover': { className: 'hover', error: 'Error' }, + 'errored + active': { className: 'active', error: 'Error' }, + 'errored + focus': { className: 'focus', error: 'Error' }, + }} + /> + ); diff --git a/packages/fuselage/src/components/SearchInput/__snapshots__/SearchInput.spec.tsx.snap b/packages/fuselage/src/components/SearchInput/__snapshots__/SearchInput.spec.tsx.snap new file mode 100644 index 0000000000..9a896795d9 --- /dev/null +++ b/packages/fuselage/src/components/SearchInput/__snapshots__/SearchInput.spec.tsx.snap @@ -0,0 +1,14 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`[SearchInput Component] renders without crashing 1`] = ` + +
+ +
+ +`; diff --git a/packages/fuselage/src/components/Select/Select.stories.tsx b/packages/fuselage/src/components/Select/Select.stories.tsx index 6e2679d42b..5023b304f2 100644 --- a/packages/fuselage/src/components/Select/Select.stories.tsx +++ b/packages/fuselage/src/components/Select/Select.stories.tsx @@ -10,6 +10,7 @@ import React from 'react'; import type { SelectOption } from '../..'; import { Select } from '../..'; +import PropsVariationSection from '../../.storybook/PropsVariation'; const options: SelectOption[] = Array.from({ length: 12, @@ -36,12 +37,21 @@ export default { }, } as ComponentMeta; -const Template: ComponentStory = (args) => +); const TemplateControlled: ComponentStory = (args) => { const [value, setValue] = React.useState('3'); - return + ); }; export const Default: ComponentStory = Template.bind({}); @@ -78,3 +88,33 @@ NoPlaceholder.args = { 'aria-label': 'No placeholder select', options, }; + +export const States = () => ( + <> + ( + + + + + + + + + + + +`; diff --git a/packages/fuselage/src/components/TelephoneInput/TelephoneInput.spec.tsx b/packages/fuselage/src/components/TelephoneInput/TelephoneInput.spec.tsx index 7d5cbe55af..b66857bc7a 100644 --- a/packages/fuselage/src/components/TelephoneInput/TelephoneInput.spec.tsx +++ b/packages/fuselage/src/components/TelephoneInput/TelephoneInput.spec.tsx @@ -1,10 +1,22 @@ +import { composeStories } from '@storybook/testing-react'; import { render } from '@testing-library/react'; +import { axe } from 'jest-axe'; import React from 'react'; -import { TelephoneInput } from '.'; +import * as stories from './TelephoneInput.stories'; + +const { Default } = composeStories(stories); describe('[TelephoneInput Component]', () => { it('renders without crashing', () => { - render(); + const tree = render(); + expect(tree.baseElement).toMatchSnapshot(); + }); + + it('%s should have no a11y violations', async () => { + const { container } = render(); + + const results = await axe(container); + expect(results).toHaveNoViolations(); }); }); diff --git a/packages/fuselage/src/components/TelephoneInput/TelephoneInput.stories.tsx b/packages/fuselage/src/components/TelephoneInput/TelephoneInput.stories.tsx index bc468092b9..9fd60d56c8 100644 --- a/packages/fuselage/src/components/TelephoneInput/TelephoneInput.stories.tsx +++ b/packages/fuselage/src/components/TelephoneInput/TelephoneInput.stories.tsx @@ -26,7 +26,7 @@ export default { } as ComponentMeta; const Template: ComponentStory = (args) => ( - + ); export const Default: ComponentStory = Template.bind({}); @@ -57,28 +57,58 @@ WithValue.args = { }; export const States: ComponentStory = () => ( - {} }} - xAxis={{ - 'default': {}, - 'with placeholder': { placeholder: 'Placeholder' }, - 'with value': { value: '+1234567890' }, - 'with icon': { - addon: , - value: '+1234567890', - }, - }} - yAxis={{ - 'default': {}, - 'hover': { className: 'hover' }, - 'active': { className: 'active' }, - 'focus': { className: 'focus' }, - 'disabled': { disabled: true }, - 'errored': { error: 'Error' }, - 'errored + hover': { className: 'hover', error: 'Error' }, - 'errored + active': { className: 'active', error: 'Error' }, - 'errored + focus': { className: 'focus', error: 'Error' }, - }} - /> + <> + {}, 'aria-label': 'telephone' }} + xAxis={{ + 'default': {}, + 'with placeholder': { placeholder: 'Placeholder' }, + 'with value': { value: '+1234567890' }, + 'with icon': { + addon: , + value: '+1234567890', + }, + }} + yAxis={{ + 'default': {}, + 'hover': { className: 'hover' }, + 'active': { className: 'active' }, + 'focus': { className: 'focus' }, + 'disabled': { disabled: true }, + 'errored': { error: 'Error' }, + 'errored + hover': { className: 'hover', error: 'Error' }, + 'errored + active': { className: 'active', error: 'Error' }, + 'errored + focus': { className: 'focus', error: 'Error' }, + }} + /> + {}, + 'small': true, + 'aria-label': 'telephone', + }} + xAxis={{ + 'small': {}, + 'with placeholder': { placeholder: 'Placeholder' }, + 'with value': { value: '+1234567890' }, + 'with icon': { + addon: , + value: '+1234567890', + }, + }} + yAxis={{ + 'small': {}, + 'hover': { className: 'hover' }, + 'active': { className: 'active' }, + 'focus': { className: 'focus' }, + 'disabled': { disabled: true }, + 'errored': { error: 'Error' }, + 'errored + hover': { className: 'hover', error: 'Error' }, + 'errored + active': { className: 'active', error: 'Error' }, + 'errored + focus': { className: 'focus', error: 'Error' }, + }} + /> + ); diff --git a/packages/fuselage/src/components/TelephoneInput/__snapshots__/TelephoneInput.spec.tsx.snap b/packages/fuselage/src/components/TelephoneInput/__snapshots__/TelephoneInput.spec.tsx.snap new file mode 100644 index 0000000000..e6b540160d --- /dev/null +++ b/packages/fuselage/src/components/TelephoneInput/__snapshots__/TelephoneInput.spec.tsx.snap @@ -0,0 +1,14 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`[TelephoneInput Component] renders without crashing 1`] = ` + +
+ +
+ +`; diff --git a/packages/fuselage/src/components/TextInput/TextInput.spec.tsx b/packages/fuselage/src/components/TextInput/TextInput.spec.tsx index bc9d399891..4d78e3376f 100644 --- a/packages/fuselage/src/components/TextInput/TextInput.spec.tsx +++ b/packages/fuselage/src/components/TextInput/TextInput.spec.tsx @@ -1,10 +1,22 @@ +import { composeStories } from '@storybook/testing-react'; import { render } from '@testing-library/react'; +import { axe } from 'jest-axe'; import React from 'react'; -import { TextInput } from '.'; +import * as stories from './TextInput.stories'; -describe('[TextInput]', () => { +const { Default } = composeStories(stories); + +describe('[TextInput Component]', () => { it('renders without crashing', () => { - render(); + const tree = render(); + expect(tree.baseElement).toMatchSnapshot(); + }); + + it('%s should have no a11y violations', async () => { + const { container } = render(); + + const results = await axe(container); + expect(results).toHaveNoViolations(); }); }); diff --git a/packages/fuselage/src/components/TextInput/TextInput.stories.tsx b/packages/fuselage/src/components/TextInput/TextInput.stories.tsx index fa090e2865..88829e6984 100644 --- a/packages/fuselage/src/components/TextInput/TextInput.stories.tsx +++ b/packages/fuselage/src/components/TextInput/TextInput.stories.tsx @@ -26,7 +26,7 @@ export default { } as ComponentMeta; const Template: ComponentStory = (args) => ( - + ); export const Default: ComponentStory = Template.bind({}); @@ -61,28 +61,54 @@ WithValue.args = { }; export const States: ComponentStory = () => ( - {} }} - xAxis={{ - 'default': {}, - 'with placeholder': { placeholder: 'Placeholder' }, - 'with value': { value: 'Value' }, - 'with icon': { - addon: , - value: 'Value', - }, - }} - yAxis={{ - 'default': {}, - 'hover': { className: 'hover' }, - 'active': { className: 'active' }, - 'focus': { className: 'focus' }, - 'disabled': { disabled: true }, - 'errored': { error: 'Error' }, - 'errored + hover': { className: 'hover', error: 'Error' }, - 'errored + active': { className: 'active', error: 'Error' }, - 'errored + focus': { className: 'focus', error: 'Error' }, - }} - /> + <> + {}, 'aria-label': 'text' }} + xAxis={{ + 'default': {}, + 'with placeholder': { placeholder: 'Placeholder' }, + 'with value': { value: 'Value' }, + 'with icon': { + addon: , + value: 'Value', + }, + }} + yAxis={{ + 'default': {}, + 'hover': { className: 'hover' }, + 'active': { className: 'active' }, + 'focus': { className: 'focus' }, + 'disabled': { disabled: true }, + 'errored': { error: 'Error' }, + 'errored + hover': { className: 'hover', error: 'Error' }, + 'errored + active': { className: 'active', error: 'Error' }, + 'errored + focus': { className: 'focus', error: 'Error' }, + }} + /> + {}, 'small': true, 'aria-label': 'text' }} + xAxis={{ + 'small': {}, + 'with placeholder': { placeholder: 'Placeholder' }, + 'with value': { value: 'Value' }, + 'with icon': { + addon: , + value: 'Value', + }, + }} + yAxis={{ + 'small': {}, + 'hover': { className: 'hover' }, + 'active': { className: 'active' }, + 'focus': { className: 'focus' }, + 'disabled': { disabled: true }, + 'errored': { error: 'Error' }, + 'errored + hover': { className: 'hover', error: 'Error' }, + 'errored + active': { className: 'active', error: 'Error' }, + 'errored + focus': { className: 'focus', error: 'Error' }, + }} + /> + ); diff --git a/packages/fuselage/src/components/TextInput/__snapshots__/TextInput.spec.tsx.snap b/packages/fuselage/src/components/TextInput/__snapshots__/TextInput.spec.tsx.snap new file mode 100644 index 0000000000..3dee7439fa --- /dev/null +++ b/packages/fuselage/src/components/TextInput/__snapshots__/TextInput.spec.tsx.snap @@ -0,0 +1,14 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`[TextInput Component] renders without crashing 1`] = ` + +
+ +
+ +`; diff --git a/packages/fuselage/src/components/UrlInput/UrlInput.spec.tsx b/packages/fuselage/src/components/UrlInput/UrlInput.spec.tsx index c86b8a6572..34a1f77195 100644 --- a/packages/fuselage/src/components/UrlInput/UrlInput.spec.tsx +++ b/packages/fuselage/src/components/UrlInput/UrlInput.spec.tsx @@ -1,10 +1,22 @@ +import { composeStories } from '@storybook/testing-react'; import { render } from '@testing-library/react'; +import { axe } from 'jest-axe'; import React from 'react'; -import UrlInput from '.'; +import * as stories from './UrlInput.stories'; + +const { Default } = composeStories(stories); describe('[UrlInput Component]', () => { it('renders without crashing', () => { - render(); + const tree = render(); + expect(tree.baseElement).toMatchSnapshot(); + }); + + it('%s should have no a11y violations', async () => { + const { container } = render(); + + const results = await axe(container); + expect(results).toHaveNoViolations(); }); }); diff --git a/packages/fuselage/src/components/UrlInput/UrlInput.stories.tsx b/packages/fuselage/src/components/UrlInput/UrlInput.stories.tsx index 0b9bbed52f..2710a10730 100644 --- a/packages/fuselage/src/components/UrlInput/UrlInput.stories.tsx +++ b/packages/fuselage/src/components/UrlInput/UrlInput.stories.tsx @@ -1,7 +1,8 @@ +import type { ComponentMeta, ComponentStory } from '@storybook/react'; import React from 'react'; import { Icon, UrlInput } from '../..'; -import PropsVariation from '../../.storybook/PropsVariation'; +import { PropsVariationSection } from '../../../.storybook/helpers'; export default { title: 'Inputs/UrlInput', @@ -9,45 +10,81 @@ export default { parameters: { jest: ['UrlInput.spec.tsx'], }, -}; +} as ComponentMeta; -export const Default = () => ; +export const Default: ComponentStory = () => ( + +); export const WithIconAddon = () => ( - } /> + } /> ); -export const Invalid = () => ; +export const Invalid = () => ; -export const Disabled = () => ; +export const Disabled = () => ; -export const WithPlaceholder = () => ; +export const WithPlaceholder = () => ( + +); -export const WithValue = () => ; +export const WithValue = () => ( + +); export const States = () => ( - undefined }} - xAxis={{ - 'default': {}, - 'with placeholder': { placeholder: 'Placeholder' }, - 'with value': { value: 'https://rocket.chat' }, - 'with icon': { - addon: , - value: 'https://rocket.chat', - }, - }} - yAxis={{ - 'default': {}, - 'hover': { className: 'hover' }, - 'active': { className: 'active' }, - 'focus': { className: 'focus' }, - 'disabled': { disabled: true }, - 'errored': { error: 'Error' }, - 'errored + hover': { className: 'hover', error: 'Error' }, - 'errored + active': { className: 'active', error: 'Error' }, - 'errored + focus': { className: 'focus', error: 'Error' }, - }} - /> + <> + undefined, 'aria-label': 'url' }} + xAxis={{ + 'default': {}, + 'with placeholder': { placeholder: 'Placeholder' }, + 'with value': { value: 'https://rocket.chat' }, + 'with icon': { + addon: , + value: 'https://rocket.chat', + }, + }} + yAxis={{ + 'default': {}, + 'hover': { className: 'hover' }, + 'active': { className: 'active' }, + 'focus': { className: 'focus' }, + 'disabled': { disabled: true }, + 'errored': { error: 'Error' }, + 'errored + hover': { className: 'hover', error: 'Error' }, + 'errored + active': { className: 'active', error: 'Error' }, + 'errored + focus': { className: 'focus', error: 'Error' }, + }} + /> + undefined, + 'small': true, + 'aria-label': 'url', + }} + xAxis={{ + 'small': {}, + 'with placeholder': { placeholder: 'Placeholder' }, + 'with value': { value: 'https://rocket.chat' }, + 'with icon': { + addon: , + value: 'https://rocket.chat', + }, + }} + yAxis={{ + 'small': {}, + 'hover': { className: 'hover' }, + 'active': { className: 'active' }, + 'focus': { className: 'focus' }, + 'disabled': { disabled: true }, + 'errored': { error: 'Error' }, + 'errored + hover': { className: 'hover', error: 'Error' }, + 'errored + active': { className: 'active', error: 'Error' }, + 'errored + focus': { className: 'focus', error: 'Error' }, + }} + /> + ); diff --git a/packages/fuselage/src/components/UrlInput/__snapshots__/UrlInput.spec.tsx.snap b/packages/fuselage/src/components/UrlInput/__snapshots__/UrlInput.spec.tsx.snap new file mode 100644 index 0000000000..edb66a68d2 --- /dev/null +++ b/packages/fuselage/src/components/UrlInput/__snapshots__/UrlInput.spec.tsx.snap @@ -0,0 +1,14 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`[UrlInput Component] renders without crashing 1`] = ` + +
+ +
+ +`;