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
+20 -15
View File
@@ -4,7 +4,7 @@ test.describe("Guide Content Rendering", () => {
test("getting-started page renders Docker quick start", async ({ page }) => {
await page.goto("/guide/getting-started");
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();
});
@@ -20,9 +20,7 @@ test.describe("Guide Content Rendering", () => {
test("configuration page renders content", async ({ page }) => {
await page.goto("/guide/configuration");
await expect(
page.getByRole("heading", { name: /Configuration/ }).first(),
).toBeVisible();
await expect(page.getByRole("heading", { name: /Configuration/ }).first()).toBeVisible();
});
test("deployment page renders content", async ({ page }) => {
@@ -32,9 +30,7 @@ test.describe("Guide Content Rendering", () => {
test("contributing page renders content", async ({ page }) => {
await page.goto("/guide/contributing");
await expect(
page.getByRole("heading", { name: /Contributing/ }).first(),
).toBeVisible();
await expect(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 }) => {
await page.goto("/api/ai");
await expect(
page.getByRole("heading", { name: /AI engine|AI Engine/ }).first(),
).toBeVisible();
await expect(page.getByRole("heading", { name: /AI engine|AI Engine/ }).first()).toBeVisible();
});
});
@@ -80,14 +74,25 @@ test.describe("Edit Links", () => {
});
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 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 expect(page.getByRole("link", { name: "/llms.txt" })).toBeVisible();
await expect(page.getByRole("link", { name: "/llms-full.txt" })).toBeVisible();
const hasLlms = await page.evaluate(
() => !!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 }) => {
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).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).toHaveAttribute("href", /\/api\/rest/);
});
@@ -37,7 +37,7 @@ test.describe("Docs Homepage", () => {
"Teams & Access Control",
];
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.getByRole("link", { name: "Guide" }).first().click();
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 }) => {
+14 -18
View File
@@ -26,9 +26,9 @@ test.describe("Docs Search", () => {
".VPNavBarSearch button, .DocSearch-Button, button[aria-label*='Search'], .VPNavBarSearchButton button",
);
await searchButton.first().click();
const searchInput = page.locator(
".VPLocalSearchBox input, .DocSearch-Input, [role='dialog'] input",
).first();
const searchInput = page
.locator(".VPLocalSearchBox input, .DocSearch-Input, [role='dialog'] input")
.first();
await searchInput.fill("docker");
const results = page.locator(
".VPLocalSearchBox .result, .DocSearch-Hits, [role='dialog'] .result, [role='listbox'] [role='option']",
@@ -38,26 +38,25 @@ test.describe("Docs Search", () => {
});
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");
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 }) => {
await page.goto("/guide/getting-started");
const html = page.locator("html");
const initialClass = await html.getAttribute("class");
const initialClass = await page.locator("html").getAttribute("class");
const toggle = page.locator(
".VPSwitchAppearance, button[aria-label*='Switch'], .VPSwitch",
).first();
await toggle.click();
await page.waitForTimeout(300);
await page.evaluate(() => {
const btn = document.querySelector('button[role="switch"].VPSwitchAppearance');
if (btn) (btn as HTMLElement).click();
});
await page.waitForTimeout(500);
const newClass = await html.getAttribute("class");
const newClass = await page.locator("html").getAttribute("class");
expect(newClass).not.toBe(initialClass);
});
});
@@ -72,10 +71,7 @@ test.describe("GitHub Stars Component", () => {
test("GitHub star button links to correct repo", async ({ page }) => {
await page.goto("/");
const starLink = page.locator('a[title="Star on GitHub"]').first();
await expect(starLink).toHaveAttribute(
"href",
"https://github.com/snapotter-hq/snapotter",
);
await expect(starLink).toHaveAttribute("href", "https://github.com/snapotter-hq/snapotter");
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 }) => {
await expect(page.getByText("Privacy Policy")).toBeVisible();
await expect(page.getByRole("heading", { name: "Privacy Policy" })).toBeVisible();
});
test("renders all section headings", async ({ page }) => {
const headings = [
"Overview", "Website (snapotter.com)", "Self-Hosted Software",
"Optional Analytics", "Contact Form", "Open Source", "Changes", "Contact",
"Overview",
"Website (snapotter.com)",
"Self-Hosted Software",
"Optional Analytics",
"Contact Form",
"Open Source",
"Changes",
"Contact",
];
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 }) => {
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 }) => {
const headings = [
"Overview", "Software License", "Website Use", "Self-Hosted Software",
"Intellectual Property", "Limitation of Liability", "Changes", "Contact",
"Overview",
"Software License",
"Website Use",
"Self-Hosted Software",
"Intellectual Property",
"Limitation of Liability",
"Changes",
"Contact",
];
for (const heading of headings) {
await expect(page.getByText(heading, { exact: true })).toBeVisible();
await expect(page.getByRole("heading", { name: heading, exact: true })).toBeVisible();
}
});