@eohjsc/react-native-smart-city 0.3.89 → 0.3.91

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 (166) hide show
  1. package/package.json +1 -1
  2. package/src/commons/ActionGroup/__test__/NumberUpDownTemplate.test.js +1 -1
  3. package/src/commons/ActionTemplate/CurtainAction.js +2 -2
  4. package/src/commons/ActionTemplate/OnOffButtonAction.js +2 -2
  5. package/src/commons/ActionTemplate/OnOffSimpleAction.js +2 -2
  6. package/src/commons/ActionTemplate/OnOffSmartLockAction.js +2 -2
  7. package/src/commons/ActionTemplate/OneButtonAction.js +2 -2
  8. package/src/commons/ActionTemplate/ThreeButtonAction.js +2 -2
  9. package/src/commons/ActionTemplate/__test__/CurtainAction.test.js +1 -1
  10. package/src/commons/ActionTemplate/__test__/OnOffButtonAction.test.js +1 -1
  11. package/src/commons/ActionTemplate/__test__/OnOffSimpleAction.test.js +1 -1
  12. package/src/commons/ActionTemplate/__test__/OnOffSmartLockAction.test.js +1 -1
  13. package/src/commons/ActionTemplate/__test__/OneButtonAction.test.js +1 -1
  14. package/src/commons/ActionTemplate/__test__/ThreeButtonAction.test.js +1 -1
  15. package/src/commons/ActionTemplate/__test__/index.test.js +21 -70
  16. package/src/commons/ActionTemplate/index.js +19 -55
  17. package/src/commons/Alert/__test__/Alert.test.js +1 -1
  18. package/src/commons/Auth/__test__/OtpInputList.test.js +4 -2
  19. package/src/commons/Auth/__test__/SocialButton.test.js +4 -2
  20. package/src/commons/BackDefault/__test__/BackDefault.test.js +1 -1
  21. package/src/commons/Button/__test__/Button.test.js +1 -1
  22. package/src/commons/ButtonPopup/__test__/ButtonPopup.test.js +1 -1
  23. package/src/commons/Calendar/__test__/Calendar.test.js +1 -1
  24. package/src/commons/ChartLoading/__test__/ChartLoading.test.js +1 -1
  25. package/src/commons/CircleButton/__test__/CircleButton.test.js +1 -1
  26. package/src/commons/CircleView/__test__/CircleView.test.js +1 -1
  27. package/src/commons/DateTimeRangeChange/__test__/DateTimeButton.test.js +4 -2
  28. package/src/commons/DateTimeRangeChange/index.js +31 -48
  29. package/src/commons/Device/Emergency/__test__/EmergencyButton.test.js +2 -2
  30. package/src/commons/Device/Emergency/__test__/EmergencyDetail.test.js +1 -1
  31. package/src/commons/Device/FlatListItems.js +1 -1
  32. package/src/commons/Device/Hanet/ItemHanetDevice.test.js +2 -2
  33. package/src/commons/Device/HistoryChart.js +6 -49
  34. package/src/commons/Device/LinearChart/LinearChart.test.js +1 -1
  35. package/src/commons/Device/ProgressBar/__test__/ProgressBar.test.js +3 -4
  36. package/src/commons/Device/ProgressBar/index.js +6 -4
  37. package/src/commons/Device/ProgressBar/styles.js +9 -6
  38. package/src/commons/Device/RainningSensor/__test__/CurrentRainSensor.test.js +5 -5
  39. package/src/commons/Device/SonosSpeaker/__test__/SonosSpeaker.test.js +3 -3
  40. package/src/commons/Device/WindDirection/Compass/Compass.test.js +2 -2
  41. package/src/commons/Device/WindSpeed/LinearChart/index.js +1 -1
  42. package/src/commons/Device/__test__/DeviceAlertStatus.test.js +3 -3
  43. package/src/commons/Device/__test__/DisconnectedView.test.js +2 -2
  44. package/src/commons/Device/__test__/FlatListItems.test.js +1 -1
  45. package/src/commons/Device/__test__/SensorConnectedStatus.test.js +1 -1
  46. package/src/commons/DisplayChecking/__test__/DisplayChecking.test.js +1 -1
  47. package/src/commons/Form/__test__/CurrencyInput.test.js +2 -2
  48. package/src/commons/Form/__test__/TextInput.test.js +2 -2
  49. package/src/commons/Form/__test__/TextInputPassword.test.js +2 -2
  50. package/src/commons/FullLoading/__test__/index.test.js +2 -2
  51. package/src/commons/ImageButton/__test__/ImageButton.test.js +1 -1
  52. package/src/commons/OneTapTemplate/NumberUpDownActionTemplate.js +2 -2
  53. package/src/commons/OneTapTemplate/OptionsDropdownActionTemplate.js +4 -4
  54. package/src/commons/OneTapTemplate/StatesGridActionTemplate.js +4 -4
  55. package/src/commons/OneTapTemplate/__test__/NumberUpDownActionTemplate.test.js +2 -2
  56. package/src/commons/OneTapTemplate/__test__/OptionsDropdownActionTemplate.test.js +1 -1
  57. package/src/commons/OneTapTemplate/__test__/StatesGridActionTemplate.test.js +2 -2
  58. package/src/commons/RowItem/__test__/RowItem.test.js +1 -1
  59. package/src/commons/RowUser/__test__/RowUser.test.js +1 -1
  60. package/src/commons/Section/Section.test.js +2 -2
  61. package/src/commons/SelectSubUnit/__test__/SelectSubUnit.test.js +1 -1
  62. package/src/commons/SelectUnit/__test__/SelectUnit.test.js +3 -3
  63. package/src/commons/Sharing/__test__/ButtonRemoveMember.test.js +1 -1
  64. package/src/commons/Sharing/__test__/DevicePermissionsCheckbox.test.js +1 -1
  65. package/src/commons/Sharing/__test__/MemberList.test.js +6 -4
  66. package/src/commons/Sharing/__test__/RowMember.test.js +2 -2
  67. package/src/commons/Sharing/__test__/StationDevicePermission.test.js +3 -3
  68. package/src/commons/Sharing/__test__/WrapHeaderScrollable.test.js +4 -2
  69. package/src/commons/SubUnit/OneTap/__test__/SubUnitAutomate.test.js +2 -10
  70. package/src/commons/SubUnit/OneTap/index.js +3 -1
  71. package/src/commons/TextButton/__test__/TextButton.test.js +2 -2
  72. package/src/commons/Today/__test__/Today.test.js +1 -1
  73. package/src/commons/TouchableScale/__test__/TouchableScale.test.js +1 -1
  74. package/src/commons/UnitSummary/AirQuality/index.js +2 -2
  75. package/src/commons/UnitSummary/ConfigHistoryChart/index.js +0 -6
  76. package/src/commons/UnitSummary/__test__/TotalPowerBox.test.js +1 -1
  77. package/src/commons/UnitSummary/__test__/TotalPowerConsumption.test.js +1 -1
  78. package/src/commons/ViewButtonBottom/__test__/ViewButtonBottom.test.js +1 -1
  79. package/src/configs/API.js +9 -32
  80. package/src/configs/Constants.js +2 -30
  81. package/src/context/reducer.ts +3 -1
  82. package/src/hoc/__test__/withRemoteControl.test.js +1 -1
  83. package/src/navigations/UnitStack.js +23 -13
  84. package/src/screens/ActivityLog/FilterPopup.js +4 -4
  85. package/src/screens/ActivityLog/__test__/FilterPopup.test.js +2 -2
  86. package/src/screens/ActivityLog/__test__/index.test.js +2 -2
  87. package/src/screens/AddCommon/__test__/SelectSubUnit.test.js +3 -3
  88. package/src/screens/AddCommon/__test__/SelectUnit.test.js +5 -5
  89. package/src/screens/AddNewAction/ChooseAction.js +180 -0
  90. package/src/screens/AddNewAction/ChooseConfig.js +207 -0
  91. package/src/screens/AddNewAction/Components/SelectDevices.js +75 -0
  92. package/src/screens/AddNewAction/Device/__test__/index.test.js +1 -1
  93. package/src/screens/AddNewAction/NewActionWrapper.js +55 -0
  94. package/src/screens/AddNewAction/SelectControlDevices.js +107 -0
  95. package/src/screens/AddNewAction/SelectMonitorDevices.js +142 -0
  96. package/src/screens/AddNewAction/SetupConfigCondition.js +245 -0
  97. package/src/screens/AddNewAction/Styles/SetupSensorStyles.js +1 -1
  98. package/src/screens/AddNewAction/__test__/{SelectAction.test.js → ChooseAction.test.js} +94 -114
  99. package/src/screens/AddNewAction/__test__/ChooseConfig.test.js +211 -0
  100. package/src/screens/AddNewAction/__test__/{SelectSensorDevices.test.js → SelectControlDevices.test.js} +32 -83
  101. package/src/screens/AddNewAction/__test__/SelectMonitorDevices.test.js +92 -0
  102. package/src/screens/AddNewAction/__test__/SetupSensor.test.js +9 -22
  103. package/src/screens/AddNewAutoSmart/__test__/AddNewAutoSmart.test.js +2 -3
  104. package/src/screens/AddNewAutoSmart/index.js +13 -33
  105. package/src/screens/AddNewGateway/PlugAndPlay/__test__/ConnectRouterGuide.test.js +1 -1
  106. package/src/screens/AddNewGateway/PlugAndPlay/__test__/FirstWarning.test.js +1 -1
  107. package/src/screens/AddNewGateway/PlugAndPlay/__test__/ZigbeeDeviceConnectGuide.test.js +1 -1
  108. package/src/screens/AddNewGateway/__test__/ConnectingWifiGuide.test.js +1 -1
  109. package/src/screens/AddNewGateway/__test__/ScanGatewayQR.test.js +2 -2
  110. package/src/screens/AddNewGateway/__test__/ScanModbusQR.test.js +3 -3
  111. package/src/screens/AddNewGateway/__test__/ScanWifiDeviceQR.test.js +2 -2
  112. package/src/screens/AddNewGateway/__test__/SelectDeviceSubUnit.test.js +3 -3
  113. package/src/screens/AddNewGateway/__test__/SelectDeviceUnit.test.js +1 -1
  114. package/src/screens/AddNewGateway/__test__/ShareWifiPassword.test.js +1 -1
  115. package/src/screens/AddNewOneTap/index.js +16 -7
  116. package/src/screens/AllCamera/__test__/index.test.js +18 -57
  117. package/src/screens/AllCamera/index.js +98 -30
  118. package/src/screens/Automate/MultiUnits.js +2 -2
  119. package/src/screens/Automate/__test__/MultiUnits.test.js +2 -2
  120. package/src/screens/Automate/__test__/index.test.js +19 -38
  121. package/src/screens/Automate/index.js +8 -3
  122. package/src/screens/Device/__test__/DetailHistoryChart.test.js +2 -2
  123. package/src/screens/Device/__test__/EmergencyCountdown.test.js +4 -2
  124. package/src/screens/Device/__test__/sensorDisplayItem.test.js +10 -10
  125. package/src/screens/Device/components/ChartWrapper.js +3 -3
  126. package/src/screens/Device/components/VisualChart.js +1 -1
  127. package/src/screens/Device/components/__test__/VisualChart.test.js +1 -1
  128. package/src/screens/Device/hooks/useEvaluateValue.js +8 -0
  129. package/src/screens/DeviceInfo/__test__/index.test.js +16 -18
  130. package/src/screens/DeviceInfo/index.js +6 -5
  131. package/src/screens/EditActionsList/__tests__/index.test.js +14 -6
  132. package/src/screens/Notification/__test__/Notification.test.js +65 -74
  133. package/src/screens/Notification/index.js +14 -14
  134. package/src/screens/ScriptDetail/__test__/index.test.js +2 -8
  135. package/src/screens/ScriptDetail/index.js +9 -88
  136. package/src/screens/ScriptDetail/utils.js +112 -0
  137. package/src/screens/SelectUnit/__test__/index.test.js +0 -5
  138. package/src/screens/SelectUnit/index.js +1 -2
  139. package/src/screens/Sharing/Components/TitleCheckBox.js +2 -2
  140. package/src/screens/SmartAccount/SuccessfullyConnected/__test__/SuccessfullyConnected.test.js +3 -3
  141. package/src/screens/SmartAccount/__test__/Connecting.test.js +1 -1
  142. package/src/screens/SmartAccount/__test__/SmartAccount.test.js +3 -3
  143. package/src/screens/SmartIr/__test__/ButtonsBottom.test.js +1 -1
  144. package/src/screens/SmartIr/__test__/GroupButtonByType.test.js +5 -5
  145. package/src/screens/SmartIr/__test__/SelectBrand.test.js +2 -2
  146. package/src/screens/SmartIr/__test__/SelectDeviceType.test.js +2 -2
  147. package/src/screens/SmartIr/__test__/SmartIr.test.js +2 -2
  148. package/src/screens/Template/__test__/detail.test.js +10 -2
  149. package/src/screens/Unit/__test__/Detail.test.js +7 -13
  150. package/src/screens/Unit/components/__test__/Header.test.js +4 -4
  151. package/src/screens/UnitSummary/components/3PPowerConsumption/__test__/3PPowerConsumption.test.js +1 -1
  152. package/src/screens/UnitSummary/components/3PPowerConsumption/index.js +14 -6
  153. package/src/screens/UnitSummary/components/PowerConsumption/__test__/PowerConsumption.test.js +1 -1
  154. package/src/screens/UnitSummary/components/Temperature/index.js +2 -2
  155. package/src/screens/UnitSummary/components/UvIndex/index.js +2 -2
  156. package/src/screens/UnitSummary/components/WaterQuality/index.js +2 -2
  157. package/src/screens/UnitSummary/components/__test__/TotalPowerBox.test.js +1 -1
  158. package/src/screens/UnitSummary/components/__test__/TotalPowerConsumption.test.js +1 -1
  159. package/src/screens/UnitSummary/components/__test__/index.test.js +2 -2
  160. package/src/utils/Apis/axios.js +3 -0
  161. package/src/utils/I18n/translations/en.json +1 -0
  162. package/src/utils/I18n/translations/vi.json +1 -0
  163. package/src/utils/Route/index.js +6 -3
  164. package/src/screens/AddNewAction/SelectAction.js +0 -570
  165. package/src/screens/AddNewAction/SelectSensorDevices.js +0 -236
  166. package/src/screens/AddNewAction/SetupSensor.js +0 -263
