Skip to content

Commit

Permalink
Use expectSnapshot, add screenshot-area and remove colored focus
Browse files Browse the repository at this point in the history
  • Loading branch information
obulat committed Sep 14, 2024
1 parent 4d8eb5d commit c829801
Show file tree
Hide file tree
Showing 19 changed files with 95 additions and 121 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,16 @@ import { h } from "vue"

import { baseButtonSizes, baseButtonVariants } from "~/types/button"

import { WithScreenshotArea } from "~~/.storybook/decorators/with-screenshot-area"

import VIconButton from "~/components/VIconButton/VIconButton.vue"

import type { Meta, StoryObj } from "@storybook/vue3"

const meta = {
title: "Components/VIconButton",
component: VIconButton,
decorators: [WithScreenshotArea],

argTypes: {
size: {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
import { h } from "vue"

import { WithScreenshotArea } from "~~/.storybook/decorators/with-screenshot-area"

import VLanguageSelect from "~/components/VLanguageSelect/VLanguageSelect.vue"

import type { Meta, StoryObj } from "@storybook/vue3"

const meta = {
title: "Components/VLanguageSelect",
component: VLanguageSelect,
decorators: [WithScreenshotArea],
} satisfies Meta<typeof VLanguageSelect>

export default meta
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { h, ref } from "vue"

import { WithScreenshotArea } from "~~/.storybook/decorators/with-screenshot-area"

import VIcon from "~/components/VIcon/VIcon.vue"
import VSelectField from "~/components/VSelectField/VSelectField.vue"

Expand All @@ -19,6 +21,7 @@ const baseArgs = {
const meta = {
title: "Components/VSelectField",
component: VSelectField,
decorators: [WithScreenshotArea],

argTypes: {
"onUpdate:modelValue": {
Expand Down
15 changes: 0 additions & 15 deletions frontend/src/components/meta/Focus.stories.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,18 +57,3 @@ export const BoldFilled = {
classNames: ["focus-bold-filled"],
},
}

export const Colored = {
render: GetTemplate("bg-tertiary text-over-dark border border-tx").bind({}),
name: "Colored",

args: {
classNames: ["focus-slim-tx bg-complementary"],
},

parameters: {
backgrounds: {
default: "dark",
},
},
}
10 changes: 3 additions & 7 deletions frontend/test/storybook/playwright.config.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import type { PlaywrightTestConfig } from "@playwright/test"
import { defineConfig } from "@playwright/test"

const config: PlaywrightTestConfig = {
snapshotPathTemplate:
"visual-regression/{testFileName}-snapshots/{arg}-linux.png",
export default defineConfig({
forbidOnly: !!process.env.CI,
webServer: {
command: "pnpm prod:storybook",
Expand All @@ -21,6 +19,4 @@ const config: PlaywrightTestConfig = {
maxDiffPixelRatio: 0.01,
},
},
}

export default config
})
9 changes: 3 additions & 6 deletions frontend/test/storybook/visual-regression/focus.spec.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,16 @@
import { test, expect, Page, Locator } from "@playwright/test"
import { test, Page } from "@playwright/test"

import { expectSnapshot } from "~~/test/storybook/utils/expect-snapshot"

const goTo = async (page: Page, slug: string) => {
await page.goto(`/iframe.html?id=meta-focus--${slug}`)
}

const expectSnapshot = async (name: string, elem: Locator) => {
expect(await elem.screenshot()).toMatchSnapshot({ name: `${name}.png` })
}

const allSlugs = [
"slim-transparent",
"slim-filled",
"slim-filled-borderless",
"bold-filled",
"colored",
]

test.describe.configure({ mode: "parallel" })
Expand Down
Binary file not shown.
23 changes: 10 additions & 13 deletions frontend/test/storybook/visual-regression/v-button.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import { expect, test } from "@playwright/test"
import { test } from "@playwright/test"

import { makeGotoWithArgs } from "~~/test/storybook/utils/args"

import { expectSnapshot } from "~~/test/storybook/utils/expect-snapshot"

import { buttonVariants } from "~/types/button"

const buttonLocator = "text=Code is Poetry"
Expand All @@ -17,34 +19,29 @@ test.describe("VButton", () => {
for (const variant of nonPressedVariants) {
test(`${variant} resting`, async ({ page }) => {
await gotoWithArgs(page, { variant })
expect(await page.locator(wrapperLocator).screenshot()).toMatchSnapshot({
name: `${variant}-resting.png`,
})
await expectSnapshot(`${variant}-resting`, page.locator(wrapperLocator))
})

test(`${variant} hovered`, async ({ page }) => {
await gotoWithArgs(page, { variant })
await page.hover(buttonLocator)
expect(await page.locator(wrapperLocator).screenshot()).toMatchSnapshot({
name: `${variant}-hovered.png`,
})
await expectSnapshot(`${variant}-hovered`, page.locator(wrapperLocator))
})

test(`${variant} focused`, async ({ page }) => {
await gotoWithArgs(page, { variant })
await page.focus(buttonLocator)
expect(await page.locator(wrapperLocator).screenshot()).toMatchSnapshot({
name: `${variant}-focused.png`,
})
await expectSnapshot(`${variant}-focused`, page.locator(wrapperLocator))
})

test(`${variant} focused hovered`, async ({ page }) => {
await gotoWithArgs(page, { variant })
await page.focus(buttonLocator)
await page.hover(buttonLocator)
expect(await page.locator(wrapperLocator).screenshot()).toMatchSnapshot({
name: `${variant}-focused-hovered.png`,
})
await expectSnapshot(
`${variant}-focused-hovered`,
page.locator(wrapperLocator)
)
})
}
})
59 changes: 16 additions & 43 deletions frontend/test/storybook/visual-regression/v-checkbox.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import { test, expect } from "@playwright/test"
import { test } from "@playwright/test"

import { expectSnapshot } from "~~/test/storybook/utils/expect-snapshot"

test.describe.configure({ mode: "parallel" })

Expand All @@ -9,86 +11,57 @@ test.describe("v-checkbox", () => {
})

test("default", async ({ page }) => {
expect(
await page.locator(".screenshot-area").screenshot()
).toMatchSnapshot({ name: "default.png" })
await expectSnapshot("default", page.locator(".screenshot-area"))
})

test("hover", async ({ page }) => {
const checkbox = page.getByRole("checkbox")
await checkbox.hover()
expect(
await page.locator(".screenshot-area").screenshot()
).toMatchSnapshot({ name: "hover.png" })
await expectSnapshot("hover", page.locator(".screenshot-area"))
})

test("focused", async ({ page }) => {
const checkbox = page.getByRole("checkbox")
await checkbox.focus()
expect(
await page.locator(".screenshot-area").screenshot()
).toMatchSnapshot({
name: "focused.png",
})
await expectSnapshot("focused", page.locator(".screenshot-area"))
})

test("disabled", async ({ page }) => {
const checkbox = page.getByRole("checkbox")
await checkbox.evaluate((checkbox) => {
;(checkbox as HTMLInputElement).disabled = true
})
expect(
await page.locator(".screenshot-area").screenshot()
).toMatchSnapshot({
name: "disabled.png",
})
await expectSnapshot("disabled", page.locator(".screenshot-area"))
})

test("on", async ({ page }) => {
const checkbox = page.locator('input[type="checkbox"]')
const checkbox = page.getByRole("checkbox")
await checkbox.click()
expect(
await page.locator(".screenshot-area").screenshot()
).toMatchSnapshot({ name: "on.png" })
await expectSnapshot("on", page.locator(".screenshot-area"))
})

test("on focused", async ({ page }) => {
const checkbox = page.locator('input[type="checkbox"]')
const checkbox = page.getByRole("checkbox")
await checkbox.focus()
await page.keyboard.press("Space")
expect(
await page.locator(".screenshot-area").screenshot()
).toMatchSnapshot({
name: "on-focused.png",
})
await expectSnapshot("on-focused", page.locator(".screenshot-area"))
})

test("on disabled", async ({ page }) => {
const checkbox = page.locator('input[type="checkbox"]')
const checkbox = page.getByRole("checkbox")
await checkbox.click()
await checkbox.evaluate((checkbox) => {
;(checkbox as HTMLInputElement).disabled = true
})
expect(
await page.locator(".screenshot-area").screenshot()
).toMatchSnapshot({
name: "on-disabled.png",
})
await expectSnapshot("on-disabled", page.locator(".screenshot-area"))
})

test("on-and-off", async ({ page }) => {
// toggle on and off again
const checkbox = page.locator('input[type="checkbox"]')
const checkbox = page.getByRole("checkbox")
await checkbox.click()
// `force: true` is required because the `input`'s pointer events are actually intercepted by the visual SVG.
// We still want to check that it works though as that does mimic the user behavior of checking directly on the checkbox.
// eslint-disable-next-line playwright/no-force-option
await checkbox.click({ force: true })
expect(
await page.locator(".screenshot-area").screenshot()
).toMatchSnapshot({
name: "on-and-off.png",
})
await checkbox.click()
await expectSnapshot("default", page.locator(".screenshot-area"))
})
})
})
21 changes: 13 additions & 8 deletions frontend/test/storybook/visual-regression/v-filter-tab.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { expect, type Page, test } from "@playwright/test"

import { makeUrlWithArgs } from "~~/test/storybook/utils/args"
import { waitForResponse } from "~~/test/storybook/utils/response"
import { expectSnapshot } from "~~/test/storybook/utils/expect-snapshot"

const urlWithArgs = makeUrlWithArgs(
"components-vheader-vheadermobile-vfiltertab--default"
Expand Down Expand Up @@ -52,8 +53,9 @@ test.describe("VFilterTab", () => {
await goAndWaitForSvg(page, { appliedFilterCount, isSelected: true })
await focusFiltersTab(page)

expect(await page.locator(wrapper).screenshot()).toMatchSnapshot(
`filter-tab-focused-${appliedFilterCount}.png`
await expectSnapshot(
`filter-tab-focused-${appliedFilterCount}`,
page.locator(wrapper)
)
})

Expand All @@ -64,8 +66,9 @@ test.describe("VFilterTab", () => {
await focusFiltersTab(page)
await hoverFiltersTab(page)

expect(await page.locator(wrapper).screenshot()).toMatchSnapshot(
`filter-tab-focused-hovered-${appliedFilterCount}.png`
await expectSnapshot(
`filter-tab-focused-hovered-${appliedFilterCount}`,
page.locator(wrapper)
)
})

Expand All @@ -76,8 +79,9 @@ test.describe("VFilterTab", () => {
}) => {
await goAndWaitForSvg(page, { appliedFilterCount, isSelected })

expect(await page.locator(wrapper).screenshot()).toMatchSnapshot(
`filter-tab-resting-${selected}-${appliedFilterCount}.png`
await expectSnapshot(
`filter-tab-resting-${selected}-${appliedFilterCount}`,
page.locator(wrapper)
)
})

Expand All @@ -87,8 +91,9 @@ test.describe("VFilterTab", () => {
await goAndWaitForSvg(page, { appliedFilterCount, isSelected })
await hoverFiltersTab(page)

expect(await page.locator(wrapper).screenshot()).toMatchSnapshot(
`filter-tab-hovered-${selected}-${appliedFilterCount}.png`
await expectSnapshot(
`filter-tab-hovered-${selected}-${appliedFilterCount}`,
page.locator(wrapper)
)
})
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { expect, test } from "@playwright/test"
import { test } from "@playwright/test"

import breakpoints from "~~/test/playwright/utils/breakpoints"
import {
Expand Down Expand Up @@ -29,7 +29,7 @@ test.describe("VHeaderInternal", () => {
})
})

breakpoints.describeXs(({ breakpoint }) => {
breakpoints.describeXs(({ expectSnapshot }) => {
test(`mobile header closed`, async ({ page }) => {
await page.goto(pageUrl(dir))

Expand All @@ -41,8 +41,9 @@ test.describe("VHeaderInternal", () => {

await page.mouse.move(0, 150)

await expect(page.locator(headerSelector)).toHaveScreenshot(
`mobile-header-internal-closed-${dir}-${breakpoint}.png`
await expectSnapshot(
`mobile-header-internal-closed-${dir}`,
page.locator(headerSelector)
)
})
})
Expand Down
13 changes: 10 additions & 3 deletions frontend/test/storybook/visual-regression/v-icon-button.spec.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@
import { expect, test } from "@playwright/test"

import { expectSnapshot } from "~~/test/storybook/utils/expect-snapshot"

test.describe("VIconButton", () => {
const url = "/iframe.html?id=components-viconbutton--sizes"

test("icon button sizes", async ({ page }) => {
await page.goto(url)
expect(await page.screenshot()).toMatchSnapshot({
name: "v-icon-button-sizes.png",
})

// Wait for buttons to be hydrated
await expect(page.getByRole("button")).toHaveCount(3)
await expect(page.getByRole("button").nth(0)).toBeEnabled()
await expectSnapshot(
"v-icon-button-sizes",
page.locator(".screenshot-area")
)
})
})
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ test.describe("VMediaReuse", () => {
await sleep(500)

await expectSnapshot(
`media-reuse-${dir}-${tab.id}-tab`,
`media-reuse-${tab.id}-tab-${dir}`,
page.locator(".media-reuse")
)
})
Expand Down
Loading

0 comments on commit c829801

Please sign in to comment.