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

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 (237) hide show
  1. package/package.json +5 -1
  2. package/src/Images/Common/reorder.svg +3 -0
  3. package/src/commons/ActionGroup/OnOffSmartLock/AutoLock/AutoLockStyles.js +1 -1
  4. package/src/commons/ActionGroup/OnOffSmartLock/AutoLock/__test__/index.test.js +3 -1
  5. package/src/commons/ActionGroup/OnOffSmartLock/AutoLock/index.js +3 -3
  6. package/src/commons/ActionGroup/OnOffSmartLock/PasscodeList/__test__/index.test.js +3 -10
  7. package/src/commons/ActionGroup/OnOffSmartLock/PasscodeList/index.js +1 -0
  8. package/src/commons/ActionGroup/OnOffSmartLock/SetupGeneratePasscode/SetupGeneratePasscodeStyles.js +1 -1
  9. package/src/commons/ActionGroup/OnOffTemplate/SwitchButtonTemplate.js +13 -5
  10. package/src/commons/ActionGroup/SliderRangeTemplate.js +100 -69
  11. package/src/commons/ActionGroup/SliderRangeTemplateStyles.js +27 -27
  12. package/src/commons/ActionGroup/StatesGridActionTemplate.js +4 -1
  13. package/src/commons/ActionGroup/__test__/OnOffTemplate.test.js +4 -1
  14. package/src/commons/ActionGroup/__test__/SliderRangeTemplate.test.js +56 -0
  15. package/src/commons/ActionGroup/__test__/StatesGridActionTemplate.test.js +2 -2
  16. package/src/commons/ActionGroup/__test__/SwitchButtonTemplate.test.js +45 -8
  17. package/src/commons/ActionGroup/__test__/index.test.js +0 -19
  18. package/src/commons/ActionGroup/index.js +0 -3
  19. package/src/commons/ActionTemplate/CurtainAction.js +3 -3
  20. package/src/commons/ActionTemplate/CurtainActionStyles.js +1 -1
  21. package/src/commons/ActionTemplate/OnOffButtonAction.js +2 -2
  22. package/src/commons/ActionTemplate/OnOffButtonActionStyles.js +1 -1
  23. package/src/commons/ActionTemplate/OnOffSimpleAction.js +2 -2
  24. package/src/commons/ActionTemplate/OnOffSimpleActionStyles.js +1 -1
  25. package/src/commons/ActionTemplate/OnOffSmartLockAction.js +2 -2
  26. package/src/commons/ActionTemplate/OnOffSmartLockActionStyles.js +1 -1
  27. package/src/commons/ActionTemplate/OneButtonAction.js +1 -1
  28. package/src/commons/ActionTemplate/OneButtonActionStyles.js +1 -1
  29. package/src/commons/ActionTemplate/ThreeButtonAction.js +3 -3
  30. package/src/commons/ActionTemplate/ThreeButtonActionStyles.js +1 -1
  31. package/src/commons/AlertAction/index.js +5 -0
  32. package/src/commons/Auth/AccountList.js +1 -1
  33. package/src/commons/Auth/__test__/OtpInputList.test.js +13 -17
  34. package/src/commons/Automate/ItemAutomate.js +10 -4
  35. package/src/commons/Automate/__test__/ItemAutomate.test.js +11 -11
  36. package/src/commons/BottomButtonView/index.js +22 -4
  37. package/src/commons/Button/index.js +5 -0
  38. package/src/commons/Device/ConnectedViewHeader.js +0 -1
  39. package/src/commons/Device/DeviceAlertStatus.js +2 -1
  40. package/src/commons/Device/Emergency/EmergencyDetail.js +4 -2
  41. package/src/commons/Device/Emergency/__test__/EmergencyDetail.test.js +4 -2
  42. package/src/commons/Device/ProgressBar/index.js +7 -11
  43. package/src/commons/Device/ProgressBar/styles.js +9 -4
  44. package/src/commons/Device/WindSpeed/Anemometer/index.js +3 -1
  45. package/src/commons/Device/WindSpeed/LinearChart/__test__/LinearChart.test.js +14 -1
  46. package/src/commons/Device/WindSpeed/LinearChart/index.js +4 -2
  47. package/src/commons/FlatListDnD/__test__/index.test.js +49 -0
  48. package/src/commons/FlatListDnD/index.js +37 -0
  49. package/src/commons/FlatListDnD/styles.js +12 -0
  50. package/src/commons/Form/__test__/TextInput.test.js +1 -1
  51. package/src/commons/Header/HeaderCustom.js +10 -19
  52. package/src/commons/HorizontalPicker/index.js +65 -38
  53. package/src/commons/IconComponent/index.js +3 -2
  54. package/src/commons/MediaPlayer/__test__/index.test.js +8 -3
  55. package/src/commons/MediaPlayer/index.js +11 -7
  56. package/src/commons/MenuActionMore/index.js +6 -4
  57. package/src/commons/Modal/ModalBottom.js +2 -3
  58. package/src/commons/Modal/ModalCustom.js +2 -3
  59. package/src/commons/NavBar/index.js +48 -50
  60. package/src/commons/OneTapTemplate/NumberUpDownActionTemplate.js +1 -1
  61. package/src/commons/OneTapTemplate/NumberUpDownActionTemplateStyles.js +1 -1
  62. package/src/commons/OneTapTemplate/OptionsDropdownActionTemplate.js +1 -1
  63. package/src/commons/OneTapTemplate/OptionsDropdownActionTemplateStyles.js +1 -1
  64. package/src/commons/OneTapTemplate/StatesGridActionTemplate.js +1 -1
  65. package/src/commons/OneTapTemplate/StatesGridActionTemplateStyles.js +1 -1
  66. package/src/commons/PreventAccess/index.js +1 -1
  67. package/src/commons/Sharing/StationDevicePermissions.js +4 -4
  68. package/src/commons/Sharing/WrapHeaderScrollable.js +5 -5
  69. package/src/commons/Sharing/__test__/DevicePermissionsCheckbox.test.js +2 -2
  70. package/src/commons/SubUnit/OneTap/ItemOneTap.js +12 -59
  71. package/src/commons/SubUnit/OneTap/__test__/SubUnitAutomate.test.js +16 -20
  72. package/src/commons/SubUnit/OneTap/index.js +20 -7
  73. package/src/commons/UnitSummary/AirQuality/__test__/index.test.js +4 -0
  74. package/src/commons/UnitSummary/ConfigHistoryChart/__test__/ConfigHistoryChart.test.js +1 -1
  75. package/src/commons/ViewButtonBottom/index.js +32 -4
  76. package/src/configs/API.js +9 -0
  77. package/src/configs/AccessibilityLabel.js +2 -0
  78. package/src/configs/BLE.js +1 -0
  79. package/src/configs/Colors.js +1 -1
  80. package/src/configs/Constants.js +12 -18
  81. package/src/context/actionType.ts +2 -1
  82. package/src/context/mockStore.ts +1 -0
  83. package/src/context/reducer.ts +12 -1
  84. package/src/hooks/Common/__test__/useStatusbar.test.js +5 -5
  85. package/src/hooks/Common/index.js +0 -2
  86. package/src/hooks/Common/useKeyboardShow.js +4 -4
  87. package/src/hooks/Common/useStatusBar.js +2 -2
  88. package/src/hooks/Common/useTitleHeader.js +5 -7
  89. package/src/hooks/Explore/useKeyboardAnimated.js +10 -4
  90. package/src/hooks/IoT/__test__/useRemoteControl.test.js +11 -0
  91. package/src/hooks/IoT/useBluetoothConnection.js +20 -29
  92. package/src/hooks/index.js +1 -2
  93. package/src/hooks/useMqtt.js +95 -0
  94. package/src/iot/Monitor.js +2 -1
  95. package/src/iot/RemoteControl/Bluetooth.js +56 -19
  96. package/src/iot/RemoteControl/__test__/Bluetooth.test.js +140 -0
  97. package/src/iot/mqtt.js +233 -0
  98. package/src/navigations/UnitStack.js +44 -12
  99. package/src/screens/AddLocationMaps/index.js +18 -16
  100. package/src/screens/AddLocationMaps/indexStyle.js +3 -0
  101. package/src/screens/AddNewGateway/SelectDeviceSubUnit.js +1 -2
  102. package/src/screens/AddNewGateway/__test__/AddNewGateway.test.js +5 -17
  103. package/src/screens/AddNewGateway/__test__/SelectDeviceSubUnit.test.js +5 -13
  104. package/src/screens/AddNewGateway/__test__/SelectDeviceUnit.test.js +9 -11
  105. package/src/screens/AddNewGateway/__test__/SelectModbusGateway.test.js +6 -14
  106. package/src/screens/AddNewGateway/__test__/SelectZigbeeGateway.test.js +6 -14
  107. package/src/screens/AddNewGateway/hooks/__Tests__/useWifiManage.test.js +3 -2
  108. package/src/screens/AddNewGateway/index.js +1 -1
  109. package/src/screens/AllCamera/index.js +2 -3
  110. package/src/screens/AllGateway/DetailConfigActionZigbee/__test__/index.test.js +0 -18
  111. package/src/screens/AllGateway/DetailConfigActionZigbee/index.js +1 -1
  112. package/src/screens/AllGateway/DeviceModbusDetail/__test__/index.test.js +5 -2
  113. package/src/screens/AllGateway/hooks/__test__/index.test.js +1 -1
  114. package/src/screens/{AddNewAction → Automate/AddNewAction}/ChooseAction.js +78 -119
  115. package/src/screens/{AddNewAction → Automate/AddNewAction}/ChooseConfig.js +45 -73
  116. package/src/screens/{AddNewAction → Automate/AddNewAction}/Components/LoadingSelectAction.js +1 -1
  117. package/src/screens/{AddNewAction → Automate/AddNewAction}/Components/SelectDevices.js +3 -3
  118. package/src/screens/{AddNewAction → Automate/AddNewAction}/Device/DeviceStyles.js +5 -1
  119. package/src/screens/{AddNewAction → Automate/AddNewAction}/Device/__test__/index.test.js +3 -3
  120. package/src/screens/{AddNewAction → Automate/AddNewAction}/Device/index.js +5 -4
  121. package/src/screens/{AddNewAction → Automate/AddNewAction}/NewActionWrapper.js +5 -7
  122. package/src/screens/{AddNewAction → Automate/AddNewAction}/SelectControlDevices.js +11 -49
  123. package/src/screens/{AddNewAction → Automate/AddNewAction}/SelectMonitorDevices.js +10 -42
  124. package/src/screens/{AddNewAction → Automate/AddNewAction}/SetupConfigCondition.js +52 -101
  125. package/src/screens/{AddNewAction → Automate/AddNewAction}/Styles/SelectActionStyles.js +1 -1
  126. package/src/screens/{AddNewAction → Automate/AddNewAction}/Styles/SelectSensorDevicesStyles.js +1 -1
  127. package/src/screens/{AddNewAction → Automate/AddNewAction}/Styles/SetupSensorStyles.js +4 -2
  128. package/src/screens/{AddNewAction → Automate/AddNewAction}/__test__/ChooseAction.test.js +10 -11
  129. package/src/screens/{AddNewAction → Automate/AddNewAction}/__test__/ChooseConfig.test.js +26 -27
  130. package/src/screens/{AddNewAction → Automate/AddNewAction}/__test__/SelectControlDevices.test.js +9 -9
  131. package/src/screens/{AddNewAction → Automate/AddNewAction}/__test__/SelectMonitorDevices.test.js +5 -5
  132. package/src/screens/{AddNewAction → Automate/AddNewAction}/__test__/SetupSensor.test.js +52 -16
  133. package/src/screens/Automate/AddNewAutoSmart/AddAutomationTypeSmart.js +25 -0
  134. package/src/screens/Automate/AddNewAutoSmart/AddTypeSmart.js +78 -0
  135. package/src/screens/Automate/AddNewAutoSmart/AddUnknownTypeSmart.js +29 -0
  136. package/src/screens/{AddNewAutoSmart → Automate/AddNewAutoSmart}/__test__/AddNewAutoSmart.test.js +18 -41
  137. package/src/screens/{AddNewAutoSmart → Automate/AddNewAutoSmart}/styles/AddNewAutoSmartStyles.js +1 -1
  138. package/src/screens/Automate/Components/InputName.js +64 -0
  139. package/src/screens/{AddNewOneTap/AddNewOneTapStyles.js → Automate/Components/InputNameStyles.js} +3 -3
  140. package/src/screens/{EditActionsList → Automate/EditActionsList}/Styles/indexStyles.js +5 -1
  141. package/src/screens/{EditActionsList → Automate/EditActionsList}/__tests__/index.test.js +17 -31
  142. package/src/screens/{EditActionsList → Automate/EditActionsList}/index.js +49 -51
  143. package/src/screens/Automate/MultiUnits.js +69 -67
  144. package/src/screens/Automate/OneTap/__test__/AddNewOneTap.test.js +134 -0
  145. package/src/screens/Automate/OneTap/index.js +16 -0
  146. package/src/screens/Automate/Scenario/ScenarioName.js +15 -0
  147. package/src/screens/{AddNewOneTap → Automate/Scenario}/__test__/AddNewOneTap.test.js +27 -45
  148. package/src/screens/Automate/ScriptDetail/Components/DeleteScript.js +45 -0
  149. package/src/screens/Automate/ScriptDetail/Components/RenameScript.js +58 -0
  150. package/src/screens/{ScriptDetail → Automate/ScriptDetail}/Styles/indexStyles.js +1 -1
  151. package/src/screens/{ScriptDetail → Automate/ScriptDetail}/__test__/index.test.js +110 -74
  152. package/src/screens/{ScriptDetail → Automate/ScriptDetail}/__test__/useStarredScript.test.js +7 -6
  153. package/src/screens/{ScriptDetail → Automate/ScriptDetail}/hooks/useStarredScript.js +4 -4
  154. package/src/screens/Automate/ScriptDetail/index.js +360 -0
  155. package/src/screens/{ScriptDetail → Automate/ScriptDetail}/utils.js +32 -31
  156. package/src/screens/{SetSchedule → Automate/SetSchedule}/__test__/SelectWeekday.test.js +2 -2
  157. package/src/screens/{SetSchedule → Automate/SetSchedule}/__test__/index.test.js +21 -46
  158. package/src/screens/{SetSchedule → Automate/SetSchedule}/components/RepeatOptionsPopup.js +4 -4
  159. package/src/screens/{SetSchedule → Automate/SetSchedule}/components/RowItem.js +2 -2
  160. package/src/screens/{SetSchedule → Automate/SetSchedule}/components/SelectWeekday.js +3 -3
  161. package/src/screens/Automate/SetSchedule/index.js +140 -0
  162. package/src/screens/{SetSchedule → Automate/SetSchedule}/styles/RepeatOptionsPopupStyles.js +1 -1
  163. package/src/screens/{SetSchedule → Automate/SetSchedule}/styles/RowItemStyles.js +1 -1
  164. package/src/screens/{SetSchedule → Automate/SetSchedule}/styles/SelectWeekdayStyles.js +1 -1
  165. package/src/screens/{SetSchedule → Automate/SetSchedule}/styles/indexStyles.js +1 -1
  166. package/src/screens/Automate/ValueChange/ValueChangeName.js +16 -0
  167. package/src/screens/Automate/__test__/MultiUnits.test.js +77 -121
  168. package/src/screens/Automate/__test__/index.test.js +3 -10
  169. package/src/screens/Automate/constants.js +0 -0
  170. package/src/screens/Automate/index.js +12 -23
  171. package/src/screens/ChangePosition/__test__/index.test.js +75 -0
  172. package/src/screens/ChangePosition/index.js +112 -0
  173. package/src/screens/ChangePosition/styles.js +87 -0
  174. package/src/screens/Device/__test__/detail.test.js +203 -258
  175. package/src/screens/Device/__test__/mqttDetail.test.js +599 -0
  176. package/src/screens/Device/__test__/sensorDisplayItem.test.js +4 -0
  177. package/src/screens/Device/components/SensorDisplayItem.js +3 -8
  178. package/src/screens/Device/components/VisualChart.js +55 -8
  179. package/src/screens/Device/detail.js +78 -30
  180. package/src/screens/Device/hooks/__test__/useEmergencyButton.test.js +35 -13
  181. package/src/screens/Device/hooks/useDeviceWatchConfigControl.js +13 -3
  182. package/src/screens/Device/hooks/useEvaluateValue.js +20 -2
  183. package/src/screens/Device/styles.js +7 -0
  184. package/src/screens/GuestInfo/components/__test__/AccessScheduleSheet.test.js +52 -0
  185. package/src/screens/MoveToAnotherSubUnit/__test__/index.test.js +18 -13
  186. package/src/screens/Notification/__test__/Notification.test.js +1 -1
  187. package/src/screens/PlayBackCamera/index.js +2 -3
  188. package/src/screens/SelectUnit/__test__/index.test.js +8 -13
  189. package/src/screens/SharedUnit/index.js +5 -4
  190. package/src/screens/Sharing/SelectUser.js +2 -2
  191. package/src/screens/Sharing/__test__/MemberList.test.js +9 -15
  192. package/src/screens/Sharing/__test__/MemberList2.test.js +10 -16
  193. package/src/screens/Sharing/__test__/SelectUser.test.js +8 -4
  194. package/src/screens/SideMenuDetail/SideMenuDetailStyles.js +1 -1
  195. package/src/screens/SmartAccount/__test__/SmartAccount.test.js +8 -4
  196. package/src/screens/SmartAccount/index.js +9 -9
  197. package/src/screens/SmartAccount/style.js +8 -7
  198. package/src/screens/SubUnit/ManageSubUnit.js +4 -4
  199. package/src/screens/SubUnit/__test__/ManageSubUnit.test.js +9 -28
  200. package/src/screens/TDSGuide/index.js +1 -1
  201. package/src/screens/Template/GatewayList.js +4 -1
  202. package/src/screens/Template/__test__/detail.test.js +14 -20
  203. package/src/screens/Template/detail.js +1 -0
  204. package/src/screens/UVIndexGuide/index.js +2 -2
  205. package/src/screens/Unit/Detail.js +10 -24
  206. package/src/screens/Unit/SelectAddToFavorites.js +1 -1
  207. package/src/screens/Unit/Summaries.js +6 -17
  208. package/src/screens/Unit/__test__/ChooseLocation.test.js +8 -13
  209. package/src/screens/Unit/__test__/Detail.test.js +3 -1
  210. package/src/screens/Unit/__test__/SelectAddToFavorites.test.js +1 -1
  211. package/src/screens/Unit/__test__/SmartAccount.test.js +8 -14
  212. package/src/screens/Unit/__test__/Summaries.test.js +2 -2
  213. package/src/screens/UnitSummary/components/UvIndex/__test__/index.test.js +4 -0
  214. package/src/screens/UnitSummary/components/WaterQuality/__test__/index.test.js +6 -11
  215. package/src/screens/WaterQualityGuide/index.js +10 -5
  216. package/src/utils/FactoryGateway.js +525 -0
  217. package/src/utils/I18n/translations/en.json +28 -19
  218. package/src/utils/I18n/translations/vi.json +26 -20
  219. package/src/utils/Route/index.js +5 -1
  220. package/src/utils/Utils.js +40 -0
  221. package/src/utils/__test__/Utils.test.js +6 -0
  222. package/src/commons/ActionGroup/CurtainButtonTemplate.js +0 -130
  223. package/src/commons/ActionGroup/__test__/CurtainButtonTemplate.test.js +0 -109
  224. package/src/commons/Auth/SocialButton.js +0 -54
  225. package/src/commons/Auth/__test__/SocialButton.test.js +0 -46
  226. package/src/commons/Device/SensorConnectedStatus.js +0 -56
  227. package/src/commons/Device/__test__/SensorConnectedStatus.test.js +0 -29
  228. package/src/commons/Sharing/__test__/StationDevicePermission.test.js +0 -85
  229. package/src/hooks/__test__/useInitDeepLink.test.js +0 -28
  230. package/src/hooks/useInitDeepLink.js +0 -25
  231. package/src/screens/AddNewAutoSmart/index.js +0 -149
  232. package/src/screens/AddNewOneTap/index.js +0 -156
  233. package/src/screens/ScriptDetail/hooks/index.js +0 -136
  234. package/src/screens/ScriptDetail/index.js +0 -446
  235. package/src/screens/SetSchedule/index.js +0 -200
  236. /package/src/screens/{AddNewAction → Automate/AddNewAction}/Components/index.js +0 -0
  237. /package/src/screens/{AddNewAction → Automate/AddNewAction}/__test__/LoadingSelectAction.test.js +0 -0