@@ -2,7 +2,7 @@ import React from 'react';
2
2
  import renderer, { act } from 'react-test-renderer';
3
3
  import MockAdapter from 'axios-mock-adapter';
4
4
 
5
- import SelectAction from '../SelectAction';
5
+ import ChooseAction from '../ChooseAction';
6
6
  import { SCProvider } from '../../../context';
7
7
  import { mockSCStore } from '../../../context/mockStore';
8
8
  import BottomButtonView from '../../../commons/BottomButtonView';
@@ -11,26 +11,18 @@ import api from '../../../utils/Apis/axios';
11
11
  import { API } from '../../../configs';
12
12
  import { TouchableOpacity } from 'react-native';
13
13
  import SelectActionCard from '../../../commons/SelectActionCard';
14
+ import { useNavigation } from '@react-navigation/native';
14
15
 
15
16
  const mock = new MockAdapter(api.axiosInstance);
16
17
 
17
- const mockedNavigate = jest.fn();
18
- jest.mock('@react-navigation/native', () => {
19
- return {
20
- ...jest.requireActual('@react-navigation/native'),
21
- useNavigation: () => ({
22
- navigate: mockedNavigate,
23
- }),
24
- };
25
- });
26
-
27
18
  const wrapComponent = (route) => (
28
19
  <SCProvider initState={mockSCStore({})}>
29
- <SelectAction route={route} />
20
+ <ChooseAction route={route} />
30
21
  </SCProvider>
31
22
  );
