-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
VizReg e2e tests: programmatically test all combinations of a given l…
…ist of props/values (#48260) * Add custom controls decorator * Add playwright util for parsing e2e controls and testing all combinations via snapshots * Add HStack e2e story + playwright test * Add VStack e2e story + playwright test * Cleanup unused values * Typo * Simplify decorator, use globalTypes to enable it * Update Playwright utils 1. expect prop config as input when computing permutations 2. use new form inputs to submit prop config instead of individual prop controls * Move list of props to test from Storybook examples to test specs * Update JSDoc * Run tests in parallel * Remove unnecessary imports * Make the whole VizReg Playwright project to be fully parallel
- Loading branch information
Showing
8 changed files
with
332 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import type { ComponentStory, ComponentMeta } from '@storybook/react'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import { View } from '../../../view'; | ||
import { HStack } from '../..'; | ||
|
||
const meta: ComponentMeta< typeof HStack > = { | ||
component: HStack, | ||
title: 'Components (Experimental)/HStack', | ||
}; | ||
export default meta; | ||
|
||
const Template: ComponentStory< typeof HStack > = ( props ) => { | ||
return ( | ||
<HStack | ||
style={ { background: '#eee', minHeight: '3rem' } } | ||
{ ...props } | ||
> | ||
{ [ 'One', 'Two', 'Three', 'Four', 'Five' ].map( ( text ) => ( | ||
<View key={ text } style={ { background: '#b9f9ff' } }> | ||
{ text } | ||
</View> | ||
) ) } | ||
</HStack> | ||
); | ||
}; | ||
|
||
export const Default: ComponentStory< typeof HStack > = Template.bind( {} ); | ||
Default.args = { | ||
spacing: 3, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import type { ComponentStory, ComponentMeta } from '@storybook/react'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import { View } from '../../../view'; | ||
import { VStack } from '../..'; | ||
|
||
const meta: ComponentMeta< typeof VStack > = { | ||
component: VStack, | ||
title: 'Components (Experimental)/VStack', | ||
}; | ||
export default meta; | ||
|
||
const Template: ComponentStory< typeof VStack > = ( props ) => { | ||
return ( | ||
<VStack | ||
{ ...props } | ||
style={ { background: '#eee', minHeight: '3rem' } } | ||
> | ||
{ [ 'One', 'Two', 'Three', 'Four', 'Five' ].map( ( text ) => ( | ||
<View key={ text } style={ { background: '#b9f9ff' } }> | ||
{ text } | ||
</View> | ||
) ) } | ||
</VStack> | ||
); | ||
}; | ||
|
||
export const Default: ComponentStory< typeof VStack > = Template.bind( {} ); | ||
Default.args = { | ||
spacing: 3, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import { test } from '@playwright/test'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import { | ||
gotoStoryId, | ||
getAllPropsPermutations, | ||
testSnapshotForPropsConfig, | ||
} from '../utils'; | ||
|
||
const PROP_VALUES_TO_TEST = [ | ||
{ | ||
propName: 'alignment', | ||
valuesToTest: [ | ||
undefined, | ||
'top', | ||
'topLeft', | ||
'topRight', | ||
'left', | ||
'center', | ||
'right', | ||
'bottom', | ||
'bottomLeft', | ||
'bottomRight', | ||
'edge', | ||
'stretch', | ||
], | ||
}, | ||
{ | ||
propName: 'direction', | ||
valuesToTest: [ undefined, 'row', 'column' ], | ||
}, | ||
]; | ||
|
||
test.describe( 'HStack', () => { | ||
test.beforeEach( async ( { page } ) => { | ||
await gotoStoryId( page, 'components-experimental-hstack--default', { | ||
decorators: { marginChecker: 'show', customE2EControls: 'show' }, | ||
} ); | ||
} ); | ||
|
||
getAllPropsPermutations( PROP_VALUES_TO_TEST ).forEach( ( propsConfig ) => { | ||
test( `should render with ${ JSON.stringify( propsConfig ) }`, async ( { | ||
page, | ||
} ) => { | ||
await page.waitForSelector( '.components-h-stack' ); | ||
|
||
await testSnapshotForPropsConfig( page, propsConfig ); | ||
} ); | ||
} ); | ||
} ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import { test } from '@playwright/test'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import { | ||
gotoStoryId, | ||
getAllPropsPermutations, | ||
testSnapshotForPropsConfig, | ||
} from '../utils'; | ||
|
||
const PROP_VALUES_TO_TEST = [ | ||
{ | ||
propName: 'alignment', | ||
valuesToTest: [ | ||
undefined, | ||
'top', | ||
'topLeft', | ||
'topRight', | ||
'left', | ||
'center', | ||
'right', | ||
'bottom', | ||
'bottomLeft', | ||
'bottomRight', | ||
'edge', | ||
'stretch', | ||
], | ||
}, | ||
{ | ||
propName: 'direction', | ||
valuesToTest: [ undefined, 'row', 'column' ], | ||
}, | ||
]; | ||
|
||
test.describe( 'VStack', () => { | ||
test.beforeEach( async ( { page } ) => { | ||
await gotoStoryId( page, 'components-experimental-vstack--default', { | ||
decorators: { marginChecker: 'show', customE2EControls: 'show' }, | ||
} ); | ||
} ); | ||
|
||
getAllPropsPermutations( PROP_VALUES_TO_TEST ).forEach( ( propsConfig ) => { | ||
test( `should render with ${ JSON.stringify( propsConfig ) }`, async ( { | ||
page, | ||
} ) => { | ||
await page.waitForSelector( '.components-v-stack' ); | ||
|
||
await testSnapshotForPropsConfig( page, propsConfig ); | ||
} ); | ||
} ); | ||
} ); |
58 changes: 58 additions & 0 deletions
58
test/storybook-playwright/storybook/decorators/with-custom-controls.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { useId, useState } from '@wordpress/element'; | ||
|
||
export const WithCustomControls = ( Story, context ) => { | ||
const textareaId = useId(); | ||
const [ partialProps, setPartialProps ] = useState( {} ); | ||
|
||
if ( context.globals.customE2EControls === 'hide' ) { | ||
return <Story { ...context } />; | ||
} | ||
|
||
const contextWithControlledProps = { | ||
...context, | ||
// override args with the ones set by custom controls | ||
args: { ...context.args, ...partialProps }, | ||
}; | ||
|
||
return ( | ||
<> | ||
<Story { ...contextWithControlledProps } /> | ||
|
||
<p>Props:</p> | ||
<pre> | ||
{ JSON.stringify( | ||
contextWithControlledProps.args, | ||
undefined, | ||
4 | ||
) } | ||
</pre> | ||
|
||
<hr /> | ||
|
||
<form | ||
name="e2e-controls-form" | ||
onSubmit={ ( event ) => { | ||
event.preventDefault(); | ||
|
||
const propsRawText = event.target.elements.props.value; | ||
|
||
const propsParsed = JSON.parse( propsRawText ); | ||
|
||
setPartialProps( ( oldProps ) => ( { | ||
...oldProps, | ||
...propsParsed, | ||
} ) ); | ||
} } | ||
> | ||
<p> | ||
<label htmlFor={ textareaId }>Raw props</label> | ||
<textarea name="props" id={ textareaId } /> | ||
</p> | ||
<button type="submit">Set props</button> | ||
</form> | ||
</> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,28 @@ | ||
export * from '../../../storybook/preview'; | ||
/** | ||
* Internal dependencies | ||
*/ | ||
|
||
import * as basePreviewConfig from '../../../storybook/preview'; | ||
import { WithCustomControls } from './decorators/with-custom-controls'; | ||
|
||
export const globalTypes = { | ||
...basePreviewConfig.globalTypes, | ||
customE2EControls: { | ||
name: 'Custom E2E Controls', | ||
description: | ||
'Shows custom UI used by e2e tests for setting props programmatically', | ||
defaultValue: 'hide', | ||
toolbar: { | ||
icon: 'edit', | ||
items: [ | ||
{ value: 'hide', title: 'Hide' }, | ||
{ value: 'show', title: 'Show' }, | ||
], | ||
}, | ||
}, | ||
}; | ||
export const decorators = [ | ||
...basePreviewConfig.decorators, | ||
WithCustomControls, | ||
]; | ||
export const parameters = { ...basePreviewConfig.parameters }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
a4c2395
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Flaky tests detected in a4c2395.
Some tests passed with failed attempts. The failures may not be related to this commit but are still reported for visibility. See the documentation for more information.
🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/4261644126
📝 Reported issues:
/test/e2e/specs/editor/blocks/navigation.spec.js
specs/editor/various/multi-block-selection.test.js