@eohjsc/react-native-smart-city 0.3.21 → 0.3.24

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.
Files changed (104) hide show
  1. package/index.js +2 -0
  2. package/package.json +2 -1
  3. package/src/Images/Common/buttonLeftCurtain.png +0 -0
  4. package/src/Images/Common/buttonLeftCurtain@2x.png +0 -0
  5. package/src/Images/Common/buttonLeftCurtain@3x.png +0 -0
  6. package/src/commons/Action/ItemQuickAction.js +1 -12
  7. package/src/commons/Action/__test__/ItemQuickAction.test.js +1 -1
  8. package/src/commons/ActionGroup/ColorPickerTemplate.js +2 -9
  9. package/src/commons/ActionGroup/CurtainButtonTemplate.js +14 -21
  10. package/src/commons/ActionGroup/CurtainButtonTemplateStyle.js +5 -0
  11. package/src/commons/ActionGroup/NumberUpDownActionTemplate.js +12 -24
  12. package/src/commons/ActionGroup/OnOffSmartLock/OnOffSmartLock.js +10 -17
  13. package/src/commons/ActionGroup/OnOffTemplate/index.js +10 -35
  14. package/src/commons/ActionGroup/OneBigButtonTemplate.js +2 -3
  15. package/src/commons/ActionGroup/OptionsDropdownActionTemplate.js +7 -8
  16. package/src/commons/ActionGroup/SliderRangeTemplate.js +3 -10
  17. package/src/commons/ActionGroup/StatesGridActionTemplate.js +9 -24
  18. package/src/commons/ActionGroup/ThreeButtonTemplate.js +6 -9
  19. package/src/commons/ActionGroup/TimerActionTemplate.js +11 -4
  20. package/src/commons/ActionGroup/TwoButtonTemplate/index.js +18 -33
  21. package/src/commons/ActionGroup/__test__/CurtainButtonTemplate.test.js +3 -15
  22. package/src/commons/ActionGroup/__test__/NumberUpDownTemplate.test.js +38 -4
  23. package/src/commons/ActionGroup/__test__/OnOffButtonTemplate.test.js +7 -0
  24. package/src/commons/ActionGroup/__test__/OnOffSmartLock.test.js +17 -12
  25. package/src/commons/ActionGroup/__test__/OnOffTemplate.test.js +11 -16
  26. package/src/commons/ActionGroup/__test__/OneBigButtonTemplate.test.js +1 -1
  27. package/src/commons/ActionGroup/__test__/OptionsDropdownTemplate.test.js +11 -10
  28. package/src/commons/ActionGroup/__test__/StatesGridActionTemplate.test.js +8 -7
  29. package/src/commons/ActionGroup/__test__/TimerActionTemplate.test.js +8 -1
  30. package/src/commons/ActionGroup/__test__/TimerActionTemplateWithutConfigValue.test.js +7 -0
  31. package/src/commons/ActionGroup/__test__/TwoButtonTemplate.test.js +17 -2
  32. package/src/commons/ActionGroup/__test__/index.test.js +15 -18
  33. package/src/commons/ConnectingProcess/index.js +6 -25
  34. package/src/commons/Device/HistoryChart.js +8 -6
  35. package/src/commons/Device/ItemDevice.js +79 -35
  36. package/src/commons/MediaPlayerDetail/index.js +5 -0
  37. package/src/commons/RowItem/index.js +6 -2
  38. package/src/commons/SubUnit/Favorites/index.js +24 -6
  39. package/src/commons/SubUnit/ShortDetail.js +31 -5
  40. package/src/commons/SubUnit/__test__/Favorites.test.js +1 -0
  41. package/src/commons/SubUnit/__test__/ShortDetail.test.js +1 -0
  42. package/src/configs/API.js +9 -4
  43. package/src/configs/Constants.js +8 -2
  44. package/src/configs/SCConfig.js +4 -0
  45. package/src/context/actionType.ts +7 -5
  46. package/src/context/mockStore.ts +10 -3
  47. package/src/context/reducer.ts +29 -15
  48. package/src/hoc/index.js +3 -0
  49. package/src/hoc/withRemoteControl.js +10 -0
  50. package/src/hooks/Common/index.js +2 -2
  51. package/src/hooks/Common/useDevicesStatus.js +57 -0
  52. package/src/hooks/Common/useGGHomeDeviceConnected.js +3 -3
  53. package/src/hooks/IoT/__test__/useGGHomeConnection.test.js +1 -2
  54. package/src/hooks/IoT/__test__/useRemoteControl.test.js +9 -11
  55. package/src/hooks/IoT/index.js +9 -1
  56. package/src/hooks/IoT/useGGHomeConnection.js +0 -1
  57. package/src/hooks/IoT/useRemoteControl.js +2 -3
  58. package/src/hooks/IoT/useUnwatchLGDeviceConfigControl.js +29 -0
  59. package/src/hooks/IoT/useValueEvaluation.js +17 -4
  60. package/src/hooks/IoT/useWatchConfigs.js +34 -0
  61. package/src/iot/Monitor.js +13 -20
  62. package/src/iot/RemoteControl/GoogleHome.js +12 -13
  63. package/src/iot/RemoteControl/Internet.js +1 -8
  64. package/src/iot/RemoteControl/LG.js +1 -0
  65. package/src/iot/RemoteControl/__test__/GoogleHome.test.js +7 -2
  66. package/src/navigations/UnitStack.js +27 -3
  67. package/src/screens/AddNewAction/SelectAction.js +1 -1
  68. package/src/screens/AddNewAction/SetupSensor.js +4 -0
  69. package/src/screens/AddNewGateway/PlugAndPlay/ConnectWifiWarning.js +44 -78
  70. package/src/screens/AddNewGateway/PlugAndPlay/GatewayWifiList.js +15 -35
  71. package/src/screens/AddNewGateway/PlugAndPlay/__test__/GatewayWifiList.test.js +2 -0
  72. package/src/screens/AllCamera/__test__/index.test.js +1 -1
  73. package/src/screens/Device/__test__/detail.test.js +1 -54
  74. package/src/screens/Device/components/SensorConnectStatusViewHeader.js +18 -8
  75. package/src/screens/Device/components/SensorDisplayItem.js +2 -2
  76. package/src/screens/Device/detail.js +36 -30
  77. package/src/screens/Device/hooks/__test__/useEvaluateValue.test.js +102 -0
  78. package/src/screens/Device/hooks/useDeviceWatchConfigControl.js +20 -0
  79. package/src/screens/Device/utils/index.js +45 -0
  80. package/src/screens/Device/utils/index.test.js +111 -0
  81. package/src/screens/EmergencyContacts/EmergencyContactsAddNew.js +35 -22
  82. package/src/screens/EmergencyContacts/EmergencyContactsSelectContacts.js +2 -1
  83. package/src/screens/EmergencyContacts/__test__/EmergencyContactAddNew.test.js +36 -2
  84. package/src/screens/MoveToAnotherSubUnit/__test__/index.test.js +0 -2
  85. package/src/screens/Notification/__test__/NotificationItem.test.js +84 -19
  86. package/src/screens/Notification/components/NotificationItem.js +64 -31
  87. package/src/screens/PlayBackCamera/index.js +22 -6
  88. package/src/screens/ScriptDetail/hooks/useStarredScript.js +2 -2
  89. package/src/screens/SubUnit/AddSubUnit.js +2 -1
  90. package/src/screens/Unit/AddMenu.js +4 -0
  91. package/src/screens/Unit/{SelectFavoritesDevices.js → SelectAddToFavorites.js} +81 -26
  92. package/src/screens/Unit/{SelectFavoritesDevicesStyles.js → SelectAddToFavoritesStyles.js} +0 -0
  93. package/src/screens/Unit/__test__/CheckSendEmail.test.js +12 -0
  94. package/src/screens/Unit/__test__/Detail.test.js +2 -3
  95. package/src/screens/Unit/__test__/SelectAddToFavorites.test.js +267 -0
  96. package/src/screens/Unit/components/AutomateScript/index.js +65 -0
  97. package/src/screens/Unit/components/AutomateScript/styles.js +48 -0
  98. package/src/screens/Unit/components/MyUnitDevice/index.js +4 -2
  99. package/src/screens/UnitSummary/components/3PPowerConsumption/index.js +4 -2
  100. package/src/utils/I18n/translations/en.json +7 -2
  101. package/src/utils/I18n/translations/vi.json +6 -1
  102. package/src/utils/Route/index.js +1 -1
  103. package/src/hooks/Common/useSensorsStatus.js +0 -62
  104. package/src/screens/Unit/__test__/SelectFavoritesDevices.test.js +0 -110
