-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathResizablePanel.test.jsx
More file actions
51 lines (42 loc) · 1.7 KB
/
Copy pathResizablePanel.test.jsx
File metadata and controls
51 lines (42 loc) · 1.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import { render, screen, fireEvent, cleanup } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import { afterEach, describe, it, expect } from 'vitest';
import { ResizablePanel } from '../ResizablePanel';
import i18n from '../../i18n';
const getRootFontSize = () => parseFloat(getComputedStyle(document.documentElement).fontSize) || 16;
const pxToRem = (px) => `${px / getRootFontSize()}rem`;
afterEach(() => {
cleanup();
});
describe('ResizablePanel', () => {
it('renders content and adjusts height with keyboard', async () => {
const user = userEvent.setup();
render(
<ResizablePanel title="Test" initialHeight={300}>
<div>content</div>
</ResizablePanel>
);
const region = screen.getByRole('region', { name: /Test/ });
expect(region.style.height).toBe(pxToRem(300));
screen.getByText('content');
const handle = screen.getByRole('button', { name: i18n.t('resize.adjust', { title: 'Test' }) });
handle.focus();
await user.keyboard('{ArrowUp}');
expect(region.style.height).toBe(pxToRem(290));
await user.keyboard('{ArrowDown}{ArrowDown}');
expect(region.style.height).toBe(pxToRem(310));
});
it('resizes using mouse drag', () => {
render(
<ResizablePanel title="Test" initialHeight={300}>
<div>content</div>
</ResizablePanel>
);
const region = screen.getByRole('region', { name: /Test/ });
const handle = screen.getByRole('button', { name: i18n.t('resize.adjust', { title: 'Test' }) });
fireEvent.mouseDown(handle, { clientY: 0 });
fireEvent.mouseMove(document, { clientY: 40 });
fireEvent.mouseUp(document);
expect(region.style.height).toBe(pxToRem(340));
});
});