import { expect, test } from "@playwright/test"
import { setTheme, setViewport, waitForPageReady, maskDynamicElements, buildMaskOption } from "./helpers/visual-helpers"
import { SCREENSHOT_DEFAULT_OPTIONS, THEMES, VIEWPORT_LIST, snapshotName } from "./visual.config"

/**
 * 首页(登录页)视觉回归测试
 *
 * 覆盖 desktop / tablet / mobile 三种视口,
 * 以及 light / dark 两种主题。
 * 快照命名: homepage-{viewport}-{theme}.png
 */
test.describe("Homepage visual regression", () => {
  for (const viewport of VIEWPORT_LIST) {
    for (const theme of THEMES) {
      test(`homepage @ ${viewport} @ ${theme}`, async ({ page }) => {
        await setViewport(page, viewport)
        await setTheme(page, theme)
        await page.goto("/login")
        await waitForPageReady(page)

        const masks = await maskDynamicElements(page)
        await expect(page).toHaveScreenshot(snapshotName("homepage", viewport, theme), {
          ...SCREENSHOT_DEFAULT_OPTIONS,
          ...buildMaskOption(masks),
        })
      })
    }
  }
})
