@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
@@ -0,0 +1,16 @@
1
+ import { StyleSheet } from 'react-native';
2
+
3
+ export default StyleSheet.create({
4
+ wrapcontent: {
5
+ flexDirection: 'row',
6
+ justifyContent: 'space-between',
7
+ alignItems: 'center',
8
+ },
9
+ card: {
10
+ marginTop: 16,
11
+ marginBottom: 0,
12
+ },
13
+ mt4: {
14
+ marginTop: 4,
15
+ },
16
+ });
@@ -0,0 +1,30 @@
1
+ import React, { memo } from 'react';
2
+ import { View, TouchableOpacity } from 'react-native';
3
+ import { IconOutline } from '@ant-design/icons-react-native';
4
+
5
+ import { Card } from '../CardShadow';
6
+ import Text from '../Text';
7
+ import { Colors } from '../../configs';
8
+ import styles from './SelectActionStyles';
9
+
10
+ const SelectActionCard = memo(({ title, action, onPress }) => {
11
+ return (
12
+ <Card style={styles.card}>
13
+ <TouchableOpacity onPress={onPress}>
14
+ <View style={styles.wrapcontent}>
15
+ <View>
16
+ <Text type="Body" color={Colors.Gray7}>
17
+ {title}
18
+ </Text>
19
+ <Text bold type="H4" style={styles.mt4}>
20
+ {action}
21
+ </Text>
22
+ </View>
23
+ <IconOutline name="right" size={20} />
24
+ </View>
25
+ </TouchableOpacity>
26
+ </Card>
27
+ );
28
+ });
29
+
30
+ export default SelectActionCard;
@@ -2,6 +2,18 @@ import React from 'react';
2
2
  import renderer, { act } from 'react-test-renderer';
3
3
  import { TouchableOpacity } from 'react-native';
4
4
  import DevicePermissionsCheckbox from '../DevicePermissionsCheckbox';
5
+ import { SCProvider } from '../../../context';
6
+ import { mockSCStore } from '../../../context/mockStore';
7
+
8
+ const wrapComponent = (sensor, mockFunction) => (
9
+ <SCProvider initState={mockSCStore({})}>
10
+ <DevicePermissionsCheckbox
11
+ sensor={sensor}
12
+ selectedIndexes={[1]}
13
+ onSelectIndexes={mockFunction}
14
+ />
15
+ </SCProvider>
16
+ );
5
17
 
6
18
  jest.mock('axios');
