50 lines
1.9 KiB
TypeScript
50 lines
1.9 KiB
TypeScript
import { test, expect } from "@playwright/test";
|
|
|
|
test.describe("Dashboard", () => {
|
|
test.beforeEach(async ({ page }) => {
|
|
// Mock backend API calls so tests run without a running backend
|
|
await page.route("**/api/notes**", (route) =>
|
|
route.fulfill({ status: 200, contentType: "application/json", body: JSON.stringify({ notes: [], total: 0 }) })
|
|
);
|
|
await page.route("**/api/workspaces**", (route) =>
|
|
route.fulfill({ status: 200, contentType: "application/json", body: JSON.stringify({ workspaces: [] }) })
|
|
);
|
|
await page.route("**/api/**", (route) =>
|
|
route.fulfill({ status: 200, contentType: "application/json", body: "{}" })
|
|
);
|
|
});
|
|
|
|
test("dashboard page loads with mocked API", async ({ page }) => {
|
|
await page.goto("/dashboard");
|
|
await page.waitForLoadState("domcontentloaded");
|
|
await expect(page.locator("body")).toBeVisible();
|
|
});
|
|
|
|
test("dashboard shows empty state when no notes exist", async ({ page }) => {
|
|
await page.goto("/dashboard");
|
|
await page.waitForLoadState("domcontentloaded");
|
|
// Page renders without crashing even with empty data
|
|
const body = await page.locator("body").textContent();
|
|
expect(body).toBeTruthy();
|
|
});
|
|
|
|
test("renders without console errors", async ({ page }) => {
|
|
const errors: string[] = [];
|
|
page.on("pageerror", (err) => errors.push(err.message));
|
|
await page.goto("/dashboard");
|
|
await page.waitForLoadState("domcontentloaded");
|
|
const realErrors = errors.filter(
|
|
(e) => !e.includes("fetch") && !e.includes("Failed") && !e.includes("Unexpected")
|
|
);
|
|
expect(realErrors).toHaveLength(0);
|
|
});
|
|
|
|
test("404 page renders for unknown routes", async ({ page }) => {
|
|
const res = await page.goto("/nonexistent-route-xyz");
|
|
if (res) {
|
|
expect([200, 404]).toContain(res.status());
|
|
}
|
|
await expect(page.locator("body")).toBeVisible();
|
|
});
|
|
});
|