2026-04-27 21:55:45 +08:00
|
|
|
import { expect, test } from "@playwright/test";
|
|
|
|
|
|
|
|
|
|
test.describe("Heading Hierarchy", () => {
|
|
|
|
|
const pages = [
|
|
|
|
|
{ path: "/", name: "Homepage" },
|
|
|
|
|
{ path: "/contact", name: "Contact" },
|
|
|
|
|
{ path: "/faq", name: "FAQ" },
|
|
|
|
|
{ path: "/privacy", name: "Privacy" },
|
|
|
|
|
{ path: "/terms", name: "Terms" },
|
2026-06-14 16:50:20 +08:00
|
|
|
{ path: "/enterprise", name: "Enterprise" },
|
2026-04-27 21:55:45 +08:00
|
|
|
];
|
|
|
|
|
|
|
|
|
|
for (const { path, name } of pages) {
|
|
|
|
|
test(`${name} page has exactly one h1`, async ({ page }) => {
|
|
|
|
|
await page.goto(path);
|
2026-07-10 14:03:29 +08:00
|
|
|
// toHaveCount auto-waits, so it doesn't race the dev server's on-demand render.
|
|
|
|
|
await expect(page.locator("h1")).toHaveCount(1);
|
2026-04-27 21:55:45 +08:00
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test.describe("External Links", () => {
|
|
|
|
|
test("GitHub links open in new tab with noopener", async ({ page }) => {
|
|
|
|
|
await page.goto("/");
|
|
|
|
|
const ghLinks = page.locator('a[href*="github.com"]');
|
|
|
|
|
const count = await ghLinks.count();
|
|
|
|
|
expect(count).toBeGreaterThan(0);
|
|
|
|
|
for (let i = 0; i < count; i++) {
|
|
|
|
|
const link = ghLinks.nth(i);
|
|
|
|
|
await expect(link).toHaveAttribute("target", "_blank");
|
|
|
|
|
const rel = await link.getAttribute("rel");
|
|
|
|
|
expect(rel).toContain("noopener");
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test("Docs link opens in new tab", async ({ page }) => {
|
|
|
|
|
await page.goto("/");
|
|
|
|
|
const docsLink = page.locator('a[href="https://docs.snapotter.com"]').first();
|
|
|
|
|
await expect(docsLink).toHaveAttribute("target", "_blank");
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test.describe("Landmark Elements", () => {
|
|
|
|
|
test("homepage has nav, main, and footer landmarks", async ({ page }) => {
|
|
|
|
|
await page.goto("/");
|
|
|
|
|
await expect(page.locator("nav").first()).toBeVisible();
|
|
|
|
|
await expect(page.locator("main")).toBeVisible();
|
|
|
|
|
await expect(page.locator("footer")).toBeVisible();
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
2026-06-14 16:50:20 +08:00
|
|
|
test.describe("Skip Link", () => {
|
|
|
|
|
test("skip link targets main content", async ({ page }) => {
|
|
|
|
|
await page.goto("/");
|
|
|
|
|
const skipLink = page.locator('a.skip-link[href="#main"]');
|
|
|
|
|
await expect(skipLink).toHaveAttribute("href", "#main");
|
|
|
|
|
await expect(page.locator("main#main")).toBeAttached();
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
2026-04-27 21:55:45 +08:00
|
|
|
test.describe("Meta Tags", () => {
|
|
|
|
|
test("homepage has meta description", async ({ page }) => {
|
|
|
|
|
await page.goto("/");
|
|
|
|
|
const metaDesc = page.locator('meta[name="description"]');
|
|
|
|
|
const content = await metaDesc.getAttribute("content");
|
|
|
|
|
expect(content).toBeTruthy();
|
2026-05-09 09:02:29 +08:00
|
|
|
expect(content?.length).toBeGreaterThan(10);
|
2026-04-27 21:55:45 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test("homepage has Open Graph tags", async ({ page }) => {
|
|
|
|
|
await page.goto("/");
|
2026-05-09 09:02:29 +08:00
|
|
|
await expect(page.locator('meta[property="og:title"]')).toHaveAttribute("content", /.+/);
|
|
|
|
|
await expect(page.locator('meta[property="og:description"]')).toHaveAttribute("content", /.+/);
|
2026-04-27 21:55:45 +08:00
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test.describe("Keyboard Navigation", () => {
|
|
|
|
|
test("Tab key moves focus through navbar links", async ({ page }) => {
|
|
|
|
|
await page.goto("/");
|
|
|
|
|
await page.keyboard.press("Tab");
|
|
|
|
|
const firstFocused = await page.evaluate(() => document.activeElement?.tagName);
|
|
|
|
|
expect(firstFocused).toBe("A");
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test.describe("Image Accessibility", () => {
|
2026-07-27 15:37:30 +08:00
|
|
|
// The logo sits inside a link that already carries the visible word
|
|
|
|
|
// SnapOtter, so alt text on it made a screen reader say the name twice
|
|
|
|
|
// (axe image-redundant-alt). It is marked decorative instead, and the link
|
|
|
|
|
// itself is what has to carry the accessible name.
|
|
|
|
|
test("navbar logo is decorative and its link is still named", async ({ page }) => {
|
2026-04-27 21:55:45 +08:00
|
|
|
await page.goto("/");
|
2026-07-27 15:37:30 +08:00
|
|
|
const logo = page.locator("nav img[src='/logo.png']");
|
2026-04-27 21:55:45 +08:00
|
|
|
await expect(logo).toBeVisible();
|
2026-07-27 15:37:30 +08:00
|
|
|
await expect(logo).toHaveAttribute("alt", "");
|
|
|
|
|
// `has` resolves relative to each candidate, so handing it the absolute
|
|
|
|
|
// `nav img[...]` locator asked for a <nav> inside the <a> and matched
|
|
|
|
|
// nothing, which made this assertion vacuous. Scope it to the image.
|
|
|
|
|
await expect(
|
|
|
|
|
page.locator("nav a").filter({ has: page.locator("img[src='/logo.png']") }),
|
|
|
|
|
).toHaveAccessibleName(/SnapOtter/);
|
2026-04-27 21:55:45 +08:00
|
|
|
});
|
|
|
|
|
});
|