@@ -3,20 +3,23 @@ import MockAdapter from 'axios-mock-adapter';
3
3
  import { Platform, TextInput, TouchableOpacity } from 'react-native';
4
4
  import { act, create } from 'react-test-renderer';
5
5
 
6
- import AddNewOneTap from '..';
7
- import { AccessibilityLabel } from '../../../configs/Constants';
8
- import { SCProvider } from '../../../context';
9
- import { mockSCStore } from '../../../context/mockStore';
10
- import Routes from '../../../utils/Route';
11
- import { HeaderCustom } from '../../../commons/Header';
12
- import api from '../../../utils/Apis/axios';
13
- import { API } from '../../../configs';
14
-
15
- const wrapComponent = (route) => (
16
- <SCProvider initState={mockSCStore({})}>
17
- <AddNewOneTap route={route} />
18
- </SCProvider>
19
- );
6
+ import ScenarioName from '../ScenarioName';
7
+ import { AccessibilityLabel } from '../../../../configs/Constants';
8
+ import { SCProvider } from '../../../../context';
9
+ import { mockSCStore } from '../../../../context/mockStore';
10
+ import Routes from '../../../../utils/Route';
11
+ import api from '../../../../utils/Apis/axios';
12
+ import { API } from '../../../../configs';
13
+ import { useNavigation, useRoute } from '@react-navigation/native';
14
+
15
+ const wrapComponent = (route) => {
16
+ useRoute.mockReturnValue(route);
17
+ return (
18
+ <SCProvider initState={mockSCStore({})}>
19
+ <ScenarioName route={route} />
20
+ </SCProvider>
21
+ );
22
+ };
20
23
  const mock = new MockAdapter(api.axiosInstance);
