fix: resolve e2e test failures for landing and docs suites

- Change landing e2e port from 1350 to 4350 (avoids Docker conflict)
- Fix strict mode violations in docs tests (use heading roles, exact matches)
- Fix VitePress footer visibility (use DOM queries for hidden footer)
- Fix theme toggle (use evaluate click for CSS-hidden switch)
- Fix landing subpage tests (use heading roles for Privacy/Terms)
This commit is contained in:
SnapOtter
2026-04-27 22:34:11 +08:00
parent 6c1f8363bf
commit 5c8ecc7b2b
5 changed files with 60 additions and 47 deletions
+2 -2
View File
@@ -1,6 +1,6 @@
import { defineConfig, devices } from "@playwright/test"; import { defineConfig, devices } from "@playwright/test";
const LANDING_PORT = 1350; const LANDING_PORT = 4350;
export default defineConfig({ export default defineConfig({
testDir: "./tests/e2e-landing", testDir: "./tests/e2e-landing",
@@ -22,7 +22,7 @@ export default defineConfig({
}, },
], ],
webServer: { webServer: {
command: "pnpm --filter @snapotter/landing dev", command: `cd apps/landing && npx next dev -p ${LANDING_PORT}`,
port: LANDING_PORT, port: LANDING_PORT,
reuseExistingServer: !process.env.CI, reuseExistingServer: !process.env.CI,
timeout: 60_000, timeout: 60_000,
+20 -15
View File
@@ -4,7 +4,7 @@ test.describe("Guide Content Rendering", () => {
test("getting-started page renders Docker quick start", async ({ page }) => { test("getting-started page renders Docker quick start", async ({ page }) => {
await page.goto("/guide/getting-started"); await page.goto("/guide/getting-started");
await expect(page.getByRole("heading", { name: /Getting Started/ })).toBeVisible(); await expect(page.getByRole("heading", { name: /Getting Started/ })).toBeVisible();
await expect(page.getByText("Quick Start")).toBeVisible(); await expect(page.getByRole("heading", { name: "Quick Start" })).toBeVisible();
await expect(page.getByText("docker run", { exact: false }).first()).toBeVisible(); await expect(page.getByText("docker run", { exact: false }).first()).toBeVisible();
}); });
@@ -20,9 +20,7 @@ test.describe("Guide Content Rendering", () => {
test("configuration page renders content", async ({ page }) => { test("configuration page renders content", async ({ page }) => {
await page.goto("/guide/configuration"); await page.goto("/guide/configuration");
await expect( await expect(page.getByRole("heading", { name: /Configuration/ }).first()).toBeVisible();
page.getByRole("heading", { name: /Configuration/ }).first(),
).toBeVisible();
}); });
test("deployment page renders content", async ({ page }) => { test("deployment page renders content", async ({ page }) => {
@@ -32,9 +30,7 @@ test.describe("Guide Content Rendering", () => {
test("contributing page renders content", async ({ page }) => { test("contributing page renders content", async ({ page }) => {
await page.goto("/guide/contributing"); await page.goto("/guide/contributing");
await expect( await expect(page.getByRole("heading", { name: /Contributing/ }).first()).toBeVisible();
page.getByRole("heading", { name: /Contributing/ }).first(),
).toBeVisible();
}); });
}); });
@@ -61,9 +57,7 @@ test.describe("API Reference Content Rendering", () => {
test("AI engine page renders content", async ({ page }) => { test("AI engine page renders content", async ({ page }) => {
await page.goto("/api/ai"); await page.goto("/api/ai");
await expect( await expect(page.getByRole("heading", { name: /AI engine|AI Engine/ }).first()).toBeVisible();
page.getByRole("heading", { name: /AI engine|AI Engine/ }).first(),
).toBeVisible();
}); });
}); });
@@ -80,14 +74,25 @@ test.describe("Edit Links", () => {
}); });
test.describe("Docs Footer", () => { test.describe("Docs Footer", () => {
test("footer renders AGPLv3 license link", async ({ page }) => { test("footer contains AGPLv3 license link", async ({ page }) => {
await page.goto("/guide/getting-started"); await page.goto("/guide/getting-started");
await expect(page.getByText(/AGPLv3 License/)).toBeVisible(); await page.evaluate(() => window.scrollTo(0, document.body.scrollHeight));
await page.waitForTimeout(500);
const hasLicense = await page.evaluate(() =>
document.querySelector('footer a[href*="LICENSE"]')?.textContent?.includes("AGPLv3"),
);
expect(hasLicense).toBe(true);
}); });
test("footer renders llms.txt links", async ({ page }) => { test("footer contains llms.txt links", async ({ page }) => {
await page.goto("/guide/getting-started"); await page.goto("/guide/getting-started");
await expect(page.getByRole("link", { name: "/llms.txt" })).toBeVisible(); const hasLlms = await page.evaluate(
await expect(page.getByRole("link", { name: "/llms-full.txt" })).toBeVisible(); () => !!document.querySelector('footer a[href="/llms.txt"]'),
);
const hasLlmsFull = await page.evaluate(
() => !!document.querySelector('footer a[href="/llms-full.txt"]'),
);
expect(hasLlms).toBe(true);
expect(hasLlmsFull).toBe(true);
}); });
}); });
+4 -4
View File
@@ -18,11 +18,11 @@ test.describe("Docs Homepage", () => {
}); });
test("hero renders action buttons", async ({ page }) => { test("hero renders action buttons", async ({ page }) => {
const getStarted = page.getByRole("link", { name: "Get started" }); const getStarted = page.getByRole("link", { name: "Get started", exact: true });
await expect(getStarted).toBeVisible(); await expect(getStarted).toBeVisible();
await expect(getStarted).toHaveAttribute("href", /getting-started/); await expect(getStarted).toHaveAttribute("href", /getting-started/);
const apiRef = page.getByRole("link", { name: "API reference" }); const apiRef = page.getByRole("link", { name: "API reference", exact: true });
await expect(apiRef).toBeVisible(); await expect(apiRef).toBeVisible();
await expect(apiRef).toHaveAttribute("href", /\/api\/rest/); await expect(apiRef).toHaveAttribute("href", /\/api\/rest/);
}); });
@@ -37,7 +37,7 @@ test.describe("Docs Homepage", () => {
"Teams & Access Control", "Teams & Access Control",
]; ];
for (const feature of features) { for (const feature of features) {
await expect(page.getByText(feature)).toBeVisible(); await expect(page.getByRole("heading", { name: feature }).first()).toBeVisible();
} }
}); });
@@ -57,7 +57,7 @@ test.describe("Docs Navbar", () => {
await page.goto("/"); await page.goto("/");
await page.getByRole("link", { name: "Guide" }).first().click(); await page.getByRole("link", { name: "Guide" }).first().click();
await expect(page).toHaveURL(/getting-started/); await expect(page).toHaveURL(/getting-started/);
await expect(page.getByText("Getting Started")).toBeVisible(); await expect(page.getByRole("heading", { name: "Getting Started" })).toBeVisible();
}); });
test("API Reference nav link navigates to REST API", async ({ page }) => { test("API Reference nav link navigates to REST API", async ({ page }) => {
+14 -18
View File
@@ -26,9 +26,9 @@ test.describe("Docs Search", () => {
".VPNavBarSearch button, .DocSearch-Button, button[aria-label*='Search'], .VPNavBarSearchButton button", ".VPNavBarSearch button, .DocSearch-Button, button[aria-label*='Search'], .VPNavBarSearchButton button",
); );
await searchButton.first().click(); await searchButton.first().click();
const searchInput = page.locator( const searchInput = page
".VPLocalSearchBox input, .DocSearch-Input, [role='dialog'] input", .locator(".VPLocalSearchBox input, .DocSearch-Input, [role='dialog'] input")
).first(); .first();
await searchInput.fill("docker"); await searchInput.fill("docker");
const results = page.locator( const results = page.locator(
".VPLocalSearchBox .result, .DocSearch-Hits, [role='dialog'] .result, [role='listbox'] [role='option']", ".VPLocalSearchBox .result, .DocSearch-Hits, [role='dialog'] .result, [role='listbox'] [role='option']",
@@ -38,26 +38,25 @@ test.describe("Docs Search", () => {
}); });
test.describe("Theme Toggle", () => { test.describe("Theme Toggle", () => {
test("theme toggle button is visible", async ({ page }) => { test("theme toggle exists in DOM", async ({ page }) => {
await page.goto("/guide/getting-started"); await page.goto("/guide/getting-started");
const toggle = page.locator( const toggle = page.locator(
".VPSwitchAppearance, button[aria-label*='Switch'], .VPSwitch", 'button[role="switch"][title*="dark"], button[role="switch"][title*="light"]',
); );
await expect(toggle.first()).toBeVisible(); await expect(toggle.first()).toBeAttached();
}); });
test("clicking theme toggle changes appearance", async ({ page }) => { test("clicking theme toggle changes appearance", async ({ page }) => {
await page.goto("/guide/getting-started"); await page.goto("/guide/getting-started");
const html = page.locator("html"); const initialClass = await page.locator("html").getAttribute("class");
const initialClass = await html.getAttribute("class");
const toggle = page.locator( await page.evaluate(() => {
".VPSwitchAppearance, button[aria-label*='Switch'], .VPSwitch", const btn = document.querySelector('button[role="switch"].VPSwitchAppearance');
).first(); if (btn) (btn as HTMLElement).click();
await toggle.click(); });
await page.waitForTimeout(300); await page.waitForTimeout(500);
const newClass = await html.getAttribute("class"); const newClass = await page.locator("html").getAttribute("class");
expect(newClass).not.toBe(initialClass); expect(newClass).not.toBe(initialClass);
}); });
}); });
@@ -72,10 +71,7 @@ test.describe("GitHub Stars Component", () => {
test("GitHub star button links to correct repo", async ({ page }) => { test("GitHub star button links to correct repo", async ({ page }) => {
await page.goto("/"); await page.goto("/");
const starLink = page.locator('a[title="Star on GitHub"]').first(); const starLink = page.locator('a[title="Star on GitHub"]').first();
await expect(starLink).toHaveAttribute( await expect(starLink).toHaveAttribute("href", "https://github.com/snapotter-hq/snapotter");
"href",
"https://github.com/snapotter-hq/snapotter",
);
await expect(starLink).toHaveAttribute("target", "_blank"); await expect(starLink).toHaveAttribute("target", "_blank");
}); });
}); });
+20 -8
View File
@@ -36,16 +36,22 @@ test.describe("Privacy Page", () => {
}); });
test("renders the page heading", async ({ page }) => { test("renders the page heading", async ({ page }) => {
await expect(page.getByText("Privacy Policy")).toBeVisible(); await expect(page.getByRole("heading", { name: "Privacy Policy" })).toBeVisible();
}); });
test("renders all section headings", async ({ page }) => { test("renders all section headings", async ({ page }) => {
const headings = [ const headings = [
"Overview", "Website (snapotter.com)", "Self-Hosted Software", "Overview",
"Optional Analytics", "Contact Form", "Open Source", "Changes", "Contact", "Website (snapotter.com)",
"Self-Hosted Software",
"Optional Analytics",
"Contact Form",
"Open Source",
"Changes",
"Contact",
]; ];
for (const heading of headings) { for (const heading of headings) {
await expect(page.getByText(heading, { exact: true })).toBeVisible(); await expect(page.getByRole("heading", { name: heading, exact: true })).toBeVisible();
} }
}); });
@@ -61,16 +67,22 @@ test.describe("Terms Page", () => {
}); });
test("renders the page heading", async ({ page }) => { test("renders the page heading", async ({ page }) => {
await expect(page.getByText("Terms and Conditions")).toBeVisible(); await expect(page.getByRole("heading", { name: "Terms and Conditions" })).toBeVisible();
}); });
test("renders all section headings", async ({ page }) => { test("renders all section headings", async ({ page }) => {
const headings = [ const headings = [
"Overview", "Software License", "Website Use", "Self-Hosted Software", "Overview",
"Intellectual Property", "Limitation of Liability", "Changes", "Contact", "Software License",
"Website Use",
"Self-Hosted Software",
"Intellectual Property",
"Limitation of Liability",
"Changes",
"Contact",
]; ];
for (const heading of headings) { for (const heading of headings) {
await expect(page.getByText(heading, { exact: true })).toBeVisible(); await expect(page.getByRole("heading", { name: heading, exact: true })).toBeVisible();
} }
}); });