|
| 1 | +import { test, expect } from '@playwright/test'; |
| 2 | +import path from 'node:path'; |
| 3 | + |
| 4 | +test('cancelled cross-grid drag preserves the saved position after returning', async ({ page }) => { |
| 5 | + await page.setViewportSize({ width: 1200, height: 850 }); |
| 6 | + await page.setContent(`<style> |
| 7 | + body { padding: 30px; } |
| 8 | + main { display: flex; gap: 30px; margin-top: 150px; } |
| 9 | + .grid-stack { width: 500px; min-height: 300px; } |
| 10 | + .grid-stack-item-content { background: lightblue; } |
| 11 | + </style><main><div id="left" class="grid-stack"></div><div id="right" class="grid-stack"></div></main>`); |
| 12 | + await page.addStyleTag({ path: path.resolve('dist/gridstack.css') }); |
| 13 | + await page.addScriptTag({ path: path.resolve('dist/gridstack-all.js') }); |
| 14 | + await page.evaluate(() => { |
| 15 | + const w = window as any; |
| 16 | + const options = { column: 4, cellHeight: 100, minRow: 3, float: true, acceptWidgets: true, animate: false, margin: 6 }; |
| 17 | + w.grids = [w.GridStack.init(options, '#left'), w.GridStack.init(options, '#right')]; |
| 18 | + w.grids[0].load([{ id: 'a', x: 0, y: 0, w: 2, h: 1 }, { id: 'b', x: 2, y: 1, w: 1, h: 1 }]); |
| 19 | + w.grids[1].load([{ id: 'c', x: 0, y: 1, w: 2, h: 1 }]); |
| 20 | + w.drops = 0; |
| 21 | + w.grids.forEach(g => g.on('dropped', () => w.drops++)); |
| 22 | + }); |
| 23 | + const saved = () => page.evaluate(() => (window as any).grids.map(g => g.save(false))); |
| 24 | + const initial = await saved(); |
| 25 | + const card = page.locator('[gs-id="a"]'); |
| 26 | + const original = (await card.boundingBox())!; |
| 27 | + const right = (await page.locator('#right').boundingBox())!; |
| 28 | + const left = (await page.locator('#left').boundingBox())!; |
| 29 | + await page.mouse.move(original.x + original.width / 2, original.y + original.height / 2); |
| 30 | + await page.mouse.down(); |
| 31 | + await page.mouse.move(original.x + original.width / 2 + 25, original.y + original.height / 2 + 5, { steps: 10 }); |
| 32 | + await page.mouse.move(right.x + 150, right.y + 150, { steps: 20 }); |
| 33 | + await expect(page.locator('#right .grid-stack-placeholder')).toHaveCount(1); |
| 34 | + await page.mouse.move(left.x + 220, left.y + 20, { steps: 20 }); |
| 35 | + await expect(page.locator('#left .grid-stack-placeholder')).toHaveCount(1); |
| 36 | + await page.keyboard.press('Escape'); |
| 37 | + await page.mouse.up(); |
| 38 | + await expect(page.locator('.grid-stack-placeholder')).toHaveCount(0); |
| 39 | + expect(await page.evaluate(() => (window as any).drops)).toBe(0); |
| 40 | + expect(await saved()).toEqual(initial); |
| 41 | + await page.evaluate(() => (window as any).grids.forEach(g => g.load(g.save(false)))); |
| 42 | + expect(await saved()).toEqual(initial); |
| 43 | + const restored = (await card.boundingBox())!; |
| 44 | + expect(restored.x).toBeCloseTo(original.x, 0); |
| 45 | + expect(restored.y).toBeCloseTo(original.y, 0); |
| 46 | +}); |
0 commit comments