|
| 1 | +import { expect, test } from "@playwright/test"; |
| 2 | + |
| 3 | +/** |
| 4 | + * Regression tests for ?tab= deep links on the proposal detail page |
| 5 | + * (e.g. the "View all updates" link on nogglesrails pages points to |
| 6 | + * /proposals/base/{n}?tab=propdates). |
| 7 | + * |
| 8 | + * The votes/propdates tabs are revealed post-mount from fetched data, so the |
| 9 | + * deep link is honored asynchronously — assertions wait for the trigger to |
| 10 | + * appear before checking it is active. |
| 11 | + */ |
| 12 | + |
| 13 | +interface EnrichedEntry { |
| 14 | + proposal: { proposalNumber: number }; |
| 15 | + propdates: unknown[]; |
| 16 | +} |
| 17 | + |
| 18 | +async function findProposalWithPropdates( |
| 19 | + request: Parameters<Parameters<typeof test>[2]>[0]["request"], |
| 20 | +): Promise<number | null> { |
| 21 | + const res = await request.get("/api/propdates/enriched"); |
| 22 | + if (!res.ok()) return null; |
| 23 | + const entries = (await res.json()) as EnrichedEntry[]; |
| 24 | + const entry = entries.find((e) => (e.propdates?.length ?? 0) > 0); |
| 25 | + return entry ? entry.proposal.proposalNumber : null; |
| 26 | +} |
| 27 | + |
| 28 | +// Serial: three parallel first-loads of the same heavy route stall the dev |
| 29 | +// server past the goto timeout; these are fast (<5s each) once compiled. |
| 30 | +test.describe.configure({ mode: "serial" }); |
| 31 | + |
| 32 | +test.describe("Proposal tab deep links", () => { |
| 33 | + test("?tab=propdates activates the Propdates tab", async ({ page, request }) => { |
| 34 | + const proposalNumber = await findProposalWithPropdates(request); |
| 35 | + test.skip(proposalNumber === null, "No proposal with propdates in this environment"); |
| 36 | + |
| 37 | + await page.goto(`/proposals/base/${proposalNumber}?tab=propdates`, { |
| 38 | + waitUntil: "domcontentloaded", |
| 39 | + timeout: 60000, |
| 40 | + }); |
| 41 | + |
| 42 | + const propdatesTab = page.getByRole("tab", { name: /propdates/i }); |
| 43 | + await expect(propdatesTab).toBeVisible({ timeout: 30000 }); |
| 44 | + await expect(propdatesTab).toHaveAttribute("data-state", "active", { timeout: 15000 }); |
| 45 | + await expect(page.getByRole("tab", { name: /details/i })).toHaveAttribute( |
| 46 | + "data-state", |
| 47 | + "inactive", |
| 48 | + ); |
| 49 | + }); |
| 50 | + |
| 51 | + test("without ?tab the Details tab stays default", async ({ page, request }) => { |
| 52 | + const proposalNumber = await findProposalWithPropdates(request); |
| 53 | + test.skip(proposalNumber === null, "No proposal with propdates in this environment"); |
| 54 | + |
| 55 | + await page.goto(`/proposals/base/${proposalNumber}`, { |
| 56 | + waitUntil: "domcontentloaded", |
| 57 | + timeout: 60000, |
| 58 | + }); |
| 59 | + |
| 60 | + // Wait for the tab list to be revealed post-mount, then assert default. |
| 61 | + const detailsTab = page.getByRole("tab", { name: /details/i }); |
| 62 | + await expect(detailsTab).toBeVisible({ timeout: 30000 }); |
| 63 | + await expect(detailsTab).toHaveAttribute("data-state", "active"); |
| 64 | + }); |
| 65 | + |
| 66 | + test("unknown ?tab value is ignored and falls back to Details", async ({ page, request }) => { |
| 67 | + const proposalNumber = await findProposalWithPropdates(request); |
| 68 | + test.skip(proposalNumber === null, "No proposal with propdates in this environment"); |
| 69 | + |
| 70 | + await page.goto(`/proposals/base/${proposalNumber}?tab=bogus`, { |
| 71 | + waitUntil: "domcontentloaded", |
| 72 | + timeout: 60000, |
| 73 | + }); |
| 74 | + |
| 75 | + const detailsTab = page.getByRole("tab", { name: /details/i }); |
| 76 | + await expect(detailsTab).toBeVisible({ timeout: 30000 }); |
| 77 | + await expect(detailsTab).toHaveAttribute("data-state", "active"); |
| 78 | + }); |
| 79 | +}); |
0 commit comments