|
| 1 | +import { test, expect, Page } from '@playwright/test'; |
| 2 | + |
| 3 | +/** |
| 4 | + * Cross-window layout history (Phase D). Undo/redo restore the whole layout — |
| 5 | + * including popout windows, which re-open **asynchronously**. The recorder holds |
| 6 | + * its re-entrancy guard across that async re-open (so the re-open doesn't record |
| 7 | + * a spurious entry) and exposes `popoutRestorationPromise` to await it. None of |
| 8 | + * this is reachable in jsdom (no real second window). |
| 9 | + */ |
| 10 | +test.describe('cross-window layout history', () => { |
| 11 | + const ready = async (page: Page) => { |
| 12 | + await page.goto('/e2e/fixtures/index.html'); |
| 13 | + await page.waitForFunction(() => (window as any).__ready === true); |
| 14 | + await page.evaluate(() => { |
| 15 | + (window as any).__dv.addPanel('alpha'); |
| 16 | + (window as any).__dv.addPanel('beta'); |
| 17 | + }); |
| 18 | + }; |
| 19 | + |
| 20 | + test('undo reverts a popout (group returns to the grid)', async ({ |
| 21 | + page, |
| 22 | + context, |
| 23 | + }) => { |
| 24 | + await ready(page); |
| 25 | + |
| 26 | + const [win] = await Promise.all([ |
| 27 | + context.waitForEvent('page'), |
| 28 | + page.evaluate(() => (window as any).__dv.popoutActiveGroup()), |
| 29 | + ]); |
| 30 | + await (win as Page).waitForLoadState(); |
| 31 | + expect( |
| 32 | + await page.evaluate(() => (window as any).__dv.popoutCount()) |
| 33 | + ).toBe(1); |
| 34 | + |
| 35 | + // Undo the popout → the window closes and the group goes back. |
| 36 | + await Promise.all([ |
| 37 | + (win as Page).waitForEvent('close'), |
| 38 | + page.evaluate(() => (window as any).__dv.undo()), |
| 39 | + ]); |
| 40 | + await expect |
| 41 | + .poll(() => page.evaluate(() => (window as any).__dv.popoutCount())) |
| 42 | + .toBe(0); |
| 43 | + }); |
| 44 | + |
| 45 | + test('undo re-opens a closed popout window', async ({ page, context }) => { |
| 46 | + await ready(page); |
| 47 | + |
| 48 | + // pop the active group out |
| 49 | + const [win1] = await Promise.all([ |
| 50 | + context.waitForEvent('page'), |
| 51 | + page.evaluate(() => (window as any).__dv.popoutActiveGroup()), |
| 52 | + ]); |
| 53 | + await (win1 as Page).waitForLoadState(); |
| 54 | + |
| 55 | + // close the popout (records a removal whose pre-image still has the popout) |
| 56 | + await Promise.all([ |
| 57 | + (win1 as Page).waitForEvent('close'), |
| 58 | + page.evaluate(() => (window as any).__dv.closeActivePopout()), |
| 59 | + ]); |
| 60 | + expect( |
| 61 | + await page.evaluate(() => (window as any).__dv.popoutCount()) |
| 62 | + ).toBe(0); |
| 63 | + expect(await page.evaluate(() => (window as any).__dv.canUndo())).toBe( |
| 64 | + true |
| 65 | + ); |
| 66 | + |
| 67 | + // undo → re-opens the popout window asynchronously |
| 68 | + const [win2] = await Promise.all([ |
| 69 | + context.waitForEvent('page'), |
| 70 | + page.evaluate(async () => { |
| 71 | + (window as any).__dv.undo(); |
| 72 | + await (window as any).__dv.awaitPopoutRestore(); |
| 73 | + }), |
| 74 | + ]); |
| 75 | + await (win2 as Page).waitForLoadState(); |
| 76 | + await expect |
| 77 | + .poll(() => page.evaluate(() => (window as any).__dv.popoutCount())) |
| 78 | + .toBe(1); |
| 79 | + |
| 80 | + // The re-open must not have left a spurious history entry that a single |
| 81 | + // redo can't account for — redo should cleanly close it again. |
| 82 | + await Promise.all([ |
| 83 | + (win2 as Page).waitForEvent('close'), |
| 84 | + page.evaluate(() => (window as any).__dv.redo()), |
| 85 | + ]); |
| 86 | + await expect |
| 87 | + .poll(() => page.evaluate(() => (window as any).__dv.popoutCount())) |
| 88 | + .toBe(0); |
| 89 | + }); |
| 90 | +}); |
0 commit comments