@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.
- package/README.md +1 -1
- package/assets/images/OneTap@1x.svg +14 -0
- package/index.js +0 -2
- package/package.json +11 -3
- package/src/Images/Common/arrow-back.png +0 -0
- package/src/Images/Common/checked@2x.png +0 -0
- package/src/Images/Common/checked@3x.png +0 -0
- package/src/Images/Common/file.png +0 -0
- package/src/Images/Common/fullscreen.png +0 -0
- package/src/Images/Common/refresh.png +0 -0
- package/src/commons/ActionGroup/NumberUpDownActionTemplate.js +1 -1
- package/src/commons/ActionGroup/OnOffTemplate/index.js +4 -4
- package/src/commons/ActionGroup/OptionsDropdownActionTemplate.js +1 -1
- package/src/commons/ActionGroup/StatesGridActionTemplate.js +2 -2
- package/src/commons/ActionGroup/__test__/OnOffButtonTemplate.test.js +8 -13
- package/src/commons/ActionGroup/__test__/OnOffTemplate.test.js +3 -3
- package/src/commons/ActionGroup/__test__/OptionsDropdownTemplate.test.js +26 -46
- package/src/commons/ActionGroup/__test__/ThreeButtonTemplate.test.js +11 -5
- package/src/commons/ActionGroup/__test__/TimerActionTemplate.test.js +14 -8
- package/src/commons/ActionGroup/__test__/TimerActionTemplateWithutConfigValue.test.js +17 -23
- package/src/commons/ActionGroup/__test__/__snapshots__/ThreeButtonTemplate.test.js.snap +241 -223
- package/src/commons/ActionGroup/__test__/index.test.js +39 -107
- package/src/commons/ActionTemplate/ActionTemplateStyles.js +14 -0
- package/src/commons/ActionTemplate/OnOffButtonAction.js +40 -0
- package/src/commons/ActionTemplate/OnOffButtonActionStyles.js +11 -0
- package/src/commons/ActionTemplate/OneButtonAction.js +26 -0
- package/src/commons/ActionTemplate/OneButtonActionStyles.js +11 -0
- package/src/commons/ActionTemplate/ThreeButtonAction.js +55 -0
- package/src/commons/ActionTemplate/ThreeButtonActionStyles.js +11 -0
- package/src/commons/ActionTemplate/__test__/OnOffButtonAction.test.js +34 -0
- package/src/commons/ActionTemplate/__test__/OneButtonAction.test.js +33 -0
- package/src/commons/ActionTemplate/__test__/ThreeButtonAction.test.js +35 -0
- package/src/commons/ActionTemplate/__test__/index.test.js +71 -0
- package/src/commons/ActionTemplate/index.js +69 -0
- package/src/commons/Automate/ItemAutomate.js +1 -31
- package/src/commons/Automate/ItemAutomateStyles.js +10 -7
- package/src/commons/Automate/ItemScriptAction.js +9 -5
- package/src/commons/Automate/ItemScriptActionStyles.js +4 -0
- package/src/commons/ChartLoading/__test__/ChartLoading.test.js +9 -7
- package/src/commons/Device/DeviceAlertStatus.js +3 -1
- package/src/commons/Device/Emergency/__test__/EmergencyButton.test.js +14 -6
- package/src/commons/Device/Emergency/__test__/EmergencyDetail.test.js +10 -2
- package/src/commons/Device/FlatListItems.js +1 -1
- package/src/commons/Device/ItemAddNew/index.js +6 -1
- package/src/commons/Device/WindDirection/Compass/Compass.test.js +19 -11
- package/src/commons/Device/WindSpeed/LinearChart/__test__/LinearChart.test.js +9 -3
- package/src/commons/Device/WindSpeed/LinearChart/__test__/__snapshots__/LinearChart.test.js.snap +0 -81
- package/src/commons/Device/__test__/ConnectedViewHeader.test.js +16 -8
- package/src/commons/Device/__test__/DeviceAlertStatus.test.js +13 -6
- package/src/commons/Device/__test__/DisconnectedView.test.js +13 -5
- package/src/commons/Device/__test__/FlatListItems.test.js +9 -1
- package/src/commons/Device/__test__/FooterInfo.test.js +13 -4
- package/src/commons/Device/__test__/SensorConnectedStatus.test.js +9 -1
- package/src/commons/Device/__test__/__snapshots__/DisconnectedView.test.js.snap +20 -20
- package/src/commons/DisplayChecking/__test__/DisplayChecking.test.js +28 -0
- package/src/commons/Explore/SearchBox/__test__/SearchBox.test.js +9 -2
- package/src/commons/Explore/__test__/CityItem.test.js +13 -15
- package/src/commons/Explore/__test__/HeaderLabel.test.js +15 -9
- package/src/commons/Header/HeaderCustom.js +7 -1
- package/src/commons/Header/__test__/HeaderCT.test.js +12 -4
- package/src/commons/ImagePicker/__test__/ImagePicker.test.js +19 -13
- package/src/commons/MediaPlayerDetail/__test__/MediaPlayerDetail.test.js +14 -8
- package/src/commons/MediaPlayerDetail/index.js +2 -0
- package/src/commons/MenuActionAddnew/__test__/MenuActionAddNew.test.js +11 -20
- package/src/commons/Modal/ModalBottom.js +51 -0
- package/src/commons/Modal/Styles/ModalBottomStyles.js +35 -0
- package/src/commons/Modal/index.js +2 -1
- package/src/commons/SelectActionCard/SelectActionStyles.js +16 -0
- package/src/commons/SelectActionCard/index.js +30 -0
- package/src/commons/Sharing/__test__/DevicePermissionsCheckbox.test.js +15 -9
- package/src/commons/Sharing/__test__/MemberList.test.js +17 -25
- package/src/commons/Sharing/__test__/StationDevicePermission.test.js +17 -12
- package/src/commons/Sharing/__test__/WrapHeaderScrollable.test.js +0 -9
- package/src/commons/SubUnit/OneTap/ItemOneTap.js +20 -9
- package/src/commons/SubUnit/OneTap/__test__/SubUnitAutomate.test.js +149 -0
- package/src/commons/SubUnit/OneTap/index.js +16 -6
- package/src/commons/SubUnit/ShortDetail.js +9 -5
- package/src/commons/SubUnit/__test__/ShortDetail.test.js +14 -6
- package/src/commons/Today/__test__/Today.test.js +9 -1
- package/src/commons/Today/__test__/__snapshots__/Today.test.js.snap +1 -1
- package/src/commons/UnitSummary/AirQuality/__test__/index.test.js +16 -17
- package/src/commons/UnitSummary/__test__/TotalPowerConsumption.test.js +15 -9
- package/src/configs/API.js +6 -1
- package/src/configs/Constants.js +42 -0
- package/src/context/SCContext.tsx +2 -26
- package/src/context/actionType.ts +11 -0
- package/src/context/mockStore.ts +49 -0
- package/src/context/reducer.ts +21 -0
- package/src/hooks/Common/__test__/useTranslations.test.js +23 -0
- package/src/hooks/Common/index.js +2 -0
- package/src/hooks/Common/useGetIdUser.js +9 -0
- package/src/iot/RemoteControl/__test__/Bluetooth.test.js +3 -6
- package/src/iot/RemoteControl/__test__/GoogleHome.test.js +3 -4
- package/src/iot/RemoteControl/__test__/Internet.test.js +1 -9
- package/src/iot/RemoteControl/__test__/LgThinq.test.js +7 -10
- package/src/navigations/UnitStack.js +14 -0
- package/src/screens/AQIGuide/__test__/AQIGuide.test.js +9 -1
- package/src/screens/AQIGuide/index.js +1 -1
- package/src/screens/ActivityLog/__test__/index.test.js +14 -39
- package/src/screens/AddCommon/SelectSubUnit.js +2 -2
- package/src/screens/AddCommon/__test__/SelectSubUnit.test.js +61 -0
- package/src/screens/AddCommon/__test__/SelectUnit.test.js +18 -10
- package/src/screens/AddNewAction/Device/__test__/index.test.js +42 -0
- package/src/screens/AddNewAction/SelectAction.js +152 -0
- package/src/screens/AddNewAction/SelectDevice.js +25 -11
- package/src/screens/AddNewAction/Styles/SelectActionStyles.js +24 -0
- package/src/screens/AddNewAction/__test__/SelectAction.test.js +172 -0
- package/src/screens/AddNewAction/__test__/SelectDevice.test.js +191 -0
- package/src/screens/AddNewAutoSmart/__test__/AddNewAutoSmart.test.js +55 -0
- package/src/screens/AddNewAutoSmart/index.js +85 -0
- package/src/screens/AddNewAutoSmart/styles/AddNewAutoSmartStyles.js +36 -0
- package/src/screens/AddNewDevice/__test__/AddNewDevice.test.js +29 -14
- package/src/screens/AddNewDevice/__test__/ConnectDevices.test.js +19 -8
- package/src/screens/AddNewDevice/__test__/ConnectingDevices.test.js +16 -7
- package/src/screens/AddNewGateway/__test__/AddNewGateway.test.js +35 -73
- package/src/screens/AddNewGateway/__test__/ConnectedGateway.test.js +14 -5
- package/src/screens/AddNewGateway/__test__/ConnectingGateway.test.js +20 -11
- package/src/screens/AddNewOneTap/__test__/AddNewOneTap.test.js +129 -0
- package/src/screens/AddNewOneTap/index.js +20 -7
- package/src/screens/AddNewScriptAction/AddNewScriptActionStyles.js +1 -0
- package/src/screens/AddNewScriptAction/index.js +21 -13
- package/src/screens/Device/__test__/detail.test.js +26 -19
- package/src/screens/Device/detail.js +5 -4
- package/src/screens/Device/hooks/useCountUp.js +4 -0
- package/src/screens/Device/styles.js +5 -1
- package/src/screens/DeviceInfo/__test__/index.test.js +12 -3
- package/src/screens/EditActionsList/Styles/indexStyles.js +11 -0
- package/src/screens/EditActionsList/index.js +83 -19
- package/src/screens/EmergencyContacts/__test__/EmergencyContactAddNew.test.js +15 -19
- package/src/screens/EmergencyContacts/__test__/EmergencyContactList.test.js +19 -24
- package/src/screens/EmergencyContacts/__test__/EmergencyContactsSelectContacts.test.js +10 -25
- package/src/screens/ManageAccess/__test__/ManageAccess.test.js +13 -1
- package/src/screens/ScanChipQR/__test__/ScanChipQR.test.js +2 -11
- package/src/screens/ScriptDetail/Styles/indexStyles.js +4 -1
- package/src/screens/ScriptDetail/index.js +30 -28
- package/src/screens/SharedUnit/__test__/TabHeader.test.js +40 -0
- package/src/screens/Sharing/__test__/MemberList.test.js +17 -14
- package/src/screens/Sharing/__test__/SelectPermission.test.js +16 -8
- package/src/screens/Sharing/__test__/SelectUser.test.js +33 -16
- package/src/screens/SubUnit/Detail.js +3 -3
- package/src/screens/SubUnit/ManageSubUnit.js +8 -8
- package/src/screens/SubUnit/__test__/AddSubUnit.test.js +17 -12
- package/src/screens/SubUnit/__test__/Detail.test.js +11 -31
- package/src/screens/SubUnit/__test__/ManageSubUnit.test.js +42 -32
- package/src/screens/TDSGuide/__test__/TDSGuide.test.js +9 -1
- package/src/screens/UVIndexGuide/__test__/UVIndexGuide.test.js +9 -1
- package/src/screens/Unit/Detail.js +33 -11
- package/src/screens/Unit/ManageUnit.js +1 -1
- package/src/screens/Unit/__test__/AddMenu.test.js +15 -15
- package/src/screens/Unit/__test__/CheckSendEmail.test.js +19 -10
- package/src/screens/Unit/__test__/Detail.test.js +92 -33
- package/src/screens/Unit/__test__/ManageUnit.test.js +16 -23
- package/src/screens/Unit/components/__test__/SharedUnit.test.js +11 -2
- package/src/screens/UnitSummary/__test__/index.test.js +12 -4
- package/src/screens/UnitSummary/components/3PPowerConsumption/__test__/3PPowerConsumption.test.js +13 -3
- package/src/screens/UnitSummary/components/PowerConsumption/__test__/PowerConsumption.test.js +16 -12
- package/src/screens/UnitSummary/components/RunningDevices/__test__/index.test.js +2 -2
- package/src/screens/UnitSummary/components/UvIndex/__test__/__snapshots__/index.test.js.snap +37 -37
- package/src/screens/UnitSummary/components/UvIndex/__test__/index.test.js +14 -6
- package/src/screens/UnitSummary/components/WaterQuality/__test__/index.test.js +11 -5
- package/src/screens/UnitSummary/components/__test__/TotalPowerConsumption.test.js +13 -7
- package/src/screens/WaterQualityGuide/__test__/index.test.js +12 -12
- package/src/utils/I18n/translations/en.json +9 -2
- package/src/utils/I18n/translations/vi.json +10 -3
- package/src/utils/Route/index.js +3 -2
- package/assets/images/Event.svg +0 -9
- package/src/commons/ChartLoading/__test__/__snapshots__/ChartLoading.test.js.snap +0 -66
- package/src/commons/Device/HistoryChart/__test__/HistoryChart.test.js +0 -57
- package/src/commons/Device/HistoryChart/__test__/__snapshots__/HistoryChart.test.js.snap +0 -593
- package/src/commons/Explore/SearchBox/__test__/__snapshots__/SearchBox.test.js.snap +0 -59
- package/src/commons/Explore/__test__/HeaderExplore.test.js +0 -21
- package/src/commons/Header/__test__/Header.test.js +0 -24
- package/src/commons/MenuActionAddnew/__test__/__snapshots__/MenuActionAddNew.test.js.snap +0 -788
- package/src/commons/Sharing/__test__/__snapshots__/WrapHeaderScrollable.test.js.snap +0 -174
- package/src/commons/UnitSummary/AirQuality/__test__/__snapshots__/index.test.js.snap +0 -26679
- package/src/iot/RemoteControl/__test__/index.test.js +0 -102
- package/src/iot/__test__/Monitor.test.js +0 -119
- package/src/navigations/AddNewActionStack.js +0 -23
- package/src/screens/EmergencyContacts/__test__/__snapshots__/EmergencyContactAddNew.test.js.snap +0 -1706
- package/src/screens/EmergencyContacts/__test__/__snapshots__/EmergencyContactList.test.js.snap +0 -4276
- package/src/screens/EmergencyContacts/__test__/__snapshots__/EmergencyContactsSelectContacts.test.js.snap +0 -2240
- package/src/screens/SyncLGDevice/__test__/AddLGDevice.test.js +0 -359
- package/src/screens/Unit/MyAllUnit/__test__/__snapshots__/index.test.js.snap +0 -1001
- package/src/screens/Unit/MyAllUnit/__test__/index.test.js +0 -48
- package/src/screens/Unit/components/MyAllUnit/__test__/__snapshots__/index.test.js.snap +0 -1001
- package/src/screens/Unit/components/MyAllUnit/__test__/index.test.js +0 -48
- package/src/screens/Unit/components/__test__/MyUnit.test.js +0 -85
- package/src/screens/UnitSummary/components/WaterQuality/__test__/__snapshots__/index.test.js.snap +0 -1574
- package/src/screens/WaterQualityGuide/__test__/__snapshots__/index.test.js.snap +0 -3375
- package/src/utils/Converter/__test__/time.test.js +0 -128
- package/src/utils/I18n/index.test.js +0 -7
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
import React, { useState } from 'react';
|
|
2
|
+
import renderer, { act } from 'react-test-renderer';
|
|
3
|
+
import axios from 'axios';
|
|
4
|
+
|
|
5
|
+
import SelectAction from '../SelectAction';
|
|
6
|
+
import { SCProvider } from '../../../context';
|
|
7
|
+
import { mockSCStore } from '../../../context/mockStore';
|
|
8
|
+
import BottomButtonView from '../../../commons/BottomButtonView';
|
|
9
|
+
import Routes from '../../../utils/Route';
|
|
10
|
+
import { TESTID } from '../../../configs/Constants';
|
|
11
|
+
import ActionTemplate from '../../../commons/ActionTemplate';
|
|
12
|
+
|
|
13
|
+
jest.mock('axios');
|
|
14
|
+
|
|
15
|
+
const mockedNavigate = jest.fn();
|
|
16
|
+
jest.mock('@react-navigation/native', () => {
|
|
17
|
+
return {
|
|
18
|
+
...jest.requireActual('@react-navigation/native'),
|
|
19
|
+
useNavigation: () => ({
|
|
20
|
+
navigate: mockedNavigate,
|
|
21
|
+
}),
|
|
22
|
+
};
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
const mockSetState = jest.fn();
|
|
26
|
+
jest.mock('react', () => {
|
|
27
|
+
return {
|
|
28
|
+
...jest.requireActual('react'),
|
|
29
|
+
memo: (x) => x,
|
|
30
|
+
useState: jest.fn((init) => [init, mockSetState]),
|
|
31
|
+
};
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
const wrapComponent = (route) => (
|
|
35
|
+
<SCProvider initState={mockSCStore({})}>
|
|
36
|
+
<SelectAction route={route} />
|
|
37
|
+
</SCProvider>
|
|
38
|
+
);
|
|
39
|
+
|
|
40
|
+
describe('Test SelectAction', () => {
|
|
41
|
+
let tree;
|
|
42
|
+
let route = {
|
|
43
|
+
params: {
|
|
44
|
+
unit: { id: 1, name: 'Unit test' },
|
|
45
|
+
device: { id: 1, name: 'Device test' },
|
|
46
|
+
stationName: 'stationName',
|
|
47
|
+
automateId: 1,
|
|
48
|
+
scriptName: 'scriptName test',
|
|
49
|
+
},
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
beforeEach(() => {
|
|
53
|
+
axios.get.mockClear();
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
test('test onSave have automateId', async () => {
|
|
57
|
+
const response = {
|
|
58
|
+
status: 200,
|
|
59
|
+
success: true,
|
|
60
|
+
};
|
|
61
|
+
axios.post.mockImplementation(async () => {
|
|
62
|
+
return response;
|
|
63
|
+
});
|
|
64
|
+
await act(async () => {
|
|
65
|
+
tree = renderer.create(wrapComponent(route));
|
|
66
|
+
});
|
|
67
|
+
const instance = tree.root;
|
|
68
|
+
|
|
69
|
+
const bottomButton = instance.findByType(BottomButtonView);
|
|
70
|
+
await act(async () => {
|
|
71
|
+
bottomButton.props.onPressMain();
|
|
72
|
+
});
|
|
73
|
+
expect(axios.post).toHaveBeenCalled();
|
|
74
|
+
expect(mockedNavigate).toHaveBeenCalled();
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
test('test onSave no automateId', async () => {
|
|
78
|
+
route.params.automateId = null;
|
|
79
|
+
await act(async () => {
|
|
80
|
+
tree = renderer.create(wrapComponent(route));
|
|
81
|
+
});
|
|
82
|
+
const instance = tree.root;
|
|
83
|
+
|
|
84
|
+
const bottomButton = instance.findByType(BottomButtonView);
|
|
85
|
+
act(() => {
|
|
86
|
+
bottomButton.props.onPressMain();
|
|
87
|
+
});
|
|
88
|
+
expect(mockedNavigate).toHaveBeenCalledWith(Routes.AddNewScriptAction, {
|
|
89
|
+
automateType: 'one-tap',
|
|
90
|
+
name: route.params.scriptName,
|
|
91
|
+
unit: route.params.unit,
|
|
92
|
+
});
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
test('test fetchData', async () => {
|
|
96
|
+
const response = {
|
|
97
|
+
status: 200,
|
|
98
|
+
success: true,
|
|
99
|
+
data: [
|
|
100
|
+
{ template: 'on_off_button_action_template' },
|
|
101
|
+
{ template: 'one_button_action_template' },
|
|
102
|
+
{ template: 'three_button_action_template' },
|
|
103
|
+
],
|
|
104
|
+
};
|
|
105
|
+
axios.get.mockImplementation(async () => {
|
|
106
|
+
return response;
|
|
107
|
+
});
|
|
108
|
+
useState.mockImplementationOnce((init) => [init, mockSetState]);
|
|
109
|
+
await act(async () => {
|
|
110
|
+
tree = renderer.create(wrapComponent(route));
|
|
111
|
+
});
|
|
112
|
+
expect(axios.get).toHaveBeenCalled();
|
|
113
|
+
|
|
114
|
+
expect(mockSetState).toHaveBeenCalledWith(response.data);
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
test('test RenderActionItem', async () => {
|
|
118
|
+
const data = [
|
|
119
|
+
{
|
|
120
|
+
title: '',
|
|
121
|
+
template: 'three_button_action_template',
|
|
122
|
+
configuration: {
|
|
123
|
+
action1: '94ae262d-46e3-42ff-9d10-516831ecc830',
|
|
124
|
+
action2: '94ae262d-46e3-42ff-9d10-516831ecc830',
|
|
125
|
+
action3: '94ae262d-46e3-42ff-9d10-516831ecc830',
|
|
126
|
+
icon1: 'up',
|
|
127
|
+
icon2: 'stop',
|
|
128
|
+
icon3: 'down',
|
|
129
|
+
text1: 'OPEN',
|
|
130
|
+
text2: 'STOP',
|
|
131
|
+
text3: 'CLOSE',
|
|
132
|
+
text_lock: 'Door lock',
|
|
133
|
+
is_display_lock: true,
|
|
134
|
+
},
|
|
135
|
+
},
|
|
136
|
+
{
|
|
137
|
+
title: '',
|
|
138
|
+
template: 'on_off_button_action_template',
|
|
139
|
+
configuration: {
|
|
140
|
+
action_off: '94ae262d-46e3-42ff-9d10-516831ecc830',
|
|
141
|
+
icon_off: 'poweroff',
|
|
142
|
+
text_off: 'OFF',
|
|
143
|
+
action_on: '94ae262d-46e3-42ff-9d10-516831ecc830',
|
|
144
|
+
icon_on: 'poweroff',
|
|
145
|
+
text_on: 'ON',
|
|
146
|
+
config: 941,
|
|
147
|
+
},
|
|
148
|
+
},
|
|
149
|
+
{
|
|
150
|
+
title: '',
|
|
151
|
+
template: 'one_button_action_template',
|
|
152
|
+
configuration: {
|
|
153
|
+
action: '94ae262d-46e3-42ff-9d10-516831ecc830',
|
|
154
|
+
icon: 'up',
|
|
155
|
+
text: 'UP',
|
|
156
|
+
},
|
|
157
|
+
},
|
|
158
|
+
];
|
|
159
|
+
useState.mockImplementationOnce((init) => [data, mockSetState]);
|
|
160
|
+
await act(async () => {
|
|
161
|
+
tree = renderer.create(wrapComponent(route));
|
|
162
|
+
});
|
|
163
|
+
const instance = tree.root;
|
|
164
|
+
const renderActionItem = instance.findAll(
|
|
165
|
+
(el) => el.props.testID === TESTID.ACTION_ITEM
|
|
166
|
+
);
|
|
167
|
+
const actionTemplate = instance.findByType(ActionTemplate);
|
|
168
|
+
|
|
169
|
+
expect(renderActionItem[0].props.data.length).toBe(3);
|
|
170
|
+
expect(actionTemplate).toBeDefined();
|
|
171
|
+
});
|
|
172
|
+
});
|
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
import React, { useState } from 'react';
|
|
2
|
+
import renderer, { act } from 'react-test-renderer';
|
|
3
|
+
import axios from 'axios';
|
|
4
|
+
|
|
5
|
+
import SelectDevice from '../SelectDevice';
|
|
6
|
+
import { SCProvider } from '../../../context';
|
|
7
|
+
import { mockSCStore } from '../../../context/mockStore';
|
|
8
|
+
import Device from '../Device';
|
|
9
|
+
import BottomButtonView from '../../../commons/BottomButtonView';
|
|
10
|
+
import NavBar from '../../../commons/NavBar';
|
|
11
|
+
import API from '../../../configs/API';
|
|
12
|
+
|
|
13
|
+
jest.mock('axios');
|
|
14
|
+
|
|
15
|
+
const mockedNavigate = jest.fn();
|
|
16
|
+
jest.mock('@react-navigation/native', () => {
|
|
17
|
+
return {
|
|
18
|
+
...jest.requireActual('@react-navigation/native'),
|
|
19
|
+
useNavigation: () => ({
|
|
20
|
+
navigate: mockedNavigate,
|
|
21
|
+
}),
|
|
22
|
+
};
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
const mockSetState = jest.fn();
|
|
26
|
+
jest.mock('react', () => {
|
|
27
|
+
return {
|
|
28
|
+
...jest.requireActual('react'),
|
|
29
|
+
memo: (x) => x,
|
|
30
|
+
useState: jest.fn((init) => [init, mockSetState]),
|
|
31
|
+
};
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
const wrapComponent = (route) => (
|
|
35
|
+
<SCProvider initState={mockSCStore({})}>
|
|
36
|
+
<SelectDevice route={route} />
|
|
37
|
+
</SCProvider>
|
|
38
|
+
);
|
|
39
|
+
|
|
40
|
+
describe('Test SelectDevice', () => {
|
|
41
|
+
let tree;
|
|
42
|
+
const route = {
|
|
43
|
+
params: {
|
|
44
|
+
unit: { id: 1, name: 'Unit test' },
|
|
45
|
+
automateId: 1,
|
|
46
|
+
scriptName: 'scriptName test',
|
|
47
|
+
},
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
beforeEach(() => {
|
|
51
|
+
axios.get.mockClear();
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
test('fetch Device success', async () => {
|
|
55
|
+
const response = {
|
|
56
|
+
status: 200,
|
|
57
|
+
success: true,
|
|
58
|
+
data: [
|
|
59
|
+
{
|
|
60
|
+
id: 1,
|
|
61
|
+
name: 'Device 1',
|
|
62
|
+
sensors: [
|
|
63
|
+
{ id: 1, name: 'sensor' },
|
|
64
|
+
{ id: 2, name: 'sensor' },
|
|
65
|
+
],
|
|
66
|
+
},
|
|
67
|
+
],
|
|
68
|
+
};
|
|
69
|
+
axios.get.mockImplementation(async () => {
|
|
70
|
+
return response;
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
await act(async () => {
|
|
74
|
+
tree = renderer.create(wrapComponent(route));
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
expect(axios.get).toHaveBeenCalledWith(API.UNIT.DEVICE_CONTROL(1), {});
|
|
78
|
+
expect(mockSetState).toHaveBeenCalledTimes(3);
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
test('onPress continue', async () => {
|
|
82
|
+
await act(async () => {
|
|
83
|
+
tree = renderer.create(wrapComponent(route));
|
|
84
|
+
});
|
|
85
|
+
const instance = tree.root;
|
|
86
|
+
|
|
87
|
+
const bottomButton = instance.findByType(BottomButtonView);
|
|
88
|
+
act(() => {
|
|
89
|
+
bottomButton.props.onPressMain();
|
|
90
|
+
});
|
|
91
|
+
expect(mockedNavigate).toHaveBeenCalled();
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
test('test onPressDevice', async () => {
|
|
95
|
+
const data = [
|
|
96
|
+
{
|
|
97
|
+
id: 1,
|
|
98
|
+
name: 'Device 1',
|
|
99
|
+
sensors: [
|
|
100
|
+
{ id: 1, name: 'sensor' },
|
|
101
|
+
{ id: 2, name: 'sensor' },
|
|
102
|
+
],
|
|
103
|
+
},
|
|
104
|
+
];
|
|
105
|
+
const mockSetSelectedDevice = jest.fn();
|
|
106
|
+
useState.mockImplementationOnce((init) => [init, mockSetState]);
|
|
107
|
+
useState.mockImplementationOnce((init) => [init, mockSetState]);
|
|
108
|
+
useState.mockImplementationOnce((init) => [init, mockSetState]);
|
|
109
|
+
useState.mockImplementationOnce((init) => [data, mockSetState]);
|
|
110
|
+
useState.mockImplementationOnce((init) => [false, mockSetSelectedDevice]);
|
|
111
|
+
|
|
112
|
+
await act(async () => {
|
|
113
|
+
tree = renderer.create(wrapComponent(route));
|
|
114
|
+
});
|
|
115
|
+
const instance = tree.root;
|
|
116
|
+
const device = instance.findAllByType(Device);
|
|
117
|
+
expect(device).toHaveLength(2);
|
|
118
|
+
|
|
119
|
+
act(() => {
|
|
120
|
+
device[0].props.onPress({ id: 1, name: 'sensor' });
|
|
121
|
+
});
|
|
122
|
+
expect(mockSetSelectedDevice).toHaveBeenCalledWith({
|
|
123
|
+
id: 1,
|
|
124
|
+
name: 'sensor',
|
|
125
|
+
});
|
|
126
|
+
});
|
|
127
|
+
|
|
128
|
+
test('test onPressDevice false', async () => {
|
|
129
|
+
const data = [
|
|
130
|
+
{
|
|
131
|
+
id: 1,
|
|
132
|
+
name: 'Device 1',
|
|
133
|
+
sensors: [
|
|
134
|
+
{ id: 1, name: 'sensor' },
|
|
135
|
+
{ id: 2, name: 'sensor' },
|
|
136
|
+
],
|
|
137
|
+
},
|
|
138
|
+
];
|
|
139
|
+
const mockSetSelectedDevice = jest.fn();
|
|
140
|
+
useState.mockImplementationOnce((init) => [init, mockSetState]);
|
|
141
|
+
useState.mockImplementationOnce((init) => [init, mockSetState]);
|
|
142
|
+
useState.mockImplementationOnce((init) => [init, mockSetState]);
|
|
143
|
+
useState.mockImplementationOnce((init) => [data, mockSetState]);
|
|
144
|
+
useState.mockImplementationOnce((init) => [
|
|
145
|
+
{ id: 1, name: 'sensor' },
|
|
146
|
+
mockSetSelectedDevice,
|
|
147
|
+
]);
|
|
148
|
+
|
|
149
|
+
await act(async () => {
|
|
150
|
+
tree = renderer.create(wrapComponent(route));
|
|
151
|
+
});
|
|
152
|
+
const instance = tree.root;
|
|
153
|
+
const device = instance.findAllByType(Device);
|
|
154
|
+
expect(device).toHaveLength(2);
|
|
155
|
+
|
|
156
|
+
act(() => {
|
|
157
|
+
device[0].props.onPress({ id: 1, name: 'sensor' });
|
|
158
|
+
});
|
|
159
|
+
expect(mockSetSelectedDevice).toHaveBeenCalledWith(false);
|
|
160
|
+
});
|
|
161
|
+
|
|
162
|
+
test('test onSnapItem', async () => {
|
|
163
|
+
const data = [
|
|
164
|
+
{
|
|
165
|
+
id: 1,
|
|
166
|
+
name: 'Device 1',
|
|
167
|
+
sensors: [
|
|
168
|
+
{ id: 1, name: 'sensor' },
|
|
169
|
+
{ id: 2, name: 'sensor' },
|
|
170
|
+
],
|
|
171
|
+
},
|
|
172
|
+
];
|
|
173
|
+
const mockSetIndexStation = jest.fn();
|
|
174
|
+
useState.mockImplementationOnce((init) => [init, mockSetState]);
|
|
175
|
+
useState.mockImplementationOnce((init) => [init, mockSetState]);
|
|
176
|
+
useState.mockImplementationOnce((init) => [init, mockSetIndexStation]);
|
|
177
|
+
useState.mockImplementationOnce((init) => [data, mockSetState]);
|
|
178
|
+
|
|
179
|
+
await act(async () => {
|
|
180
|
+
tree = renderer.create(wrapComponent(route));
|
|
181
|
+
});
|
|
182
|
+
const instance = tree.root;
|
|
183
|
+
const navBar = instance.findByType(NavBar);
|
|
184
|
+
|
|
185
|
+
act(() => {
|
|
186
|
+
navBar.props.onSnapToItem({ id: 1, name: 'sensor' }, 0);
|
|
187
|
+
});
|
|
188
|
+
|
|
189
|
+
expect(mockSetIndexStation).toBeCalledWith(0);
|
|
190
|
+
});
|
|
191
|
+
});
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { act, create } from 'react-test-renderer';
|
|
3
|
+
import AddNewAutoSmart from '..';
|
|
4
|
+
import { SCProvider } from '../../../context';
|
|
5
|
+
import { mockSCStore } from '../../../context/mockStore';
|
|
6
|
+
import { TESTID } from '../../../configs/Constants';
|
|
7
|
+
import ItemAutomate from '../../../commons/Automate/ItemAutomate';
|
|
8
|
+
|
|
9
|
+
const wrapComponent = (route) => (
|
|
10
|
+
<SCProvider initState={mockSCStore({})}>
|
|
11
|
+
<AddNewAutoSmart route={route} />
|
|
12
|
+
</SCProvider>
|
|
13
|
+
);
|
|
14
|
+
|
|
15
|
+
jest.mock('react-redux', () => {
|
|
16
|
+
return {
|
|
17
|
+
...jest.requireActual('react-redux'),
|
|
18
|
+
useSelector: () => 'vi',
|
|
19
|
+
};
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
describe('test AddNewAutoSmart', () => {
|
|
23
|
+
test('render AddNewAutoSmart', async () => {
|
|
24
|
+
let tree;
|
|
25
|
+
let route = {
|
|
26
|
+
params: { type: 'value_change' },
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
await act(async () => {
|
|
30
|
+
tree = await create(wrapComponent(route));
|
|
31
|
+
});
|
|
32
|
+
const instance = tree.root;
|
|
33
|
+
const addNewAutoSmart = instance.findAllByType(ItemAutomate);
|
|
34
|
+
expect(addNewAutoSmart).toHaveLength(2);
|
|
35
|
+
});
|
|
36
|
+
test('render BottomButtonView', async () => {
|
|
37
|
+
let tree;
|
|
38
|
+
let route = {
|
|
39
|
+
params: { type: 'change_value' },
|
|
40
|
+
};
|
|
41
|
+
await act(async () => {
|
|
42
|
+
tree = await create(wrapComponent(route));
|
|
43
|
+
});
|
|
44
|
+
const instance = tree.root;
|
|
45
|
+
const bottomButton = instance.find(
|
|
46
|
+
(item) =>
|
|
47
|
+
item.props.testID ===
|
|
48
|
+
`${TESTID.PREFIX.BUTTON_ADD_AUTO_SMART}${TESTID.BOTTOM_VIEW_MAIN}`
|
|
49
|
+
);
|
|
50
|
+
expect(bottomButton).toBeTruthy();
|
|
51
|
+
await act(async () => {
|
|
52
|
+
await bottomButton.props.onPress();
|
|
53
|
+
});
|
|
54
|
+
});
|
|
55
|
+
});
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import React, { memo, useState } from 'react';
|
|
2
|
+
import { Alert, View } from 'react-native';
|
|
3
|
+
import { HeaderCustom } from '../../commons/Header';
|
|
4
|
+
import styles from './styles/AddNewAutoSmartStyles';
|
|
5
|
+
import Text from '../../commons/Text';
|
|
6
|
+
import BottomButtonView from '../../commons/BottomButtonView';
|
|
7
|
+
import ItemAutomate from '../../commons/Automate/ItemAutomate';
|
|
8
|
+
import { AUTOMATE_TYPE, TESTID } from '../../configs/Constants';
|
|
9
|
+
|
|
10
|
+
import { useTranslations } from '../../hooks/Common/useTranslations';
|
|
11
|
+
|
|
12
|
+
const AddNewAutoSmart = memo(({ route }) => {
|
|
13
|
+
const t = useTranslations();
|
|
14
|
+
const { type } = route.params;
|
|
15
|
+
const typeAutoSmart = {
|
|
16
|
+
automate: [
|
|
17
|
+
{
|
|
18
|
+
type: AUTOMATE_TYPE.ONE_TAP,
|
|
19
|
+
},
|
|
20
|
+
{
|
|
21
|
+
type: AUTOMATE_TYPE.VALUE_CHANGE,
|
|
22
|
+
},
|
|
23
|
+
{
|
|
24
|
+
type: AUTOMATE_TYPE.SCHEDULE,
|
|
25
|
+
},
|
|
26
|
+
],
|
|
27
|
+
value_change: [
|
|
28
|
+
{
|
|
29
|
+
type: AUTOMATE_TYPE.VALUE_CHANGE,
|
|
30
|
+
},
|
|
31
|
+
{
|
|
32
|
+
type: AUTOMATE_TYPE.SCHEDULE,
|
|
33
|
+
},
|
|
34
|
+
],
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
// eslint-disable-next-line no-alert
|
|
38
|
+
const onPress = () => {
|
|
39
|
+
Alert.alert(t('feature_under_development'));
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
const [selectedIndex, setSelectedIndex] = useState(-1);
|
|
43
|
+
const [data] = useState(typeAutoSmart[type]);
|
|
44
|
+
|
|
45
|
+
const handleSelectIndex = (index) => {
|
|
46
|
+
if (index !== selectedIndex) {
|
|
47
|
+
setSelectedIndex(index);
|
|
48
|
+
} else {
|
|
49
|
+
setSelectedIndex(-1);
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
return (
|
|
54
|
+
<View style={styles.wrap}>
|
|
55
|
+
<HeaderCustom isShowClose />
|
|
56
|
+
<View style={styles.container}>
|
|
57
|
+
<Text semibold type={'H2'} style={styles.titleCreate}>
|
|
58
|
+
{t('create_smart')}
|
|
59
|
+
</Text>
|
|
60
|
+
<Text type={'Body'} style={styles.titleChoose}>
|
|
61
|
+
{t('choose_the_automation_method_you_want')}
|
|
62
|
+
</Text>
|
|
63
|
+
<View>
|
|
64
|
+
{!!data &&
|
|
65
|
+
data.map((item, index) => (
|
|
66
|
+
<ItemAutomate
|
|
67
|
+
type={item.type}
|
|
68
|
+
isSelected={selectedIndex === index}
|
|
69
|
+
onPress={() => handleSelectIndex(index)}
|
|
70
|
+
/>
|
|
71
|
+
))}
|
|
72
|
+
</View>
|
|
73
|
+
</View>
|
|
74
|
+
<BottomButtonView
|
|
75
|
+
testIDPrefix={TESTID.PREFIX.BUTTON_ADD_AUTO_SMART}
|
|
76
|
+
onPressMain={onPress}
|
|
77
|
+
style={styles.bottomButton}
|
|
78
|
+
mainTitle={t('continue')}
|
|
79
|
+
typeMain={selectedIndex === -1 ? 'disabled' : 'primary'}
|
|
80
|
+
/>
|
|
81
|
+
</View>
|
|
82
|
+
);
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
export default AddNewAutoSmart;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { StyleSheet } from 'react-native';
|
|
2
|
+
import { Colors } from '../../../configs';
|
|
3
|
+
import { getBottomSpace } from 'react-native-iphone-x-helper';
|
|
4
|
+
|
|
5
|
+
export default StyleSheet.create({
|
|
6
|
+
wrap: {
|
|
7
|
+
flex: 1,
|
|
8
|
+
backgroundColor: Colors.White,
|
|
9
|
+
},
|
|
10
|
+
titleCreate: {
|
|
11
|
+
fontStyle: 'normal',
|
|
12
|
+
fontWeight: '600',
|
|
13
|
+
color: Colors.Gray9,
|
|
14
|
+
},
|
|
15
|
+
titleChoose: {
|
|
16
|
+
fontStyle: 'normal',
|
|
17
|
+
fontWeight: '400',
|
|
18
|
+
color: Colors.Gray8,
|
|
19
|
+
},
|
|
20
|
+
container: {
|
|
21
|
+
flex: 1,
|
|
22
|
+
paddingHorizontal: 16,
|
|
23
|
+
paddingTop: 10,
|
|
24
|
+
paddingBottom: getBottomSpace() + 10,
|
|
25
|
+
},
|
|
26
|
+
bottomButton: {
|
|
27
|
+
borderWidth: 0,
|
|
28
|
+
borderColor: Colors.Gray4,
|
|
29
|
+
paddingTop: 24,
|
|
30
|
+
paddingBottom: 24,
|
|
31
|
+
borderTopWidth: 1,
|
|
32
|
+
borderStyle: 'solid',
|
|
33
|
+
position: 'absolute',
|
|
34
|
+
bottom: 0,
|
|
35
|
+
},
|
|
36
|
+
});
|
|
@@ -2,13 +2,21 @@ import React from 'react';
|
|
|
2
2
|
import { act, create } from 'react-test-renderer';
|
|
3
3
|
import axios from 'axios';
|
|
4
4
|
|
|
5
|
-
import { useTranslations } from '../../../hooks/Common/useTranslations';
|
|
6
5
|
import AddNewDevice from '../index';
|
|
7
6
|
import GroupCheckBox from '../../../commons/GroupCheckBox';
|
|
8
7
|
import { TESTID } from '../../../configs/Constants';
|
|
9
8
|
import API from '../../../configs/API';
|
|
10
9
|
import { ViewButtonBottom } from '../../../commons';
|
|
11
10
|
import Routes from '../../../utils/Route';
|
|
11
|
+
import { getTranslate } from '../../../utils/I18n';
|
|
12
|
+
import { SCProvider } from '../../../context';
|
|
13
|
+
import { mockSCStore } from '../../../context/mockStore';
|
|
14
|
+
|
|
15
|
+
const wrapComponent = (route) => (
|
|
16
|
+
<SCProvider initState={mockSCStore({})}>
|
|
17
|
+
<AddNewDevice route={route} />
|
|
18
|
+
</SCProvider>
|
|
19
|
+
);
|
|
12
20
|
|
|
13
21
|
jest.mock('axios');
|
|
14
22
|
|
|
@@ -30,7 +38,6 @@ jest.mock('@react-navigation/native', () => {
|
|
|
30
38
|
});
|
|
31
39
|
|
|
32
40
|
describe('Test AddNewDevice', () => {
|
|
33
|
-
const t = useTranslations();
|
|
34
41
|
let tree;
|
|
35
42
|
let route;
|
|
36
43
|
|
|
@@ -53,13 +60,17 @@ describe('Test AddNewDevice', () => {
|
|
|
53
60
|
|
|
54
61
|
test('create', async () => {
|
|
55
62
|
await act(async () => {
|
|
56
|
-
tree = await create(
|
|
63
|
+
tree = await create(wrapComponent(route));
|
|
57
64
|
});
|
|
58
65
|
const instance = tree.root;
|
|
59
66
|
const textAdd = getText(instance, TESTID.ADD_NEW_DEVICE_ADD);
|
|
60
67
|
const textThen = getText(instance, TESTID.ADD_NEW_DEVICE_THEN_SELECT);
|
|
61
|
-
expect(textAdd.props.children).toEqual(
|
|
62
|
-
|
|
68
|
+
expect(textAdd.props.children).toEqual(
|
|
69
|
+
getTranslate('en', 'add_new_device')
|
|
70
|
+
);
|
|
71
|
+
expect(textThen.props.children).toEqual(
|
|
72
|
+
getTranslate('en', 'then_select_a_sub_unit_to_add')
|
|
73
|
+
);
|
|
63
74
|
|
|
64
75
|
const groupCheckBox = instance.findAllByType(GroupCheckBox);
|
|
65
76
|
expect(groupCheckBox).toHaveLength(1);
|
|
@@ -80,7 +91,7 @@ describe('Test AddNewDevice', () => {
|
|
|
80
91
|
});
|
|
81
92
|
|
|
82
93
|
await act(async () => {
|
|
83
|
-
tree = await create(
|
|
94
|
+
tree = await create(wrapComponent(route));
|
|
84
95
|
});
|
|
85
96
|
const instance = tree.root;
|
|
86
97
|
expect(axios.get).toHaveBeenCalledWith(API.UNIT.UNIT_DETAIL(1), {});
|
|
@@ -100,7 +111,7 @@ describe('Test AddNewDevice', () => {
|
|
|
100
111
|
});
|
|
101
112
|
|
|
102
113
|
await act(async () => {
|
|
103
|
-
tree = await create(
|
|
114
|
+
tree = await create(wrapComponent(route));
|
|
104
115
|
});
|
|
105
116
|
const instance = tree.root;
|
|
106
117
|
expect(axios.get).toHaveBeenCalledWith(API.UNIT.UNIT_DETAIL(1), {});
|
|
@@ -111,18 +122,22 @@ describe('Test AddNewDevice', () => {
|
|
|
111
122
|
|
|
112
123
|
test('ViewButtonBottom', async () => {
|
|
113
124
|
await act(async () => {
|
|
114
|
-
tree = await create(
|
|
125
|
+
tree = await create(wrapComponent(route));
|
|
115
126
|
});
|
|
116
127
|
const instance = tree.root;
|
|
117
128
|
const viewButtonBottom = instance.findByType(ViewButtonBottom);
|
|
118
129
|
|
|
119
|
-
expect(viewButtonBottom.props.leftTitle).toEqual(
|
|
120
|
-
|
|
130
|
+
expect(viewButtonBottom.props.leftTitle).toEqual(
|
|
131
|
+
getTranslate('en', 'text_back')
|
|
132
|
+
);
|
|
133
|
+
expect(viewButtonBottom.props.rightTitle).toEqual(
|
|
134
|
+
getTranslate('en', 'text_next')
|
|
135
|
+
);
|
|
121
136
|
});
|
|
122
137
|
|
|
123
138
|
test('ViewButtonBottom onLeftClick', async () => {
|
|
124
139
|
await act(async () => {
|
|
125
|
-
tree = await create(
|
|
140
|
+
tree = await create(wrapComponent(route));
|
|
126
141
|
});
|
|
127
142
|
const instance = tree.root;
|
|
128
143
|
const viewButtonBottom = instance.findByType(ViewButtonBottom);
|
|
@@ -134,14 +149,14 @@ describe('Test AddNewDevice', () => {
|
|
|
134
149
|
|
|
135
150
|
test('ViewButtonBottom onRightClick without select stationId', async () => {
|
|
136
151
|
await act(async () => {
|
|
137
|
-
tree = await create(
|
|
152
|
+
tree = await create(wrapComponent(route));
|
|
138
153
|
});
|
|
139
154
|
const instance = tree.root;
|
|
140
155
|
const viewButtonBottom = instance.findByType(ViewButtonBottom);
|
|
141
156
|
await act(async () => {
|
|
142
157
|
viewButtonBottom.props.onRightClick();
|
|
143
158
|
});
|
|
144
|
-
expect(mockedNavigate).
|
|
159
|
+
expect(mockedNavigate).toHaveBeenCalled();
|
|
145
160
|
});
|
|
146
161
|
|
|
147
162
|
test('ViewButtonBottom onRightClick with stationId', async () => {
|
|
@@ -158,7 +173,7 @@ describe('Test AddNewDevice', () => {
|
|
|
158
173
|
});
|
|
159
174
|
|
|
160
175
|
await act(async () => {
|
|
161
|
-
tree = await create(
|
|
176
|
+
tree = await create(wrapComponent(route));
|
|
162
177
|
});
|
|
163
178
|
const instance = tree.root;
|
|
164
179
|
|