@controleonline/ui-default 1.0.263 → 1.0.264
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 +48 -47
- package/package.json +3 -6
- package/src/react/components/errors/DefaultErrors.js +360 -360
- package/src/react/components/files/DefaultFile.js +46 -46
- package/src/react/components/filters/CompactFilterSelector.js +22 -3
- package/src/react/components/filters/DefaultColumnFilter.js +15 -13
- package/src/react/components/filters/DefaultExternalFilters.js +44 -39
- package/src/react/components/filters/DefaultSearch.js +140 -103
- package/src/react/components/filters/DefaultSearch.styles.js +65 -70
- package/src/react/components/form/DefaultForm.js +200 -198
- package/src/react/components/help/DefaultTooltip.js +87 -87
- package/src/react/components/help/DefaultTooltip.styles.js +61 -61
- package/src/react/components/inputs/DefaultInput.js +162 -160
- package/src/react/components/inputs/DefaultSelect.js +203 -192
- package/src/react/components/map/DefaultGoogleMap.styles.js +115 -9
- package/src/react/components/map/DefaultGoogleMap.web.js +560 -446
- package/src/react/components/map/DefaultMap.native.js +73 -71
- package/src/react/components/map/DefaultMap.styles.js +16 -16
- package/src/react/components/map/DefaultMap.web.js +68 -66
- package/src/react/components/map/DefaultNativeMap.native.js +307 -183
- package/src/react/components/map/DefaultNativeMap.shared.js +439 -340
- package/src/react/components/map/DefaultNativeMap.styles.js +156 -122
- package/src/react/components/table/DefaultTable.js +529 -355
- package/src/react/components/table/DefaultTable.styles.js +30 -39
- package/src/react/index.js +10 -10
- package/src/tests/react/components/errors/DefaultErrors.test.js +162 -162
- package/src/tests/react/components/files/DefaultFile.test.js +80 -80
- package/src/tests/react/components/inputs/DefaultSelect.test.js +93 -0
- package/src/tests/react/components/table/DefaultTable.test.js +334 -0
|
@@ -12,29 +12,25 @@ const shadow = Platform.select({
|
|
|
12
12
|
});
|
|
13
13
|
|
|
14
14
|
const styles = StyleSheet.create({
|
|
15
|
-
wrap: {
|
|
16
|
-
flex: 1,
|
|
17
|
-
width: '100%',
|
|
18
|
-
minHeight: 0,
|
|
19
|
-
borderWidth: 1,
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
position: 'relative',
|
|
25
|
-
},
|
|
15
|
+
wrap: {
|
|
16
|
+
flex: 1,
|
|
17
|
+
width: '100%',
|
|
18
|
+
minHeight: 0,
|
|
19
|
+
borderWidth: 1,
|
|
20
|
+
borderRadius: 10,
|
|
21
|
+
overflow: 'visible',
|
|
22
|
+
position: 'relative',
|
|
23
|
+
},
|
|
26
24
|
toolbar: {
|
|
27
25
|
minHeight: 36,
|
|
28
26
|
paddingHorizontal: 8,
|
|
29
27
|
paddingVertical: 4,
|
|
30
28
|
borderBottomWidth: 1,
|
|
31
|
-
borderBottomColor: '#E2E8F0',
|
|
32
29
|
flexDirection: 'row',
|
|
33
30
|
flexWrap: 'wrap',
|
|
34
31
|
alignItems: 'center',
|
|
35
32
|
justifyContent: 'flex-end',
|
|
36
33
|
gap: 6,
|
|
37
|
-
backgroundColor: '#FFFFFF',
|
|
38
34
|
zIndex: 10,
|
|
39
35
|
},
|
|
40
36
|
toolbarLeft: {
|
|
@@ -85,38 +81,33 @@ const styles = StyleSheet.create({
|
|
|
85
81
|
maxWidth: '100%',
|
|
86
82
|
minWidth: 104,
|
|
87
83
|
},
|
|
88
|
-
toolbarCountPill: {
|
|
89
|
-
minWidth: 0,
|
|
90
|
-
maxWidth: 112,
|
|
91
|
-
height: 28,
|
|
92
|
-
borderRadius: 999,
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
flexShrink: 1,
|
|
84
|
+
toolbarCountPill: {
|
|
85
|
+
minWidth: 0,
|
|
86
|
+
maxWidth: 112,
|
|
87
|
+
height: 28,
|
|
88
|
+
borderRadius: 999,
|
|
89
|
+
paddingHorizontal: 10,
|
|
90
|
+
alignItems: 'center',
|
|
91
|
+
justifyContent: 'center',
|
|
92
|
+
flexShrink: 1,
|
|
98
93
|
},
|
|
99
94
|
toolbarCountText: {
|
|
100
95
|
fontSize: 9,
|
|
101
96
|
fontWeight: '900',
|
|
102
97
|
},
|
|
103
|
-
toolbarButton: {
|
|
104
|
-
minWidth: 28,
|
|
105
|
-
height: 28,
|
|
106
|
-
borderRadius: 14,
|
|
107
|
-
paddingHorizontal: 7,
|
|
108
|
-
borderWidth: 1,
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
justifyContent: 'center',
|
|
114
|
-
gap: 4,
|
|
115
|
-
},
|
|
116
|
-
toolbarButtonActive: {
|
|
117
|
-
backgroundColor: '#F8FAFC',
|
|
118
|
-
borderColor: '#CBD5E1',
|
|
98
|
+
toolbarButton: {
|
|
99
|
+
minWidth: 28,
|
|
100
|
+
height: 28,
|
|
101
|
+
borderRadius: 14,
|
|
102
|
+
paddingHorizontal: 7,
|
|
103
|
+
borderWidth: 1,
|
|
104
|
+
flexDirection: 'row',
|
|
105
|
+
alignItems: 'center',
|
|
106
|
+
justifyContent: 'center',
|
|
107
|
+
gap: 4,
|
|
119
108
|
},
|
|
109
|
+
toolbarButtonActive: {
|
|
110
|
+
},
|
|
120
111
|
toolbarAddButton: {
|
|
121
112
|
minWidth: 30,
|
|
122
113
|
width: 30,
|
package/src/react/index.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
// React entrypoint kept after Vue removal.
|
|
2
|
-
import DefaultFile from './components/files/DefaultFile';
|
|
3
|
-
|
|
4
|
-
const moduleEntry = {
|
|
5
|
-
DefaultFile,
|
|
6
|
-
};
|
|
7
|
-
|
|
8
|
-
export {DefaultFile};
|
|
9
|
-
|
|
10
|
-
export default moduleEntry;
|
|
1
|
+
// React entrypoint kept after Vue removal.
|
|
2
|
+
import DefaultFile from './components/files/DefaultFile';
|
|
3
|
+
|
|
4
|
+
const moduleEntry = {
|
|
5
|
+
DefaultFile,
|
|
6
|
+
};
|
|
7
|
+
|
|
8
|
+
export {DefaultFile};
|
|
9
|
+
|
|
10
|
+
export default moduleEntry;
|
|
@@ -1,162 +1,162 @@
|
|
|
1
|
-
const React = require('react');
|
|
2
|
-
const renderer = require('react-test-renderer');
|
|
3
|
-
const {jest} = require('@jest/globals');
|
|
4
|
-
|
|
5
|
-
const {afterEach, beforeEach, describe, expect, it} = global;
|
|
6
|
-
|
|
7
|
-
global.IS_REACT_ACT_ENVIRONMENT = true;
|
|
8
|
-
|
|
9
|
-
let mockStores = {};
|
|
10
|
-
let consoleErrorSpy = null;
|
|
11
|
-
|
|
12
|
-
jest.mock('@store', () => ({
|
|
13
|
-
useStore: jest.fn(name => {
|
|
14
|
-
if (name === 'theme') {
|
|
15
|
-
return {
|
|
16
|
-
getters: {
|
|
17
|
-
colors: {
|
|
18
|
-
inputErrorBackground: '#FEF2F2',
|
|
19
|
-
inputErrorBorder: '#DC2626',
|
|
20
|
-
inputErrorText: '#B91C1C',
|
|
21
|
-
modalBackground: '#FFFFFF',
|
|
22
|
-
modalBorder: '#DC2626',
|
|
23
|
-
modalCloseIcon: '#B91C1C',
|
|
24
|
-
modalOverlay: 'rgba(15, 23, 42, 0.55)',
|
|
25
|
-
modalText: '#334155',
|
|
26
|
-
primary: '#0EA5E9',
|
|
27
|
-
textDanger: '#DC2626',
|
|
28
|
-
},
|
|
29
|
-
},
|
|
30
|
-
};
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
return mockStores[name] || {actions: {}, getters: {}};
|
|
34
|
-
}),
|
|
35
|
-
useStores: jest.fn(selector =>
|
|
36
|
-
(typeof selector === 'function' ? selector(mockStores) : mockStores),
|
|
37
|
-
),
|
|
38
|
-
}));
|
|
39
|
-
|
|
40
|
-
jest.mock('react-native', () => {
|
|
41
|
-
const React = require('react');
|
|
42
|
-
const createComponent = name => props =>
|
|
43
|
-
React.createElement(name, props, props.children);
|
|
44
|
-
|
|
45
|
-
return {
|
|
46
|
-
Modal: props => React.createElement('modal', props, props.children),
|
|
47
|
-
Pressable: props => React.createElement('pressable', props, props.children),
|
|
48
|
-
StyleSheet: {
|
|
49
|
-
create: styles => styles,
|
|
50
|
-
},
|
|
51
|
-
Text: createComponent('text'),
|
|
52
|
-
TouchableOpacity: createComponent('touchable-opacity'),
|
|
53
|
-
View: createComponent('view'),
|
|
54
|
-
};
|
|
55
|
-
});
|
|
56
|
-
|
|
57
|
-
const DefaultErrors =
|
|
58
|
-
require('../../../../react/components/errors/DefaultErrors').default;
|
|
59
|
-
|
|
60
|
-
const getTextNodes = tree =>
|
|
61
|
-
tree.root
|
|
62
|
-
.findAllByType('text')
|
|
63
|
-
.map(node => (Array.isArray(node.children) ? node.children.join('') : ''))
|
|
64
|
-
.filter(Boolean);
|
|
65
|
-
|
|
66
|
-
describe('DefaultErrors', () => {
|
|
67
|
-
beforeEach(() => {
|
|
68
|
-
jest.useFakeTimers();
|
|
69
|
-
consoleErrorSpy = jest.spyOn(console, 'error').mockImplementation(() => {});
|
|
70
|
-
mockStores = {
|
|
71
|
-
orders: {
|
|
72
|
-
actions: {
|
|
73
|
-
setError: jest.fn(),
|
|
74
|
-
},
|
|
75
|
-
getters: {
|
|
76
|
-
error: 'Falha ao salvar.',
|
|
77
|
-
},
|
|
78
|
-
},
|
|
79
|
-
};
|
|
80
|
-
});
|
|
81
|
-
|
|
82
|
-
afterEach(() => {
|
|
83
|
-
if (consoleErrorSpy) {
|
|
84
|
-
consoleErrorSpy.mockRestore();
|
|
85
|
-
consoleErrorSpy = null;
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
jest.clearAllTimers();
|
|
89
|
-
jest.useRealTimers();
|
|
90
|
-
});
|
|
91
|
-
|
|
92
|
-
it('renders the store error in a popup and clears the store when closed', () => {
|
|
93
|
-
let tree;
|
|
94
|
-
|
|
95
|
-
renderer.act(() => {
|
|
96
|
-
tree = renderer.create(
|
|
97
|
-
React.createElement(DefaultErrors, {
|
|
98
|
-
store: 'orders',
|
|
99
|
-
title: 'Nao foi possivel concluir',
|
|
100
|
-
}),
|
|
101
|
-
);
|
|
102
|
-
});
|
|
103
|
-
|
|
104
|
-
expect(tree.root.findByType('modal').props.visible).toBe(true);
|
|
105
|
-
expect(getTextNodes(tree)).toEqual(
|
|
106
|
-
expect.arrayContaining([
|
|
107
|
-
'Nao foi possivel concluir',
|
|
108
|
-
'Falha ao salvar.',
|
|
109
|
-
'×',
|
|
110
|
-
]),
|
|
111
|
-
);
|
|
112
|
-
|
|
113
|
-
const closeButton = tree.root.findByProps({testID: 'default-errors-close'});
|
|
114
|
-
|
|
115
|
-
renderer.act(() => {
|
|
116
|
-
closeButton.props.onPress();
|
|
117
|
-
});
|
|
118
|
-
|
|
119
|
-
expect(mockStores.orders.actions.setError).toHaveBeenCalledWith('');
|
|
120
|
-
expect(tree.toJSON()).toBeNull();
|
|
121
|
-
});
|
|
122
|
-
|
|
123
|
-
it('renders an explicit popup even without a store binding', () => {
|
|
124
|
-
let tree;
|
|
125
|
-
|
|
126
|
-
renderer.act(() => {
|
|
127
|
-
tree = renderer.create(
|
|
128
|
-
React.createElement(DefaultErrors, {
|
|
129
|
-
title: 'Pedido nao informado.',
|
|
130
|
-
}),
|
|
131
|
-
);
|
|
132
|
-
});
|
|
133
|
-
|
|
134
|
-
expect(tree.root.findByType('modal').props.visible).toBe(true);
|
|
135
|
-
expect(getTextNodes(tree)).toEqual(
|
|
136
|
-
expect.arrayContaining([
|
|
137
|
-
'Pedido nao informado.',
|
|
138
|
-
'×',
|
|
139
|
-
]),
|
|
140
|
-
);
|
|
141
|
-
});
|
|
142
|
-
|
|
143
|
-
it('auto closes after five seconds and clears the store error', () => {
|
|
144
|
-
let tree;
|
|
145
|
-
|
|
146
|
-
renderer.act(() => {
|
|
147
|
-
tree = renderer.create(
|
|
148
|
-
React.createElement(DefaultErrors, {
|
|
149
|
-
store: 'orders',
|
|
150
|
-
title: 'Nao foi possivel concluir',
|
|
151
|
-
}),
|
|
152
|
-
);
|
|
153
|
-
});
|
|
154
|
-
|
|
155
|
-
renderer.act(() => {
|
|
156
|
-
jest.advanceTimersByTime(5000);
|
|
157
|
-
});
|
|
158
|
-
|
|
159
|
-
expect(mockStores.orders.actions.setError).toHaveBeenCalledWith('');
|
|
160
|
-
expect(tree.toJSON()).toBeNull();
|
|
161
|
-
});
|
|
162
|
-
});
|
|
1
|
+
const React = require('react');
|
|
2
|
+
const renderer = require('react-test-renderer');
|
|
3
|
+
const {jest} = require('@jest/globals');
|
|
4
|
+
|
|
5
|
+
const {afterEach, beforeEach, describe, expect, it} = global;
|
|
6
|
+
|
|
7
|
+
global.IS_REACT_ACT_ENVIRONMENT = true;
|
|
8
|
+
|
|
9
|
+
let mockStores = {};
|
|
10
|
+
let consoleErrorSpy = null;
|
|
11
|
+
|
|
12
|
+
jest.mock('@store', () => ({
|
|
13
|
+
useStore: jest.fn(name => {
|
|
14
|
+
if (name === 'theme') {
|
|
15
|
+
return {
|
|
16
|
+
getters: {
|
|
17
|
+
colors: {
|
|
18
|
+
inputErrorBackground: '#FEF2F2',
|
|
19
|
+
inputErrorBorder: '#DC2626',
|
|
20
|
+
inputErrorText: '#B91C1C',
|
|
21
|
+
modalBackground: '#FFFFFF',
|
|
22
|
+
modalBorder: '#DC2626',
|
|
23
|
+
modalCloseIcon: '#B91C1C',
|
|
24
|
+
modalOverlay: 'rgba(15, 23, 42, 0.55)',
|
|
25
|
+
modalText: '#334155',
|
|
26
|
+
primary: '#0EA5E9',
|
|
27
|
+
textDanger: '#DC2626',
|
|
28
|
+
},
|
|
29
|
+
},
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
return mockStores[name] || {actions: {}, getters: {}};
|
|
34
|
+
}),
|
|
35
|
+
useStores: jest.fn(selector =>
|
|
36
|
+
(typeof selector === 'function' ? selector(mockStores) : mockStores),
|
|
37
|
+
),
|
|
38
|
+
}));
|
|
39
|
+
|
|
40
|
+
jest.mock('react-native', () => {
|
|
41
|
+
const React = require('react');
|
|
42
|
+
const createComponent = name => props =>
|
|
43
|
+
React.createElement(name, props, props.children);
|
|
44
|
+
|
|
45
|
+
return {
|
|
46
|
+
Modal: props => React.createElement('modal', props, props.children),
|
|
47
|
+
Pressable: props => React.createElement('pressable', props, props.children),
|
|
48
|
+
StyleSheet: {
|
|
49
|
+
create: styles => styles,
|
|
50
|
+
},
|
|
51
|
+
Text: createComponent('text'),
|
|
52
|
+
TouchableOpacity: createComponent('touchable-opacity'),
|
|
53
|
+
View: createComponent('view'),
|
|
54
|
+
};
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
const DefaultErrors =
|
|
58
|
+
require('../../../../react/components/errors/DefaultErrors').default;
|
|
59
|
+
|
|
60
|
+
const getTextNodes = tree =>
|
|
61
|
+
tree.root
|
|
62
|
+
.findAllByType('text')
|
|
63
|
+
.map(node => (Array.isArray(node.children) ? node.children.join('') : ''))
|
|
64
|
+
.filter(Boolean);
|
|
65
|
+
|
|
66
|
+
describe('DefaultErrors', () => {
|
|
67
|
+
beforeEach(() => {
|
|
68
|
+
jest.useFakeTimers();
|
|
69
|
+
consoleErrorSpy = jest.spyOn(console, 'error').mockImplementation(() => {});
|
|
70
|
+
mockStores = {
|
|
71
|
+
orders: {
|
|
72
|
+
actions: {
|
|
73
|
+
setError: jest.fn(),
|
|
74
|
+
},
|
|
75
|
+
getters: {
|
|
76
|
+
error: 'Falha ao salvar.',
|
|
77
|
+
},
|
|
78
|
+
},
|
|
79
|
+
};
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
afterEach(() => {
|
|
83
|
+
if (consoleErrorSpy) {
|
|
84
|
+
consoleErrorSpy.mockRestore();
|
|
85
|
+
consoleErrorSpy = null;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
jest.clearAllTimers();
|
|
89
|
+
jest.useRealTimers();
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
it('renders the store error in a popup and clears the store when closed', () => {
|
|
93
|
+
let tree;
|
|
94
|
+
|
|
95
|
+
renderer.act(() => {
|
|
96
|
+
tree = renderer.create(
|
|
97
|
+
React.createElement(DefaultErrors, {
|
|
98
|
+
store: 'orders',
|
|
99
|
+
title: 'Nao foi possivel concluir',
|
|
100
|
+
}),
|
|
101
|
+
);
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
expect(tree.root.findByType('modal').props.visible).toBe(true);
|
|
105
|
+
expect(getTextNodes(tree)).toEqual(
|
|
106
|
+
expect.arrayContaining([
|
|
107
|
+
'Nao foi possivel concluir',
|
|
108
|
+
'Falha ao salvar.',
|
|
109
|
+
'×',
|
|
110
|
+
]),
|
|
111
|
+
);
|
|
112
|
+
|
|
113
|
+
const closeButton = tree.root.findByProps({testID: 'default-errors-close'});
|
|
114
|
+
|
|
115
|
+
renderer.act(() => {
|
|
116
|
+
closeButton.props.onPress();
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
expect(mockStores.orders.actions.setError).toHaveBeenCalledWith('');
|
|
120
|
+
expect(tree.toJSON()).toBeNull();
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
it('renders an explicit popup even without a store binding', () => {
|
|
124
|
+
let tree;
|
|
125
|
+
|
|
126
|
+
renderer.act(() => {
|
|
127
|
+
tree = renderer.create(
|
|
128
|
+
React.createElement(DefaultErrors, {
|
|
129
|
+
title: 'Pedido nao informado.',
|
|
130
|
+
}),
|
|
131
|
+
);
|
|
132
|
+
});
|
|
133
|
+
|
|
134
|
+
expect(tree.root.findByType('modal').props.visible).toBe(true);
|
|
135
|
+
expect(getTextNodes(tree)).toEqual(
|
|
136
|
+
expect.arrayContaining([
|
|
137
|
+
'Pedido nao informado.',
|
|
138
|
+
'×',
|
|
139
|
+
]),
|
|
140
|
+
);
|
|
141
|
+
});
|
|
142
|
+
|
|
143
|
+
it('auto closes after five seconds and clears the store error', () => {
|
|
144
|
+
let tree;
|
|
145
|
+
|
|
146
|
+
renderer.act(() => {
|
|
147
|
+
tree = renderer.create(
|
|
148
|
+
React.createElement(DefaultErrors, {
|
|
149
|
+
store: 'orders',
|
|
150
|
+
title: 'Nao foi possivel concluir',
|
|
151
|
+
}),
|
|
152
|
+
);
|
|
153
|
+
});
|
|
154
|
+
|
|
155
|
+
renderer.act(() => {
|
|
156
|
+
jest.advanceTimersByTime(5000);
|
|
157
|
+
});
|
|
158
|
+
|
|
159
|
+
expect(mockStores.orders.actions.setError).toHaveBeenCalledWith('');
|
|
160
|
+
expect(tree.toJSON()).toBeNull();
|
|
161
|
+
});
|
|
162
|
+
});
|
|
@@ -1,80 +1,80 @@
|
|
|
1
|
-
const React = require('react');
|
|
2
|
-
const renderer = require('react-test-renderer');
|
|
3
|
-
const {jest} = require('@jest/globals');
|
|
4
|
-
|
|
5
|
-
const {afterEach, beforeEach, describe, expect, it} = global;
|
|
6
|
-
|
|
7
|
-
global.IS_REACT_ACT_ENVIRONMENT = true;
|
|
8
|
-
|
|
9
|
-
jest.mock('@env', () => ({
|
|
10
|
-
env: {
|
|
11
|
-
API_ENTRYPOINT: 'https://api.controleonline.com',
|
|
12
|
-
DOMAIN: 'manager.controleonline.com',
|
|
13
|
-
},
|
|
14
|
-
}));
|
|
15
|
-
|
|
16
|
-
jest.mock('@store', () => ({
|
|
17
|
-
useStore: jest.fn(() => ({
|
|
18
|
-
getters: {},
|
|
19
|
-
})),
|
|
20
|
-
}));
|
|
21
|
-
|
|
22
|
-
jest.mock('react-native', () => ({
|
|
23
|
-
Image: props => React.createElement('image', props, props.children),
|
|
24
|
-
}));
|
|
25
|
-
|
|
26
|
-
const DefaultFile =
|
|
27
|
-
require('../../../../react/components/files/DefaultFile').default;
|
|
28
|
-
|
|
29
|
-
describe('DefaultFile', () => {
|
|
30
|
-
beforeEach(() => {
|
|
31
|
-
jest.clearAllMocks();
|
|
32
|
-
});
|
|
33
|
-
|
|
34
|
-
afterEach(() => {
|
|
35
|
-
jest.clearAllTimers();
|
|
36
|
-
});
|
|
37
|
-
|
|
38
|
-
it('renders backend download files with app-domain query and headers', () => {
|
|
39
|
-
let tree;
|
|
40
|
-
|
|
41
|
-
renderer.act(() => {
|
|
42
|
-
tree = renderer.create(
|
|
43
|
-
React.createElement(DefaultFile, {
|
|
44
|
-
file: {
|
|
45
|
-
id: 3,
|
|
46
|
-
url: '/files/3/download',
|
|
47
|
-
},
|
|
48
|
-
company: {
|
|
49
|
-
domain: 'maincompany.controleonline.com',
|
|
50
|
-
},
|
|
51
|
-
headers: {
|
|
52
|
-
Authorization: 'Bearer token',
|
|
53
|
-
},
|
|
54
|
-
resizeMode: 'contain',
|
|
55
|
-
}),
|
|
56
|
-
);
|
|
57
|
-
});
|
|
58
|
-
|
|
59
|
-
const image = tree.root.findByType('image');
|
|
60
|
-
|
|
61
|
-
expect(image.props.source).toEqual({
|
|
62
|
-
uri: 'https://api.controleonline.com/files/3/download?app-domain=maincompany.controleonline.com',
|
|
63
|
-
headers: {
|
|
64
|
-
Authorization: 'Bearer token',
|
|
65
|
-
'app-domain': 'maincompany.controleonline.com',
|
|
66
|
-
},
|
|
67
|
-
});
|
|
68
|
-
expect(image.props.resizeMode).toBe('contain');
|
|
69
|
-
});
|
|
70
|
-
|
|
71
|
-
it('returns null when there is no file source', () => {
|
|
72
|
-
let tree;
|
|
73
|
-
|
|
74
|
-
renderer.act(() => {
|
|
75
|
-
tree = renderer.create(React.createElement(DefaultFile, null));
|
|
76
|
-
});
|
|
77
|
-
|
|
78
|
-
expect(tree.toJSON()).toBeNull();
|
|
79
|
-
});
|
|
80
|
-
});
|
|
1
|
+
const React = require('react');
|
|
2
|
+
const renderer = require('react-test-renderer');
|
|
3
|
+
const {jest} = require('@jest/globals');
|
|
4
|
+
|
|
5
|
+
const {afterEach, beforeEach, describe, expect, it} = global;
|
|
6
|
+
|
|
7
|
+
global.IS_REACT_ACT_ENVIRONMENT = true;
|
|
8
|
+
|
|
9
|
+
jest.mock('@env', () => ({
|
|
10
|
+
env: {
|
|
11
|
+
API_ENTRYPOINT: 'https://api.controleonline.com',
|
|
12
|
+
DOMAIN: 'manager.controleonline.com',
|
|
13
|
+
},
|
|
14
|
+
}));
|
|
15
|
+
|
|
16
|
+
jest.mock('@store', () => ({
|
|
17
|
+
useStore: jest.fn(() => ({
|
|
18
|
+
getters: {},
|
|
19
|
+
})),
|
|
20
|
+
}));
|
|
21
|
+
|
|
22
|
+
jest.mock('react-native', () => ({
|
|
23
|
+
Image: props => React.createElement('image', props, props.children),
|
|
24
|
+
}));
|
|
25
|
+
|
|
26
|
+
const DefaultFile =
|
|
27
|
+
require('../../../../react/components/files/DefaultFile').default;
|
|
28
|
+
|
|
29
|
+
describe('DefaultFile', () => {
|
|
30
|
+
beforeEach(() => {
|
|
31
|
+
jest.clearAllMocks();
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
afterEach(() => {
|
|
35
|
+
jest.clearAllTimers();
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
it('renders backend download files with app-domain query and headers', () => {
|
|
39
|
+
let tree;
|
|
40
|
+
|
|
41
|
+
renderer.act(() => {
|
|
42
|
+
tree = renderer.create(
|
|
43
|
+
React.createElement(DefaultFile, {
|
|
44
|
+
file: {
|
|
45
|
+
id: 3,
|
|
46
|
+
url: '/files/3/download',
|
|
47
|
+
},
|
|
48
|
+
company: {
|
|
49
|
+
domain: 'maincompany.controleonline.com',
|
|
50
|
+
},
|
|
51
|
+
headers: {
|
|
52
|
+
Authorization: 'Bearer token',
|
|
53
|
+
},
|
|
54
|
+
resizeMode: 'contain',
|
|
55
|
+
}),
|
|
56
|
+
);
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
const image = tree.root.findByType('image');
|
|
60
|
+
|
|
61
|
+
expect(image.props.source).toEqual({
|
|
62
|
+
uri: 'https://api.controleonline.com/files/3/download?app-domain=maincompany.controleonline.com',
|
|
63
|
+
headers: {
|
|
64
|
+
Authorization: 'Bearer token',
|
|
65
|
+
'app-domain': 'maincompany.controleonline.com',
|
|
66
|
+
},
|
|
67
|
+
});
|
|
68
|
+
expect(image.props.resizeMode).toBe('contain');
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
it('returns null when there is no file source', () => {
|
|
72
|
+
let tree;
|
|
73
|
+
|
|
74
|
+
renderer.act(() => {
|
|
75
|
+
tree = renderer.create(React.createElement(DefaultFile, null));
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
expect(tree.toJSON()).toBeNull();
|
|
79
|
+
});
|
|
80
|
+
});
|