21
24
 
22
25
  jest.mock('react-redux', () => {
@@ -26,24 +29,15 @@ jest.mock('react-redux', () => {
26
29
  };
27
30
  });
28
31
 
29
- const mockedNavigate = jest.fn();
30
- jest.mock('@react-navigation/native', () => {
31
- return {
32
- ...jest.requireActual('@react-navigation/native'),
33
- useNavigation: () => ({
34
- navigate: mockedNavigate,
35
- }),
36
- };
37
- });
38
-
39
32
  let tree;
40
33
 
41
- describe('test AddNewOneTap', () => {
34
+ describe('test OneTap', () => {
35
+ const mockedNavigate = useNavigation().navigate;
42
36
  beforeEach(() => {
43
37
  mockedNavigate.mockClear();
44
38
  });
45
39
 
46
- it('create AddNewOneTap success', async () => {
40
+ it('create OneTap success', async () => {
47
41
  Platform.OS = 'ios';
48
42
  let route = {
49
43
  params: {
@@ -94,7 +88,7 @@ describe('test AddNewOneTap', () => {
94
88
  });
95
89
  });
96
90
 
97
- it('create AddNewOneTap fail', async () => {
91
+ it('create OneTap fail', async () => {
98
92
  Platform.OS = 'android';
99
93
  let route = {
100
94
  params: { type: 'one_tap' },
@@ -123,13 +117,7 @@ describe('test AddNewOneTap', () => {
123
117
  Platform.OS = 'android';
124
118
  let route = {
125
119
  params: {
126
- automateId: 1,
127
- scriptName: 'script test',
128
- type: 'one_tap',
129
- havePermission: true,
130
- unit: { id: 1 },
131
- isMultiUnits: false,
132
- isAutomateTab: false,
120
+ closeScreen: Routes.ScriptDetail,
133
121
  },
134
122
  };
135
123
  mock.onPost(API.AUTOMATE.CREATE_AUTOMATE()).reply(400);
@@ -137,19 +125,13 @@ describe('test AddNewOneTap', () => {
137
125
  tree = await create(wrapComponent(route));
138
126
  });
139
127
 
140
- const header = tree.root.findByType(HeaderCustom);
128
+ const header = tree.root.findByProps({
129
+ accessibilityLabel: AccessibilityLabel.ICON_CLOSE,
130
+ });
141
131
 
142
132
  await act(async () => {
143
- header.props.onClose();
144
- });
145
- expect(mockedNavigate).toHaveBeenCalledWith(Routes.ScriptDetail, {
146
- id: 1,
147
- name: 'script test',
148
- type: undefined,
149
- havePermission: true,
150
- unit: { id: 1 },
151
- isMultiUnits: false,
152
- isAutomateTab: false,
133
+ header.props.onPress();
153
134
  });
135
+ expect(mockedNavigate).toHaveBeenCalledWith(Routes.ScriptDetail);
154
136
  });
155
137
  });
@@ -0,0 +1,45 @@
1
+ import React, { useCallback } from 'react';
2
+ import { API, Colors } from '../../../../configs';
3
+ import AlertAction from '../../../../commons/AlertAction';
4
+ import { axiosDelete } from '../../../../utils/Apis/axios';
5
+ import { ToastBottomHelper } from '../../../../utils/Utils';
6
+ import { useTranslations } from '../../../../hooks/Common/useTranslations';
7
+ import { useNavigation } from '@react-navigation/native';
8
+
9
+ const RenameScript = ({ automate, isVisible, setIsVisible }) => {
10
+ const t = useTranslations();
11
+ const { goBack } = useNavigation();
12
+
13
+ const deleteScript = useCallback(async () => {
14
+ const { success } = await axiosDelete(API.AUTOMATE.SCRIPT(automate.id));
15
+ if (success) {
16
+ setIsVisible(false);
17
+ goBack();
18
+ ToastBottomHelper.success(t('removed_successfully'));
19
+ } else {
20
+ ToastBottomHelper.error(t('remove_failed'));
21
+ }
22
+ }, [automate.id, goBack, setIsVisible, t]);
23
+
24
+ const hidePopup = () => setIsVisible(false);
25
+
26
+ return (
27
+ <AlertAction
28
+ visible={isVisible}
29
+ hideModal={hidePopup}
30
+ title={t('title_delete_script', {
31
+ scriptName: automate?.name,
32
+ })}
33
+ message={t('message_delete_script', {
34
+ scriptName: automate?.name,
35
+ })}
36
+ leftButtonTitle={t('cancel')}
37
+ leftButtonClick={hidePopup}
38
+ rightButtonTitle={t('remove')}
39
+ rightButtonClick={deleteScript}
40
+ rightButtonStyle={{ color: Colors.Red6 }}
41
+ />
42
+ );
43
+ };
44
+
45
+ export default RenameScript;
@@ -0,0 +1,58 @@
1
+ import React, { useCallback, useState } from 'react';
2
+ import { API, Colors } from '../../../../configs';
3
+ import _TextInput from '../../../../commons/Form/TextInput';
4
+ import styles from '../Styles/indexStyles';
5
+ import AlertAction from '../../../../commons/AlertAction';
6
+ import { axiosPatch } from '../../../../utils/Apis/axios';
7
+ import { ToastBottomHelper } from '../../../../utils/Utils';
8
+ import { useTranslations } from '../../../../hooks/Common/useTranslations';
9
+ import useKeyboardAnimated from '../../../../hooks/Explore/useKeyboardAnimated';
10
+
11
+ const RenameScript = ({ automate, setAutomate, isVisible, setIsVisible }) => {
12
+ const t = useTranslations();
13
+ const [inputName, setInputName] = useState(automate.name);
14
+ const transY = useKeyboardAnimated();
15
+
16
+ const renameScript = useCallback(async () => {
17
+ const { success, data: script } = await axiosPatch(
18
+ API.AUTOMATE.SCRIPT(automate.id),
19
+ {
20
+ name: inputName,
21
+ }
22
+ );
23
+ if (success) {
24
+ setAutomate((prev) => ({ ...prev, name: script.name }));
25
+ ToastBottomHelper.success(t('rename_successfully'));
26
+ } else {
27
+ ToastBottomHelper.error(t('rename_failed'));
28
+ }
29
+ setIsVisible(false);
30
+ }, [automate.id, inputName, setAutomate, setIsVisible, t]);
31
+
32
+ const hidePopup = () => setIsVisible(false);
33
+
34
+ return (
35
+ <AlertAction
36
+ visible={isVisible}
37
+ hideModal={hidePopup}
38
+ title={t('rename_automate')}
39
+ message=""
40
+ leftButtonTitle={t('cancel')}
41
+ leftButtonClick={hidePopup}
42
+ rightButtonTitle={t('rename')}
43
+ rightButtonClick={renameScript}
44
+ rightButtonStyle={{ color: Colors.Primary }}
45
+ transY={transY}
46
+ >
47
+ <_TextInput
48
+ onChange={setInputName}
49
+ value={inputName}
50
+ defaultValue={automate?.name}
51
+ textInputStyle={styles.textInput}
52
+ maxLength={64}
53
+ />
54
+ </AlertAction>
55
+ );
56
+ };
57
+
58
+ export default RenameScript;
@@ -1,4 +1,4 @@
1
- import { Colors } from '../../../configs';
1
+ import { Colors } from '../../../../configs';
2
2
  import { Platform, StyleSheet } from 'react-native';
3
3
  import { getBottomSpace } from 'react-native-iphone-x-helper';
4
4
 
@@ -1,21 +1,28 @@
1
1
  import React from 'react';
2
2
  import { create, act } from 'react-test-renderer';
3
3
  import Toast from 'react-native-toast-message';
4
-
5
- import MockAdapter from 'axios-mock-adapter';
6
- import { SCProvider } from '../../../context';
7
- import { mockSCStore } from '../../../context/mockStore';
8
- import ScriptDetail from '..';
9
- import MenuActionMore from '../../../commons/MenuActionMore';
10
- import AlertAction from '../../../commons/AlertAction';
11
- import _TextInput from '../../../commons/Form/TextInput';
12
- import { AUTOMATE_TYPE, AccessibilityLabel } from '../../../configs/Constants';
13
- import { API } from '../../../configs';
4
+ import { useNavigation } from '@react-navigation/native';
14
5
  import { TouchableOpacity } from 'react-native';
15
- import Routes from '../../../utils/Route';
16
- import WrapHeaderScrollable from '../../../commons/Sharing/WrapHeaderScrollable';
17
- import ItemAutomate from '../../../commons/Automate/ItemAutomate';
18
- import api from '../../../utils/Apis/axios';
6
+ import MockAdapter from 'axios-mock-adapter';
7
+
8
+ import { SCProvider } from '../../../../context';
9
+ import { mockSCStore } from '../../../../context/mockStore';
10
+ import ScriptDetail from '../index';
11
+ import MenuActionMore from '../../../../commons/MenuActionMore';
12
+ import AlertAction from '../../../../commons/AlertAction';
13
+ import _TextInput from '../../../../commons/Form/TextInput';
14
+ import {
15
+ AUTOMATE_TYPE,
16
+ AccessibilityLabel,
17
+ } from '../../../../configs/Constants';
18
+ import { API } from '../../../../configs';
19
+ import Routes from '../../../../utils/Route';
20
+ import WrapHeaderScrollable from '../../../../commons/Sharing/WrapHeaderScrollable';
21
+ import ItemAutomate from '../../../../commons/Automate/ItemAutomate';
22
+ import api from '../../../../utils/Apis/axios';
23
+ import Text from '../../../../commons/Text';
24
+ import { ToastBottomHelper } from '../../../../utils/Utils';
25
+ import { getTranslate } from '../../../../utils/I18n';
19
26
 
20
27
  const wrapComponent = (route) => (
21
28
  <SCProvider initState={mockSCStore({})}>
@@ -23,18 +30,6 @@ const wrapComponent = (route) => (
23
30
  </SCProvider>
24
31
  );
25
32
 
26
- const mockGoBack = jest.fn();
27
- const mockNavigate = jest.fn();
28
- jest.mock('@react-navigation/native', () => {
29
- return {
30
- ...jest.requireActual('@react-navigation/native'),
31
- useNavigation: () => ({
32
- goBack: mockGoBack,
33
- navigate: mockNavigate,
34
- }),
35
- };
36
- });
37
-
38
33
  const mock = new MockAdapter(api.axiosInstance);
39
34
 
40
35
  describe('Test ScriptDetail', () => {
@@ -42,18 +37,20 @@ describe('Test ScriptDetail', () => {
42
37
  let data;
43
38
  let tree;
44
39
 
40
+ const mockGoBack = useNavigation().goBack;
41
+ const mockNavigate = useNavigation().navigate;
45
42
  beforeEach(() => {
46
43
  mockGoBack.mockClear();
44
+ mockNavigate.mockClear();
45
+ mock.reset();
47
46
  route = {
48
47
  params: {
49
48
  id: 1,
50
- name: 'script',
51
- unit: { id: 2 },
52
- type: AUTOMATE_TYPE.ONE_TAP,
53
- havePermission: true,
54
- automate: {
49
+ preAutomate: {
50
+ unit: 2,
55
51
  author: 'Le Minh Tam',
56
- id: 1009,
52
+ id: 1,
53
+ can_edit: true,
57
54
  type: 'value_change',
58
55
  value_change: {
59
56
  condition: '<',
@@ -63,9 +60,6 @@ describe('Test ScriptDetail', () => {
63
60
  sensor_id: 73,
64
61
  value: 35,
65
62
  },
66
- script: {
67
- id: 1,
68
- },
69
63
  },
70
64
  },
71
65
  };
@@ -89,7 +83,7 @@ describe('Test ScriptDetail', () => {
89
83
  });
90
84
  const instance = tree.root;
91
85
  const menu = instance.findByType(MenuActionMore);
92
- const alertAction = instance.findByType(AlertAction);
86
+ const alertAction = instance.findAllByType(AlertAction)[0];
93
87
  const rename = menu.props.listMenuItem[0];
94
88
 
95
89
  await act(async () => {
@@ -115,7 +109,7 @@ describe('Test ScriptDetail', () => {
115
109
  });
116
110
  const instance = tree.root;
117
111
  const menu = instance.findByType(MenuActionMore);
118
- const alertAction = instance.findByType(AlertAction);
112
+ const alertAction = instance.findAllByType(AlertAction)[0];
119
113
  const rename = menu.props.listMenuItem[0];
120
114
 
121
115
  await act(async () => {
@@ -124,7 +118,7 @@ describe('Test ScriptDetail', () => {
124
118
  expect(menu.props.isVisible).toBeFalsy();
125
119
  expect(alertAction.props.visible).toBeTruthy();
126
120
 
127
- mock.onPatch(API.AUTOMATE.SCRIPT(1)).reply(500, { name: 'new_name' });
121
+ mock.onPatch(API.AUTOMATE.SCRIPT(1)).reply(500);
128
122
  await act(async () => {
129
123
  await alertAction.props.rightButtonClick();
130
124
  });
@@ -132,14 +126,34 @@ describe('Test ScriptDetail', () => {
132
126
  expect(Toast.show).toHaveBeenCalled();
133
127
  });
134
128
 
129
+ it('test cannot rename script', async () => {
130
+ route.params.preAutomate.can_edit = false;
131
+ const spyToastError = jest.spyOn(ToastBottomHelper, 'error');
132
+
133
+ await act(async () => {
134
+ tree = await create(wrapComponent(route));
135
+ });
136
+ const instance = tree.root;
137
+ const menu = instance.findByProps({
138
+ accessibilityLabel: AccessibilityLabel.ICON_MORE,
139
+ });
140
+
141
+ await act(async () => {
142
+ await menu.props.onPress();
143
+ });
144
+ expect(spyToastError).toBeCalledWith(
145
+ getTranslate('en', 'only_owner_has_permission_to_edit_this_script')
146
+ );
147
+ });
148
+
135
149
  it('test delete script', async () => {
136
150
  await act(async () => {
137
151
  tree = await create(wrapComponent(route));
138
152
  });
139
153
  const instance = tree.root;
140
154
  const menu = instance.findByType(MenuActionMore);
141
- const alertAction = instance.findByType(AlertAction);
142
- const deleteItem = menu.props.listMenuItem[3];
155
+ const alertAction = instance.findAllByType(AlertAction)[1];
156
+ const deleteItem = menu.props.listMenuItem[2];
143
157
 
144
158
  await act(async () => {
145
159
  await menu.props.onItemClick(deleteItem);
@@ -187,6 +201,8 @@ describe('Test ScriptDetail', () => {
187
201
 
188
202
  it('test activate one tap', async () => {
189
203
  mock.onGet(API.AUTOMATE.SCRIPT(1)).reply(200, data);
204
+ route.params.preAutomate.type = AUTOMATE_TYPE.ONE_TAP;
205
+
190
206
  await act(async () => {
191
207
  tree = await create(wrapComponent(route));
192
208
  });
@@ -220,13 +236,25 @@ describe('Test ScriptDetail', () => {
220
236
  await button.props.onPress();
221
237
  });
222
238
  expect(mockNavigate).toHaveBeenCalledWith(Routes.SelectControlDevices, {
223
- unit: route.params.unit,
224
- automateId: route.params.id,
225
- scriptName: route.params.name,
226
- type: AUTOMATE_TYPE.ONE_TAP,
227
- oldType: AUTOMATE_TYPE.ONE_TAP,
228
- automate: route.params.automate,
239
+ unitId: route.params.preAutomate.unit,
240
+ automateId: route.params.preAutomate.id,
241
+ });
242
+ });
243
+
244
+ it('test not see add action', async () => {
245
+ route.params.preAutomate.can_edit = false;
246
+ mock.onGet(API.AUTOMATE.SCRIPT(1)).reply(200, data);
247
+ await act(async () => {
248
+ tree = await create(wrapComponent(route));
229
249
  });
250
+ const instance = tree.root;
251
+ const buttons = instance.findAll(
252
+ (el) =>
253
+ el.props.accessibilityLabel ===
254
+ AccessibilityLabel.BUTTON_ADD_SCRIPT_ACTION &&
255
+ el.type === TouchableOpacity
256
+ );
257
+ expect(buttons).toHaveLength(0);
230
258
  });
231
259
 
232
260
  it('test onPress onGoBack', async () => {
@@ -240,21 +268,24 @@ describe('Test ScriptDetail', () => {
240
268
  await act(async () => {
241
269
  await WrapHeaderScrollables[0].props.onGoBack();
242
270
  });
243
- expect(mockNavigate).toBeCalled();
271
+ expect(mockGoBack).toBeCalled();
244
272
  });
245
273
 
246
- const _testGoToActivityLog = (automateType, activityLogType, isMultiUnit) => {
247
- it('test go to activity log', async () => {
248
- route.params.type = automateType;
249
- if (isMultiUnit) {
250
- route.params.unit.id = undefined;
251
- }
274
+ const _testGoToActivityLog = (
275
+ count,
276
+ automateType,
277
+ activityLogType,
278
+ unitId
279
+ ) => {
280
+ it(`test go to activity log ${count}`, async () => {
281
+ route.params.preAutomate.type = automateType;
282
+ route.params.preAutomate.unit = unitId;
252
283
  await act(async () => {
253
284
  tree = await create(wrapComponent(route));
254
285
  });
255
286
  const instance = tree.root;
256
287
  const menu = instance.findByType(MenuActionMore);
257
- const gotoActivityLog = menu.props.listMenuItem[2];
288
+ const gotoActivityLog = menu.props.listMenuItem[1];
258
289
 
259
290
  await act(async () => {
260
291
  await menu.props.onItemClick(gotoActivityLog);
@@ -262,9 +293,9 @@ describe('Test ScriptDetail', () => {
262
293
  expect(mockNavigate).toHaveBeenCalledWith(Routes.ActivityLog, {
263
294
  id: route.params.id,
264
295
  type: activityLogType,
265
- share: route.params.unit,
296
+ share: unitId,
266
297
  filterEnabled: {
267
- user: !isMultiUnit,
298
+ user: !!unitId,
268
299
  date: true,
269
300
  },
270
301
  });
@@ -272,18 +303,19 @@ describe('Test ScriptDetail', () => {
272
303
  };
273
304
 
274
305
  _testGoToActivityLog(
306
+ 1,
275
307
  AUTOMATE_TYPE.ONE_TAP,
276
308
  `automate.${AUTOMATE_TYPE.ONE_TAP}`,
277
- false
309
+ 2
278
310
  );
279
- _testGoToActivityLog(AUTOMATE_TYPE.VALUE_CHANGE, 'automate', false);
280
- _testGoToActivityLog(AUTOMATE_TYPE.VALUE_CHANGE, 'automate', true);
311
+ _testGoToActivityLog(2, AUTOMATE_TYPE.VALUE_CHANGE, 'automate', 2);
312
+ _testGoToActivityLog(3, AUTOMATE_TYPE.VALUE_CHANGE, 'automate', undefined);
281
313
 
282
314
  it('Test render textCondition value change >', async () => {
283
315
  route.params = {
284
316
  ...route.params,
285
- type: AUTOMATE_TYPE.VALUE_CHANGE,
286
- automate: {
317
+ preAutomate: {
318
+ type: AUTOMATE_TYPE.VALUE_CHANGE,
287
319
  value_change: {
288
320
  config_name: 'Light Value',
289
321
  value: 3,
@@ -296,7 +328,7 @@ describe('Test ScriptDetail', () => {
296
328
  });
297
329
  const instance = tree.root;
298
330
  const itemAutomate = instance.findByType(ItemAutomate);
299
- expect(itemAutomate.props.textCondition).toEqual(
331
+ expect(itemAutomate.findAllByType(Text)[1].props.children).toEqual(
300
332
  'Light Value higher than 3'
301
333
  );
302
334
 
@@ -309,8 +341,8 @@ describe('Test ScriptDetail', () => {
309
341
  it('Test render textCondition value change =', async () => {
310
342
  route.params = {
311
343
  ...route.params,
312
- type: AUTOMATE_TYPE.VALUE_CHANGE,
313
- automate: {
344
+ preAutomate: {
345
+ type: AUTOMATE_TYPE.VALUE_CHANGE,
314
346
  value_change: { config_name: 'Light Value', value: 3, condition: '=' },
315
347
  },
316
348
  };
@@ -319,14 +351,16 @@ describe('Test ScriptDetail', () => {
319
351
  });
320
352
  const instance = tree.root;
321
353
  const itemAutomate = instance.findByType(ItemAutomate);
322
- expect(itemAutomate.props.textCondition).toEqual('Light Value equal 3');
354
+ expect(itemAutomate.findAllByType(Text)[1].props.children).toEqual(
355
+ 'Light Value equal 3'
356
+ );
323
357
  });
324
358
 
325
359
  it('Test render textCondition value change <', async () => {
326
360
  route.params = {
327
361
  ...route.params,
328
- type: AUTOMATE_TYPE.VALUE_CHANGE,
329
- automate: {
362
+ preAutomate: {
363
+ type: AUTOMATE_TYPE.VALUE_CHANGE,
330
364
  value_change: {
331
365
  config_name: 'Light Value',
332
366
  value: 3,
@@ -339,7 +373,7 @@ describe('Test ScriptDetail', () => {
339
373
  });
340
374
  const instance = tree.root;
341
375
  const itemAutomate = instance.findByType(ItemAutomate);
342
- expect(itemAutomate.props.textCondition).toEqual(
376
+ expect(itemAutomate.findAllByType(Text)[1].props.children).toEqual(
343
377
  'Light Value lower than 3'
344
378
  );
345
379
  });
@@ -347,8 +381,8 @@ describe('Test ScriptDetail', () => {
347
381
  it('Test render textCondition schedule repeat everyday', async () => {
348
382
  route.params = {
349
383
  ...route.params,
350
- type: AUTOMATE_TYPE.SCHEDULE,
351
- automate: {
384
+ preAutomate: {
385
+ type: AUTOMATE_TYPE.SCHEDULE,
352
386
  schedule: {
353
387
  repeat: 'every_day',
354
388
  date_repeat: '2022-01-02',
@@ -361,14 +395,16 @@ describe('Test ScriptDetail', () => {
361
395
  });
362
396
  const instance = tree.root;
363
397
  const itemAutomate = instance.findByType(ItemAutomate);
364
- expect(itemAutomate.props.textCondition).toEqual('Every day at 19:00');
398
+ expect(itemAutomate.findAllByType(Text)[1].props.children).toEqual(
399
+ 'Every day at 19:00'
400
+ );
365
401
  });
366
402
 
367
403
  it('Test render textCondition schedule repeat weekday', async () => {
368
404
  route.params = {
369
405
  ...route.params,
370
- type: AUTOMATE_TYPE.SCHEDULE,
371
- automate: {
406
+ preAutomate: {
407
+ type: AUTOMATE_TYPE.SCHEDULE,
372
408
  schedule: {
373
409
  repeat: 'every_week',
374
410
  date_repeat: '2022-01-02',
@@ -382,7 +418,7 @@ describe('Test ScriptDetail', () => {
382
418
  });
383
419
  const instance = tree.root;
384
420
  const itemAutomate = instance.findByType(ItemAutomate);
385
- expect(itemAutomate.props.textCondition).toEqual(
421
+ expect(itemAutomate.findAllByType(Text)[1].props.children).toEqual(
386
422
  'Mon, Tue, Thu, Sat at 19:00'
387
423
  );
388
424
  });
@@ -1,12 +1,12 @@
1
1
  import React from 'react';
2
2
  import { act, renderHook } from '@testing-library/react-hooks';
3
- import { SCProvider } from '../../../context';
4
- import { mockSCStore } from '../../../context/mockStore';
3
+ import { SCProvider } from '../../../../context';
4
+ import { mockSCStore } from '../../../../context/mockStore';
5
5
  import { useStarredScript } from '../hooks/useStarredScript';
6
6
  import MockAdapter from 'axios-mock-adapter';
7
- import api from '../../../utils/Apis/axios';
8
- import { API } from '../../../configs';
9
- import { Action } from '../../../context/actionType';
7
+ import api from '../../../../utils/Apis/axios';
8
+ import { API } from '../../../../configs';
9
+ import { Action } from '../../../../context/actionType';
10
10
 
11
11
  const mockedSetAction = jest.fn();
12
12
  const mock = new MockAdapter(api.axiosInstance);
@@ -22,8 +22,9 @@ React.useContext = mockUseContext;
22
22
 
23
23
  jest.mock('react-native-deep-linking');
24
24
 
25
- describe('Test useStarredScript', async () => {
25
+ describe('Test useStarredScript', () => {
26
26
  let props;
27
+
27
28
  beforeEach(() => {
28
29
  mockedSetAction.mockClear();
29
30
  props = {
@@ -1,8 +1,8 @@
1
1
  import { useCallback, useContext } from 'react';
2
- import { SCContext, useSCContextSelector } from '../../../context';
3
- import { Action } from '../../../context/actionType';
4
- import { axiosPost } from '../../../utils/Apis/axios';
5
- import { API } from '../../../configs';
2
+ import { SCContext, useSCContextSelector } from '../../../../context';
3
+ import { Action } from '../../../../context/actionType';
4
+ import { axiosPost } from '../../../../utils/Apis/axios';
5
+ import { API } from '../../../../configs';
6
6
 
7
7
  export const useStarredScript = (automate) => {
8
8
  const { setAction } = useContext(SCContext);