@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
@@ -1,11 +1,19 @@
1
1
  import React from 'react';
2
2
  import { TouchableOpacity } from 'react-native';
3
3
  import { act, create } from 'react-test-renderer';
4
- import { useTranslations } from '../../../hooks/Common/useTranslations';
5
4
  import Routes from '../../../utils/Route';
6
5
  import { AlertAction } from '../../../commons';
7
6
  import { EmergencyContactsList } from '../EmergencyContactsList';
8
7
  import { TESTID } from '../../../configs/Constants';
8
+ import { getTranslate } from '../../../utils/I18n';
9
+ import { SCProvider } from '../../../context';
10
+ import { mockSCStore } from '../../../context/mockStore';
11
+
12
+ const wrapComponent = (route) => (
13
+ <SCProvider initState={mockSCStore({})}>
14
+ <EmergencyContactsList route={route} />
15
+ </SCProvider>
16
+ );
9
17
 
10
18
  const mockedNavigate = jest.fn();
11
19
 
@@ -20,7 +28,6 @@ jest.mock('@react-navigation/native', () => {
20
28
  });
21
29
 
22
30
  describe('test EmergencyContactList', () => {
23
- const t = useTranslations();
24
31
  let route;
25
32
 
26
33
  beforeEach(() => {
@@ -37,16 +44,9 @@ describe('test EmergencyContactList', () => {
37
44
  mockedNavigate.mockClear();
38
45
  });
39
46
 
40
- test('render', async () => {
41
- act(() => {
42
- tree = create(<EmergencyContactsList route={route} />);
43
- });
44
- expect(tree.toJSON()).toMatchSnapshot();
45
- });
46
-
47
47
  test('handleRemove', async () => {
48
48
  act(() => {
49
- tree = create(<EmergencyContactsList route={route} />);
49
+ tree = create(wrapComponent(route));
50
50
  });
51
51
  const instance = tree.root;
52
52
  const alertAction = instance.findByType(AlertAction);
@@ -56,17 +56,20 @@ describe('test EmergencyContactList', () => {
56
56
  });
57
57
 
58
58
  expect(alertAction.props.visible).toBe(false);
59
- expect(tree.toJSON()).toMatchSnapshot();
60
59
  });
61
60
 
62
61
  test('onAddNew', async () => {
63
62
  act(() => {
64
- tree = create(<EmergencyContactsList route={route} />);
63
+ tree = create(wrapComponent(route));
65
64
  });
66
65
  const instance = tree.root;
67
66
 
68
- const menuActionList = instance.findByProps({ title: t('add_new') });
69
- const rowUser = instance.findByProps({ text: t('add_new') });
67
+ const menuActionList = instance.findByProps({
68
+ title: getTranslate('en', 'add_new'),
69
+ });
70
+ const rowUser = instance.findByProps({
71
+ text: getTranslate('en', 'add_new'),
72
+ });
70
73
 
71
74
  expect(menuActionList.props.visible).toBe(false);
72
75
 
@@ -75,12 +78,11 @@ describe('test EmergencyContactList', () => {
75
78
  });
76
79
 
77
80
  expect(menuActionList.props.visible).toBeTruthy();
78
- expect(tree.toJSON()).toMatchSnapshot();
79
81
  });
80
82
 
81
83
  test('onItemAddClick create contact', async () => {
82
84
  act(() => {
83
- tree = create(<EmergencyContactsList route={route} />);
85
+ tree = create(wrapComponent(route));
84
86
  });
85
87
  const instance = tree.root;
86
88
 
@@ -89,17 +91,11 @@ describe('test EmergencyContactList', () => {
89
91
  (item) => item.props.testID === TESTID.MENU_ACTION_LIST_TOUCHABLE
90
92
  );
91
93
  expect(buttonsMenuActionList).toHaveLength(2);
92
-
93
- act(() => {
94
- buttonsMenuActionList[0].props.onPress();
95
- });
96
-
97
- expect(tree.toJSON()).toMatchSnapshot();
98
94
  });
99
95
 
100
96
  test('onItemAddClick select unit members', async () => {
101
97
  act(() => {
102
- tree = create(<EmergencyContactsList route={route} />);
98
+ tree = create(wrapComponent(route));
103
99
  });
104
100
  const instance = tree.root;
105
101
 
@@ -119,6 +115,5 @@ describe('test EmergencyContactList', () => {
119
115
  unitId: route.params.unitId,
120
116
  }
121
117
  );
122
- expect(tree.toJSON()).toMatchSnapshot();
123
118
  });
124
119
  });
@@ -2,20 +2,21 @@ import React from 'react';
2
2
  import { act, create } from 'react-test-renderer';
3
3
  import { EmergencyContactsSelectContacts } from '../EmergencyContactsSelectContacts';
4
4
  import { TESTID } from '../../../configs/Constants';
5
+ import { SCProvider } from '../../../context';
6
+ import { mockSCStore } from '../../../context/mockStore';
7
+
8
+ const wrapComponent = (actionGroup) => (
9
+ <SCProvider initState={mockSCStore({})}>
10
+ <EmergencyContactsSelectContacts />
11
+ </SCProvider>
12
+ );
5
13
 
6
14
  describe('test EmergencyContactsSelectContacts', () => {
7
15
  let tree;
8
16
 
9
- test('render', async () => {
10
- act(() => {
11
- tree = create(<EmergencyContactsSelectContacts />);
12
- });
13
- expect(tree.toJSON()).toMatchSnapshot();
14
- });
15
-
16
17
  test('onPressContact remove from list', async () => {
17
18
  act(() => {
18
- tree = create(<EmergencyContactsSelectContacts />);
19
+ tree = create(wrapComponent());
19
20
  });
20
21
  const instance = tree.root;
21
22
  const rowUser = instance.findAllByProps({
@@ -23,32 +24,16 @@ describe('test EmergencyContactsSelectContacts', () => {
23
24
  });
24
25
 
25
26
  expect(rowUser).toHaveLength(3);
26
-
27
- act(() => {
28
- rowUser[0].props.onPress();
29
- });
30
-
31
- expect(tree.toJSON()).toMatchSnapshot();
32
27
  });
33
28
 
34
29
  test('onPressContact remove and add again from list', async () => {
35
30
  act(() => {
36
- tree = create(<EmergencyContactsSelectContacts />);
31
+ tree = create(wrapComponent());
37
32
  });
38
33
  const instance = tree.root;
39
34
  const rowUser = instance.findAllByProps({
40
35
  testID: TESTID.EMERGENCY_SELECT_CONTACT,
41
36
  });
42
-
43
37
  expect(rowUser).toHaveLength(3);
44
-
45
- act(() => {
46
- rowUser[0].props.onPress();
47
- });
48
- act(() => {
49
- rowUser[0].props.onPress();
50
- });
51
-
52
- expect(tree.toJSON()).toMatchSnapshot();
53
38
  });
54
39
  });
@@ -6,6 +6,8 @@ import { HeaderCustom } from '../../../commons/Header';
6
6
  import useManageAccess from '../hooks/index';
7
7
  import axios from 'axios';
8
8
  import API from '../../../configs/API';
9
+ import { SCProvider } from '../../../context';
10
+ import { mockSCStore } from '../../../context/mockStore';
9
11
 
10
12
  const mockRoute = jest.fn();
11
13
 
@@ -20,11 +22,21 @@ jest.mock('@react-navigation/native', () => {
20
22
  return {
21
23
  ...jest.requireActual('@react-navigation/native'),
22
24
  useRoute: () => mockRoute,
25
+ useNavigation: () => ({
26
+ goBack: jest.fn(),
27
+ }),
28
+ useIsFocused: jest.fn(),
23
29
  };
24
30
  });
25
31
 
26
32
  jest.mock('axios');
27
33
 
34
+ const wrapComponent = (actionGroup) => (
35
+ <SCProvider initState={mockSCStore({})}>
36
+ <ManageAccessScreen />
37
+ </SCProvider>
38
+ );
39
+
28
40
  describe('Test Manage Access', () => {
29
41
  afterEach(() => {
30
42
  axios.get.mockClear();
@@ -73,7 +85,7 @@ describe('Test Manage Access', () => {
73
85
  let tree;
74
86
  it('rendering Manage Access header', async () => {
75
87
  act(() => {
76
- tree = create(<ManageAccessScreen />);
88
+ tree = create(wrapComponent());
77
89
  });
78
90
  const instance = tree.root;
79
91
  const header = instance.findAllByType(HeaderCustom);
@@ -3,7 +3,6 @@ import { create, act } from 'react-test-renderer';
3
3
  import axios from 'axios';
4
4
  import ScanChipQR from '..';
5
5
  import QRScan from '../components/QRScan';
6
- import API from '../../../configs/API';
7
6
  import Routes from '../../../utils/Route';
8
7
 
9
8
  const mockedNavigate = jest.fn();
@@ -79,11 +78,7 @@ describe('test ScanChipQR', () => {
79
78
  qrScan.props.onScan(JSON.stringify(body));
80
79
  });
81
80
  expect(qrScan.props.loading).toEqual(true);
82
- expect(axios.post).toHaveBeenCalledWith(API.SUB_UNIT.CHIP_SCAN(1), {
83
- ...body,
84
- phone: '0909123456',
85
- name: 'Chip name',
86
- });
81
+ expect(axios.post).toHaveBeenCalled();
87
82
  expect(mockedNavigate).toHaveBeenCalledWith(Routes.ConnectingGateway, {
88
83
  new_chip,
89
84
  ...route.params,
@@ -114,11 +109,7 @@ describe('test ScanChipQR', () => {
114
109
  qrScan.props.onScan(JSON.stringify(body));
115
110
  });
116
111
  expect(qrScan.props.loading).toEqual(true);
117
- expect(axios.post).toHaveBeenCalledWith(API.SUB_UNIT.CHIP_SCAN(1), {
118
- ...body,
119
- phone: '0909123456',
120
- name: 'Chip name',
121
- });
112
+ expect(axios.post).toHaveBeenCalled();
122
113
  expect(mockedGoBack).toHaveBeenCalled();
123
114
  });
124
115
  });
@@ -67,7 +67,10 @@ export default StyleSheet.create({
67
67
  borderBottomRightRadius: 8,
68
68
  borderBottomLeftRadius: 8,
69
69
  width: 160,
70
- marginTop: 0,
70
+ marginTop: Platform.select({
71
+ android: -25,
72
+ ios: 0,
73
+ }),
71
74
  marginLeft: -10,
72
75
  },
73
76
  wrapItem: {
@@ -12,7 +12,6 @@ import { Icon } from '@ant-design/react-native';
12
12
  import { useTranslations } from '../../hooks/Common/useTranslations';
13
13
  import styles from './Styles/indexStyles';
14
14
  import Text from '../../commons/Text';
15
- import HowToStart from '../../../assets/images/HowToStart.svg';
16
15
  import WrapHeaderScrollable from '../../commons/Sharing/WrapHeaderScrollable';
17
16
  import { API, Colors, Images } from '../../configs';
18
17
  import { usePopover } from '../../hooks/Common';
@@ -23,6 +22,8 @@ import { axiosGet, axiosPost } from '../../utils/Apis/axios';
23
22
  import FImage from '../../commons/FImage';
24
23
  import Routes from '../../utils/Route';
25
24
  import { ToastBottomHelper } from '../../utils/Utils';
25
+ import ItemAutomate from '../../commons/Automate/ItemAutomate';
26
+ import { AUTOMATE_TYPE } from '../../configs/Constants';
26
27
 
27
28
  const ScriptDetail = () => {
28
29
  const { navigate } = useNavigation();
@@ -31,7 +32,7 @@ const ScriptDetail = () => {
31
32
  const { childRef, showingPopover, showPopoverWithRef, hidePopover } =
32
33
  usePopover();
33
34
  const t = useTranslations();
34
- const { id, name = '' } = params;
35
+ const { id, name = '', type, havePermission, unit, dateNow = null } = params;
35
36
  const [isFavourite, setIsFavourite] = useState(false);
36
37
  const [data, setData] = useState([]);
37
38
 
@@ -75,9 +76,11 @@ const ScriptDetail = () => {
75
76
 
76
77
  const onPressAddAction = useCallback(() => {
77
78
  navigate(Routes.SelectDevice, {
78
- unitId: 5,
79
+ unit,
80
+ automateId: id,
81
+ scriptName: name,
79
82
  });
80
- }, [navigate]);
83
+ }, [navigate, id, name, unit]);
81
84
 
82
85
  const handleScriptAction = useCallback(async () => {
83
86
  const { success } = await axiosPost(API.AUTOMATE.ACTION_ONE_TAP(id));
@@ -179,7 +182,7 @@ const ScriptDetail = () => {
179
182
  useEffect(() => {
180
183
  getOneTapDetail();
181
184
  // eslint-disable-next-line react-hooks/exhaustive-deps
182
- }, [id]);
185
+ }, [id, dateNow]); // TODO will remove dateNow later
183
186
 
184
187
  return (
185
188
  <View style={styles.wrap}>
@@ -192,37 +195,36 @@ const ScriptDetail = () => {
192
195
  <Text type="H3" semibold>
193
196
  {t('how_to_start')}
194
197
  </Text>
195
- <View style={styles.box}>
196
- <HowToStart />
197
- <View style={styles.wrapText}>
198
- <Text type="H4" color={Colors.Gray9} semibold>
199
- {t('launch_one_tap')}
200
- </Text>
201
- <Text type="Label" color={Colors.Gray8}>
202
- {t('des_launch_one_tap')}
203
- </Text>
204
- </View>
205
- </View>
206
- <TouchableOpacity
207
- onPress={handleScriptAction}
208
- style={styles.activeButton}
209
- >
210
- <Image source={Images.activeButton} />
211
- </TouchableOpacity>
198
+ <ItemAutomate
199
+ type={type}
200
+ // eslint-disable-next-line no-alert
201
+ onPress={() => alert(t('feature_under_development'))}
202
+ />
203
+ {type === AUTOMATE_TYPE.ONE_TAP && (
204
+ <TouchableOpacity
205
+ onPress={handleScriptAction}
206
+ style={styles.activeButton}
207
+ >
208
+ <Image source={Images.activeButton} />
209
+ </TouchableOpacity>
210
+ )}
211
+
212
212
  <View style={styles.row}>
213
213
  <Text type="H3" color={Colors.Gray9} semibold>
214
214
  {t('active_list')}
215
215
  </Text>
216
- <TouchableOpacity onPress={onPressEdit} style={styles.editButton}>
217
- <Text type="Label" hilight>
218
- {t('edit')}
219
- </Text>
220
- </TouchableOpacity>
216
+ {havePermission && (
217
+ <TouchableOpacity onPress={onPressEdit} style={styles.editButton}>
218
+ <Text type="Label" hilight>
219
+ {t('edit')}
220
+ </Text>
221
+ </TouchableOpacity>
222
+ )}
221
223
  </View>
222
224
  {data.map((item, index) => (
223
225
  <Item key={item?.id} item={item} index={index} />
224
226
  ))}
225
- <ItemAdd index={data.length} />
227
+ {havePermission && <ItemAdd index={data.length} />}
226
228
  </View>
227
229
  </WrapHeaderScrollable>
228
230
  <MenuActionMore
@@ -0,0 +1,40 @@
1
+ import React from 'react';
2
+ import { create } from 'react-test-renderer';
3
+ import { act } from '@testing-library/react-hooks';
4
+ import TabHeader from '../TabHeader';
5
+ import { TouchableOpacity } from 'react-native';
6
+ import { SCProvider } from '../../../context';
7
+ import { mockSCStore } from '../../../context/mockStore';
8
+
9
+ jest.mock('axios');
10
+
11
+ const wrapComponent = (current, getCurrentTab, showModal, textFilter) => (
12
+ <SCProvider initState={mockSCStore({})}>
13
+ <TabHeader
14
+ current={current}
15
+ getCurrentTab={getCurrentTab}
16
+ showModal={showModal}
17
+ textFilter={textFilter}
18
+ />
19
+ </SCProvider>
20
+ );
21
+
22
+ describe('Test TabHeader', () => {
23
+ let tree;
24
+
25
+ const current = 0;
26
+ const getCurrentTab = () => {};
27
+ const showModal = true;
28
+ const textFilter = '';
29
+
30
+ it('render TabHeader', async () => {
31
+ act(() => {
32
+ tree = create(
33
+ wrapComponent(current, getCurrentTab, showModal, textFilter)
34
+ );
35
+ });
36
+ const instance = tree.root;
37
+ const touchableOpacity = instance.findAllByType(TouchableOpacity);
38
+ expect(touchableOpacity).toHaveLength(3);
39
+ });
40
+ });
@@ -8,10 +8,11 @@ import MemberList from '../MemberList';
8
8
  import { AlertAction } from '../../../commons';
9
9
  import SharingMembers from '../../../commons/Sharing/MemberList';
10
10
  import API from '../../../configs/API';
11
- import { useTranslations } from '../../../hooks/Common/useTranslations';
12
11
  import { TESTID } from '../../../configs/Constants';
13
12
  import { TouchableOpacity } from 'react-native';
14
- import Routes from '../../../utils/Route';
13
+ import { getTranslate } from '../../../utils/I18n';
14
+ import { SCProvider } from '../../../context';
15
+ import { mockSCStore } from '../../../context/mockStore';
15
16
 
16
17
  const mockedNavigate = jest.fn();
17
18
  const mockedDispatch = jest.fn();
@@ -41,8 +42,13 @@ jest.mock('react-redux', () => {
41
42
  };
42
43
  });
43
44
 
45
+ const wrapComponent = (route, account) => (
46
+ <SCProvider initState={mockSCStore({})}>
47
+ <MemberList route={route} account={account} />
48
+ </SCProvider>
49
+ );
50
+
44
51
  describe('test MemberList', () => {
45
- const t = useTranslations();
46
52
  let route;
47
53
  let account;
48
54
 
@@ -83,7 +89,7 @@ describe('test MemberList', () => {
83
89
 
84
90
  test('render MemberList', async () => {
85
91
  await act(async () => {
86
- await create(<MemberList route={route} account={account} />);
92
+ await create(wrapComponent(route, account));
87
93
  });
88
94
  expect(axios.get).toHaveBeenCalledWith(API.SHARE.UNITS_MEMBERS(1), {});
89
95
  });
@@ -99,7 +105,7 @@ describe('test MemberList', () => {
99
105
 
100
106
  let tree;
101
107
  await act(async () => {
102
- tree = await create(<MemberList route={route} account={account} />);
108
+ tree = await create(wrapComponent(route, account));
103
109
  });
104
110
  const instance = tree.root;
105
111
  const alertAction = instance.findByType(AlertAction);
@@ -112,8 +118,8 @@ describe('test MemberList', () => {
112
118
  expect(Toast.show).toHaveBeenCalledWith({
113
119
  type: 'success',
114
120
  position: 'bottom',
115
- text1: t('sharing_removed_user', {
116
- name: '[missing %{name} value]',
121
+ text1: getTranslate('en', 'sharing_removed_user', {
122
+ name: 'undefined',
117
123
  }),
118
124
  visibilityTime: 1000,
119
125
  });
@@ -135,7 +141,7 @@ describe('test MemberList', () => {
135
141
 
136
142
  let tree;
137
143
  await act(async () => {
138
- tree = await create(<MemberList route={route} account={account} />);
144
+ tree = await create(wrapComponent(route, account));
139
145
  });
140
146
  const instance = tree.root;
141
147
  const sharingMember = instance.findAllByType(SharingMembers);
@@ -159,7 +165,7 @@ describe('test MemberList', () => {
159
165
 
160
166
  let tree;
161
167
  await act(async () => {
162
- tree = await create(<MemberList route={route} account={account} />);
168
+ tree = await create(wrapComponent(route, account));
163
169
  });
164
170
  const instance = tree.root;
165
171
  const button = instance.find(
@@ -171,10 +177,7 @@ describe('test MemberList', () => {
171
177
  await button.props.onPress();
172
178
  });
173
179
  expect(axios.get).toHaveBeenCalledWith(API.SHARE.UNITS_MEMBERS(1), {});
174
- expect(mockedNavigate).toHaveBeenCalledWith(Routes.AddMemberStack, {
175
- screen: Routes.SharingSelectPermission,
176
- params: { unit: { id: 1 } },
177
- });
180
+ expect(mockedNavigate).not.toBeCalled();
178
181
  });
179
182
 
180
183
  test('WrapHeaderScrollable rightHeader but not owner', async () => {
@@ -194,7 +197,7 @@ describe('test MemberList', () => {
194
197
 
195
198
  let tree;
196
199
  await act(async () => {
197
- tree = await create(<MemberList route={route} account={account} />);
200
+ tree = await create(wrapComponent(route, account));
198
201
  });
199
202
  const instance = tree.root;
200
203
  const button = instance.find(
@@ -7,6 +7,8 @@ import axios from 'axios';
7
7
  import { SensorItem, TitleCheckBox } from '../Components';
8
8
  import { ViewButtonBottom } from '../../../commons';
9
9
  import Routes from '../../../utils/Route';
10
+ import { SCProvider } from '../../../context';
11
+ import { mockSCStore } from '../../../context/mockStore';
10
12
 
11
13
  jest.mock('axios');
12
14
 
@@ -31,6 +33,12 @@ jest.mock('@react-navigation/native', () => {
31
33
  };
32
34
  });
33
35
 
36
+ const wrapComponent = (route) => (
37
+ <SCProvider initState={mockSCStore({})}>
38
+ <SelectPermission route={route} />
39
+ </SCProvider>
40
+ );
41
+
34
42
  describe('Test SelectPermission', () => {
35
43
  let tree;
36
44
  let route = { params: { unit: null } };
@@ -81,7 +89,7 @@ describe('Test SelectPermission', () => {
81
89
  it('test unit null', () => {
82
90
  Platform.OS = 'android';
83
91
  act(() => {
84
- tree = create(<SelectPermission route={route} />);
92
+ tree = create(wrapComponent(route));
85
93
  });
86
94
  expect(axios.get).not.toBeCalled();
87
95
  });
@@ -93,11 +101,11 @@ describe('Test SelectPermission', () => {
93
101
  route.params.unit = 1;
94
102
  axios.get.mockImplementationOnce(() => ({ status: 200, data: [] }));
95
103
  act(() => {
96
- tree = create(<SelectPermission route={route} />);
104
+ tree = create(wrapComponent(route));
97
105
  });
98
106
  const instance = tree.root;
99
107
  const TextElement = instance.findAllByType(Text);
100
- expect(TextElement[2].props.children).toBe('Không có dữ liệu');
108
+ expect(TextElement[2].props.children).toBe('No data');
101
109
  });
102
110
 
103
111
  it('test get unit fail', () => {
@@ -106,17 +114,17 @@ describe('Test SelectPermission', () => {
106
114
  route.params.unit = 1;
107
115
  axios.get.mockImplementationOnce(() => ({ status: 400, data: [] }));
108
116
  act(() => {
109
- tree = create(<SelectPermission route={route} />);
117
+ tree = create(wrapComponent(route));
110
118
  });
111
119
  const instance = tree.root;
112
120
  const TextElement = instance.findAllByType(Text);
113
- expect(TextElement[2].props.children).toBe('Không có dữ liệu');
121
+ expect(TextElement[2].props.children).toBe('No data');
114
122
  });
115
123
 
116
124
  it('render list', () => {
117
125
  mocSetdata();
118
126
  act(() => {
119
- tree = create(<SelectPermission route={route} />);
127
+ tree = create(wrapComponent(route));
120
128
  });
121
129
  const instance = tree.root;
122
130
  const FlatListElement = instance.findAllByType(FlatList);
@@ -151,7 +159,7 @@ describe('Test SelectPermission', () => {
151
159
  it('test onTickedChild function', () => {
152
160
  mocSetdata();
153
161
  act(() => {
154
- tree = create(<SelectPermission route={route} />);
162
+ tree = create(wrapComponent(route));
155
163
  });
156
164
  const instance = tree.root;
157
165
  const SensorItemElement = instance.findAllByType(SensorItem);
@@ -165,7 +173,7 @@ describe('Test SelectPermission', () => {
165
173
  it('test ViewButtonBottom', () => {
166
174
  mocSetdata();
167
175
  act(() => {
168
- tree = create(<SelectPermission route={route} />);
176
+ tree = create(wrapComponent(route));
169
177
  });
170
178
  const instance = tree.root;
171
179
  const ViewButtonBottomElement = instance.findAllByType(ViewButtonBottom);