@eohjsc/react-native-smart-city 0.5.1 → 0.5.2-rc
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.
- package/package.json +1 -1
- package/src/commons/ActionGroup/OnOffTemplate/OnOffSimpleTemplateStyle.js +1 -0
- package/src/commons/ActionGroup/SliderRangeTemplate.js +10 -3
- package/src/commons/ActionGroup/__test__/SliderRangeTemplate.test.js +4 -0
- package/src/commons/ProcessingBar/index.js +32 -0
- package/src/commons/ProcessingBar/styles.js +57 -0
- package/src/configs/AccessibilityLabel.js +8 -0
- package/src/navigations/AddMemberStack.js +8 -3
- package/src/screens/AddCommon/SelectUnit.js +1 -1
- package/src/screens/AddCommon/__test__/SelectUnit.test.js +1 -1
- package/src/screens/EnterPassword/index.js +3 -2
- package/src/screens/Sharing/Components/CheckBoxConfig.js +44 -0
- package/src/screens/Sharing/Components/CheckBoxCustom.js +2 -13
- package/src/screens/Sharing/Components/CheckBoxSubUnit.js +35 -0
- package/src/screens/Sharing/Components/EndDevice.js +93 -0
- package/src/screens/Sharing/Components/Styles/CheckBoxConfigStyles.js +18 -0
- package/src/screens/Sharing/Components/Styles/DeviceItemStyles.js +28 -35
- package/src/screens/Sharing/Components/index.js +1 -2
- package/src/screens/Sharing/InfoMemberUnit.js +5 -3
- package/src/screens/Sharing/SelectShareDevice.js +273 -0
- package/src/screens/Sharing/SelectUser.js +6 -0
- package/src/screens/Sharing/Styles/SelectPermissionStyles.js +2 -11
- package/src/screens/Sharing/UnitMemberList.js +2 -1
- package/src/screens/Sharing/UpdateShareDevice.js +322 -0
- package/src/screens/Sharing/__test__/SelectShareDevice.test.js +215 -0
- package/src/screens/Sharing/__test__/UnitMemberList.test.js +1 -1
- package/src/screens/Sharing/__test__/UpdateShareDevice.test.js +307 -0
- package/src/screens/Sharing/hooks/index.js +5 -0
- package/src/screens/SubUnit/AddSubUnit.js +2 -6
- package/src/screens/SubUnit/EditSubUnitStyles.js +2 -1
- package/src/screens/Unit/AddMenu.js +1 -1
- package/src/utils/Route/index.js +2 -1
- package/src/screens/Sharing/Components/DeviceItem.js +0 -146
- package/src/screens/Sharing/Components/__test__/DeviceItem.test.js +0 -48
- package/src/screens/Sharing/SharingSelectPermission.js +0 -409
- package/src/screens/Sharing/__test__/SharingSelectPermission.test.js +0 -292
|
@@ -1,292 +0,0 @@
|
|
|
1
|
-
import { act } from '@testing-library/react-hooks';
|
|
2
|
-
import React, { useState } from 'react';
|
|
3
|
-
import { FlatList, Text, Platform } from 'react-native';
|
|
4
|
-
import { create } from 'react-test-renderer';
|
|
5
|
-
import MockAdapter from 'axios-mock-adapter';
|
|
6
|
-
import { DeviceItem, TitleCheckBox } from '../Components';
|
|
7
|
-
import { ViewButtonBottom } from '../../../commons';
|
|
8
|
-
import { SCProvider } from '../../../context';
|
|
9
|
-
import { mockSCStore } from '../../../context/mockStore';
|
|
10
|
-
import API from '../../../configs/API';
|
|
11
|
-
import api from '../../../utils/Apis/axios';
|
|
12
|
-
import SharingSelectPermission from '../SharingSelectPermission';
|
|
13
|
-
|
|
14
|
-
const mock = new MockAdapter(api.axiosInstance);
|
|
15
|
-
|
|
16
|
-
const mockSetState = jest.fn();
|
|
17
|
-
jest.mock('react', () => {
|
|
18
|
-
return {
|
|
19
|
-
...jest.requireActual('react'),
|
|
20
|
-
useState: jest.fn((init) => [init, mockSetState]),
|
|
21
|
-
memo: (x) => x,
|
|
22
|
-
};
|
|
23
|
-
});
|
|
24
|
-
|
|
25
|
-
const mockNavigate = jest.fn();
|
|
26
|
-
const mockGoBack = jest.fn();
|
|
27
|
-
jest.mock('@react-navigation/native', () => {
|
|
28
|
-
return {
|
|
29
|
-
...jest.requireActual('@react-navigation/native'),
|
|
30
|
-
useNavigation: () => ({
|
|
31
|
-
navigate: mockNavigate,
|
|
32
|
-
goBack: mockGoBack,
|
|
33
|
-
}),
|
|
34
|
-
};
|
|
35
|
-
});
|
|
36
|
-
|
|
37
|
-
const wrapComponent = (route) => (
|
|
38
|
-
<SCProvider initState={mockSCStore({})}>
|
|
39
|
-
<SharingSelectPermission route={route} />
|
|
40
|
-
</SCProvider>
|
|
41
|
-
);
|
|
42
|
-
|
|
43
|
-
describe('Test SharingSelectPermission', () => {
|
|
44
|
-
let tree;
|
|
45
|
-
let route = { params: { unit: { id: 1, name: 'unit 1' } } };
|
|
46
|
-
let listDevices = [
|
|
47
|
-
{
|
|
48
|
-
id: 204,
|
|
49
|
-
name: 'device',
|
|
50
|
-
devices: [
|
|
51
|
-
{
|
|
52
|
-
id: 123,
|
|
53
|
-
actions: [{ id: 136, name: 'action 1' }],
|
|
54
|
-
read_configs: [{ id: 137, name: 'config 1' }],
|
|
55
|
-
name: 'child1',
|
|
56
|
-
},
|
|
57
|
-
],
|
|
58
|
-
},
|
|
59
|
-
];
|
|
60
|
-
|
|
61
|
-
const mockSetTickAllDevice = jest.fn();
|
|
62
|
-
const mockSetActiveItemId = jest.fn();
|
|
63
|
-
const mockSetDataStations = jest.fn();
|
|
64
|
-
|
|
65
|
-
afterEach(() => {
|
|
66
|
-
mockSetState.mockClear();
|
|
67
|
-
mockSetTickAllDevice.mockClear();
|
|
68
|
-
mockSetActiveItemId.mockClear();
|
|
69
|
-
mockSetDataStations.mockClear();
|
|
70
|
-
});
|
|
71
|
-
|
|
72
|
-
function mockLoading() {
|
|
73
|
-
useState.mockImplementationOnce((init) => [init, mockSetState]);
|
|
74
|
-
useState.mockImplementationOnce((init) => [init, mockSetState]);
|
|
75
|
-
useState.mockImplementationOnce((init) => [init, mockSetState]);
|
|
76
|
-
useState.mockImplementationOnce((init) => [false, mockSetState]); // loading
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
function mocSetdata() {
|
|
80
|
-
useState.mockImplementationOnce((init) => [
|
|
81
|
-
listDevices,
|
|
82
|
-
mockSetDataStations,
|
|
83
|
-
]);
|
|
84
|
-
useState.mockImplementationOnce((init) => [init, mockSetTickAllDevice]);
|
|
85
|
-
useState.mockImplementationOnce((init) => [init, mockSetActiveItemId]);
|
|
86
|
-
useState.mockImplementationOnce((init) => [false, mockSetState]); // loading
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
it('test unit null', async () => {
|
|
90
|
-
Platform.OS = 'android';
|
|
91
|
-
await act(async () => {
|
|
92
|
-
tree = await create(wrapComponent(route));
|
|
93
|
-
});
|
|
94
|
-
const instance = tree.root;
|
|
95
|
-
const ViewButtonBottoms = instance.findAllByType(ViewButtonBottom);
|
|
96
|
-
expect(ViewButtonBottoms).toHaveLength(1);
|
|
97
|
-
});
|
|
98
|
-
|
|
99
|
-
it('render empty list', async () => {
|
|
100
|
-
mockLoading();
|
|
101
|
-
Platform.OS = 'ios';
|
|
102
|
-
route.params.unit = 1;
|
|
103
|
-
mock.onGet(API.SHARE.UNIT_MEMBER_SHARE_DEVICE(1, 1)).reply(200);
|
|
104
|
-
await act(async () => {
|
|
105
|
-
tree = await create(wrapComponent(route));
|
|
106
|
-
});
|
|
107
|
-
const instance = tree.root;
|
|
108
|
-
const TextElement = instance.findAllByType(Text);
|
|
109
|
-
expect(TextElement[2].props.children).toBe('No data');
|
|
110
|
-
});
|
|
111
|
-
|
|
112
|
-
it('test unit get permission default', async () => {
|
|
113
|
-
mocSetdata();
|
|
114
|
-
const routes = { params: { unit: { id: 1, name: '123' } } };
|
|
115
|
-
mock.onGet(API.SHARE.UNIT_PERMISSIONS(1)).reply(200);
|
|
116
|
-
await act(async () => {
|
|
117
|
-
tree = await create(wrapComponent(routes));
|
|
118
|
-
});
|
|
119
|
-
const instance = tree.root;
|
|
120
|
-
const FlatListElement = instance.findAllByType(FlatList);
|
|
121
|
-
expect(FlatListElement).toHaveLength(1);
|
|
122
|
-
});
|
|
123
|
-
|
|
124
|
-
it('test unit fail default', async () => {
|
|
125
|
-
mockLoading();
|
|
126
|
-
const routes = { params: { unit: null } };
|
|
127
|
-
mock.onGet(API.SHARE.UNIT_PERMISSIONS(1)).reply(400);
|
|
128
|
-
await act(async () => {
|
|
129
|
-
tree = await create(wrapComponent(routes));
|
|
130
|
-
});
|
|
131
|
-
const instance = tree.root;
|
|
132
|
-
const TextElement = instance.findAllByType(Text);
|
|
133
|
-
expect(TextElement[2].props.children).toBe('No data');
|
|
134
|
-
});
|
|
135
|
-
|
|
136
|
-
it('test get unit fail shared', async () => {
|
|
137
|
-
mockLoading();
|
|
138
|
-
route.params.unit = 1;
|
|
139
|
-
mock.onGet(API.SHARE.UNIT_MEMBER_SHARE_DEVICE(1, 1)).reply(400);
|
|
140
|
-
await act(async () => {
|
|
141
|
-
tree = await create(wrapComponent(route));
|
|
142
|
-
});
|
|
143
|
-
const instance = tree.root;
|
|
144
|
-
const TextElement = instance.findAllByType(Text);
|
|
145
|
-
expect(TextElement[2].props.children).toBe('No data');
|
|
146
|
-
});
|
|
147
|
-
|
|
148
|
-
it('render list', async () => {
|
|
149
|
-
mocSetdata();
|
|
150
|
-
await act(async () => {
|
|
151
|
-
tree = await create(wrapComponent(route));
|
|
152
|
-
});
|
|
153
|
-
const instance = tree.root;
|
|
154
|
-
const FlatListElement = instance.findAllByType(FlatList);
|
|
155
|
-
expect(FlatListElement).toHaveLength(1);
|
|
156
|
-
const TitleCheckBoxElement = instance.findAllByType(TitleCheckBox);
|
|
157
|
-
expect(TitleCheckBoxElement).toHaveLength(2);
|
|
158
|
-
await act(async () => {
|
|
159
|
-
TitleCheckBoxElement[0].props.onPress(null, true);
|
|
160
|
-
});
|
|
161
|
-
expect(mockSetTickAllDevice).toBeCalledWith(true);
|
|
162
|
-
expect(mockSetDataStations).toBeCalledWith([
|
|
163
|
-
{
|
|
164
|
-
id: 204,
|
|
165
|
-
isChecked: true,
|
|
166
|
-
name: 'device',
|
|
167
|
-
devices: [
|
|
168
|
-
{
|
|
169
|
-
actions: [{ id: 136, isChecked: true, name: 'action 1' }],
|
|
170
|
-
id: 123,
|
|
171
|
-
isChecked: true,
|
|
172
|
-
name: 'child1',
|
|
173
|
-
read_configs: [{ id: 137, isChecked: true, name: 'config 1' }],
|
|
174
|
-
},
|
|
175
|
-
],
|
|
176
|
-
},
|
|
177
|
-
]);
|
|
178
|
-
await act(async () => {
|
|
179
|
-
TitleCheckBoxElement[0].props.onPress(204, true);
|
|
180
|
-
});
|
|
181
|
-
expect(mockSetTickAllDevice).toBeCalledWith(true);
|
|
182
|
-
});
|
|
183
|
-
|
|
184
|
-
it('test onTickedChild function', async () => {
|
|
185
|
-
mocSetdata();
|
|
186
|
-
await act(async () => {
|
|
187
|
-
tree = await create(wrapComponent(route));
|
|
188
|
-
});
|
|
189
|
-
const instance = tree.root;
|
|
190
|
-
const DeviceItemElement = instance.findAllByType(DeviceItem);
|
|
191
|
-
expect(DeviceItemElement).toHaveLength(1);
|
|
192
|
-
await act(async () => {
|
|
193
|
-
DeviceItemElement[0].props.onTickedChild(204, 123, 137, true, true);
|
|
194
|
-
});
|
|
195
|
-
expect(mockSetDataStations).toBeCalled();
|
|
196
|
-
});
|
|
197
|
-
|
|
198
|
-
it('test onTickedDevice function', async () => {
|
|
199
|
-
mocSetdata();
|
|
200
|
-
await act(async () => {
|
|
201
|
-
tree = await create(wrapComponent(route));
|
|
202
|
-
});
|
|
203
|
-
const instance = tree.root;
|
|
204
|
-
const DeviceItemElement = instance.findAllByType(DeviceItem);
|
|
205
|
-
expect(DeviceItemElement).toHaveLength(1);
|
|
206
|
-
await act(async () => {
|
|
207
|
-
DeviceItemElement[0].props.onTickedDevice(204, 123, true);
|
|
208
|
-
DeviceItemElement[0].props.toggleItem(123);
|
|
209
|
-
});
|
|
210
|
-
expect(mockSetDataStations).toBeCalled();
|
|
211
|
-
});
|
|
212
|
-
|
|
213
|
-
it('test onTickedDeviceIcon function', async () => {
|
|
214
|
-
mocSetdata();
|
|
215
|
-
await act(async () => {
|
|
216
|
-
tree = await create(wrapComponent(route));
|
|
217
|
-
});
|
|
218
|
-
const instance = tree.root;
|
|
219
|
-
const DeviceItemElement = instance.findAllByType(DeviceItem);
|
|
220
|
-
expect(DeviceItemElement).toHaveLength(1);
|
|
221
|
-
await act(async () => {
|
|
222
|
-
DeviceItemElement[0].props.onTickedDeviceIcon(204, 123, true);
|
|
223
|
-
});
|
|
224
|
-
expect(mockSetDataStations).toBeCalled();
|
|
225
|
-
});
|
|
226
|
-
|
|
227
|
-
it('test ViewButtonBottom', async () => {
|
|
228
|
-
mocSetdata();
|
|
229
|
-
await act(async () => {
|
|
230
|
-
tree = await create(wrapComponent(route));
|
|
231
|
-
});
|
|
232
|
-
const instance = tree.root;
|
|
233
|
-
const ViewButtonBottomElement = instance.findAllByType(ViewButtonBottom);
|
|
234
|
-
expect(ViewButtonBottomElement).toHaveLength(1);
|
|
235
|
-
await act(async () => {
|
|
236
|
-
ViewButtonBottomElement[0].props.onRightClick();
|
|
237
|
-
});
|
|
238
|
-
await act(async () => {
|
|
239
|
-
ViewButtonBottomElement[0].props.onLeftClick();
|
|
240
|
-
});
|
|
241
|
-
expect(mockGoBack).toBeCalled();
|
|
242
|
-
});
|
|
243
|
-
|
|
244
|
-
it('test SharingSelectPermission type share_device', async () => {
|
|
245
|
-
mocSetdata();
|
|
246
|
-
useState.mockImplementationOnce((init) => [true, mockSetState]);
|
|
247
|
-
const response = {
|
|
248
|
-
status: 200,
|
|
249
|
-
data: [
|
|
250
|
-
{
|
|
251
|
-
id: 204,
|
|
252
|
-
isChecked: true,
|
|
253
|
-
name: 'device',
|
|
254
|
-
devices: [
|
|
255
|
-
{
|
|
256
|
-
actions: [{ id: 136, isChecked: true, name: 'action 1' }],
|
|
257
|
-
id: 123,
|
|
258
|
-
isChecked: true,
|
|
259
|
-
name: 'child1',
|
|
260
|
-
read_configs: [{ id: 137, isChecked: true, name: 'config 1' }],
|
|
261
|
-
},
|
|
262
|
-
],
|
|
263
|
-
},
|
|
264
|
-
],
|
|
265
|
-
};
|
|
266
|
-
mock
|
|
267
|
-
.onGet(API.SHARE.UNIT_MEMBER_SHARE_DEVICE(1, 1))
|
|
268
|
-
.reply(200, response.data);
|
|
269
|
-
const routes = {
|
|
270
|
-
params: {
|
|
271
|
-
unit: { id: 1 },
|
|
272
|
-
type: 'update_shared',
|
|
273
|
-
member: {
|
|
274
|
-
id: 1,
|
|
275
|
-
name: 'a',
|
|
276
|
-
phone_number: '89898888',
|
|
277
|
-
email: 'abcderfg@gmail.com',
|
|
278
|
-
},
|
|
279
|
-
},
|
|
280
|
-
};
|
|
281
|
-
await act(async () => {
|
|
282
|
-
tree = await create(wrapComponent(routes));
|
|
283
|
-
});
|
|
284
|
-
const instance = tree.root;
|
|
285
|
-
const ViewButtonBottomElement = instance.findAllByType(ViewButtonBottom);
|
|
286
|
-
await act(async () => {
|
|
287
|
-
ViewButtonBottomElement[0].props.onRightClick();
|
|
288
|
-
});
|
|
289
|
-
mock.onPost(API.SHARE.SHARE()).reply(200);
|
|
290
|
-
expect(mockGoBack).toBeCalled();
|
|
291
|
-
});
|
|
292
|
-
});
|