@controleonline/ui-default 1.0.264 → 1.0.266
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/AGENTS.md +3 -2
- package/package.json +21 -18
- package/src/react/components/errors/DefaultErrors.js +64 -82
- package/src/react/components/filters/CompactFilterSelector.js +58 -23
- package/src/react/components/filters/CompactFilterSelector.styles.js +17 -5
- package/src/react/components/filters/DefaultColumnFilter.js +177 -45
- package/src/react/components/filters/DefaultExternalFilters.js +201 -143
- package/src/react/components/filters/DefaultSearch.js +27 -25
- package/src/react/components/form/DefaultForm.js +72 -53
- package/src/react/components/form/DefaultForm.styles.js +71 -66
- package/src/react/components/inputs/DefaultDateInput.js +150 -0
- package/src/react/components/inputs/DefaultInput.js +44 -11
- package/src/react/components/inputs/DefaultInput.styles.js +6 -0
- package/src/react/components/inputs/DefaultSelect.js +200 -43
- package/src/react/components/inputs/defaultInputUtils.js +40 -19
- package/src/react/components/table/DefaultColumnMenu.js +108 -0
- package/src/react/components/table/DefaultDebug.js +234 -0
- package/src/react/components/table/DefaultFiltersModal.js +142 -0
- package/src/react/components/table/DefaultModalButton.js +18 -0
- package/src/react/components/table/DefaultSearchModal.js +49 -0
- package/src/react/components/table/DefaultTable.js +322 -1964
- package/src/react/components/table/DefaultTable.styles.js +234 -102
- package/src/react/components/table/DefaultTable.utils.js +502 -0
- package/src/react/components/table/DefaultTableBody.js +26 -0
- package/src/react/components/table/DefaultTableCards.js +171 -0
- package/src/react/components/table/DefaultTableControls.js +205 -0
- package/src/react/components/table/DefaultTableEmptyState.js +22 -0
- package/src/react/components/table/DefaultTableFooter.js +172 -0
- package/src/react/components/table/DefaultTableInput.js +145 -0
- package/src/react/components/table/DefaultTableRows.js +344 -0
- package/src/react/components/table/DefaultTableSearch.js +100 -0
- package/src/react/components/table/DefaultTableToolbar.js +98 -0
- package/src/react/components/table/DefaultToolbarAction.js +56 -0
- package/src/react/components/table/useDefaultTablePagination.js +370 -0
- package/src/react/components/table/useDefaultTableSorting.js +126 -0
- package/src/react/components/table/useDefaultTableTheme.js +52 -0
- package/src/react/utils/tableVisibleColumnsPreferences.js +239 -211
- package/src/store/default/actions.js +51 -13
- package/src/store/default/getters.js +10 -8
- package/src/store/default/mutation_types.js +4 -2
- package/src/store/default/mutations.js +10 -1
- package/src/tests/react/components/form/DefaultForm.test.js +81 -0
- package/src/tests/react/components/inputs/DefaultSelect.test.js +106 -14
- package/src/tests/react/components/table/DefaultTable.test.js +1318 -334
- package/src/tests/react/store/defaultActions.test.js +59 -0
- package/src/tests/react/utils/tableVisibleColumnsPreferences.test.js +247 -168
|
@@ -1,334 +1,1318 @@
|
|
|
1
|
-
const React = require('react');
|
|
2
|
-
const renderer = require('react-test-renderer');
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
let
|
|
10
|
-
let
|
|
11
|
-
let
|
|
12
|
-
let
|
|
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
|
-
jest.
|
|
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
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
});
|
|
201
|
-
|
|
202
|
-
expect(
|
|
203
|
-
expect(
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
expect(
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
.
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
};
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
storeName: '
|
|
315
|
-
}),
|
|
316
|
-
);
|
|
317
|
-
});
|
|
318
|
-
|
|
319
|
-
expect(
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
})
|
|
1
|
+
const React = require('react');
|
|
2
|
+
const renderer = require('react-test-renderer');
|
|
3
|
+
|
|
4
|
+
const {afterEach, beforeEach, describe, expect, it} = global;
|
|
5
|
+
|
|
6
|
+
global.IS_REACT_ACT_ENVIRONMENT = true;
|
|
7
|
+
|
|
8
|
+
let consoleErrorSpy = null;
|
|
9
|
+
let mockStores = {};
|
|
10
|
+
let mockWindowDimensions = {width: 480, height: 800};
|
|
11
|
+
let mockCapturedColumnFilterProps = [];
|
|
12
|
+
let mockCapturedDefaultInputProps = [];
|
|
13
|
+
|
|
14
|
+
const createLocalStorageMock = () => {
|
|
15
|
+
let storage = {};
|
|
16
|
+
|
|
17
|
+
return {
|
|
18
|
+
clear: () => {
|
|
19
|
+
storage = {};
|
|
20
|
+
},
|
|
21
|
+
getItem: key => (key in storage ? storage[key] : null),
|
|
22
|
+
removeItem: key => {
|
|
23
|
+
delete storage[key];
|
|
24
|
+
},
|
|
25
|
+
setItem: (key, value) => {
|
|
26
|
+
storage[key] = String(value);
|
|
27
|
+
},
|
|
28
|
+
};
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
jest.mock('@store', () => ({
|
|
32
|
+
getAllStores: jest.fn(() => ({})),
|
|
33
|
+
useStore: jest.fn(name => mockStores[name] || {actions: {}, getters: {}}),
|
|
34
|
+
}));
|
|
35
|
+
|
|
36
|
+
jest.mock('@react-navigation/native', () => ({
|
|
37
|
+
useIsFocused: jest.fn(() => false),
|
|
38
|
+
useRoute: jest.fn(() => ({
|
|
39
|
+
key: 'OrderHistoryPage-key',
|
|
40
|
+
name: 'OrderHistoryPage',
|
|
41
|
+
})),
|
|
42
|
+
}));
|
|
43
|
+
|
|
44
|
+
jest.mock('@controleonline/ui-common/src/react/components/MessageService', () => ({
|
|
45
|
+
useMessage: jest.fn(() => ({
|
|
46
|
+
showError: jest.fn(),
|
|
47
|
+
})),
|
|
48
|
+
}));
|
|
49
|
+
|
|
50
|
+
jest.mock('react-native-vector-icons/Feather', () => {
|
|
51
|
+
const React = require('react');
|
|
52
|
+
return props => React.createElement('icon', props, props.children);
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
jest.mock('react-native', () => {
|
|
56
|
+
const React = require('react');
|
|
57
|
+
const createComponent = name => props =>
|
|
58
|
+
React.createElement(name, props, props.children);
|
|
59
|
+
|
|
60
|
+
const FlatList = props => {
|
|
61
|
+
const items = Array.isArray(props.data) ? props.data : [];
|
|
62
|
+
|
|
63
|
+
return React.createElement(
|
|
64
|
+
'FlatList',
|
|
65
|
+
props,
|
|
66
|
+
items.map((item, index) =>
|
|
67
|
+
props.renderItem ? props.renderItem({item, index}) : null,
|
|
68
|
+
),
|
|
69
|
+
items.length === 0 && props.ListEmptyComponent ? props.ListEmptyComponent : null,
|
|
70
|
+
props.ListFooterComponent || null,
|
|
71
|
+
);
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
return {
|
|
75
|
+
FlatList,
|
|
76
|
+
Modal: createComponent('Modal'),
|
|
77
|
+
Platform: {
|
|
78
|
+
select: value => value.web || value.default || null,
|
|
79
|
+
},
|
|
80
|
+
ScrollView: createComponent('ScrollView'),
|
|
81
|
+
StyleSheet: {create: value => value},
|
|
82
|
+
Text: createComponent('Text'),
|
|
83
|
+
TouchableOpacity: createComponent('TouchableOpacity'),
|
|
84
|
+
View: createComponent('View'),
|
|
85
|
+
useWindowDimensions: jest.fn(() => mockWindowDimensions),
|
|
86
|
+
};
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
jest.mock('../../../../react/components/filters/DefaultColumnFilter', () => props => {
|
|
90
|
+
const React = require('react');
|
|
91
|
+
mockCapturedColumnFilterProps.push(props);
|
|
92
|
+
return React.createElement('DefaultColumnFilter', props);
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
jest.mock('../../../../react/components/filters/DefaultSearch', () => props => {
|
|
96
|
+
const React = require('react');
|
|
97
|
+
return React.createElement('DefaultSearch', props);
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
jest.mock('../../../../react/components/form/DefaultForm', () => () => {
|
|
101
|
+
const React = require('react');
|
|
102
|
+
return React.createElement('DefaultForm');
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
jest.mock('../../../../react/components/inputs/DefaultInput', () => props => {
|
|
106
|
+
const React = require('react');
|
|
107
|
+
mockCapturedDefaultInputProps.push(props);
|
|
108
|
+
return React.createElement('DefaultInput', props);
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
jest.mock('@controleonline/ui-common/src/react/components/StateStore', () => props => {
|
|
112
|
+
const React = require('react');
|
|
113
|
+
return React.createElement('StateStore', props, props.children);
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
const {
|
|
117
|
+
default: DefaultTable,
|
|
118
|
+
mergeSortedDataWithLiveItems,
|
|
119
|
+
resolveColumnListLoadParams,
|
|
120
|
+
shouldTriggerEndReachedFromScroll,
|
|
121
|
+
} = require('../../../../react/components/table/DefaultTable');
|
|
122
|
+
const {
|
|
123
|
+
DEFAULT_TABLE_PREFERENCES_STORAGE_KEY,
|
|
124
|
+
} = require('../../../../react/utils/tableVisibleColumnsPreferences');
|
|
125
|
+
const reactNavigation = require('@react-navigation/native');
|
|
126
|
+
const {getAllStores} = require('@store');
|
|
127
|
+
const STORE_ACTION_META_KEY = '__storeMeta';
|
|
128
|
+
|
|
129
|
+
const flattenStyle = style => {
|
|
130
|
+
if (Array.isArray(style)) {
|
|
131
|
+
return style.reduce(
|
|
132
|
+
(acc, item) => ({
|
|
133
|
+
...acc,
|
|
134
|
+
...flattenStyle(item),
|
|
135
|
+
}),
|
|
136
|
+
{},
|
|
137
|
+
);
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
return style && typeof style === 'object' ? style : {};
|
|
141
|
+
};
|
|
142
|
+
|
|
143
|
+
describe('resolveColumnListLoadParams', () => {
|
|
144
|
+
it('uses company for category stores and people for financial owner stores', () => {
|
|
145
|
+
expect(resolveColumnListLoadParams({
|
|
146
|
+
column: {list: 'categories/getItems'},
|
|
147
|
+
currentCompanyId: 21,
|
|
148
|
+
})).toEqual({company: 21});
|
|
149
|
+
expect(resolveColumnListLoadParams({
|
|
150
|
+
column: {list: 'wallet/getItems'},
|
|
151
|
+
currentCompanyId: 21,
|
|
152
|
+
})).toEqual({people: 21});
|
|
153
|
+
expect(resolveColumnListLoadParams({
|
|
154
|
+
column: {list: 'paymentType/getItems'},
|
|
155
|
+
currentCompanyId: 21,
|
|
156
|
+
})).toEqual({people: 21});
|
|
157
|
+
});
|
|
158
|
+
|
|
159
|
+
it('resolves contextual list params without losing the company scope', () => {
|
|
160
|
+
expect(resolveColumnListLoadParams({
|
|
161
|
+
column: {
|
|
162
|
+
list: 'categories/getItems',
|
|
163
|
+
listRequestParams: ({requestParams}) => ({context: requestParams.context}),
|
|
164
|
+
},
|
|
165
|
+
currentCompanyId: 21,
|
|
166
|
+
requestParams: {context: 'receive'},
|
|
167
|
+
})).toEqual({company: 21, context: 'receive'});
|
|
168
|
+
});
|
|
169
|
+
});
|
|
170
|
+
|
|
171
|
+
describe('mergeSortedDataWithLiveItems', () => {
|
|
172
|
+
it('keeps the sorted order and replaces stale rows with live store items', () => {
|
|
173
|
+
const sortedData = [
|
|
174
|
+
{
|
|
175
|
+
'@id': '/invoices/332',
|
|
176
|
+
id: 332,
|
|
177
|
+
status: {id: 32, status: 'open'},
|
|
178
|
+
},
|
|
179
|
+
{
|
|
180
|
+
'@id': '/invoices/333',
|
|
181
|
+
id: 333,
|
|
182
|
+
status: {id: 33, status: 'paid'},
|
|
183
|
+
},
|
|
184
|
+
];
|
|
185
|
+
const liveItems = [
|
|
186
|
+
{
|
|
187
|
+
id: 333,
|
|
188
|
+
status: {id: 33, status: 'paid'},
|
|
189
|
+
},
|
|
190
|
+
{
|
|
191
|
+
id: 332,
|
|
192
|
+
status: {id: 33, status: 'paid'},
|
|
193
|
+
},
|
|
194
|
+
{
|
|
195
|
+
id: 334,
|
|
196
|
+
status: {id: 33, status: 'paid'},
|
|
197
|
+
},
|
|
198
|
+
];
|
|
199
|
+
|
|
200
|
+
const mergedData = mergeSortedDataWithLiveItems({liveItems, sortedData});
|
|
201
|
+
|
|
202
|
+
expect(mergedData.map(item => item.id)).toEqual([332, 333]);
|
|
203
|
+
expect(mergedData[0].status.status).toBe('paid');
|
|
204
|
+
});
|
|
205
|
+
});
|
|
206
|
+
|
|
207
|
+
describe('shouldTriggerEndReachedFromScroll', () => {
|
|
208
|
+
it('returns true before the scroll reaches the exact end', () => {
|
|
209
|
+
expect(shouldTriggerEndReachedFromScroll({
|
|
210
|
+
nativeEvent: {
|
|
211
|
+
contentOffset: {y: 650},
|
|
212
|
+
contentSize: {height: 1200},
|
|
213
|
+
layoutMeasurement: {height: 400},
|
|
214
|
+
},
|
|
215
|
+
})).toBe(true);
|
|
216
|
+
|
|
217
|
+
expect(shouldTriggerEndReachedFromScroll({
|
|
218
|
+
nativeEvent: {
|
|
219
|
+
contentOffset: {y: 100},
|
|
220
|
+
contentSize: {height: 1200},
|
|
221
|
+
layoutMeasurement: {height: 400},
|
|
222
|
+
},
|
|
223
|
+
})).toBe(false);
|
|
224
|
+
});
|
|
225
|
+
});
|
|
226
|
+
|
|
227
|
+
describe('DefaultTable', () => {
|
|
228
|
+
beforeEach(() => {
|
|
229
|
+
consoleErrorSpy = jest.spyOn(console, 'error').mockImplementation(() => {});
|
|
230
|
+
mockWindowDimensions = {width: 480, height: 800};
|
|
231
|
+
mockCapturedColumnFilterProps = [];
|
|
232
|
+
mockCapturedDefaultInputProps = [];
|
|
233
|
+
getAllStores.mockImplementation(() => ({}));
|
|
234
|
+
global.localStorage = createLocalStorageMock();
|
|
235
|
+
global.t = {
|
|
236
|
+
t: jest.fn((store, type, key) => {
|
|
237
|
+
if (type === 'label' && key === 'search') return 'Buscar';
|
|
238
|
+
if (type === 'label' && key === 'items') return 'registros';
|
|
239
|
+
if (type === 'label' && key === 'loading') return 'Carregando...';
|
|
240
|
+
if (type === 'label' && key === 'empty') return 'Nenhum registro encontrado';
|
|
241
|
+
if (type === 'label' && key === 'filters') return 'Filtros';
|
|
242
|
+
if (type === 'label' && key === 'select') return 'Selecionar';
|
|
243
|
+
if (type === 'button' && key === 'add') return 'Adicionar';
|
|
244
|
+
if (type === 'button' && key === 'edit') return 'Editar';
|
|
245
|
+
if (type === 'button' && key === 'apply') return 'Aplicar';
|
|
246
|
+
if (type === 'button' && key === 'clear') return 'Limpar';
|
|
247
|
+
if (type === 'input' && key === 'search') return 'Buscar...';
|
|
248
|
+
return undefined;
|
|
249
|
+
}),
|
|
250
|
+
};
|
|
251
|
+
reactNavigation.useIsFocused.mockImplementation(() => false);
|
|
252
|
+
|
|
253
|
+
mockStores = {
|
|
254
|
+
people: {
|
|
255
|
+
getters: {
|
|
256
|
+
currentCompany: {
|
|
257
|
+
theme: {
|
|
258
|
+
colors: {},
|
|
259
|
+
},
|
|
260
|
+
},
|
|
261
|
+
},
|
|
262
|
+
},
|
|
263
|
+
theme: {
|
|
264
|
+
getters: {
|
|
265
|
+
colors: {},
|
|
266
|
+
},
|
|
267
|
+
},
|
|
268
|
+
};
|
|
269
|
+
});
|
|
270
|
+
|
|
271
|
+
afterEach(() => {
|
|
272
|
+
delete global.t;
|
|
273
|
+
if (consoleErrorSpy) {
|
|
274
|
+
consoleErrorSpy.mockRestore();
|
|
275
|
+
consoleErrorSpy = null;
|
|
276
|
+
}
|
|
277
|
+
});
|
|
278
|
+
|
|
279
|
+
it('keeps the list/card toggle visible on compact layouts even when cards are forced', () => {
|
|
280
|
+
let tree;
|
|
281
|
+
|
|
282
|
+
renderer.act(() => {
|
|
283
|
+
tree = renderer.create(
|
|
284
|
+
React.createElement(DefaultTable, {
|
|
285
|
+
columns: [{key: 'name', label: 'Nome'}],
|
|
286
|
+
data: [],
|
|
287
|
+
showColumnFiltersButton: false,
|
|
288
|
+
}),
|
|
289
|
+
);
|
|
290
|
+
});
|
|
291
|
+
|
|
292
|
+
const iconNames = tree.root.findAllByType('icon').map(node => node.props.name);
|
|
293
|
+
|
|
294
|
+
expect(iconNames).toEqual(expect.arrayContaining(['grid', 'columns']));
|
|
295
|
+
});
|
|
296
|
+
|
|
297
|
+
it('respects the compact grid/list toggle in the table body', () => {
|
|
298
|
+
mockWindowDimensions = {width: 480, height: 800};
|
|
299
|
+
mockStores.orders = {
|
|
300
|
+
actions: {},
|
|
301
|
+
getters: {
|
|
302
|
+
columns: [{key: 'name', label: 'Nome'}],
|
|
303
|
+
items: [{id: 1, name: 'Pedido'}],
|
|
304
|
+
visibleColumns: {},
|
|
305
|
+
},
|
|
306
|
+
};
|
|
307
|
+
let tree;
|
|
308
|
+
|
|
309
|
+
renderer.act(() => {
|
|
310
|
+
tree = renderer.create(
|
|
311
|
+
React.createElement(DefaultTable, {
|
|
312
|
+
data: [{id: 1, name: 'Pedido'}],
|
|
313
|
+
showColumnFiltersButton: false,
|
|
314
|
+
storeName: 'orders',
|
|
315
|
+
}),
|
|
316
|
+
);
|
|
317
|
+
});
|
|
318
|
+
|
|
319
|
+
expect(
|
|
320
|
+
tree.root.findAllByType('ScrollView').some(node => node.props.horizontal === true),
|
|
321
|
+
).toBe(false);
|
|
322
|
+
|
|
323
|
+
const toggleViewButton = tree.root
|
|
324
|
+
.findAllByType('TouchableOpacity')
|
|
325
|
+
.find(node => node.findAllByType('icon').some(icon => icon.props.name === 'list'));
|
|
326
|
+
|
|
327
|
+
renderer.act(() => {
|
|
328
|
+
toggleViewButton.props.onPress();
|
|
329
|
+
tree.update(
|
|
330
|
+
React.createElement(DefaultTable, {
|
|
331
|
+
data: [{id: 1, name: 'Pedido'}],
|
|
332
|
+
showColumnFiltersButton: false,
|
|
333
|
+
storeName: 'orders',
|
|
334
|
+
}),
|
|
335
|
+
);
|
|
336
|
+
});
|
|
337
|
+
|
|
338
|
+
expect(
|
|
339
|
+
tree.root.findAllByType('ScrollView').some(node => node.props.horizontal === true),
|
|
340
|
+
).toBe(true);
|
|
341
|
+
expect(tree.root.findAllByType('icon').map(node => node.props.name)).toContain('grid');
|
|
342
|
+
});
|
|
343
|
+
|
|
344
|
+
it('pins identity and action columns on table view', () => {
|
|
345
|
+
mockWindowDimensions = {width: 1200, height: 800};
|
|
346
|
+
mockStores.orders = {
|
|
347
|
+
actions: {},
|
|
348
|
+
getters: {
|
|
349
|
+
columns: [
|
|
350
|
+
{key: 'id', label: 'ID', isIdentity: true},
|
|
351
|
+
{key: 'name', label: 'Nome'},
|
|
352
|
+
],
|
|
353
|
+
items: [{id: 1, name: 'Pedido'}],
|
|
354
|
+
visibleColumns: {},
|
|
355
|
+
},
|
|
356
|
+
};
|
|
357
|
+
const rowActionsComponent = () => React.createElement('row-actions');
|
|
358
|
+
let tree;
|
|
359
|
+
|
|
360
|
+
renderer.act(() => {
|
|
361
|
+
tree = renderer.create(
|
|
362
|
+
React.createElement(DefaultTable, {
|
|
363
|
+
rowActionsComponent,
|
|
364
|
+
storeName: 'orders',
|
|
365
|
+
}),
|
|
366
|
+
);
|
|
367
|
+
});
|
|
368
|
+
|
|
369
|
+
const renderedStyles = [
|
|
370
|
+
...tree.root.findAllByType('View'),
|
|
371
|
+
...tree.root.findAllByType('TouchableOpacity'),
|
|
372
|
+
].map(node => flattenStyle(node.props.style));
|
|
373
|
+
|
|
374
|
+
expect(renderedStyles).toEqual(
|
|
375
|
+
expect.arrayContaining([
|
|
376
|
+
expect.objectContaining({position: 'sticky', left: 0}),
|
|
377
|
+
expect.objectContaining({position: 'sticky', right: 0}),
|
|
378
|
+
]),
|
|
379
|
+
);
|
|
380
|
+
|
|
381
|
+
const horizontalScroll = tree.root
|
|
382
|
+
.findAllByType('ScrollView')
|
|
383
|
+
.find(node => node.props.horizontal);
|
|
384
|
+
|
|
385
|
+
renderer.act(() => {
|
|
386
|
+
horizontalScroll.props.onLayout({nativeEvent: {layout: {width: 300}}});
|
|
387
|
+
horizontalScroll.props.onContentSizeChange(600, 200);
|
|
388
|
+
horizontalScroll.props.onScroll({nativeEvent: {contentOffset: {x: 120}}});
|
|
389
|
+
});
|
|
390
|
+
|
|
391
|
+
const scrolledStyles = [
|
|
392
|
+
...tree.root.findAllByType('View'),
|
|
393
|
+
...tree.root.findAllByType('TouchableOpacity'),
|
|
394
|
+
].map(node => flattenStyle(node.props.style));
|
|
395
|
+
|
|
396
|
+
expect(scrolledStyles).toEqual(
|
|
397
|
+
expect.arrayContaining([
|
|
398
|
+
expect.objectContaining({transform: [{translateX: 120}]}),
|
|
399
|
+
expect.objectContaining({transform: [{translateX: -180}]}),
|
|
400
|
+
]),
|
|
401
|
+
);
|
|
402
|
+
});
|
|
403
|
+
|
|
404
|
+
it('keeps only the identity column pinned when row actions are not pinned', () => {
|
|
405
|
+
mockWindowDimensions = {width: 1200, height: 800};
|
|
406
|
+
mockStores.orders = {
|
|
407
|
+
actions: {},
|
|
408
|
+
getters: {
|
|
409
|
+
columns: [
|
|
410
|
+
{key: 'id', label: 'ID', isIdentity: true},
|
|
411
|
+
{key: 'name', label: 'Nome'},
|
|
412
|
+
],
|
|
413
|
+
items: [{id: 1, name: 'Pedido'}],
|
|
414
|
+
visibleColumns: {},
|
|
415
|
+
},
|
|
416
|
+
};
|
|
417
|
+
const rowActionsComponent = () => React.createElement('row-actions');
|
|
418
|
+
let tree;
|
|
419
|
+
|
|
420
|
+
renderer.act(() => {
|
|
421
|
+
tree = renderer.create(
|
|
422
|
+
React.createElement(DefaultTable, {
|
|
423
|
+
pinRowActions: false,
|
|
424
|
+
rowActionsComponent,
|
|
425
|
+
storeName: 'orders',
|
|
426
|
+
}),
|
|
427
|
+
);
|
|
428
|
+
});
|
|
429
|
+
|
|
430
|
+
const renderedStyles = [
|
|
431
|
+
...tree.root.findAllByType('View'),
|
|
432
|
+
...tree.root.findAllByType('TouchableOpacity'),
|
|
433
|
+
].map(node => flattenStyle(node.props.style));
|
|
434
|
+
|
|
435
|
+
expect(renderedStyles).toEqual(
|
|
436
|
+
expect.arrayContaining([
|
|
437
|
+
expect.objectContaining({position: 'sticky', left: 0}),
|
|
438
|
+
]),
|
|
439
|
+
);
|
|
440
|
+
expect(renderedStyles).not.toEqual(
|
|
441
|
+
expect.arrayContaining([
|
|
442
|
+
expect.objectContaining({position: 'sticky', right: 0}),
|
|
443
|
+
]),
|
|
444
|
+
);
|
|
445
|
+
|
|
446
|
+
const horizontalScroll = tree.root
|
|
447
|
+
.findAllByType('ScrollView')
|
|
448
|
+
.find(node => node.props.horizontal);
|
|
449
|
+
|
|
450
|
+
renderer.act(() => {
|
|
451
|
+
horizontalScroll.props.onLayout({nativeEvent: {layout: {width: 300}}});
|
|
452
|
+
horizontalScroll.props.onContentSizeChange(600, 200);
|
|
453
|
+
horizontalScroll.props.onScroll({nativeEvent: {contentOffset: {x: 120}}});
|
|
454
|
+
});
|
|
455
|
+
|
|
456
|
+
const scrolledStyles = [
|
|
457
|
+
...tree.root.findAllByType('View'),
|
|
458
|
+
...tree.root.findAllByType('TouchableOpacity'),
|
|
459
|
+
].map(node => flattenStyle(node.props.style));
|
|
460
|
+
|
|
461
|
+
expect(scrolledStyles).toEqual(
|
|
462
|
+
expect.arrayContaining([
|
|
463
|
+
expect.objectContaining({transform: [{translateX: 120}]}),
|
|
464
|
+
]),
|
|
465
|
+
);
|
|
466
|
+
expect(scrolledStyles).not.toEqual(
|
|
467
|
+
expect.arrayContaining([
|
|
468
|
+
expect.objectContaining({transform: [{translateX: -180}]}),
|
|
469
|
+
]),
|
|
470
|
+
);
|
|
471
|
+
});
|
|
472
|
+
|
|
473
|
+
it('keeps the complete search aligned in the toolbar when there is enough room', () => {
|
|
474
|
+
mockWindowDimensions = {width: 430, height: 932};
|
|
475
|
+
mockStores.orders = {
|
|
476
|
+
actions: {},
|
|
477
|
+
getters: {
|
|
478
|
+
columns: [{key: 'name', label: 'Nome', searchable: true}],
|
|
479
|
+
},
|
|
480
|
+
};
|
|
481
|
+
let tree;
|
|
482
|
+
|
|
483
|
+
renderer.act(() => {
|
|
484
|
+
tree = renderer.create(
|
|
485
|
+
React.createElement(DefaultTable, {
|
|
486
|
+
columns: [{key: 'name', label: 'Nome'}],
|
|
487
|
+
data: [],
|
|
488
|
+
storeName: 'orders',
|
|
489
|
+
}),
|
|
490
|
+
);
|
|
491
|
+
});
|
|
492
|
+
|
|
493
|
+
expect(tree.root.findAllByType('DefaultSearch')).toHaveLength(1);
|
|
494
|
+
expect(tree.root.findAllByType('icon').map(node => node.props.name)).not.toContain('search');
|
|
495
|
+
});
|
|
496
|
+
|
|
497
|
+
it('hides the toolbar when the screen disables it', () => {
|
|
498
|
+
mockWindowDimensions = {width: 430, height: 932};
|
|
499
|
+
mockStores.orders = {
|
|
500
|
+
actions: {},
|
|
501
|
+
getters: {
|
|
502
|
+
columns: [{key: 'name', label: 'Nome', searchable: true}],
|
|
503
|
+
},
|
|
504
|
+
};
|
|
505
|
+
let tree;
|
|
506
|
+
|
|
507
|
+
renderer.act(() => {
|
|
508
|
+
tree = renderer.create(
|
|
509
|
+
React.createElement(DefaultTable, {
|
|
510
|
+
columns: [{key: 'name', label: 'Nome', searchable: true}],
|
|
511
|
+
data: [],
|
|
512
|
+
showToolbar: false,
|
|
513
|
+
storeName: 'orders',
|
|
514
|
+
}),
|
|
515
|
+
);
|
|
516
|
+
});
|
|
517
|
+
|
|
518
|
+
expect(tree.root.findAllByType('DefaultSearch')).toHaveLength(0);
|
|
519
|
+
expect(tree.root.findAllByType('icon').map(node => node.props.name)).not.toEqual(
|
|
520
|
+
expect.arrayContaining(['columns', 'grid', 'list', 'search']),
|
|
521
|
+
);
|
|
522
|
+
});
|
|
523
|
+
|
|
524
|
+
it('keeps add available as a floating button when the toolbar is hidden', () => {
|
|
525
|
+
const onAdd = jest.fn();
|
|
526
|
+
mockWindowDimensions = {width: 430, height: 932};
|
|
527
|
+
mockStores.orders = {
|
|
528
|
+
actions: {},
|
|
529
|
+
getters: {
|
|
530
|
+
add: true,
|
|
531
|
+
columns: [{key: 'name', label: 'Nome', searchable: true}],
|
|
532
|
+
},
|
|
533
|
+
};
|
|
534
|
+
let tree;
|
|
535
|
+
|
|
536
|
+
renderer.act(() => {
|
|
537
|
+
tree = renderer.create(
|
|
538
|
+
React.createElement(DefaultTable, {
|
|
539
|
+
columns: [{key: 'name', label: 'Nome', searchable: true}],
|
|
540
|
+
data: [],
|
|
541
|
+
onAdd,
|
|
542
|
+
showToolbar: false,
|
|
543
|
+
storeName: 'orders',
|
|
544
|
+
}),
|
|
545
|
+
);
|
|
546
|
+
});
|
|
547
|
+
|
|
548
|
+
const addButton = tree.root
|
|
549
|
+
.findAllByType('TouchableOpacity')
|
|
550
|
+
.find(node => node.findAllByType('icon').some(icon => icon.props.name === 'plus'));
|
|
551
|
+
|
|
552
|
+
expect(addButton).toBeTruthy();
|
|
553
|
+
expect(addButton.props.accessibilityRole).toBe('button');
|
|
554
|
+
expect(addButton.props.accessibilityLabel).toBe('Adicionar');
|
|
555
|
+
|
|
556
|
+
renderer.act(() => addButton.props.onPress());
|
|
557
|
+
|
|
558
|
+
expect(onAdd).toHaveBeenCalledTimes(1);
|
|
559
|
+
});
|
|
560
|
+
|
|
561
|
+
it('collapses search into an icon on narrow toolbars and opens the search modal', () => {
|
|
562
|
+
mockWindowDimensions = {width: 375, height: 667};
|
|
563
|
+
mockStores.orders = {
|
|
564
|
+
actions: {},
|
|
565
|
+
getters: {
|
|
566
|
+
columns: [{key: 'name', label: 'Nome', searchable: true}],
|
|
567
|
+
},
|
|
568
|
+
};
|
|
569
|
+
let tree;
|
|
570
|
+
|
|
571
|
+
renderer.act(() => {
|
|
572
|
+
tree = renderer.create(
|
|
573
|
+
React.createElement(DefaultTable, {
|
|
574
|
+
columns: [{key: 'name', label: 'Nome'}],
|
|
575
|
+
data: [],
|
|
576
|
+
storeName: 'orders',
|
|
577
|
+
}),
|
|
578
|
+
);
|
|
579
|
+
});
|
|
580
|
+
|
|
581
|
+
expect(tree.root.findAllByType('DefaultSearch')).toHaveLength(0);
|
|
582
|
+
const searchButton = tree.root
|
|
583
|
+
.findAllByType('TouchableOpacity')
|
|
584
|
+
.find(node => node.findAllByType('icon').some(icon => icon.props.name === 'search'));
|
|
585
|
+
|
|
586
|
+
expect(searchButton.props.accessibilityRole).toBe('button');
|
|
587
|
+
expect(searchButton.props.accessibilityLabel).toBe('Buscar');
|
|
588
|
+
|
|
589
|
+
renderer.act(() => searchButton.props.onPress());
|
|
590
|
+
|
|
591
|
+
expect(tree.root.findAllByType('DefaultSearch')).toHaveLength(1);
|
|
592
|
+
expect(tree.root.findByType('DefaultSearch').props.autoFocus).toBe(true);
|
|
593
|
+
});
|
|
594
|
+
|
|
595
|
+
it('gives collapsed search a stable accessible name without a placeholder', () => {
|
|
596
|
+
mockWindowDimensions = {width: 375, height: 667};
|
|
597
|
+
mockStores.orders = {
|
|
598
|
+
actions: {},
|
|
599
|
+
getters: {
|
|
600
|
+
columns: [{key: 'name', label: 'Nome', searchable: true}],
|
|
601
|
+
},
|
|
602
|
+
};
|
|
603
|
+
let tree;
|
|
604
|
+
|
|
605
|
+
renderer.act(() => {
|
|
606
|
+
tree = renderer.create(
|
|
607
|
+
React.createElement(DefaultTable, {
|
|
608
|
+
columns: [{key: 'name', label: 'Nome'}],
|
|
609
|
+
data: [],
|
|
610
|
+
storeName: 'orders',
|
|
611
|
+
}),
|
|
612
|
+
);
|
|
613
|
+
});
|
|
614
|
+
|
|
615
|
+
const searchButton = tree.root
|
|
616
|
+
.findAllByType('TouchableOpacity')
|
|
617
|
+
.find(node => node.findAllByType('icon').some(icon => icon.props.name === 'search'));
|
|
618
|
+
|
|
619
|
+
expect(searchButton.props.accessibilityRole).toBe('button');
|
|
620
|
+
expect(searchButton.props.accessibilityLabel).toBe('Buscar');
|
|
621
|
+
});
|
|
622
|
+
|
|
623
|
+
it('keeps the financial compact toolbar aligned when the total is already in the footer', () => {
|
|
624
|
+
mockWindowDimensions = {width: 375, height: 667};
|
|
625
|
+
mockStores.orders = {
|
|
626
|
+
actions: {},
|
|
627
|
+
getters: {
|
|
628
|
+
columns: [{key: 'name', label: 'Nome', searchable: true}],
|
|
629
|
+
totalItems: 27,
|
|
630
|
+
},
|
|
631
|
+
};
|
|
632
|
+
let tree;
|
|
633
|
+
|
|
634
|
+
renderer.act(() => {
|
|
635
|
+
tree = renderer.create(
|
|
636
|
+
React.createElement(DefaultTable, {
|
|
637
|
+
columns: [{key: 'name', label: 'Nome'}],
|
|
638
|
+
data: [],
|
|
639
|
+
showTotalItemsInCompactToolbar: true,
|
|
640
|
+
showTotalItemsInFooter: true,
|
|
641
|
+
storeName: 'orders',
|
|
642
|
+
}),
|
|
643
|
+
);
|
|
644
|
+
});
|
|
645
|
+
|
|
646
|
+
const iconNames = tree.root.findAllByType('icon').map(node => node.props.name);
|
|
647
|
+
|
|
648
|
+
expect(tree.root.findAllByType('DefaultSearch')).toHaveLength(0);
|
|
649
|
+
expect(iconNames).toEqual(expect.arrayContaining(['search', 'filter', 'list', 'columns']));
|
|
650
|
+
expect(
|
|
651
|
+
tree.root.findAllByType('Text').filter(node => node.props.children === '27 registros'),
|
|
652
|
+
).toHaveLength(1);
|
|
653
|
+
});
|
|
654
|
+
|
|
655
|
+
it('opens the filters modal with filterable columns only', () => {
|
|
656
|
+
mockWindowDimensions = {width: 375, height: 667};
|
|
657
|
+
mockStores.orders = {
|
|
658
|
+
actions: {},
|
|
659
|
+
getters: {
|
|
660
|
+
columns: [
|
|
661
|
+
{key: 'name', label: 'Nome'},
|
|
662
|
+
{key: 'ignored', label: 'Ignorado', filter: false},
|
|
663
|
+
{
|
|
664
|
+
key: 'status',
|
|
665
|
+
label: 'Status',
|
|
666
|
+
list: [{value: 'pos', label: 'POS'}],
|
|
667
|
+
},
|
|
668
|
+
],
|
|
669
|
+
filters: {},
|
|
670
|
+
},
|
|
671
|
+
};
|
|
672
|
+
let tree;
|
|
673
|
+
|
|
674
|
+
renderer.act(() => {
|
|
675
|
+
tree = renderer.create(
|
|
676
|
+
React.createElement(DefaultTable, {
|
|
677
|
+
data: [],
|
|
678
|
+
storeName: 'orders',
|
|
679
|
+
}),
|
|
680
|
+
);
|
|
681
|
+
});
|
|
682
|
+
|
|
683
|
+
expect(tree.root.findAllByType('DefaultColumnFilter')).toHaveLength(0);
|
|
684
|
+
const filterButton = tree.root
|
|
685
|
+
.findAllByType('TouchableOpacity')
|
|
686
|
+
.find(node => node.findAllByType('icon').some(icon => icon.props.name === 'filter'));
|
|
687
|
+
|
|
688
|
+
renderer.act(() => filterButton.props.onPress());
|
|
689
|
+
|
|
690
|
+
expect(tree.root.findAllByType('DefaultColumnFilter')).toHaveLength(2);
|
|
691
|
+
expect(mockCapturedColumnFilterProps.map(props => props.column.key)).toEqual(['name', 'status']);
|
|
692
|
+
});
|
|
693
|
+
|
|
694
|
+
it('persists filters and sort under default-table[store][route]', () => {
|
|
695
|
+
const setFilters = jest.fn();
|
|
696
|
+
mockWindowDimensions = {width: 1024, height: 800};
|
|
697
|
+
mockStores.orders = {
|
|
698
|
+
actions: {
|
|
699
|
+
setFilters,
|
|
700
|
+
},
|
|
701
|
+
getters: {
|
|
702
|
+
columns: [
|
|
703
|
+
{key: 'status', label: 'Status', sortable: true},
|
|
704
|
+
{key: 'price', label: 'Preco'},
|
|
705
|
+
],
|
|
706
|
+
filters: {},
|
|
707
|
+
},
|
|
708
|
+
};
|
|
709
|
+
|
|
710
|
+
let tree;
|
|
711
|
+
|
|
712
|
+
renderer.act(() => {
|
|
713
|
+
tree = renderer.create(
|
|
714
|
+
React.createElement(DefaultTable, {
|
|
715
|
+
storeName: 'orders',
|
|
716
|
+
}),
|
|
717
|
+
);
|
|
718
|
+
});
|
|
719
|
+
|
|
720
|
+
const filterButton = tree.root
|
|
721
|
+
.findAllByType('TouchableOpacity')
|
|
722
|
+
.find(node => node.findAllByType('icon').some(icon => icon.props.name === 'filter'));
|
|
723
|
+
|
|
724
|
+
renderer.act(() => filterButton.props.onPress());
|
|
725
|
+
|
|
726
|
+
const statusFilterProps = mockCapturedColumnFilterProps
|
|
727
|
+
.find(props => props.column.key === 'status');
|
|
728
|
+
|
|
729
|
+
renderer.act(() => {
|
|
730
|
+
statusFilterProps.onChange('status', 'paid');
|
|
731
|
+
});
|
|
732
|
+
|
|
733
|
+
const statusHeader = tree.root
|
|
734
|
+
.findAllByType('TouchableOpacity')
|
|
735
|
+
.find(node => node.findAllByType('Text').some(text => text.props.children === 'Status'));
|
|
736
|
+
|
|
737
|
+
renderer.act(() => {
|
|
738
|
+
statusHeader.props.onPress();
|
|
739
|
+
});
|
|
740
|
+
|
|
741
|
+
expect(setFilters).toHaveBeenCalledWith({status: 'paid'});
|
|
742
|
+
expect(
|
|
743
|
+
JSON.parse(
|
|
744
|
+
global.localStorage.getItem(DEFAULT_TABLE_PREFERENCES_STORAGE_KEY),
|
|
745
|
+
),
|
|
746
|
+
).toEqual({
|
|
747
|
+
orders: {
|
|
748
|
+
OrderHistoryPage: {
|
|
749
|
+
filters: {
|
|
750
|
+
status: 'paid',
|
|
751
|
+
},
|
|
752
|
+
sort: {
|
|
753
|
+
direction: 'asc',
|
|
754
|
+
field: 'status',
|
|
755
|
+
},
|
|
756
|
+
},
|
|
757
|
+
},
|
|
758
|
+
});
|
|
759
|
+
});
|
|
760
|
+
|
|
761
|
+
it('hydrates the saved sort using a stable preference key on auto tables', async () => {
|
|
762
|
+
const getItems = jest.fn(() => Promise.resolve([]));
|
|
763
|
+
reactNavigation.useIsFocused.mockImplementation(() => true);
|
|
764
|
+
global.localStorage.setItem(
|
|
765
|
+
DEFAULT_TABLE_PREFERENCES_STORAGE_KEY,
|
|
766
|
+
JSON.stringify({
|
|
767
|
+
orders: {
|
|
768
|
+
'order-history-page': {
|
|
769
|
+
sort: {
|
|
770
|
+
direction: 'desc',
|
|
771
|
+
field: 'status',
|
|
772
|
+
},
|
|
773
|
+
},
|
|
774
|
+
},
|
|
775
|
+
}),
|
|
776
|
+
);
|
|
777
|
+
mockStores.orders = {
|
|
778
|
+
actions: {
|
|
779
|
+
getItems,
|
|
780
|
+
},
|
|
781
|
+
getters: {
|
|
782
|
+
columns: [
|
|
783
|
+
{key: 'status', label: 'Status', sortable: true},
|
|
784
|
+
{key: 'price', label: 'Preco'},
|
|
785
|
+
],
|
|
786
|
+
filters: {},
|
|
787
|
+
items: [],
|
|
788
|
+
},
|
|
789
|
+
};
|
|
790
|
+
|
|
791
|
+
await renderer.act(async () => {
|
|
792
|
+
renderer.create(
|
|
793
|
+
React.createElement(DefaultTable, {
|
|
794
|
+
storeName: 'orders',
|
|
795
|
+
visibleColumnsPreferenceKey: 'order-history-page',
|
|
796
|
+
}),
|
|
797
|
+
);
|
|
798
|
+
await Promise.resolve();
|
|
799
|
+
});
|
|
800
|
+
|
|
801
|
+
expect(getItems).toHaveBeenCalledWith(
|
|
802
|
+
expect.objectContaining({
|
|
803
|
+
'order[status]': 'desc',
|
|
804
|
+
itemsPerPage: 50,
|
|
805
|
+
page: 1,
|
|
806
|
+
}),
|
|
807
|
+
);
|
|
808
|
+
});
|
|
809
|
+
|
|
810
|
+
it('hydrates and persists controlled filters under default-table[store][route]', () => {
|
|
811
|
+
const onFilterChange = jest.fn();
|
|
812
|
+
const setFilters = jest.fn();
|
|
813
|
+
global.location = {pathname: '/product-showcases-page'};
|
|
814
|
+
global.localStorage.setItem(
|
|
815
|
+
DEFAULT_TABLE_PREFERENCES_STORAGE_KEY,
|
|
816
|
+
JSON.stringify({
|
|
817
|
+
product_showcase_items: {
|
|
818
|
+
'product-showcases-page': {
|
|
819
|
+
filters: {
|
|
820
|
+
integration: 'pos',
|
|
821
|
+
},
|
|
822
|
+
},
|
|
823
|
+
},
|
|
824
|
+
}),
|
|
825
|
+
);
|
|
826
|
+
mockStores.product_showcase_items = {
|
|
827
|
+
actions: {
|
|
828
|
+
setFilters,
|
|
829
|
+
},
|
|
830
|
+
getters: {
|
|
831
|
+
columns: [
|
|
832
|
+
{key: 'integration', label: 'Integration', externalFilter: true},
|
|
833
|
+
{key: 'price', label: 'Price'},
|
|
834
|
+
],
|
|
835
|
+
filters: {},
|
|
836
|
+
},
|
|
837
|
+
};
|
|
838
|
+
|
|
839
|
+
let tree;
|
|
840
|
+
|
|
841
|
+
renderer.act(() => {
|
|
842
|
+
tree = renderer.create(
|
|
843
|
+
React.createElement(DefaultTable, {
|
|
844
|
+
filters: {},
|
|
845
|
+
onFilterChange,
|
|
846
|
+
storeName: 'product_showcase_items',
|
|
847
|
+
}),
|
|
848
|
+
);
|
|
849
|
+
});
|
|
850
|
+
|
|
851
|
+
expect(onFilterChange).toHaveBeenCalledWith({integration: 'pos'});
|
|
852
|
+
|
|
853
|
+
renderer.act(() => {
|
|
854
|
+
tree.update(
|
|
855
|
+
React.createElement(DefaultTable, {
|
|
856
|
+
filters: {integration: 'ifood'},
|
|
857
|
+
onFilterChange,
|
|
858
|
+
storeName: 'product_showcase_items',
|
|
859
|
+
}),
|
|
860
|
+
);
|
|
861
|
+
});
|
|
862
|
+
|
|
863
|
+
expect(
|
|
864
|
+
JSON.parse(
|
|
865
|
+
global.localStorage.getItem(DEFAULT_TABLE_PREFERENCES_STORAGE_KEY),
|
|
866
|
+
),
|
|
867
|
+
).toEqual({
|
|
868
|
+
product_showcase_items: {
|
|
869
|
+
'product-showcases-page': {
|
|
870
|
+
filters: {
|
|
871
|
+
integration: 'ifood',
|
|
872
|
+
},
|
|
873
|
+
},
|
|
874
|
+
},
|
|
875
|
+
});
|
|
876
|
+
|
|
877
|
+
delete global.location;
|
|
878
|
+
});
|
|
879
|
+
|
|
880
|
+
it('preserves the compact toolbar total when the footer total is disabled', () => {
|
|
881
|
+
mockWindowDimensions = {width: 375, height: 667};
|
|
882
|
+
mockStores.orders = {
|
|
883
|
+
actions: {},
|
|
884
|
+
getters: {
|
|
885
|
+
totalItems: 27,
|
|
886
|
+
},
|
|
887
|
+
};
|
|
888
|
+
let tree;
|
|
889
|
+
|
|
890
|
+
renderer.act(() => {
|
|
891
|
+
tree = renderer.create(
|
|
892
|
+
React.createElement(DefaultTable, {
|
|
893
|
+
columns: [{key: 'name', label: 'Nome'}],
|
|
894
|
+
data: [],
|
|
895
|
+
showTotalItemsInCompactToolbar: true,
|
|
896
|
+
showTotalItemsInFooter: false,
|
|
897
|
+
storeName: 'orders',
|
|
898
|
+
}),
|
|
899
|
+
);
|
|
900
|
+
});
|
|
901
|
+
|
|
902
|
+
expect(tree.root.findAllByType('Text').map(node => node.props.children)).toContain('27 registros');
|
|
903
|
+
});
|
|
904
|
+
|
|
905
|
+
it('forces cards when entering compact mode and still toggles between cards and list', () => {
|
|
906
|
+
const props = {
|
|
907
|
+
columns: [{key: 'name', label: 'Nome'}],
|
|
908
|
+
data: [{id: 1, name: 'Pedido 1'}],
|
|
909
|
+
showColumnFiltersButton: false,
|
|
910
|
+
};
|
|
911
|
+
let tree;
|
|
912
|
+
|
|
913
|
+
mockWindowDimensions = {width: 1024, height: 800};
|
|
914
|
+
|
|
915
|
+
renderer.act(() => {
|
|
916
|
+
tree = renderer.create(
|
|
917
|
+
React.createElement(DefaultTable, props),
|
|
918
|
+
);
|
|
919
|
+
});
|
|
920
|
+
|
|
921
|
+
expect(tree.root.findAllByType('ScrollView')).toHaveLength(1);
|
|
922
|
+
|
|
923
|
+
mockWindowDimensions = {width: 480, height: 800};
|
|
924
|
+
|
|
925
|
+
renderer.act(() => {
|
|
926
|
+
tree.update(React.createElement(DefaultTable, props));
|
|
927
|
+
});
|
|
928
|
+
|
|
929
|
+
expect(tree.root.findAllByType('ScrollView')).toHaveLength(0);
|
|
930
|
+
expect(tree.root.findByProps({name: 'grid'})).toBeTruthy();
|
|
931
|
+
|
|
932
|
+
renderer.act(() => {
|
|
933
|
+
tree.root.findByProps({name: 'grid'}).parent.props.onPress();
|
|
934
|
+
tree.update(React.createElement(DefaultTable, props));
|
|
935
|
+
});
|
|
936
|
+
|
|
937
|
+
expect(tree.root.findAllByType('ScrollView')).toHaveLength(1);
|
|
938
|
+
expect(tree.root.findByProps({name: 'list'})).toBeTruthy();
|
|
939
|
+
|
|
940
|
+
renderer.act(() => {
|
|
941
|
+
tree.root.findByProps({name: 'list'}).parent.props.onPress();
|
|
942
|
+
tree.update(React.createElement(DefaultTable, props));
|
|
943
|
+
});
|
|
944
|
+
|
|
945
|
+
expect(tree.root.findAllByType('ScrollView')).toHaveLength(0);
|
|
946
|
+
expect(tree.root.findByProps({name: 'grid'})).toBeTruthy();
|
|
947
|
+
});
|
|
948
|
+
|
|
949
|
+
it('applies a custom rowStyle to rendered table rows', () => {
|
|
950
|
+
let tree;
|
|
951
|
+
const rowStyle = jest.fn(() => ({
|
|
952
|
+
borderLeftColor: '#DC2626',
|
|
953
|
+
borderLeftWidth: 4,
|
|
954
|
+
}));
|
|
955
|
+
|
|
956
|
+
mockWindowDimensions = {width: 1024, height: 800};
|
|
957
|
+
|
|
958
|
+
renderer.act(() => {
|
|
959
|
+
tree = renderer.create(
|
|
960
|
+
React.createElement(DefaultTable, {
|
|
961
|
+
columns: [{key: 'name', label: 'Nome'}],
|
|
962
|
+
data: [{id: 1, name: 'Pedido 1'}],
|
|
963
|
+
onRowPress: () => {},
|
|
964
|
+
rowStyle,
|
|
965
|
+
showColumnFiltersButton: false,
|
|
966
|
+
}),
|
|
967
|
+
);
|
|
968
|
+
});
|
|
969
|
+
|
|
970
|
+
const row = tree.root
|
|
971
|
+
.findAllByType('TouchableOpacity')
|
|
972
|
+
.find(node => node.props?.activeOpacity === 0.84);
|
|
973
|
+
|
|
974
|
+
expect(rowStyle).toHaveBeenCalledWith(
|
|
975
|
+
expect.objectContaining({id: 1, name: 'Pedido 1'}),
|
|
976
|
+
0,
|
|
977
|
+
);
|
|
978
|
+
expect(Array.isArray(row.props.style)).toBe(true);
|
|
979
|
+
expect(
|
|
980
|
+
row.props.style.some(
|
|
981
|
+
style => style && style.borderLeftWidth === 4 && style.borderLeftColor === '#DC2626',
|
|
982
|
+
),
|
|
983
|
+
).toBe(true);
|
|
984
|
+
});
|
|
985
|
+
|
|
986
|
+
it('blocks row navigation while an inline cell is editing or saving', async () => {
|
|
987
|
+
let resolveSave;
|
|
988
|
+
const onRowPress = jest.fn();
|
|
989
|
+
const save = jest.fn(() => new Promise(resolve => {
|
|
990
|
+
resolveSave = resolve;
|
|
991
|
+
}));
|
|
992
|
+
let tree;
|
|
993
|
+
|
|
994
|
+
mockWindowDimensions = {width: 1024, height: 800};
|
|
995
|
+
|
|
996
|
+
renderer.act(() => {
|
|
997
|
+
tree = renderer.create(
|
|
998
|
+
React.createElement(DefaultTable, {
|
|
999
|
+
actions: {save},
|
|
1000
|
+
columns: [{key: 'name', label: 'Nome', editable: true}],
|
|
1001
|
+
data: [{id: 1, name: 'Cliente'}],
|
|
1002
|
+
onRowPress,
|
|
1003
|
+
showColumnFiltersButton: false,
|
|
1004
|
+
showRowActions: false,
|
|
1005
|
+
}),
|
|
1006
|
+
);
|
|
1007
|
+
});
|
|
1008
|
+
|
|
1009
|
+
const findRow = () => tree.root
|
|
1010
|
+
.findAllByType('TouchableOpacity')
|
|
1011
|
+
.find(node => node.props?.activeOpacity === 0.84);
|
|
1012
|
+
const latestInput = () => mockCapturedDefaultInputProps[mockCapturedDefaultInputProps.length - 1];
|
|
1013
|
+
|
|
1014
|
+
renderer.act(() => {
|
|
1015
|
+
findRow().props.onPress();
|
|
1016
|
+
});
|
|
1017
|
+
expect(onRowPress).toHaveBeenCalledTimes(1);
|
|
1018
|
+
onRowPress.mockClear();
|
|
1019
|
+
|
|
1020
|
+
renderer.act(() => {
|
|
1021
|
+
latestInput().onStartEditing();
|
|
1022
|
+
});
|
|
1023
|
+
renderer.act(() => {
|
|
1024
|
+
findRow().props.onPress();
|
|
1025
|
+
});
|
|
1026
|
+
expect(onRowPress).not.toHaveBeenCalled();
|
|
1027
|
+
|
|
1028
|
+
let savePromise;
|
|
1029
|
+
renderer.act(() => {
|
|
1030
|
+
savePromise = latestInput().onSave('Cliente alterado');
|
|
1031
|
+
});
|
|
1032
|
+
renderer.act(() => {
|
|
1033
|
+
latestInput().onCancelEditing();
|
|
1034
|
+
});
|
|
1035
|
+
renderer.act(() => {
|
|
1036
|
+
findRow().props.onPress();
|
|
1037
|
+
});
|
|
1038
|
+
expect(onRowPress).not.toHaveBeenCalled();
|
|
1039
|
+
|
|
1040
|
+
await renderer.act(async () => {
|
|
1041
|
+
resolveSave({id: 1, name: 'Cliente alterado'});
|
|
1042
|
+
await savePromise;
|
|
1043
|
+
});
|
|
1044
|
+
|
|
1045
|
+
renderer.act(() => {
|
|
1046
|
+
findRow().props.onPress();
|
|
1047
|
+
});
|
|
1048
|
+
expect(onRowPress).toHaveBeenCalledTimes(1);
|
|
1049
|
+
});
|
|
1050
|
+
|
|
1051
|
+
it('protects custom card openRow while a card field is editing', () => {
|
|
1052
|
+
const onRowPress = jest.fn();
|
|
1053
|
+
let tree;
|
|
1054
|
+
|
|
1055
|
+
renderer.act(() => {
|
|
1056
|
+
tree = renderer.create(
|
|
1057
|
+
React.createElement(DefaultTable, {
|
|
1058
|
+
columns: [{key: 'name', label: 'Nome', editable: true}],
|
|
1059
|
+
data: [{id: 1, name: 'Cliente'}],
|
|
1060
|
+
onRowPress,
|
|
1061
|
+
renderCard: ({openRow, renderField}) => React.createElement(
|
|
1062
|
+
'CustomCard',
|
|
1063
|
+
{openRow},
|
|
1064
|
+
renderField('name'),
|
|
1065
|
+
),
|
|
1066
|
+
showColumnFiltersButton: false,
|
|
1067
|
+
showRowActions: false,
|
|
1068
|
+
}),
|
|
1069
|
+
);
|
|
1070
|
+
});
|
|
1071
|
+
|
|
1072
|
+
const latestInput = () => mockCapturedDefaultInputProps[mockCapturedDefaultInputProps.length - 1];
|
|
1073
|
+
|
|
1074
|
+
renderer.act(() => {
|
|
1075
|
+
latestInput().onStartEditing();
|
|
1076
|
+
});
|
|
1077
|
+
renderer.act(() => {
|
|
1078
|
+
tree.root.findByType('CustomCard').props.openRow();
|
|
1079
|
+
});
|
|
1080
|
+
expect(onRowPress).not.toHaveBeenCalled();
|
|
1081
|
+
|
|
1082
|
+
renderer.act(() => {
|
|
1083
|
+
latestInput().onCancelEditing();
|
|
1084
|
+
});
|
|
1085
|
+
renderer.act(() => {
|
|
1086
|
+
tree.root.findByType('CustomCard').props.openRow();
|
|
1087
|
+
});
|
|
1088
|
+
expect(onRowPress).toHaveBeenCalledTimes(1);
|
|
1089
|
+
});
|
|
1090
|
+
|
|
1091
|
+
it('renders a custom footer component when provided', () => {
|
|
1092
|
+
let tree;
|
|
1093
|
+
mockStores.orders = {
|
|
1094
|
+
actions: {},
|
|
1095
|
+
getters: {
|
|
1096
|
+
totalItems: 7,
|
|
1097
|
+
},
|
|
1098
|
+
};
|
|
1099
|
+
|
|
1100
|
+
const FooterComponent = props =>
|
|
1101
|
+
React.createElement('CustomFooter', {
|
|
1102
|
+
resolvedTotalItemsText: props.resolvedTotalItemsText,
|
|
1103
|
+
});
|
|
1104
|
+
|
|
1105
|
+
mockWindowDimensions = {width: 1024, height: 800};
|
|
1106
|
+
|
|
1107
|
+
renderer.act(() => {
|
|
1108
|
+
tree = renderer.create(
|
|
1109
|
+
React.createElement(DefaultTable, {
|
|
1110
|
+
columns: [{key: 'name', label: 'Nome'}],
|
|
1111
|
+
data: [{id: 1, name: 'Pedido 1'}],
|
|
1112
|
+
footerComponent: FooterComponent,
|
|
1113
|
+
showColumnFiltersButton: false,
|
|
1114
|
+
storeName: 'orders',
|
|
1115
|
+
}),
|
|
1116
|
+
);
|
|
1117
|
+
});
|
|
1118
|
+
|
|
1119
|
+
const footer = tree.root.findByType('CustomFooter');
|
|
1120
|
+
|
|
1121
|
+
expect(footer.props.resolvedTotalItemsText).toBe('7 registros');
|
|
1122
|
+
});
|
|
1123
|
+
|
|
1124
|
+
it('keeps infinite scroll loading transparent over existing rows', () => {
|
|
1125
|
+
let tree;
|
|
1126
|
+
const getItems = jest.fn(() => Promise.resolve({member: []}));
|
|
1127
|
+
mockWindowDimensions = {width: 1024, height: 800};
|
|
1128
|
+
mockStores.invoices = {
|
|
1129
|
+
actions: {
|
|
1130
|
+
getItems,
|
|
1131
|
+
},
|
|
1132
|
+
getters: {
|
|
1133
|
+
columns: [{key: 'status', label: 'Situação'}],
|
|
1134
|
+
items: [{id: 332, status: 'Pago'}],
|
|
1135
|
+
totalItems: 1394,
|
|
1136
|
+
},
|
|
1137
|
+
};
|
|
1138
|
+
|
|
1139
|
+
renderer.act(() => {
|
|
1140
|
+
tree = renderer.create(
|
|
1141
|
+
React.createElement(DefaultTable, {
|
|
1142
|
+
showColumnFiltersButton: false,
|
|
1143
|
+
showRowActions: false,
|
|
1144
|
+
storeName: 'invoices',
|
|
1145
|
+
}),
|
|
1146
|
+
);
|
|
1147
|
+
});
|
|
1148
|
+
|
|
1149
|
+
expect(tree.root.findAllByType('StateStore')).toHaveLength(0);
|
|
1150
|
+
const flatList = tree.root.findByType('FlatList');
|
|
1151
|
+
expect(flatList.props.onEndReachedThreshold).toBeGreaterThanOrEqual(0.75);
|
|
1152
|
+
expect(tree.root.findByType('ScrollView').props.contentContainerStyle).toEqual(
|
|
1153
|
+
expect.objectContaining({minWidth: '100%'}),
|
|
1154
|
+
);
|
|
1155
|
+
|
|
1156
|
+
renderer.act(() => {
|
|
1157
|
+
flatList.props.onScroll({
|
|
1158
|
+
nativeEvent: {
|
|
1159
|
+
contentOffset: {y: 650},
|
|
1160
|
+
contentSize: {height: 1200},
|
|
1161
|
+
layoutMeasurement: {height: 400},
|
|
1162
|
+
},
|
|
1163
|
+
});
|
|
1164
|
+
});
|
|
1165
|
+
|
|
1166
|
+
expect(getItems).toHaveBeenCalledWith(expect.objectContaining({append: true}));
|
|
1167
|
+
});
|
|
1168
|
+
|
|
1169
|
+
it('uses the configured summary and labels before the store summary', () => {
|
|
1170
|
+
let tree;
|
|
1171
|
+
mockWindowDimensions = {width: 1024, height: 800};
|
|
1172
|
+
mockStores.invoice = {
|
|
1173
|
+
actions: {},
|
|
1174
|
+
getters: {
|
|
1175
|
+
summary: {
|
|
1176
|
+
financial: {
|
|
1177
|
+
paidAmount: 0,
|
|
1178
|
+
},
|
|
1179
|
+
},
|
|
1180
|
+
totalItems: 1,
|
|
1181
|
+
},
|
|
1182
|
+
};
|
|
1183
|
+
|
|
1184
|
+
renderer.act(() => {
|
|
1185
|
+
tree = renderer.create(
|
|
1186
|
+
React.createElement(DefaultTable, {
|
|
1187
|
+
columns: [{key: 'status', label: 'Situação'}],
|
|
1188
|
+
data: [{id: 332, status: 'Pago'}],
|
|
1189
|
+
showColumnFiltersButton: false,
|
|
1190
|
+
showRowActions: false,
|
|
1191
|
+
storeName: 'invoice',
|
|
1192
|
+
summary: {
|
|
1193
|
+
financial: {
|
|
1194
|
+
paidAmount: 80.25,
|
|
1195
|
+
},
|
|
1196
|
+
},
|
|
1197
|
+
summaryLabels: {
|
|
1198
|
+
'financial.paidAmount': 'Valor pago',
|
|
1199
|
+
},
|
|
1200
|
+
}),
|
|
1201
|
+
);
|
|
1202
|
+
});
|
|
1203
|
+
|
|
1204
|
+
const textValues = tree.root.findAllByType('Text').map(node => node.props.children);
|
|
1205
|
+
expect(textValues).toContain('Valor pago');
|
|
1206
|
+
expect(textValues).toContain('R$ 80,25');
|
|
1207
|
+
});
|
|
1208
|
+
|
|
1209
|
+
it('opens a debug query modal when the store exposes debug.query', () => {
|
|
1210
|
+
mockWindowDimensions = {width: 1024, height: 800};
|
|
1211
|
+
mockStores.orders = {
|
|
1212
|
+
actions: {},
|
|
1213
|
+
getters: {
|
|
1214
|
+
columns: [{key: 'id', label: 'ID'}],
|
|
1215
|
+
debug: {
|
|
1216
|
+
interpolatedQuery: "SELECT * FROM orders WHERE provider_id = '2'",
|
|
1217
|
+
query: 'SELECT * FROM orders WHERE provider_id = 2',
|
|
1218
|
+
},
|
|
1219
|
+
filters: {
|
|
1220
|
+
provider: '/people/2',
|
|
1221
|
+
},
|
|
1222
|
+
items: [],
|
|
1223
|
+
},
|
|
1224
|
+
};
|
|
1225
|
+
|
|
1226
|
+
let tree;
|
|
1227
|
+
|
|
1228
|
+
renderer.act(() => {
|
|
1229
|
+
tree = renderer.create(
|
|
1230
|
+
React.createElement(DefaultTable, {
|
|
1231
|
+
requestParams: {itemsPerPage: 50},
|
|
1232
|
+
storeName: 'orders',
|
|
1233
|
+
}),
|
|
1234
|
+
);
|
|
1235
|
+
});
|
|
1236
|
+
|
|
1237
|
+
const debugButton = tree.root
|
|
1238
|
+
.findAllByType('TouchableOpacity')
|
|
1239
|
+
.find(node => node.props.accessibilityLabel === 'Debug query');
|
|
1240
|
+
|
|
1241
|
+
expect(debugButton).toBeTruthy();
|
|
1242
|
+
|
|
1243
|
+
renderer.act(() => debugButton.props.onPress());
|
|
1244
|
+
|
|
1245
|
+
const textValues = tree.root.findAllByType('Text').map(node => node.props.children);
|
|
1246
|
+
expect(textValues).toContain('Debug query');
|
|
1247
|
+
expect(textValues).toContain('SELECT * FROM orders WHERE provider_id = 2');
|
|
1248
|
+
expect(textValues).toContain('Query preenchida');
|
|
1249
|
+
expect(textValues).toContain("SELECT * FROM orders WHERE provider_id = '2'");
|
|
1250
|
+
expect(textValues.some(value => String(value).includes('"provider": "/people/2"'))).toBe(true);
|
|
1251
|
+
});
|
|
1252
|
+
|
|
1253
|
+
it('uses store actions when no explicit table actions are passed', async () => {
|
|
1254
|
+
const save = jest.fn(() => Promise.resolve({
|
|
1255
|
+
id: 1,
|
|
1256
|
+
jobTitle: '/categories/2',
|
|
1257
|
+
}));
|
|
1258
|
+
|
|
1259
|
+
mockStores.employee_profiles = {
|
|
1260
|
+
actions: {
|
|
1261
|
+
save,
|
|
1262
|
+
},
|
|
1263
|
+
getters: {
|
|
1264
|
+
columns: [],
|
|
1265
|
+
},
|
|
1266
|
+
};
|
|
1267
|
+
|
|
1268
|
+
await renderer.act(async () => {
|
|
1269
|
+
renderer.create(
|
|
1270
|
+
React.createElement(DefaultTable, {
|
|
1271
|
+
columns: [
|
|
1272
|
+
{
|
|
1273
|
+
key: 'jobTitle',
|
|
1274
|
+
label: 'Cargo',
|
|
1275
|
+
editable: true,
|
|
1276
|
+
list: 'categories/getItems',
|
|
1277
|
+
formatList: item => ({
|
|
1278
|
+
value: item.id,
|
|
1279
|
+
label: item.name,
|
|
1280
|
+
}),
|
|
1281
|
+
saveFormat: value => `/categories/${parseInt(value.value || value, 10)}`,
|
|
1282
|
+
},
|
|
1283
|
+
],
|
|
1284
|
+
data: [{
|
|
1285
|
+
id: 1,
|
|
1286
|
+
jobTitle: '/categories/1',
|
|
1287
|
+
}],
|
|
1288
|
+
showColumnFiltersButton: false,
|
|
1289
|
+
showRowActions: false,
|
|
1290
|
+
storeName: 'employee_profiles',
|
|
1291
|
+
}),
|
|
1292
|
+
);
|
|
1293
|
+
});
|
|
1294
|
+
|
|
1295
|
+
expect(mockCapturedDefaultInputProps.length).toBeGreaterThan(0);
|
|
1296
|
+
|
|
1297
|
+
await renderer.act(async () => {
|
|
1298
|
+
await mockCapturedDefaultInputProps[0].onSave({
|
|
1299
|
+
value: '2',
|
|
1300
|
+
label: 'Departamento',
|
|
1301
|
+
object: {id: 2, name: 'Departamento'},
|
|
1302
|
+
});
|
|
1303
|
+
});
|
|
1304
|
+
|
|
1305
|
+
expect(save).toHaveBeenCalledWith({
|
|
1306
|
+
id: '1',
|
|
1307
|
+
jobTitle: '/categories/2',
|
|
1308
|
+
[STORE_ACTION_META_KEY]: {
|
|
1309
|
+
savedItemPatch: {
|
|
1310
|
+
jobTitle: {
|
|
1311
|
+
id: 2,
|
|
1312
|
+
name: 'Departamento',
|
|
1313
|
+
},
|
|
1314
|
+
},
|
|
1315
|
+
},
|
|
1316
|
+
});
|
|
1317
|
+
});
|
|
1318
|
+
});
|