|
| 1 | +import { test, expect } from '../../playwright'; |
| 2 | + |
| 3 | +const FOLDERS = '/?fixture=folders'; |
| 4 | +const DESKTOP = { width: 1280, height: 900 }; |
| 5 | + |
| 6 | +// The resize handle sits at the sidebar's right edge (left: var(--sidebar-width), |
| 7 | +// default 260px), and the drag is delta-based from where it is grabbed, so moving |
| 8 | +// the pointer to an absolute x lands the width near that x. Collapse fires when the |
| 9 | +// pointer is dragged ~100px past the 200px min (i.e. below x=100); re-expand fires |
| 10 | +// once it climbs back to the min (x>=200) within the same held gesture. |
| 11 | + |
| 12 | +test.describe('docs sidebar - resize (desktop)', () => { |
| 13 | + test.use({ viewport: DESKTOP }); |
| 14 | + |
| 15 | + test('widens when the handle is dragged right', async ({ page, sidebar }) => { |
| 16 | + await page.goto(FOLDERS); |
| 17 | + await expect(sidebar.inline).toBeVisible(); |
| 18 | + const before = await sidebar.width(); |
| 19 | + |
| 20 | + await sidebar.grabResizer(); |
| 21 | + await sidebar.movePointerToX(400); |
| 22 | + await sidebar.releasePointer(); |
| 23 | + |
| 24 | + const after = await sidebar.width(); |
| 25 | + expect(after).toBeGreaterThan(before); |
| 26 | + expect(after).toBeGreaterThan(360); |
| 27 | + }); |
| 28 | + |
| 29 | + test('clamps to the max width (480px)', async ({ page, sidebar }) => { |
| 30 | + await page.goto(FOLDERS); |
| 31 | + await sidebar.grabResizer(); |
| 32 | + await sidebar.movePointerToX(900); |
| 33 | + await sidebar.releasePointer(); |
| 34 | + |
| 35 | + const after = await sidebar.width(); |
| 36 | + expect(after).toBeGreaterThan(470); |
| 37 | + expect(after).toBeLessThanOrEqual(482); |
| 38 | + }); |
| 39 | + |
| 40 | + test('persists the resized width across a reload (sessionStorage)', async ({ page, sidebar }) => { |
| 41 | + await page.goto(FOLDERS); |
| 42 | + await sidebar.grabResizer(); |
| 43 | + await sidebar.movePointerToX(380); |
| 44 | + await sidebar.releasePointer(); |
| 45 | + const resized = await sidebar.width(); |
| 46 | + expect(resized).toBeGreaterThan(360); |
| 47 | + |
| 48 | + await page.reload(); |
| 49 | + await expect(sidebar.inline).toBeVisible(); |
| 50 | + expect(Math.abs((await sidebar.width()) - resized)).toBeLessThan(5); |
| 51 | + }); |
| 52 | + |
| 53 | + test('collapses when dragged past the min, and can be re-opened', async ({ page, sidebar }) => { |
| 54 | + await page.goto(FOLDERS); |
| 55 | + await sidebar.grabResizer(); |
| 56 | + await sidebar.movePointerToX(60); |
| 57 | + await sidebar.releasePointer(); |
| 58 | + |
| 59 | + await expect(sidebar.inline).toHaveCount(0); |
| 60 | + await expect(sidebar.expandButton).toBeVisible(); |
| 61 | + |
| 62 | + await sidebar.expand(); |
| 63 | + await expect(sidebar.inline).toBeVisible(); |
| 64 | + }); |
| 65 | + |
| 66 | + test('re-expands within the same held drag after collapsing', async ({ page, sidebar }) => { |
| 67 | + await page.goto(FOLDERS); |
| 68 | + await sidebar.grabResizer(); |
| 69 | + |
| 70 | + await sidebar.movePointerToX(60); |
| 71 | + await expect(sidebar.inline).toHaveCount(0); |
| 72 | + |
| 73 | + await sidebar.movePointerToX(320); |
| 74 | + await expect(sidebar.inline).toBeVisible(); |
| 75 | + |
| 76 | + await sidebar.releasePointer(); |
| 77 | + await expect(sidebar.inline).toBeVisible(); |
| 78 | + }); |
| 79 | +}); |
| 80 | + |
| 81 | +test.describe('playground sidebar - resize (bottom dock)', () => { |
| 82 | + test.use({ viewport: DESKTOP }); |
| 83 | + |
| 84 | + test('widens when the handle is dragged right', async ({ playground }) => { |
| 85 | + await playground.open('bottom'); |
| 86 | + await expect(playground.sidebarPanel).toBeVisible(); |
| 87 | + const before = await playground.sidebarWidth(); |
| 88 | + |
| 89 | + await playground.grabSidebarResizer(); |
| 90 | + await playground.movePointerToX(400); |
| 91 | + await playground.releasePointer(); |
| 92 | + |
| 93 | + expect(await playground.sidebarWidth()).toBeGreaterThan(before); |
| 94 | + }); |
| 95 | + |
| 96 | + test('collapses when dragged past the min, and re-opens from the toggle', async ({ playground }) => { |
| 97 | + await playground.open('bottom'); |
| 98 | + await expect(playground.sidebarPanel).toBeVisible(); |
| 99 | + |
| 100 | + await playground.grabSidebarResizer(); |
| 101 | + await playground.movePointerToX(60); |
| 102 | + await playground.releasePointer(); |
| 103 | + |
| 104 | + await expect(playground.sidebarPanel).toHaveCount(0); |
| 105 | + |
| 106 | + await playground.sidebarToggle.click(); |
| 107 | + await expect(playground.sidebarPanel).toBeVisible(); |
| 108 | + }); |
| 109 | +}); |
0 commit comments