slint/docs/astro/tests/link-test.spec.ts
Nigel Breslaw 3fae8b2a9a
Docs tests: remove leading slash (#7170)
* Docs tests: remove leading slash

* Fix slash handling in link-data.json for the C++ docs

* Fix trailing slash handling for link-data.json for the Rust API docs

---------

Co-authored-by: Simon Hausmann <simon.hausmann@slint.dev>
2024-12-19 14:01:49 +02:00

38 lines
1.3 KiB
TypeScript

// Copyright © SixtyFPS GmbH <info@slint.dev>
// SPDX-License-Identifier: MIT
import { test, expect } from "@playwright/test";
import { linkMap } from "../src/utils/utils";
test("Test all links", async ({ page }) => {
for (const [key, value] of Object.entries(linkMap)) {
const href = value.href;
// Skip testing anchor links (internal page references)
if (href.includes("#")) {
// Optionally test if the base page exists
const basePath = href.split("#")[0];
if (basePath) {
const response = await page.goto(basePath);
const status = response?.status();
expect(
[200, 304].includes(status!),
`Link ${key} (${basePath}) returned ${status}`,
).toBeTruthy();
}
continue;
}
const response = await page.goto(href);
const status = response?.status();
expect(
[200, 304].includes(status!),
`Link ${key} (${href}) returned ${status}`,
).toBeTruthy();
// Optionally verify we didn't get to an error page
const title = await page.title();
expect(title, `Page ${href} has error title: ${title}`).not.toContain(
"404",
);
}
});