@controleonline/ui-default 1.0.265 → 1.0.267
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/package.json +1 -1
- package/src/react/components/inputs/DefaultInput.js +71 -33
- package/src/react/components/inputs/DefaultInput.styles.js +36 -4
- package/src/react/components/inputs/DefaultSelect.js +83 -35
- package/src/react/components/inputs/defaultInputUtils.js +173 -26
- package/src/react/components/table/DefaultDebug.js +234 -233
- package/src/react/components/table/DefaultTable.js +431 -396
- package/src/react/components/table/DefaultTable.styles.js +69 -54
- package/src/react/components/table/DefaultTableCards.js +18 -9
- package/src/react/components/table/DefaultTableControls.js +205 -208
- package/src/react/components/table/DefaultTableFooter.js +10 -1
- package/src/react/components/table/DefaultTableRows.js +360 -333
- package/src/react/components/table/DefaultTableToolbar.js +8 -2
- package/src/react/components/table/useDefaultTableTheme.js +90 -47
- package/src/tests/react/components/table/DefaultTable.test.js +376 -241
- package/src/tests/react/inputs/defaultInputUtils.test.js +80 -9
|
@@ -2,9 +2,9 @@ const React = require('react');
|
|
|
2
2
|
const renderer = require('react-test-renderer');
|
|
3
3
|
|
|
4
4
|
const {afterEach, beforeEach, describe, expect, it} = global;
|
|
5
|
-
|
|
6
|
-
global.IS_REACT_ACT_ENVIRONMENT = true;
|
|
7
|
-
|
|
5
|
+
|
|
6
|
+
global.IS_REACT_ACT_ENVIRONMENT = true;
|
|
7
|
+
|
|
8
8
|
let consoleErrorSpy = null;
|
|
9
9
|
let mockStores = {};
|
|
10
10
|
let mockWindowDimensions = {width: 480, height: 800};
|
|
@@ -27,12 +27,12 @@ const createLocalStorageMock = () => {
|
|
|
27
27
|
},
|
|
28
28
|
};
|
|
29
29
|
};
|
|
30
|
-
|
|
30
|
+
|
|
31
31
|
jest.mock('@store', () => ({
|
|
32
32
|
getAllStores: jest.fn(() => ({})),
|
|
33
33
|
useStore: jest.fn(name => mockStores[name] || {actions: {}, getters: {}}),
|
|
34
34
|
}));
|
|
35
|
-
|
|
35
|
+
|
|
36
36
|
jest.mock('@react-navigation/native', () => ({
|
|
37
37
|
useIsFocused: jest.fn(() => false),
|
|
38
38
|
useRoute: jest.fn(() => ({
|
|
@@ -40,52 +40,52 @@ jest.mock('@react-navigation/native', () => ({
|
|
|
40
40
|
name: 'OrderHistoryPage',
|
|
41
41
|
})),
|
|
42
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
|
-
|
|
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
89
|
jest.mock('../../../../react/components/filters/DefaultColumnFilter', () => props => {
|
|
90
90
|
const React = require('react');
|
|
91
91
|
mockCapturedColumnFilterProps.push(props);
|
|
@@ -112,7 +112,7 @@ jest.mock('@controleonline/ui-common/src/react/components/StateStore', () => pro
|
|
|
112
112
|
const React = require('react');
|
|
113
113
|
return React.createElement('StateStore', props, props.children);
|
|
114
114
|
});
|
|
115
|
-
|
|
115
|
+
|
|
116
116
|
const {
|
|
117
117
|
default: DefaultTable,
|
|
118
118
|
mergeSortedDataWithLiveItems,
|
|
@@ -139,32 +139,32 @@ const flattenStyle = style => {
|
|
|
139
139
|
|
|
140
140
|
return style && typeof style === 'object' ? style : {};
|
|
141
141
|
};
|
|
142
|
-
|
|
142
|
+
|
|
143
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'});
|
|
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
168
|
});
|
|
169
169
|
});
|
|
170
170
|
|
|
@@ -254,42 +254,42 @@ describe('DefaultTable', () => {
|
|
|
254
254
|
people: {
|
|
255
255
|
getters: {
|
|
256
256
|
currentCompany: {
|
|
257
|
-
theme: {
|
|
258
|
-
colors: {},
|
|
259
|
-
},
|
|
260
|
-
},
|
|
261
|
-
},
|
|
262
|
-
},
|
|
263
|
-
theme: {
|
|
264
|
-
getters: {
|
|
265
|
-
colors: {},
|
|
266
|
-
},
|
|
267
|
-
},
|
|
268
|
-
};
|
|
269
|
-
});
|
|
270
|
-
|
|
257
|
+
theme: {
|
|
258
|
+
colors: {},
|
|
259
|
+
},
|
|
260
|
+
},
|
|
261
|
+
},
|
|
262
|
+
},
|
|
263
|
+
theme: {
|
|
264
|
+
getters: {
|
|
265
|
+
colors: {},
|
|
266
|
+
},
|
|
267
|
+
},
|
|
268
|
+
};
|
|
269
|
+
});
|
|
270
|
+
|
|
271
271
|
afterEach(() => {
|
|
272
272
|
delete global.t;
|
|
273
273
|
if (consoleErrorSpy) {
|
|
274
|
-
consoleErrorSpy.mockRestore();
|
|
275
|
-
consoleErrorSpy = null;
|
|
276
|
-
}
|
|
277
|
-
});
|
|
278
|
-
|
|
274
|
+
consoleErrorSpy.mockRestore();
|
|
275
|
+
consoleErrorSpy = null;
|
|
276
|
+
}
|
|
277
|
+
});
|
|
278
|
+
|
|
279
279
|
it('keeps the list/card toggle visible on compact layouts even when cards are forced', () => {
|
|
280
280
|
let tree;
|
|
281
281
|
|
|
282
282
|
renderer.act(() => {
|
|
283
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);
|
|
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
293
|
|
|
294
294
|
expect(iconNames).toEqual(expect.arrayContaining(['grid', 'columns']));
|
|
295
295
|
});
|
|
@@ -322,7 +322,7 @@ describe('DefaultTable', () => {
|
|
|
322
322
|
|
|
323
323
|
const toggleViewButton = tree.root
|
|
324
324
|
.findAllByType('TouchableOpacity')
|
|
325
|
-
.find(node => node.findAllByType('icon').some(icon => icon.props.name === '
|
|
325
|
+
.find(node => node.findAllByType('icon').some(icon => icon.props.name === 'list'));
|
|
326
326
|
|
|
327
327
|
renderer.act(() => {
|
|
328
328
|
toggleViewButton.props.onPress();
|
|
@@ -338,7 +338,7 @@ describe('DefaultTable', () => {
|
|
|
338
338
|
expect(
|
|
339
339
|
tree.root.findAllByType('ScrollView').some(node => node.props.horizontal === true),
|
|
340
340
|
).toBe(true);
|
|
341
|
-
expect(tree.root.findAllByType('icon').map(node => node.props.name)).toContain('
|
|
341
|
+
expect(tree.root.findAllByType('icon').map(node => node.props.name)).toContain('grid');
|
|
342
342
|
});
|
|
343
343
|
|
|
344
344
|
it('pins identity and action columns on table view', () => {
|
|
@@ -401,6 +401,75 @@ describe('DefaultTable', () => {
|
|
|
401
401
|
);
|
|
402
402
|
});
|
|
403
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
|
+
|
|
404
473
|
it('keeps the complete search aligned in the toolbar when there is enough room', () => {
|
|
405
474
|
mockWindowDimensions = {width: 430, height: 932};
|
|
406
475
|
mockStores.orders = {
|
|
@@ -425,6 +494,70 @@ describe('DefaultTable', () => {
|
|
|
425
494
|
expect(tree.root.findAllByType('icon').map(node => node.props.name)).not.toContain('search');
|
|
426
495
|
});
|
|
427
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
|
+
|
|
428
561
|
it('collapses search into an icon on narrow toolbars and opens the search modal', () => {
|
|
429
562
|
mockWindowDimensions = {width: 375, height: 667};
|
|
430
563
|
mockStores.orders = {
|
|
@@ -513,7 +646,7 @@ describe('DefaultTable', () => {
|
|
|
513
646
|
const iconNames = tree.root.findAllByType('icon').map(node => node.props.name);
|
|
514
647
|
|
|
515
648
|
expect(tree.root.findAllByType('DefaultSearch')).toHaveLength(0);
|
|
516
|
-
expect(iconNames).toEqual(expect.arrayContaining(['search', 'filter', '
|
|
649
|
+
expect(iconNames).toEqual(expect.arrayContaining(['search', 'filter', 'list', 'columns']));
|
|
517
650
|
expect(
|
|
518
651
|
tree.root.findAllByType('Text').filter(node => node.props.children === '27 registros'),
|
|
519
652
|
).toHaveLength(1);
|
|
@@ -770,81 +903,83 @@ describe('DefaultTable', () => {
|
|
|
770
903
|
});
|
|
771
904
|
|
|
772
905
|
it('forces cards when entering compact mode and still toggles between cards and list', () => {
|
|
773
|
-
const props = {
|
|
774
|
-
columns: [{key: 'name', label: 'Nome'}],
|
|
775
|
-
data: [{id: 1, name: 'Pedido 1'}],
|
|
776
|
-
showColumnFiltersButton: false,
|
|
777
|
-
};
|
|
778
|
-
let tree;
|
|
779
|
-
|
|
780
|
-
mockWindowDimensions = {width: 1024, height: 800};
|
|
781
|
-
|
|
782
|
-
renderer.act(() => {
|
|
783
|
-
tree = renderer.create(
|
|
784
|
-
React.createElement(DefaultTable, props),
|
|
785
|
-
);
|
|
786
|
-
});
|
|
787
|
-
|
|
788
|
-
expect(tree.root.findAllByType('ScrollView')).toHaveLength(1);
|
|
789
|
-
|
|
790
|
-
mockWindowDimensions = {width: 480, height: 800};
|
|
791
|
-
|
|
792
|
-
renderer.act(() => {
|
|
793
|
-
tree.update(React.createElement(DefaultTable, props));
|
|
794
|
-
});
|
|
795
|
-
|
|
796
|
-
expect(tree.root.findAllByType('ScrollView')).toHaveLength(0);
|
|
797
|
-
expect(tree.root.findByProps({name: 'grid'})).toBeTruthy();
|
|
798
|
-
|
|
799
|
-
renderer.act(() => {
|
|
800
|
-
tree.root.findByProps({name: 'grid'}).parent.props.onPress();
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
expect(tree.root.
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
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
|
+
|
|
814
949
|
it('applies a custom rowStyle to rendered table rows', () => {
|
|
815
|
-
let tree;
|
|
816
|
-
const rowStyle = jest.fn(() => ({
|
|
817
|
-
borderLeftColor: '#DC2626',
|
|
818
|
-
borderLeftWidth: 4,
|
|
819
|
-
}));
|
|
820
|
-
|
|
821
|
-
mockWindowDimensions = {width: 1024, height: 800};
|
|
822
|
-
|
|
823
|
-
renderer.act(() => {
|
|
824
|
-
tree = renderer.create(
|
|
825
|
-
React.createElement(DefaultTable, {
|
|
826
|
-
columns: [{key: 'name', label: 'Nome'}],
|
|
827
|
-
data: [{id: 1, name: 'Pedido 1'}],
|
|
828
|
-
onRowPress: () => {},
|
|
829
|
-
rowStyle,
|
|
830
|
-
showColumnFiltersButton: false,
|
|
831
|
-
}),
|
|
832
|
-
);
|
|
833
|
-
});
|
|
834
|
-
|
|
835
|
-
const row = tree.root
|
|
836
|
-
.findAllByType('TouchableOpacity')
|
|
837
|
-
.find(node => node.props?.activeOpacity === 0.84);
|
|
838
|
-
|
|
839
|
-
expect(rowStyle).toHaveBeenCalledWith(
|
|
840
|
-
expect.objectContaining({id: 1, name: 'Pedido 1'}),
|
|
841
|
-
0,
|
|
842
|
-
);
|
|
843
|
-
expect(Array.isArray(row.props.style)).toBe(true);
|
|
844
|
-
expect(
|
|
845
|
-
row.props.style.some(
|
|
846
|
-
style => style && style.borderLeftWidth === 4 && style.borderLeftColor === '#DC2626',
|
|
847
|
-
),
|
|
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
|
+
),
|
|
848
983
|
).toBe(true);
|
|
849
984
|
});
|
|
850
985
|
|
|
@@ -963,15 +1098,15 @@ describe('DefaultTable', () => {
|
|
|
963
1098
|
};
|
|
964
1099
|
|
|
965
1100
|
const FooterComponent = props =>
|
|
966
|
-
React.createElement('CustomFooter', {
|
|
967
|
-
resolvedTotalItemsText: props.resolvedTotalItemsText,
|
|
968
|
-
});
|
|
969
|
-
|
|
970
|
-
mockWindowDimensions = {width: 1024, height: 800};
|
|
971
|
-
|
|
972
|
-
renderer.act(() => {
|
|
973
|
-
tree = renderer.create(
|
|
974
|
-
React.createElement(DefaultTable, {
|
|
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, {
|
|
975
1110
|
columns: [{key: 'name', label: 'Nome'}],
|
|
976
1111
|
data: [{id: 1, name: 'Pedido 1'}],
|
|
977
1112
|
footerComponent: FooterComponent,
|
|
@@ -979,9 +1114,9 @@ describe('DefaultTable', () => {
|
|
|
979
1114
|
storeName: 'orders',
|
|
980
1115
|
}),
|
|
981
1116
|
);
|
|
982
|
-
});
|
|
983
|
-
|
|
984
|
-
const footer = tree.root.findByType('CustomFooter');
|
|
1117
|
+
});
|
|
1118
|
+
|
|
1119
|
+
const footer = tree.root.findByType('CustomFooter');
|
|
985
1120
|
|
|
986
1121
|
expect(footer.props.resolvedTotalItemsText).toBe('7 registros');
|
|
987
1122
|
});
|
|
@@ -1116,57 +1251,57 @@ describe('DefaultTable', () => {
|
|
|
1116
1251
|
});
|
|
1117
1252
|
|
|
1118
1253
|
it('uses store actions when no explicit table actions are passed', async () => {
|
|
1119
|
-
const save = jest.fn(() => Promise.resolve({
|
|
1120
|
-
id: 1,
|
|
1121
|
-
jobTitle: '/categories/2',
|
|
1122
|
-
}));
|
|
1123
|
-
|
|
1124
|
-
mockStores.employee_profiles = {
|
|
1125
|
-
actions: {
|
|
1126
|
-
save,
|
|
1127
|
-
},
|
|
1128
|
-
getters: {
|
|
1129
|
-
columns: [],
|
|
1130
|
-
},
|
|
1131
|
-
};
|
|
1132
|
-
|
|
1133
|
-
await renderer.act(async () => {
|
|
1134
|
-
renderer.create(
|
|
1135
|
-
React.createElement(DefaultTable, {
|
|
1136
|
-
columns: [
|
|
1137
|
-
{
|
|
1138
|
-
key: 'jobTitle',
|
|
1139
|
-
label: 'Cargo',
|
|
1140
|
-
editable: true,
|
|
1141
|
-
list: 'categories/getItems',
|
|
1142
|
-
formatList: item => ({
|
|
1143
|
-
value: item.id,
|
|
1144
|
-
label: item.name,
|
|
1145
|
-
}),
|
|
1146
|
-
saveFormat: value => `/categories/${parseInt(value.value || value, 10)}`,
|
|
1147
|
-
},
|
|
1148
|
-
],
|
|
1149
|
-
data: [{
|
|
1150
|
-
id: 1,
|
|
1151
|
-
jobTitle: '/categories/1',
|
|
1152
|
-
}],
|
|
1153
|
-
showColumnFiltersButton: false,
|
|
1154
|
-
showRowActions: false,
|
|
1155
|
-
storeName: 'employee_profiles',
|
|
1156
|
-
}),
|
|
1157
|
-
);
|
|
1158
|
-
});
|
|
1159
|
-
|
|
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
|
+
|
|
1160
1295
|
expect(mockCapturedDefaultInputProps.length).toBeGreaterThan(0);
|
|
1161
1296
|
|
|
1162
1297
|
await renderer.act(async () => {
|
|
1163
1298
|
await mockCapturedDefaultInputProps[0].onSave({
|
|
1164
|
-
value: '2',
|
|
1165
|
-
label: 'Departamento',
|
|
1166
|
-
object: {id: 2, name: 'Departamento'},
|
|
1167
|
-
});
|
|
1168
|
-
});
|
|
1169
|
-
|
|
1299
|
+
value: '2',
|
|
1300
|
+
label: 'Departamento',
|
|
1301
|
+
object: {id: 2, name: 'Departamento'},
|
|
1302
|
+
});
|
|
1303
|
+
});
|
|
1304
|
+
|
|
1170
1305
|
expect(save).toHaveBeenCalledWith({
|
|
1171
1306
|
id: '1',
|
|
1172
1307
|
jobTitle: '/categories/2',
|