From 6a75e4778b3af859fbc4046c3779ac370b9a2bc8 Mon Sep 17 00:00:00 2001 From: shamoon <4887959+shamoon@users.noreply.github.com> Date: Sun, 26 Jul 2026 14:11:10 -0700 Subject: [PATCH] Add e2e test --- .../document-detail/document-detail.spec.ts | 59 ++++++++++++++++++- 1 file changed, 58 insertions(+), 1 deletion(-) diff --git a/src-ui/e2e/document-detail/document-detail.spec.ts b/src-ui/e2e/document-detail/document-detail.spec.ts index ba10745ec..99080910a 100644 --- a/src-ui/e2e/document-detail/document-detail.spec.ts +++ b/src-ui/e2e/document-detail/document-detail.spec.ts @@ -1,4 +1,4 @@ -import { expect, test } from '@playwright/test' +import { expect, test, type WebSocketRoute } from '@playwright/test' import path from 'node:path' const REQUESTS_HAR = path.join(__dirname, 'requests/api-document-detail.har') @@ -95,3 +95,60 @@ test('should support quick filters', async ({ page }) => { .click() await expect(page).toHaveURL(/tags__id__all=4&sort=created&reverse=1&page=1/) }) + +test('should finish reloading the preview after a remote document update', async ({ + page, +}) => { + let resolveStatusSocket: (socket: WebSocketRoute) => void + const statusSocketReady = new Promise((resolve) => { + resolveStatusSocket = resolve + }) + await page.routeWebSocket(/\/ws\/status\/$/, (socket) => { + resolveStatusSocket(socket) + }) + await page.routeFromHAR(REQUESTS_HAR, { notFound: 'fallback' }) + let previewRequestCount = 0 + page.on('request', (request) => { + if (request.url().includes('/api/documents/175/preview/')) { + previewRequestCount++ + } + }) + await page.goto('/documents/175/details') + + await page.locator('pngx-document-detail').waitFor() + await expect(page.getByTitle('Storage path', { exact: true })).toHaveText( + /\w+/ + ) + const previewWasLoaded = await page.evaluate(() => { + const detail = document.querySelector('pngx-document-detail') + const component = (window as any).ng.getComponent(detail) + component.pdfPreviewLoaded({ numPages: 1 }) + return component.previewLoaded() + }) + expect(previewWasLoaded).toBe(true) + const previewRequestsBeforeReload = previewRequestCount + + const statusSocket = await statusSocketReady + const documentReloaded = page.waitForResponse( + (response) => + response.url().includes('/api/documents/175/?full_perms=true') && + response.request().method() === 'GET' + ) + statusSocket.send( + JSON.stringify({ + type: 'document_updated', + data: { + document_id: 175, + modified: '2026-07-26T20:00:00Z', + }, + }) + ) + await documentReloaded + + await expect( + page.getByText('Document reloaded with latest changes.').first() + ).toBeVisible() + await expect + .poll(() => previewRequestCount) + .toBeGreaterThan(previewRequestsBeforeReload + 1) +})