learning_ai_notes/web/e2e/smart-actions.spec.ts

134 lines
3.9 KiB
TypeScript

import { test, expect } from "@playwright/test";
test.describe("Smart Actions", () => {
test.beforeEach(async ({ page }) => {
// Mock all backend API calls
await page.route("**/api/note-prompts**", (route) => {
if (route.request().method() === "GET") {
return route.fulfill({
status: 200,
contentType: "application/json",
body: JSON.stringify({
items: [
{
id: "builtin-summarize",
slug: "summarize",
name: "Summarize",
category: "transform",
isBuiltin: true,
inputType: "text",
outputType: "new_note",
},
{
id: "custom-1",
slug: "my-custom",
name: "My Custom Template",
category: "generate",
isBuiltin: false,
inputType: "text",
outputType: "replace",
},
],
total: 2,
}),
});
}
if (route.request().method() === "POST") {
return route.fulfill({
status: 201,
contentType: "application/json",
body: JSON.stringify({
id: "new-template-1",
slug: "new-template",
name: "New Template",
category: "transform",
isBuiltin: false,
}),
});
}
if (route.request().method() === "DELETE") {
return route.fulfill({ status: 204 });
}
return route.fulfill({ status: 200, contentType: "application/json", body: "{}" });
});
await page.route("**/api/notes**", (route) =>
route.fulfill({
status: 200,
contentType: "application/json",
body: JSON.stringify({ items: [], total: 0 }),
})
);
await page.route("**/api/workspaces**", (route) =>
route.fulfill({
status: 200,
contentType: "application/json",
body: JSON.stringify({ items: [], total: 0 }),
})
);
await page.route("**/api/prompt-schedules**", (route) =>
route.fulfill({
status: 200,
contentType: "application/json",
body: JSON.stringify({ items: [], total: 0 }),
})
);
await page.route("**/api/prompt-webhooks**", (route) =>
route.fulfill({
status: 200,
contentType: "application/json",
body: JSON.stringify({ items: [], total: 0 }),
})
);
await page.route("**/api/**", (route) =>
route.fulfill({ status: 200, contentType: "application/json", body: "{}" })
);
});
test("dashboard page loads with smart actions API mocked", async ({ page }) => {
await page.goto("/dashboard");
await page.waitForLoadState("domcontentloaded");
await expect(page.locator("body")).toBeVisible();
});
test("note detail page loads without JS errors", async ({ page }) => {
const errors: string[] = [];
page.on("pageerror", (err) => errors.push(err.message));
await page.goto("/notes/test-note-1");
await page.waitForLoadState("domcontentloaded");
await expect(page.locator("body")).toBeVisible();
const realErrors = errors.filter(
(e) =>
!e.includes("fetch") &&
!e.includes("Failed") &&
!e.includes("Unexpected") &&
!e.includes("hydration")
);
expect(realErrors).toHaveLength(0);
});
test("settings page loads without JS errors", async ({ page }) => {
const errors: string[] = [];
page.on("pageerror", (err) => errors.push(err.message));
await page.goto("/settings");
await page.waitForLoadState("domcontentloaded");
await expect(page.locator("body")).toBeVisible();
const realErrors = errors.filter(
(e) =>
!e.includes("fetch") &&
!e.includes("Failed") &&
!e.includes("Unexpected") &&
!e.includes("hydration")
);
expect(realErrors).toHaveLength(0);
});
});