|
8 | 8 | */ |
9 | 9 |
|
10 | 10 | const { test, expect } = require('@playwright/test'); |
11 | | -const { runDemo, openEnv, closeEnvs } = require('../support/helpers'); |
| 11 | +const { runDemo, openEnv, closeEnvs, collectDownloads } = require('../support/helpers'); |
12 | 12 |
|
13 | 13 | const WIN_SEL = '.layout .react-grid-item'; |
14 | 14 | const CONTAINER_SEL = `${WIN_SEL} .content > div`; |
@@ -388,18 +388,21 @@ test.describe('Image Pane', () => { |
388 | 388 |
|
389 | 389 | await expect(comparePane.locator('img.content-image')).toHaveCount(2); |
390 | 390 |
|
391 | | - // Both downloads fire simultaneously when save is clicked in compare mode |
392 | | - const [dl1, dl2] = await Promise.all([ |
393 | | - page.waitForEvent('download'), |
394 | | - page.waitForEvent('download'), |
395 | | - comparePane.locator("button[title='save']").click(), |
396 | | - ]); |
| 391 | + // ImageComparePane.handleDownload staggers each link.click() by 300ms |
| 392 | + // (index * 300 ms setTimeout). Promise.all([waitForEvent, waitForEvent]) |
| 393 | + // catches both promises on the same first event. Use collectDownloads instead. |
| 394 | + const downloads = await collectDownloads( |
| 395 | + page, |
| 396 | + 2, |
| 397 | + () => comparePane.locator("button[title='save']").click() |
| 398 | + ); |
397 | 399 |
|
398 | | - const filenames = [dl1.suggestedFilename(), dl2.suggestedFilename()].sort(); |
| 400 | + const filenames = downloads.map((d) => d.suggestedFilename()).sort(); |
399 | 401 | expect(filenames).toContain('Random!_1.jpg'); |
400 | 402 | expect(filenames).toContain('Random!_2.jpg'); |
401 | | - expect(await dl1.path()).toBeTruthy(); |
402 | | - expect(await dl2.path()).toBeTruthy(); |
| 403 | + for (const dl of downloads) { |
| 404 | + expect(await dl.path()).toBeTruthy(); |
| 405 | + } |
403 | 406 | }); |
404 | 407 |
|
405 | 408 | test('image_compare_basic: captions are visible and do not overlap images', async ({ |
@@ -477,16 +480,17 @@ test.describe('Image Pane', () => { |
477 | 480 |
|
478 | 481 | await expect(comparePane.locator('img.content-image')).toHaveCount(2); |
479 | 482 |
|
480 | | - const [dl1, dl2] = await Promise.all([ |
481 | | - page.waitForEvent('download'), |
482 | | - page.waitForEvent('download'), |
483 | | - comparePane.locator("button[title='save']").click(), |
484 | | - ]); |
| 483 | + const downloads = await collectDownloads( |
| 484 | + page, |
| 485 | + 2, |
| 486 | + () => comparePane.locator("button[title='save']").click() |
| 487 | + ); |
485 | 488 |
|
486 | | - const filenames = [dl1.suggestedFilename(), dl2.suggestedFilename()].sort(); |
| 489 | + const filenames = downloads.map((d) => d.suggestedFilename()).sort(); |
487 | 490 | expect(filenames).toContain('CompareTest_1.jpg'); |
488 | 491 | expect(filenames).toContain('CompareTest_2.jpg'); |
489 | | - expect(await dl1.path()).toBeTruthy(); |
490 | | - expect(await dl2.path()).toBeTruthy(); |
| 492 | + for (const dl of downloads) { |
| 493 | + expect(await dl.path()).toBeTruthy(); |
| 494 | + } |
491 | 495 | }); |
492 | 496 | }); |
0 commit comments