32
23
 
33
- describe('Test SelectAction', () => {
24
+ describe('Test ChooseAction', () => {
25
+ const mockedNavigate = useNavigation().navigate;
34
26
  let tree;
35
27
  let route = {
36
28
  params: {
@@ -39,12 +31,12 @@ describe('Test SelectAction', () => {
39
31
  stationName: 'stationName',
40
32
  automateId: 1,
41
33
  scriptName: 'scriptName test',
42
- isCreateNewAction: true,
43
34
  },
44
35
  };
45
36
 
46
37
  beforeEach(() => {
47
38
  mock.resetHistory();
39
+ mockedNavigate.mockReset();
48
40
  });
49
41
 
50
42
  test('test onSave have automateId', async () => {
@@ -71,24 +63,20 @@ describe('Test SelectAction', () => {
71
63
  await act(async () => {
72
64
  bottomButton.props.onPressMain();
73
65
  });
74
- expect(mockedNavigate).toHaveBeenCalled();
66
+ expect(mockedNavigate).not.toHaveBeenCalled();
75
67
  });
76
68
 
77
69
  it('test fetchData', async () => {
78
- const response = {
79
- status: 200,
80
- success: true,
81
- data: [
82
- { template: 'on_off_button_action_template' },
83
- { template: 'one_button_action_template' },
84
- { template: 'three_button_action_template' },
85
- ],
86
- };
87
- mock.onGet(API.DEVICE.DISPLAY_ACTIONS(1)).reply(200, response.data);
70
+ const response = [
71
+ { template: 'on_off_button_action_template' },
72
+ { template: 'one_button_action_template' },
73
+ { template: 'three_button_action_template' },
74
+ ];
75
+ mock.onGet(API.DEVICE.DISPLAY_ACTIONS(1)).reply(200, response);
88
76
  await act(async () => {
89
77
  tree = await renderer.create(wrapComponent(route));
90
78
  });
91
- expect(mockedNavigate).toHaveBeenCalled();
79
+ expect(mockedNavigate).not.toHaveBeenCalled();
92
80
  });
93
81
 
94
82
  test('test RenderActionItem air conditioner device IR', async () => {
@@ -97,101 +85,93 @@ describe('Test SelectAction', () => {
97
85
  config3 = 3,
98
86
  config4 = 4,
99
87
  config5 = 5;
100
- const response = {
101
- status: 200,
102
- success: true,
103
- data: [
104
- {
105
- id: 1,
106
- title: '',
107
- template: 'OnOffSimpleActionTemplate',
108
- configuration: {
109
- allow_config_store_value: true,
110
- config: config1,
111
- action_on: '94ae262d-46e3-42ff-9d10-516831ecc830',
112
- action_off: '94ae262d-46e3-42ff-9d10-516831ecc830',
113
- },
88
+ const response = [
89
+ {
90
+ id: 1,
91
+ title: '',
92
+ template: 'OnOffSimpleActionTemplate',
93
+ configuration: {
94
+ allow_config_store_value: true,
95
+ config: config1,
96
+ action_on: '94ae262d-46e3-42ff-9d10-516831ecc830',
97
+ action_off: '94ae262d-46e3-42ff-9d10-516831ecc830',
114
98
  },
115
- {
116
- id: 2,
117
- title: 'Fan Speed',
118
- template: 'OptionsDropdownActionTemplate',
119
- configuration: {
120
- config: config2,
121
- action: '05195362-75de-4db5-9e5e-98fef9d4910c',
122
- allow_config_store_value: true,
123
- options: [
124
- {
125
- text: 'Auto',
126
- value_int: 1,
127
- value_text: 'auto',
128
- },
129
- {
130
- text: 'Level1',
131
- value_int: 2,
132
- value_text: 'level1',
133
- },
134
- ],
135
- icon: 'up',
136
- icon_kit: 43,
137
- },
99
+ },
100
+ {
101
+ id: 2,
102
+ title: 'Fan Speed',
103
+ template: 'OptionsDropdownActionTemplate',
104
+ configuration: {
105
+ config: config2,
106
+ action: '05195362-75de-4db5-9e5e-98fef9d4910c',
107
+ allow_config_store_value: true,
108
+ options: [
109
+ {
110
+ text: 'Auto',
111
+ value_int: 1,
112
+ value_text: 'auto',
113
+ },
114
+ {
115
+ text: 'Level1',
116
+ value_int: 2,
117
+ value_text: 'level1',
118
+ },
119
+ ],
120
+ icon: 'up',
121
+ icon_kit: 43,
138
122
  },
139
- {
140
- id: 3,
141
- title: '',
142
- template: 'NumberUpDownActionTemplate',
143
- configuration: {
144
- keep_track_config: true,
145
- config: config3,
146
- allow_config_store_value: true,
147
- action: 'b498234c-6c1a-452d-a1d1-87a314c20528',
148
- min_value: 16,
149
- max_value: 30,
150
- text_format: '{number} \u00b0C',
151
- },
123
+ },
124
+ {
125
+ id: 3,
126
+ title: '',
127
+ template: 'NumberUpDownActionTemplate',
128
+ configuration: {
129
+ keep_track_config: true,
130
+ config: config3,
131
+ allow_config_store_value: true,
132
+ action: 'b498234c-6c1a-452d-a1d1-87a314c20528',
133
+ min_value: 16,
134
+ max_value: 30,
135
+ text_format: '{number} \u00b0C',
152
136
  },
153
- {
154
- id: 4,
155
- title: '',
156
- template: 'NumberUpDownActionTemplate',
157
- configuration: {
158
- config: config4,
159
- allow_config_store_value: true,
160
- action: '11111111-6c1a-452d-a1d1-87a314c20528',
161
- min_value: 12,
162
- max_value: 20,
163
- text_format: '{number} \u00b0C',
164
- },
137
+ },
138
+ {
139
+ id: 4,
140
+ title: '',
141
+ template: 'NumberUpDownActionTemplate',
142
+ configuration: {
143
+ config: config4,
144
+ allow_config_store_value: true,
145
+ action: '11111111-6c1a-452d-a1d1-87a314c20528',
146
+ min_value: 12,
147
+ max_value: 20,
148
+ text_format: '{number} \u00b0C',
165
149
  },
166
- {
167
- id: 5,
168
- title: '',
169
- template: 'StatesGridActionTemplate',
170
- configuration: {
171
- options: [
172
- {
173
- config: config5,
174
- is_on_value: 1,
175
- action: '800ff454-4e2a-4a38-bad6-1bded728193e',
176
- allow_config_store_value: true,
177
- icon: 'up-circle',
178
- icon_kit: 41,
179
- text: 'Auto',
180
- },
181
- ],
182
- },
150
+ },
151
+ {
152
+ id: 5,
153
+ title: '',
154
+ template: 'StatesGridActionTemplate',
155
+ configuration: {
156
+ options: [
157
+ {
158
+ config: config5,
159
+ is_on_value: 1,
160
+ action: '800ff454-4e2a-4a38-bad6-1bded728193e',
161
+ allow_config_store_value: true,
162
+ icon: 'up-circle',
163
+ icon_kit: 41,
164
+ text: 'Auto',
165
+ },
166
+ ],
183
167
  },
184
- ],
185
- };
186
- mock.onGet(API.DEVICE.DISPLAY_ACTIONS(1)).reply(200, response.data);
168
+ },
169
+ ];
170
+ mock.onGet(API.DEVICE.DISPLAY_ACTIONS(1)).reply(200, response);
187
171
  await act(async () => {
188
- tree = renderer.create(wrapComponent(route));
172
+ tree = await renderer.create(wrapComponent(route));
189
173
  });
190
174
  const instance = tree.root;
191
- const renderActionItem = instance.find(
192
- (el) => el.props.accessibilityLabel === AccessibilityLabel.ACTION_ITEM
193
- );
194
- expect(renderActionItem.props.data.length).toBe(5);
195
175
 
196
176
  const cards = instance.findAllByType(SelectActionCard);
197
177
  // force all render
@@ -257,7 +237,7 @@ describe('Test SelectAction', () => {
257
237
  item.type === TouchableOpacity
258
238
  );
259
239
  await act(async () => {
260
- await chooseMode.props.onPress(response.data[4].configuration.options[0]);
240
+ await chooseMode.props.onPress(response[4].configuration.options[0]);
261
241
  });
262
242
 
263
243
  mock.onPost(API.AUTOMATE.ADD_SCRIPT_ACTION(1)).reply(200);
@@ -0,0 +1,211 @@
1
+ import React from 'react';
2
+ import renderer, { act } from 'react-test-renderer';
3
+ import MockAdapter from 'axios-mock-adapter';
4
+
5
+ import ChooseConfig from '../ChooseConfig';
6
+ import { SCProvider } from '../../../context';
7
+ import { mockSCStore } from '../../../context/mockStore';
8
+ import { DEVICE_TYPE } from '../../../configs/Constants';
9
+ import api from '../../../utils/Apis/axios';
10
+ import { API } from '../../../configs';
11
+ import TitleCheckBox from '../../Sharing/Components/TitleCheckBox';
12
+ import Text from '../../../commons/Text';
13
+ import t from '../../../hooks/Common/useTranslations';
14
+ import Routes from '../../../utils/Route';
15
+ import CheckBoxCustom from '../../Sharing/Components/CheckBoxCustom';
16
+ import BottomButtonView from '../../../commons/BottomButtonView';
17
+ import { ToastBottomHelper } from '../../../utils/Utils';
18
+ import { useNavigation } from '@react-navigation/native';
19
+
20
+ const mock = new MockAdapter(api.axiosInstance);
21
+
22
+ const wrapComponent = (route) => (
23
+ <SCProvider initState={mockSCStore({})}>
24
+ <ChooseConfig route={route} />
25
+ </SCProvider>
26
+ );
27
+
28
+ describe('Test ChooseConfig', () => {
29
+ let tree;
30
+ let route = {
31
+ params: {
32
+ unit: { id: 1, name: 'Unit test' },
33
+ device: { id: 1, name: 'Device test', device_type: DEVICE_TYPE.ZIGBEE },
34
+ },
35
+ };
36
+ const mockedNavigate = useNavigation().navigate;
37
+
38
+ beforeEach(() => {
39
+ mock.resetHistory();
40
+ mockedNavigate.mockReset();
41
+ });
42
+
43
+ it('test fetchData', async () => {
44
+ mock.onGet(API.AUTOMATE.DISPLAY_CONFIGS(1)).reply(200, []);
45
+ await act(async () => {
46
+ tree = await renderer.create(wrapComponent(route));
47
+ });
48
+ expect(tree.root.findAllByType(TitleCheckBox)).toHaveLength(0);
49
+ expect(mock.history.get).toHaveLength(1);
50
+ });
51
+
52
+ it('test fetchData with data and no default', async () => {
53
+ mock
54
+ .onGet(API.AUTOMATE.DISPLAY_CONFIGS(1))
55
+ .reply(200, [{ id: 1 }, { id: 2 }]);
56
+ await act(async () => {
57
+ tree = await renderer.create(wrapComponent(route));
58
+ });
59
+ const checkBoxs = tree.root.findAllByType(TitleCheckBox);
60
+ expect(checkBoxs).toHaveLength(2);
61
+ expect(checkBoxs[0].props.isChecked).toBeFalsy();
62
+ expect(checkBoxs[1].props.isChecked).toBeFalsy();
63
+ });
64
+
65
+ it('choose config', async () => {
66
+ mock
67
+ .onGet(API.AUTOMATE.DISPLAY_CONFIGS(1))
68
+ .reply(200, [{ id: 1 }, { id: 2 }]);
69
+ await act(async () => {
70
+ tree = await renderer.create(wrapComponent(route));
71
+ });
72
+ const checkBoxs = tree.root.findAllByType(TitleCheckBox);
73
+ await act(async () => {
74
+ await checkBoxs[0].findByType(CheckBoxCustom).props.onPress();
75
+ });
76
+ expect(checkBoxs[0].props.isChecked).toBeTruthy();
77
+ });
78
+
79
+ it('test fetchData with data and default', async () => {
80
+ mock.onGet(API.AUTOMATE.DISPLAY_CONFIGS(1)).reply(200, [
81
+ {
82
+ id: 1,
83
+ },
84
+ {
85
+ id: 2,
86
+ },
87
+ ]);
88
+ await act(async () => {
89
+ tree = await renderer.create(
90
+ wrapComponent({
91
+ ...route,
92
+ params: { ...route.params, automate: { config_id: 2 } },
93
+ })
94
+ );
95
+ });
96
+ const checkBoxs = tree.root.findAllByType(TitleCheckBox);
97
+ expect(checkBoxs[1].props.isChecked).toBeTruthy();
98
+ });
99
+
100
+ it('not checked but is default', async () => {
101
+ mock.onGet(API.AUTOMATE.DISPLAY_CONFIGS(1)).reply(200, [
102
+ {
103
+ id: 1,
104
+ },
105
+ {
106
+ id: 2,
107
+ },
108
+ ]);
109
+ await act(async () => {
110
+ tree = await renderer.create(
111
+ wrapComponent({
112
+ ...route,
113
+ params: { ...route.params, automate: { config_id: 2 } },
114
+ })
115
+ );
116
+ });
117
+ const conditionTexts = tree.root.findAll(
118
+ (el) => el.type === Text && el.props.type === 'H4'
119
+ );
120
+ expect(conditionTexts[0].props.children).toEqual(t('no_condition'));
121
+ expect(conditionTexts[1].props.children).not.toEqual(t('no_condition'));
122
+ });
123
+
124
+ it('go to setup', async () => {
125
+ mock.onGet(API.AUTOMATE.DISPLAY_CONFIGS(1)).reply(200, [
126
+ {
127
+ id: 1,
128
+ },
129
+ ]);
130
+ await act(async () => {
131
+ tree = await renderer.create(wrapComponent(route));
132
+ });
133
+ const conditionTouch = tree.root.findByProps({
134
+ accessibilityLabel: 'config-1',
135
+ });
136
+ await act(async () => {
137
+ conditionTouch.props.onPress();
138
+ });
139
+ expect(mockedNavigate).toHaveBeenCalledWith(Routes.SetupConfigCondition, {
140
+ item: { id: 1 },
141
+ sensorData: [{ id: 1 }],
142
+ isAutomateTab: undefined,
143
+ type: undefined,
144
+ automate: {},
145
+ });
146
+ });
147
+
148
+ it('render condition from setup', async () => {
149
+ mock.onGet(API.AUTOMATE.DISPLAY_CONFIGS(1)).reply(400); // hack test to fail api data
150
+ await act(async () => {
151
+ tree = await renderer.create(
152
+ wrapComponent({
153
+ ...route,
154
+ params: {
155
+ ...route.params,
156
+ newSensorData: [{ id: 1 }, { id: 2, value: 1 }],
157
+ },
158
+ })
159
+ );
160
+ });
161
+ const conditionTexts = tree.root.findAll(
162
+ (el) => el.type === Text && el.props.type === 'H4'
163
+ );
164
+ expect(conditionTexts[1].props.children).not.toEqual(t('no_condition'));
165
+ });
166
+
167
+ it('on save without select condition', async () => {
168
+ mock.onGet(API.AUTOMATE.DISPLAY_CONFIGS(1)).reply(200, [{ id: 1 }]);
169
+ await act(async () => {
170
+ tree = await renderer.create(wrapComponent(route));
171
+ });
172
+ const button = tree.root.findByType(BottomButtonView);
173
+ const spyToastError = jest.spyOn(ToastBottomHelper, 'error');
174
+ await act(async () => {
175
+ await button.props.onPressMain();
176
+ });
177
+ expect(spyToastError).toHaveBeenCalledWith(
178
+ t('please_choose_condition_before_continue')
179
+ );
180
+ });
181
+
182
+ it('on save with selected condition', async () => {
183
+ mock.onGet(API.AUTOMATE.DISPLAY_CONFIGS(1)).reply(400); // hack test to fail api data
184
+ await act(async () => {
185
+ tree = await renderer.create(
186
+ wrapComponent({
187
+ ...route,
188
+ params: {
189
+ ...route.params,
190
+ automate: { config_id: 1 },
191
+ newSensorData: [{ id: 1, value: 1 }],
192
+ },
193
+ })
194
+ );
195
+ });
196
+ const button = tree.root.findByType(BottomButtonView);
197
+ await act(async () => {
198
+ await button.props.onPressMain();
199
+ });
200
+ expect(mockedNavigate).toHaveBeenCalledWith(Routes.AddNewOneTap, {
201
+ automate: { config_id: 1, id: 1, value: 1 },
202
+ automateData: { id: 1, value: 1 },
203
+ automateId: undefined,
204
+ isAutomateTab: undefined,
205
+ isMultiUnits: undefined,
206
+ scriptName: undefined,
207
+ type: undefined,
208
+ unit: route.params.unit,
209
+ });
210
+ });
211
+ });
@@ -1,44 +1,30 @@
1
1
  import React from 'react';
2
2
  import renderer, { act } from 'react-test-renderer';
3
3
  import MockAdapter from 'axios-mock-adapter';
4
-
5
- import SelectSensorDevices from '../SelectSensorDevices';
6
4
  import { SCProvider } from '../../../context';
7
5
  import { mockSCStore } from '../../../context/mockStore';
8
6
  import Device from '../Device';
9
7
  import BottomButtonView from '../../../commons/BottomButtonView';
10
8
  import NavBar from '../../../commons/NavBar';
11
9
  import API from '../../../configs/API';
12
- import {
13
- AUTOMATE_SELECT,
14
- AccessibilityLabel,
15
- } from '../../../configs/Constants';
10
+ import { AccessibilityLabel } from '../../../configs/Constants';
16
11
  import { TouchableOpacity } from 'react-native';
17
12
  import Routes from '../../../utils/Route';
18
13
  import api from '../../../utils/Apis/axios';
14
+ import SelectControlDevices from '../SelectControlDevices';
15
+ import { useNavigation, useRoute } from '@react-navigation/native';
19
16
 
20
17
  const mock = new MockAdapter(api.axiosInstance);
21
18
 
22
- const mockedNavigate = jest.fn();
23
- const mockedDispatch = jest.fn();
24
-
25
- jest.mock('@react-navigation/native', () => {
26
- return {
27
- ...jest.requireActual('@react-navigation/native'),
28
- useNavigation: () => ({
29
- navigate: mockedNavigate,
30
- dispatch: mockedDispatch,
31
- }),
32
- };
33
- });
34
-
35
19
  const wrapComponent = (route) => (
36
20
  <SCProvider initState={mockSCStore({})}>
37
- <SelectSensorDevices route={route} />
21
+ <SelectControlDevices route={route} />
38
22
  </SCProvider>
39
23
  );
40
24
 
41
- describe('Test SelectSensorDevices', () => {
25
+ describe('Test SelectMonitorDevices', () => {
26
+ const mockedNavigate = useNavigation().navigate;
27
+
42
28
  let tree;
43
29
  const route = {
44
30
  params: {
@@ -48,31 +34,29 @@ describe('Test SelectSensorDevices', () => {
48
34
  automate: {
49
35
  sensor_id: 1,
50
36
  },
37
+ closeScreen: Routes.ScriptDetail,
51
38
  },
52
39
  };
53
- const response = {
54
- status: 200,
55
- success: true,
56
- data: [
57
- {
58
- id: 1,
59
- name: 'Device 1',
60
- sensors: [
61
- { id: 1, name: 'sensor' },
62
- { id: 2, name: 'sensor' },
63
- ],
64
- },
65
- ],
66
- };
40
+ const response = [
41
+ {
42
+ id: 1,
43
+ name: 'Device 1',
44
+ sensors: [
45
+ { id: 1, name: 'sensor' },
46
+ { id: 2, name: 'sensor' },
47
+ ],
48
+ },
49
+ ];
67
50
 
68
51
  beforeEach(() => {
69
52
  mockedNavigate.mockClear();
53
+ useRoute.mockImplementation(() => route);
70
54
  });
71
55
 
72
56
  it('fetch Device success', async () => {
73
- mock.onGet(API.UNIT.DEVICE_CONTROL(1)).reply(200, response.data);
57
+ mock.onGet(API.UNIT.DEVICE_CONTROL(1)).reply(200, response);
74
58
  await act(async () => {
75
- tree = renderer.create(wrapComponent(route));
59
+ tree = await renderer.create(wrapComponent(route));
76
60
  });
77
61
  const instance = tree.root;
78
62
  const navBar = instance.findByType(NavBar);
@@ -80,9 +64,9 @@ describe('Test SelectSensorDevices', () => {
80
64
  });
81
65
 
82
66
  it('onPress continue', async () => {
83
- mock.onGet(API.UNIT.DEVICE_CONTROL(1)).reply(200, response.data);
67
+ mock.onGet(API.UNIT.DEVICE_CONTROL(1)).reply(200, response);
84
68
  await act(async () => {
85
- tree = renderer.create(wrapComponent(route));
69
+ tree = await renderer.create(wrapComponent(route));
86
70
  });
87
71
  const instance = tree.root;
88
72
 
@@ -94,9 +78,9 @@ describe('Test SelectSensorDevices', () => {
94
78
  });
95
79
 
96
80
  it('test onPressDevice', async () => {
97
- mock.onGet(API.UNIT.DEVICE_CONTROL(1)).reply(200, response.data);
81
+ mock.onGet(API.UNIT.DEVICE_CONTROL(1)).reply(200, response);
98
82
  await act(async () => {
99
- tree = renderer.create(wrapComponent(route));
83
+ tree = await renderer.create(wrapComponent(route));
100
84
  });
101
85
  const instance = tree.root;
102
86
  const device = instance.findAllByType(Device);
@@ -105,17 +89,17 @@ describe('Test SelectSensorDevices', () => {
105
89
  await act(async () => {
106
90
  device[0].props.onPress({ id: 1, name: 'sensor' });
107
91
  });
108
- expect(device[0].props.isSelectDevice).toEqual(true);
92
+ expect(device[0].props.isSelectDevice).toBeTruthy();
109
93
  await act(async () => {
110
94
  device[0].props.onPress({ id: 1, name: 'sensor' });
111
95
  });
112
- expect(device[0].props.isSelectDevice).toEqual(false);
96
+ expect(device[0].props.isSelectDevice).toBeFalsy();
113
97
  });
114
98
 
115
99
  it('test onSnapItem', async () => {
116
- mock.onGet(API.UNIT.DEVICE_CONTROL(1)).reply(200, response.data);
100
+ mock.onGet(API.UNIT.DEVICE_CONTROL(1)).reply(200, response);
117
101
  await act(async () => {
118
- tree = renderer.create(wrapComponent(route));
102
+ tree = await renderer.create(wrapComponent(route));
119
103
  });
120
104
  const instance = tree.root;
121
105
  const navBar = instance.findByType(NavBar);
@@ -126,9 +110,9 @@ describe('Test SelectSensorDevices', () => {
126
110
  });
127
111
 
128
112
  it('test onPressClose user already has an automateId', async () => {
129
- mock.onGet(API.UNIT.DEVICE_CONTROL(1)).reply(200, response.data);
113
+ mock.onGet(API.UNIT.DEVICE_CONTROL(1)).reply(200, response);
130
114
  await act(async () => {
131
- tree = renderer.create(wrapComponent(route));
115
+ tree = await renderer.create(wrapComponent(route));
132
116
  });
133
117
  const instance = tree.root;
134
118
  const iconClose = instance.findAll(
@@ -141,41 +125,6 @@ describe('Test SelectSensorDevices', () => {
141
125
  await act(async () => {
142
126
  iconClose[0].props.onPress();
143
127
  });
144
- expect(mockedNavigate).toHaveBeenCalledWith(Routes.ScriptDetail, {
145
- havePermission: true,
146
- id: 1,
147
- isAutomateTab: undefined,
148
- isCreateNewAction: undefined,
149
- isMultiUnits: undefined,
150
- name: 'scriptName test',
151
- type: undefined,
152
- unit: { id: 1, name: 'Unit test' },
153
- });
154
- });
155
-
156
- it('test onPressClose user already has not an automateId', async () => {
157
- mock.onGet(API.UNIT.DEVICE_SENSOR(1)).reply(200, response.data);
158
- const new_route = {
159
- ...route,
160
- params: {
161
- ...route.params,
162
- automateId: null,
163
- title: AUTOMATE_SELECT.SELECT_SENSOR,
164
- },
165
- };
166
- await act(async () => {
167
- tree = renderer.create(wrapComponent(new_route));
168
- });
169
- const instance = tree.root;
170
- const iconClose = instance.findAll(
171
- (el) =>
172
- el.props.accessibilityLabel === AccessibilityLabel.ICON_CLOSE &&
173
- el.type === TouchableOpacity
174
- );
175
- expect(iconClose).toHaveLength(1);
176
- await act(async () => {
177
- iconClose[0].props.onPress();
178
- });
179
- expect(mockedDispatch).toBeCalled();
128
+ expect(mockedNavigate).toHaveBeenCalledWith(Routes.ScriptDetail);
180
129
  });
181
130
  });