Skip to content

Commit

Permalink
Add the ability to check two snapshots for each test
Browse files Browse the repository at this point in the history
  • Loading branch information
obulat committed Sep 15, 2024
1 parent 6bcc141 commit 97f4618
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions frontend/test/playwright/utils/theme-switcher.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { Page } from "@playwright/test"

import { LanguageDirection, t } from "~~/test/playwright/utils/i18n"

type EffectiveColorMode = "dark" | "light"
const themeSelectLabel = (dir: LanguageDirection) => t("theme.theme", dir)
const themeOption = (colorMode: EffectiveColorMode, dir: LanguageDirection) =>
t(`theme.choices.${colorMode}`, dir)

export const setThemeSwitcherVisibility = async (
page: Page,
visibility: "visible" | "hidden"
) => {
await page.evaluate((visibility) => {
const themeSwitcher = document.getElementById("storybook-theme-switcher")
if (themeSwitcher) {
themeSwitcher.style.visibility = visibility
}
}, visibility)
}

export const turnOnDarkMode = async (page: Page, dir: LanguageDirection) => {
await setThemeSwitcherVisibility(page, "visible")
await page
.getByLabel(themeSelectLabel(dir))
.selectOption(themeOption("dark", dir))
await setThemeSwitcherVisibility(page, "hidden")
}

0 comments on commit 97f4618

Please sign in to comment.