-
Notifications
You must be signed in to change notification settings - Fork 8
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(pie-divider): DSW-2277 Divider visual test refactor #2028
Closed
Closed
Changes from 1 commit
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 |
---|---|---|
|
@@ -2,3 +2,5 @@ version: 2 | |
discovery: | ||
disallowedHostnames: | ||
- unpkg.com | ||
allowedHostnames: | ||
- cloudfront.net |
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,69 @@ | ||
import { html } from 'lit'; | ||
import { type Meta } from '@storybook/web-components'; | ||
import '@justeattakeaway/pie-webc-testing/src/helpers/components/web-component-test-wrapper/WebComponentTestWrapper.ts'; | ||
|
||
import { | ||
type DividerProps, defaultProps, orientations, variants, | ||
} from '@justeattakeaway/pie-divider'; | ||
|
||
import { getAllPropCombinations } from '@justeattakeaway/pie-webc-testing/src/helpers/get-all-prop-combos'; | ||
|
||
const props = { | ||
orientation: orientations, | ||
label: ['', 'Label', 'Lorem ipsum dolor sit amet consectetur'], | ||
}; | ||
|
||
type DividerStoryMeta = Meta<DividerProps>; | ||
|
||
const defaultArgs: DividerProps = { ...defaultProps }; | ||
|
||
const visualTestStoryMeta: DividerStoryMeta = { | ||
title: 'Divider/Visual Test', | ||
component: 'pie-divider', | ||
args: defaultArgs, | ||
parameters: { | ||
controls: { hideNoControlsWarning: true }, | ||
}, | ||
}; | ||
|
||
export default visualTestStoryMeta; | ||
|
||
const generatePropKeyValues = (props: DividerProps) => `orientation: ${props.orientation}, label: ${props.label || '-'}`; | ||
|
||
const propCombinations = getAllPropCombinations(props); | ||
|
||
export const Default = () => html` | ||
${propCombinations.map(({ variant, orientation, label }) => { | ||
const propKeyValues = generatePropKeyValues({ variant, orientation, label }); | ||
|
||
return html` | ||
<web-component-test-wrapper propKeyValues="${propKeyValues}"> | ||
<div style="${orientation === 'vertical' ? 'height: 250px;' : ''}" slot="component"> | ||
<pie-divider | ||
variant="default" | ||
orientation="${orientation}" | ||
label="${label}"> | ||
</pie-divider> | ||
</div> | ||
</web-component-test-wrapper> | ||
`; | ||
})} | ||
`; | ||
|
||
export const Inverse = () => html` | ||
${propCombinations.map(({ variant, orientation, label }) => { | ||
const propKeyValues = generatePropKeyValues({ variant, orientation, label }); | ||
|
||
return html` | ||
<web-component-test-wrapper propKeyValues="${propKeyValues}" darkMode="${variant === 'inverse'}"> | ||
<div style="${orientation === 'vertical' ? 'height: 250px;' : ''}" slot="component"> | ||
<pie-divider | ||
variant="inverse" | ||
orientation="${orientation}" | ||
label="${label}"> | ||
</pie-divider> | ||
</div> | ||
</web-component-test-wrapper> | ||
`; | ||
})} | ||
`; |
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
22 changes: 22 additions & 0 deletions
22
packages/components/pie-divider/test/helpers/page-object/pie-divider.page.ts
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,22 @@ | ||
import { type Locator, type Page } from '@playwright/test'; | ||
import { BasePage } from '@justeattakeaway/pie-webc-testing/src/helpers/page-object/base-page.ts'; | ||
import { divider } from './selectors'; | ||
|
||
export class DividerComponent extends BasePage { | ||
private readonly componentLocator: Locator; | ||
|
||
constructor (page: Page) { | ||
super(page, 'divider'); | ||
this.componentLocator = page.getByTestId(divider.selectors.container.dataTestId); | ||
} | ||
|
||
/** | ||
* Checks whether the cookie banner is currently visible on the page. | ||
* | ||
* @returns {Promise<boolean>} A Promise that resolves to a boolean value indicating | ||
* whether the cookie banner is visible (`true`) or not (`false`). | ||
*/ | ||
async isDividerVisible () : Promise<boolean> { | ||
return this.componentLocator.isVisible(); | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
packages/components/pie-divider/test/helpers/page-object/selectors.ts
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,11 @@ | ||
const divider = { | ||
selectors: { | ||
container: { | ||
description: 'The selector for the divider', | ||
dataTestId: 'pie-divider', | ||
}, | ||
}, | ||
}; | ||
export { | ||
divider, | ||
}; |
71 changes: 12 additions & 59 deletions
71
packages/components/pie-divider/test/visual/pie-divider.spec.ts
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,66 +1,19 @@ | ||
import { test } from '@sand4rt/experimental-ct-web'; | ||
import { test } from '@justeattakeaway/pie-webc-testing/src/playwright/playwright-fixtures.ts'; | ||
import percySnapshot from '@percy/playwright'; | ||
import { | ||
type PropObject, type WebComponentPropValues, type WebComponentTestInput, | ||
} from '@justeattakeaway/pie-webc-testing/src/helpers/defs.ts'; | ||
import { | ||
getAllPropCombinations, splitCombinationsByPropertyValue, | ||
} from '@justeattakeaway/pie-webc-testing/src/helpers/get-all-prop-combos.ts'; | ||
import { | ||
createTestWebComponent, | ||
} from '@justeattakeaway/pie-webc-testing/src/helpers/rendering.ts'; | ||
import { | ||
WebComponentTestWrapper, | ||
} from '@justeattakeaway/pie-webc-testing/src/helpers/components/web-component-test-wrapper/WebComponentTestWrapper.ts'; | ||
import { DividerComponent } from 'test/helpers/page-object/pie-divider.page.ts'; | ||
import { percyWidths } from '@justeattakeaway/pie-webc-testing/src/percy/breakpoints.ts'; | ||
import { variants, orientations, type DividerProps } from '../../src/defs.ts'; | ||
import { PieDivider } from '../../src/index.ts'; | ||
import { variants } from '../../src/defs.ts'; | ||
|
||
const props: PropObject<DividerProps> = { | ||
variant: variants, | ||
orientation: orientations, | ||
label: ['', 'Label', 'Lorem ipsum dolor sit amet consectetur'], | ||
}; | ||
let pieDividerComponent: DividerComponent; | ||
|
||
const renderTestPieDivider = (propVals: WebComponentPropValues) => { | ||
const { variant, orientation, label } = propVals; | ||
if (orientation === 'vertical') { | ||
return ` | ||
<div style="height: 250px"> | ||
<pie-divider variant="${variant}" orientation="${orientation}" label="${label}"></pie-divider> | ||
</div> | ||
`; | ||
} | ||
return `<pie-divider variant="${variant}" orientation="${orientation}" label="${label}"></pie-divider>`; | ||
}; | ||
test.describe('PieDivider - Visual tests', () => { | ||
test.beforeEach(async ({ page }) => { | ||
pieDividerComponent = new DividerComponent(page); | ||
}); | ||
|
||
const componentPropsMatrix : WebComponentPropValues[] = getAllPropCombinations(props); | ||
const componentPropsMatrixByVariant: Record<string, WebComponentPropValues[]> = splitCombinationsByPropertyValue(componentPropsMatrix, 'variant'); | ||
const componentVariants: string[] = Object.keys(componentPropsMatrixByVariant); | ||
variants.forEach((variant) => test(`should render all prop variations for variant: ${variant} `, async ({ page }) => { | ||
await pieDividerComponent.load({}, variant); | ||
|
||
test.beforeEach(async ({ mount }) => { | ||
const component = await mount(PieDivider); | ||
await component.unmount(); | ||
await percySnapshot(page, `PIE Divider - variant: ${variant}`, percyWidths); | ||
})); | ||
}); | ||
|
||
componentVariants.forEach((variant) => test(`should render all prop variations for variant: ${variant} `, async ({ | ||
page, | ||
mount, | ||
}) => { | ||
for (const combo of componentPropsMatrixByVariant[variant]) { | ||
const testComponent: WebComponentTestInput = createTestWebComponent(combo, renderTestPieDivider); | ||
const propKeyValues = `orientation: ${testComponent.propValues.orientation}, label: ${testComponent.propValues.label || '-'}`; | ||
|
||
await mount( | ||
WebComponentTestWrapper, | ||
{ | ||
props: { propKeyValues, darkMode: variant === 'inverse' }, | ||
slots: { | ||
component: testComponent.renderedString.trim(), | ||
}, | ||
}, | ||
); | ||
} | ||
|
||
await percySnapshot(page, `PIE Divider - variant: ${variant}`, percyWidths); | ||
})); |
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
As discussed, probably worth renaming this to
pie-divider.test.stories.ts
👍🏼