@eohjsc/react-native-smart-city 0.3.86 → 0.3.88
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/commons/ActionGroup/__test__/TwoButtonTemplate.test.js +30 -0
- package/src/commons/{FourButtonFilterHistory → ChartAggregationOption}/__test__/FourButtonFilterHistory.test.js +2 -2
- package/src/commons/ChartAggregationOption/index.js +72 -0
- package/src/commons/{FourButtonFilterHistory → ChartAggregationOption}/styles.js +0 -0
- package/src/commons/Dashboard/MyPinnedSharedUnit/__test__/MyPinnedSharedUnit.test.js +19 -0
- package/src/commons/Dashboard/MyPinnedSharedUnit/index.js +30 -9
- package/src/commons/Dashboard/MyUnit/__test__/MyUnit.test.js +13 -1
- package/src/commons/Dashboard/MyUnit/index.js +20 -10
- package/src/commons/DateTimeRangeChange/DateTimeButton.js +3 -12
- package/src/commons/DateTimeRangeChange/index.js +113 -19
- package/src/commons/Device/HistoryChart.js +2 -2
- package/src/commons/Device/LinearChart.js +2 -2
- package/src/commons/Device/WindSpeed/Anemometer/index.js +23 -18
- package/src/commons/Device/WindSpeed/__test__/Anemometer.test.js +1 -1
- package/src/commons/MenuActionAddnew/__test__/MenuActionAddNew.test.js +1 -1
- package/src/commons/MenuActionList/__test__/MenuActionList.test.js +1 -1
- package/src/commons/ModalPopupCT/index.js +31 -25
- package/src/commons/UnitSummary/ConfigHistoryChart/__test__/ConfigHistoryChart.test.js +7 -7
- package/src/commons/UnitSummary/ConfigHistoryChart/index.js +40 -13
- package/src/configs/API.js +2 -2
- package/src/configs/AccessibilityLabel.js +7 -0
- package/src/context/actionType.ts +2 -0
- package/src/context/reducer.ts +10 -0
- package/src/hooks/Common/useTranslations.ts +1 -1
- package/src/hooks/IoT/useRemoteControl.js +0 -1
- package/src/screens/ActivityLog/__test__/FilterPopup.test.js +1 -1
- package/src/screens/ActivityLog/__test__/index.test.js +1 -1
- package/src/screens/AddLocationMaps/index.js +5 -4
- package/src/screens/AddNewGateway/__test__/ScanModbusQR.test.js +15 -0
- package/src/screens/AllGateway/hooks/__test__/index.test.js +26 -2
- package/src/screens/AllGateway/hooks/useGateway.js +11 -9
- package/src/screens/Device/__test__/DetailHistoryChart.test.js +1 -0
- package/src/screens/Device/__test__/sensorDisplayItem.test.js +150 -2
- package/src/screens/Device/components/ChartWrapper.js +39 -0
- package/src/screens/Device/components/ChartWrapperStyles.js +42 -0
- package/src/screens/Device/components/SensorDisplayItem.js +6 -2
- package/src/screens/Device/components/VisualChart.js +255 -0
- package/src/screens/Device/components/__test__/VisualChart.test.js +440 -0
- package/src/screens/EmergencyContacts/__test__/EmergencyContactsSelectContacts.test.js +7 -6
- package/src/screens/Sharing/InfoMemberUnit.js +41 -8
- package/src/screens/Sharing/Styles/inforMemberUnitStyles.js +11 -0
- package/src/screens/Sharing/__test__/InfoMemberUnit.test.js +62 -2
- package/src/screens/SmartAccount/SuccessfullyConnected/__test__/SuccessfullyConnected.test.js +3 -0
- package/src/screens/SmartIr/__test__/GroupButtonByType.test.js +47 -0
- package/src/screens/SmartIr/components/GroupButtonByType/GroupButtonByType.js +15 -2
- package/src/screens/SubUnit/AddSubUnit.js +8 -5
- package/src/screens/SyncLGDevice/__test__/AddLGDevice.test.js +52 -0
- package/src/screens/Unit/ChooseLocationStyles.js +1 -0
- package/src/screens/Unit/components/__test__/Header.test.js +9 -0
- package/src/screens/Unit/hook/__test__/useUnitConnectRemoteDevices.test.js +57 -0
- package/src/utils/I18n/translations/en.json +4 -1
- package/src/utils/I18n/translations/vi.json +4 -1
- package/src/commons/FourButtonFilterHistory/index.js +0 -72
|
@@ -0,0 +1,440 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import MockAdapter from 'axios-mock-adapter';
|
|
3
|
+
import moment from 'moment';
|
|
4
|
+
import HighchartsReactNative from '@eohjsc/highcharts';
|
|
5
|
+
import { act, create } from 'react-test-renderer';
|
|
6
|
+
|
|
7
|
+
import VisualChart from '../VisualChart';
|
|
8
|
+
import { API } from '../../../../configs';
|
|
9
|
+
import { getPusher } from '../../../../utils/Pusher';
|
|
10
|
+
import { flushPromises } from '../../../AllGateway/test-utils';
|
|
11
|
+
import api from '../../../../utils/Apis/axios';
|
|
12
|
+
import ChartAggregationOption from '../../../../commons/ChartAggregationOption';
|
|
13
|
+
import DateTimeRangeChange from '../../../../commons/DateTimeRangeChange';
|
|
14
|
+
|
|
15
|
+
const render = async (component) => {
|
|
16
|
+
let tree;
|
|
17
|
+
await act(async () => {
|
|
18
|
+
tree = await create(component);
|
|
19
|
+
});
|
|
20
|
+
return tree;
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
jest.mock('react-redux', () => {
|
|
24
|
+
return {
|
|
25
|
+
...jest.requireActual('react-redux'),
|
|
26
|
+
useSelector: jest.fn(),
|
|
27
|
+
};
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
const mockAxios = new MockAdapter(api.axiosInstance);
|
|
31
|
+
|
|
32
|
+
describe('Test LinearChartWidget', () => {
|
|
33
|
+
let tree;
|
|
34
|
+
beforeEach(() => {
|
|
35
|
+
mockAxios.reset();
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
const assertChartData = (data, expected) => {
|
|
39
|
+
const expected2 = expected.map((item) => [
|
|
40
|
+
moment(item[0]).valueOf(),
|
|
41
|
+
item[1],
|
|
42
|
+
]);
|
|
43
|
+
expect([expected.toString(), expected2.toString()]).toContain(
|
|
44
|
+
data.toString()
|
|
45
|
+
);
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
it('Test render fetch data from api', async () => {
|
|
49
|
+
mockAxios.onGet(API.CONFIG.DISPLAY_HISTORY_V3()).reply(200, {
|
|
50
|
+
configs: [
|
|
51
|
+
{
|
|
52
|
+
id: 1,
|
|
53
|
+
head: [],
|
|
54
|
+
tail: [{ x: 1000, y: 100 }],
|
|
55
|
+
middle: { ready: [], not_ready: [] },
|
|
56
|
+
},
|
|
57
|
+
],
|
|
58
|
+
});
|
|
59
|
+
tree = await render(
|
|
60
|
+
<VisualChart
|
|
61
|
+
item={{
|
|
62
|
+
is_configuration_ready: true,
|
|
63
|
+
configuration: {
|
|
64
|
+
type: 'line_chart',
|
|
65
|
+
configs: [
|
|
66
|
+
{
|
|
67
|
+
id: 1,
|
|
68
|
+
},
|
|
69
|
+
],
|
|
70
|
+
},
|
|
71
|
+
id: 1,
|
|
72
|
+
template: 'history',
|
|
73
|
+
}}
|
|
74
|
+
/>
|
|
75
|
+
);
|
|
76
|
+
const instance = tree.root;
|
|
77
|
+
const chart = instance.findByType(HighchartsReactNative);
|
|
78
|
+
assertChartData(chart.props.options.series[0].data, [[moment(1000), 100]]);
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
it('Test render fetch data from api and cache', async () => {
|
|
82
|
+
const cacheUrl1 = 'https://s3.eoh.io/xxx1.json';
|
|
83
|
+
const cacheUrl2 = 'https://s3.eoh.io/xxx2.json';
|
|
84
|
+
const cacheUrl3 = 'https://s3.eoh.io/xxx3.json';
|
|
85
|
+
const cacheUrl4 = 'https://s3.eoh.io/xxx4.json';
|
|
86
|
+
const responseData = {
|
|
87
|
+
configs: [
|
|
88
|
+
{
|
|
89
|
+
id: 1,
|
|
90
|
+
head: [{ x: 1, y: 2 }],
|
|
91
|
+
tail: [{ x: 2, y: 3 }],
|
|
92
|
+
middle: {
|
|
93
|
+
ready: [
|
|
94
|
+
{ date: '2022-03-02', url: cacheUrl1 },
|
|
95
|
+
{ date: '2022-03-04', url: cacheUrl3 },
|
|
96
|
+
],
|
|
97
|
+
not_ready: [
|
|
98
|
+
{ date: '2022-03-03', url: cacheUrl2 },
|
|
99
|
+
{ date: '2022-03-05', url: cacheUrl4 },
|
|
100
|
+
],
|
|
101
|
+
channel: 'cache-xxx',
|
|
102
|
+
},
|
|
103
|
+
},
|
|
104
|
+
],
|
|
105
|
+
};
|
|
106
|
+
mockAxios.onGet(cacheUrl1).reply(200, [{ x: 3, y: 4 }]);
|
|
107
|
+
mockAxios.onGet(cacheUrl2).reply(200, [{ x: 4, y: 5 }]);
|
|
108
|
+
mockAxios.onGet(cacheUrl3).reply(200, [{ x: 5, y: 6 }]);
|
|
109
|
+
mockAxios.onGet(cacheUrl4).reply(200, [{ x: 7, y: 8 }]);
|
|
110
|
+
|
|
111
|
+
mockAxios.onGet(API.CONFIG.DISPLAY_HISTORY_V3()).reply(200, responseData);
|
|
112
|
+
tree = await render(
|
|
113
|
+
<VisualChart
|
|
114
|
+
item={{
|
|
115
|
+
is_configuration_ready: true,
|
|
116
|
+
configuration: {
|
|
117
|
+
type: 'line_chart',
|
|
118
|
+
configs: [
|
|
119
|
+
{
|
|
120
|
+
id: 1,
|
|
121
|
+
},
|
|
122
|
+
],
|
|
123
|
+
},
|
|
124
|
+
id: 1,
|
|
125
|
+
template: 'history',
|
|
126
|
+
}}
|
|
127
|
+
/>
|
|
128
|
+
);
|
|
129
|
+
const instance = tree.root;
|
|
130
|
+
const chart = instance.findByType(HighchartsReactNative);
|
|
131
|
+
assertChartData(chart.props.options.series[0].data, [
|
|
132
|
+
[moment(1), 2],
|
|
133
|
+
[moment(3), 4],
|
|
134
|
+
[moment(5), 6],
|
|
135
|
+
[moment(2), 3],
|
|
136
|
+
]);
|
|
137
|
+
|
|
138
|
+
await act(async () => {
|
|
139
|
+
await getPusher()
|
|
140
|
+
.subscribe('cache-xxx')
|
|
141
|
+
.trigger('caching-value-log-process', {
|
|
142
|
+
success: true,
|
|
143
|
+
});
|
|
144
|
+
});
|
|
145
|
+
|
|
146
|
+
await flushPromises();
|
|
147
|
+
|
|
148
|
+
assertChartData(chart.props.options.series[0].data, [
|
|
149
|
+
[moment(1), 2],
|
|
150
|
+
[moment(3), 4],
|
|
151
|
+
[moment(4), 5],
|
|
152
|
+
[moment(5), 6],
|
|
153
|
+
[moment(7), 8],
|
|
154
|
+
[moment(2), 3],
|
|
155
|
+
]);
|
|
156
|
+
});
|
|
157
|
+
|
|
158
|
+
it('Test render aggregation sum', async () => {
|
|
159
|
+
mockAxios.onGet(API.CONFIG.DISPLAY_HISTORY_V3()).reply(200, {
|
|
160
|
+
configs: [
|
|
161
|
+
{
|
|
162
|
+
id: 1,
|
|
163
|
+
head: [],
|
|
164
|
+
tail: [
|
|
165
|
+
{ x: 1000, y: 100 },
|
|
166
|
+
{ x: 1000 + 86400000, y: 100 },
|
|
167
|
+
],
|
|
168
|
+
middle: { ready: [], not_ready: [] },
|
|
169
|
+
},
|
|
170
|
+
],
|
|
171
|
+
});
|
|
172
|
+
tree = await render(
|
|
173
|
+
<VisualChart
|
|
174
|
+
item={{
|
|
175
|
+
is_configuration_ready: true,
|
|
176
|
+
configuration: {
|
|
177
|
+
type: 'line_chart',
|
|
178
|
+
value_type: 'sum',
|
|
179
|
+
aggregation_period: 'day',
|
|
180
|
+
configs: [
|
|
181
|
+
{
|
|
182
|
+
id: 1,
|
|
183
|
+
},
|
|
184
|
+
],
|
|
185
|
+
},
|
|
186
|
+
id: 1,
|
|
187
|
+
template: 'history',
|
|
188
|
+
}}
|
|
189
|
+
/>
|
|
190
|
+
);
|
|
191
|
+
const instance = tree.root;
|
|
192
|
+
const chart = instance.findByType(HighchartsReactNative);
|
|
193
|
+
assertChartData(chart.props.options.series[0].data, [
|
|
194
|
+
['1970-01-01', 100],
|
|
195
|
+
['1970-01-02', 100],
|
|
196
|
+
]);
|
|
197
|
+
|
|
198
|
+
const groupByOption = instance.findByType(ChartAggregationOption);
|
|
199
|
+
|
|
200
|
+
await act(async () => {
|
|
201
|
+
groupByOption.props.setGroupBy('month');
|
|
202
|
+
});
|
|
203
|
+
assertChartData(chart.props.options.series[0].data, [['1970-01', 200]]);
|
|
204
|
+
});
|
|
205
|
+
|
|
206
|
+
it('Test render aggregation sum', async () => {
|
|
207
|
+
mockAxios.onGet(API.CONFIG.DISPLAY_HISTORY_V3()).reply(200, {
|
|
208
|
+
configs: [
|
|
209
|
+
{
|
|
210
|
+
id: 1,
|
|
211
|
+
head: [],
|
|
212
|
+
tail: [
|
|
213
|
+
{ x: 1000, y: 100 },
|
|
214
|
+
{ x: 1000, y: 100 },
|
|
215
|
+
],
|
|
216
|
+
middle: { ready: [], not_ready: [] },
|
|
217
|
+
},
|
|
218
|
+
],
|
|
219
|
+
});
|
|
220
|
+
tree = await render(
|
|
221
|
+
<VisualChart
|
|
222
|
+
item={{
|
|
223
|
+
is_configuration_ready: true,
|
|
224
|
+
configuration: {
|
|
225
|
+
type: 'line_chart',
|
|
226
|
+
value_type: 'sum',
|
|
227
|
+
aggregation_period: 'day',
|
|
228
|
+
configs: [
|
|
229
|
+
{
|
|
230
|
+
id: 1,
|
|
231
|
+
},
|
|
232
|
+
],
|
|
233
|
+
},
|
|
234
|
+
id: 1,
|
|
235
|
+
template: 'history',
|
|
236
|
+
}}
|
|
237
|
+
/>
|
|
238
|
+
);
|
|
239
|
+
const instance = tree.root;
|
|
240
|
+
const chart = instance.findByType(HighchartsReactNative);
|
|
241
|
+
assertChartData(chart.props.options.series[0].data, [['1970-01-01', 200]]);
|
|
242
|
+
});
|
|
243
|
+
|
|
244
|
+
it('Test render aggregation average', async () => {
|
|
245
|
+
mockAxios.onGet(API.CONFIG.DISPLAY_HISTORY_V3()).reply(200, {
|
|
246
|
+
configs: [
|
|
247
|
+
{
|
|
248
|
+
id: 1,
|
|
249
|
+
head: [],
|
|
250
|
+
tail: [
|
|
251
|
+
{ x: 1000, y: 100 },
|
|
252
|
+
{ x: 1000, y: 200 },
|
|
253
|
+
],
|
|
254
|
+
middle: { ready: [], not_ready: [] },
|
|
255
|
+
},
|
|
256
|
+
],
|
|
257
|
+
});
|
|
258
|
+
tree = await render(
|
|
259
|
+
<VisualChart
|
|
260
|
+
item={{
|
|
261
|
+
is_configuration_ready: true,
|
|
262
|
+
configuration: {
|
|
263
|
+
type: 'line_chart',
|
|
264
|
+
value_type: 'avg',
|
|
265
|
+
aggregation_period: 'day',
|
|
266
|
+
configs: [
|
|
267
|
+
{
|
|
268
|
+
id: 1,
|
|
269
|
+
},
|
|
270
|
+
],
|
|
271
|
+
},
|
|
272
|
+
id: 1,
|
|
273
|
+
template: 'history',
|
|
274
|
+
}}
|
|
275
|
+
/>
|
|
276
|
+
);
|
|
277
|
+
const instance = tree.root;
|
|
278
|
+
const chart = instance.findByType(HighchartsReactNative);
|
|
279
|
+
assertChartData(chart.props.options.series[0].data, [['1970-01-01', 150]]);
|
|
280
|
+
});
|
|
281
|
+
|
|
282
|
+
it('Test render not demo', async () => {
|
|
283
|
+
mockAxios.onGet(API.CONFIG.DISPLAY_HISTORY_V3()).reply(400);
|
|
284
|
+
tree = await render(
|
|
285
|
+
<VisualChart
|
|
286
|
+
item={{
|
|
287
|
+
configuration: {
|
|
288
|
+
type: 'line_chart',
|
|
289
|
+
configs: [
|
|
290
|
+
{
|
|
291
|
+
data: [{ x: 1000, y: 100 }],
|
|
292
|
+
title: 'xxx',
|
|
293
|
+
},
|
|
294
|
+
],
|
|
295
|
+
},
|
|
296
|
+
id: 1,
|
|
297
|
+
template: 'history',
|
|
298
|
+
}}
|
|
299
|
+
/>
|
|
300
|
+
);
|
|
301
|
+
const instance = tree.root;
|
|
302
|
+
const chart = instance.findByType(HighchartsReactNative);
|
|
303
|
+
assertChartData(chart.props.options.series[0].data, [[moment(1000), 100]]);
|
|
304
|
+
});
|
|
305
|
+
|
|
306
|
+
it('Test render bar chart', async () => {
|
|
307
|
+
tree = await render(
|
|
308
|
+
<VisualChart
|
|
309
|
+
item={{
|
|
310
|
+
configuration: {
|
|
311
|
+
type: 'bar_chart',
|
|
312
|
+
configs: [],
|
|
313
|
+
},
|
|
314
|
+
id: 1,
|
|
315
|
+
template: 'history',
|
|
316
|
+
}}
|
|
317
|
+
/>
|
|
318
|
+
);
|
|
319
|
+
const instance = tree.root;
|
|
320
|
+
const chart = instance.findByType(HighchartsReactNative);
|
|
321
|
+
expect(chart.props.options.chart.type).toEqual('column');
|
|
322
|
+
});
|
|
323
|
+
|
|
324
|
+
it('Test render horizontal_bar_chart', async () => {
|
|
325
|
+
tree = await render(
|
|
326
|
+
<VisualChart
|
|
327
|
+
item={{
|
|
328
|
+
configuration: {
|
|
329
|
+
type: 'horizontal_bar_chart',
|
|
330
|
+
configs: [],
|
|
331
|
+
},
|
|
332
|
+
id: 1,
|
|
333
|
+
template: 'history',
|
|
334
|
+
}}
|
|
335
|
+
/>
|
|
336
|
+
);
|
|
337
|
+
const instance = tree.root;
|
|
338
|
+
const chart = instance.findByType(HighchartsReactNative);
|
|
339
|
+
expect(chart.props.options.chart.type).toEqual('bar');
|
|
340
|
+
});
|
|
341
|
+
|
|
342
|
+
it('Test render area_chart', async () => {
|
|
343
|
+
tree = await render(
|
|
344
|
+
<VisualChart
|
|
345
|
+
item={{
|
|
346
|
+
configuration: {
|
|
347
|
+
type: 'area_chart',
|
|
348
|
+
configs: [],
|
|
349
|
+
},
|
|
350
|
+
id: 1,
|
|
351
|
+
template: 'history',
|
|
352
|
+
}}
|
|
353
|
+
/>
|
|
354
|
+
);
|
|
355
|
+
const instance = tree.root;
|
|
356
|
+
const chart = instance.findByType(HighchartsReactNative);
|
|
357
|
+
expect(chart.props.options.chart.type).toEqual('area');
|
|
358
|
+
});
|
|
359
|
+
|
|
360
|
+
it('Test render stacked_bar_chart', async () => {
|
|
361
|
+
tree = await render(
|
|
362
|
+
<VisualChart
|
|
363
|
+
item={{
|
|
364
|
+
configuration: {
|
|
365
|
+
type: 'stacked_bar_chart',
|
|
366
|
+
configs: [],
|
|
367
|
+
},
|
|
368
|
+
id: 1,
|
|
369
|
+
template: 'history',
|
|
370
|
+
}}
|
|
371
|
+
/>
|
|
372
|
+
);
|
|
373
|
+
const instance = tree.root;
|
|
374
|
+
const chart = instance.findByType(HighchartsReactNative);
|
|
375
|
+
expect(chart.props.options.chart.type).toEqual('column');
|
|
376
|
+
expect(chart.props.options.plotOptions.column.stacking).toEqual('normal');
|
|
377
|
+
});
|
|
378
|
+
|
|
379
|
+
it('Test render scatter_chart', async () => {
|
|
380
|
+
tree = await render(
|
|
381
|
+
<VisualChart
|
|
382
|
+
item={{
|
|
383
|
+
configuration: {
|
|
384
|
+
type: 'scatter_chart',
|
|
385
|
+
configs: [],
|
|
386
|
+
},
|
|
387
|
+
id: 1,
|
|
388
|
+
template: 'history',
|
|
389
|
+
}}
|
|
390
|
+
/>
|
|
391
|
+
);
|
|
392
|
+
const instance = tree.root;
|
|
393
|
+
const chart = instance.findByType(HighchartsReactNative);
|
|
394
|
+
expect(chart.props.options.chart.type).toEqual('scatter');
|
|
395
|
+
});
|
|
396
|
+
|
|
397
|
+
it('not fetch data if empty config', async () => {
|
|
398
|
+
tree = await render(
|
|
399
|
+
<VisualChart
|
|
400
|
+
item={{
|
|
401
|
+
configuration: {
|
|
402
|
+
type: 'line_chart',
|
|
403
|
+
configs: [{}],
|
|
404
|
+
},
|
|
405
|
+
id: 1,
|
|
406
|
+
template: 'history',
|
|
407
|
+
}}
|
|
408
|
+
/>
|
|
409
|
+
);
|
|
410
|
+
expect(mockAxios.history.get).toHaveLength(0);
|
|
411
|
+
});
|
|
412
|
+
|
|
413
|
+
it('not fetch data when change date', async () => {
|
|
414
|
+
tree = await render(
|
|
415
|
+
<VisualChart
|
|
416
|
+
item={{
|
|
417
|
+
configuration: {
|
|
418
|
+
type: 'line_chart',
|
|
419
|
+
configs: [{ id: 1 }],
|
|
420
|
+
},
|
|
421
|
+
id: 1,
|
|
422
|
+
template: 'history',
|
|
423
|
+
}}
|
|
424
|
+
/>
|
|
425
|
+
);
|
|
426
|
+
expect(mockAxios.history.get).toHaveLength(1);
|
|
427
|
+
|
|
428
|
+
const instance = tree.root;
|
|
429
|
+
const dateRange = instance.findByType(DateTimeRangeChange);
|
|
430
|
+
await act(async () => {
|
|
431
|
+
dateRange.props.selectStart(moment().subtract(5, 'days'));
|
|
432
|
+
});
|
|
433
|
+
expect(mockAxios.history.get).toHaveLength(2);
|
|
434
|
+
|
|
435
|
+
await act(async () => {
|
|
436
|
+
dateRange.props.selectEnd(moment().subtract(1, 'days'));
|
|
437
|
+
});
|
|
438
|
+
expect(mockAxios.history.get).toHaveLength(3);
|
|
439
|
+
});
|
|
440
|
+
});
|
|
@@ -70,12 +70,13 @@ describe('test EmergencyContactsSelectContacts', () => {
|
|
|
70
70
|
tree = await create(wrapComponent(route));
|
|
71
71
|
});
|
|
72
72
|
const instance = tree.root;
|
|
73
|
-
const rowUser = instance.
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
73
|
+
const rowUser = instance.findByProps({
|
|
74
|
+
accessibilityLabel: AccessibilityLabel.EMERGENCY_SELECT_CONTACT + 0,
|
|
75
|
+
});
|
|
76
|
+
await act(async () => {
|
|
77
|
+
rowUser.props.onPress();
|
|
78
|
+
});
|
|
79
|
+
expect(rowUser.props.text).toEqual('test');
|
|
79
80
|
});
|
|
80
81
|
|
|
81
82
|
it('test onSave emergencyContactsSelectContacts', async () => {
|
|
@@ -9,7 +9,7 @@ import { HeaderCustom } from '../../commons/Header';
|
|
|
9
9
|
import RowMemberInfo from '../GuestInfo/components/RowGuestInfo';
|
|
10
10
|
import { useIsOwnerOfUnit } from '../../hooks/Common';
|
|
11
11
|
import { axiosGet } from '../../utils/Apis/axios';
|
|
12
|
-
import { AlertAction } from '../../commons';
|
|
12
|
+
import { AlertAction, ViewButtonBottom } from '../../commons';
|
|
13
13
|
import { useStateAlertAction, useDataMember } from './hooks';
|
|
14
14
|
import ItemChangeRole from './Components/ItemChangeRole';
|
|
15
15
|
import MemberSvg from '../../Images/Common/member.svg';
|
|
@@ -18,6 +18,7 @@ import styles from './Styles/inforMemberUnitStyles';
|
|
|
18
18
|
import { useNavigation, useIsFocused } from '@react-navigation/native';
|
|
19
19
|
import Routes from '../../utils/Route';
|
|
20
20
|
import { AccessibilityLabel } from '../../configs/Constants';
|
|
21
|
+
import ModalPopupCT from '../../commons/ModalPopupCT';
|
|
21
22
|
|
|
22
23
|
const InfoMemberUnit = memo(({ route }) => {
|
|
23
24
|
const t = useTranslations();
|
|
@@ -28,6 +29,7 @@ const InfoMemberUnit = memo(({ route }) => {
|
|
|
28
29
|
};
|
|
29
30
|
const { navigate } = useNavigation();
|
|
30
31
|
const [isLoading, setIsLoading] = useState(true);
|
|
32
|
+
const [isShowWarning, setIsShowWarning] = useState(false);
|
|
31
33
|
const [memberInfo, setMemberInfo] = useState({});
|
|
32
34
|
const [itemSelected, setItemSelected] = useState({});
|
|
33
35
|
const isFocused = useIsFocused();
|
|
@@ -56,10 +58,7 @@ const InfoMemberUnit = memo(({ route }) => {
|
|
|
56
58
|
if (stateAlertAction?.is_change) {
|
|
57
59
|
hideAlertAction();
|
|
58
60
|
if (itemSelected?.role?.is_owner) {
|
|
59
|
-
|
|
60
|
-
dataParams: { unit_id: unit?.id, member },
|
|
61
|
-
type: 'infoMemberUnit',
|
|
62
|
-
});
|
|
61
|
+
setIsShowWarning(true);
|
|
63
62
|
}
|
|
64
63
|
} else {
|
|
65
64
|
removeMember(
|
|
@@ -72,14 +71,19 @@ const InfoMemberUnit = memo(({ route }) => {
|
|
|
72
71
|
}, [
|
|
73
72
|
hideAlertAction,
|
|
74
73
|
itemSelected?.role?.is_owner,
|
|
75
|
-
member,
|
|
76
|
-
navigate,
|
|
77
74
|
removeMember,
|
|
78
75
|
stateAlertAction?.is_change,
|
|
79
76
|
stateAlertAction?.member,
|
|
80
|
-
unit?.id,
|
|
81
77
|
]);
|
|
82
78
|
|
|
79
|
+
const handleChangeOwner = useCallback(() => {
|
|
80
|
+
setIsShowWarning(false);
|
|
81
|
+
navigate(Routes.EnterPassword, {
|
|
82
|
+
dataParams: { unit_id: unit?.id, member },
|
|
83
|
+
type: 'infoMemberUnit',
|
|
84
|
+
});
|
|
85
|
+
}, [member, navigate, unit?.id]);
|
|
86
|
+
|
|
83
87
|
const fetchMemberInfo = useCallback(async () => {
|
|
84
88
|
setIsLoading(true);
|
|
85
89
|
const { success, data } = await axiosGet(
|
|
@@ -158,6 +162,22 @@ const InfoMemberUnit = memo(({ route }) => {
|
|
|
158
162
|
return <></>;
|
|
159
163
|
}, [isOwner, navigate, unit?.id, memberInfo]);
|
|
160
164
|
|
|
165
|
+
const footerWarning = useMemo(() => {
|
|
166
|
+
return (
|
|
167
|
+
<>
|
|
168
|
+
<View style={styles.line} />
|
|
169
|
+
<ViewButtonBottom
|
|
170
|
+
leftTitle={t('cancel')}
|
|
171
|
+
rightTitle={t('change')}
|
|
172
|
+
styleButton={styles.styleButton}
|
|
173
|
+
styleButtonLeftText={styles.textButton}
|
|
174
|
+
onLeftClick={() => setIsShowWarning(false)}
|
|
175
|
+
onRightClick={handleChangeOwner}
|
|
176
|
+
/>
|
|
177
|
+
</>
|
|
178
|
+
);
|
|
179
|
+
}, [handleChangeOwner, t]);
|
|
180
|
+
|
|
161
181
|
useEffect(() => {
|
|
162
182
|
if (isIdentityOwner) {
|
|
163
183
|
setItemSelected(itemsRoleModal[0]);
|
|
@@ -223,6 +243,7 @@ const InfoMemberUnit = memo(({ route }) => {
|
|
|
223
243
|
<TouchableOpacity
|
|
224
244
|
onPress={onPressChangeRole}
|
|
225
245
|
style={styles.role}
|
|
246
|
+
accessibilityLabel={AccessibilityLabel.CHANGE_ROLE}
|
|
226
247
|
>
|
|
227
248
|
<View style={styles.leftRole}>
|
|
228
249
|
<Text type="Body" color={Colors.Gray7}>
|
|
@@ -271,6 +292,18 @@ const InfoMemberUnit = memo(({ route }) => {
|
|
|
271
292
|
>
|
|
272
293
|
<ChangeRoleContent />
|
|
273
294
|
</AlertAction>
|
|
295
|
+
|
|
296
|
+
<ModalPopupCT
|
|
297
|
+
isVisible={isShowWarning}
|
|
298
|
+
title={t('transfer_ownership')}
|
|
299
|
+
subTitle={t('text_change_owner')}
|
|
300
|
+
isShowAlert
|
|
301
|
+
isShowUnderstand={false}
|
|
302
|
+
textShowAlert={t('text_alert_change_owner')}
|
|
303
|
+
styleWrapButton={styles.wrapButton}
|
|
304
|
+
styleRightButton={styles.button}
|
|
305
|
+
footer={footerWarning}
|
|
306
|
+
/>
|
|
274
307
|
</>
|
|
275
308
|
);
|
|
276
309
|
});
|
|
@@ -89,4 +89,15 @@ export default StyleSheet.create({
|
|
|
89
89
|
removeButtonStyle: {
|
|
90
90
|
color: Colors.Red,
|
|
91
91
|
},
|
|
92
|
+
line: {
|
|
93
|
+
borderTopWidth: 1,
|
|
94
|
+
borderTopColor: Colors.Neutral.Neutral3,
|
|
95
|
+
},
|
|
96
|
+
styleButton: {
|
|
97
|
+
paddingTop: 24,
|
|
98
|
+
paddingBottom: 0,
|
|
99
|
+
},
|
|
100
|
+
textButton: {
|
|
101
|
+
color: Colors.Gray9,
|
|
102
|
+
},
|
|
92
103
|
});
|
|
@@ -7,10 +7,13 @@ import InfoMemberUnit from '../InfoMemberUnit';
|
|
|
7
7
|
import { HeaderCustom } from '../../../commons/Header';
|
|
8
8
|
import { SCProvider } from '../../../context';
|
|
9
9
|
import { mockSCStore } from '../../../context/mockStore';
|
|
10
|
-
import { AlertAction } from '../../../commons';
|
|
10
|
+
import { AlertAction, ViewButtonBottom } from '../../../commons';
|
|
11
11
|
import API from '../../../configs/API';
|
|
12
12
|
import { AccessibilityLabel } from '../../../configs/Constants';
|
|
13
13
|
import api from '../../../utils/Apis/axios';
|
|
14
|
+
import ItemChangeRole from '../Components/ItemChangeRole';
|
|
15
|
+
import ModalPopupCT from '../../../commons/ModalPopupCT';
|
|
16
|
+
import Routes from '../../../utils/Route';
|
|
14
17
|
|
|
15
18
|
const mock = new MockAdapter(api.axiosInstance);
|
|
16
19
|
|
|
@@ -53,6 +56,7 @@ describe('Test InfoMemberUnit', () => {
|
|
|
53
56
|
unit: {
|
|
54
57
|
id: 1,
|
|
55
58
|
name: 'unit',
|
|
59
|
+
user_id: 1,
|
|
56
60
|
},
|
|
57
61
|
member: {
|
|
58
62
|
id: 1,
|
|
@@ -107,7 +111,7 @@ describe('Test InfoMemberUnit', () => {
|
|
|
107
111
|
|
|
108
112
|
it('render InfoMemberUnit delete member', async () => {
|
|
109
113
|
mock.onGet(API.SHARE.UNIT_MEMBER_INFO(1, 1)).reply(200, {
|
|
110
|
-
id:
|
|
114
|
+
id: 2,
|
|
111
115
|
identity: 'owner',
|
|
112
116
|
phone_number: '88888',
|
|
113
117
|
name: 'user',
|
|
@@ -131,4 +135,60 @@ describe('Test InfoMemberUnit', () => {
|
|
|
131
135
|
});
|
|
132
136
|
expect(mockGoBack).toBeCalled();
|
|
133
137
|
});
|
|
138
|
+
|
|
139
|
+
it('test change owner', async () => {
|
|
140
|
+
mock.onGet(API.SHARE.UNIT_MEMBER_INFO(1, 1)).reply(200, {
|
|
141
|
+
id: 2,
|
|
142
|
+
identity: 'owner',
|
|
143
|
+
phone_number: '88888',
|
|
144
|
+
name: 'user',
|
|
145
|
+
email: 'abc@gmail.com',
|
|
146
|
+
});
|
|
147
|
+
await act(async () => {
|
|
148
|
+
tree = await create(wrapComponent(route));
|
|
149
|
+
});
|
|
150
|
+
const instance = tree.root;
|
|
151
|
+
|
|
152
|
+
const touchChangeRole = instance.findByProps({
|
|
153
|
+
accessibilityLabel: AccessibilityLabel.CHANGE_ROLE,
|
|
154
|
+
});
|
|
155
|
+
await act(async () => {
|
|
156
|
+
await touchChangeRole.props.onPress();
|
|
157
|
+
});
|
|
158
|
+
|
|
159
|
+
const alertAction = instance.findByType(AlertAction);
|
|
160
|
+
expect(alertAction.props.visible).toEqual(true);
|
|
161
|
+
|
|
162
|
+
const itemChangeRole = instance.findAllByType(ItemChangeRole);
|
|
163
|
+
expect(itemChangeRole).toHaveLength(2);
|
|
164
|
+
|
|
165
|
+
const modalPopupCT = instance.findByType(ModalPopupCT);
|
|
166
|
+
await act(async () => {
|
|
167
|
+
await itemChangeRole[0].props.onPress();
|
|
168
|
+
});
|
|
169
|
+
await act(async () => {
|
|
170
|
+
await alertAction.props.rightButtonClick();
|
|
171
|
+
});
|
|
172
|
+
expect(alertAction.props.visible).toEqual(false);
|
|
173
|
+
expect(modalPopupCT.props.isVisible).toEqual(true);
|
|
174
|
+
|
|
175
|
+
const viewButtonBottom = instance.findAllByType(ViewButtonBottom);
|
|
176
|
+
expect(viewButtonBottom).toHaveLength(2);
|
|
177
|
+
|
|
178
|
+
await act(async () => {
|
|
179
|
+
await viewButtonBottom[1].props.onRightClick();
|
|
180
|
+
});
|
|
181
|
+
expect(modalPopupCT.props.isVisible).toEqual(false);
|
|
182
|
+
expect(mockedNavigate).toHaveBeenCalledWith(Routes.EnterPassword, {
|
|
183
|
+
dataParams: {
|
|
184
|
+
unit_id: 1,
|
|
185
|
+
member: {
|
|
186
|
+
id: 1,
|
|
187
|
+
name: 'user1',
|
|
188
|
+
share_id: 1,
|
|
189
|
+
},
|
|
190
|
+
},
|
|
191
|
+
type: 'infoMemberUnit',
|
|
192
|
+
});
|
|
193
|
+
});
|
|
134
194
|
});
|
package/src/screens/SmartAccount/SuccessfullyConnected/__test__/SuccessfullyConnected.test.js
CHANGED
|
@@ -91,6 +91,9 @@ describe('Test SuccessfullyConnected', () => {
|
|
|
91
91
|
await flushPromises();
|
|
92
92
|
const instance = tree.root;
|
|
93
93
|
const inputs = instance.findAllByType(_TextInput);
|
|
94
|
+
await act(async () => {
|
|
95
|
+
inputs[0].props.onChange();
|
|
96
|
+
});
|
|
94
97
|
expect(inputs).toHaveLength(3); // sensor + 2 end device
|
|
95
98
|
expect(mock.history.get).toHaveLength(1);
|
|
96
99
|
expect(mock.history.get[0].url).toBe(API.CHIP.RENAME_DEVICES(1));
|