@eohjsc/react-native-smart-city 0.7.20 → 0.7.22

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 (67) hide show
  1. package/assets/images/Schedule.svg +39 -0
  2. package/assets/images/ValueChange.svg +49 -0
  3. package/package.json +1 -1
  4. package/src/Images/Common/default_end_device.png +0 -0
  5. package/src/commons/Automate/ButtonAddCondition.js +51 -0
  6. package/src/commons/Automate/ItemConditionScriptDetail.js +28 -15
  7. package/src/commons/Automate/ItemConditionScriptDetailStyles.js +9 -0
  8. package/src/commons/Dashboard/MyUnit/index.js +19 -20
  9. package/src/commons/DevMode/Search.js +1 -1
  10. package/src/commons/Device/RainningSensor/CurrentRainSensor.js +5 -5
  11. package/src/commons/Widgets/IFrameWithConfig/IFrameWithConfig.js +1 -3
  12. package/src/commons/Widgets/IFrameWithConfig/__tests__/IFrameWithConfig.test.js +1 -1
  13. package/src/configs/API.js +16 -1
  14. package/src/configs/AccessibilityLabel.js +9 -1
  15. package/src/configs/Images.js +1 -0
  16. package/src/context/actionType.ts +5 -0
  17. package/src/context/reducer.ts +30 -1
  18. package/src/navigations/AddMemberStack.js +3 -3
  19. package/src/navigations/UnitStack.js +8 -0
  20. package/src/screens/AddCommon/SelectUnit.js +3 -2
  21. package/src/screens/AddLocationMaps/__test__/index.test.js +13 -13
  22. package/src/screens/Automate/AddNewAction/SetupConfigCondition.js +73 -30
  23. package/src/screens/Automate/AddNewAction/__test__/ChooseConfig.test.js +9 -11
  24. package/src/screens/Automate/AddNewAction/__test__/SetupConfigCondition.test.js +115 -10
  25. package/src/screens/Automate/AddNewAutoSmart/AddTypeSmart.js +7 -3
  26. package/src/screens/Automate/AddNewAutoSmart/__test__/AddAutomationTypeSmart.test.js +31 -0
  27. package/src/screens/Automate/ScriptDetail/Components/DeleteCondition.js +51 -0
  28. package/src/screens/Automate/ScriptDetail/Components/ModalAddCondition.js +196 -0
  29. package/src/screens/Automate/ScriptDetail/Styles/indexStyles.js +18 -0
  30. package/src/screens/Automate/ScriptDetail/__test__/index.test.js +441 -47
  31. package/src/screens/Automate/ScriptDetail/index.js +359 -72
  32. package/src/screens/Automate/ScriptDetail/utils.js +7 -31
  33. package/src/screens/Automate/SetSchedule/AddEditConditionSchedule.js +173 -0
  34. package/src/screens/Automate/SetSchedule/__test__/AddEditConditionSchedule.test.js +211 -0
  35. package/src/screens/ConfirmUnitDeletion/__test__/ConfirmUnitDeletion.test.js +69 -13
  36. package/src/screens/ConfirmUnitDeletion/index.js +14 -14
  37. package/src/screens/Sharing/Components/ConfigItem.js +34 -0
  38. package/src/screens/Sharing/Components/DeviceItem.js +77 -0
  39. package/src/screens/Sharing/Components/ItemChangeRole.js +3 -4
  40. package/src/screens/Sharing/Components/ShareDeviceSelector.js +255 -0
  41. package/src/screens/Sharing/Components/Styles/CheckBoxCustomStyles.js +1 -1
  42. package/src/screens/Sharing/Components/Styles/DeviceItemStyles.js +11 -27
  43. package/src/screens/Sharing/{Styles/SelectPermissionStyles.js → Components/Styles/ShareDeviceSelectorStyles.js} +3 -11
  44. package/src/screens/Sharing/Components/SubUnitItem.js +28 -0
  45. package/src/screens/Sharing/Components/SubUnitTreeView.js +68 -0
  46. package/src/screens/Sharing/Components/TitleCheckBox.js +23 -41
  47. package/src/screens/Sharing/Components/__test__/ItemChangeRole.test.js +7 -7
  48. package/src/screens/Sharing/Components/__test__/ShareDeviceSelector.test.js +298 -0
  49. package/src/screens/Sharing/Components/index.js +14 -1
  50. package/src/screens/Sharing/InfoMemberUnit.js +20 -20
  51. package/src/screens/Sharing/SelectShareDevice.js +11 -255
  52. package/src/screens/Sharing/SelectUser.js +12 -12
  53. package/src/screens/Sharing/UpdateShareDevice.js +45 -301
  54. package/src/screens/Sharing/__test__/InfoMemberUnit.test.js +58 -11
  55. package/src/screens/Sharing/__test__/SelectShareDevice.test.js +51 -160
  56. package/src/screens/Sharing/__test__/SelectUser.test.js +72 -10
  57. package/src/screens/Sharing/__test__/UpdateShareDevice.test.js +49 -209
  58. package/src/utils/I18n/translations/en.js +22 -1
  59. package/src/utils/I18n/translations/vi.js +23 -3
  60. package/src/utils/Route/index.js +1 -0
  61. package/src/commons/Sharing/StationDevicePermissions.js +0 -204
  62. package/src/screens/Sharing/Components/CheckBoxConfig.js +0 -44
  63. package/src/screens/Sharing/Components/CheckBoxSubUnit.js +0 -35
  64. package/src/screens/Sharing/Components/EndDevice.js +0 -93
  65. package/src/screens/Sharing/Components/Styles/CheckBoxConfigStyles.js +0 -18
  66. package/src/screens/Sharing/Components/Styles/TitleCheckBoxStyles.js +0 -21
  67. package/src/screens/Sharing/Components/__test__/TitleCheckBox.test.js +0 -31
