|
| 1 | +import { test, expect } from "@playwright/test"; |
| 2 | +import type { ConsoleMessage, Page } from "@playwright/test"; |
| 3 | + |
| 4 | +/** |
| 5 | + * CI-safe smoke test for the Northwind banking showcase. |
| 6 | + * |
| 7 | + * What this covers: |
| 8 | + * 1. App boots and the dashboard renders credible content (brand + cards UI). |
| 9 | + * 2. The CopilotKit v2 popup launcher opens the modal. |
| 10 | + * 3. The three configured suggestion pills are visible. |
| 11 | + * |
| 12 | + * What this intentionally does NOT do: |
| 13 | + * - Send any chat message |
| 14 | + * - Click any suggestion (which would invoke the agent / hit OpenAI) |
| 15 | + * - Exercise any tool |
| 16 | + * |
| 17 | + * That keeps the test runnable in CI without secrets. |
| 18 | + */ |
| 19 | + |
| 20 | +// Console-error filtering: the page may legitimately log network errors for |
| 21 | +// the /api/copilotkit endpoint (e.g. if the popup pings it on open and the |
| 22 | +// runtime fails because OPENAI_API_KEY is a dummy value), and Next.js dev mode |
| 23 | +// prints various non-fatal warnings. We only fail on genuine page/script |
| 24 | +// errors that indicate the app itself is broken. |
| 25 | +const IGNORED_ERROR_PATTERNS: RegExp[] = [ |
| 26 | + /favicon/i, |
| 27 | + /\/api\/copilotkit/i, |
| 28 | + /Failed to load resource/i, |
| 29 | + /net::ERR_/i, |
| 30 | + /Download the React DevTools/i, |
| 31 | + /Hydration/i, // Next.js dev-only hydration warnings are out of scope |
| 32 | +]; |
| 33 | + |
| 34 | +function isIgnoredError(message: ConsoleMessage): boolean { |
| 35 | + if (message.type() !== "error") return true; |
| 36 | + const text = message.text(); |
| 37 | + return IGNORED_ERROR_PATTERNS.some((re) => re.test(text)); |
| 38 | +} |
| 39 | + |
| 40 | +function collectConsoleErrors(page: Page): string[] { |
| 41 | + const errors: string[] = []; |
| 42 | + page.on("console", (msg) => { |
| 43 | + if (msg.type() === "error" && !isIgnoredError(msg)) { |
| 44 | + errors.push(msg.text()); |
| 45 | + } |
| 46 | + }); |
| 47 | + return errors; |
| 48 | +} |
| 49 | + |
| 50 | +test.describe("banking showcase smoke", () => { |
| 51 | + test("dashboard renders and popup opens with suggestions", async ({ |
| 52 | + page, |
| 53 | + }) => { |
| 54 | + const consoleErrors = collectConsoleErrors(page); |
| 55 | + |
| 56 | + await page.goto("/"); |
| 57 | + |
| 58 | + // Brand assertion: the document title is the Northwind Finance brand. |
| 59 | + await expect(page).toHaveTitle(/Northwind/); |
| 60 | + |
| 61 | + // The credit-cards page renders an h1 "Credit Cards" and an "Add Card" |
| 62 | + // dropdown — that's our credible-content check that the dashboard is up. |
| 63 | + await expect( |
| 64 | + page.getByRole("heading", { name: "Credit Cards", level: 1 }), |
| 65 | + ).toBeVisible(); |
| 66 | + |
| 67 | + // Open the CopilotKit popup. v2 renders a fixed launcher button with |
| 68 | + // data-testid="copilot-chat-toggle" (see CopilotChatToggleButton.tsx). |
| 69 | + const launcher = page.getByTestId("copilot-chat-toggle"); |
| 70 | + await expect(launcher).toBeVisible(); |
| 71 | + await launcher.click(); |
| 72 | + |
| 73 | + // The popup modal exposes the configured assistant title as its aria-label |
| 74 | + // (modalHeaderTitle = IDENTITY.assistant = "Northwind Copilot"). We assert |
| 75 | + // on the dialog rather than visible text since the title may be rendered |
| 76 | + // as aria-only. |
| 77 | + await expect( |
| 78 | + page.getByRole("dialog", { name: /Northwind Copilot/i }), |
| 79 | + ).toBeVisible(); |
| 80 | + |
| 81 | + // The three suggestion pills configured by BankingSuggestions render as |
| 82 | + // buttons with data-testid="copilot-suggestion" (see |
| 83 | + // CopilotChatSuggestionPill.tsx). Their labels are the suggestion titles. |
| 84 | + const suggestions = page.getByTestId("copilot-suggestion"); |
| 85 | + await expect(suggestions).toHaveCount(3); |
| 86 | + await expect( |
| 87 | + suggestions.filter({ hasText: "View transactions" }), |
| 88 | + ).toBeVisible(); |
| 89 | + await expect(suggestions.filter({ hasText: "Add a card" })).toBeVisible(); |
| 90 | + await expect( |
| 91 | + suggestions.filter({ hasText: "Assign a policy" }), |
| 92 | + ).toBeVisible(); |
| 93 | + |
| 94 | + // Make sure nothing genuinely broken showed up in the console while the |
| 95 | + // page rendered and the popup opened. |
| 96 | + expect( |
| 97 | + consoleErrors, |
| 98 | + `Unexpected console errors:\n${consoleErrors.join("\n")}`, |
| 99 | + ).toEqual([]); |
| 100 | + }); |
| 101 | +}); |
0 commit comments