import { expect, test } from '@playwright/test'; import { captureUnexpectedConsole, catalogueSearchLocators, findShareButton, installClipboardStub, isMachineUrl, machineCardLinks, openCatalogue, openFirstMachineFromCatalogue, tryNudgeShareableState, waitForAnyVisible, waitForAppShell, waitForClipboardWrite, waitForViewerSurface, } from './helpers'; test.describe('production regression: catalogue → viewer → share link', () => { test.use({ viewport: { width: 1440, height: 900 }, hasTouch: false, isMobile: false, reducedMotion: 'no-preference', }); test('keeps catalogue search, machine navigation, and share URL restoration wired together', async ({ page, context, }) => { await installClipboardStub(page); const consoleCapture = captureUnexpectedConsole(page); try { await openCatalogue(page); await waitForAnyVisible(page, [machineCardLinks(page)], 'initial catalogue machine cards'); expect(await machineCardLinks(page).count()).toBeGreaterThan(0); const searchControl = await waitForAnyVisible( page, catalogueSearchLocators(page), 'catalogue search control', 10_000, ); await searchControl.fill('engine'); await waitForAnyVisible( page, [machineCardLinks(page)], 'machine cards after searching for "engine"', 10_000, ); expect(await machineCardLinks(page).count()).toBeGreaterThan(0); await searchControl.fill(''); await searchControl.press('Escape').catch(() => undefined); await openFirstMachineFromCatalogue(page); await waitForViewerSurface(page); const currentViewerUrl = new URL(page.url()); expect(isMachineUrl(currentViewerUrl)).toBe(true); await tryNudgeShareableState(page); const shareButton = await findShareButton(page); await shareButton.click(); const copied = await waitForClipboardWrite(page); const copiedUrl = new URL(copied, currentViewerUrl); expect(copiedUrl.origin).toBe(currentViewerUrl.origin); expect(isMachineUrl(copiedUrl)).toBe(true); expect(copiedUrl.pathname).toBe(new URL(page.url()).pathname); expect(copiedUrl.search.length + copiedUrl.hash.length).toBeGreaterThan(0); const replayPage = await context.newPage(); const replayConsoleCapture = captureUnexpectedConsole(replayPage); try { await replayPage.goto(copiedUrl.toString()); await waitForAppShell(replayPage); await waitForViewerSurface(replayPage); expect(isMachineUrl(new URL(replayPage.url()))).toBe(true); await replayConsoleCapture.expectNoErrors(); } finally { replayConsoleCapture.dispose(); await replayPage.close(); } await consoleCapture.expectNoErrors(); } finally { consoleCapture.dispose(); } }); });