@@ -1,19 +1,20 @@
1
- import { act } from '@testing-library/react-hooks';
2
- import React from 'react';
3
- import { Alert } from 'react-native';
4
- import { create } from 'react-test-renderer';
5
- import MockAdapter from 'axios-mock-adapter';
6
- import { ViewButtonBottom } from '../../../commons';
7
- import { SCProvider } from '../../../context';
8
- import { mockSCStore } from '../../../context/mockStore';
9
1
  import API from '../../../configs/API';
10
- import api from '../../../utils/Apis/axios';
11
2
  import AccessibilityLabel from '../../../configs/AccessibilityLabel';
12
- import SelectShareDevice from '../SelectShareDevice';
3
+ import { IconOutline } from '@ant-design/icons-react-native';
4
+ import MockAdapter from 'axios-mock-adapter';
5
+ import React from 'react';
13
6
  import Routes from '../../../utils/Route';
7
+ import { SCProvider } from '../../../context';
8
+ import SelectShareDevice from '../SelectShareDevice';
9
+ import { ShareDeviceSelector } from '../Components';
10
+ import { ViewButtonBottom } from '../../../commons';
11
+ import { act } from '@testing-library/react-hooks';
12
+ import api from '../../../utils/Apis/axios';
13
+ import { create } from 'react-test-renderer';
14
+ import { mockSCStore } from '../../../context/mockStore';
15
+ import { useNavigation } from '@react-navigation/native';
14
16
 
15
17
  const mock = new MockAdapter(api.axiosInstance);
16
- jest.spyOn(Alert, 'alert').mockImplementation(() => {});
17
18
 
