From 30358f4704dbca446b6b2f7461261922b1ffe418 Mon Sep 17 00:00:00 2001 From: Josh Black Date: Thu, 1 Aug 2024 15:55:19 -0500 Subject: [PATCH] test(e2e): add vrt for blankslate --- e2e/components/Blankslate.test.ts | 92 +++++++++++++++++++++++++++++++ 1 file changed, 92 insertions(+) create mode 100644 e2e/components/Blankslate.test.ts diff --git a/e2e/components/Blankslate.test.ts b/e2e/components/Blankslate.test.ts new file mode 100644 index 00000000000..49ff3f2a4cd --- /dev/null +++ b/e2e/components/Blankslate.test.ts @@ -0,0 +1,92 @@ +import {test, expect} from '@playwright/test' +import {visit} from '../test-helpers/storybook' +import {themes} from '../test-helpers/themes' +import {viewports} from '../test-helpers/viewports' + +const stories: Array<{title: string; id: string; viewports?: Array}> = [ + { + title: 'Default', + id: 'drafts-components-blankslate--default', + viewports: ['primer.breakpoint.xs', 'primer.breakpoint.sm'], + }, + { + title: 'Narrow', + id: 'drafts-components-blankslate-features--narrow', + viewports: ['primer.breakpoint.xs', 'primer.breakpoint.sm'], + }, + { + title: 'Spacious', + id: 'drafts-components-blankslate-features--spacious', + viewports: ['primer.breakpoint.xs', 'primer.breakpoint.sm'], + }, + { + title: 'With Border', + id: 'drafts-components-blankslate-features--with-border', + viewports: ['primer.breakpoint.sm'], + }, + { + title: 'With Primary Action', + id: 'drafts-components-blankslate-features--with-primary-action', + viewports: ['primer.breakpoint.sm'], + }, + { + title: 'With Secondary Action', + id: 'drafts-components-blankslate-features--with-secondary-action', + viewports: ['primer.breakpoint.sm'], + }, + { + title: 'With Visual', + id: 'drafts-components-blankslate-features--with-visual', + viewports: ['primer.breakpoint.sm'], + }, +] + +test.describe('Blankslate', () => { + for (const story of stories) { + test.describe(story.title, () => { + for (const theme of themes) { + test.describe(theme, () => { + test('default @vrt', async ({page}) => { + await visit(page, { + id: story.id, + globals: { + colorScheme: theme, + }, + }) + + // Default state + expect(await page.screenshot()).toMatchSnapshot(`Blankslate.${story.title}.${theme}.png`) + }) + + test('axe @aat', async ({page}) => { + await visit(page, { + id: story.id, + globals: { + colorScheme: theme, + }, + }) + await expect(page).toHaveNoViolations() + }) + }) + } + + if (story.viewports) { + for (const name of story.viewports) { + test(`${name} @vrt`, async ({page}) => { + await visit(page, { + id: story.id, + globals: {}, + }) + const width = viewports[name] + + await page.setViewportSize({ + width, + height: 667, + }) + expect(await page.screenshot()).toMatchSnapshot(`Blankslate.${story.title}.${name}.png`) + }) + } + } + }) + } +})