Files

40 lines
1.9 KiB
JavaScript

// SPDX-License-Identifier: LicenseRef-ConusAI-Template-1.0
// Read-only browser smoke for a built image or a live deployment. No account is needed.
// pnpm exec playwright install chromium
// node scripts/verify-shell.mjs https://your-app.example.test
import { strict as assert } from "node:assert"
import { chromium, expect } from "@playwright/test"
const base = new URL(process.argv[2] ?? "http://127.0.0.1:3000")
assert(["http:", "https:"].includes(base.protocol), "expected an HTTP(S) app URL")
const browser = await chromium.launch()
try {
const context = await browser.newContext({ locale: "en-US" })
const page = await context.newPage()
page.setDefaultTimeout(15_000)
const errors = []
page.on("pageerror", (error) => errors.push(error.message))
const response = await page.goto(new URL("/", base).href, { waitUntil: "networkidle" })
assert.equal(response?.status(), 200)
const root = page.locator("html")
await page.getByRole("button", { name: "Theme: Dark", exact: true }).click()
await expect(root).toHaveClass("light")
await page.reload()
await expect(root).toHaveClass("light")
await page.getByRole("combobox", { name: /^Language/ }).selectOption("lt")
await expect(root).toHaveAttribute("lang", "lt")
await expect(page.getByRole("button", { name: "Tema: Šviesi", exact: true })).toBeVisible()
await page.reload()
await expect(root).toHaveAttribute("lang", "lt")
await expect(root).toHaveClass("light")
await page.getByRole("button", { name: "Tema: Šviesi", exact: true }).click()
await expect(root).not.toHaveClass("light")
await page.getByRole("combobox", { name: /^Kalba/ }).selectOption("en")
await expect(root).toHaveAttribute("lang", "en")
await expect(page.getByRole("button", { name: "Theme: Dark", exact: true })).toBeVisible()
assert.deepEqual(errors, [], "browser runtime errors")
console.log("verify-shell: theme and language switch both ways and persist across reloads")
} finally {
await browser.close()
}