7
19
  describe('Test DevicePermissionsCheckbox', () => {
@@ -13,15 +25,9 @@ describe('Test DevicePermissionsCheckbox', () => {
13
25
  actions: [13],
14
26
  };
15
27
  const mockFunction = jest.fn();
16
- test('test create DevicePermissionsCheckbox', () => {
17
- act(() => {
18
- tree = renderer.create(
19
- <DevicePermissionsCheckbox
20
- sensor={sensor}
21
- selectedIndexes={[1]}
22
- onSelectIndexes={mockFunction}
23
- />
24
- );
28
+ test('test create DevicePermissionsCheckbox', async () => {
29
+ await act(() => {
30
+ tree = renderer.create(wrapComponent(sensor, mockFunction));
25
31
  });
26
32
  const instance = tree.root;
27
33
  const dropdownButtons = instance.findAllByType(TouchableOpacity);
@@ -3,6 +3,19 @@ import renderer, { act } from 'react-test-renderer';
3
3
  import MemberList from '../MemberList';
4
4
  import RowMember from '../RowMember';
5
5
  import Text from '../../Text';
6
+ import { SCProvider } from '../../../context';
7
+ import { mockSCStore } from '../../../context/mockStore';
8
+
9
+ const wrapComponent = (dataMember, ownerId, currentUserId, mockFunc) => (
10
+ <SCProvider initState={mockSCStore({})}>
11
+ <MemberList
12
+ dataMember={dataMember}
13
+ ownerId={ownerId}
14
+ currentUserId={currentUserId}
15
+ onPressRemove={mockFunc}
16
+ />
17
+ </SCProvider>
18
+ );
6
19
 
7
20
  describe('MemberList', () => {
8
21
  let tree;
@@ -10,14 +23,7 @@ describe('MemberList', () => {
10
23
  test('MemberList snapshot id dataMember === ownerId', () => {
11
24
  const dataMember = [{ id: 1, name: 'CEO' }];
12
25
  act(() => {
13
- tree = renderer.create(
14
- <MemberList
15
- dataMember={dataMember}
16
- ownerId={1}
17
- currentUserId={2}
18
- onPressRemove={mockFunc}
19
- />
20
- );
26
+ tree = renderer.create(wrapComponent(dataMember, 1, 2, mockFunc));
21
27
  });
22
28
  const instance = tree.root;
23
29
  const textInputs = instance.findAllByType(Text);
@@ -26,13 +32,7 @@ describe('MemberList', () => {
26
32
  test('MemberList snapshot id dataMember !== ownerId', () => {
27
33
  const dataMember = [{ id: 1, name: 'CEO' }];
28
34
  act(() => {
29
- tree = renderer.create(
30
- <MemberList
31
- dataMember={dataMember}
32
- ownerId={2}
33
- onPressRemove={mockFunc}
34
- />
35
- );
35
+ tree = renderer.create(wrapComponent(dataMember, 2, null, mockFunc));
36
36
  });
37
37
  const instance = tree.root;
38
38
  const textInputs = instance.findAllByType(Text);
@@ -41,14 +41,7 @@ describe('MemberList', () => {
41
41
  test('MemberList snapshot id dataMember === currentUserId', () => {
42
42
  const dataMember = [{ id: 1, name: 'CEO' }];
43
43
  act(() => {
44
- tree = renderer.create(
45
- <MemberList
46
- dataMember={dataMember}
47
- ownerId={2}
48
- currentUserId={1}
49
- onPressRemove={mockFunc}
50
- />
51
- );
44
+ tree = renderer.create(wrapComponent(dataMember, 2, 1, mockFunc));
52
45
  });
53
46
  const instance = tree.root;
54
47
  const textInputs = instance.findAllByType(Text);
@@ -56,9 +49,8 @@ describe('MemberList', () => {
56
49
  });
57
50
  test('MemberList dataMember null', () => {
58
51
  const dataMember = [];
59
- const component = <MemberList dataMember={dataMember} />;
60
52
  act(() => {
61
- tree = renderer.create(component);
53
+ tree = renderer.create(wrapComponent(dataMember));
62
54
  });
63
55
  const instance = tree.root;
64
56
  const textInputs = instance.findAllByType(RowMember);
@@ -3,10 +3,18 @@ import renderer, { act } from 'react-test-renderer';
3
3
  import StationDevicePermissions from '../StationDevicePermissions';
4
4
  import { TouchableOpacity } from 'react-native';
5
5
  import { IconOutline } from '@ant-design/icons-react-native';
6
+ import { SCProvider } from '../../../context';
7
+ import { mockSCStore } from '../../../context/mockStore';
8
+
9
+ const wrapComponent = (dataStation) => (
10
+ <SCProvider initState={mockSCStore({})}>
11
+ <StationDevicePermissions dataStation={dataStation} />
12
+ </SCProvider>
13
+ );
6
14
 
7
15
  describe('StationDevicePermission', () => {
8
16
  let tree;
9
- test('StationDevicePermission', () => {
17
+ test('StationDevicePermission', async () => {
10
18
  const dataStation = {
11
19
  name: 'test',
12
20
  sensors: [
@@ -19,9 +27,8 @@ describe('StationDevicePermission', () => {
19
27
  },
20
28
  ],
21
29
  };
22
- const component = <StationDevicePermissions dataStation={dataStation} />;
23
- act(() => {
24
- tree = renderer.create(component);
30
+ await act(() => {
31
+ tree = renderer.create(wrapComponent(dataStation));
25
32
  });
26
33
  const instance = tree.root;
27
34
  const textInputs = instance.findAllByType(TouchableOpacity);
@@ -35,7 +42,7 @@ describe('StationDevicePermission', () => {
35
42
  iconOutline = instance.findAllByType(IconOutline);
36
43
  expect(iconOutline[0].props.name).toEqual('up');
37
44
  });
38
- test('StationDevicePermission icon: barrier', () => {
45
+ test('StationDevicePermission icon: barrier', async () => {
39
46
  const dataStation = {
40
47
  name: 'test',
41
48
  sensors: [
@@ -48,15 +55,14 @@ describe('StationDevicePermission', () => {
48
55
  },
49
56
  ],
50
57
  };
51
- const component = <StationDevicePermissions dataStation={dataStation} />;
52
- act(() => {
53
- tree = renderer.create(component);
58
+ await act(() => {
59
+ tree = renderer.create(wrapComponent(dataStation));
54
60
  });
55
61
  const instance = tree.root;
56
62
  const textInputs = instance.findAllByType(TouchableOpacity);
57
63
  expect(textInputs.length).toBe(5);
58
64
  });
59
- test('StationDevicePermission icon: sensor', () => {
65
+ test('StationDevicePermission icon: sensor', async () => {
60
66
  const dataStation = {
61
67
  name: 'test',
62
68
  sensors: [
@@ -68,9 +74,8 @@ describe('StationDevicePermission', () => {
68
74
  },
69
75
  ],
70
76
  };
71
- const component = <StationDevicePermissions dataStation={dataStation} />;
72
- act(() => {
73
- tree = renderer.create(component);
77
+ await act(() => {
78
+ tree = renderer.create(wrapComponent(dataStation));
74
79
  });
75
80
 
76
81
  const instance = tree.root;
@@ -6,15 +6,6 @@ import WrapHeaderScrollable from '../WrapHeaderScrollable';
6
6
  describe('WrapHeaderScrollable', () => {
7
7
  let tree;
8
8
 
9
- test('WrapHeaderScrollable snapshot', () => {
10
- const loadMore = jest.fn();
11
- const component = <WrapHeaderScrollable onLoadMore={loadMore} />;
12
- act(() => {
13
- tree = renderer.create(component);
14
- });
15
- expect(tree.toJSON()).toMatchSnapshot();
16
- });
17
-
18
9
  test('WrapHeaderScrollable scroll to end', () => {
19
10
  const loadMore = jest.fn();
20
11
  act(() => {
@@ -12,18 +12,26 @@ import styles from './ItemOneTapStyles.js';
12
12
  import { ToastBottomHelper } from '../../../utils/Utils';
13
13
  import { axiosPost } from '../../../utils/Apis/axios';
14
14
  import { useTranslations } from '../../../hooks/Common/useTranslations';
15
- import { useNavigation } from '@react-navigation/core';
15
+ import { useNavigation } from '@react-navigation/native';
16
16
  import Routes from '../../../utils/Route';
17
+ import { useGetIdUser } from '../../../hooks/Common';
18
+ import { TESTID } from '../../../configs/Constants';
17
19
 
18
- const ItemOneTap = memo(({ automate }) => {
20
+ const ItemOneTap = memo(({ isOwner, automate, unit }) => {
19
21
  const { navigate } = useNavigation();
20
- const { id, script, activate_at } = automate;
21
-
22
+ const { id, type, user, script, activate_at } = automate;
22
23
  const t = useTranslations();
24
+ const idUser = useGetIdUser();
25
+
23
26
  const goToDetail = useCallback(() => {
24
- navigate(Routes.ScriptDetail, { id, name: script?.name });
25
- // eslint-disable-next-line react-hooks/exhaustive-deps
26
- }, []);
27
+ navigate(Routes.ScriptDetail, {
28
+ id,
29
+ name: script?.name,
30
+ type: type,
31
+ havePermission: isOwner || user === idUser,
32
+ unit,
33
+ });
34
+ }, [isOwner, user, idUser, navigate, id, script, type, unit]);
27
35
 
28
36
  const handleScriptAction = useCallback(async () => {
29
37
  const { success } = await axiosPost(API.AUTOMATE.ACTION_ONE_TAP(id));
@@ -51,11 +59,14 @@ const ItemOneTap = memo(({ automate }) => {
51
59
  <View style={styles.container}>
52
60
  <View style={styles.boxIcon}>
53
61
  {displayIcon()}
54
- <TouchableOpacity onPress={handleScriptAction}>
62
+ <TouchableOpacity
63
+ testID={TESTID.AUTOMATE_SCRIPT_ACTION}
64
+ onPress={handleScriptAction}
65
+ >
55
66
  <CheckCircle />
56
67
  </TouchableOpacity>
57
68
  </View>
58
- <TouchableOpacity onPress={goToDetail}>
69
+ <TouchableOpacity testID={TESTID.GO_DETAIL} onPress={goToDetail}>
59
70
  <Text
60
71
  numberOfLines={1}
61
72
  semibold
@@ -0,0 +1,149 @@
1
+ import axios from 'axios';
2
+ import React from 'react';
3
+ import { TouchableOpacity } from 'react-native';
4
+ import Toast from 'react-native-toast-message';
5
+ import { act, create } from 'react-test-renderer';
6
+ import SubUnitAutomate from '..';
7
+ import { TESTID } from '../../../../configs/Constants';
8
+ import { SCProvider } from '../../../../context';
9
+ import { mockSCStore } from '../../../../context/mockStore';
10
+ import Routes from '../../../../utils/Route';
11
+
12
+ const wrapComponent = (data) => (
13
+ <SCProvider initState={mockSCStore({})}>
14
+ <SubUnitAutomate {...data} />
15
+ </SCProvider>
16
+ );
17
+
18
+ jest.mock('react-redux', () => {
19
+ return {
20
+ ...jest.requireActual('react-redux'),
21
+ useSelector: () => 'vi',
22
+ };
23
+ });
24
+
25
+ const mockedNavigate = jest.fn();
26
+ jest.mock('@react-navigation/native', () => {
27
+ return {
28
+ ...jest.requireActual('@react-navigation/native'),
29
+ useNavigation: () => ({
30
+ navigate: mockedNavigate,
31
+ }),
32
+ };
33
+ });
34
+
35
+ jest.mock('axios');
36
+
37
+ let tree;
38
+ let data = {
39
+ isOwner: true,
40
+ type: 'one_tap',
41
+ automates: [
42
+ {
43
+ id: 1,
44
+ user: 6,
45
+ type: 'one_tap',
46
+ activate_at: '2021-09-17T05:30:00Z',
47
+ script: {
48
+ name: 'Joshua Ray',
49
+ icon: '',
50
+ icon_kit: '',
51
+ },
52
+ },
53
+ ],
54
+ };
55
+
56
+ describe('test Item', () => {
57
+ beforeEach(() => {
58
+ axios.post.mockClear();
59
+ mockedNavigate.mockClear();
60
+ });
61
+ test('render SubUnitAutomate isOwner', async () => {
62
+ const response = {
63
+ status: 200,
64
+ };
65
+
66
+ axios.post.mockImplementation(async () => {
67
+ return response;
68
+ });
69
+
70
+ await act(async () => {
71
+ tree = await create(wrapComponent(data));
72
+ });
73
+
74
+ const instance = tree.root;
75
+ const item = instance.findAll(
76
+ (el) => el.props.testID === TESTID.PLUS && el.type === TouchableOpacity
77
+ );
78
+
79
+ expect(item).toHaveLength(1);
80
+ await act(async () => {
81
+ await item[0].props.onPress();
82
+ });
83
+ expect(mockedNavigate).toHaveBeenCalledWith(Routes.AddNewOneTap, {
84
+ type: 'one_tap',
85
+ });
86
+ mockedNavigate.mockClear();
87
+
88
+ const goDetail = instance.findAll(
89
+ (el) =>
90
+ el.props.testID === TESTID.GO_DETAIL && el.type === TouchableOpacity
91
+ );
92
+ expect(goDetail).toHaveLength(1);
93
+ await act(async () => {
94
+ await goDetail[0].props.onPress();
95
+ });
96
+ expect(mockedNavigate).toHaveBeenCalledWith(Routes.ScriptDetail, {
97
+ havePermission: true,
98
+ id: 1,
99
+ name: 'Joshua Ray',
100
+ type: 'one_tap',
101
+ });
102
+
103
+ const handleScriptAction = instance.findAll(
104
+ (el) =>
105
+ el.props.testID === TESTID.AUTOMATE_SCRIPT_ACTION &&
106
+ el.type === TouchableOpacity
107
+ );
108
+ expect(handleScriptAction).toHaveLength(1);
109
+ await act(async () => {
110
+ await handleScriptAction[0].props.onPress();
111
+ });
112
+ expect(Toast.show).toBeCalledWith({
113
+ type: 'success',
114
+ position: 'bottom',
115
+ text1: 'Activated successfully.',
116
+ visibilityTime: 1000,
117
+ });
118
+ });
119
+
120
+ test('render SubUnitAutomate handleScriptAction fail', async () => {
121
+ const response = {
122
+ status: 400,
123
+ };
124
+
125
+ axios.post.mockImplementation(async () => {
126
+ return response;
127
+ });
128
+
129
+ await act(async () => {
130
+ tree = await create(wrapComponent(data));
131
+ });
132
+
133
+ const handleScriptAction = tree.root.findAll(
134
+ (el) =>
135
+ el.props.testID === TESTID.AUTOMATE_SCRIPT_ACTION &&
136
+ el.type === TouchableOpacity
137
+ );
138
+ expect(handleScriptAction).toHaveLength(1);
139
+ await act(async () => {
140
+ await handleScriptAction[0].props.onPress();
141
+ });
142
+ expect(Toast.show).toBeCalledWith({
143
+ type: 'error',
144
+ position: 'bottom',
145
+ text1: 'Activation failed.',
146
+ visibilityTime: 1000,
147
+ });
148
+ });
149
+ });
@@ -8,22 +8,32 @@ import ItemOneTap from './ItemOneTap';
8
8
  import { useTranslations } from '../../../hooks/Common/useTranslations';
9
9
  import { useNavigation } from '@react-navigation/native';
10
10
  import Routes from '../../../utils/Route/index.js';
11
+ import { AUTOMATE_TYPE } from '../../../configs/Constants';
11
12
 
12
- const SubUnitOneTap = ({ automates }) => {
13
+ const SubUnitAutomate = ({ isOwner, type, automates, unit }) => {
13
14
  const t = useTranslations();
14
- const navigation = useNavigation();
15
+ const { navigate } = useNavigation();
15
16
  const handleOnAddNew = () => {
16
- navigation.navigate(Routes.AddNewOneTap);
17
+ switch (type) {
18
+ case AUTOMATE_TYPE.ONE_TAP:
19
+ navigate(Routes.AddNewOneTap, { type: type, unit });
20
+ break;
21
+ case AUTOMATE_TYPE.VALUE_CHANGE:
22
+ navigate(Routes.AddNewAutoSmart, { type: type });
23
+ break;
24
+ }
17
25
  };
18
26
  return (
19
27
  <Section style={styles.noShadow}>
20
28
  <View style={styles.boxDevices}>
21
- <ItemAddNew title={t('add_new')} onAddNew={handleOnAddNew} />
22
29
  {!!automates.length &&
23
- automates.map((item) => <ItemOneTap automate={item} />)}
30
+ automates.map((item) => (
31
+ <ItemOneTap isOwner={isOwner} automate={item} unit={unit} />
32
+ ))}
33
+ <ItemAddNew title={t('add_new')} onAddNew={handleOnAddNew} />
24
34
  </View>
25
35
  </Section>
26
36
  );
27
37
  };
28
38
 
29
- export default SubUnitOneTap;
39
+ export default SubUnitAutomate;
@@ -4,7 +4,7 @@ import { useNavigation } from '@react-navigation/native';
4
4
  import { useTranslations } from '../../hooks/Common/useTranslations';
5
5
 
6
6
  import { Images, Device } from '../../configs';
7
- import { TESTID } from '../../configs/Constants';
7
+ import { SubUnitName, TESTID } from '../../configs/Constants';
8
8
  import { Section } from '../Section';
9
9
  import Text from '../Text';
10
10
  import ItemDevice from '../Device/ItemDevice';
@@ -75,9 +75,13 @@ const ShortDetailSubUnit = ({ unit, station, isGGHomeConnected }) => {
75
75
  }
76
76
  };
77
77
 
78
- const itemAddNewTitle = station.isFavorites
79
- ? t('add_to_favorites')
80
- : t('add_new_device');
78
+ const itemAddNewTitle = t(
79
+ station?.isFavorites
80
+ ? 'add_to_favorites'
81
+ : station?.name === SubUnitName.scenario
82
+ ? 'add_script'
83
+ : 'add_new_device'
84
+ );
81
85
 
82
86
  return (
83
87
  <Section style={styles.noShadow}>
@@ -90,7 +94,6 @@ const ShortDetailSubUnit = ({ unit, station, isGGHomeConnected }) => {
90
94
  )}
91
95
 
92
96
  <View style={styles.boxDevices}>
93
- <ItemAddNew title={itemAddNewTitle} onAddNew={handleOnAddNew} />
94
97
  {!!station.sensors &&
95
98
  station.sensors.map((sensor, index) => (
96
99
  <ItemDevice
@@ -108,6 +111,7 @@ const ShortDetailSubUnit = ({ unit, station, isGGHomeConnected }) => {
108
111
  isGGHomeConnected={isGGHomeConnected}
109
112
  />
110
113
  ))}
114
+ <ItemAddNew title={itemAddNewTitle} onAddNew={handleOnAddNew} />
111
115
  </View>
112
116
  </Section>
113
117
  );
@@ -2,8 +2,16 @@ import React from 'react';
2
2
  import { Image, View, TouchableWithoutFeedback } from 'react-native';
3
3
  import { act, create } from 'react-test-renderer';
4
4
  import { TESTID } from '../../../configs/Constants';
5
+ import { SCProvider } from '../../../context';
6
+ import { mockSCStore } from '../../../context/mockStore';
5
7
  import Routes from '../../../utils/Route';
6
8
 
9
+ const wrapComponent = (unit, station) => (
10
+ <SCProvider initState={mockSCStore({})}>
11
+ <ShortDetailSubUnit unit={unit} station={station} />
12
+ </SCProvider>
13
+ );
14
+
7
15
  import ShortDetailSubUnit from '../ShortDetail';
8
16
 
9
17
  const mockedNavigate = jest.fn();
@@ -54,20 +62,20 @@ describe('test ShortDetail Subunit', () => {
54
62
 
55
63
  test('render ShortDetail', () => {
56
64
  act(() => {
57
- tree = create(<ShortDetailSubUnit unit={unit} station={station} />);
65
+ tree = create(wrapComponent(unit, station));
58
66
  });
59
67
  const instance = tree.root;
60
68
  const image = instance.findAllByType(Image);
61
69
  const imageBackground = image.find(
62
70
  (item) => item.props.testID === TESTID.SUB_UNIT_BACKGROUND
63
71
  );
64
- expect(imageBackground).toBeDefined();
72
+ expect(imageBackground).not.toBeDefined();
65
73
  });
66
74
 
67
75
  test('render ShortDetail without background', () => {
68
76
  station.background = '';
69
77
  act(() => {
70
- tree = create(<ShortDetailSubUnit unit={unit} station={station} />);
78
+ tree = create(wrapComponent(unit, station));
71
79
  });
72
80
  const instance = tree.root;
73
81
  const image = instance.findAllByType(Image);
@@ -86,7 +94,7 @@ describe('test ShortDetail Subunit', () => {
86
94
  };
87
95
 
88
96
  act(() => {
89
- tree = create(<ShortDetailSubUnit unit={unit} station={station} />);
97
+ tree = create(wrapComponent(unit, station));
90
98
  });
91
99
  const instance = tree.root;
92
100
  const view = instance.findAllByType(View);
@@ -120,7 +128,7 @@ describe('test ShortDetail Subunit', () => {
120
128
  ];
121
129
 
122
130
  act(() => {
123
- tree = create(<ShortDetailSubUnit unit={unit} station={station} />);
131
+ tree = create(wrapComponent(unit, station));
124
132
  });
125
133
  const instance = tree.root;
126
134
  const itemDevice = instance.findAll(
@@ -132,7 +140,7 @@ describe('test ShortDetail Subunit', () => {
132
140
 
133
141
  test('render ShortDetail add new device', () => {
134
142
  act(() => {
135
- tree = create(<ShortDetailSubUnit unit={unit} station={station} />);
143
+ tree = create(wrapComponent(unit, station));
136
144
  });
137
145
  const instance = tree.root;
138
146
  const buttonAddNew = instance.findAllByType(TouchableWithoutFeedback);
@@ -1,13 +1,21 @@
1
1
  import React from 'react';
2
2
  import renderer, { act } from 'react-test-renderer';
3
+ import { SCProvider } from '../../../context';
4
+ import { mockSCStore } from '../../../context/mockStore';
3
5
  import Today from '../index';
4
6
 
7
+ const wrapComponent = () => (
8
+ <SCProvider initState={mockSCStore({})}>
9
+ <Today />
10
+ </SCProvider>
11
+ );
12
+
5
13
  describe('Test Today', () => {
6
14
  let tree;
7
15
  test('create Today', () => {
8
16
  Date.now = jest.fn(() => new Date('2021-01-24T12:00:00.000Z'));
9
17
  act(() => {
10
- tree = renderer.create(<Today />);
18
+ tree = renderer.create(wrapComponent());
11
19
  });
12
20
  expect(tree.toJSON()).toMatchSnapshot();
13
21
  });
@@ -20,7 +20,7 @@ exports[`Test Today create Today 1`] = `
20
20
  ]
21
21
  }
22
22
  >
23
- Hôm nay, 24 tháng 1
23
+ Today, Jan 24
24
24
  </Text>
25
25
  </View>
26
26
  `;