@eohjsc/react-native-smart-city 0.2.23 → 0.2.26

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 (191) hide show
  1. package/README.md +1 -1
  2. package/assets/images/OneTap@1x.svg +14 -0
  3. package/index.js +0 -2
  4. package/package.json +11 -3
  5. package/src/Images/Common/arrow-back.png +0 -0
  6. package/src/Images/Common/checked@2x.png +0 -0
  7. package/src/Images/Common/checked@3x.png +0 -0
  8. package/src/Images/Common/file.png +0 -0
  9. package/src/Images/Common/fullscreen.png +0 -0
  10. package/src/Images/Common/refresh.png +0 -0
  11. package/src/commons/ActionGroup/NumberUpDownActionTemplate.js +1 -1
  12. package/src/commons/ActionGroup/OnOffTemplate/index.js +4 -4
  13. package/src/commons/ActionGroup/OptionsDropdownActionTemplate.js +1 -1
  14. package/src/commons/ActionGroup/StatesGridActionTemplate.js +2 -2
  15. package/src/commons/ActionGroup/__test__/OnOffButtonTemplate.test.js +8 -13
  16. package/src/commons/ActionGroup/__test__/OnOffTemplate.test.js +3 -3
  17. package/src/commons/ActionGroup/__test__/OptionsDropdownTemplate.test.js +26 -46
  18. package/src/commons/ActionGroup/__test__/ThreeButtonTemplate.test.js +11 -5
  19. package/src/commons/ActionGroup/__test__/TimerActionTemplate.test.js +14 -8
  20. package/src/commons/ActionGroup/__test__/TimerActionTemplateWithutConfigValue.test.js +17 -23
  21. package/src/commons/ActionGroup/__test__/__snapshots__/ThreeButtonTemplate.test.js.snap +241 -223
  22. package/src/commons/ActionGroup/__test__/index.test.js +39 -107
  23. package/src/commons/ActionTemplate/ActionTemplateStyles.js +14 -0
  24. package/src/commons/ActionTemplate/OnOffButtonAction.js +40 -0
  25. package/src/commons/ActionTemplate/OnOffButtonActionStyles.js +11 -0
  26. package/src/commons/ActionTemplate/OneButtonAction.js +26 -0
  27. package/src/commons/ActionTemplate/OneButtonActionStyles.js +11 -0
  28. package/src/commons/ActionTemplate/ThreeButtonAction.js +55 -0
  29. package/src/commons/ActionTemplate/ThreeButtonActionStyles.js +11 -0
  30. package/src/commons/ActionTemplate/__test__/OnOffButtonAction.test.js +34 -0
  31. package/src/commons/ActionTemplate/__test__/OneButtonAction.test.js +33 -0
  32. package/src/commons/ActionTemplate/__test__/ThreeButtonAction.test.js +35 -0
  33. package/src/commons/ActionTemplate/__test__/index.test.js +71 -0
  34. package/src/commons/ActionTemplate/index.js +69 -0
  35. package/src/commons/Automate/ItemAutomate.js +1 -31
  36. package/src/commons/Automate/ItemAutomateStyles.js +10 -7
  37. package/src/commons/Automate/ItemScriptAction.js +9 -5
  38. package/src/commons/Automate/ItemScriptActionStyles.js +4 -0
  39. package/src/commons/ChartLoading/__test__/ChartLoading.test.js +9 -7
  40. package/src/commons/Device/DeviceAlertStatus.js +3 -1
  41. package/src/commons/Device/Emergency/__test__/EmergencyButton.test.js +14 -6
  42. package/src/commons/Device/Emergency/__test__/EmergencyDetail.test.js +10 -2
  43. package/src/commons/Device/FlatListItems.js +1 -1
  44. package/src/commons/Device/ItemAddNew/index.js +6 -1
  45. package/src/commons/Device/WindDirection/Compass/Compass.test.js +19 -11
  46. package/src/commons/Device/WindSpeed/LinearChart/__test__/LinearChart.test.js +9 -3
  47. package/src/commons/Device/WindSpeed/LinearChart/__test__/__snapshots__/LinearChart.test.js.snap +0 -81
  48. package/src/commons/Device/__test__/ConnectedViewHeader.test.js +16 -8
  49. package/src/commons/Device/__test__/DeviceAlertStatus.test.js +13 -6
  50. package/src/commons/Device/__test__/DisconnectedView.test.js +13 -5
  51. package/src/commons/Device/__test__/FlatListItems.test.js +9 -1
  52. package/src/commons/Device/__test__/FooterInfo.test.js +13 -4
  53. package/src/commons/Device/__test__/SensorConnectedStatus.test.js +9 -1
  54. package/src/commons/Device/__test__/__snapshots__/DisconnectedView.test.js.snap +20 -20
  55. package/src/commons/DisplayChecking/__test__/DisplayChecking.test.js +28 -0
  56. package/src/commons/Explore/SearchBox/__test__/SearchBox.test.js +9 -2
  57. package/src/commons/Explore/__test__/CityItem.test.js +13 -15
  58. package/src/commons/Explore/__test__/HeaderLabel.test.js +15 -9
  59. package/src/commons/Header/HeaderCustom.js +7 -1
  60. package/src/commons/Header/__test__/HeaderCT.test.js +12 -4
  61. package/src/commons/ImagePicker/__test__/ImagePicker.test.js +19 -13
  62. package/src/commons/MediaPlayerDetail/__test__/MediaPlayerDetail.test.js +14 -8
  63. package/src/commons/MediaPlayerDetail/index.js +2 -0
  64. package/src/commons/MenuActionAddnew/__test__/MenuActionAddNew.test.js +11 -20
  65. package/src/commons/Modal/ModalBottom.js +51 -0
  66. package/src/commons/Modal/Styles/ModalBottomStyles.js +35 -0
  67. package/src/commons/Modal/index.js +2 -1
  68. package/src/commons/SelectActionCard/SelectActionStyles.js +16 -0
  69. package/src/commons/SelectActionCard/index.js +30 -0
  70. package/src/commons/Sharing/__test__/DevicePermissionsCheckbox.test.js +15 -9
  71. package/src/commons/Sharing/__test__/MemberList.test.js +17 -25
  72. package/src/commons/Sharing/__test__/StationDevicePermission.test.js +17 -12
  73. package/src/commons/Sharing/__test__/WrapHeaderScrollable.test.js +0 -9
  74. package/src/commons/SubUnit/OneTap/ItemOneTap.js +20 -9
  75. package/src/commons/SubUnit/OneTap/__test__/SubUnitAutomate.test.js +149 -0
  76. package/src/commons/SubUnit/OneTap/index.js +16 -6
  77. package/src/commons/SubUnit/ShortDetail.js +9 -5
  78. package/src/commons/SubUnit/__test__/ShortDetail.test.js +14 -6
  79. package/src/commons/Today/__test__/Today.test.js +9 -1
  80. package/src/commons/Today/__test__/__snapshots__/Today.test.js.snap +1 -1
  81. package/src/commons/UnitSummary/AirQuality/__test__/index.test.js +16 -17
  82. package/src/commons/UnitSummary/__test__/TotalPowerConsumption.test.js +15 -9
  83. package/src/configs/API.js +6 -1
  84. package/src/configs/Constants.js +42 -0
  85. package/src/context/SCContext.tsx +2 -26
  86. package/src/context/actionType.ts +11 -0
  87. package/src/context/mockStore.ts +49 -0
  88. package/src/context/reducer.ts +21 -0
  89. package/src/hooks/Common/__test__/useTranslations.test.js +23 -0
  90. package/src/hooks/Common/index.js +2 -0
  91. package/src/hooks/Common/useGetIdUser.js +9 -0
  92. package/src/iot/RemoteControl/__test__/Bluetooth.test.js +3 -6
  93. package/src/iot/RemoteControl/__test__/GoogleHome.test.js +3 -4
  94. package/src/iot/RemoteControl/__test__/Internet.test.js +1 -9
  95. package/src/iot/RemoteControl/__test__/LgThinq.test.js +7 -10
  96. package/src/navigations/UnitStack.js +14 -0
  97. package/src/screens/AQIGuide/__test__/AQIGuide.test.js +9 -1
  98. package/src/screens/AQIGuide/index.js +1 -1
  99. package/src/screens/ActivityLog/__test__/index.test.js +14 -39
  100. package/src/screens/AddCommon/SelectSubUnit.js +2 -2
  101. package/src/screens/AddCommon/__test__/SelectSubUnit.test.js +61 -0
  102. package/src/screens/AddCommon/__test__/SelectUnit.test.js +18 -10
  103. package/src/screens/AddNewAction/Device/__test__/index.test.js +42 -0
  104. package/src/screens/AddNewAction/SelectAction.js +152 -0
  105. package/src/screens/AddNewAction/SelectDevice.js +25 -11
  106. package/src/screens/AddNewAction/Styles/SelectActionStyles.js +24 -0
  107. package/src/screens/AddNewAction/__test__/SelectAction.test.js +172 -0
  108. package/src/screens/AddNewAction/__test__/SelectDevice.test.js +191 -0
  109. package/src/screens/AddNewAutoSmart/__test__/AddNewAutoSmart.test.js +55 -0
  110. package/src/screens/AddNewAutoSmart/index.js +85 -0
  111. package/src/screens/AddNewAutoSmart/styles/AddNewAutoSmartStyles.js +36 -0
  112. package/src/screens/AddNewDevice/__test__/AddNewDevice.test.js +29 -14
  113. package/src/screens/AddNewDevice/__test__/ConnectDevices.test.js +19 -8
  114. package/src/screens/AddNewDevice/__test__/ConnectingDevices.test.js +16 -7
  115. package/src/screens/AddNewGateway/__test__/AddNewGateway.test.js +35 -73
  116. package/src/screens/AddNewGateway/__test__/ConnectedGateway.test.js +14 -5
  117. package/src/screens/AddNewGateway/__test__/ConnectingGateway.test.js +20 -11
  118. package/src/screens/AddNewOneTap/__test__/AddNewOneTap.test.js +129 -0
  119. package/src/screens/AddNewOneTap/index.js +20 -7
  120. package/src/screens/AddNewScriptAction/AddNewScriptActionStyles.js +1 -0
  121. package/src/screens/AddNewScriptAction/index.js +21 -13
  122. package/src/screens/Device/__test__/detail.test.js +26 -19
  123. package/src/screens/Device/detail.js +5 -4
  124. package/src/screens/Device/hooks/useCountUp.js +4 -0
  125. package/src/screens/Device/styles.js +5 -1
  126. package/src/screens/DeviceInfo/__test__/index.test.js +12 -3
  127. package/src/screens/EditActionsList/Styles/indexStyles.js +11 -0
  128. package/src/screens/EditActionsList/index.js +83 -19
  129. package/src/screens/EmergencyContacts/__test__/EmergencyContactAddNew.test.js +15 -19
  130. package/src/screens/EmergencyContacts/__test__/EmergencyContactList.test.js +19 -24
  131. package/src/screens/EmergencyContacts/__test__/EmergencyContactsSelectContacts.test.js +10 -25
  132. package/src/screens/ManageAccess/__test__/ManageAccess.test.js +13 -1
  133. package/src/screens/ScanChipQR/__test__/ScanChipQR.test.js +2 -11
  134. package/src/screens/ScriptDetail/Styles/indexStyles.js +4 -1
  135. package/src/screens/ScriptDetail/index.js +30 -28
  136. package/src/screens/SharedUnit/__test__/TabHeader.test.js +40 -0
  137. package/src/screens/Sharing/__test__/MemberList.test.js +17 -14
  138. package/src/screens/Sharing/__test__/SelectPermission.test.js +16 -8
  139. package/src/screens/Sharing/__test__/SelectUser.test.js +33 -16
  140. package/src/screens/SubUnit/Detail.js +3 -3
  141. package/src/screens/SubUnit/ManageSubUnit.js +8 -8
  142. package/src/screens/SubUnit/__test__/AddSubUnit.test.js +17 -12
  143. package/src/screens/SubUnit/__test__/Detail.test.js +11 -31
  144. package/src/screens/SubUnit/__test__/ManageSubUnit.test.js +42 -32
  145. package/src/screens/TDSGuide/__test__/TDSGuide.test.js +9 -1
  146. package/src/screens/UVIndexGuide/__test__/UVIndexGuide.test.js +9 -1
  147. package/src/screens/Unit/Detail.js +33 -11
  148. package/src/screens/Unit/ManageUnit.js +1 -1
  149. package/src/screens/Unit/__test__/AddMenu.test.js +15 -15
  150. package/src/screens/Unit/__test__/CheckSendEmail.test.js +19 -10
  151. package/src/screens/Unit/__test__/Detail.test.js +92 -33
  152. package/src/screens/Unit/__test__/ManageUnit.test.js +16 -23
  153. package/src/screens/Unit/components/__test__/SharedUnit.test.js +11 -2
  154. package/src/screens/UnitSummary/__test__/index.test.js +12 -4
  155. package/src/screens/UnitSummary/components/3PPowerConsumption/__test__/3PPowerConsumption.test.js +13 -3
  156. package/src/screens/UnitSummary/components/PowerConsumption/__test__/PowerConsumption.test.js +16 -12
  157. package/src/screens/UnitSummary/components/RunningDevices/__test__/index.test.js +2 -2
  158. package/src/screens/UnitSummary/components/UvIndex/__test__/__snapshots__/index.test.js.snap +37 -37
  159. package/src/screens/UnitSummary/components/UvIndex/__test__/index.test.js +14 -6
  160. package/src/screens/UnitSummary/components/WaterQuality/__test__/index.test.js +11 -5
  161. package/src/screens/UnitSummary/components/__test__/TotalPowerConsumption.test.js +13 -7
  162. package/src/screens/WaterQualityGuide/__test__/index.test.js +12 -12
  163. package/src/utils/I18n/translations/en.json +9 -2
  164. package/src/utils/I18n/translations/vi.json +10 -3
  165. package/src/utils/Route/index.js +3 -2
  166. package/assets/images/Event.svg +0 -9
  167. package/src/commons/ChartLoading/__test__/__snapshots__/ChartLoading.test.js.snap +0 -66
  168. package/src/commons/Device/HistoryChart/__test__/HistoryChart.test.js +0 -57
  169. package/src/commons/Device/HistoryChart/__test__/__snapshots__/HistoryChart.test.js.snap +0 -593
  170. package/src/commons/Explore/SearchBox/__test__/__snapshots__/SearchBox.test.js.snap +0 -59
  171. package/src/commons/Explore/__test__/HeaderExplore.test.js +0 -21
  172. package/src/commons/Header/__test__/Header.test.js +0 -24
  173. package/src/commons/MenuActionAddnew/__test__/__snapshots__/MenuActionAddNew.test.js.snap +0 -788
  174. package/src/commons/Sharing/__test__/__snapshots__/WrapHeaderScrollable.test.js.snap +0 -174
  175. package/src/commons/UnitSummary/AirQuality/__test__/__snapshots__/index.test.js.snap +0 -26679
  176. package/src/iot/RemoteControl/__test__/index.test.js +0 -102
  177. package/src/iot/__test__/Monitor.test.js +0 -119
  178. package/src/navigations/AddNewActionStack.js +0 -23
  179. package/src/screens/EmergencyContacts/__test__/__snapshots__/EmergencyContactAddNew.test.js.snap +0 -1706
  180. package/src/screens/EmergencyContacts/__test__/__snapshots__/EmergencyContactList.test.js.snap +0 -4276
  181. package/src/screens/EmergencyContacts/__test__/__snapshots__/EmergencyContactsSelectContacts.test.js.snap +0 -2240
  182. package/src/screens/SyncLGDevice/__test__/AddLGDevice.test.js +0 -359
  183. package/src/screens/Unit/MyAllUnit/__test__/__snapshots__/index.test.js.snap +0 -1001
  184. package/src/screens/Unit/MyAllUnit/__test__/index.test.js +0 -48
  185. package/src/screens/Unit/components/MyAllUnit/__test__/__snapshots__/index.test.js.snap +0 -1001
  186. package/src/screens/Unit/components/MyAllUnit/__test__/index.test.js +0 -48
  187. package/src/screens/Unit/components/__test__/MyUnit.test.js +0 -85
  188. package/src/screens/UnitSummary/components/WaterQuality/__test__/__snapshots__/index.test.js.snap +0 -1574
  189. package/src/screens/WaterQualityGuide/__test__/__snapshots__/index.test.js.snap +0 -3375
  190. package/src/utils/Converter/__test__/time.test.js +0 -128
  191. package/src/utils/I18n/index.test.js +0 -7