18
19
  const wrapComponent = (route) => (
19
20
  <SCProvider initState={mockSCStore({})}>
@@ -28,175 +29,65 @@ describe('Test SelectShareDevice', () => {
28
29
  unit: { id: 1, name: 'unit 1' },
29
30
  },
30
31
  };
31
- let listDevices = [
32
- {
33
- id: 1,
34
- name: 'Sub unit',
35
- devices: [
36
- {
37
- id: 2,
38
- actions: [{ id: 3, name: 'action 1' }],
39
- read_configs: [{ id: 4, name: 'config 1' }],
40
- name: 'child1',
41
- },
42
- {
43
- id: 5,
44
- actions: [{ id: 6, name: 'action 2' }],
45
- read_configs: [{ id: 7, name: 'config 2' }],
46
- name: 'child2',
47
- },
48
- {
49
- id: 8,
50
- actions: [],
51
- read_configs: [],
52
- name: 'child3',
53
- },
54
- ],
55
- },
56
- ];
57
-
58
- afterEach(() => {
59
- Alert.alert.mockReset();
32
+ let listDevices;
33
+ beforeEach(() => {
60
34
  mock.resetHistory();
35
+ listDevices = [
36
+ {
37
+ id: 1,
38
+ name: 'Sub unit 1',
39
+ devices: [
40
+ {
41
+ id: 1,
42
+ icon_kit: 'https://xxx.png',
43
+ actions: [{ id: 1, name: 'action 1' }],
44
+ read_configs: [{ id: 1, name: 'config 1' }],
45
+ name: 'child1',
46
+ },
47
+ ],
48
+ },
49
+ ];
61
50
  });
62
-
63
- const clickCheckBoxAllDevice = async (instance, statusCheckbox) => {
64
- const checkBoxAllDevice = instance.find(
65
- (el) =>
66
- el.props.accessibilityLabel ===
67
- `${AccessibilityLabel.CHECK_BOX_CUSTOM}-undefined`
68
- );
69
- expect(checkBoxAllDevice.props.isChecked).toEqual(statusCheckbox);
70
- await act(async () => {
71
- await checkBoxAllDevice.props.onPress();
72
- });
73
- };
74
-
75
- const clickCheckBoxSubUnit = async (instance, statusCheckbox) => {
76
- const checkBoxSubunit = instance.find(
51
+ const clickChooseDevice = async (instance, deviceId, status) => {
52
+ const chooseDevice = instance.find(
77
53
  (el) =>
78
54
  el.props.accessibilityLabel ===
79
- `${AccessibilityLabel.CHECK_BOX_CUSTOM}-0`
55
+ `${AccessibilityLabel.SHARE_DEVICE.NAME_END_DEVICE}-device-${deviceId}`
80
56
  );
81
- expect(checkBoxSubunit.props.isChecked).toEqual(statusCheckbox);
82
57
  await act(async () => {
83
- await checkBoxSubunit.props.onPress();
58
+ chooseDevice.props.onPress();
84
59
  });
85
- };
86
-
87
- const clickCheckBoxConfig = async (instance, configId, statusCheckbox) => {
88
- let checkBoxConfig = instance.find(
60
+ const iconCheck = instance.findAll(
89
61
  (el) =>
90
62
  el.props.accessibilityLabel ===
91
- `${AccessibilityLabel.SHARE_DEVICE.CHECK_BOX_CONFIG}-${configId}`
63
+ `${AccessibilityLabel.SHARE_DEVICE.ICON_CHECK}-device-${deviceId}` &&
64
+ el.type === IconOutline
92
65
  );
93
- expect(checkBoxConfig.props.isChecked).toEqual(statusCheckbox);
94
- await act(async () => {
95
- await checkBoxConfig.props.onPress();
96
- });
66
+ expect(iconCheck).toHaveLength(status ? 1 : 0);
97
67
  };
98
-
99
- const clickExpandEndDevice = async (instance, indexEndDevice, statusIcon) => {
100
- const expandEndDevice = instance.find(
101
- (el) =>
102
- el.props.accessibilityLabel ===
103
- `${AccessibilityLabel.SHARE_DEVICE.EXPAND_END_DEVICE}-${indexEndDevice}`
104
- );
105
- expect(expandEndDevice.props.name).toEqual(statusIcon);
106
- await act(async () => {
107
- await expandEndDevice.props.onPress();
108
- });
109
- };
110
-
111
- const clickNameEndDevice = async (instance, indexEndDevice) => {
112
- const nameEndDevice = instance.find(
113
- (el) =>
114
- el.props.accessibilityLabel ===
115
- `${AccessibilityLabel.SHARE_DEVICE.CLICK_NAME_END_DEVICE}-${indexEndDevice}`
116
- );
117
- await act(async () => {
118
- await nameEndDevice.props.onPress();
119
- });
120
- };
121
-
122
- it('test user select share device', async () => {
123
- mock.onGet(API.SHARE.UNIT_PERMISSIONS(1)).reply(200, listDevices);
124
-
68
+ test('test render SelectShareDevice', async () => {
69
+ const mockedNavigate = useNavigation().navigate;
70
+ mock.onGet(API.SHARE.UNIT_PERMISSIONS_v2(1)).reply(200, listDevices);
125
71
  await act(async () => {
126
72
  tree = await create(wrapComponent(route));
127
73
  });
128
- let instance = tree.root;
129
- await clickNameEndDevice(instance, 0); // click to select all configs in end device index 0
130
- await clickNameEndDevice(instance, 0); // click again to remove all configs, and coverage expand end device
131
- await clickCheckBoxConfig(instance, 3, false); // click to select action
132
- await clickCheckBoxConfig(instance, 3, true); // click again to coverage case status reversal
133
- await clickCheckBoxConfig(instance, 4, false); // click to select config
134
- await clickCheckBoxConfig(instance, 4, true); // click again to coverage case status reversal
135
- await clickExpandEndDevice(instance, 0, 'up');
136
- await clickExpandEndDevice(instance, 0, 'down'); // click again to coverage case status reversal
137
74
 
138
- await clickCheckBoxAllDevice(instance, false); // click to select all device
139
- await clickCheckBoxSubUnit(instance, true); // click to remove all device in sub unit id 1
140
- await clickNameEndDevice(instance, 1); // click to select all configs in end device index 1
141
- await clickNameEndDevice(instance, 2); // click to select all configs in end device index 2
75
+ const instance = tree.root;
76
+ expect(instance.findAllByType(ShareDeviceSelector)).toHaveLength(1);
77
+ expect(instance.findAllByType(ViewButtonBottom)).toHaveLength(1);
78
+ await clickChooseDevice(instance, 1, true);
142
79
 
143
- const ViewButtonBottomElement = instance.findAllByType(ViewButtonBottom);
80
+ const viewButtonBottom = instance.findByType(ViewButtonBottom);
144
81
  await act(async () => {
145
- ViewButtonBottomElement[0].props.onRightClick();
82
+ viewButtonBottom.props.onRightClick();
146
83
  });
147
- expect(global.mockedNavigate).toBeCalledWith(Routes.SharingInviteMembers, {
148
- unit: { id: 1, name: 'unit 1' },
84
+ expect(viewButtonBottom.props.rightTitle).toEqual('Next');
85
+ expect(mockedNavigate).toHaveBeenCalledWith(Routes.SharingInviteMembers, {
86
+ unit: route.params.unit,
149
87
  permissions: {
150
- read_permissions: [
151
- { id: 5, values: [7] },
152
- { id: 8, values: [] },
153
- ],
154
- control_permissions: [{ id: 5, values: [6] }],
88
+ read_permissions: [{ id: 1, values: [1] }],
89
+ control_permissions: [{ id: 1, values: [1] }],
155
90
  },
156
91
  });
157
92
  });
158
-
159
- it('test no data, api get UNIT_PERMISSIONS false', async () => {
160
- mock.onGet(API.SHARE.UNIT_PERMISSIONS(1)).reply(400);
161
-
162
- await act(async () => {
163
- tree = await create(wrapComponent(route));
164
- });
165
- const instance = tree.root;
166
-
167
- let text = instance.find(
168
- (el) =>
169
- el.props.accessibilityLabel === AccessibilityLabel.TEXT_NO_DATA_STATIONS
170
- );
171
- expect(text.props.children).toEqual('No data');
172
- });
173
-
174
- it('user not choose device click button back', async () => {
175
- await act(async () => {
176
- tree = await create(wrapComponent(route));
177
- });
178
- const instance = tree.root;
179
- const ViewButtonBottomElement = instance.findAllByType(ViewButtonBottom);
180
- expect(ViewButtonBottomElement).toHaveLength(1);
181
-
182
- await act(async () => {
183
- ViewButtonBottomElement[0].props.onLeftClick();
184
- });
185
- expect(global.mockedGoBack).toBeCalled();
186
- });
187
-
188
- it('user not choose device click button next', async () => {
189
- await act(async () => {
190
- tree = await create(wrapComponent(route));
191
- });
192
- const instance = tree.root;
193
- const ViewButtonBottomElement = instance.findAllByType(ViewButtonBottom);
194
- expect(ViewButtonBottomElement).toHaveLength(1);
195
- await act(async () => {
196
- ViewButtonBottomElement[0].props.onRightClick();
197
- });
198
- expect(Alert.alert.mock.calls[0][1]).toEqual(
199
- 'Please choose at least one sensor.'
200
- );
201
- });
202
93
  });
@@ -1,18 +1,18 @@
1
- import React from 'react';
2
- import { create, act } from 'react-test-renderer';
3
- import MockAdapter from 'axios-mock-adapter';
1
+ import { Button, ViewButtonBottom } from '../../../commons';
2
+ import { act, create } from 'react-test-renderer';
4
3
 
5
- import { ViewButtonBottom, Button } from '../../../commons';
6
- import _TextInput from '../../../commons/Form/TextInput';
7
- import AccountList from '../../../commons/Auth/AccountList';
8
4
  import { API } from '../../../configs';
9
- import { getTranslate } from '../../../utils/I18n';
5
+ import AccountList from '../../../commons/Auth/AccountList';
6
+ import { IconOutline } from '@ant-design/icons-react-native';
7
+ import MockAdapter from 'axios-mock-adapter';
8
+ import React from 'react';
10
9
  import { SCProvider } from '../../../context';
11
- import { mockSCStore } from '../../../context/mockStore';
12
- import api from '../../../utils/Apis/axios';
13
10
  import SharingInviteMembers from '../SelectUser';
14
11
  import { ToastBottomHelper } from '../../../utils/Utils';
15
- import { IconOutline } from '@ant-design/icons-react-native';
12
+ import _TextInput from '../../../commons/Form/TextInput';
13
+ import api from '../../../utils/Apis/axios';
14
+ import { getTranslate } from '../../../utils/I18n';
15
+ import { mockSCStore } from '../../../context/mockStore';
16
16
 
17
17
  const wrapComponent = (route) => (
18
18
  <SCProvider initState={mockSCStore({})}>
@@ -27,6 +27,7 @@ describe('test SharingInviteMembers container', () => {
27
27
  let route;
28
28
 
29
29
  beforeEach(() => {
30
+ mock.resetHistory();
30
31
  route = {
31
32
  params: {
32
33
  unit: {
@@ -67,6 +68,30 @@ describe('test SharingInviteMembers container', () => {
67
68
  expect(viewButtonBottom.props.rightDisabled).toBeTruthy();
68
69
  });
69
70
 
71
+ it('search user by phone api response error', async () => {
72
+ const spyToast = jest.spyOn(ToastBottomHelper, 'error');
73
+ const phone = '0909123456';
74
+ mock.onGet(API.SHARE.SEARCH_USER_BY_PHONE(phone)).reply(400);
75
+ await act(async () => {
76
+ tree = await create(wrapComponent(route));
77
+ });
78
+ const instance = tree.root;
79
+
80
+ const textInput = instance.findByType(_TextInput);
81
+ const button = instance.findByType(Button);
82
+
83
+ expect(textInput.props.errorText).toEqual('');
84
+ await act(async () => {
85
+ textInput.props.onChange(phone);
86
+ });
87
+ await act(async () => {
88
+ button.props.onPress();
89
+ });
90
+ let accountList = instance.findAllByType(AccountList);
91
+ expect(accountList).toHaveLength(0);
92
+ expect(spyToast).toBeCalledWith('Not found');
93
+ });
94
+
70
95
  it('input phone valid and call api share permission', async () => {
71
96
  const phone = '0909123456';
72
97
  const spyToast = jest.spyOn(ToastBottomHelper, 'success');
@@ -104,6 +129,43 @@ describe('test SharingInviteMembers container', () => {
104
129
  expect(spyToast).toBeCalledWith('Invited user');
105
130
  });
106
131
 
132
+ it('input phone valid and call api share permission error', async () => {
133
+ const phone = '0909123456';
134
+ const spyToast = jest.spyOn(ToastBottomHelper, 'success');
135
+ spyToast.mockClear();
136
+ mock.onGet(API.SHARE.SEARCH_USER_BY_PHONE(phone)).reply(200, {
137
+ id: 3,
138
+ name: 'user add',
139
+ phone_number: phone,
140
+ });
141
+
142
+ mock.onPost(API.SHARE.SHARE_V2()).reply(400);
143
+ await act(async () => {
144
+ tree = await create(wrapComponent(route));
145
+ });
146
+ const instance = tree.root;
147
+ const textInput = instance.findByType(_TextInput);
148
+ const buttonCheckUser = instance.findByType(Button);
149
+ let accountList = instance.findAllByType(AccountList);
150
+ expect(accountList).toHaveLength(0);
151
+ await act(async () => {
152
+ await textInput.props.onChange(phone);
153
+ });
154
+ await act(async () => {
155
+ await buttonCheckUser.props.onPress();
156
+ });
157
+
158
+ accountList = instance.findAllByType(AccountList);
159
+ expect(accountList).toHaveLength(1);
160
+ expect(accountList[0].props.accounts).toHaveLength(1);
161
+
162
+ const viewButtonBottom = instance.findByType(ViewButtonBottom);
163
+ await act(async () => {
164
+ viewButtonBottom.props.onRightClick();
165
+ });
166
+ expect(spyToast).not.toHaveBeenCalled();
167
+ });
168
+
107
169
  it('input 2 email valid and remove 1 email then call api share permission', async () => {
108
170
  const email_1 = 'test1@gmail.com';
109
171
  const email_2 = 'test2@gmail.com';
@@ -1,15 +1,17 @@
1
- import { act } from '@testing-library/react-hooks';
1
+ import API from '../../../configs/API';
2
+ import AccessibilityLabel from '../../../configs/AccessibilityLabel';
3
+ import { Alert } from 'react-native';
4
+ import { IconOutline } from '@ant-design/icons-react-native';
2
5
  import MockAdapter from 'axios-mock-adapter';
3
6
  import React from 'react';
4
- import { Alert } from 'react-native';
5
- import { create } from 'react-test-renderer';
6
- import { ViewButtonBottom } from '../../../commons';
7
- import AccessibilityLabel from '../../../configs/AccessibilityLabel';
8
- import API from '../../../configs/API';
9
7
  import { SCProvider } from '../../../context';
10
- import { mockSCStore } from '../../../context/mockStore';
11
- import api from '../../../utils/Apis/axios';
8
+ import { ShareDeviceSelector } from '../Components';
12
9
  import UpdateShareDevice from '../UpdateShareDevice';
10
+ import { ViewButtonBottom } from '../../../commons';
11
+ import { act } from '@testing-library/react-hooks';
12
+ import api from '../../../utils/Apis/axios';
13
+ import { create } from 'react-test-renderer';
14
+ import { mockSCStore } from '../../../context/mockStore';
13
15
 
14
16
  const mock = new MockAdapter(api.axiosInstance);
15
17
  jest.spyOn(Alert, 'alert').mockImplementation(() => {});
@@ -39,256 +41,94 @@ describe('Test UpdateShareDevice', () => {
39
41
  name: 'Sub unit',
40
42
  devices: [
41
43
  {
42
- id: 2,
43
- actions: [{ id: 3, name: 'action 1' }],
44
- read_configs: [{ id: 4, name: 'config 1' }],
44
+ id: 1,
45
+ actions: [{ id: 1, name: 'action 1' }],
46
+ read_configs: [{ id: 1, name: 'config 1' }],
45
47
  name: 'child1',
46
48
  },
47
49
  {
48
- id: 5,
49
- actions: [{ id: 6, name: 'action 2' }],
50
- read_configs: [{ id: 7, name: 'config 2' }],
50
+ id: 2,
51
+ actions: [{ id: 2, name: 'action 2' }],
52
+ read_configs: [{ id: 2, name: 'config 2' }],
51
53
  name: 'child2',
52
54
  },
53
- {
54
- id: 8,
55
- actions: [],
56
- read_configs: [],
57
- name: 'child3',
58
- },
59
55
  ],
60
56
  },
61
57
  ];
62
58
 
63
59
  afterEach(() => {
64
- Alert.alert.mockReset();
65
60
  mock.resetHistory();
66
61
  });
67
62
 
68
- const clickCheckBoxAllDevice = async (instance, statusCheckbox) => {
69
- const checkBoxAllDevice = instance.find(
63
+ const clickChooseDevice = async (instance, deviceId, status) => {
64
+ const chooseDevice = instance.find(
70
65
  (el) =>
71
66
  el.props.accessibilityLabel ===
72
- `${AccessibilityLabel.CHECK_BOX_CUSTOM}-undefined`
67
+ `${AccessibilityLabel.SHARE_DEVICE.NAME_END_DEVICE}-device-${deviceId}`
73
68
  );
74
- expect(checkBoxAllDevice.props.isChecked).toEqual(statusCheckbox);
75
69
  await act(async () => {
76
- await checkBoxAllDevice.props.onPress();
70
+ chooseDevice.props.onPress();
77
71
  });
78
- };
79
-
80
- const clickCheckBoxSubUnit = async (instance, statusCheckbox) => {
81
- const checkBoxSubunit = instance.find(
72
+ const iconCheck = instance.findAll(
82
73
  (el) =>
83
74
  el.props.accessibilityLabel ===
84
- `${AccessibilityLabel.CHECK_BOX_CUSTOM}-0`
75
+ `${AccessibilityLabel.SHARE_DEVICE.ICON_CHECK}-device-${deviceId}` &&
76
+ el.type === IconOutline
85
77
  );
86
- expect(checkBoxSubunit.props.isChecked).toEqual(statusCheckbox);
87
- await act(async () => {
88
- await checkBoxSubunit.props.onPress();
89
- });
78
+ expect(iconCheck).toHaveLength(status ? 1 : 0);
90
79
  };
91
-
92
- const clickCheckBoxConfig = async (instance, configId, statusCheckbox) => {
93
- let checkBoxConfig = instance.find(
94
- (el) =>
95
- el.props.accessibilityLabel ===
96
- `${AccessibilityLabel.SHARE_DEVICE.CHECK_BOX_CONFIG}-${configId}`
97
- );
98
- expect(checkBoxConfig.props.isChecked).toEqual(statusCheckbox);
99
- await act(async () => {
100
- await checkBoxConfig.props.onPress();
101
- });
102
- };
103
-
104
- const clickExpandEndDevice = async (instance, indexEndDevice, statusIcon) => {
105
- const expandEndDevice = instance.find(
106
- (el) =>
107
- el.props.accessibilityLabel ===
108
- `${AccessibilityLabel.SHARE_DEVICE.EXPAND_END_DEVICE}-${indexEndDevice}`
109
- );
110
- expect(expandEndDevice.props.name).toEqual(statusIcon);
111
- await act(async () => {
112
- await expandEndDevice.props.onPress();
113
- });
114
- };
115
-
116
- const clickNameEndDevice = async (instance, indexEndDevice) => {
117
- const nameEndDevice = instance.find(
118
- (el) =>
119
- el.props.accessibilityLabel ===
120
- `${AccessibilityLabel.SHARE_DEVICE.CLICK_NAME_END_DEVICE}-${indexEndDevice}`
121
- );
122
- await act(async () => {
123
- await nameEndDevice.props.onPress();
124
- });
125
- };
126
-
127
80
  it('test user update share device by phone', async () => {
128
- mock.onGet(API.SHARE.UNIT_PERMISSIONS(1)).reply(200, listDevices);
129
- mock.onGet(API.SHARE.UNIT_MEMBER_SHARE_DEVICE(1, 1)).reply(200, []);
130
- mock.onPost(API.SHARE.SHARE()).reply(200);
81
+ mock.onGet(API.SHARE.UNIT_PERMISSIONS_v2(1)).reply(200, listDevices);
82
+ mock.onGet(API.SHARE.UNIT_MEMBER_SHARE_DEVICE_V2(1, 1)).reply(200, [
83
+ {
84
+ id: 1,
85
+ devices: [{ id: 2, read_configs: [{ id: 2 }], actions: [{ id: 2 }] }],
86
+ },
87
+ ]);
88
+ mock.onPost(API.SHARE.SHARE_V2()).reply(200);
131
89
 
132
90
  await act(async () => {
133
91
  tree = await create(wrapComponent(route));
134
92
  });
135
93
  let instance = tree.root;
136
- await clickNameEndDevice(instance, 0); // click to select all configs in end device index 0
137
- await clickNameEndDevice(instance, 0); // click again to remove all configs, and coverage expand end device
138
- await clickCheckBoxConfig(instance, 3, false); // click to select action
139
- await clickCheckBoxConfig(instance, 3, true); // click again to coverage case status reversal
140
- await clickCheckBoxConfig(instance, 4, false); // click to select config
141
- await clickCheckBoxConfig(instance, 4, true); // click again to coverage case status reversal
142
- await clickExpandEndDevice(instance, 0, 'up');
143
- await clickExpandEndDevice(instance, 0, 'down'); // click again to coverage case status reversal
144
-
145
- await clickCheckBoxAllDevice(instance, false); // click to select all device
146
- await clickCheckBoxSubUnit(instance, true); // click to remove all device in sub unit id 1
147
- await clickNameEndDevice(instance, 1); // click to select all configs in end device index 1
148
- await clickNameEndDevice(instance, 2); // click to select all configs in end device index 2
94
+ await clickChooseDevice(instance, 1, true);
149
95
 
150
- const ViewButtonBottomElement = instance.findAllByType(ViewButtonBottom);
96
+ const viewButtonBottom = instance.findByType(ViewButtonBottom);
151
97
  await act(async () => {
152
- ViewButtonBottomElement[0].props.onRightClick();
98
+ viewButtonBottom.props.onRightClick();
153
99
  });
100
+ expect(viewButtonBottom.props.rightTitle).toEqual('Done');
154
101
  expect(global.mockedGoBack).toHaveBeenCalled();
155
102
  expect(mock.history.post[0].data).toEqual(
156
103
  JSON.stringify({
157
- phone: '0901234567',
158
- email: '',
104
+ user_ids: [1],
159
105
  unit: 1,
160
106
  permissions: {
161
107
  read_permissions: [
162
- { id: 5, values: [7] },
163
- { id: 8, values: [] },
108
+ { id: 1, values: [1] },
109
+ { id: 2, values: [2] },
110
+ ],
111
+ control_permissions: [
112
+ { id: 1, values: [1] },
113
+ { id: 2, values: [2] },
164
114
  ],
165
- control_permissions: [{ id: 5, values: [6] }],
166
- },
167
- is_remove_old_permission: true,
168
- })
169
- );
170
- });
171
-
172
- it('test user update share device by email', async () => {
173
- mock.onGet(API.SHARE.UNIT_PERMISSIONS(1)).reply(200, listDevices);
174
- mock.onGet(API.SHARE.UNIT_MEMBER_SHARE_DEVICE(1, 1)).reply(200, []);
175
- mock.onPost(API.SHARE.SHARE()).reply(200);
176
-
177
- route.params.member.phone_number = '';
178
- await act(async () => {
179
- tree = await create(wrapComponent(route));
180
- });
181
- const instance = tree.root;
182
- await clickNameEndDevice(instance, 0); // click to select all configs in end device index 0
183
- const ViewButtonBottomElement = instance.findAllByType(ViewButtonBottom);
184
- expect(ViewButtonBottomElement).toHaveLength(1);
185
- await act(async () => {
186
- ViewButtonBottomElement[0].props.onRightClick();
187
- });
188
- expect(global.mockedGoBack).toHaveBeenCalled();
189
- expect(mock.history.post[0].data).toEqual(
190
- JSON.stringify({
191
- phone: '',
192
- email: 'email@gmail.com',
193
- unit: 1,
194
- permissions: {
195
- read_permissions: [{ id: 2, values: [4] }],
196
- control_permissions: [{ id: 2, values: [3] }],
197
- },
198
- is_remove_old_permission: true,
199
- })
200
- );
201
- });
202
-
203
- it('test user update share device not have phone and email', async () => {
204
- mock.onGet(API.SHARE.UNIT_PERMISSIONS(1)).reply(200, listDevices);
205
- mock.onGet(API.SHARE.UNIT_MEMBER_SHARE_DEVICE(1, 1)).reply(200, []);
206
- mock.onPost(API.SHARE.SHARE()).reply(400);
207
-
208
- route.params.member.phone_number = '';
209
- route.params.member.email = '';
210
- await act(async () => {
211
- tree = await create(wrapComponent(route));
212
- });
213
- const instance = tree.root;
214
- await clickNameEndDevice(instance, 0); // click to select all configs in end device index 0
215
- const ViewButtonBottomElement = instance.findAllByType(ViewButtonBottom);
216
- expect(ViewButtonBottomElement).toHaveLength(1);
217
- await act(async () => {
218
- ViewButtonBottomElement[0].props.onRightClick();
219
- });
220
- expect(global.mockedGoBack).not.toHaveBeenCalled();
221
- expect(mock.history.post[0].data).toEqual(
222
- JSON.stringify({
223
- phone: '',
224
- email: '',
225
- unit: 1,
226
- permissions: {
227
- read_permissions: [{ id: 2, values: [4] }],
228
- control_permissions: [{ id: 2, values: [3] }],
229
115
  },
230
116
  is_remove_old_permission: true,
231
117
  })
232
118
  );
233
119
  });
234
120
 
235
- it('test no data, api get UNIT_PERMISSIONS false', async () => {
236
- mock.onGet(API.SHARE.UNIT_PERMISSIONS(1)).reply(400);
237
-
238
- await act(async () => {
239
- tree = await create(wrapComponent(route));
240
- });
241
- const instance = tree.root;
242
-
243
- let text = instance.find(
244
- (el) =>
245
- el.props.accessibilityLabel === AccessibilityLabel.TEXT_NO_DATA_STATIONS
246
- );
247
- expect(text.props.children).toEqual('No data');
248
- });
249
-
250
- it('test api get UNIT_MEMBER_SHARE_DEVICE false', async () => {
251
- mock.onGet(API.SHARE.UNIT_PERMISSIONS(1)).reply(200, listDevices);
252
- mock.onGet(API.SHARE.UNIT_MEMBER_SHARE_DEVICE(1, 1)).reply(400);
121
+ it('test user update share device get unit member share device error', async () => {
122
+ mock.onGet(API.SHARE.UNIT_PERMISSIONS_v2(1)).reply(200, listDevices);
123
+ mock.onGet(API.SHARE.UNIT_MEMBER_SHARE_DEVICE_V2(1, 1)).reply(400);
124
+ mock.onPost(API.SHARE.SHARE_V2()).reply(200);
253
125
 
254
126
  await act(async () => {
255
127
  tree = await create(wrapComponent(route));
256
128
  });
257
129
  const instance = tree.root;
258
130
 
259
- let text = instance.findAll(
260
- (el) =>
261
- el.props.accessibilityLabel === AccessibilityLabel.TEXT_NO_DATA_STATIONS
262
- );
263
- expect(text).toEqual([]);
264
- });
265
-
266
- it('user not choose device click button back', async () => {
267
- await act(async () => {
268
- tree = await create(wrapComponent(route));
269
- });
270
- const instance = tree.root;
271
- const ViewButtonBottomElement = instance.findAllByType(ViewButtonBottom);
272
- expect(ViewButtonBottomElement).toHaveLength(1);
273
-
274
- await act(async () => {
275
- ViewButtonBottomElement[0].props.onLeftClick();
276
- });
277
- expect(global.mockedGoBack).toHaveBeenCalled();
278
- });
279
-
280
- it('user not choose device click button next', async () => {
281
- await act(async () => {
282
- tree = await create(wrapComponent(route));
283
- });
284
- const instance = tree.root;
285
- const ViewButtonBottomElement = instance.findAllByType(ViewButtonBottom);
286
- expect(ViewButtonBottomElement).toHaveLength(1);
287
- await act(async () => {
288
- ViewButtonBottomElement[0].props.onRightClick();
289
- });
290
- expect(Alert.alert.mock.calls[0][1]).toEqual(
291
- 'Please choose at least one sensor.'
292
- );
131
+ const shareDeviceSelector = instance.findByType(ShareDeviceSelector);
132
+ expect(shareDeviceSelector.props.initialSelectedKeys).toEqual([]);
293
133
  });
294
134
  });