From 56faefb7c3a0d62be9c883e1a92c98ee3e7e54f6 Mon Sep 17 00:00:00 2001 From: Ben Howell Date: Mon, 17 Oct 2022 13:24:33 -0700 Subject: [PATCH 1/2] chore: Refactor Field VR tests to have individual tests per component --- .../src/stories/Field.stories.tsx | 200 +++++++++++------- 1 file changed, 120 insertions(+), 80 deletions(-) diff --git a/apps/vr-tests-react-components/src/stories/Field.stories.tsx b/apps/vr-tests-react-components/src/stories/Field.stories.tsx index d84d951888ddd..68fd519b41bbc 100644 --- a/apps/vr-tests-react-components/src/stories/Field.stories.tsx +++ b/apps/vr-tests-react-components/src/stories/Field.stories.tsx @@ -6,7 +6,6 @@ import { CheckboxField, ComboboxField, InputField, - InputFieldProps, ProgressField, RadioGroupField, SelectField, @@ -16,85 +15,126 @@ import { TextareaField, } from '@fluentui/react-field'; import { SparkleFilled } from '@fluentui/react-icons'; +import { FieldComponent, FieldPropsWithOptionalComponentProps } from '@fluentui/react-field/src/Field'; -const AllFields = ( - props: Pick< - InputFieldProps, - 'orientation' | 'required' | 'label' | 'validationState' | 'validationMessage' | 'validationMessageIcon' | 'hint' - >, -) => { - return ( -
- - - - - - - - - - - - - - - - -
- ); -}; +type FieldComponentProps = Pick< + FieldPropsWithOptionalComponentProps, + 'orientation' | 'required' | 'label' | 'validationState' | 'validationMessage' | 'validationMessageIcon' | 'hint' +>; -storiesOf('Field Converged', module) - .addDecorator(story => ( -
-
- {story()} +/** + * Common VR tests for all field components. Pass the given Field component (or a wrapper around it). + */ +const storiesOfField = (name: string, Field: React.VoidFunctionComponent) => + storiesOf(name, module) + .addDecorator(story => {story()}) + .addDecorator(story => ( +
+
+ {story()} +
-
- )) - .addStory('base', () => ) - .addStory('required', () => ) - .addStory('validation:error', () => ) - .addStory('validation:warning', () => ) - .addStory('validation:success', () => ) - .addStory('validation:custom', () => ( - } validationMessage="Custom message" /> - )) - .addStory('hint', () => ) - .addStory('horizontal', () => ) - .addStory('horizontal+label:multiline', () => ( - - )) - .addStory('horizontal+validation:error+hint', () => ( - - )) - .addStory('size:small', () => ( -
- - - - - - - - -
- )) - .addStory('size:large', () => ( -
- - - - - - - -
- )) - .addStory('CheckboxField+fieldLabel', () => ( - - )); + )) + .addStory('base', () => ) + .addStory('required', () => ) + .addStory('validation', () => ( +
+ + + + } + validationMessage="Custom message" + /> +
+ )) + .addStory('hint', () => ) + .addStory('horizontal', () => ( + + )); + +/** + * Same as storiesOfField, but with extra stories for Field components that support the size prop. + */ +const storiesOfFieldWithSize = ( + name: string, + Field: React.VoidFunctionComponent, +) => + storiesOfField(name, Field) + .addStory('size:small', () => ) + .addStory('size:large', () => ); + +// +// CheckboxField +// +storiesOfField('CheckboxField converged', CheckboxField) + .addStory('size:large', () => ) + .addStory('fieldLabel', () => ); + +// +// ComboboxField +// +storiesOfFieldWithSize('ComboboxField converged', ComboboxField); + +// +// InputField +// +storiesOfFieldWithSize('InputField converged', InputField); + +// +// ProgressField +// +storiesOfField('ProgressField converged', props => + props.validationState === 'warning' ? null : ( + + ), +); + +// +// RadioGroupField +// +storiesOfField('RadioGroupField converged', props => ( + + + + + +)); + +// +// SelectField +// +storiesOfFieldWithSize('SelectField converged', props => ( + + + + + +)); + +// +// SliderField +// +storiesOfField('SliderField converged', SliderField); + +// +// SpinButtonField +// +storiesOfField('SpinButtonField converged', SpinButtonField); + +// +// SwitchField +// +storiesOfField('SwitchField converged', SwitchField); + +// +// TextareaField +// +storiesOfFieldWithSize('TextareaField converged', TextareaField); From 9fd9db1f190230f5f01df7394098bb87ff370fc7 Mon Sep 17 00:00:00 2001 From: Ben Howell Date: Fri, 21 Oct 2022 16:19:48 -0700 Subject: [PATCH 2/2] Restore progress warning test --- .../src/stories/Field.stories.tsx | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/apps/vr-tests-react-components/src/stories/Field.stories.tsx b/apps/vr-tests-react-components/src/stories/Field.stories.tsx index 68fd519b41bbc..663edb6328523 100644 --- a/apps/vr-tests-react-components/src/stories/Field.stories.tsx +++ b/apps/vr-tests-react-components/src/stories/Field.stories.tsx @@ -91,11 +91,7 @@ storiesOfFieldWithSize('InputField converged', InputField); // // ProgressField // -storiesOfField('ProgressField converged', props => - props.validationState === 'warning' ? null : ( - - ), -); +storiesOfField('ProgressField converged', props => ); // // RadioGroupField @@ -114,8 +110,6 @@ storiesOfField('RadioGroupField converged', props => ( storiesOfFieldWithSize('SelectField converged', props => ( - - ));