-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
/
Copy pathDataTable.test.tsx
159 lines (133 loc) · 4.43 KB
/
DataTable.test.tsx
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
import * as React from 'react';
import { render } from '@testing-library/react-native';
import mockSafeAreaContext from 'react-native-safe-area-context/jest/mock';
import Checkbox from '../Checkbox';
import DataTable from '../DataTable/DataTable';
jest.mock('react-native-safe-area-context', () => mockSafeAreaContext);
describe('DataTable.Header', () => {
it('renders data table header', () => {
const tree = render(
<DataTable.Header>
<DataTable.Title>Dessert</DataTable.Title>
<DataTable.Title>Calories</DataTable.Title>
</DataTable.Header>
).toJSON();
expect(tree).toMatchSnapshot();
});
});
describe('DataTable.Title', () => {
it('renders data table title with sort icon', () => {
const tree = render(
<DataTable.Title sortDirection="descending">Dessert</DataTable.Title>
).toJSON();
expect(tree).toMatchSnapshot();
});
it('renders right aligned data table title', () => {
const tree = render(
<DataTable.Title numeric>Calories</DataTable.Title>
).toJSON();
expect(tree).toMatchSnapshot();
});
it('renders data table title with press handler', () => {
const tree = render(
<DataTable.Title sortDirection="descending" onPress={() => {}}>
Dessert
</DataTable.Title>
).toJSON();
expect(tree).toMatchSnapshot();
});
});
describe('DataTable.Cell', () => {
it('renders data table cell', () => {
const tree = render(<DataTable.Cell>Cupcake</DataTable.Cell>).toJSON();
expect(tree).toMatchSnapshot();
});
it('renders right aligned data table cell', () => {
const tree = render(<DataTable.Cell numeric>356</DataTable.Cell>).toJSON();
expect(tree).toMatchSnapshot();
});
it('renders data table cell with text container', () => {
const { getByText, getByTestId } = render(
<DataTable.Cell testID="table-cell">Table cell</DataTable.Cell>
);
expect(getByText('Table cell')).toBeOnTheScreen();
expect(getByTestId('table-cell-text-container')).toBeOnTheScreen();
});
it('renders data table cell children without text container', () => {
const { queryByTestId } = render(
<DataTable.Cell testID="table-cell">
<Checkbox status="checked" testID="table-cell-checkbox" />
</DataTable.Cell>
);
expect(queryByTestId('table-cell-text-container')).not.toBeOnTheScreen();
});
});
describe('DataTable.Pagination', () => {
it('renders data table pagination', () => {
const tree = render(
<DataTable.Pagination
page={3}
numberOfPages={15}
onPageChange={() => {}}
/>
).toJSON();
expect(tree).toMatchSnapshot();
});
it('renders data table pagination with label', () => {
const tree = render(
<DataTable.Pagination
page={3}
numberOfPages={15}
onPageChange={() => {}}
label="11-20 of 150"
/>
).toJSON();
expect(tree).toMatchSnapshot();
});
it('renders data table pagination with fast-forward buttons', () => {
const { getByLabelText, toJSON } = render(
<DataTable.Pagination
page={3}
numberOfPages={15}
onPageChange={() => {}}
label="11-20 of 150"
showFastPaginationControls
/>
);
expect(getByLabelText('page-first')).toBeTruthy();
expect(getByLabelText('page-last')).toBeTruthy();
expect(toJSON()).toMatchSnapshot();
});
it('renders data table pagination without options select', () => {
const { queryByLabelText } = render(
<DataTable.Pagination
page={3}
numberOfPages={15}
onPageChange={() => {}}
label="11-20 of 150"
showFastPaginationControls
/>
);
expect(queryByLabelText('Options Select')).toBeFalsy();
});
it('renders data table pagination with options select', () => {
const { getByLabelText, toJSON } = render(
<mockSafeAreaContext.SafeAreaProvider>
<DataTable.Pagination
page={3}
numberOfPages={15}
onPageChange={() => {}}
label="11-20 of 150"
showFastPaginationControls
numberOfItemsPerPageList={[2, 4, 6]}
numberOfItemsPerPage={2}
onItemsPerPageChange={() => {}}
selectPageDropdownLabel={'Rows per page'}
/>
</mockSafeAreaContext.SafeAreaProvider>
);
expect(getByLabelText('Options Select')).toBeTruthy();
expect(getByLabelText('selectPageDropdownLabel')).toBeTruthy();
expect(toJSON()).toMatchSnapshot();
});
});