@@ -12,7 +12,9 @@ import styles from './TimerActionTemplateStyles';
12
12
  import Text from '../Text';
13
13
  import { Colors } from '../../configs';
14
14
  import { useConfigGlobalState } from '../../iot/states';
15
+ import { useUnwatchLGDeviceConfigControl } from '../../hooks/IoT';
15
16
  import BottomScrollPicker from '../BottomScrollPicker';
17
+ import { DEVICE_TYPE } from '../../configs/Constants';
16
18
 
17
19
  const TimerActionTemplate = ({ actionGroup = {}, doAction, sensor = {} }) => {
18
20
  const t = useTranslations();
@@ -22,8 +24,8 @@ const TimerActionTemplate = ({ actionGroup = {}, doAction, sensor = {} }) => {
22
24
 
23
25
  // eslint-disable-next-line no-unused-vars
24
26
  const [configValues, setConfigValues] = useConfigGlobalState('configValues');
25
- const configHour = configValues[configuration.config_hour];
26
- const configMinute = configValues[configuration.config_minute];
27
+ const configHour = configValues[configuration.config_hour]?.value;
28
+ const configMinute = configValues[configuration.config_minute]?.value;
27
29
 
28
30
  const dataTime = useMemo(() => {
29
31
  if (
@@ -94,7 +96,7 @@ const TimerActionTemplate = ({ actionGroup = {}, doAction, sensor = {} }) => {
94
96
  if (sensor.is_managed_by_backend) {
95
97
  hour !== undefined &&
96
98
  minute !== undefined &&
97
- sensor.device_type !== 'GOOGLE_HOME' &&
99
+ sensor.device_type !== DEVICE_TYPE.LG_THINQ &&
98
100
  watchMultiConfigs([
99
101
  configuration.config_hour,
100
102
  configuration.config_minute,
@@ -116,7 +118,7 @@ const TimerActionTemplate = ({ actionGroup = {}, doAction, sensor = {} }) => {
116
118
  doAction(configuration.action_data, JSON.stringify({ hour }));
117
119
  if (
118
120
  sensor.is_managed_by_backend &&
119
- sensor.device_type !== 'GOOGLE_HOME'
121
+ sensor.device_type !== DEVICE_TYPE.LG_THINQ
120
122
  ) {
121
123
  hour && watchMultiConfigs([configuration.config_hour]);
122
124
  }
@@ -130,6 +132,11 @@ const TimerActionTemplate = ({ actionGroup = {}, doAction, sensor = {} }) => {
130
132
  ]
131
133
  );
132
134
 
135
+ useUnwatchLGDeviceConfigControl(sensor, [
136
+ configuration.config_minute,
137
+ configuration.config_hour,
138
+ ]);
139
+
133
140
  const onConfirmTime = useCallback(
134
141
  (timeData) => {
135
142
  onHideTime();
@@ -6,6 +6,7 @@ import { Colors } from '../../../configs';
6
6
  import { DEVICE_TYPE, TESTID } from '../../../configs/Constants';
7
7
  import { watchMultiConfigs } from '../../../iot/Monitor';
8
8
  import { useConfigGlobalState } from '../../../iot/states';
9
+ import { useUnwatchLGDeviceConfigControl } from '../../../hooks/IoT';
9
10
  import Text from '../../Text';
10
11
  import styles from './TwoButtonTemplateStyles';
11
12
 
@@ -17,75 +18,68 @@ const TwoButtonTemplate = memo(({ actionGroup, doAction, sensor }) => {
17
18
  const [configValues] = useConfigGlobalState('configValues');
18
19
  const isLight = false;
19
20
 
20
- const actionName = useCallback(
21
- (text) => {
22
- const actionNameType = `${
23
- sensor?.name
24
- } ${actionGroup?.title?.toLowerCase()} ${text}`;
25
- return actionNameType.replace(/\s+/g, ' ').trim();
26
- },
27
- [actionGroup?.title, sensor?.name]
28
- );
29
-
30
21
  const triggerAction1 = useCallback(async () => {
31
22
  if (button1?.action_on_data && button1?.action_off_data) {
32
23
  if (isOn) {
33
- await doAction(button1?.action_off_data, null, actionName('off'));
24
+ await doAction(button1?.action_off_data, null);
34
25
  } else {
35
- await doAction(button1?.action_on_data, null, actionName('on'));
26
+ await doAction(button1?.action_on_data, null);
36
27
  }
37
28
  }
38
29
  if (sensor?.is_managed_by_backend) {
39
30
  configuration.config &&
40
- sensor.device_type !== 'GOOGLE_HOME' &&
31
+ sensor.device_type === DEVICE_TYPE.LG_THINQ &&
41
32
  watchMultiConfigs([configuration.config]);
42
33
  }
43
34
  }, [
44
- actionName,
45
35
  button1,
46
36
  configuration.config,
47
37
  doAction,
48
38
  isOn,
49
39
  sensor?.is_managed_by_backend,
50
- sensor?.device_type,
40
+ sensor.device_type,
51
41
  ]);
52
42
 
53
43
  const triggerAction2 = useCallback(async () => {
54
44
  if (button2?.action_on_data && button2?.action_off_data) {
55
45
  if (isStart) {
56
- await doAction(button2?.action_off_data, null, actionName('stop'));
46
+ await doAction(button2?.action_off_data, null);
57
47
  } else {
58
- await doAction(button2?.action_on_data, null, actionName('start'));
48
+ await doAction(button2?.action_on_data, null);
59
49
  }
60
50
  }
61
- if (sensor?.is_managed_by_backend && sensor.device_type !== 'GOOGLE_HOME') {
51
+ if (
52
+ sensor?.is_managed_by_backend &&
53
+ sensor.device_type === DEVICE_TYPE.LG_THINQ
54
+ ) {
62
55
  configuration.config && watchMultiConfigs([configuration.config]);
63
56
  }
64
57
  }, [
65
- actionName,
66
58
  button2?.action_off_data,
67
59
  button2?.action_on_data,
68
60
  configuration.config,
69
61
  doAction,
70
62
  isStart,
71
63
  sensor?.is_managed_by_backend,
72
- sensor?.device_type,
64
+ sensor.device_type,
73
65
  ]);
74
66
 
67
+ useUnwatchLGDeviceConfigControl(sensor, [configuration.config]);
68
+
75
69
  useEffect(() => {
76
70
  const configValue1 = configValues[button1?.config];
77
71
  const configValue2 = configValues[button2?.config];
78
72
  if (button1?.is_on_value && button1?.is_on_value.length > 0) {
79
- setIsOn(button1?.is_on_value.includes(configValue1));
73
+ setIsOn(button1?.is_on_value.includes(configValue1?.value));
80
74
  return;
81
75
  }
82
76
  if (button2?.is_on_value && button2?.is_on_value.length > 0) {
83
- setIsStart(button2?.is_on_value.includes(configValue2));
77
+ setIsStart(button2?.is_on_value.includes(configValue2?.value));
84
78
  return;
85
79
  }
86
80
 
87
- setIsOn(configValue1);
88
- setIsStart(configValue2);
81
+ setIsOn(configValue1?.value);
82
+ setIsStart(configValue2?.value);
89
83
  }, [
90
84
  configuration.config,
91
85
  configValues,
@@ -97,15 +91,6 @@ const TwoButtonTemplate = memo(({ actionGroup, doAction, sensor }) => {
97
91
  button2?.is_on_value,
98
92
  ]);
99
93
 
100
- useEffect(() => {
101
- if (sensor?.device_type === DEVICE_TYPE.LG_THINQ) {
102
- return;
103
- }
104
- if (sensor?.is_managed_by_backend && sensor.device_type !== 'GOOGLE_HOME') {
105
- watchMultiConfigs([configuration.config]);
106
- }
107
- }, [sensor, configuration.config]);
108
-
109
94
  const RenderTwoButtonAction = () => {
110
95
  const buttons = [
111
96
  {
@@ -97,25 +97,13 @@ describe('Test CurtainButtonTemplate', () => {
97
97
  await touchableOpacities[0].props.onPress();
98
98
  await touchableOpacities[1].props.onPress();
99
99
  await touchableOpacities[2].props.onPress();
100
- expect(mockDoAction).toBeCalledWith(
101
- mockCloseActionData,
102
- null,
103
- sensor?.name + ' undefined'
104
- );
100
+ expect(mockDoAction).toBeCalledWith(mockCloseActionData, null);
105
101
 
106
102
  const Switchs = instance.findAllByType(Switch);
107
103
  expect(Switchs).toHaveLength(1);
108
104
  await Switchs[0].props.onValueChange();
109
- expect(mockDoAction).toBeCalledWith(
110
- mockActionOnData,
111
- null,
112
- `${sensor.name} lock`
113
- );
105
+ expect(mockDoAction).toBeCalledWith(mockActionOnData, null);
114
106
  await Switchs[0].props.onValueChange();
115
- expect(mockDoAction).toBeCalledWith(
116
- mockActionOffData,
117
- null,
118
- `${sensor.name} unlock`
119
- );
107
+ expect(mockDoAction).toBeCalledWith(mockActionOffData, null);
120
108
  });
121
109
  });
@@ -9,9 +9,16 @@ import NumberUpDownActionTemplate from '../NumberUpDownActionTemplate';
9
9
  jest.mock('../../../iot/Monitor');
10
10
 
11
11
  jest.mock('../../../iot/states', () => ({
12
- useConfigGlobalState: () => [{ 5: 25 }, null],
12
+ useConfigGlobalState: () => [{ 5: { value: 25 } }, null],
13
13
  }));
14
14
 
15
+ jest.mock('@react-navigation/native', () => {
16
+ return {
17
+ ...jest.requireActual('@react-navigation/native'),
18
+ useFocusEffect: jest.fn(),
19
+ };
20
+ });
21
+
15
22
  describe('Test NumberUpDownActionTemplate', () => {
16
23
  const action_data = {
17
24
  color: '#00979D',
@@ -90,6 +97,31 @@ describe('Test NumberUpDownActionTemplate', () => {
90
97
  expect(watchMultiConfigs).not.toBeCalled();
91
98
  });
92
99
 
100
+ test('do action not call watchConfigs cause device_type not lq_thinq', async () => {
101
+ const mockDoAction = jest.fn();
102
+ await act(async () => {
103
+ wrapper = await create(
104
+ <NumberUpDownActionTemplate
105
+ actionGroup={actionGroup}
106
+ doAction={mockDoAction}
107
+ sensor={{
108
+ is_managed_by_backend: true,
109
+ device_type: DEVICE_TYPE.ZIGBEE,
110
+ }}
111
+ />
112
+ );
113
+ });
114
+ const instance = wrapper.root;
115
+ const touchs = instance.findAllByType(TouchableOpacity);
116
+ expect(touchs).toHaveLength(2);
117
+
118
+ await act(async () => {
119
+ await touchs[0].props.onPress();
120
+ });
121
+
122
+ expect(watchMultiConfigs).not.toBeCalled();
123
+ });
124
+
93
125
  test('do action watchConfigs cause allow_config_store_value true', async () => {
94
126
  const mockDoAction = jest.fn();
95
127
  actionGroup.configuration.allow_config_store_value = true;
@@ -98,7 +130,10 @@ describe('Test NumberUpDownActionTemplate', () => {
98
130
  <NumberUpDownActionTemplate
99
131
  actionGroup={actionGroup}
100
132
  doAction={mockDoAction}
101
- sensor={{ is_managed_by_backend: true }}
133
+ sensor={{
134
+ is_managed_by_backend: true,
135
+ device_type: DEVICE_TYPE.LG_THINQ,
136
+ }}
102
137
  />
103
138
  );
104
139
  });
@@ -364,8 +399,7 @@ describe('Test NumberUpDownActionTemplate', () => {
364
399
  id: 20,
365
400
  key: '5ed1d4dc-a905-47cd-b0c9-f979644bd21a',
366
401
  },
367
- 26,
368
- 'Device temp up'
402
+ 26
369
403
  );
370
404
  });
371
405
  });
@@ -15,6 +15,13 @@ jest.mock('react', () => ({
15
15
  useState: jest.fn(),
16
16
  }));
17
17
 
18
+ jest.mock('@react-navigation/native', () => {
19
+ return {
20
+ ...jest.requireActual('@react-navigation/native'),
21
+ useFocusEffect: jest.fn(),
22
+ };
23
+ });
24
+
18
25
  describe('Test OneBigButtonTemplate', () => {
19
26
  const action_on_data = {
20
27
  color: '#00979D',
@@ -13,6 +13,13 @@ jest.mock('../../../iot/states', () => ({
13
13
  useConfigGlobalState: jest.fn(),
14
14
  }));
15
15
 
16
+ jest.mock('@react-navigation/native', () => {
17
+ return {
18
+ ...jest.requireActual('@react-navigation/native'),
19
+ useFocusEffect: jest.fn(),
20
+ };
21
+ });
22
+
16
23
  const wrapComponent = (actionGroup, doAction, sensor) => (
17
24
  <SCProvider initState={mockSCStore({})}>
18
25
  <OnOffSmartLock
@@ -65,7 +72,10 @@ describe('Test OnOffTemplate', () => {
65
72
  });
66
73
 
67
74
  test('render with template OnOffSmartLockActionTemplate doAction lock', async () => {
68
- useConfigGlobalState.mockImplementation(() => [{ 5: 2 }, jest.fn()]);
75
+ useConfigGlobalState.mockImplementation(() => [
76
+ { 5: { value: 2 } },
77
+ jest.fn(),
78
+ ]);
69
79
  const sensor = { is_managed_by_backend: true, name: 'Sensor' };
70
80
  await act(async () => {
71
81
  wrapper = await create(wrapComponent(actionGroup, mockDoAction, sensor));
@@ -77,17 +87,16 @@ describe('Test OnOffTemplate', () => {
77
87
  await act(async () => {
78
88
  await button.props.onPress();
79
89
  });
80
- expect(mockDoAction).toBeCalledWith(
81
- action_on_data,
82
- '{"door_lock":0}',
83
- 'Sensor smartlock lock'
84
- );
90
+ expect(mockDoAction).toBeCalledWith(action_on_data, '{"door_lock":0}');
85
91
  });
86
92
 
87
93
  test('render with template OnOffSmartLockActionTemplate doAction unlock', async () => {
88
94
  actionGroup.configuration.is_on_value = null;
89
95
  const sensor = { is_managed_by_backend: false, name: 'Sensor' };
90
- useConfigGlobalState.mockImplementation(() => [{ 5: 0 }, jest.fn()]);
96
+ useConfigGlobalState.mockImplementation(() => [
97
+ { 5: { value: 0 } },
98
+ jest.fn(),
99
+ ]);
91
100
  await act(async () => {
92
101
  wrapper = await create(wrapComponent(actionGroup, mockDoAction, sensor));
93
102
  });
@@ -98,10 +107,6 @@ describe('Test OnOffTemplate', () => {
98
107
  await act(async () => {
99
108
  await button.props.onPress();
100
109
  });
101
- expect(mockDoAction).toBeCalledWith(
102
- action_off_data,
103
- '{"door_lock":1}',
104
- 'Sensor smartlock unlock'
105
- );
110
+ expect(mockDoAction).toBeCalledWith(action_off_data, '{"door_lock":1}');
106
111
  });
107
112
  });
@@ -24,7 +24,7 @@ const wrapComponent = (actionGroup, mockDoAction, sensor) => (
24
24
  jest.mock('../../../iot/Monitor');
25
25
 
26
26
  jest.mock('../../../iot/states', () => ({
27
- useConfigGlobalState: () => [{ 5: 2 }, null],
27
+ useConfigGlobalState: () => [{ 5: { value: 2 } }, null],
28
28
  }));
29
29
 
30
30
  jest.mock('react-redux', () => ({
@@ -32,6 +32,13 @@ jest.mock('react-redux', () => ({
32
32
  useSelector: jest.fn(),
33
33
  }));
34
34
 
35
+ jest.mock('@react-navigation/native', () => {
36
+ return {
37
+ ...jest.requireActual('@react-navigation/native'),
38
+ useFocusEffect: jest.fn(),
39
+ };
40
+ });
41
+
35
42
  describe('Test OnOffTemplate', () => {
36
43
  let actionGroup;
37
44
  let tree;
@@ -157,11 +164,7 @@ describe('Test OnOffTemplate', () => {
157
164
  await act(async () => {
158
165
  await template.props.triggerAction();
159
166
  });
160
- expect(mockDoAction).toHaveBeenCalledWith(
161
- action_off_data,
162
- null,
163
- 'Sensor turn on / off off'
164
- );
167
+ expect(mockDoAction).toHaveBeenCalledWith(action_off_data, null);
165
168
  expect(watchMultiConfigs).toBeCalledTimes(0);
166
169
  });
167
170
 
@@ -178,11 +181,7 @@ describe('Test OnOffTemplate', () => {
178
181
  await act(async () => {
179
182
  await template.props.triggerAction();
180
183
  });
181
- expect(mockDoAction).toHaveBeenCalledWith(
182
- action_on_data,
183
- null,
184
- 'Sensor turn on / off on'
185
- );
184
+ expect(mockDoAction).toHaveBeenCalledWith(action_on_data, null);
186
185
  });
187
186
 
188
187
  test('template OnOffSimpleActionTemplate doAction with is_on_value and is_managed_by_backend', async () => {
@@ -197,11 +196,7 @@ describe('Test OnOffTemplate', () => {
197
196
  await act(async () => {
198
197
  await template.props.triggerAction();
199
198
  });
200
- expect(mockDoAction).toHaveBeenCalledWith(
201
- action_off_data,
202
- null,
203
- 'Sensor turn on / off off'
204
- );
199
+ expect(mockDoAction).toHaveBeenCalledWith(action_off_data, null);
205
200
  expect(watchMultiConfigs).toBeCalledTimes(0);
206
201
  });
207
202
 
@@ -69,6 +69,6 @@ describe('Test OneBigButtonTemplate', () => {
69
69
  });
70
70
 
71
71
  expect(mockDoAction).toHaveBeenCalledTimes(1);
72
- expect(mockDoAction).toHaveBeenCalledWith(action_data, null, 'Sensor up');
72
+ expect(mockDoAction).toHaveBeenCalledWith(action_data, null);
73
73
  });
74
74
  });
@@ -23,9 +23,16 @@ const wrapComponent = (actionGroup, mockDoAction, sensor) => (
23
23
  jest.mock('../../../iot/Monitor');
24
24
 
25
25
  jest.mock('../../../iot/states', () => ({
26
- useConfigGlobalState: () => [{ 5: 2 }, null],
26
+ useConfigGlobalState: () => [{ 5: { value: 2 } }, null],
27
27
  }));
28
28
 
29
+ jest.mock('@react-navigation/native', () => {
30
+ return {
31
+ ...jest.requireActual('@react-navigation/native'),
32
+ useFocusEffect: jest.fn(),
33
+ };
34
+ });
35
+
29
36
  describe('Test OptionsDropdownActionTemplate', () => {
30
37
  const action_data = {
31
38
  color: '#00979D',
@@ -152,8 +159,7 @@ describe('Test OptionsDropdownActionTemplate', () => {
152
159
 
153
160
  expect(mockDoAction).toHaveBeenCalledWith(
154
161
  action_data,
155
- JSON.stringify({ level: 1, key_code: 1 }),
156
- 'Sensor name fan speed 1'
162
+ JSON.stringify({ level: 1, key_code: 1 })
157
163
  );
158
164
  is_managed_by_backend
159
165
  ? expect(watchMultiConfigs).not.toBeCalled()
@@ -221,8 +227,7 @@ describe('Test OptionsDropdownActionTemplate', () => {
221
227
 
222
228
  expect(mockDoAction).toHaveBeenCalledWith(
223
229
  action_data,
224
- JSON.stringify({ level: 'level-1', key_code: 1 }),
225
- 'Sensor name fan speed level-1'
230
+ JSON.stringify({ level: 'level-1', key_code: 1 })
226
231
  ); // doAction with text instead of int
227
232
 
228
233
  expect(texts[1].props.children).toEqual('Level2');
@@ -296,10 +301,6 @@ describe('Test OptionsDropdownActionTemplate', () => {
296
301
  });
297
302
  expect(alertAction.props.visible).toBeFalsy();
298
303
 
299
- expect(mockDoAction).toHaveBeenCalledWith(
300
- action_data,
301
- 'level-1',
302
- 'Sensor name fan speed level-1'
303
- ); // doAction with text instead of int
304
+ expect(mockDoAction).toHaveBeenCalledWith(action_data, 'level-1'); // doAction with text instead of int
304
305
  });
305
306
  });
@@ -7,6 +7,13 @@ import StatesGridActionTemplate from '../StatesGridActionTemplate';
7
7
  const mockDoAction = jest.fn();
8
8
  const mockActionData = jest.fn();
9
9
 
10
+ jest.mock('@react-navigation/native', () => {
11
+ return {
12
+ ...jest.requireActual('@react-navigation/native'),
13
+ useFocusEffect: jest.fn(),
14
+ };
15
+ });
16
+
10
17
  describe('Test StatesGridActionTemplate', () => {
11
18
  let tree;
12
19
  const actionGroup = {
@@ -66,12 +73,6 @@ describe('Test StatesGridActionTemplate', () => {
66
73
  const TouchableOpacities = instance.findAllByType(TouchableOpacity);
67
74
  expect(TouchableOpacities).toHaveLength(2);
68
75
  await TouchableOpacities[0].props.onPress();
69
- expect(mockDoAction).toBeCalledWith(
70
- mockActionData,
71
- null,
72
- `${sensor.name} ${actionGroup.title.toLowerCase()} ${
73
- actionGroup.configuration.options[0].text
74
- }`
75
- );
76
+ expect(mockDoAction).toBeCalledWith(mockActionData, null);
76
77
  });
77
78
  });
@@ -14,9 +14,16 @@ import { mockSCStore } from '../../../context/mockStore';
14
14
  jest.mock('../../../iot/Monitor');
15
15
 
16
16
  jest.mock('../../../iot/states', () => ({
17
- useConfigGlobalState: () => [{ 5: 18, 6: 30 }, null],
17
+ useConfigGlobalState: () => [{ 5: { value: 18 }, 6: { value: 30 } }, null],
18
18
  }));
19
19
 
20
+ jest.mock('@react-navigation/native', () => {
21
+ return {
22
+ ...jest.requireActual('@react-navigation/native'),
23
+ useFocusEffect: jest.fn(),
24
+ };
25
+ });
26
+
20
27
  const mockDoAction = jest.fn();
21
28
 
22
29
  const wrapComponent = (actionGroup, sensor) => (
@@ -16,6 +16,13 @@ jest.mock('../../../iot/states', () => ({
16
16
  useConfigGlobalState: () => [{}, null],
17
17
  }));
18
18
 
19
+ jest.mock('@react-navigation/native', () => {
20
+ return {
21
+ ...jest.requireActual('@react-navigation/native'),
22
+ useFocusEffect: jest.fn(),
23
+ };
24
+ });
25
+
19
26
  const wrapComponent = (actionGroup, mockDoAction, is_managed_by_backend) => (
20
27
  <SCProvider initState={mockSCStore({})}>
21
28
  <TimerActionTemplate
@@ -9,6 +9,13 @@ jest.mock('react', () => ({
9
9
  useState: jest.fn(),
10
10
  }));
11
11
 
12
+ jest.mock('@react-navigation/native', () => {
13
+ return {
14
+ ...jest.requireActual('@react-navigation/native'),
15
+ useFocusEffect: jest.fn(),
16
+ };
17
+ });
18
+
12
19
  describe('Test TwoButtonTemplate', () => {
13
20
  const action_on_data = {
14
21
  color: '#00979D',
@@ -74,7 +81,11 @@ describe('Test TwoButtonTemplate', () => {
74
81
  const mockDoAction = jest.fn();
75
82
  act(() => {
76
83
  wrapper = create(
77
- <TwoButtonTemplate actionGroup={actionGroup} doAction={mockDoAction} />
84
+ <TwoButtonTemplate
85
+ actionGroup={actionGroup}
86
+ doAction={mockDoAction}
87
+ sensor={sensor}
88
+ />
78
89
  );
79
90
  });
80
91
 
@@ -94,7 +105,11 @@ describe('Test TwoButtonTemplate', () => {
94
105
  const mockDoAction = jest.fn();
95
106
  act(() => {
96
107
  wrapper = create(
97
- <TwoButtonTemplate actionGroup={actionGroup} doAction={mockDoAction} />
108
+ <TwoButtonTemplate
109
+ actionGroup={actionGroup}
110
+ doAction={mockDoAction}
111
+ sensor={sensor}
112
+ />
98
113
  );
99
114
  });
100
115
 
@@ -21,6 +21,13 @@ const wrapComponent = (actionGroup, mockDoAction, sensor) => (
21
21
  </SCProvider>
22
22
  );
23
23
 
24
+ jest.mock('@react-navigation/native', () => {
25
+ return {
26
+ ...jest.requireActual('@react-navigation/native'),
27
+ useFocusEffect: jest.fn(),
28
+ };
29
+ });
30
+
24
31
  describe('Test ActionGroup', () => {
25
32
  const configuration_with_none_action_on_off = {
26
33
  action1: '2b949045-8e03-4c07-a855-7794ade2e69c',
@@ -176,8 +183,7 @@ describe('Test ActionGroup', () => {
176
183
  expect(mockDoAction).toHaveBeenCalledTimes(1);
177
184
  expect(mockDoAction).toHaveBeenCalledWith(
178
185
  actionGroup.configuration.action1_data,
179
- null,
180
- 'Sensor name up'
186
+ null
181
187
  );
182
188
  act(() => {
183
189
  buttons[1].props.onPress();
@@ -185,8 +191,7 @@ describe('Test ActionGroup', () => {
185
191
  expect(mockDoAction).toHaveBeenCalledTimes(2);
186
192
  expect(mockDoAction).toHaveBeenCalledWith(
187
193
  actionGroup.configuration.action2_data,
188
- null,
189
- 'Sensor name stop'
194
+ null
190
195
  );
191
196
  act(() => {
192
197
  buttons[2].props.onPress();
@@ -194,8 +199,7 @@ describe('Test ActionGroup', () => {
194
199
  expect(mockDoAction).toHaveBeenCalledTimes(3);
195
200
  expect(mockDoAction).toHaveBeenCalledWith(
196
201
  actionGroup.configuration.action3_data,
197
- null,
198
- 'Sensor name down'
202
+ null
199
203
  );
200
204
  });
201
205
 
@@ -250,8 +254,7 @@ describe('Test ActionGroup', () => {
250
254
  expect(mockDoAction).toHaveBeenCalledTimes(1);
251
255
  expect(mockDoAction).toHaveBeenCalledWith(
252
256
  actionGroup.configuration.action1_data,
253
- null,
254
- 'Sensor name up'
257
+ null
255
258
  );
256
259
  act(() => {
257
260
  buttons[1].props.onPress();
@@ -259,8 +262,7 @@ describe('Test ActionGroup', () => {
259
262
  expect(mockDoAction).toHaveBeenCalledTimes(2);
260
263
  expect(mockDoAction).toHaveBeenCalledWith(
261
264
  actionGroup.configuration.action2_data,
262
- null,
263
- 'Sensor name stop'
265
+ null
264
266
  );
265
267
  act(() => {
266
268
  buttons[2].props.onPress();
@@ -268,8 +270,7 @@ describe('Test ActionGroup', () => {
268
270
  expect(mockDoAction).toHaveBeenCalledTimes(3);
269
271
  expect(mockDoAction).toHaveBeenCalledWith(
270
272
  actionGroup.configuration.action3_data,
271
- null,
272
- 'Sensor name down'
273
+ null
273
274
  );
274
275
  });
275
276
 
@@ -309,11 +310,7 @@ describe('Test ActionGroup', () => {
309
310
  buttons[0].props.onPress();
310
311
  });
311
312
  expect(mockDoAction).toHaveBeenCalledTimes(1);
312
- expect(mockDoAction).toHaveBeenCalledWith(
313
- action_data,
314
- null,
315
- 'Sensor name up'
316
- );
313
+ expect(mockDoAction).toHaveBeenCalledWith(action_data, null);
317
314
  });
318
315
 
319
316
  test('render ActionGroup on_off_button_action_template', async () => {
@@ -522,7 +519,7 @@ describe('Test ActionGroup', () => {
522
519
  });
523
520
  const instance = wrapper.root;
524
521
  const texts = instance.findAllByType(Text);
525
- expect(texts).toHaveLength(2);
522
+ expect(texts).toHaveLength(5);
526
523
  });
527
524
 
528
525
  test('render SmartTiviActionTemplate', async () => {