|
| 1 | +/** |
| 2 | + * SPDX-FileCopyrightText: 2026 Nextcloud GmbH and Nextcloud contributors |
| 3 | + * SPDX-License-Identifier: AGPL-3.0-or-later |
| 4 | + */ |
| 5 | + |
| 6 | +import { expect } from '@playwright/test' |
| 7 | +import { test } from '../support/fixtures/create-collectives.ts' |
| 8 | + |
| 9 | +test.describe('Collective print view', () => { |
| 10 | + test('loads all images before opening print dialog', async ({ user, page, collective }) => { |
| 11 | + // Create two pages each with an image. The second page is below initial viewport. |
| 12 | + for (let i = 0; i < 2; i++) { |
| 13 | + const collectivePage = await collective.createPage({ |
| 14 | + title: `Page with image ${i}`, |
| 15 | + user, |
| 16 | + page, |
| 17 | + }) |
| 18 | + const src = await collectivePage.uploadImage({ |
| 19 | + filename: 'test.png', |
| 20 | + user, |
| 21 | + page, |
| 22 | + }) |
| 23 | + await collectivePage.setContent({ |
| 24 | + content: `# Image ${i}\n\n\n`, |
| 25 | + user, |
| 26 | + page, |
| 27 | + }) |
| 28 | + } |
| 29 | + |
| 30 | + // Stub window.print so the real print dialog doesn't block the test |
| 31 | + await page.addInitScript(() => { |
| 32 | + (window as Window & { __printCalls?: number }).__printCalls = 0 |
| 33 | + window.print = () => { |
| 34 | + (window as Window & { __printCalls?: number }).__printCalls! += 1 |
| 35 | + } |
| 36 | + }) |
| 37 | + |
| 38 | + await page.goto(`/index.php/apps/collectives/_/print/${collective.getCollectiveUrlPart()}`) |
| 39 | + |
| 40 | + await expect(page.getByText('Preparing collective for exporting or printing')) |
| 41 | + .toBeVisible() |
| 42 | + await expect(page.getByText('Preparing collective for exporting or printing')) |
| 43 | + .toBeHidden({ timeout: 30000 }) |
| 44 | + |
| 45 | + const printCalls = await page.evaluate(() => (window as Window & { __printCalls?: number }).__printCalls) |
| 46 | + expect(printCalls).toBeGreaterThan(0) |
| 47 | + |
| 48 | + const imgs = page.locator('div.ProseMirror figure.image img.image__main') |
| 49 | + const count = await imgs.count() |
| 50 | + expect(count).toBe(2) |
| 51 | + for (let i = 0; i < count; i++) { |
| 52 | + const naturalWidth = await imgs.nth(i).evaluate((el: HTMLImageElement) => el.naturalWidth) |
| 53 | + expect(naturalWidth, `image ${i} should have loaded`).toBeGreaterThan(0) |
| 54 | + } |
| 55 | + }) |
| 56 | +}) |
0 commit comments