|
| 1 | +import { admin, expect, MARK, providerCall, signIn, stackReady, test } from "./stack"; |
| 2 | +import type { Page } from "@playwright/test"; |
| 3 | + |
| 4 | +test.skip(!stackReady, "Local full stack is required (run ./.superset/db-gate.sh)"); |
| 5 | + |
| 6 | +async function addSource(page: Page, title: string, content: string) { |
| 7 | + await page.getByRole("button", { name: "Add Source" }).click(); |
| 8 | + await page.getByRole("textbox", { name: "Source title..." }).fill(title); |
| 9 | + await page.getByRole("textbox", { name: "Paste source content..." }).fill(content); |
| 10 | + await page.getByRole("button", { name: "Save to Library" }).click(); |
| 11 | + await expect(page.getByRole("switch", { name: `Toggle ${title}` })).toBeChecked(); |
| 12 | +} |
| 13 | + |
| 14 | +test("only active Library sources ground AI requests, and deletions persist", async ({ signedIn: page, user }) => { |
| 15 | + await page.goto("/app/library"); |
| 16 | + await addSource(page, "Active study", "ACTIVE-SOURCE-MARKER ridership rose after fares were removed."); |
| 17 | + await addSource(page, "Paused study", "PAUSED-SOURCE-MARKER congestion did not change."); |
| 18 | + await page.getByRole("switch", { name: "Toggle Paused study" }).click(); |
| 19 | + await expect(page.getByRole("switch", { name: "Toggle Paused study" })).not.toBeChecked(); |
| 20 | + |
| 21 | + await page.goto("/app/brainstorm"); |
| 22 | + await page.getByLabel("Motion / Topic *").fill("Public transport should be free"); |
| 23 | + await page.getByRole("button", { name: "Start Brainstorming" }).click(); |
| 24 | + await expect(page.getByText(`${MARK} idea 1`)).toBeVisible({ timeout: 30_000 }); |
| 25 | + const call = await providerCall("brainstorm"); |
| 26 | + expect(call.system).toContain("ACTIVE-SOURCE-MARKER"); |
| 27 | + expect(call.system).not.toContain("PAUSED-SOURCE-MARKER"); |
| 28 | + |
| 29 | + await page.goto("/app/library"); |
| 30 | + await page.getByRole("button", { name: "Delete Paused study", exact: true }).click(); |
| 31 | + await expect(page.getByRole("switch", { name: "Toggle Paused study" })).toHaveCount(0); |
| 32 | + await page.reload(); |
| 33 | + await expect(page.getByRole("switch", { name: "Toggle Active study" })).toBeVisible(); |
| 34 | + await expect(page.getByRole("switch", { name: "Toggle Paused study" })).toHaveCount(0); |
| 35 | + |
| 36 | + const { data } = await admin.from("sources").select("title").eq("user_id", await user.userId()); |
| 37 | + expect(data?.map((row) => row.title)).toEqual(["Active study"]); |
| 38 | +}); |
| 39 | + |
| 40 | +test("the output language setting follows the account and reaches the model", async ({ signedIn: page, user, browser }) => { |
| 41 | + await page.goto("/app/settings"); |
| 42 | + await page.locator("div.space-y-2", { has: page.getByText("AI Output Language", { exact: true }) }).getByRole("combobox").click(); |
| 43 | + await page.getByRole("option", { name: "Magyar" }).click(); |
| 44 | + await expect.poll(async () => { |
| 45 | + const { data } = await admin.from("user_settings").select("output_language").eq("user_id", await user.userId()).single(); |
| 46 | + return data?.output_language; |
| 47 | + }).toBe("hu"); |
| 48 | + |
| 49 | + // A new device starts with English defaults and must hydrate from the account. |
| 50 | + const context = await browser.newContext(); |
| 51 | + try { |
| 52 | + const other = await context.newPage(); |
| 53 | + await other.addInitScript(() => localStorage.setItem("debate-trainer-onboarding", JSON.stringify({ state: { hasCompletedOnboarding: true, isTourRunning: false }, version: 0 }))); |
| 54 | + await signIn(other, user); |
| 55 | + await other.goto("/app/attack"); |
| 56 | + await other.getByLabel("Your Argument *").fill("Free transit cuts congestion."); |
| 57 | + await other.getByRole("button", { name: "Find Weaknesses" }).click(); |
| 58 | + await expect(other.getByText(`${MARK} weakness`)).toBeVisible({ timeout: 30_000 }); |
| 59 | + expect((await providerCall("attack")).user).toContain("Language: Hungarian (hu)"); |
| 60 | + } finally { |
| 61 | + await context.close(); |
| 62 | + } |
| 63 | +}); |
| 64 | + |
| 65 | +test("a saved flowchart is stored on the account", async ({ signedIn: page, user }) => { |
| 66 | + const title = `Flow ${Date.now()}`; |
| 67 | + await page.goto("/app/flowchart"); |
| 68 | + await page.getByRole("button", { name: "Save", exact: true }).click(); |
| 69 | + const dialog = page.getByRole("dialog"); |
| 70 | + await dialog.getByRole("textbox").fill(title); |
| 71 | + await dialog.getByRole("button", { name: "Save Flowchart" }).click(); |
| 72 | + await expect(page.getByText("Flowchart saved successfully")).toBeVisible(); |
| 73 | + |
| 74 | + const { data } = await admin.from("flowcharts").select("title").eq("user_id", await user.userId()); |
| 75 | + expect(data?.map((row) => row.title)).toEqual([title]); |
| 76 | +}); |
0 commit comments