evOo-local/apps/web/e2e/thread-card.spec.ts
2026-10-05 00:23:59 +02:00

55 lines
2.3 KiB
TypeScript

import { expect, type Page, test } from "@playwright/test";
import { captureScreenshot, completeOnboarding, openUserSettings, signup } from "./helpers";
async function useAppearance(page: Page, appearance: "light" | "dark") {
const settings = await openUserSettings(page);
await settings.getByTestId(`ui-appearance-${appearance}`).click();
await expect(page.locator("html")).toHaveAttribute("data-theme", appearance);
await settings.getByRole("button", { name: "Close user settings" }).click();
await expect(settings).toBeHidden();
}
test("a bot's card is ticked off and answered with a tap", async ({ page }, testInfo) => {
const stamp = Date.now();
await signup(page, `thread-card-${stamp}@rakazo.test`, "password12", "Thread Card");
await completeOnboarding(page);
await page.getByPlaceholder(/Message/).fill("What should we cook tonight?");
await page.keyboard.press("Enter");
const card = page.getByTestId("thread-card");
await expect(card).toBeVisible({ timeout: 60_000 });
await expect(card).toContainText("Dinner tonight");
await expect(card).toContainText("30 min · 2 servings");
await card.getByRole("checkbox", { name: "Tomatoes" }).click();
await expect(card.getByRole("checkbox", { name: "Tomatoes" })).toBeChecked();
// The tick is stored, not just drawn.
await page.reload({ waitUntil: "domcontentloaded" });
await expect(
page.getByTestId("thread-card").getByRole("checkbox", { name: "Tomatoes" }),
).toBeChecked({
timeout: 30_000,
});
await useAppearance(page, "light");
await card.scrollIntoViewIfNeeded();
await captureScreenshot(page, testInfo, "thread-card-light");
await useAppearance(page, "dark");
await card.scrollIntoViewIfNeeded();
await captureScreenshot(page, testInfo, "thread-card-dark");
await card.getByRole("button", { name: "Curry" }).click();
await expect(card).toHaveAttribute("data-answered", "true", { timeout: 15_000 });
await expect(card.getByRole("button", { name: "Pasta" })).toBeDisabled();
// The choice reaches the bot as the user's reply.
await expect(
page.getByTestId("message-user-bubble").filter({ hasText: /^\s*Curry\s*$/ }),
).toHaveCount(1, {
timeout: 30_000,
});
// A checklist stays usable after the choice.
await card.getByRole("checkbox", { name: "Basil" }).click();
await expect(card.getByRole("checkbox", { name: "Basil" })).toBeChecked();
});