@eohjsc/react-native-smart-city 0.3.3 → 0.3.6

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 (43) hide show
  1. package/package.json +3 -1
  2. package/src/commons/ActionGroup/ColorPickerTemplate.js +36 -23
  3. package/src/commons/ActionGroup/NumberUpDownActionTemplate.js +31 -12
  4. package/src/commons/ActionGroup/OnOffTemplate/OnOffButtonTemplate.js +8 -2
  5. package/src/commons/ActionGroup/OptionsDropdownActionTemplate.js +9 -7
  6. package/src/commons/ActionGroup/SliderRangeTemplate.js +5 -1
  7. package/src/commons/ActionGroup/__test__/NumberUpDownTemplate.test.js +83 -3
  8. package/src/commons/ActionGroup/__test__/OptionsDropdownTemplate.test.js +57 -1
  9. package/src/commons/ActionGroup/__test__/index.test.js +4 -7
  10. package/src/commons/ConnectingProcess/index.js +4 -1
  11. package/src/commons/Device/ItemDevice.js +4 -1
  12. package/src/commons/Device/WaterQualitySensor/QualityIndicatorsItem.js +7 -2
  13. package/src/commons/Form/CurrencyInput.js +15 -1
  14. package/src/commons/Form/TextInputPassword.js +1 -1
  15. package/src/commons/HeaderAni/index.js +6 -1
  16. package/src/commons/MediaPlayerDetail/index.js +11 -2
  17. package/src/commons/Sharing/MemberList.js +10 -2
  18. package/src/commons/Sharing/WrapHeaderScrollable.js +2 -0
  19. package/src/commons/SubUnit/__test__/ShortDetail.test.js +1 -1
  20. package/src/configs/Constants.js +20 -0
  21. package/src/configs/SCConfig.js +2 -0
  22. package/src/navigations/UnitStack.js +3 -20
  23. package/src/navigations/UnitStackStyles.js +21 -0
  24. package/src/screens/AddNewDevice/__test__/AddNewDevice.test.js +8 -1
  25. package/src/screens/AddNewDevice/__test__/ConnectingDevices.test.js +1 -1
  26. package/src/screens/AddNewGateway/PlugAndPlay/GatewayWifiList.js +39 -36
  27. package/src/screens/AddNewGateway/PlugAndPlay/__test__/GatewayWifiList.test.js +64 -10
  28. package/src/screens/Device/EditDevice/index.js +15 -13
  29. package/src/screens/SubUnit/AddSubUnit.js +23 -17
  30. package/src/screens/SubUnit/EditSubUnit.js +15 -13
  31. package/src/screens/SubUnit/__test__/AddSubUnit.test.js +9 -23
  32. package/src/screens/SyncLGDevice/__test__/AddLGDevice.test.js +8 -1
  33. package/src/screens/Unit/SelectAddress.js +7 -1
  34. package/src/screens/Unit/Station/index.js +3 -0
  35. package/src/screens/Unit/__test__/SelectAddress.test.js +80 -3
  36. package/src/screens/Unit/components/MyUnitDevice/index.js +4 -4
  37. package/src/screens/Unit/components/__test__/MyUnitDevice.test.js +2 -2
  38. package/src/utils/Apis/axios.js +9 -1
  39. package/src/utils/I18n/translations/en.json +3 -1
  40. package/src/utils/I18n/translations/vi.json +3 -1
  41. package/src/utils/Setting/Location.js +30 -0
  42. package/src/utils/__test__/Utils.test.js +12 -0
  43. package/src/commons/ActionGroup/__test__/NumberUpDownTemplateWithNullConfigValue.test.js +0 -60
@@ -13,6 +13,7 @@ import { isIphoneX } from 'react-native-iphone-x-helper';
13
13
  import { Colors, Theme } from '../../configs';
14
14
  import HeaderAni, { heightHeader } from '../../commons/HeaderAni';
15
15
  import Text from '../../commons/Text';
16
+ import { TESTID } from '../../configs/Constants';
16
17
 
