2026-04-27 21:56:45 +08:00
|
|
|
import { expect, test } from "@playwright/test";
|
|
|
|
|
|
2026-06-19 18:46:59 +08:00
|
|
|
test.describe("docs search (Pagefind)", () => {
|
2026-04-27 21:56:45 +08:00
|
|
|
test("search button is visible", async ({ page }) => {
|
2026-06-19 18:46:59 +08:00
|
|
|
await page.goto("/");
|
|
|
|
|
await expect(page.locator(".blog-search").first()).toBeVisible();
|
2026-04-27 21:56:45 +08:00
|
|
|
});
|
|
|
|
|
|
2026-06-19 18:46:59 +08:00
|
|
|
test("clicking search opens the dialog with an input", async ({ page }) => {
|
|
|
|
|
await page.goto("/");
|
|
|
|
|
await page.locator(".blog-search").first().click();
|
|
|
|
|
await expect(page.locator('input[placeholder="Search Docs"]')).toBeVisible();
|
2026-04-27 21:56:45 +08:00
|
|
|
});
|
|
|
|
|
|
2026-06-19 18:46:59 +08:00
|
|
|
test("typing a query shows results", async ({ page }) => {
|
|
|
|
|
await page.goto("/");
|
|
|
|
|
await page.locator(".blog-search").first().click();
|
|
|
|
|
const input = page.locator('input[placeholder="Search Docs"]');
|
|
|
|
|
await input.fill("docker");
|
|
|
|
|
await expect(page.locator('[role="option"]').first()).toBeVisible({ timeout: 10000 });
|
2026-04-27 21:56:45 +08:00
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test.describe("Theme Toggle", () => {
|
2026-04-27 22:34:11 +08:00
|
|
|
test("theme toggle exists in DOM", async ({ page }) => {
|
2026-04-27 21:56:45 +08:00
|
|
|
await page.goto("/guide/getting-started");
|
|
|
|
|
const toggle = page.locator(
|
2026-04-27 22:34:11 +08:00
|
|
|
'button[role="switch"][title*="dark"], button[role="switch"][title*="light"]',
|
2026-04-27 21:56:45 +08:00
|
|
|
);
|
2026-04-27 22:34:11 +08:00
|
|
|
await expect(toggle.first()).toBeAttached();
|
2026-04-27 21:56:45 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test("clicking theme toggle changes appearance", async ({ page }) => {
|
|
|
|
|
await page.goto("/guide/getting-started");
|
2026-06-19 18:46:59 +08:00
|
|
|
const html = page.locator("html");
|
|
|
|
|
const initialClass = await html.getAttribute("class");
|
|
|
|
|
const wasDark = initialClass?.includes("dark") ?? false;
|
2026-04-27 21:56:45 +08:00
|
|
|
|
2026-06-19 18:46:59 +08:00
|
|
|
// Click the visible toggle inside our custom nav area (the hidden default
|
|
|
|
|
// VPNavBarAppearance is first in DOM order, so a bare querySelector would
|
|
|
|
|
// hit it instead). Playwright's click auto-waits for hydration.
|
|
|
|
|
await page.locator('.nav-bar-right button[role="switch"]').click();
|
2026-04-27 21:56:45 +08:00
|
|
|
|
2026-06-19 18:46:59 +08:00
|
|
|
// Assert the dark class actually toggled
|
|
|
|
|
if (wasDark) {
|
|
|
|
|
await expect(html).not.toHaveClass(/dark/);
|
|
|
|
|
} else {
|
|
|
|
|
await expect(html).toHaveClass(/dark/);
|
|
|
|
|
}
|
2026-04-27 21:56:45 +08:00
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test.describe("GitHub Stars Component", () => {
|
|
|
|
|
test("GitHub star button is visible in navbar", async ({ page }) => {
|
|
|
|
|
await page.goto("/");
|
|
|
|
|
const githubBtn = page.locator(".github-btn, .github-btn-wrapper").first();
|
|
|
|
|
await expect(githubBtn).toBeVisible();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test("GitHub star button links to correct repo", async ({ page }) => {
|
|
|
|
|
await page.goto("/");
|
|
|
|
|
const starLink = page.locator('a[title="Star on GitHub"]').first();
|
2026-04-27 22:34:11 +08:00
|
|
|
await expect(starLink).toHaveAttribute("href", "https://github.com/snapotter-hq/snapotter");
|
2026-04-27 21:56:45 +08:00
|
|
|
await expect(starLink).toHaveAttribute("target", "_blank");
|
|
|
|
|
});
|
|
|
|
|
});
|