@eohjsc/react-native-smart-city 0.4.42 → 0.4.44
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/android/build.gradle +19 -24
- package/package.json +15 -12
- package/src/commons/Action/ItemQuickAction.js +1 -0
- package/src/commons/ActionGroup/ColorPickerTemplate.js +3 -4
- package/src/commons/ActionGroup/NumberUpDownActionTemplate.js +7 -10
- package/src/commons/ActionGroup/OnOffSmartLock/OnOffSmartLock.js +2 -2
- package/src/commons/ActionGroup/OnOffTemplate/OnOffButtonTemplate.js +4 -5
- package/src/commons/ActionGroup/OnOffTemplate/SwitchButtonTemplate.js +4 -4
- package/src/commons/ActionGroup/OnOffTemplate/index.js +6 -5
- package/src/commons/ActionGroup/OneBigButtonTemplate.js +4 -4
- package/src/commons/ActionGroup/OptionsDropdownActionTemplate.js +6 -17
- package/src/commons/ActionGroup/SliderRangeTemplate.js +5 -3
- package/src/commons/ActionGroup/SmartTiviActionTemplate/SmartTiviActionTemplate.js +7 -7
- package/src/commons/ActionGroup/StatesGridActionTemplate.js +6 -20
- package/src/commons/ActionGroup/ThreeButtonTemplate/__test__/ThreeButtonTemplate.test.js +6 -6
- package/src/commons/ActionGroup/ThreeButtonTemplate/index.js +2 -2
- package/src/commons/ActionGroup/TimerActionTemplate.js +3 -2
- package/src/commons/ActionGroup/TwoButtonTemplate/index.js +133 -135
- package/src/commons/ActionGroup/__test__/ColorPickerTemplate.test.js +37 -14
- package/src/commons/ActionGroup/__test__/NumberUpDownTemplate.test.js +75 -32
- package/src/commons/ActionGroup/__test__/OnOffButtonTemplate.test.js +11 -11
- package/src/commons/ActionGroup/__test__/OnOffSmartLock.test.js +13 -17
- package/src/commons/ActionGroup/__test__/OnOffTemplate.test.js +44 -48
- package/src/commons/ActionGroup/__test__/OneBigButtonTemplate.test.js +56 -22
- package/src/commons/ActionGroup/__test__/OptionsDropdownTemplate.test.js +123 -21
- package/src/commons/ActionGroup/__test__/SliderRangeTemplate.test.js +12 -16
- package/src/commons/ActionGroup/__test__/StatesGridActionTemplate.test.js +73 -38
- package/src/commons/ActionGroup/__test__/SwitchButtonTemplate.test.js +11 -15
- package/src/commons/ActionGroup/__test__/TimerActionTemplate.test.js +11 -15
- package/src/commons/ActionGroup/__test__/TimerActionTemplateWithutConfigValue.test.js +9 -9
- package/src/commons/ActionGroup/__test__/TwoButtonTemplate.test.js +21 -31
- package/src/commons/ActionGroup/__test__/index.test.js +36 -21
- package/src/commons/ActionGroup/index.js +4 -7
- package/src/commons/Dashboard/MyPinnedSharedUnit/__test__/MyPinnedSharedUnit.test.js +0 -5
- package/src/commons/Dashboard/MyUnit/index.js +10 -8
- package/src/commons/DateTimeRangeChange/index.js +3 -3
- package/src/commons/Device/HistoryChart.js +1 -1
- package/src/commons/Device/HorizontalBarChart.js +3 -4
- package/src/commons/Device/LinearChart.js +3 -5
- package/src/commons/FlatListDnD/__test__/index.test.js +27 -25
- package/src/commons/GroupCheckBox/__test__/GroupCheckBox.test.js +1 -22
- package/src/commons/HeaderAni/index.js +12 -2
- package/src/commons/Highcharts/index.js +111 -0
- package/src/commons/MediaPlayerDetail/__test__/MediaPlayerFull.test.js +1 -23
- package/src/commons/Modal/ModalCustom.js +2 -2
- package/src/commons/OneTapTemplate/__test__/NumberUpDownActionTemplate.test.js +5 -3
- package/src/commons/Processing/index.js +1 -0
- package/src/commons/Processing/styles.js +3 -0
- package/src/commons/SubUnit/OneTap/ItemOneTap.js +2 -0
- package/src/commons/Unit/HeaderUnit/index.js +15 -8
- package/src/commons/UnitSummary/ConfigHistoryChart/index.js +1 -59
- package/src/commons/icon/index.js +57 -0
- package/src/configs/AccessibilityLabel.js +2 -0
- package/src/hooks/IoT/__test__/useRemoteControl.test.js +52 -51
- package/src/hooks/IoT/__test__/useWatchConfigs.test.js +3 -2
- package/src/hooks/useMqtt.js +5 -2
- package/src/iot/mqtt.js +2 -0
- package/src/navigations/UnitStack.js +2 -2
- package/src/screens/AddNewGateway/ConnectingDevice.js +3 -2
- package/src/screens/AddNewGateway/ShareWifiPassword.js +3 -2
- package/src/screens/AllGateway/DeviceModbusDetail/__test__/index.test.js +31 -32
- package/src/screens/Automate/AddNewAction/SetupConfigCondition.js +19 -2
- package/src/screens/Automate/AddNewAction/__test__/{SetupSensor.test.js → SetupConfigCondition.test.js} +97 -0
- package/src/screens/Automate/EditActionsList/__tests__/index.test.js +69 -68
- package/src/screens/ChangePosition/__test__/index.test.js +34 -32
- package/src/screens/ConfirmUnitDeletion/__test__/ConfirmUnitDeletion.test.js +1 -11
- package/src/screens/Device/__test__/detail.test.js +101 -46
- package/src/screens/Device/__test__/sensorDisplayItem.test.js +14 -2
- package/src/screens/Device/components/ChartWrapper.js +14 -12
- package/src/screens/Device/components/SensorDisplayItem.js +18 -2
- package/src/screens/Device/components/VisualChart.js +17 -3
- package/src/screens/Device/components/__test__/VisualChart.test.js +12 -15
- package/src/screens/Device/detail.js +49 -36
- package/src/screens/Device/hooks/__test__/useEvaluateValue.test.js +20 -18
- package/src/screens/Device/styles.js +3 -0
- package/src/screens/Sharing/InfoMemberUnit.js +3 -1
- package/src/screens/Sharing/MemberList.js +16 -3
- package/src/screens/Sharing/__test__/InfoMemberUnit.test.js +2 -0
- package/src/screens/Sharing/__test__/SelectPermission.test.js +96 -137
- package/src/screens/Template/__test__/EditTemplate.test.js +48 -45
- package/src/screens/Unit/SelectAddToFavorites.js +1 -0
- package/src/screens/Unit/__test__/SelectAddress.test.js +4 -11
- package/src/screens/UnitSummary/components/3PPowerConsumption/__test__/3PPowerConsumption.test.js +1 -11
- package/src/utils/Apis/axios.js +1 -0
- package/src/utils/I18n/translations/en.js +2 -0
- package/src/utils/I18n/translations/vi.js +2 -0
- package/src/utils/Monitor.js +2 -2
- package/src/commons/UnitSummary/ConfigHistoryChart/__test__/ConfigHistoryChart.test.js +0 -289
|
@@ -10,10 +10,14 @@ import { getTranslate } from '../../../utils/I18n';
|
|
|
10
10
|
import { SCProvider } from '../../../context';
|
|
11
11
|
import { mockSCStore } from '../../../context/mockStore';
|
|
12
12
|
|
|
13
|
-
|
|
13
|
+
import SvgDoorState from '../../../../assets/images/Device/door-state.svg';
|
|
14
|
+
import SvgCurrentState from '../../../../assets/images/Device/current-state.svg';
|
|
15
|
+
import SvgWindStrength from '../../../../assets/images/Device/wind-strength.svg';
|
|
16
|
+
|
|
17
|
+
const wrapComponent = (item, mockDoAction, sensor) => (
|
|
14
18
|
<SCProvider initState={mockSCStore({})}>
|
|
15
19
|
<OptionsDropdownActionTemplate
|
|
16
|
-
|
|
20
|
+
item={item}
|
|
17
21
|
doAction={mockDoAction}
|
|
18
22
|
sensor={sensor}
|
|
19
23
|
/>
|
|
@@ -34,7 +38,7 @@ jest.mock('@react-navigation/native', () => {
|
|
|
34
38
|
});
|
|
35
39
|
|
|
36
40
|
describe('Test OptionsDropdownActionTemplate', () => {
|
|
37
|
-
const
|
|
41
|
+
const actionData = {
|
|
38
42
|
color: '#00979D',
|
|
39
43
|
command_prefer_over_bluetooth: true,
|
|
40
44
|
command_prefer_over_googlehome: false,
|
|
@@ -45,16 +49,16 @@ describe('Test OptionsDropdownActionTemplate', () => {
|
|
|
45
49
|
key: '5ed1d4dc-a905-47cd-b0c9-f979644bd21a',
|
|
46
50
|
};
|
|
47
51
|
|
|
48
|
-
let
|
|
52
|
+
let displayItem;
|
|
49
53
|
let sensor;
|
|
50
54
|
let wrapper;
|
|
51
55
|
|
|
52
56
|
beforeEach(() => {
|
|
53
57
|
watchMultiConfigs.mockClear();
|
|
54
|
-
|
|
58
|
+
displayItem = {
|
|
55
59
|
title: 'Fan Speed',
|
|
56
60
|
configuration: {
|
|
57
|
-
action_data,
|
|
61
|
+
action_data: actionData,
|
|
58
62
|
config: 5,
|
|
59
63
|
action: 'e5d23347-ee31-4fe3-9fb5-bbce05bf4b61',
|
|
60
64
|
options: [
|
|
@@ -82,7 +86,7 @@ describe('Test OptionsDropdownActionTemplate', () => {
|
|
|
82
86
|
const mockDoAction = jest.fn();
|
|
83
87
|
sensor.is_managed_by_backend = true;
|
|
84
88
|
await act(async () => {
|
|
85
|
-
wrapper = await create(wrapComponent(
|
|
89
|
+
wrapper = await create(wrapComponent(displayItem, mockDoAction, sensor));
|
|
86
90
|
});
|
|
87
91
|
const instance = wrapper.root;
|
|
88
92
|
await act(async () => {
|
|
@@ -98,13 +102,36 @@ describe('Test OptionsDropdownActionTemplate', () => {
|
|
|
98
102
|
expect(touchs).toHaveLength(5); // show-hide alert + 2 options + onDone
|
|
99
103
|
});
|
|
100
104
|
|
|
105
|
+
it('render icon', async () => {
|
|
106
|
+
const mockDoAction = jest.fn();
|
|
107
|
+
sensor.is_managed_by_backend = true;
|
|
108
|
+
|
|
109
|
+
displayItem.configuration.icon = 'door-state-1';
|
|
110
|
+
await act(async () => {
|
|
111
|
+
wrapper = await create(wrapComponent(displayItem, mockDoAction, sensor));
|
|
112
|
+
});
|
|
113
|
+
expect(wrapper.root.findAllByType(SvgDoorState)).toHaveLength(1);
|
|
114
|
+
|
|
115
|
+
displayItem.configuration.icon = 'curent-state-1';
|
|
116
|
+
await act(async () => {
|
|
117
|
+
wrapper = await create(wrapComponent(displayItem, mockDoAction, sensor));
|
|
118
|
+
});
|
|
119
|
+
expect(wrapper.root.findAllByType(SvgCurrentState)).toHaveLength(1);
|
|
120
|
+
|
|
121
|
+
displayItem.configuration.icon = 'wind-strength-1';
|
|
122
|
+
await act(async () => {
|
|
123
|
+
wrapper = await create(wrapComponent(displayItem, mockDoAction, sensor));
|
|
124
|
+
});
|
|
125
|
+
expect(wrapper.root.findAllByType(SvgWindStrength)).toHaveLength(1);
|
|
126
|
+
});
|
|
127
|
+
|
|
101
128
|
it('render template without selectedOption match, get first one', async () => {
|
|
102
|
-
|
|
103
|
-
|
|
129
|
+
displayItem.configuration.options[1].value_text = '3';
|
|
130
|
+
displayItem.configuration.options[1].value_int = 3;
|
|
104
131
|
sensor.is_managed_by_backend = true;
|
|
105
132
|
const mockDoAction = jest.fn();
|
|
106
133
|
await act(async () => {
|
|
107
|
-
wrapper = await create(wrapComponent(
|
|
134
|
+
wrapper = await create(wrapComponent(displayItem, mockDoAction, sensor));
|
|
108
135
|
});
|
|
109
136
|
const instance = wrapper.root;
|
|
110
137
|
await act(async () => {
|
|
@@ -119,7 +146,7 @@ describe('Test OptionsDropdownActionTemplate', () => {
|
|
|
119
146
|
const assertUpdateSelectedOption = async (is_managed_by_backend) => {
|
|
120
147
|
const mockDoAction = jest.fn();
|
|
121
148
|
await act(async () => {
|
|
122
|
-
wrapper = await create(wrapComponent(
|
|
149
|
+
wrapper = await create(wrapComponent(displayItem, mockDoAction, sensor));
|
|
123
150
|
});
|
|
124
151
|
const instance = wrapper.root;
|
|
125
152
|
|
|
@@ -164,7 +191,7 @@ describe('Test OptionsDropdownActionTemplate', () => {
|
|
|
164
191
|
});
|
|
165
192
|
expect(alertAction.props.visible).toBeFalsy();
|
|
166
193
|
|
|
167
|
-
expect(mockDoAction).toHaveBeenCalledWith(
|
|
194
|
+
expect(mockDoAction).toHaveBeenCalledWith(actionData, {
|
|
168
195
|
level: '1',
|
|
169
196
|
key_code: 1,
|
|
170
197
|
value: 1,
|
|
@@ -185,10 +212,10 @@ describe('Test OptionsDropdownActionTemplate', () => {
|
|
|
185
212
|
});
|
|
186
213
|
|
|
187
214
|
it('doAction with text when have value_text', async () => {
|
|
188
|
-
|
|
215
|
+
displayItem.configuration.options[0].value_text = 'level-1';
|
|
189
216
|
const mockDoAction = jest.fn();
|
|
190
217
|
await act(async () => {
|
|
191
|
-
wrapper = await create(wrapComponent(
|
|
218
|
+
wrapper = await create(wrapComponent(displayItem, mockDoAction, sensor));
|
|
192
219
|
});
|
|
193
220
|
const instance = wrapper.root;
|
|
194
221
|
|
|
@@ -219,7 +246,7 @@ describe('Test OptionsDropdownActionTemplate', () => {
|
|
|
219
246
|
);
|
|
220
247
|
expect(listChoosingOption).toHaveLength(2);
|
|
221
248
|
|
|
222
|
-
//
|
|
249
|
+
// Choose Level1 option
|
|
223
250
|
await act(async () => {
|
|
224
251
|
await listChoosingOption[0].props.onPress();
|
|
225
252
|
});
|
|
@@ -233,7 +260,7 @@ describe('Test OptionsDropdownActionTemplate', () => {
|
|
|
233
260
|
});
|
|
234
261
|
expect(alertAction.props.visible).toBeFalsy();
|
|
235
262
|
|
|
236
|
-
expect(mockDoAction).toHaveBeenCalledWith(
|
|
263
|
+
expect(mockDoAction).toHaveBeenCalledWith(actionData, {
|
|
237
264
|
level: 'level-1',
|
|
238
265
|
key_code: 1,
|
|
239
266
|
value: 1,
|
|
@@ -242,13 +269,88 @@ describe('Test OptionsDropdownActionTemplate', () => {
|
|
|
242
269
|
expect(texts[1].props.children).toEqual('Level2');
|
|
243
270
|
});
|
|
244
271
|
|
|
272
|
+
it('doAction without value_text', async () => {
|
|
273
|
+
delete displayItem.configuration.options[0].value_text;
|
|
274
|
+
|
|
275
|
+
const mockDoAction = jest.fn();
|
|
276
|
+
await act(async () => {
|
|
277
|
+
wrapper = await create(wrapComponent(displayItem, mockDoAction, sensor));
|
|
278
|
+
});
|
|
279
|
+
const instance = wrapper.root;
|
|
280
|
+
|
|
281
|
+
const touchs = instance.findAllByType(TouchableOpacity);
|
|
282
|
+
const showListOption = touchs[0];
|
|
283
|
+
|
|
284
|
+
const alertAction = instance.findByType(AlertAction);
|
|
285
|
+
await act(async () => {
|
|
286
|
+
await showListOption.props.onPress();
|
|
287
|
+
});
|
|
288
|
+
const listChoosingOption = instance.findAll(
|
|
289
|
+
(el) =>
|
|
290
|
+
el.props.accessibilityLabel ===
|
|
291
|
+
AccessibilityLabel.OPTIONS_DROPDOWN_ACTION_CHOOSING_ITEM &&
|
|
292
|
+
el.type === TouchableOpacity
|
|
293
|
+
);
|
|
294
|
+
await act(async () => {
|
|
295
|
+
await listChoosingOption[0].props.onPress();
|
|
296
|
+
});
|
|
297
|
+
|
|
298
|
+
await act(async () => {
|
|
299
|
+
await alertAction.props.rightButtonClick();
|
|
300
|
+
});
|
|
301
|
+
|
|
302
|
+
expect(mockDoAction).toHaveBeenCalledWith(actionData, {
|
|
303
|
+
level: 1,
|
|
304
|
+
key_code: 1,
|
|
305
|
+
value: 1,
|
|
306
|
+
});
|
|
307
|
+
});
|
|
308
|
+
|
|
309
|
+
it('doAction with allow config value', async () => {
|
|
310
|
+
displayItem.configuration.allow_config_store_value = true;
|
|
311
|
+
|
|
312
|
+
const mockDoAction = jest.fn();
|
|
313
|
+
await act(async () => {
|
|
314
|
+
wrapper = await create(wrapComponent(displayItem, mockDoAction, sensor));
|
|
315
|
+
});
|
|
316
|
+
const instance = wrapper.root;
|
|
317
|
+
|
|
318
|
+
const touchs = instance.findAllByType(TouchableOpacity);
|
|
319
|
+
const showListOption = touchs[0];
|
|
320
|
+
|
|
321
|
+
await act(async () => {
|
|
322
|
+
await showListOption.props.onPress();
|
|
323
|
+
});
|
|
324
|
+
const listChoosingOption = instance.findAll(
|
|
325
|
+
(el) =>
|
|
326
|
+
el.props.accessibilityLabel ===
|
|
327
|
+
AccessibilityLabel.OPTIONS_DROPDOWN_ACTION_CHOOSING_ITEM &&
|
|
328
|
+
el.type === TouchableOpacity
|
|
329
|
+
);
|
|
330
|
+
await act(async () => {
|
|
331
|
+
await listChoosingOption[0].props.onPress();
|
|
332
|
+
});
|
|
333
|
+
const alertAction = instance.findByType(AlertAction);
|
|
334
|
+
await act(async () => {
|
|
335
|
+
await alertAction.props.rightButtonClick();
|
|
336
|
+
});
|
|
337
|
+
|
|
338
|
+
expect(mockDoAction).toHaveBeenCalledWith(actionData, {
|
|
339
|
+
level: 1,
|
|
340
|
+
key_code: 1,
|
|
341
|
+
value: 1,
|
|
342
|
+
config_id: 5,
|
|
343
|
+
config_value: 1,
|
|
344
|
+
});
|
|
345
|
+
});
|
|
346
|
+
|
|
245
347
|
it('render template without read config', async () => {
|
|
246
|
-
delete
|
|
348
|
+
delete displayItem.configuration.config;
|
|
247
349
|
sensor.is_managed_by_backend = true;
|
|
248
350
|
|
|
249
351
|
const mockDoAction = jest.fn();
|
|
250
352
|
await act(async () => {
|
|
251
|
-
wrapper = await create(wrapComponent(
|
|
353
|
+
wrapper = await create(wrapComponent(displayItem, mockDoAction, sensor));
|
|
252
354
|
});
|
|
253
355
|
const instance = wrapper.root;
|
|
254
356
|
await act(async () => {
|
|
@@ -266,11 +368,11 @@ describe('Test OptionsDropdownActionTemplate', () => {
|
|
|
266
368
|
});
|
|
267
369
|
|
|
268
370
|
it('doAction sensor device type is GOOGLE_HOME', async () => {
|
|
269
|
-
|
|
371
|
+
displayItem.configuration.options[0].value_text = 'level-1';
|
|
270
372
|
sensor.device_type = DEVICE_TYPE.GOOGLE_HOME;
|
|
271
373
|
const mockDoAction = jest.fn();
|
|
272
374
|
await act(async () => {
|
|
273
|
-
wrapper = await create(wrapComponent(
|
|
375
|
+
wrapper = await create(wrapComponent(displayItem, mockDoAction, sensor));
|
|
274
376
|
});
|
|
275
377
|
const instance = wrapper.root;
|
|
276
378
|
const touchs = instance.findAllByType(TouchableOpacity);
|
|
@@ -313,6 +415,6 @@ describe('Test OptionsDropdownActionTemplate', () => {
|
|
|
313
415
|
});
|
|
314
416
|
expect(alertAction.props.visible).toBeFalsy();
|
|
315
417
|
|
|
316
|
-
expect(mockDoAction).toHaveBeenCalledWith(
|
|
418
|
+
expect(mockDoAction).toHaveBeenCalledWith(actionData, 'level-1');
|
|
317
419
|
});
|
|
318
420
|
});
|
|
@@ -14,21 +14,17 @@ jest.mock('../../../iot/states', () => ({
|
|
|
14
14
|
useConfigGlobalState: jest.fn(),
|
|
15
15
|
}));
|
|
16
16
|
|
|
17
|
-
const wrapComponent = (
|
|
17
|
+
const wrapComponent = (item, doAction, sensor) => (
|
|
18
18
|
<SCProvider initState={mockSCStore({})}>
|
|
19
|
-
<SliderRangeTemplate
|
|
20
|
-
actionGroup={actionGroup}
|
|
21
|
-
doAction={doAction}
|
|
22
|
-
sensor={sensor}
|
|
23
|
-
/>
|
|
19
|
+
<SliderRangeTemplate item={item} doAction={doAction} sensor={sensor} />
|
|
24
20
|
</SCProvider>
|
|
25
21
|
);
|
|
26
22
|
|
|
27
23
|
describe('Test SliderRangeTemplate', () => {
|
|
28
24
|
let wrapper;
|
|
29
|
-
let
|
|
25
|
+
let displayItem;
|
|
30
26
|
|
|
31
|
-
const
|
|
27
|
+
const actionData = {
|
|
32
28
|
color: '#00979D',
|
|
33
29
|
command_prefer_over_bluetooth: false,
|
|
34
30
|
command_prefer_over_googlehome: false,
|
|
@@ -40,11 +36,11 @@ describe('Test SliderRangeTemplate', () => {
|
|
|
40
36
|
jest.useFakeTimers();
|
|
41
37
|
watchMultiConfigs.mockClear();
|
|
42
38
|
mockDoAction.mockClear();
|
|
43
|
-
|
|
39
|
+
displayItem = {
|
|
44
40
|
template: 'ColorPickerTemplate',
|
|
45
41
|
configuration: {
|
|
46
42
|
config: 5,
|
|
47
|
-
action_data,
|
|
43
|
+
action_data: actionData,
|
|
48
44
|
},
|
|
49
45
|
title: '',
|
|
50
46
|
};
|
|
@@ -54,7 +50,7 @@ describe('Test SliderRangeTemplate', () => {
|
|
|
54
50
|
useConfigGlobalState.mockImplementation(() => [{}, jest.fn()]);
|
|
55
51
|
const sensor = { is_managed_by_backend: true, name: 'Sensor' };
|
|
56
52
|
await act(async () => {
|
|
57
|
-
wrapper = await create(wrapComponent(
|
|
53
|
+
wrapper = await create(wrapComponent(displayItem, mockDoAction, sensor));
|
|
58
54
|
});
|
|
59
55
|
const instance = wrapper.root;
|
|
60
56
|
const silderRange = instance.findAllByType(Slider);
|
|
@@ -63,7 +59,7 @@ describe('Test SliderRangeTemplate', () => {
|
|
|
63
59
|
await silderRange[0].props.onSlidingComplete([50]);
|
|
64
60
|
});
|
|
65
61
|
expect(mockDoAction).toHaveBeenCalledWith(
|
|
66
|
-
|
|
62
|
+
actionData,
|
|
67
63
|
JSON.stringify({ value_brness: 50, value: 50 })
|
|
68
64
|
);
|
|
69
65
|
});
|
|
@@ -79,7 +75,7 @@ describe('Test SliderRangeTemplate', () => {
|
|
|
79
75
|
]);
|
|
80
76
|
const sensor = { is_managed_by_backend: true, name: 'Sensor' };
|
|
81
77
|
await act(async () => {
|
|
82
|
-
wrapper = await create(wrapComponent(
|
|
78
|
+
wrapper = await create(wrapComponent(displayItem, mockDoAction, sensor));
|
|
83
79
|
});
|
|
84
80
|
const instance = wrapper.root;
|
|
85
81
|
const silderRange = instance.findByType(Slider);
|
|
@@ -98,7 +94,7 @@ describe('Test SliderRangeTemplate', () => {
|
|
|
98
94
|
const sensor = { is_managed_by_backend: true, name: 'Sensor' };
|
|
99
95
|
|
|
100
96
|
await act(async () => {
|
|
101
|
-
wrapper = await create(wrapComponent(
|
|
97
|
+
wrapper = await create(wrapComponent(displayItem, mockDoAction, sensor));
|
|
102
98
|
});
|
|
103
99
|
const instance = wrapper.root;
|
|
104
100
|
const textInput = instance.findByType(_TextInput);
|
|
@@ -122,7 +118,7 @@ describe('Test SliderRangeTemplate', () => {
|
|
|
122
118
|
const sensor = { is_managed_by_backend: true, name: 'Sensor' };
|
|
123
119
|
|
|
124
120
|
await act(async () => {
|
|
125
|
-
wrapper = await create(wrapComponent(
|
|
121
|
+
wrapper = await create(wrapComponent(displayItem, mockDoAction, sensor));
|
|
126
122
|
});
|
|
127
123
|
|
|
128
124
|
const instance = wrapper.root;
|
|
@@ -135,7 +131,7 @@ describe('Test SliderRangeTemplate', () => {
|
|
|
135
131
|
jest.runAllTimers();
|
|
136
132
|
});
|
|
137
133
|
expect(mockDoAction).toHaveBeenCalledWith(
|
|
138
|
-
|
|
134
|
+
actionData,
|
|
139
135
|
JSON.stringify({ value_brness: 60, value: 60 })
|
|
140
136
|
);
|
|
141
137
|
});
|
|
@@ -3,6 +3,7 @@ import { TouchableOpacity } from 'react-native';
|
|
|
3
3
|
import { act, create } from 'react-test-renderer';
|
|
4
4
|
import Text from '../../Text';
|
|
5
5
|
import StatesGridActionTemplate from '../StatesGridActionTemplate';
|
|
6
|
+
import { DEVICE_TYPE } from '../../../configs/Constants';
|
|
6
7
|
|
|
7
8
|
const mockDoAction = jest.fn();
|
|
8
9
|
const mockActionData = jest.fn();
|
|
@@ -16,61 +17,95 @@ jest.mock('@react-navigation/native', () => {
|
|
|
16
17
|
|
|
17
18
|
describe('Test StatesGridActionTemplate', () => {
|
|
18
19
|
let tree;
|
|
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
|
-
|
|
20
|
+
let displayItem;
|
|
21
|
+
let sensor;
|
|
22
|
+
|
|
23
|
+
beforeEach(() => {
|
|
24
|
+
mockDoAction.mockReset();
|
|
25
|
+
displayItem = {
|
|
26
|
+
configuration: {
|
|
27
|
+
options: [
|
|
28
|
+
{
|
|
29
|
+
config: 1,
|
|
30
|
+
active: false,
|
|
31
|
+
text: 'item 1',
|
|
32
|
+
icon_kit_data: 'icon_kit_data',
|
|
33
|
+
icon: '123',
|
|
34
|
+
action_data: mockActionData,
|
|
35
|
+
},
|
|
36
|
+
{
|
|
37
|
+
config: 2,
|
|
38
|
+
active: true,
|
|
39
|
+
text: 'item 2',
|
|
40
|
+
icon_kit_data: 'icon_kit_data',
|
|
41
|
+
icon: 'icon',
|
|
42
|
+
action_data: mockActionData,
|
|
43
|
+
},
|
|
44
|
+
],
|
|
45
|
+
is_on_value: true,
|
|
46
|
+
},
|
|
47
|
+
title: 'Title',
|
|
48
|
+
};
|
|
49
|
+
sensor = {
|
|
50
|
+
is_managed_by_backend: true,
|
|
51
|
+
device_type: '',
|
|
52
|
+
|
|
53
|
+
name: 'Sensor name',
|
|
54
|
+
};
|
|
55
|
+
});
|
|
48
56
|
|
|
49
57
|
it('test render without params', async () => {
|
|
50
58
|
await act(async () => {
|
|
51
59
|
tree = await create(<StatesGridActionTemplate />);
|
|
52
60
|
});
|
|
53
61
|
const instance = tree.root;
|
|
54
|
-
const
|
|
55
|
-
expect(
|
|
62
|
+
const texts = instance.findAllByType(Text);
|
|
63
|
+
expect(texts).not.toHaveLength(1);
|
|
56
64
|
});
|
|
57
65
|
|
|
58
|
-
it('test
|
|
66
|
+
it('test trigger action', async () => {
|
|
59
67
|
await act(async () => {
|
|
60
68
|
tree = await create(
|
|
61
69
|
<StatesGridActionTemplate
|
|
62
70
|
doAction={mockDoAction}
|
|
63
71
|
sensor={sensor}
|
|
64
|
-
|
|
72
|
+
item={displayItem}
|
|
65
73
|
/>
|
|
66
74
|
);
|
|
67
75
|
});
|
|
68
76
|
const instance = tree.root;
|
|
69
|
-
const
|
|
70
|
-
expect(
|
|
71
|
-
const
|
|
72
|
-
expect(
|
|
73
|
-
await
|
|
77
|
+
const texts = instance.findAllByType(Text);
|
|
78
|
+
expect(texts).toHaveLength(3);
|
|
79
|
+
const touchableOpacities = instance.findAllByType(TouchableOpacity);
|
|
80
|
+
expect(touchableOpacities).toHaveLength(2);
|
|
81
|
+
await act(async () => {
|
|
82
|
+
await touchableOpacities[0].props.onPress();
|
|
83
|
+
});
|
|
74
84
|
expect(mockDoAction).toBeCalledWith(mockActionData, null);
|
|
75
85
|
});
|
|
86
|
+
|
|
87
|
+
it('test trigger special action', async () => {
|
|
88
|
+
displayItem.configuration.options[0].allow_config_store_value = true;
|
|
89
|
+
displayItem.configuration.options[0].config = 1;
|
|
90
|
+
sensor.device_type = DEVICE_TYPE.LG_THINQ;
|
|
91
|
+
|
|
92
|
+
await act(async () => {
|
|
93
|
+
tree = await create(
|
|
94
|
+
<StatesGridActionTemplate
|
|
95
|
+
doAction={mockDoAction}
|
|
96
|
+
sensor={sensor}
|
|
97
|
+
item={displayItem}
|
|
98
|
+
/>
|
|
99
|
+
);
|
|
100
|
+
});
|
|
101
|
+
const instance = tree.root;
|
|
102
|
+
const touchableOpacities = instance.findAllByType(TouchableOpacity);
|
|
103
|
+
await act(async () => {
|
|
104
|
+
await touchableOpacities[0].props.onPress();
|
|
105
|
+
});
|
|
106
|
+
expect(mockDoAction).toBeCalledWith(
|
|
107
|
+
mockActionData,
|
|
108
|
+
JSON.stringify({ config_id: 1, config_value: undefined })
|
|
109
|
+
);
|
|
110
|
+
});
|
|
76
111
|
});
|
|
@@ -11,13 +11,9 @@ jest.mock('../../../iot/states', () => ({
|
|
|
11
11
|
useConfigGlobalState: jest.fn(),
|
|
12
12
|
}));
|
|
13
13
|
|
|
14
|
-
const wrapComponent = (
|
|
14
|
+
const wrapComponent = (item, mockDoAction, isOn) => (
|
|
15
15
|
<SCProvider initState={mockSCStore({})}>
|
|
16
|
-
<SwitchButtonTemplate
|
|
17
|
-
actionGroup={actionGroup}
|
|
18
|
-
doAction={mockDoAction}
|
|
19
|
-
isOn={isOn}
|
|
20
|
-
/>
|
|
16
|
+
<SwitchButtonTemplate item={item} doAction={mockDoAction} isOn={isOn} />
|
|
21
17
|
</SCProvider>
|
|
22
18
|
);
|
|
23
19
|
|
|
@@ -29,7 +25,7 @@ jest.mock('@react-navigation/native', () => {
|
|
|
29
25
|
});
|
|
30
26
|
|
|
31
27
|
describe('Test SwitchButtonTemplate', () => {
|
|
32
|
-
const
|
|
28
|
+
const actionOnData = {
|
|
33
29
|
color: '#00979D',
|
|
34
30
|
command_prefer_over_bluetooth: true,
|
|
35
31
|
command_prefer_over_googlehome: false,
|
|
@@ -40,7 +36,7 @@ describe('Test SwitchButtonTemplate', () => {
|
|
|
40
36
|
key: '5ed1d4dc-a905-47cd-b0c9-f979644bd21a',
|
|
41
37
|
};
|
|
42
38
|
|
|
43
|
-
const
|
|
39
|
+
const actionOffData = {
|
|
44
40
|
color: '#00979D',
|
|
45
41
|
command_prefer_over_bluetooth: true,
|
|
46
42
|
command_prefer_over_googlehome: false,
|
|
@@ -50,14 +46,14 @@ describe('Test SwitchButtonTemplate', () => {
|
|
|
50
46
|
id: 20,
|
|
51
47
|
key: '5ed1d4dc-a905-47cd-b0c9-f979644bd21a',
|
|
52
48
|
};
|
|
53
|
-
const
|
|
49
|
+
const displayItem = {
|
|
54
50
|
configuration: {
|
|
55
51
|
action_on: '5ed1d4dc-a905-47cd-b0c9-f979644bd21a',
|
|
56
|
-
action_on_data:
|
|
52
|
+
action_on_data: actionOnData,
|
|
57
53
|
icon_on: 'caret-up',
|
|
58
54
|
text_on: 'ON',
|
|
59
55
|
action_off: '5ed1d4dc-a905-47cd-b0c9-f979644bd21b',
|
|
60
|
-
action_off_data:
|
|
56
|
+
action_off_data: actionOffData,
|
|
61
57
|
icon_off: 'caret-up',
|
|
62
58
|
text_off: 'OFF',
|
|
63
59
|
config: 1,
|
|
@@ -69,7 +65,7 @@ describe('Test SwitchButtonTemplate', () => {
|
|
|
69
65
|
const mockDoAction = jest.fn();
|
|
70
66
|
|
|
71
67
|
await act(async () => {
|
|
72
|
-
wrapper = await create(wrapComponent(
|
|
68
|
+
wrapper = await create(wrapComponent(displayItem, mockDoAction));
|
|
73
69
|
});
|
|
74
70
|
|
|
75
71
|
const renderJson = wrapper.toJSON();
|
|
@@ -107,7 +103,7 @@ describe('Test SwitchButtonTemplate', () => {
|
|
|
107
103
|
const assertActionCall = async (state, action_data) => {
|
|
108
104
|
const mockDoAction = jest.fn();
|
|
109
105
|
await act(async () => {
|
|
110
|
-
wrapper = await create(wrapComponent(
|
|
106
|
+
wrapper = await create(wrapComponent(displayItem, mockDoAction, state));
|
|
111
107
|
});
|
|
112
108
|
expect(mockDoAction).not.toHaveBeenCalled();
|
|
113
109
|
const root = wrapper.root;
|
|
@@ -121,10 +117,10 @@ describe('Test SwitchButtonTemplate', () => {
|
|
|
121
117
|
};
|
|
122
118
|
|
|
123
119
|
it('action state on', async () => {
|
|
124
|
-
await assertActionCall(true,
|
|
120
|
+
await assertActionCall(true, actionOffData);
|
|
125
121
|
});
|
|
126
122
|
|
|
127
123
|
it('action state off', async () => {
|
|
128
|
-
await assertActionCall(false,
|
|
124
|
+
await assertActionCall(false, actionOnData);
|
|
129
125
|
});
|
|
130
126
|
});
|
|
@@ -26,18 +26,14 @@ jest.mock('@react-navigation/native', () => {
|
|
|
26
26
|
|
|
27
27
|
const mockDoAction = jest.fn();
|
|
28
28
|
|
|
29
|
-
const wrapComponent = (
|
|
29
|
+
const wrapComponent = (item, sensor) => (
|
|
30
30
|
<SCProvider initState={mockSCStore({})}>
|
|
31
|
-
<TimerActionTemplate
|
|
32
|
-
actionGroup={actionGroup}
|
|
33
|
-
doAction={mockDoAction}
|
|
34
|
-
sensor={sensor}
|
|
35
|
-
/>
|
|
31
|
+
<TimerActionTemplate item={item} doAction={mockDoAction} sensor={sensor} />
|
|
36
32
|
</SCProvider>
|
|
37
33
|
);
|
|
38
34
|
|
|
39
35
|
describe('Test TimerActionTemplate success with config value', () => {
|
|
40
|
-
const
|
|
36
|
+
const actionData = {
|
|
41
37
|
color: '#00979D',
|
|
42
38
|
command_prefer_over_bluetooth: true,
|
|
43
39
|
command_prefer_over_googlehome: false,
|
|
@@ -48,16 +44,16 @@ describe('Test TimerActionTemplate success with config value', () => {
|
|
|
48
44
|
key: '5ed1d4dc-a905-47cd-b0c9-f979644bd21a',
|
|
49
45
|
};
|
|
50
46
|
|
|
51
|
-
let
|
|
47
|
+
let displayItem;
|
|
52
48
|
let wrapper;
|
|
53
49
|
let sensor;
|
|
54
50
|
|
|
55
51
|
beforeEach(() => {
|
|
56
52
|
watchMultiConfigs.mockClear();
|
|
57
|
-
|
|
53
|
+
displayItem = {
|
|
58
54
|
title: 'Timer',
|
|
59
55
|
configuration: {
|
|
60
|
-
action_data,
|
|
56
|
+
action_data: actionData,
|
|
61
57
|
config_hour: 5,
|
|
62
58
|
config_minute: 6,
|
|
63
59
|
},
|
|
@@ -79,7 +75,7 @@ describe('Test TimerActionTemplate success with config value', () => {
|
|
|
79
75
|
|
|
80
76
|
it('render template', async () => {
|
|
81
77
|
await act(async () => {
|
|
82
|
-
wrapper = await create(wrapComponent(
|
|
78
|
+
wrapper = await create(wrapComponent(displayItem, sensor));
|
|
83
79
|
});
|
|
84
80
|
const instance = wrapper.root;
|
|
85
81
|
|
|
@@ -107,16 +103,16 @@ describe('Test TimerActionTemplate success with config value', () => {
|
|
|
107
103
|
});
|
|
108
104
|
|
|
109
105
|
it('render template with config_hour', async () => {
|
|
110
|
-
|
|
111
|
-
...
|
|
106
|
+
displayItem = {
|
|
107
|
+
...displayItem,
|
|
112
108
|
configuration: {
|
|
113
|
-
...
|
|
109
|
+
...displayItem.configuration,
|
|
114
110
|
config_hour: 5,
|
|
115
111
|
config_minute: null,
|
|
116
112
|
},
|
|
117
113
|
};
|
|
118
114
|
await act(async () => {
|
|
119
|
-
wrapper = await create(wrapComponent(
|
|
115
|
+
wrapper = await create(wrapComponent(displayItem, sensor));
|
|
120
116
|
});
|
|
121
117
|
const instance = wrapper.root;
|
|
122
118
|
|