Skip to content

Commit a251e0e

Browse files
committed
Add test to make sure we're not breaking resizable panes.
1 parent 90f55df commit a251e0e

File tree

2 files changed

+30
-1
lines changed

2 files changed

+30
-1
lines changed

src/PageLayout/PageLayout.test.tsx

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
import React from 'react'
2-
import {act, render, screen} from '@testing-library/react'
2+
import {act, fireEvent, render, screen} from '@testing-library/react'
33
import MatchMediaMock from 'jest-matchmedia-mock'
44
import 'react-intersection-observer/test-utils'
55
import {ThemeProvider} from '..'
66
import {viewportRanges} from '../hooks/useResponsiveValue'
77
import {PageLayout} from './PageLayout'
8+
import {Placeholder} from '../Placeholder'
89

910
let matchMedia: MatchMediaMock
1011

@@ -171,5 +172,32 @@ describe('PageLayout', () => {
171172
)
172173
expect(ref).toHaveBeenCalledWith(screen.getByTestId('content').parentNode)
173174
})
175+
176+
it('should be resizable if `resizable` is set correctly', async () => {
177+
render(
178+
<ThemeProvider>
179+
<PageLayout>
180+
<PageLayout.Pane resizable>
181+
<Placeholder height={320} label="Pane" />
182+
</PageLayout.Pane>
183+
<PageLayout.Content>
184+
<Placeholder height={640} label="Content" />
185+
</PageLayout.Content>
186+
</PageLayout>
187+
</ThemeProvider>,
188+
)
189+
190+
const placeholder = await screen.findByText('Pane')
191+
const pane = placeholder.parentNode
192+
const initialWidth = (pane as HTMLElement).style.getPropertyValue('--pane-width')
193+
194+
const divider = await screen.findByRole('separator')
195+
// Moving divider should resize pane.
196+
fireEvent.mouseDown(divider)
197+
fireEvent.mouseMove(divider)
198+
fireEvent.mouseUp(divider)
199+
const finalWidth = (pane as HTMLElement).style.getPropertyValue('--pane-width')
200+
expect(finalWidth).not.toEqual(initialWidth)
201+
})
174202
})
175203
})

src/PageLayout/PageLayout.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,7 @@ const VerticalDivider: React.FC<React.PropsWithChildren<DividerProps & Draggable
291291
bg: isDragging ? 'accent.fg' : 'neutral.muted',
292292
},
293293
}}
294+
role="separator"
294295
onMouseDown={() => {
295296
setIsDragging(true)
296297
onDragStart?.()

0 commit comments

Comments
 (0)