|
1 | | -import { describe, it, expect } from 'vitest'; |
| 1 | +import { describe, it, expect, vi } from 'vitest'; |
2 | 2 | import { render, screen, act } from '@testing-library/react'; |
3 | | -import type { RenderResult } from '@testing-library/react'; |
4 | 3 | import { SplitPane } from './SplitPane'; |
5 | 4 | import { Pane } from './Pane'; |
6 | 5 |
|
7 | 6 | describe('SplitPane', () => { |
8 | | - // TODO: Fix ResizeObserver mock timing for these tests |
9 | | - // These tests work in real browsers but have timing issues in test environment |
10 | | - // Core functionality is verified by utility tests |
11 | | - it.skip('renders children panes', async () => { |
| 7 | + it('renders children panes', async () => { |
| 8 | + render( |
| 9 | + <SplitPane> |
| 10 | + <Pane> |
| 11 | + <div>Pane 1</div> |
| 12 | + </Pane> |
| 13 | + <Pane> |
| 14 | + <div>Pane 2</div> |
| 15 | + </Pane> |
| 16 | + </SplitPane> |
| 17 | + ); |
| 18 | + |
| 19 | + // Flush state updates from ResizeObserver callback |
12 | 20 | await act(async () => { |
13 | | - render( |
14 | | - <SplitPane> |
15 | | - <Pane> |
16 | | - <div>Pane 1</div> |
17 | | - </Pane> |
18 | | - <Pane> |
19 | | - <div>Pane 2</div> |
20 | | - </Pane> |
21 | | - </SplitPane> |
22 | | - ); |
23 | | - // Give ResizeObserver time to fire |
24 | | - await new Promise((resolve) => setTimeout(resolve, 10)); |
| 21 | + await vi.runAllTimersAsync(); |
25 | 22 | }); |
26 | 23 |
|
27 | 24 | expect(screen.getByText('Pane 1')).toBeInTheDocument(); |
28 | 25 | expect(screen.getByText('Pane 2')).toBeInTheDocument(); |
29 | 26 | }); |
30 | 27 |
|
31 | | - it.skip('renders divider between panes', async () => { |
32 | | - let component: RenderResult | undefined; |
| 28 | + it('renders divider between panes', async () => { |
| 29 | + const { container } = render( |
| 30 | + <SplitPane> |
| 31 | + <Pane>Pane 1</Pane> |
| 32 | + <Pane>Pane 2</Pane> |
| 33 | + </SplitPane> |
| 34 | + ); |
33 | 35 |
|
34 | 36 | await act(async () => { |
35 | | - component = render( |
36 | | - <SplitPane> |
37 | | - <Pane>Pane 1</Pane> |
38 | | - <Pane>Pane 2</Pane> |
39 | | - </SplitPane> |
40 | | - ); |
41 | | - await new Promise((resolve) => setTimeout(resolve, 10)); |
| 37 | + await vi.runAllTimersAsync(); |
42 | 38 | }); |
43 | 39 |
|
44 | | - const divider = component?.container.querySelector('[role="separator"]'); |
| 40 | + const divider = container.querySelector('[role="separator"]'); |
45 | 41 | expect(divider).toBeInTheDocument(); |
46 | 42 | }); |
47 | 43 |
|
@@ -81,23 +77,20 @@ describe('SplitPane', () => { |
81 | 77 | expect(splitPane).toHaveClass('custom-class'); |
82 | 78 | }); |
83 | 79 |
|
84 | | - it.skip('renders correct number of dividers for multiple panes', async () => { |
85 | | - let component: RenderResult | undefined; |
| 80 | + it('renders correct number of dividers for multiple panes', async () => { |
| 81 | + const { container } = render( |
| 82 | + <SplitPane> |
| 83 | + <Pane>Pane 1</Pane> |
| 84 | + <Pane>Pane 2</Pane> |
| 85 | + <Pane>Pane 3</Pane> |
| 86 | + </SplitPane> |
| 87 | + ); |
86 | 88 |
|
87 | 89 | await act(async () => { |
88 | | - component = render( |
89 | | - <SplitPane> |
90 | | - <Pane>Pane 1</Pane> |
91 | | - <Pane>Pane 2</Pane> |
92 | | - <Pane>Pane 3</Pane> |
93 | | - </SplitPane> |
94 | | - ); |
95 | | - await new Promise((resolve) => setTimeout(resolve, 10)); |
| 90 | + await vi.runAllTimersAsync(); |
96 | 91 | }); |
97 | 92 |
|
98 | | - const dividers = component?.container.querySelectorAll( |
99 | | - '[role="separator"]' |
100 | | - ); |
| 93 | + const dividers = container.querySelectorAll('[role="separator"]'); |
101 | 94 | expect(dividers).toHaveLength(2); // n-1 dividers for n panes |
102 | 95 | }); |
103 | 96 | }); |
0 commit comments