@qoretechnologies/reqore 0.32.3 → 0.34.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/__tests__/collection.test.tsx +144 -5
- package/__tests__/containers/paging.test.tsx +106 -0
- package/__tests__/hooks/useLatestZIndex.test.tsx +10 -0
- package/__tests__/hooks/useReqorePaging.test.tsx +255 -0
- package/__tests__/hooks/useTheme.test.tsx +31 -0
- package/__tests__/pagination.test.tsx +305 -0
- package/__tests__/popover.test.tsx +20 -6
- package/__tests__/setup.js +8 -0
- package/__tests__/tree.test.tsx +0 -1
- package/dist/components/Button/index.d.ts +1 -0
- package/dist/components/Button/index.d.ts.map +1 -1
- package/dist/components/Button/index.js +11 -7
- package/dist/components/Button/index.js.map +1 -1
- package/dist/components/Collection/index.d.ts +4 -3
- package/dist/components/Collection/index.d.ts.map +1 -1
- package/dist/components/Collection/index.js +31 -13
- package/dist/components/Collection/index.js.map +1 -1
- package/dist/components/Dropdown/index.d.ts +9 -2
- package/dist/components/Dropdown/index.d.ts.map +1 -1
- package/dist/components/Dropdown/index.js +2 -2
- package/dist/components/Dropdown/index.js.map +1 -1
- package/dist/components/Dropdown/list.d.ts +6 -1
- package/dist/components/Dropdown/list.d.ts.map +1 -1
- package/dist/components/Dropdown/list.js +13 -5
- package/dist/components/Dropdown/list.js.map +1 -1
- package/dist/components/Menu/index.d.ts +1 -0
- package/dist/components/Menu/index.d.ts.map +1 -1
- package/dist/components/Menu/index.js +4 -1
- package/dist/components/Menu/index.js.map +1 -1
- package/dist/components/Menu/item.d.ts +1 -0
- package/dist/components/Menu/item.d.ts.map +1 -1
- package/dist/components/Menu/item.js +14 -2
- package/dist/components/Menu/item.js.map +1 -1
- package/dist/components/MultiSelect/index.d.ts +1 -1
- package/dist/components/MultiSelect/index.d.ts.map +1 -1
- package/dist/components/Paging/index.d.ts +32 -0
- package/dist/components/Paging/index.d.ts.map +1 -0
- package/dist/components/Paging/index.js +127 -0
- package/dist/components/Paging/index.js.map +1 -0
- package/dist/components/Panel/index.d.ts +1 -0
- package/dist/components/Panel/index.d.ts.map +1 -1
- package/dist/components/Panel/index.js +2 -2
- package/dist/components/Panel/index.js.map +1 -1
- package/dist/components/Tag/index.d.ts +3 -2
- package/dist/components/Tag/index.d.ts.map +1 -1
- package/dist/components/Tag/index.js +10 -7
- package/dist/components/Tag/index.js.map +1 -1
- package/dist/constants/colors.d.ts +2 -9
- package/dist/constants/colors.d.ts.map +1 -1
- package/dist/constants/colors.js +3 -1
- package/dist/constants/colors.js.map +1 -1
- package/dist/constants/paging.d.ts +17 -0
- package/dist/constants/paging.d.ts.map +1 -0
- package/dist/constants/paging.js +45 -0
- package/dist/constants/paging.js.map +1 -0
- package/dist/constants/theme.d.ts.map +1 -1
- package/dist/constants/theme.js +8 -7
- package/dist/constants/theme.js.map +1 -1
- package/dist/containers/Paging.d.ts +15 -0
- package/dist/containers/Paging.d.ts.map +1 -0
- package/dist/containers/Paging.js +51 -0
- package/dist/containers/Paging.js.map +1 -0
- package/dist/containers/ReqoreProvider.d.ts.map +1 -1
- package/dist/containers/ReqoreProvider.js +2 -2
- package/dist/containers/ReqoreProvider.js.map +1 -1
- package/dist/containers/UIProvider.d.ts.map +1 -1
- package/dist/containers/UIProvider.js +9 -3
- package/dist/containers/UIProvider.js.map +1 -1
- package/dist/hooks/useCombinedRefs.d.ts +2 -2
- package/dist/hooks/useCombinedRefs.d.ts.map +1 -1
- package/dist/hooks/useCombinedRefs.js.map +1 -1
- package/dist/hooks/usePaging.d.ts +28 -0
- package/dist/hooks/usePaging.d.ts.map +1 -0
- package/dist/hooks/usePaging.js +85 -0
- package/dist/hooks/usePaging.js.map +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +8 -2
- package/dist/index.js.map +1 -1
- package/package.json +6 -4
- package/src/components/Button/index.tsx +18 -10
- package/src/components/Collection/index.tsx +78 -49
- package/src/components/ControlGroup/index.tsx +1 -1
- package/src/components/Dropdown/index.tsx +27 -12
- package/src/components/Dropdown/list.tsx +49 -24
- package/src/components/Menu/index.tsx +3 -2
- package/src/components/Menu/item.tsx +16 -2
- package/src/components/MultiSelect/index.tsx +1 -1
- package/src/components/Paging/index.tsx +260 -0
- package/src/components/Panel/index.tsx +4 -1
- package/src/components/Tag/index.tsx +9 -7
- package/src/constants/colors.ts +5 -1
- package/src/constants/paging.ts +67 -0
- package/src/constants/theme.ts +8 -7
- package/src/containers/Paging.tsx +90 -0
- package/src/containers/ReqoreProvider.tsx +3 -3
- package/src/containers/UIProvider.tsx +17 -4
- package/src/hooks/useCombinedRefs.ts +2 -2
- package/src/hooks/usePaging.ts +114 -0
- package/src/index.tsx +3 -0
- package/src/mock/collectionData.tsx +19 -0
- package/src/mock/tableData.ts +1 -0
- package/src/stories/Button/Button.stories.tsx +25 -8
- package/src/stories/Collection/Collection.stories.tsx +51 -42
- package/src/stories/Dropdown/Dropdown.stories.tsx +71 -29
- package/src/stories/Menu/Menu.stories.tsx +4 -0
- package/src/stories/Paging/Paging.stories.tsx +202 -0
- package/src/stories/Tag/Tag.stories.tsx +50 -0
- package/tests.json +1 -1
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import '@testing-library/jest-dom/extend-expect';
|
|
2
|
-
import { fireEvent, render } from '@testing-library/react';
|
|
2
|
+
import { act, fireEvent, render, screen } from '@testing-library/react';
|
|
3
3
|
import React from 'react';
|
|
4
|
+
import { mockAllIsIntersecting } from 'react-intersection-observer/test-utils';
|
|
4
5
|
import { ReqoreCollection, ReqoreLayoutContent, ReqoreUIProvider } from '../src';
|
|
5
|
-
import items from '../src/mock/collectionData';
|
|
6
|
+
import items, { bigCollection } from '../src/mock/collectionData';
|
|
6
7
|
|
|
7
8
|
test('Renders basic <Collection /> properly', () => {
|
|
8
9
|
render(
|
|
@@ -35,16 +36,21 @@ test('<Collection /> items can be filtered', () => {
|
|
|
35
36
|
|
|
36
37
|
expect(fn).not.toHaveBeenCalled();
|
|
37
38
|
|
|
38
|
-
|
|
39
|
+
act(() => {
|
|
40
|
+
jest.advanceTimersByTime(500);
|
|
41
|
+
});
|
|
39
42
|
|
|
40
43
|
expect(fn).toHaveBeenCalledWith('I have');
|
|
44
|
+
|
|
41
45
|
expect(document.querySelectorAll('.reqore-collection-item').length).toBe(2);
|
|
42
46
|
|
|
43
47
|
fireEvent.change(document.querySelector('.reqore-input')!, {
|
|
44
48
|
target: { value: 'asg' },
|
|
45
49
|
});
|
|
46
50
|
|
|
47
|
-
|
|
51
|
+
act(() => {
|
|
52
|
+
jest.runAllTimers();
|
|
53
|
+
});
|
|
48
54
|
|
|
49
55
|
expect(document.querySelectorAll('.reqore-collection-item').length).toBe(0);
|
|
50
56
|
expect(document.querySelectorAll('.reqore-message').length).toBe(1);
|
|
@@ -53,12 +59,49 @@ test('<Collection /> items can be filtered', () => {
|
|
|
53
59
|
target: { value: 'secret' },
|
|
54
60
|
});
|
|
55
61
|
|
|
56
|
-
|
|
62
|
+
act(() => {
|
|
63
|
+
jest.runAllTimers();
|
|
64
|
+
});
|
|
57
65
|
|
|
58
66
|
expect(document.querySelectorAll('.reqore-collection-item').length).toBe(1);
|
|
59
67
|
expect(document.querySelectorAll('.reqore-message').length).toBe(0);
|
|
60
68
|
});
|
|
61
69
|
|
|
70
|
+
test('<Collection /> filter is properly removed by the clear button', () => {
|
|
71
|
+
const fn = jest.fn();
|
|
72
|
+
jest.useFakeTimers();
|
|
73
|
+
|
|
74
|
+
render(
|
|
75
|
+
<ReqoreUIProvider>
|
|
76
|
+
<ReqoreLayoutContent>
|
|
77
|
+
<ReqoreCollection items={items} filterable onQueryChange={fn} />
|
|
78
|
+
</ReqoreLayoutContent>
|
|
79
|
+
</ReqoreUIProvider>
|
|
80
|
+
);
|
|
81
|
+
|
|
82
|
+
expect(document.querySelectorAll('.reqore-collection-item').length).toBe(9);
|
|
83
|
+
|
|
84
|
+
fireEvent.change(document.querySelector('.reqore-input')!, {
|
|
85
|
+
target: { value: 'I have' },
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
expect(fn).not.toHaveBeenCalled();
|
|
89
|
+
|
|
90
|
+
act(() => {
|
|
91
|
+
jest.advanceTimersByTime(500);
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
expect(fn).toHaveBeenCalledWith('I have');
|
|
95
|
+
|
|
96
|
+
expect(document.querySelectorAll('.reqore-collection-item').length).toBe(2);
|
|
97
|
+
|
|
98
|
+
fireEvent.click(document.querySelector('.reqore-clear-input-button')!);
|
|
99
|
+
|
|
100
|
+
expect(document.querySelectorAll('.reqore-collection-item').length).toBe(9);
|
|
101
|
+
// Expect the input value to be empty
|
|
102
|
+
expect(document.querySelector('.reqore-input')?.getAttribute('value')).toBe('');
|
|
103
|
+
});
|
|
104
|
+
|
|
62
105
|
test('<Collection /> shows no data message when empty', () => {
|
|
63
106
|
render(
|
|
64
107
|
<ReqoreUIProvider>
|
|
@@ -90,3 +133,99 @@ test('<Collection /> can be sorted', () => {
|
|
|
90
133
|
|
|
91
134
|
expect(firstNewItem?.querySelector('h3')?.textContent).toBe('This item is not flat');
|
|
92
135
|
});
|
|
136
|
+
|
|
137
|
+
test('<Collection /> has default paging', () => {
|
|
138
|
+
render(
|
|
139
|
+
<ReqoreUIProvider>
|
|
140
|
+
<ReqoreLayoutContent>
|
|
141
|
+
<ReqoreCollection items={bigCollection} paging='buttons' />
|
|
142
|
+
</ReqoreLayoutContent>
|
|
143
|
+
</ReqoreUIProvider>
|
|
144
|
+
);
|
|
145
|
+
|
|
146
|
+
expect(document.querySelectorAll('.reqore-pagination-wrapper').length).toBe(1);
|
|
147
|
+
});
|
|
148
|
+
|
|
149
|
+
test('<Collection /> has list paging', () => {
|
|
150
|
+
render(
|
|
151
|
+
<ReqoreUIProvider>
|
|
152
|
+
<ReqoreLayoutContent>
|
|
153
|
+
<ReqoreCollection items={bigCollection} paging='list' />
|
|
154
|
+
</ReqoreLayoutContent>
|
|
155
|
+
</ReqoreUIProvider>
|
|
156
|
+
);
|
|
157
|
+
|
|
158
|
+
expect(document.querySelectorAll('.reqore-pagination-wrapper').length).toBe(1);
|
|
159
|
+
expect(document.querySelectorAll('.reqore-dropdown-control').length).toBe(1);
|
|
160
|
+
expect(screen.getAllByText('1 / 10')).toBeTruthy();
|
|
161
|
+
});
|
|
162
|
+
|
|
163
|
+
test('<Collection /> has infinite paging', () => {
|
|
164
|
+
render(
|
|
165
|
+
<ReqoreUIProvider>
|
|
166
|
+
<ReqoreLayoutContent>
|
|
167
|
+
<ReqoreCollection items={bigCollection} paging='infinite' />
|
|
168
|
+
</ReqoreLayoutContent>
|
|
169
|
+
</ReqoreUIProvider>
|
|
170
|
+
);
|
|
171
|
+
|
|
172
|
+
expect(document.querySelectorAll('.reqore-pagination-wrapper').length).toBe(1);
|
|
173
|
+
expect(document.querySelectorAll('.reqore-button').length).toBe(2);
|
|
174
|
+
expect(screen.getAllByText('90')).toBeTruthy();
|
|
175
|
+
|
|
176
|
+
expect(document.querySelectorAll('.reqore-collection-item').length).toBe(10);
|
|
177
|
+
|
|
178
|
+
fireEvent.click(document.querySelectorAll('.reqore-button')[1]);
|
|
179
|
+
|
|
180
|
+
expect(document.querySelectorAll('.reqore-collection-item').length).toBe(20);
|
|
181
|
+
});
|
|
182
|
+
|
|
183
|
+
test('<Collection /> has custom paging', () => {
|
|
184
|
+
render(
|
|
185
|
+
<ReqoreUIProvider>
|
|
186
|
+
<ReqoreLayoutContent>
|
|
187
|
+
<ReqoreCollection
|
|
188
|
+
items={bigCollection}
|
|
189
|
+
paging={{
|
|
190
|
+
itemsPerPage: 50,
|
|
191
|
+
infinite: true,
|
|
192
|
+
autoLoadMore: true,
|
|
193
|
+
showLabels: true,
|
|
194
|
+
loadMoreLabel: 'Scroll to load more',
|
|
195
|
+
}}
|
|
196
|
+
/>
|
|
197
|
+
</ReqoreLayoutContent>
|
|
198
|
+
</ReqoreUIProvider>
|
|
199
|
+
);
|
|
200
|
+
|
|
201
|
+
expect(document.querySelectorAll('.reqore-pagination-wrapper').length).toBe(1);
|
|
202
|
+
expect(document.querySelectorAll('.reqore-button').length).toBe(2);
|
|
203
|
+
expect(document.querySelectorAll('.reqore-collection-item').length).toBe(50);
|
|
204
|
+
expect(screen.getAllByText('Scroll to load more')).toBeTruthy();
|
|
205
|
+
expect(screen.getAllByText('50')).toBeTruthy();
|
|
206
|
+
|
|
207
|
+
mockAllIsIntersecting(true);
|
|
208
|
+
|
|
209
|
+
expect(document.querySelectorAll('.reqore-collection-item').length).toBe(100);
|
|
210
|
+
});
|
|
211
|
+
|
|
212
|
+
test('<Collection /> has 2 paging controls', () => {
|
|
213
|
+
render(
|
|
214
|
+
<ReqoreUIProvider>
|
|
215
|
+
<ReqoreLayoutContent>
|
|
216
|
+
<ReqoreCollection
|
|
217
|
+
items={bigCollection}
|
|
218
|
+
paging={{
|
|
219
|
+
itemsPerPage: 10,
|
|
220
|
+
showPagesAs: 'list',
|
|
221
|
+
pageControlsPosition: 'both',
|
|
222
|
+
}}
|
|
223
|
+
/>
|
|
224
|
+
</ReqoreLayoutContent>
|
|
225
|
+
</ReqoreUIProvider>
|
|
226
|
+
);
|
|
227
|
+
|
|
228
|
+
expect(document.querySelectorAll('.reqore-pagination-wrapper').length).toBe(2);
|
|
229
|
+
expect(document.querySelectorAll('.reqore-button').length).toBe(11);
|
|
230
|
+
expect(document.querySelectorAll('.reqore-collection-item').length).toBe(10);
|
|
231
|
+
});
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import { fireEvent, render, screen } from '@testing-library/react';
|
|
2
|
+
import React from 'react';
|
|
3
|
+
import {
|
|
4
|
+
ReqoreContent,
|
|
5
|
+
ReqoreControlGroup,
|
|
6
|
+
ReqoreLayoutContent,
|
|
7
|
+
ReqorePaginationContainer,
|
|
8
|
+
ReqoreTag,
|
|
9
|
+
ReqoreUIProvider,
|
|
10
|
+
} from '../../src';
|
|
11
|
+
import { tableData as data } from '../../src/mock/tableData';
|
|
12
|
+
|
|
13
|
+
test('Renders default <PaginationContainer />', () => {
|
|
14
|
+
render(
|
|
15
|
+
<ReqoreUIProvider>
|
|
16
|
+
<ReqoreLayoutContent>
|
|
17
|
+
<ReqoreContent>
|
|
18
|
+
<ReqorePaginationContainer<any> items={data} type='buttons'>
|
|
19
|
+
{(items) => (
|
|
20
|
+
<ReqoreControlGroup vertical>
|
|
21
|
+
{items.map((item) => (
|
|
22
|
+
<ReqoreTag label={`${item.firstName} ${item.lastName}`} />
|
|
23
|
+
))}
|
|
24
|
+
</ReqoreControlGroup>
|
|
25
|
+
)}
|
|
26
|
+
</ReqorePaginationContainer>
|
|
27
|
+
</ReqoreContent>
|
|
28
|
+
</ReqoreLayoutContent>
|
|
29
|
+
</ReqoreUIProvider>
|
|
30
|
+
);
|
|
31
|
+
|
|
32
|
+
expect(document.querySelectorAll('.reqore-pagination-wrapper').length).toBe(1);
|
|
33
|
+
expect(document.querySelectorAll('.reqore-button')[0]?.getAttribute('disabled')).toBe('');
|
|
34
|
+
expect(document.querySelectorAll('.reqore-button').length).toBe(102);
|
|
35
|
+
|
|
36
|
+
fireEvent.click(document.querySelectorAll('.reqore-button')[100]);
|
|
37
|
+
|
|
38
|
+
expect(screen.getAllByText('Rodd Solly')).toBeTruthy();
|
|
39
|
+
expect(document.querySelectorAll('.reqore-button')[101]?.getAttribute('disabled')).toBe('');
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
test('Renders default <PaginationContainer /> with both control wrappers', () => {
|
|
43
|
+
render(
|
|
44
|
+
<ReqoreUIProvider>
|
|
45
|
+
<ReqoreLayoutContent>
|
|
46
|
+
<ReqoreContent>
|
|
47
|
+
<ReqorePaginationContainer<any> items={data} type={{ pageControlsPosition: 'both' }}>
|
|
48
|
+
{(items) => (
|
|
49
|
+
<ReqoreControlGroup vertical>
|
|
50
|
+
{items.map((item) => (
|
|
51
|
+
<ReqoreTag label={`${item.firstName} ${item.lastName}`} />
|
|
52
|
+
))}
|
|
53
|
+
</ReqoreControlGroup>
|
|
54
|
+
)}
|
|
55
|
+
</ReqorePaginationContainer>
|
|
56
|
+
</ReqoreContent>
|
|
57
|
+
</ReqoreLayoutContent>
|
|
58
|
+
</ReqoreUIProvider>
|
|
59
|
+
);
|
|
60
|
+
|
|
61
|
+
expect(document.querySelectorAll('.reqore-pagination-wrapper').length).toBe(2);
|
|
62
|
+
expect(document.querySelectorAll('.reqore-button')[0]?.getAttribute('disabled')).toBe('');
|
|
63
|
+
expect(document.querySelectorAll('.reqore-button').length).toBe(204);
|
|
64
|
+
|
|
65
|
+
fireEvent.click(document.querySelectorAll('.reqore-button')[100]);
|
|
66
|
+
|
|
67
|
+
expect(screen.getAllByText('Rodd Solly')).toBeTruthy();
|
|
68
|
+
|
|
69
|
+
expect(document.querySelectorAll('.reqore-button')[101]?.getAttribute('disabled')).toBe('');
|
|
70
|
+
expect(document.querySelectorAll('.reqore-button')[203]?.getAttribute('disabled')).toBe('');
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
test('Renders default <PaginationContainer /> with both control wrappers, one included in children', () => {
|
|
74
|
+
render(
|
|
75
|
+
<ReqoreUIProvider>
|
|
76
|
+
<ReqoreLayoutContent>
|
|
77
|
+
<ReqoreContent>
|
|
78
|
+
<ReqorePaginationContainer<any>
|
|
79
|
+
items={data}
|
|
80
|
+
type={{ pageControlsPosition: 'both', includeBottomControls: false }}
|
|
81
|
+
>
|
|
82
|
+
{(items, Controls, { includeBottomControls }) => (
|
|
83
|
+
<ReqoreControlGroup vertical>
|
|
84
|
+
{items.map((item) => (
|
|
85
|
+
<ReqoreTag label={`${item.firstName} ${item.lastName}`} />
|
|
86
|
+
))}
|
|
87
|
+
{!includeBottomControls && <Controls />}
|
|
88
|
+
</ReqoreControlGroup>
|
|
89
|
+
)}
|
|
90
|
+
</ReqorePaginationContainer>
|
|
91
|
+
</ReqoreContent>
|
|
92
|
+
</ReqoreLayoutContent>
|
|
93
|
+
</ReqoreUIProvider>
|
|
94
|
+
);
|
|
95
|
+
|
|
96
|
+
expect(document.querySelectorAll('.reqore-pagination-wrapper').length).toBe(2);
|
|
97
|
+
expect(document.querySelectorAll('.reqore-button')[0]?.getAttribute('disabled')).toBe('');
|
|
98
|
+
expect(document.querySelectorAll('.reqore-button').length).toBe(204);
|
|
99
|
+
|
|
100
|
+
fireEvent.click(document.querySelectorAll('.reqore-button')[100]);
|
|
101
|
+
|
|
102
|
+
expect(screen.getAllByText('Rodd Solly')).toBeTruthy();
|
|
103
|
+
|
|
104
|
+
expect(document.querySelectorAll('.reqore-button')[101]?.getAttribute('disabled')).toBe('');
|
|
105
|
+
expect(document.querySelectorAll('.reqore-button')[203]?.getAttribute('disabled')).toBe('');
|
|
106
|
+
});
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { renderHook } from '@testing-library/react';
|
|
2
|
+
import React from 'react';
|
|
3
|
+
import { ReqoreUIProvider, useLatestZIndex } from '../../src';
|
|
4
|
+
|
|
5
|
+
test('useLatestZIndex returns incremental z indexes', () => {
|
|
6
|
+
const wrapper = ({ children }: any) => <ReqoreUIProvider>{children}</ReqoreUIProvider>;
|
|
7
|
+
const { result } = renderHook(() => useLatestZIndex(), { wrapper });
|
|
8
|
+
|
|
9
|
+
expect(result.current).toEqual(9002);
|
|
10
|
+
});
|
|
@@ -0,0 +1,255 @@
|
|
|
1
|
+
import { renderHook } from '@testing-library/react';
|
|
2
|
+
import React from 'react';
|
|
3
|
+
import { act } from 'react-dom/test-utils';
|
|
4
|
+
import { ReqoreUIProvider, useReqorePaging } from '../../src';
|
|
5
|
+
import { IReqorePagingOptions } from '../../src/hooks/usePaging';
|
|
6
|
+
import { tableData as data } from '../../src/mock/tableData';
|
|
7
|
+
|
|
8
|
+
test('useReqorePaging returns all pages', () => {
|
|
9
|
+
const wrapper = ({ children }: any) => <ReqoreUIProvider>{children}</ReqoreUIProvider>;
|
|
10
|
+
const { result } = renderHook(
|
|
11
|
+
({ items }) =>
|
|
12
|
+
useReqorePaging({
|
|
13
|
+
items,
|
|
14
|
+
}),
|
|
15
|
+
{ wrapper, initialProps: { items: data } }
|
|
16
|
+
);
|
|
17
|
+
|
|
18
|
+
expect(result.current.pages.length).toEqual(100);
|
|
19
|
+
expect(result.current.pageCount).toEqual(100);
|
|
20
|
+
expect(result.current.renderControls).toEqual(true);
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
test('useReqorePaging with default start page', () => {
|
|
24
|
+
const wrapper = ({ children }: any) => <ReqoreUIProvider>{children}</ReqoreUIProvider>;
|
|
25
|
+
const { result } = renderHook(
|
|
26
|
+
({ items }) =>
|
|
27
|
+
useReqorePaging({
|
|
28
|
+
items,
|
|
29
|
+
startPage: 11,
|
|
30
|
+
pagesToShow: 5,
|
|
31
|
+
}),
|
|
32
|
+
{ wrapper, initialProps: { items: data } }
|
|
33
|
+
);
|
|
34
|
+
|
|
35
|
+
expect(result.current.pageCount).toEqual(100);
|
|
36
|
+
expect(result.current.currentPage).toEqual(11);
|
|
37
|
+
expect(result.current.pages.length).toEqual(7);
|
|
38
|
+
expect(result.current.pages[0]).toEqual(1);
|
|
39
|
+
expect(result.current.pages[1]).toEqual(9);
|
|
40
|
+
expect(result.current.pages[5]).toEqual(13);
|
|
41
|
+
expect(result.current.pages[6]).toEqual(100);
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
test('useReqorePaging specified number of pages', () => {
|
|
45
|
+
const wrapper = ({ children }: any) => <ReqoreUIProvider>{children}</ReqoreUIProvider>;
|
|
46
|
+
const { result } = renderHook(
|
|
47
|
+
({ items }) =>
|
|
48
|
+
useReqorePaging({
|
|
49
|
+
items,
|
|
50
|
+
pagesToShow: 5,
|
|
51
|
+
}),
|
|
52
|
+
{ wrapper, initialProps: { items: data } }
|
|
53
|
+
);
|
|
54
|
+
|
|
55
|
+
expect(result.current.allPages.length).toEqual(100);
|
|
56
|
+
expect(result.current.pages!.length).toEqual(6);
|
|
57
|
+
expect(result.current.pages![0]).toEqual(1);
|
|
58
|
+
expect(result.current.pages![4]).toEqual(5);
|
|
59
|
+
|
|
60
|
+
act(() => {
|
|
61
|
+
result.current.setPage(8);
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
expect(result.current.pages![1]).toEqual(6);
|
|
65
|
+
expect(result.current.pages![5]).toEqual(10);
|
|
66
|
+
|
|
67
|
+
act(() => {
|
|
68
|
+
result.current.last();
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
expect(result.current.pages![1]).toEqual(96);
|
|
72
|
+
expect(result.current.pages![5]).toEqual(100);
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
test('useReqorePaging returns 1 page when items are empty', () => {
|
|
76
|
+
const wrapper = ({ children }: any) => <ReqoreUIProvider>{children}</ReqoreUIProvider>;
|
|
77
|
+
const { result } = renderHook(
|
|
78
|
+
({ items }) =>
|
|
79
|
+
useReqorePaging({
|
|
80
|
+
items,
|
|
81
|
+
}),
|
|
82
|
+
{ wrapper, initialProps: { items: [] } }
|
|
83
|
+
);
|
|
84
|
+
|
|
85
|
+
expect(result.current.pages.length).toEqual(1);
|
|
86
|
+
expect(result.current.renderControls).toEqual(false);
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
test('useReqorePaging returns correct number of rounded pages', () => {
|
|
90
|
+
const wrapper = ({ children }: any) => <ReqoreUIProvider>{children}</ReqoreUIProvider>;
|
|
91
|
+
const { result } = renderHook(
|
|
92
|
+
({ itemsPerPage, items }) =>
|
|
93
|
+
useReqorePaging({
|
|
94
|
+
items,
|
|
95
|
+
itemsPerPage,
|
|
96
|
+
}),
|
|
97
|
+
{ wrapper, initialProps: { itemsPerPage: 13, items: data } }
|
|
98
|
+
);
|
|
99
|
+
|
|
100
|
+
expect(result.current.pages.length).toEqual(77);
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
test('useReqorePaging returns items per page', () => {
|
|
104
|
+
const wrapper = ({ children }: any) => <ReqoreUIProvider>{children}</ReqoreUIProvider>;
|
|
105
|
+
const { result } = renderHook(
|
|
106
|
+
({ itemsPerPage, items }) =>
|
|
107
|
+
useReqorePaging({
|
|
108
|
+
items,
|
|
109
|
+
itemsPerPage,
|
|
110
|
+
}),
|
|
111
|
+
{ wrapper, initialProps: { itemsPerPage: 10, items: data } }
|
|
112
|
+
);
|
|
113
|
+
|
|
114
|
+
expect(result.current.pages.length).toEqual(100);
|
|
115
|
+
expect(result.current.items.length).toEqual(10);
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
test('useReqorePaging returns new items and pages when size of data change, current page is set to 1', () => {
|
|
119
|
+
const wrapper = ({ children }: any) => <ReqoreUIProvider>{children}</ReqoreUIProvider>;
|
|
120
|
+
const { result, rerender } = renderHook(
|
|
121
|
+
({ itemsPerPage, items }) =>
|
|
122
|
+
useReqorePaging({
|
|
123
|
+
items,
|
|
124
|
+
itemsPerPage,
|
|
125
|
+
}),
|
|
126
|
+
{ wrapper, initialProps: { itemsPerPage: 10, items: data } }
|
|
127
|
+
);
|
|
128
|
+
|
|
129
|
+
expect(result.current.pages.length).toEqual(100);
|
|
130
|
+
expect(result.current.items.length).toEqual(10);
|
|
131
|
+
|
|
132
|
+
act(() => {
|
|
133
|
+
result.current.setPage(5);
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
expect(result.current.currentPage).toEqual(5);
|
|
137
|
+
|
|
138
|
+
rerender({ itemsPerPage: 15, items: data.slice(0, 30) });
|
|
139
|
+
|
|
140
|
+
expect(result.current.pages.length).toEqual(2);
|
|
141
|
+
expect(result.current.items.length).toEqual(15);
|
|
142
|
+
expect(result.current.currentPage).toEqual(1);
|
|
143
|
+
});
|
|
144
|
+
|
|
145
|
+
test('useReqorePaging does not return new items and pages when data change', () => {
|
|
146
|
+
const wrapper = ({ children }: any) => <ReqoreUIProvider>{children}</ReqoreUIProvider>;
|
|
147
|
+
const { result, rerender } = renderHook(
|
|
148
|
+
({ itemsPerPage, items }: IReqorePagingOptions<any>) =>
|
|
149
|
+
useReqorePaging({
|
|
150
|
+
items,
|
|
151
|
+
itemsPerPage,
|
|
152
|
+
}),
|
|
153
|
+
{ wrapper, initialProps: { itemsPerPage: 10, items: data } as IReqorePagingOptions<any> }
|
|
154
|
+
);
|
|
155
|
+
|
|
156
|
+
expect(result.current.pages.length).toEqual(100);
|
|
157
|
+
expect(result.current.items.length).toEqual(10);
|
|
158
|
+
|
|
159
|
+
act(() => {
|
|
160
|
+
result.current.setPage(5);
|
|
161
|
+
});
|
|
162
|
+
|
|
163
|
+
rerender({ items: [...data] });
|
|
164
|
+
|
|
165
|
+
expect(result.current.pages.length).toEqual(100);
|
|
166
|
+
expect(result.current.items.length).toEqual(10);
|
|
167
|
+
expect(result.current.currentPage).toEqual(5);
|
|
168
|
+
});
|
|
169
|
+
|
|
170
|
+
test('useReqorePaging page navigation works correctly', () => {
|
|
171
|
+
const wrapper = ({ children }: any) => <ReqoreUIProvider>{children}</ReqoreUIProvider>;
|
|
172
|
+
const { result } = renderHook(
|
|
173
|
+
({ itemsPerPage, items }: IReqorePagingOptions<any>) =>
|
|
174
|
+
useReqorePaging({
|
|
175
|
+
items,
|
|
176
|
+
itemsPerPage,
|
|
177
|
+
infinite: true,
|
|
178
|
+
}),
|
|
179
|
+
{ wrapper, initialProps: { itemsPerPage: 10, items: data } as IReqorePagingOptions<any> }
|
|
180
|
+
);
|
|
181
|
+
|
|
182
|
+
expect(result.current.pages.length).toEqual(100);
|
|
183
|
+
expect(result.current.items.length).toEqual(10);
|
|
184
|
+
|
|
185
|
+
act(() => {
|
|
186
|
+
result.current.setPage(2);
|
|
187
|
+
});
|
|
188
|
+
|
|
189
|
+
expect(result.current.currentPage).toEqual(2);
|
|
190
|
+
|
|
191
|
+
act(() => {
|
|
192
|
+
result.current.next();
|
|
193
|
+
});
|
|
194
|
+
|
|
195
|
+
expect(result.current.currentPage).toEqual(3);
|
|
196
|
+
|
|
197
|
+
act(() => {
|
|
198
|
+
result.current.last();
|
|
199
|
+
});
|
|
200
|
+
|
|
201
|
+
expect(result.current.isLastPage).toEqual(true);
|
|
202
|
+
expect(result.current.currentPage).toEqual(100);
|
|
203
|
+
|
|
204
|
+
act(() => {
|
|
205
|
+
result.current.back();
|
|
206
|
+
});
|
|
207
|
+
|
|
208
|
+
expect(result.current.currentPage).toEqual(99);
|
|
209
|
+
|
|
210
|
+
act(() => {
|
|
211
|
+
result.current.first();
|
|
212
|
+
});
|
|
213
|
+
|
|
214
|
+
expect(result.current.isFirstPage).toEqual(true);
|
|
215
|
+
expect(result.current.currentPage).toEqual(1);
|
|
216
|
+
});
|
|
217
|
+
|
|
218
|
+
test('useReqorePaging returns correct number of items with infinite loading', () => {
|
|
219
|
+
const wrapper = ({ children }: any) => <ReqoreUIProvider>{children}</ReqoreUIProvider>;
|
|
220
|
+
const { result } = renderHook(
|
|
221
|
+
({ itemsPerPage, items }: IReqorePagingOptions<any>) =>
|
|
222
|
+
useReqorePaging({
|
|
223
|
+
items,
|
|
224
|
+
itemsPerPage,
|
|
225
|
+
infinite: true,
|
|
226
|
+
}),
|
|
227
|
+
{ wrapper, initialProps: { itemsPerPage: 10, items: data } as IReqorePagingOptions<any> }
|
|
228
|
+
);
|
|
229
|
+
|
|
230
|
+
expect(result.current.pages.length).toEqual(100);
|
|
231
|
+
expect(result.current.items.length).toEqual(10);
|
|
232
|
+
|
|
233
|
+
act(() => {
|
|
234
|
+
result.current.setPage(2);
|
|
235
|
+
});
|
|
236
|
+
|
|
237
|
+
expect(result.current.pages.length).toEqual(100);
|
|
238
|
+
expect(result.current.items.length).toEqual(20);
|
|
239
|
+
|
|
240
|
+
act(() => {
|
|
241
|
+
result.current.setPage(5);
|
|
242
|
+
});
|
|
243
|
+
|
|
244
|
+
expect(result.current.items.length).toEqual(50);
|
|
245
|
+
expect(result.current.itemsLeft).toEqual(950);
|
|
246
|
+
expect(result.current.renderControls).toEqual(true);
|
|
247
|
+
|
|
248
|
+
act(() => {
|
|
249
|
+
result.current.last();
|
|
250
|
+
});
|
|
251
|
+
|
|
252
|
+
expect(result.current.items.length).toEqual(1000);
|
|
253
|
+
expect(result.current.itemsLeft).toEqual(0);
|
|
254
|
+
expect(result.current.renderControls).toEqual(false);
|
|
255
|
+
});
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { renderHook } from '@testing-library/react';
|
|
2
|
+
import { ReqoreColors } from '../../src';
|
|
3
|
+
import { DEFAULT_THEME } from '../../src/constants/theme';
|
|
4
|
+
import { useReqoreTheme } from '../../src/hooks/useTheme';
|
|
5
|
+
|
|
6
|
+
test('useReqoreTheme should return the default theme', () => {
|
|
7
|
+
const { result } = renderHook(() => useReqoreTheme());
|
|
8
|
+
|
|
9
|
+
expect(result.current).toEqual(DEFAULT_THEME);
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
test('useReqoreTheme should return modified main intent color, original color is preserved', () => {
|
|
13
|
+
const { result } = renderHook(() => useReqoreTheme('main', { main: 'info' }));
|
|
14
|
+
|
|
15
|
+
expect(result.current.main).toEqual(ReqoreColors.BLUE);
|
|
16
|
+
expect(result.current.originalMain).toEqual(ReqoreColors.DARK_THEME);
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
test('useReqoreTheme should return modified main custom color, original color is preserved', () => {
|
|
20
|
+
const { result } = renderHook(() => useReqoreTheme('main', { main: '#7fbb26' }));
|
|
21
|
+
|
|
22
|
+
expect(result.current.main).toEqual('#7fbb26');
|
|
23
|
+
expect(result.current.originalMain).toEqual(ReqoreColors.DARK_THEME);
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
test('useReqoreTheme should return modified main color if intent is passed, original color is preserved', () => {
|
|
27
|
+
const { result } = renderHook(() => useReqoreTheme('main', { main: '#7fbb26' }, 'info'));
|
|
28
|
+
|
|
29
|
+
expect(result.current.main).toEqual(ReqoreColors.BLUE);
|
|
30
|
+
expect(result.current.originalMain).toEqual(ReqoreColors.DARK_THEME);
|
|
31
|
+
});
|