|
| 1 | +import { test, expect } from "./extension-fixture"; |
| 2 | +import type { Route, Page } from "@playwright/test"; |
| 3 | + |
| 4 | +// Regression test for ClickUp 86exu5xd7 — "Bring the ConsoleCrane into popup app". |
| 5 | +// |
| 6 | +// The popup reuses WordDetailModule, whose "Practice with AI" / "Preview |
| 7 | +// flashcard" buttons open the practice-config / flashcard-preview console pages. |
| 8 | +// On the popup page (no console-crane.js content script) these are hosted in the |
| 9 | +// popup's OWN router and render as full popup pages — no modal. This drives the |
| 10 | +// real popup.html end-to-end: |
| 11 | +// |
| 12 | +// open popup.html → translate stub → WordDetail renders + action buttons → |
| 13 | +// click → popup router navigates to the console page (no modal) → Back → |
| 14 | +// Home is restored (kept-alive) with the translation still shown. |
| 15 | + |
| 16 | +async function stubTranslate(page: Page) { |
| 17 | + await page.route("**/function/run", async (route: Route) => { |
| 18 | + const body = route.request().postDataJSON(); |
| 19 | + if (body?.name === "translateWithContext") { |
| 20 | + const phrase: string = body.args?.phrase ?? ""; |
| 21 | + const context: string = body.args?.context ?? ""; |
| 22 | + |
| 23 | + if (body.args?.translationType === "simple") { |
| 24 | + return route.fulfill({ |
| 25 | + status: 200, |
| 26 | + contentType: "application/json", |
| 27 | + body: JSON.stringify({ data: `[stub] ${phrase}` }), |
| 28 | + }); |
| 29 | + } |
| 30 | + |
| 31 | + // detailed — a truthy translation.phrase is what makes the action buttons show. |
| 32 | + return route.fulfill({ |
| 33 | + status: 200, |
| 34 | + contentType: "application/json", |
| 35 | + body: JSON.stringify({ |
| 36 | + data: { |
| 37 | + translation: { phrase: `[translated] ${phrase}`, context: "" }, |
| 38 | + direction: { source: "ltr", target: "ltr" }, |
| 39 | + language_info: { source: "English", target: "Spanish" }, |
| 40 | + linguistic_data: { |
| 41 | + isValid: true, |
| 42 | + type: "noun", |
| 43 | + definition: "a container with a flat base and sides", |
| 44 | + phonetic: { transliteration: "bɒks" }, |
| 45 | + formality_level: "neutral", |
| 46 | + }, |
| 47 | + chunks: [], |
| 48 | + context, |
| 49 | + }, |
| 50 | + }), |
| 51 | + }); |
| 52 | + } |
| 53 | + return route.fallback(); |
| 54 | + }); |
| 55 | + |
| 56 | + // Auth + saved-phrase lookups offline so the anonymous-login chain doesn't |
| 57 | + // reach the network or stall the flow. |
| 58 | + await page.route("**/user/**", (route) => |
| 59 | + route.fulfill({ |
| 60 | + status: 200, |
| 61 | + contentType: "application/json", |
| 62 | + body: JSON.stringify({ data: {} }), |
| 63 | + }) |
| 64 | + ); |
| 65 | + await page.route("**/data-provider/**", (route) => |
| 66 | + route.fulfill({ |
| 67 | + status: 200, |
| 68 | + contentType: "application/json", |
| 69 | + body: JSON.stringify({ data: null }), |
| 70 | + }) |
| 71 | + ); |
| 72 | +} |
| 73 | + |
| 74 | +/** |
| 75 | + * Open the popup page and translate a phrase. Asserts there is NO ConsoleCrane |
| 76 | + * modal app on the popup page (the old approach), then returns once WordDetail |
| 77 | + * has rendered its action buttons. |
| 78 | + */ |
| 79 | +async function openPopupAndTranslate(page: Page, extensionId: string) { |
| 80 | + await stubTranslate(page); |
| 81 | + await page.goto(`chrome-extension://${extensionId}/popup.html`); |
| 82 | + |
| 83 | + // No modal ConsoleCrane app is mounted on the popup page anymore. |
| 84 | + await expect(page.locator("#subturtle-console-crane-root")).toHaveCount(0); |
| 85 | + |
| 86 | + const input = page.getByPlaceholder("Type or paste any text"); |
| 87 | + await expect(input).toBeVisible({ timeout: 15_000 }); |
| 88 | + await input.fill("box"); |
| 89 | + await input.press("Enter"); |
| 90 | + |
| 91 | + await expect( |
| 92 | + page.locator('#subturtle-popup button:has-text("Practice with AI")') |
| 93 | + ).toBeVisible({ timeout: 15_000 }); |
| 94 | +} |
| 95 | + |
| 96 | +test.describe("Popup: ConsoleCrane phrase actions (router pages, no modal)", () => { |
| 97 | + test('"Practice with AI" navigates to the practice page; Back restores Home', async ({ |
| 98 | + context, |
| 99 | + extensionId, |
| 100 | + }) => { |
| 101 | + const page = await context.newPage(); |
| 102 | + await openPopupAndTranslate(page, extensionId); |
| 103 | + |
| 104 | + await page |
| 105 | + .locator('#subturtle-popup button:has-text("Practice with AI")') |
| 106 | + .click(); |
| 107 | + |
| 108 | + // Popup router navigated to the console page — full popup page, no modal. |
| 109 | + await expect(page.locator("#subturtle-popup")).toContainText( |
| 110 | + "Choose a coach voice", |
| 111 | + { timeout: 15_000 } |
| 112 | + ); |
| 113 | + expect(page.url()).toContain("#/practice-config/"); |
| 114 | + await expect(page.locator("#subturtle-console-crane-root")).toHaveCount(0); |
| 115 | + |
| 116 | + // Back returns to the kept-alive Home with the translation still rendered. |
| 117 | + await page.locator('#subturtle-popup button:has-text("Back")').click(); |
| 118 | + await expect(page.getByPlaceholder("Type or paste any text")).toBeVisible(); |
| 119 | + await expect( |
| 120 | + page.locator('#subturtle-popup button:has-text("Practice with AI")') |
| 121 | + ).toBeVisible(); |
| 122 | + |
| 123 | + await page.close(); |
| 124 | + }); |
| 125 | + |
| 126 | + test('"Preview flashcard" navigates to the flashcard page', async ({ |
| 127 | + context, |
| 128 | + extensionId, |
| 129 | + }) => { |
| 130 | + const page = await context.newPage(); |
| 131 | + await openPopupAndTranslate(page, extensionId); |
| 132 | + |
| 133 | + await page |
| 134 | + .locator('#subturtle-popup button:has-text("Preview flashcard")') |
| 135 | + .click(); |
| 136 | + |
| 137 | + await expect(page.locator("#subturtle-popup")).toContainText( |
| 138 | + "Flashcard preview", |
| 139 | + { timeout: 15_000 } |
| 140 | + ); |
| 141 | + expect(page.url()).toContain("#/flashcard-preview/"); |
| 142 | + await expect(page.locator("#subturtle-console-crane-root")).toHaveCount(0); |
| 143 | + |
| 144 | + await page.close(); |
| 145 | + }); |
| 146 | +}); |
0 commit comments