Files
famapp/tests/e2e/assistant.spec.ts
T

59 lines
2.6 KiB
TypeScript

import { expect, test, type Page } from "@playwright/test";
async function ensureSignedIn(page: Page) {
await page.goto("/");
const devLogin = page.getByRole("button", { name: "Dev login" });
if (await devLogin.isVisible().catch(() => false)) {
await devLogin.click();
await page.waitForURL((url) => !url.pathname.startsWith("/login"));
}
}
test("assistant bubble is hidden until opted in", async ({ page }) => {
await page.goto("/");
await expect(page.getByRole("button", { name: "Open assistant" })).toHaveCount(0);
});
test("assistant chat smoke after opt-in", async ({ page }) => {
await ensureSignedIn(page);
await page.goto("/settings?s=appearance");
const assistantSwitch = page.getByRole("switch", { name: "AI assistant" });
if (!(await assistantSwitch.isChecked())) {
await assistantSwitch.click();
}
await expect(assistantSwitch).toBeChecked();
await page.goto("/");
await page.getByRole("button", { name: "Open assistant" }).click();
await expect(page.getByRole("dialog", { name: "Assistant" })).toBeVisible();
const routeSelector = page.getByRole("combobox", { name: "Assistant model route" });
await expect(routeSelector).toBeVisible();
await routeSelector.selectOption("auto");
await expect(routeSelector).toHaveValue("auto");
await expect(routeSelector).toBeEnabled();
await routeSelector.selectOption("uncensored");
await expect(routeSelector).toHaveValue("uncensored");
await expect(routeSelector).toBeEnabled();
const modelSelector = page.getByRole("combobox", { name: "Assistant model", exact: true });
await expect(modelSelector).toBeVisible();
const refreshModels = page.getByRole("button", { name: "Refresh assistant models" });
await expect(refreshModels).toBeVisible();
await refreshModels.click();
await expect.poll(() => modelSelector.evaluate((node) => node.tagName)).toBe("SELECT");
await expect
.poll(() => modelSelector.evaluate((node) => node.getBoundingClientRect().height))
.toBeGreaterThanOrEqual(36);
await page.getByLabel("Message for Assistant").fill("hello assistant");
await page.getByRole("button", { name: "Send" }).click();
await expect(page.getByText("hello assistant")).toBeVisible();
const dialog = page.getByRole("dialog", { name: "Assistant" });
await expect(dialog.locator(".animate-spin").first()).toBeVisible({ timeout: 5000 });
await expect(dialog.locator(".animate-spin")).toHaveCount(0, { timeout: 30_000 });
await page.reload();
await page.getByRole("button", { name: "Open assistant" }).click();
await expect(page.getByText("hello assistant")).toBeVisible();
});