-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(pie-thumbnail): DSW-2580 update visual tests
- Loading branch information
Showing
3 changed files
with
39 additions
and
72 deletions.
There are no files selected for viewing
48 changes: 30 additions & 18 deletions
48
apps/pie-storybook/stories/testing/pie-thumbnail.test.stories.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,34 +1,46 @@ | ||
import { html } from 'lit'; | ||
import { type Meta } from '@storybook/web-components'; | ||
|
||
import '@justeattakeaway/pie-thumbnail'; | ||
import { type ThumbnailProps } from '@justeattakeaway/pie-thumbnail'; | ||
|
||
import { createStory } from '../../utilities'; | ||
import { type Meta } from '@storybook/web-components'; | ||
import { createVariantStory, type TemplateFunction } from '../../utilities'; | ||
|
||
type ThumbnailStoryMeta = Meta<ThumbnailProps>; | ||
|
||
const defaultArgs: ThumbnailProps = {}; | ||
|
||
const thumbnailStoryMeta: ThumbnailStoryMeta = { | ||
title: 'Thumbnail', | ||
component: 'pie-thumbnail', | ||
argTypes: {}, | ||
args: defaultArgs, | ||
parameters: { | ||
design: { | ||
type: 'figma', | ||
url: '', | ||
}, | ||
}, | ||
}; | ||
|
||
export default thumbnailStoryMeta; | ||
|
||
// TODO: remove the eslint-disable rule when props are added | ||
// eslint-disable-next-line no-empty-pattern | ||
const Template = ({}: ThumbnailProps) => html` | ||
<pie-thumbnail></pie-thumbnail> | ||
`; | ||
const Template: TemplateFunction<ThumbnailProps> = ({ | ||
variant, | ||
src, | ||
alt, | ||
}) => html` | ||
<pie-thumbnail | ||
variant="${variant}" | ||
src="${src}" | ||
alt="${alt}"> | ||
</pie-thumbnail>`; | ||
|
||
// Define the prop options for the matrix | ||
const sharedPropOptions = { | ||
src: ['https://www.takeaway.com/consumer-web/images/takeaway-brand.61e55e0b.svg'], | ||
alt: ['JET logo'], | ||
}; | ||
|
||
const defaultPropOptions = { | ||
...sharedPropOptions, | ||
variant: ['default'], | ||
}; | ||
|
||
const outlinePropOptions = { | ||
...sharedPropOptions, | ||
variant: ['outline'], | ||
}; | ||
|
||
export const Default = createStory<ThumbnailProps>(Template, defaultArgs)(); | ||
export const DefaultPropVariations = createVariantStory<ThumbnailProps>(Template, defaultPropOptions); | ||
export const OutlinePropVariations = createVariantStory<ThumbnailProps>(Template, outlinePropOptions); |
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
61 changes: 8 additions & 53 deletions
61
packages/components/pie-thumbnail/test/visual/pie-thumbnail.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,60 +1,15 @@ | ||
import { test } from '@sand4rt/experimental-ct-web'; | ||
import { test } from '@playwright/test'; | ||
import percySnapshot from '@percy/playwright'; | ||
import { type PropObject, type WebComponentPropValues } 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 { percyWidths } from '@justeattakeaway/pie-webc-testing/src/percy/breakpoints.ts'; | ||
import { variants } from '@justeattakeaway/pie-thumbnail/src'; | ||
import { PieThumbnail } from '../../src/index.ts'; | ||
import { BasePage } from '@justeattakeaway/pie-webc-testing/src/helpers/page-object/base-page.ts'; | ||
import { variants } from '../../src/defs.ts'; | ||
|
||
const props: PropObject = { | ||
variant: variants, | ||
src: 'https://www.takeaway.com/consumer-web/images/takeaway-brand.61e55e0b.svg', | ||
alt: 'JET logo', | ||
}; | ||
variants.forEach((variant) => test(`should render all prop variations for Variant: ${variant}`, async ({ page }) => { | ||
const basePage = new BasePage(page, `thumbnail--${variant}-prop-variations`); | ||
|
||
// Renders a <pie-thumbnail> HTML string with the given prop values | ||
const renderTestPieThumbnail = (propVals: WebComponentPropValues) => `<pie-thumbnail variant="${propVals.variant}" src="${propVals.src}" alt="${propVals.alt}"></pie-thumbnail>`; | ||
basePage.load(); | ||
|
||
const componentPropsMatrix = getAllPropCombinations(props); | ||
const componentPropsMatrixByVariant = splitCombinationsByPropertyValue(componentPropsMatrix, 'variant'); | ||
const componentVariants = Object.keys(componentPropsMatrixByVariant); | ||
await page.waitForTimeout(5000); | ||
|
||
// This ensures the component is registered in the DOM for each test | ||
// This is not required if your tests mount the web component directly in the tests | ||
test.beforeEach(async ({ mount }, testInfo) => { | ||
testInfo.setTimeout(testInfo.timeout + 40000); | ||
|
||
const component = await mount(PieThumbnail); | ||
await component.unmount(); | ||
}); | ||
|
||
componentVariants.forEach((variant) => test(`should render all prop variations for Variant: ${variant}`, async ({ page, mount }) => { | ||
for (const combo of componentPropsMatrixByVariant[variant]) { | ||
const testComponent = createTestWebComponent(combo, renderTestPieThumbnail); | ||
const propKeyValues = ` | ||
variant: ${testComponent.propValues.variant}, | ||
src: ${testComponent.propValues.src}, | ||
alt: ${testComponent.propValues.alt} | ||
`; | ||
|
||
await mount( | ||
WebComponentTestWrapper, | ||
{ | ||
props: { propKeyValues }, | ||
slots: { | ||
component: testComponent.renderedString.trim(), | ||
}, | ||
}, | ||
); | ||
} | ||
|
||
await percySnapshot(page, `PieThumbnail - Variant: ${variant}`, percyWidths); | ||
await percySnapshot(page, `PIE Thumbnail - Variant: ${variant}`, percyWidths); | ||
})); |