Skip to content
Source
Sign inSign up
TanStack/devtools
Open History to see the last commit

resize.spec.ts

50 lines1.9 KB

1import { test, expect } from '@playwright/test'
2import { DevtoolsPage, SELECTORS } from '@tanstack/devtools-e2e'
3​
4test('dragging the resize handle below the minimum height collapses the panel', async ({
5 page,
6}) => {
7 const dt = new DevtoolsPage(page)
8 await dt.goto()
9 await dt.openViaTrigger()
10​
11 // The panel is anchored to the bottom of the viewport, so its resize handle
12 // always sits a few pixels above the viewport bottom. Playwright's
13 // `mouse.move` clamps to the viewport, so a real downward drag can never
14 // travel far enough to push the (~400px) panel below the 70px collapse
15 // threshold. We instead dispatch the exact mouse event sequence the resize
16 // handler listens for (mousedown on the handle, then document-level
17 // mousemove/mouseup) with an explicit downward `pageY`. This drives the real
18 // `handleDragStart` collapse logic without being defeated by viewport
19 // clamping.
20 await page.evaluate(
21 ([handleSel, panelSel]) => {
22 const handle = document.querySelector(handleSel) as HTMLElement
23 const box = handle.getBoundingClientRect()
24 const startX = box.x + box.width / 2
25 const startY = box.y + box.height / 2
26 const fire = (type: string, target: EventTarget, y: number) => {
27 target.dispatchEvent(
28 new MouseEvent(type, {
29 bubbles: true,
30 cancelable: true,
31 button: 0,
32 clientX: startX,
33 clientY: y,
34 }),
35 )
36 }
37 fire('mousedown', handle, startY)
38 // Drag downward well past the panel's height to fall below the 70px minimum.
39 for (let i = 1; i <= 10; i++) {
40 fire('mousemove', document, startY + (500 * i) / 10)
41 }
42 fire('mouseup', document, startY + 500)
43 },
44 [SELECTORS.resizeHandle, SELECTORS.mainPanel].map(
45 (id) => `[data-testid="${id}"]`,
46 ) as [string, string],
47 )
48​
49 await expect(dt.panel()).toHaveAttribute('data-open', 'false')
50})