-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
Expand file tree
/
Copy pathColumnsButton.spec.tsx
More file actions
59 lines (58 loc) · 2.5 KB
/
ColumnsButton.spec.tsx
File metadata and controls
59 lines (58 loc) · 2.5 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
52
53
54
55
56
57
58
59
import * as React from 'react';
import { render, screen, fireEvent, waitFor } from '@testing-library/react';
import { Basic, FewColumns, LabelTypes } from './ColumnsButton.stories';
describe('ColumnsButton', () => {
it('should render one row per column unless they are hidden', async () => {
render(<Basic />);
fireEvent.click(await screen.findByText('ra.action.select_columns'));
await screen.findByLabelText('c_0');
await screen.findByLabelText('c_1');
await screen.findByLabelText('c_2');
await screen.findByLabelText('c_3');
await screen.findByLabelText('c_4');
await screen.findByLabelText('c_5');
// await screen.findByLabelText('c_6'); // hidden
await screen.findByLabelText('c_7');
});
it('should not render the filter input when there are too few columns', async () => {
render(<FewColumns />);
fireEvent.click(await screen.findByText('ra.action.select_columns'));
await screen.findByLabelText('c_0');
expect(screen.queryByText('ra.action.search_columns')).toBeNull();
});
it('should render a filter input when there are many columns', async () => {
render(<LabelTypes />);
fireEvent.click(await screen.findByText('ra.action.select_columns'));
await screen.findByLabelText('resources.test.fields.col0');
expect(
screen
.getByRole('menu')
.querySelectorAll('li:not(.columns-selector-actions)')
).toHaveLength(8); // 7 columns + the filter input li
// Typing a filter
fireEvent.change(
screen.getByPlaceholderText('ra.action.search_columns'),
{
// filter should be case and diacritics insensitive
target: { value: 'DiA' },
}
);
await waitFor(() => {
expect(
screen
.getByRole('menu')
.querySelectorAll('li:not(.columns-selector-actions)')
).toHaveLength(2); // only the column with 'DiA' in its label should remain + the filter input li
});
screen.getByLabelText('Téstïng diàcritics');
// Clear the filter
fireEvent.click(screen.getByLabelText('ra.action.clear_input_value'));
await waitFor(() => {
expect(
screen
.getByRole('menu')
.querySelectorAll('li:not(.columns-selector-actions)')
).toHaveLength(8);
});
});
});