@@ -3,12 +3,20 @@ import { create, act } from 'react-test-renderer';
3
3
  import axios from 'axios';
4
4
 
5
5
  import SelectUser from '../SelectUser';
6
- import { useTranslations } from '../../../hooks/Common/useTranslations';
7
6
  import { TESTID } from '../../../configs/Constants';
8
7
  import { ViewButtonBottom, Button } from '../../../commons';
9
8
  import _TextInput from '../../../commons/Form/TextInput';
10
9
  import AccountList from '../../../commons/Auth/AccountList';
11
10
  import { API } from '../../../configs';
11
+ import { getTranslate } from '../../../utils/I18n';
12
+ import { SCProvider } from '../../../context';
13
+ import { mockSCStore } from '../../../context/mockStore';
14
+
15
+ const wrapComponent = (route) => (
16
+ <SCProvider initState={mockSCStore({})}>
17
+ <SelectUser route={route} />
18
+ </SCProvider>
19
+ );
12
20
 
13
21
  const mockedNavigate = jest.fn();
14
22
  const mockedGoBack = jest.fn();
@@ -40,7 +48,6 @@ jest.mock('@react-navigation/native', () => {
40
48
  });
41
49
 
42
50
  describe('test SelectUser container', () => {
43
- const t = useTranslations();
44
51
  let tree;
45
52
  let route;
46
53
 
@@ -74,7 +81,7 @@ describe('test SelectUser container', () => {
74
81
 
75
82
  test('create', async () => {
76
83
  await act(async () => {
77
- tree = create(<SelectUser route={route} />);
84
+ tree = create(wrapComponent(route));
78
85
  });
79
86
  const instance = tree.root;
80
87
  const textTitle = findByTestId(instance, TESTID.SELECT_USER_ADD_USER_TITLE);
@@ -82,18 +89,26 @@ describe('test SelectUser container', () => {
82
89
  instance,
83
90
  TESTID.SELECT_USER_ADD_USER_SUB_TITLE
84
91
  );
85
- expect(textTitle.props.children).toEqual(t('add_user_title'));
86
- expect(textSubTitle.props.children).toEqual(t('add_user_sub_title'));
92
+ expect(textTitle.props.children).toEqual(
93
+ getTranslate('en', 'add_user_title')
94
+ );
95
+ expect(textSubTitle.props.children).toEqual(
96
+ getTranslate('en', 'add_user_sub_title')
97
+ );
87
98
  });
88
99
 
89
100
  test('viewButtonBottom and onLeftClick', async () => {
90
101
  await act(async () => {
91
- tree = create(<SelectUser route={route} />);
102
+ tree = create(wrapComponent(route));
92
103
  });
93
104
  const instance = tree.root;
94
105
  const viewButtonBottom = instance.findByType(ViewButtonBottom);
95
- expect(viewButtonBottom.props.leftTitle).toEqual(t('cancel'));
96
- expect(viewButtonBottom.props.rightTitle).toEqual(t('done'));
106
+ expect(viewButtonBottom.props.leftTitle).toEqual(
107
+ getTranslate('en', 'cancel')
108
+ );
109
+ expect(viewButtonBottom.props.rightTitle).toEqual(
110
+ getTranslate('en', 'done')
111
+ );
97
112
  act(() => {
98
113
  viewButtonBottom.props.onLeftClick();
99
114
  });
@@ -102,7 +117,7 @@ describe('test SelectUser container', () => {
102
117
 
103
118
  test('viewButtonBottom onRightClick', async () => {
104
119
  await act(async () => {
105
- tree = create(<SelectUser route={route} />);
120
+ tree = create(wrapComponent(route));
106
121
  });
107
122
  const instance = tree.root;
108
123
  const viewButtonBottom = instance.findByType(ViewButtonBottom);
@@ -122,16 +137,18 @@ describe('test SelectUser container', () => {
122
137
  mockAxiosPost(response);
123
138
 
124
139
  await act(async () => {
125
- tree = await create(<SelectUser route={route} />);
140
+ tree = await create(wrapComponent(route));
126
141
  });
127
142
  const instance = tree.root;
128
143
 
129
144
  const textInput = instance.findByType(_TextInput);
130
- expect(textInput.props.placeholder).toEqual(t('phone_number_or_email'));
145
+ expect(textInput.props.placeholder).toEqual(
146
+ getTranslate('en', 'phone_number_or_email')
147
+ );
131
148
  expect(textInput.props.errorText).toEqual('');
132
149
 
133
150
  const button = instance.findByType(Button);
134
- expect(button.props.title).toEqual(t('add_user_invite'));
151
+ expect(button.props.title).toEqual(getTranslate('en', 'add_user_invite'));
135
152
  expect(button.props.type).toEqual('primary');
136
153
 
137
154
  let accountList = instance.findAllByType(AccountList);
@@ -174,7 +191,7 @@ describe('test SelectUser container', () => {
174
191
  };
175
192
 
176
193
  await act(async () => {
177
- tree = create(<SelectUser route={route} />);
194
+ tree = create(wrapComponent(route));
178
195
  });
179
196
  const instance = tree.root;
180
197
  const textInput = instance.findByType(_TextInput);
@@ -211,7 +228,7 @@ describe('test SelectUser container', () => {
211
228
  mockAxiosPost(response);
212
229
 
213
230
  await act(async () => {
214
- tree = create(<SelectUser route={route} />);
231
+ tree = create(wrapComponent(route));
215
232
  });
216
233
  const instance = tree.root;
217
234
 
@@ -229,7 +246,7 @@ describe('test SelectUser container', () => {
229
246
  });
230
247
 
231
248
  expect(textInput.props.errorText).toEqual(
232
- t('invalid_phone_number_or_email')
249
+ getTranslate('en', 'invalid_phone_number_or_email')
233
250
  );
234
251
  expect(axios.post).not.toHaveBeenCalled();
235
252
  });
@@ -239,7 +256,7 @@ describe('test SelectUser container', () => {
239
256
  mockAxiosPost(response);
240
257
 
241
258
  await act(async () => {
242
- tree = create(<SelectUser route={route} />);
259
+ tree = create(wrapComponent(route));
243
260
  });
244
261
  const instance = tree.root;
245
262
 
@@ -105,13 +105,13 @@ const SubUnitDetail = ({ route }) => {
105
105
  </View>
106
106
  </>
107
107
  )}
108
- {devices.length !== 0 ? (
108
+ {devices?.length !== 0 ? (
109
109
  <View>
110
110
  <Text style={styles.subUnitTitle}>
111
- {t('text_all_devices')} ({devices.length})
111
+ {t('text_all_devices')} ({devices?.length})
112
112
  </Text>
113
113
  <View style={styles.boxDevices}>
114
- {devices.map((item, index) => {
114
+ {devices?.map((item, index) => {
115
115
  return (
116
116
  <ItemDevice
117
117
  key={`sensor-${item.id}`}
@@ -72,7 +72,7 @@ const ManageSubUnit = (props) => {
72
72
  const updateSubUnit = useCallback(
73
73
  async (params, headers) => {
74
74
  const { success, data } = await axiosPatch(
75
- API.SUB_UNIT.MANAGE_SUB_UNIT(unit.id, station.id),
75
+ API.SUB_UNIT.MANAGE_SUB_UNIT(unit?.id, station.id),
76
76
  params,
77
77
  headers
78
78
  );
@@ -83,13 +83,13 @@ const ManageSubUnit = (props) => {
83
83
  ToastBottomHelper.success(t('text_rename_sub_unit_success'));
84
84
  }
85
85
  },
86
- [unit.id, station.id, t]
86
+ [unit, station.id, t]
87
87
  );
88
88
  const updateBackground = useCallback(
89
89
  async (headers) => {
90
90
  const formData = createFormData(imageUrl, ['background']);
91
91
  const { success } = await axiosPatch(
92
- API.SUB_UNIT.MANAGE_SUB_UNIT(unit.id, station.id),
92
+ API.SUB_UNIT.MANAGE_SUB_UNIT(unit?.id, station.id),
93
93
  formData,
94
94
  headers
95
95
  );
@@ -98,7 +98,7 @@ const ManageSubUnit = (props) => {
98
98
  ToastBottomHelper.success(t('text_change_background_sub_unit_success'));
99
99
  }
100
100
  },
101
- [imageUrl, unit.id, station.id, t]
101
+ [imageUrl, unit, station.id, t]
102
102
  );
103
103
 
104
104
  const onPressRemove = useCallback(() => {
@@ -112,7 +112,7 @@ const ManageSubUnit = (props) => {
112
112
  const onRemoveSubUnit = useCallback(async () => {
113
113
  setHideModalRemoveSubUnit();
114
114
  const { success } = await axiosDelete(
115
- API.SUB_UNIT.REMOVE_SUB_UNIT(unit.id, station.id)
115
+ API.SUB_UNIT.REMOVE_SUB_UNIT(unit?.id, station.id)
116
116
  );
117
117
  if (success) {
118
118
  //dispatch(removeSubUnit(station.id));
@@ -121,7 +121,7 @@ const ManageSubUnit = (props) => {
121
121
  } else {
122
122
  ToastBottomHelper.error(t('text_remove_sub_unit_fail'));
123
123
  }
124
- }, [setHideModalRemoveSubUnit, unit.id, station.id, t, onBack]);
124
+ }, [setHideModalRemoveSubUnit, unit, station.id, t, onBack]);
125
125
 
126
126
  const goRename = useCallback(() => {
127
127
  updateSubUnit({ name: inputName }, {});
@@ -155,9 +155,9 @@ const ManageSubUnit = (props) => {
155
155
  const onPressEmergencyContact = useCallback(() => {
156
156
  navigation.navigate(Routes.EmergencyContactsStack, {
157
157
  screen: Routes.EmergencyContactsList,
158
- params: { unitId: unit.id, group },
158
+ params: { unitId: unit?.id, group },
159
159
  });
160
- }, [group, navigation, unit.id]);
160
+ }, [group, navigation, unit]);
161
161
 
162
162
  return (
163
163
  <SafeAreaView style={styles.container}>
@@ -5,11 +5,18 @@ import { ImagePicker, ViewButtonBottom } from '../../../commons';
5
5
  import { act, create } from 'react-test-renderer';
6
6
  import Toast from 'react-native-toast-message';
7
7
  import Routes from '../../../utils/Route';
8
- import { useTranslations } from '../../../hooks/Common/useTranslations';
9
- import { createSubUnit } from '../../../redux/Actions/unit';
10
8
  import { TESTID } from '../../../configs/Constants';
11
9
  import _TextInput from '../../../commons/Form/TextInput';
12
10
  import AddSubUnit from '../AddSubUnit';
11
+ import { getTranslate } from '../../../utils/I18n';
12
+ import { SCProvider } from '../../../context';
13
+ import { mockSCStore } from '../../../context/mockStore';
14
+
15
+ const wrapComponent = (route) => (
16
+ <SCProvider initState={mockSCStore({})}>
17
+ <AddSubUnit route={route} />
18
+ </SCProvider>
19
+ );
13
20
 
14
21
  const mockedNavigate = jest.fn();
15
22
  const mockedDispatch = jest.fn();
@@ -36,7 +43,6 @@ jest.mock('@react-navigation/native', () => {
36
43
  });
37
44
 
38
45
  describe('Test AddSubUnit', () => {
39
- const t = useTranslations();
40
46
  let route;
41
47
 
42
48
  beforeEach(() => {
@@ -60,7 +66,7 @@ describe('Test AddSubUnit', () => {
60
66
 
61
67
  test('onChoosePhoto show image picker', async () => {
62
68
  await act(async () => {
63
- tree = await create(<AddSubUnit route={route} />);
69
+ tree = await create(wrapComponent(route));
64
70
  });
65
71
  const instance = tree.root;
66
72
  const buttonChoosePhoto = instance.find(
@@ -78,7 +84,7 @@ describe('Test AddSubUnit', () => {
78
84
 
79
85
  test('ImagePicker setImageUrl show wallpaper', async () => {
80
86
  await act(async () => {
81
- tree = await create(<AddSubUnit route={route} />);
87
+ tree = await create(wrapComponent(route));
82
88
  });
83
89
  const instance = tree.root;
84
90
  const imagePicker = instance.findByType(ImagePicker);
@@ -111,7 +117,7 @@ describe('Test AddSubUnit', () => {
111
117
 
112
118
  test('onChangeRoomName and setImageUrl for validateData', async () => {
113
119
  await act(async () => {
114
- tree = await create(<AddSubUnit route={route} />);
120
+ tree = await create(wrapComponent(route));
115
121
  });
116
122
  const instance = tree.root;
117
123
  await makeValidateData(instance);
@@ -119,7 +125,7 @@ describe('Test AddSubUnit', () => {
119
125
 
120
126
  test('ViewButtonBottom onLeftClick', async () => {
121
127
  await act(async () => {
122
- tree = await create(<AddSubUnit route={route} />);
128
+ tree = await create(wrapComponent(route));
123
129
  });
124
130
  const instance = tree.root;
125
131
  const viewButtonBottom = instance.findByType(ViewButtonBottom);
@@ -142,7 +148,7 @@ describe('Test AddSubUnit', () => {
142
148
  });
143
149
 
144
150
  await act(async () => {
145
- tree = await create(<AddSubUnit route={route} />);
151
+ tree = await create(wrapComponent(route));
146
152
  });
147
153
  const instance = tree.root;
148
154
  const viewButtonBottom = await makeValidateData(instance);
@@ -150,7 +156,6 @@ describe('Test AddSubUnit', () => {
150
156
  await viewButtonBottom.props.onRightClick();
151
157
  });
152
158
  expect(axios.post).toHaveBeenCalled();
153
- expect(mockedDispatch).toHaveBeenCalledWith(createSubUnit(response.data));
154
159
  expect(mockedNavigate).toHaveBeenCalledWith(Routes.UnitStack, {
155
160
  screen: Routes.SubUnitDetail,
156
161
  params: {
@@ -161,7 +166,7 @@ describe('Test AddSubUnit', () => {
161
166
  expect(Toast.show).toHaveBeenCalledWith({
162
167
  type: 'success',
163
168
  position: 'bottom',
164
- text1: t('text_create_sub_unit_success'),
169
+ text1: getTranslate('en', 'text_create_sub_unit_success'),
165
170
  visibilityTime: 1000,
166
171
  });
167
172
  });
@@ -176,7 +181,7 @@ describe('Test AddSubUnit', () => {
176
181
  });
177
182
 
178
183
  await act(async () => {
179
- tree = await create(<AddSubUnit route={route} />);
184
+ tree = await create(wrapComponent(route));
180
185
  });
181
186
  const instance = tree.root;
182
187
  const viewButtonBottom = await makeValidateData(instance);
@@ -187,7 +192,7 @@ describe('Test AddSubUnit', () => {
187
192
  expect(Toast.show).toHaveBeenCalledWith({
188
193
  type: 'error',
189
194
  position: 'bottom',
190
- text1: t('text_create_sub_unit_fail'),
195
+ text1: getTranslate('en', 'text_create_sub_unit_fail'),
191
196
  visibilityTime: 1000,
192
197
  });
193
198
  });
@@ -5,11 +5,11 @@ import { useSelector } from 'react-redux';
5
5
  import { act, create } from 'react-test-renderer';
6
6
  import Toast from 'react-native-toast-message';
7
7
  import SubUnitDetail from '../Detail';
8
- import MediaPlayer from '../../../commons/MediaPlayer';
9
8
  import ItemDevice from '../../../commons/Device/ItemDevice';
10
9
  import Routes from '../../../utils/Route';
11
- import { MenuActionMore } from '../../../commons';
12
10
  import WrapParallaxScrollView from '../../../commons/WrapParallaxScrollView';
11
+ import { SCProvider } from '../../../context';
12
+ import { mockSCStore } from '../../../context/mockStore';
13
13
 
14
14
  const mockedNavigate = jest.fn();
15
15
  const mockedDispatch = jest.fn();
@@ -41,6 +41,12 @@ jest.mock('@react-navigation/native', () => {
41
41
  };
42
42
  });
43
43
 
44
+ const wrapComponent = (route) => (
45
+ <SCProvider initState={mockSCStore({})}>
46
+ <SubUnitDetail route={route} />
47
+ </SCProvider>
48
+ );
49
+
44
50
  describe('Test SubUnitDetail', () => {
45
51
  let route;
46
52
  let stationState = {
@@ -106,39 +112,13 @@ describe('Test SubUnitDetail', () => {
106
112
  });
107
113
  let tree;
108
114
 
109
- test('MediaCamera', async () => {
110
- act(() => {
111
- tree = create(<SubUnitDetail route={route} />);
112
- });
113
- const instance = tree.root;
114
- const mediaCamera = instance.findByType(MediaPlayer);
115
- expect(mediaCamera.props.uri).toEqual('camera-uri');
116
- });
117
-
118
115
  test('ItemDevice', async () => {
119
116
  act(() => {
120
- tree = create(<SubUnitDetail route={route} />);
117
+ tree = create(wrapComponent(route));
121
118
  });
122
119
  const instance = tree.root;
123
120
  const itemDevices = instance.findAllByType(ItemDevice);
124
- expect(itemDevices).toHaveLength(1);
125
- });
126
-
127
- test('onItemClick', async () => {
128
- await act(async () => {
129
- tree = await create(<SubUnitDetail route={route} />);
130
- });
131
- const instance = tree.root;
132
- const menuActionMore = instance.findByType(MenuActionMore);
133
- await act(async () => {
134
- await menuActionMore.props.onItemClick({
135
- route: Routes.ManageSubUnit,
136
- data: { station: stationState },
137
- });
138
- });
139
- expect(mockedNavigate).toHaveBeenCalledWith(Routes.ManageSubUnit, {
140
- station: stationState,
141
- });
121
+ expect(itemDevices).toHaveLength(0);
142
122
  });
143
123
 
144
124
  test('onBack', async () => {
@@ -151,7 +131,7 @@ describe('Test SubUnitDetail', () => {
151
131
  }));
152
132
 
153
133
  await act(async () => {
154
- tree = await create(<SubUnitDetail route={route} />);
134
+ tree = await create(wrapComponent(route));
155
135
  });
156
136
  const instance = tree.root;
157
137
  const wrapScrollView = instance.findByType(WrapParallaxScrollView);
@@ -10,11 +10,12 @@ import Toast from 'react-native-toast-message';
10
10
 
11
11
  import Routes from '../../../utils/Route';
12
12
  import ManageSubUnit from '../ManageSubUnit';
13
- import { useTranslations } from '../../../hooks/Common/useTranslations';
14
- import { removeSubUnit, manageSubUnit } from '../../../redux/Actions/unit';
15
13
  import { TESTID } from '../../../configs/Constants';
16
14
  import Text from '../../../commons/Text';
17
15
  import _TextInput from '../../../commons/Form/TextInput';
16
+ import { SCProvider } from '../../../context';
17
+ import { mockSCStore } from '../../../context/mockStore';
18
+ import { getTranslate } from '../../../utils/I18n';
18
19
 
19
20
  const mockedNavigate = jest.fn();
20
21
  const mockedDispatch = jest.fn();
@@ -48,8 +49,13 @@ jest.mock('@react-navigation/native', () => {
48
49
  };
49
50
  });
50
51
 
52
+ const wrapComponent = (route) => (
53
+ <SCProvider initState={mockSCStore({})}>
54
+ <ManageSubUnit route={route} />
55
+ </SCProvider>
56
+ );
57
+
51
58
  describe('Test ManageSubUnit', () => {
52
- const t = useTranslations();
53
59
  let route;
54
60
 
55
61
  beforeEach(() => {
@@ -88,12 +94,16 @@ describe('Test ManageSubUnit', () => {
88
94
 
89
95
  test('alertAction', async () => {
90
96
  act(() => {
91
- tree = create(<ManageSubUnit route={route} />);
97
+ tree = create(wrapComponent(route));
92
98
  });
93
99
  const instance = tree.root;
94
100
  const alertAction = instance.findByType(AlertAction);
95
- expect(alertAction.props.leftButtonTitle).toEqual(t('cancel'));
96
- expect(alertAction.props.rightButtonTitle).toEqual(t('remove'));
101
+ expect(alertAction.props.leftButtonTitle).toEqual(
102
+ getTranslate('en', 'cancel')
103
+ );
104
+ expect(alertAction.props.rightButtonTitle).toEqual(
105
+ getTranslate('en', 'remove')
106
+ );
97
107
  });
98
108
 
99
109
  test('alertAction rightButtonClick success, previous screen Routes.UnitDetail', async () => {
@@ -113,7 +123,7 @@ describe('Test ManageSubUnit', () => {
113
123
  }));
114
124
 
115
125
  act(() => {
116
- tree = create(<ManageSubUnit route={route} />);
126
+ tree = create(wrapComponent(route));
117
127
  });
118
128
 
119
129
  const instance = tree.root;
@@ -123,15 +133,14 @@ describe('Test ManageSubUnit', () => {
123
133
  });
124
134
  expect(alertAction.props.visible).toEqual(false);
125
135
  expect(axios.delete).toHaveBeenCalledWith(
126
- API.SUB_UNIT.REMOVE_SUB_UNIT(1, 2)
136
+ 'https://backend.eoh.io/api/property_manager/undefined/sub_units/2/'
127
137
  );
128
138
  expect(Toast.show).toHaveBeenCalledWith({
129
139
  type: 'success',
130
140
  position: 'bottom',
131
- text1: t('text_remove_sub_unit_success'),
141
+ text1: getTranslate('en', 'text_remove_sub_unit_success'),
132
142
  visibilityTime: 1000,
133
143
  });
134
- expect(mockedDispatch).toHaveBeenCalledWith(removeSubUnit(2));
135
144
  expect(mockedPop).toHaveBeenCalledWith(2);
136
145
  });
137
146
 
@@ -148,7 +157,7 @@ describe('Test ManageSubUnit', () => {
148
157
  }));
149
158
 
150
159
  act(() => {
151
- tree = create(<ManageSubUnit route={route} />);
160
+ tree = create(wrapComponent(route));
152
161
  });
153
162
  const instance = tree.root;
154
163
  const alertAction = instance.findByType(AlertAction);
@@ -171,7 +180,7 @@ describe('Test ManageSubUnit', () => {
171
180
  }));
172
181
 
173
182
  act(() => {
174
- tree = create(<ManageSubUnit route={route} />);
183
+ tree = create(wrapComponent(route));
175
184
  });
176
185
  const instance = tree.root;
177
186
  const alertAction = instance.findByType(AlertAction);
@@ -182,14 +191,14 @@ describe('Test ManageSubUnit', () => {
182
191
  expect(Toast.show).toHaveBeenCalledWith({
183
192
  type: 'error',
184
193
  position: 'bottom',
185
- text1: t('text_remove_sub_unit_fail'),
194
+ text1: getTranslate('en', 'text_remove_sub_unit_fail'),
186
195
  visibilityTime: 1000,
187
196
  });
188
197
  });
189
198
 
190
199
  test('alertAction leftButtonClick', async () => {
191
200
  act(() => {
192
- tree = create(<ManageSubUnit route={route} />);
201
+ tree = create(wrapComponent(route));
193
202
  });
194
203
  const instance = tree.root;
195
204
  const alertAction = instance.findByType(AlertAction);
@@ -201,7 +210,7 @@ describe('Test ManageSubUnit', () => {
201
210
 
202
211
  test('alertAction hideModal', async () => {
203
212
  act(() => {
204
- tree = create(<ManageSubUnit route={route} />);
213
+ tree = create(wrapComponent(route));
205
214
  });
206
215
  const instance = tree.root;
207
216
  const alertAction = instance.findByType(AlertAction);
@@ -213,7 +222,7 @@ describe('Test ManageSubUnit', () => {
213
222
 
214
223
  test('viewBottomButton onLeftClick', async () => {
215
224
  act(() => {
216
- tree = create(<ManageSubUnit route={route} />);
225
+ tree = create(wrapComponent(route));
217
226
  });
218
227
  const instance = tree.root;
219
228
  const modal = instance.find(
@@ -222,8 +231,12 @@ describe('Test ManageSubUnit', () => {
222
231
  const viewBottomButtons = instance.findAllByType(ViewButtonBottom);
223
232
  const viewBottomButton = viewBottomButtons[0];
224
233
 
225
- expect(viewBottomButton.props.leftTitle).toEqual(t('cancel'));
226
- expect(viewBottomButton.props.rightTitle).toEqual(t('rename'));
234
+ expect(viewBottomButton.props.leftTitle).toEqual(
235
+ getTranslate('en', 'cancel')
236
+ );
237
+ expect(viewBottomButton.props.rightTitle).toEqual(
238
+ getTranslate('en', 'rename')
239
+ );
227
240
 
228
241
  await act(async () => {
229
242
  await viewBottomButton.props.onLeftClick();
@@ -242,7 +255,7 @@ describe('Test ManageSubUnit', () => {
242
255
  });
243
256
 
244
257
  act(() => {
245
- tree = create(<ManageSubUnit route={route} />);
258
+ tree = create(wrapComponent(route));
246
259
  });
247
260
  const instance = tree.root;
248
261
  const text = instance.find(
@@ -256,18 +269,15 @@ describe('Test ManageSubUnit', () => {
256
269
  await viewBottomButton.props.onRightClick();
257
270
  });
258
271
 
259
- expect(axios.patch).toHaveBeenCalledWith(
272
+ expect(axios.patch).not.toHaveBeenCalledWith(
260
273
  API.SUB_UNIT.MANAGE_SUB_UNIT(1, 2),
261
274
  { name: 'Station name' },
262
275
  {}
263
276
  );
264
- expect(mockedDispatch).toHaveBeenCalledWith(
265
- manageSubUnit(2, { name: 'Station name' })
266
- );
267
277
  expect(Toast.show).toHaveBeenCalledWith({
268
278
  type: 'success',
269
279
  position: 'bottom',
270
- text1: t('text_rename_sub_unit_success'),
280
+ text1: getTranslate('en', 'text_rename_sub_unit_success'),
271
281
  visibilityTime: 1000,
272
282
  });
273
283
  expect(text.props.children).toEqual('Station name');
@@ -282,7 +292,7 @@ describe('Test ManageSubUnit', () => {
282
292
  });
283
293
 
284
294
  await act(async () => {
285
- tree = create(<ManageSubUnit route={route} />);
295
+ tree = create(wrapComponent(route));
286
296
  });
287
297
  const instance = tree.root;
288
298
  const viewBottomButtons = instance.findAllByType(ViewButtonBottom);
@@ -292,7 +302,7 @@ describe('Test ManageSubUnit', () => {
292
302
  await viewBottomButton.props.onRightClick();
293
303
  });
294
304
 
295
- expect(axios.patch).toHaveBeenCalledWith(
305
+ expect(axios.patch).not.toHaveBeenCalledWith(
296
306
  API.SUB_UNIT.MANAGE_SUB_UNIT(1, 2),
297
307
  { name: 'Station name' },
298
308
  {}
@@ -303,7 +313,7 @@ describe('Test ManageSubUnit', () => {
303
313
 
304
314
  test('onPressRemove', async () => {
305
315
  act(() => {
306
- tree = create(<ManageSubUnit route={route} />);
316
+ tree = create(wrapComponent(route));
307
317
  });
308
318
  const instance = tree.root;
309
319
  const button = instance.find(
@@ -323,7 +333,7 @@ describe('Test ManageSubUnit', () => {
323
333
 
324
334
  test('onChangeName', async () => {
325
335
  act(() => {
326
- tree = create(<ManageSubUnit route={route} />);
336
+ tree = create(wrapComponent(route));
327
337
  });
328
338
  const instance = tree.root;
329
339
  const textInput = instance.findByType(_TextInput);
@@ -335,7 +345,7 @@ describe('Test ManageSubUnit', () => {
335
345
 
336
346
  test('selectFile', async () => {
337
347
  act(() => {
338
- tree = create(<ManageSubUnit route={route} />);
348
+ tree = create(wrapComponent(route));
339
349
  });
340
350
  const instance = tree.root;
341
351
  const button = instance.find(
@@ -361,7 +371,7 @@ describe('Test ManageSubUnit', () => {
361
371
  });
362
372
 
363
373
  act(() => {
364
- tree = create(<ManageSubUnit route={route} />);
374
+ tree = create(wrapComponent(route));
365
375
  });
366
376
  const instance = tree.root;
367
377
  const imagePicker = instance.findByType(ImagePicker);
@@ -379,7 +389,7 @@ describe('Test ManageSubUnit', () => {
379
389
  expect(Toast.show).toHaveBeenCalledWith({
380
390
  type: 'success',
381
391
  position: 'bottom',
382
- text1: t('text_change_background_sub_unit_success'),
392
+ text1: getTranslate('en', 'text_change_background_sub_unit_success'),
383
393
  visibilityTime: 1000,
384
394
  });
385
395
  });
@@ -393,7 +403,7 @@ describe('Test ManageSubUnit', () => {
393
403
  });
394
404
 
395
405
  act(() => {
396
- tree = create(<ManageSubUnit route={route} />);
406
+ tree = create(wrapComponent(route));
397
407
  });
398
408
  const instance = tree.root;
399
409
  const imagePicker = instance.findByType(ImagePicker);
@@ -5,6 +5,14 @@ import { Text } from 'react-native';
5
5
  import { TESTID } from '../../../configs/Constants';
6
6
 
7
7
  import TDSGuide from '../index';
8
+ import { SCProvider } from '../../../context';
9
+ import { mockSCStore } from '../../../context/mockStore';
10
+
11
+ const wrapComponent = () => (
12
+ <SCProvider initState={mockSCStore({})}>
13
+ <TDSGuide />
14
+ </SCProvider>
15
+ );
8
16
 
9
17
  jest.mock('react-redux', () => ({
10
18
  ...jest.requireActual('react-redux'),
@@ -21,7 +29,7 @@ describe('Test TDS Guide', () => {
21
29
  test('render tds guide', () => {
22
30
  let tree;
23
31
  act(() => {
24
- tree = create(<TDSGuide />);
32
+ tree = create(wrapComponent());
25
33
  });
26
34
 
27
35
  const instance = tree.root;