17
18
  const WrapHeaderScrollable = ({
18
19
  children,
@@ -59,6 +60,7 @@ const WrapHeaderScrollable = ({
59
60
  onLeft={onGoBack}
60
61
  />
61
62
  <Animated.ScrollView
63
+ testID={TESTID.ANIMATED_SCROLL}
62
64
  scrollEventThrottle={16}
63
65
  onScroll={Animated.event(
64
66
  [{ nativeEvent: { contentOffset: { y: animatedScrollYValue } } }],
@@ -151,7 +151,7 @@ describe('test ShortDetail Subunit', () => {
151
151
  (item) =>
152
152
  item.props.testID === TESTID.SUB_UNIT_DEVICES && item.type === View
153
153
  );
154
- expect(itemDevice.length).toBe(1);
154
+ expect(itemDevice.length).toBe(0);
155
155
  });
156
156
 
157
157
  test('render ShortDetail add new device', async () => {
@@ -75,6 +75,7 @@ export const DEVICE_TYPE = {
75
75
  LG_THINQ: 'LG_THINQ',
76
76
  HANET: 'HANET',
77
77
  ZIGBEE: 'ZIGBEE',
78
+ GOOGLE_HOME: 'GOOGLE_HOME',
78
79
  };
79
80
 
80
81
  const marginItem = 12;
@@ -288,6 +289,8 @@ export const TESTID = {
288
289
  SUB_UNIT_TEXT_DROPDOWN: 'SUB_UNIT_TEXT_DROPDOWN',
289
290
  SUB_UNIT_GO_DETAIL: 'SUB_UNIT_GO_DETAIL',
290
291
  VIEW_SUB_UNIT_AUTOMATE: 'VIEW_SUB_UNIT_AUTOMATE',
292
+ SUB_UNIT_NAME: 'SUB_UNIT_NAME',
293
+ ANIMATED_SCROLL: 'ANIMATED_SCROLL',
291
294
  ADD_SUB_UNIT: 'ADD_SUB_UNIT',
292
295
 
293
296
  // NavBar
@@ -392,6 +395,7 @@ export const TESTID = {
392
395
  ITEM_TEXT_ERROR: 'ITEM_TEXT_ERROR',
393
396
  SEARCH_BAR_INPUT: 'SEARCH_BAR_INPUT',
394
397
  GO_DETAIL: 'GO_DETAIL',
398
+ NAV_LIST: 'NAV_LIST',
395
399
 
396
400
  // Automate
397
401
  AUTOMATE_SCRIPT_ACTION: 'AUTOMATE_SCRIPT_ACTION',
@@ -447,8 +451,13 @@ export const TESTID = {
447
451
  ITEM_QUICK_ACTION_PRESS: 'ITEM_QUICK_ACTION_PRESS',
448
452
  TIME_COUNT_DOWN_TEXT: 'TIME_COUNT_DOWN_TEXT',
449
453
  ACTION_ITEM: 'ACTION_ITEM',
454
+
450
455
  // Sensor Item
451
456
  TEXT_SENSOR_ITEM: 'TEXT_SENSOR_ITEM',
457
+ SENSOR_NAME: 'SENSOR_NAME',
458
+ ON_OFF_BUTTON: 'ON_OFF_BUTTON',
459
+ SENSOR_STATUS: 'SENSOR_STATUS',
460
+ ICON_BACK: 'ICON_BACK',
452
461
 
453
462
  // DeviceInfo
454
463
  DEVICE_INFO_BATTERY: 'DEVICE_INFO_BATTERY',
@@ -564,6 +573,7 @@ export const TESTID = {
564
573
  ICON_ADD_STAR_SHARED_UNIT: 'ICON_ADD_STAR_SHARED_UNIT',
565
574
  TOUCH_SHARED_UNIT: 'TOUCH_SHARED_UNIT',
566
575
  SHARED_UNIT_OWN_BY: 'SHARED_UNIT_OWN_BY',
576
+ ICON_UNIT: 'ICON_UNIT',
567
577
 
568
578
  // Select subunit
569
579
 
@@ -809,3 +819,13 @@ export const SENSOR_TYPE = {
809
819
  SOS: 'sos',
810
820
  FILTER_WATER: 'filter_water',
811
821
  };
822
+
823
+ export const PROBLEM_CODE = {
824
+ CLIENT_ERROR: 'CLIENT_ERROR',
825
+ SERVER_ERROR: 'SERVER_ERROR',
826
+ TIMEOUT_ERROR: 'TIMEOUT_ERROR',
827
+ CONNECTION_ERROR: 'CONNECTION_ERROR',
828
+ NETWORK_ERROR: 'NETWORK_ERROR',
829
+ UNKNOWN_ERROR: 'UNKNOWN_ERROR',
830
+ CANCEL_ERROR: 'CANCEL_ERROR',
831
+ };
@@ -107,11 +107,13 @@ export class SCConfig {
107
107
  static VCONNEX_REDIRECT_URI_APP = SCDefaultConfig.VCONNEX_REDIRECT_URI_APP;
108
108
  static pusherAppKey = SCDefaultConfig.pusherAppKey;
109
109
  static pusherAppCluste = SCDefaultConfig.pusherAppCluster;
110
+ static language = 'en';
110
111
  }
111
112
 
112
113
  export const initSCConfig = (config) => {
113
114
  api.setBaseURL(config.apiRoot ?? SCDefaultConfig.apiRoot);
114
115
  LocaleConfig.defaultLocale = config.language;
116
+ SCConfig.language = config.language ?? SCConfig.language;
115
117
  SCConfig.apiRoot = config.apiRoot ?? SCDefaultConfig.apiRoot;
116
118
  SCConfig.GOOGLE_MAP_API_KEY =
117
119
  config.GOOGLE_MAP_API_KEY ?? SCDefaultConfig.GOOGLE_MAP_API_KEY;
@@ -1,5 +1,5 @@
1
1
  import React, { memo, useContext, useEffect } from 'react';
2
- import { View, StyleSheet } from 'react-native';
2
+ import { View } from 'react-native';
3
3
  import { IconOutline } from '@ant-design/icons-react-native';
4
4
  import { createStackNavigator } from '@react-navigation/stack';
5
5
  import { BleManager } from 'react-native-ble-plx';
@@ -52,10 +52,10 @@ import ConfirmUnitDeletion from '../screens/ConfirmUnitDeletion';
52
52
  import InfoMemberUnit from '../screens/Sharing/InfoMemberUnit';
53
53
  import EnterPassword from '../screens/EnterPassword';
54
54
  import { HanetCameraStack } from './HanetCameraStack';
55
-
56
55
  import { axiosGet } from '../utils/Apis/axios';
57
56
  import { API } from '../configs';
58
57
  import SideMenuDetail from '../screens/SideMenuDetail';
58
+ import { styles } from './UnitStackStyles';
59
59
 
60
60
  const Stack = createStackNavigator();
61
61
 
@@ -173,12 +173,9 @@ export const UnitStack = memo((props) => {
173
173
  component={ChooseLocation}
174
174
  options={{
175
175
  headerShown: true,
176
- headerTitleStyle: {
177
- ...styles.headerLocation,
178
- },
179
176
  headerTitle: () => (
180
177
  <View style={styles.headerLocation}>
181
- <Text type="H3" color={Colors.Gray9} bold>
178
+ <Text color={Colors.Gray9} style={styles.headerTitle} bold>
182
179
  {t('choose_on_map')}
183
180
  </Text>
184
181
 
@@ -406,17 +403,3 @@ export const UnitStack = memo((props) => {
406
403
  </Stack.Navigator>
407
404
  );
408
405
  });
409
-
410
- const styles = StyleSheet.create({
411
- icLeft: {
412
- marginLeft: Device.isIOS ? 8 : 0,
413
- },
414
- headerLocation: {
415
- alignItems: 'center',
416
- justifyContent: 'center',
417
- },
418
- headerContent: {
419
- textAlign: 'center',
420
- paddingBottom: 8,
421
- },
422
- });
@@ -0,0 +1,21 @@
1
+ import { StyleSheet } from 'react-native';
2
+ import { Device } from '../configs';
3
+
4
+ export const styles = StyleSheet.create({
5
+ icLeft: {
6
+ marginLeft: Device.isIOS ? 8 : 0,
7
+ },
8
+ headerLocation: {
9
+ alignItems: 'center',
10
+ justifyContent: 'center',
11
+ width: 290,
12
+ },
13
+ headerTitle: {
14
+ fontSize: 20,
15
+ lineHeight: 28,
16
+ },
17
+ headerContent: {
18
+ textAlign: 'center',
19
+ paddingBottom: 4,
20
+ },
21
+ });
@@ -53,6 +53,7 @@ describe('Test AddNewDevice', () => {
53
53
  unit_id: 1,
54
54
  },
55
55
  };
56
+ mock.resetHistory();
56
57
  });
57
58
 
58
59
  const getText = (instance, id) => {
@@ -103,7 +104,13 @@ describe('Test AddNewDevice', () => {
103
104
  });
104
105
  const instance = tree.root;
105
106
  const groupCheckBox = instance.findByType(GroupCheckBox);
106
- expect(groupCheckBox.props.data).toEqual([]);
107
+ expect(groupCheckBox.props.data).toEqual([
108
+ {
109
+ id: 2,
110
+ name: 'Station name',
111
+ title: 'Station name',
112
+ },
113
+ ]);
107
114
  });
108
115
 
109
116
  test('ViewButtonBottom', async () => {
@@ -103,7 +103,7 @@ describe('Test ConnectingDevices', () => {
103
103
  await jest.runOnlyPendingTimers();
104
104
  });
105
105
  expect(setInterval).toHaveBeenCalled();
106
- expect(mockedNavigate).not.toHaveBeenCalledWith(Routes.ConnectDevices, {
106
+ expect(mockedNavigate).toHaveBeenCalledWith(Routes.ConnectDevices, {
107
107
  new_sensor: { id: 1 },
108
108
  });
109
109
  });
@@ -28,8 +28,6 @@ import WifiManager from 'react-native-wifi-reborn';
28
28
  import { useNavigation } from '@react-navigation/native';
29
29
  import { TESTID } from '../../../configs/Constants';
30
30
 
31
- const isIos = Platform.OS === 'ios';
32
-
33
31
  const GatewayWifiList = memo(({ route }) => {
34
32
  const {
35
33
  list_wifi,
@@ -72,41 +70,46 @@ const GatewayWifiList = memo(({ route }) => {
72
70
  if (Object.prototype.hasOwnProperty.call(data, 'gateway')) {
73
71
  const checkWifiInterval = setInterval(() => {
74
72
  // eslint-disable-next-line promise/prefer-await-to-then
75
- WifiManager.getCurrentWifiSSID().then((ssid) => {
76
- if (ssid !== wifi_ssid) {
77
- const IsRobot = devicePrefixName === 'ROBOT';
78
- if (IsRobot) {
79
- setAction(Action.IS_CONNECT_WIFI_GATEWAY, false);
80
- navigate(Routes.AddDeviceStack, {
81
- screen: Routes.AddCommonSelectSubUnit,
82
- params: {
83
- scan_sensor_data: scan_sensor_data,
84
- addType: 'AddDeviceNewFlow',
85
- gateway: data?.gateway,
86
- unit_id: unit_id,
87
- devicePrefixName: devicePrefixName,
88
- wifi_ssid: wifi_ssid,
89
- wifi_pass: wifi_pass,
90
- },
91
- });
92
- clearInterval(checkWifiInterval);
93
- } else {
94
- setAction(Action.IS_CONNECT_WIFI_GATEWAY, false);
95
- navigate(Routes.AddDeviceStack, {
96
- screen: Routes.ConnectingProcess,
97
- params: {
98
- unit_id: unit_id,
99
- unit_name: unit_name,
100
- scan_sensor_data: scan_sensor_data,
101
- gateway: data?.gateway,
102
- devicePrefixName: devicePrefixName,
103
- chip_id: chip_id,
104
- },
105
- });
106
- clearInterval(checkWifiInterval);
73
+ WifiManager.getCurrentWifiSSID().then(
74
+ (ssid) => {
75
+ if (ssid !== wifi_ssid) {
76
+ const IsRobot = devicePrefixName === 'ROBOT';
77
+ if (IsRobot) {
78
+ setAction(Action.IS_CONNECT_WIFI_GATEWAY, false);
79
+ navigate(Routes.AddDeviceStack, {
80
+ screen: Routes.AddCommonSelectSubUnit,
81
+ params: {
82
+ scan_sensor_data: scan_sensor_data,
83
+ addType: 'AddDeviceNewFlow',
84
+ gateway: data?.gateway,
85
+ unit_id: unit_id,
86
+ devicePrefixName: devicePrefixName,
87
+ wifi_ssid: wifi_ssid,
88
+ wifi_pass: wifi_pass,
89
+ },
90
+ });
91
+ clearInterval(checkWifiInterval);
92
+ } else {
93
+ setAction(Action.IS_CONNECT_WIFI_GATEWAY, false);
94
+ navigate(Routes.AddDeviceStack, {
95
+ screen: Routes.ConnectingProcess,
96
+ params: {
97
+ unit_id: unit_id,
98
+ unit_name: unit_name,
99
+ scan_sensor_data: scan_sensor_data,
100
+ gateway: data?.gateway,
101
+ devicePrefixName: devicePrefixName,
102
+ chip_id: chip_id,
103
+ },
104
+ });
105
+ clearInterval(checkWifiInterval);
106
+ }
107
107
  }
108
+ },
109
+ () => {
110
+ ToastBottomHelper.error('Cannot get current SSID!');
108
111
  }
109
- });
112
+ );
110
113
  }, 3000);
111
114
  }
112
115
  },
@@ -151,7 +154,7 @@ const GatewayWifiList = memo(({ route }) => {
151
154
 
152
155
  const connectWifi = useCallback(async () => {
153
156
  if (!isConnectWifiGateway) {
154
- if (isIos) {
157
+ if (Platform.OS === 'ios') {
155
158
  sendConnect(0);
156
159
  setAction(Action.IS_CONNECT_WIFI_GATEWAY, true);
157
160
  setIsSendWifi(true);
@@ -1,25 +1,32 @@
1
1
  import React from 'react';
2
2
  import { act, create } from 'react-test-renderer';
3
3
  import GatewayWifiList from '../GatewayWifiList';
4
- import { Text, ScrollView, TouchableOpacity } from 'react-native';
4
+ import { Text, ScrollView, TouchableOpacity, Platform } from 'react-native';
5
5
  import { getTranslate } from '../../../../utils/I18n';
6
6
  import { SCProvider } from '../../../../context';
7
7
  import { mockSCStore } from '../../../../context/mockStore';
8
8
  import TextInputPassword from '../../../../commons/Form/TextInputPassword';
9
9
  import { TESTID } from '../../../../configs/Constants';
10
+ import WifiManager from 'react-native-wifi-reborn';
11
+ import { useNavigation } from '@react-navigation/native';
12
+ import Routes from '../../../../utils/Route';
10
13
 
11
- const wrapComponent = (route) => (
12
- <SCProvider initState={mockSCStore({})}>
14
+ const wrapComponent = (route, state = {}) => (
15
+ <SCProvider initState={{ ...mockSCStore({}), ...state }}>
13
16
  <GatewayWifiList route={route} />
14
17
  </SCProvider>
15
18
  );
16
19
 
17
20
  describe('Test GatewayWifiList', () => {
18
21
  let tree;
22
+ const socket = {
23
+ on: jest.fn(),
24
+ send: jest.fn(),
25
+ };
19
26
  let route = {
20
27
  params: {
21
28
  list_wifi: [{ ssid: 'eoh@io' }, { ssid: 'eoh@ras.io' }],
22
- socket: { send: jest.fn() },
29
+ socket: socket,
23
30
  },
24
31
  };
25
32
 
@@ -33,6 +40,7 @@ describe('Test GatewayWifiList', () => {
33
40
  expect(texts[1].props.children).toEqual(getTranslate('en', 'set_network'));
34
41
  expect(texts[3].props.children).toEqual('eoh@io');
35
42
  });
43
+
36
44
  test('onPress wifi', async () => {
37
45
  await act(async () => {
38
46
  tree = await create(wrapComponent(route));
@@ -46,6 +54,7 @@ describe('Test GatewayWifiList', () => {
46
54
  await touchableOpacity[1].props.onPress();
47
55
  });
48
56
  });
57
+
49
58
  test('onChange TextInputPassword', async () => {
50
59
  await act(async () => {
51
60
  tree = await create(wrapComponent(route));
@@ -60,15 +69,60 @@ describe('Test GatewayWifiList', () => {
60
69
  const ButtonPopup = instance.find(
61
70
  (el) => el.props.testID === TESTID.GATEWAY_WIFI_LIST.BUTTON_POPUP
62
71
  );
63
- await act(() => {
64
- ButtonPopup.props.onPressMain();
72
+ await act(async () => {
73
+ await ButtonPopup.props.onPressMain();
65
74
  });
66
- await act(() => {
67
- ButtonPopup.props.onPressSecondary();
75
+ await act(async () => {
76
+ await ButtonPopup.props.onPressSecondary();
68
77
  });
69
- await act(() => {
70
- ButtonPopup.props.onClose();
78
+ await act(async () => {
79
+ await ButtonPopup.props.onClose();
71
80
  });
72
81
  expect(ButtonPopup).toBeDefined();
73
82
  });
83
+
84
+ test('on device is connected to wifi and mobile re-connect to internet', async () => {
85
+ jest.useFakeTimers();
86
+ Platform.OS = 'android';
87
+
88
+ await act(async () => {
89
+ tree = await create(wrapComponent(route, {}));
90
+ });
91
+
92
+ const instance = tree.root;
93
+ const ButtonPopup = instance.find(
94
+ (el) => el.props.testID === TESTID.GATEWAY_WIFI_LIST.BUTTON_POPUP
95
+ );
96
+ await act(async () => {
97
+ await ButtonPopup.props.onPressMain();
98
+ });
99
+ expect(socket.on).toBeCalled();
100
+ expect(socket.send).toBeCalled();
101
+
102
+ const mockWifiThen = jest.fn();
103
+ WifiManager.getCurrentWifiSSID.mockImplementation(() => ({
104
+ then: mockWifiThen,
105
+ }));
106
+
107
+ // receive message
108
+ await act(async () => {
109
+ await socket.on.mock.calls[0][1](
110
+ JSON.stringify({
111
+ gateway: true,
112
+ })
113
+ );
114
+ });
115
+ jest.runOnlyPendingTimers();
116
+
117
+ expect(WifiManager.getCurrentWifiSSID).toBeCalled();
118
+ expect(mockWifiThen).toBeCalled();
119
+
120
+ // get ssid success
121
+ act(() => {
122
+ mockWifiThen.mock.calls[0][0]('new-ssid');
123
+ });
124
+ const { navigate } = useNavigation();
125
+ expect(navigate).toBeCalled();
126
+ expect(navigate.mock.calls[0][0]).toEqual(Routes.AddDeviceStack);
127
+ });
74
128
  });
@@ -104,20 +104,22 @@ const EditDevice = memo(() => {
104
104
  />
105
105
  </View>
106
106
  </TouchableOpacity>
107
- <TouchableOpacity
108
- style={styles.removeButton}
109
- onPress={onShowDelete(sensor?.name)}
110
- testID={TESTID.DEVICE_SHOW_REMOVE}
111
- >
112
- <Text
113
- type={'H4'}
114
- semibold
115
- color={Colors.Red}
116
- style={styles.removeBorderBottom}
107
+ {!stateAlertAction.visible && (
108
+ <TouchableOpacity
109
+ style={styles.removeButton}
110
+ onPress={onShowDelete(sensor?.name)}
111
+ testID={TESTID.DEVICE_SHOW_REMOVE}
117
112
  >
118
- {t('remove_device')}
119
- </Text>
120
- </TouchableOpacity>
113
+ <Text
114
+ type={'H4'}
115
+ semibold
116
+ color={Colors.Red}
117
+ style={styles.removeBorderBottom}
118
+ >
119
+ {t('remove_device')}
120
+ </Text>
121
+ </TouchableOpacity>
122
+ )}
121
123
  </View>
122
124
  <AlertAction
123
125
  visible={stateAlertAction.visible}
@@ -25,11 +25,12 @@ import { ToastBottomHelper } from '../../utils/Utils';
25
25
  import { TESTID } from '../../configs/Constants';
26
26
  import styles from './AddSubUnitStyles';
27
27
  import useKeyboardShow from '../../hooks/Common/useKeyboardShow';
28
+ import { replace } from '../../navigations/utils';
28
29
 
29
30
  const AddSubUnit = ({ route }) => {
30
31
  const t = useTranslations();
31
32
  const { dismissKeyboard } = useKeyboardShow();
32
- const { navigate, goBack } = useNavigation();
33
+ const { navigate, goBack, dispatch } = useNavigation();
33
34
  const { unit, addType, isAddUnit, location = '' } = route?.params;
34
35
  const [roomName, setRoomName] = useState('');
35
36
  const [wallpaper, setWallpaper] = useState('');
@@ -62,13 +63,15 @@ const AddSubUnit = ({ route }) => {
62
63
  }
63
64
  );
64
65
  if (success) {
65
- navigate(Routes.UnitStack, {
66
- screen: Routes.UnitDetail,
67
- params: {
68
- unitId: data?.id,
69
- routeName: Routes.DashboardStack,
70
- },
71
- });
66
+ dispatch(
67
+ replace(Routes.UnitStack, {
68
+ screen: Routes.UnitDetail,
69
+ params: {
70
+ unitId: data?.id,
71
+ routeName: Routes.DashboardStack,
72
+ },
73
+ })
74
+ );
72
75
  cleanData();
73
76
  } else {
74
77
  awaitCreate.current = false;
@@ -98,15 +101,17 @@ const AddSubUnit = ({ route }) => {
98
101
  });
99
102
  return;
100
103
  }
101
- navigate(Routes.UnitStack, {
102
- screen: Routes.UnitDetail,
103
- params: {
104
- unitId: unit.id,
105
- unitData: unit,
106
- isAddSubUnit: true,
107
- routeName: Routes.DashboardStack,
108
- },
109
- });
104
+ dispatch(
105
+ replace(Routes.UnitStack, {
106
+ screen: Routes.UnitDetail,
107
+ params: {
108
+ unitId: unit.id,
109
+ unitData: unit,
110
+ isAddSubUnit: true,
111
+ routeName: Routes.DashboardStack,
112
+ },
113
+ })
114
+ );
110
115
  cleanData();
111
116
  } else {
112
117
  awaitCreate.current = false;
@@ -123,6 +128,7 @@ const AddSubUnit = ({ route }) => {
123
128
  t,
124
129
  unit,
125
130
  addType,
131
+ dispatch,
126
132
  goBack,
127
133
  route.params,
128
134
  ]);
@@ -228,20 +228,22 @@ const EditSubUnit = ({ route }) => {
228
228
  setImageUrl={setImageUrl}
229
229
  optionsCapture={options}
230
230
  />
231
- <TouchableOpacity
232
- testID={TESTID.MANAGE_SUB_UNIT_REMOVE_BUTTON}
233
- onPress={onPressRemove}
234
- style={styles.removeButton}
235
- >
236
- <Text
237
- type={'H4'}
238
- semibold
239
- color={Colors.Red}
240
- style={styles.removeText}
231
+ {!showEdit && (
232
+ <TouchableOpacity
233
+ testID={TESTID.MANAGE_SUB_UNIT_REMOVE_BUTTON}
234
+ onPress={onPressRemove}
235
+ style={styles.removeButton}
241
236
  >
242
- {t('remove_sub_unit')}
243
- </Text>
244
- </TouchableOpacity>
237
+ <Text
238
+ type={'H4'}
239
+ semibold
240
+ color={Colors.Red}
241
+ style={styles.removeText}
242
+ >
243
+ {t('remove_sub_unit')}
244
+ </Text>
245
+ </TouchableOpacity>
246
+ )}
245
247
  </View>
246
248
  </View>
247
249
  <ModalCustom
@@ -36,13 +36,20 @@ jest.mock('react-redux', () => {
36
36
  };
37
37
  });
38
38
 
39
+ const mockNavigationDispatch = jest.fn();
40
+ const mockReplace = jest.fn();
41
+
39
42
  jest.mock('@react-navigation/native', () => {
40
43
  return {
41
44
  ...jest.requireActual('@react-navigation/native'),
42
45
  useNavigation: () => ({
43
46
  navigate: mockedNavigate,
44
47
  goBack: mockedGoBack,
48
+ dispatch: mockNavigationDispatch,
45
49
  }),
50
+ StackActions: {
51
+ replace: () => mockReplace,
52
+ },
46
53
  };
47
54
  });
48
55
 
@@ -63,6 +70,7 @@ describe('Test AddSubUnit', () => {
63
70
  afterEach(() => {
64
71
  mockedDispatch.mockClear();
65
72
  mockedNavigate.mockClear();
73
+ mockNavigationDispatch.mockClear();
66
74
  Toast.show.mockClear();
67
75
  });
68
76
  let tree;
@@ -150,15 +158,6 @@ describe('Test AddSubUnit', () => {
150
158
  await act(async () => {
151
159
  await viewButtonBottom.props.onRightClick();
152
160
  });
153
- expect(mockedNavigate).not.toHaveBeenCalledWith(Routes.UnitStack, {
154
- screen: Routes.UnitDetail,
155
- params: {
156
- unitId: route.params.unit.id,
157
- unitData: route.params.unit,
158
- routeName: 'DashboardStack',
159
- isAddSubUnit: true,
160
- },
161
- });
162
161
  expect(Toast.show).toHaveBeenCalledWith({
163
162
  type: 'error',
164
163
  position: 'bottom',
@@ -186,13 +185,6 @@ describe('Test AddSubUnit', () => {
186
185
  });
187
186
 
188
187
  test('test create Unit', async () => {
189
- const response = {
190
- success: true,
191
- status: 200,
192
- data: {
193
- id: 2,
194
- },
195
- };
196
188
  route.params = {
197
189
  ...route.params,
198
190
  location: 'Unit address',
@@ -211,13 +203,7 @@ describe('Test AddSubUnit', () => {
211
203
  await act(async () => {
212
204
  await viewButtonBottom.props.onRightClick();
213
205
  });
214
- expect(mockedNavigate).toHaveBeenCalledWith(Routes.UnitStack, {
215
- screen: Routes.UnitDetail,
216
- params: {
217
- unitId: response.data.id,
218
- routeName: Routes.DashboardStack,
219
- },
220
- });
206
+ expect(mockNavigationDispatch).toBeCalledWith(mockReplace);
221
207
  });
222
208
 
223
209
  test('test choose Location', async () => {
@@ -53,6 +53,7 @@ describe('Test Add LG Device', () => {
53
53
  backend_url: 'https://doamin.com',
54
54
  },
55
55
  };
56
+ mock.resetHistory();
56
57
  });
57
58
 
58
59
  const getText = (instance, id) => {
@@ -105,7 +106,13 @@ describe('Test Add LG Device', () => {
105
106
  });
106
107
  const instance = tree.root;
107
108
  const groupCheckBox = instance.findByType(GroupCheckBox);
108
- expect(groupCheckBox.props.data).toEqual([]);
109
+ expect(groupCheckBox.props.data).toEqual([
110
+ {
111
+ id: 2,
112
+ name: 'Station name',
113
+ title: 'Station name',
114
+ },
115
+ ]);
109
116
  });
110
117
 
111
118
  test('ViewButtonBottom', async () => {