@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
|
@@ -1,359 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import { act, create } from 'react-test-renderer';
|
|
3
|
-
import { useTranslations } from '../../../hooks/Common/useTranslations';
|
|
4
|
-
import axios from 'axios';
|
|
5
|
-
|
|
6
|
-
import AddLGDevice from '../AddLGDevice';
|
|
7
|
-
import { API } from '../../../configs';
|
|
8
|
-
import GroupCheckBox from '../../../commons/GroupCheckBox';
|
|
9
|
-
import { TESTID } from '../../../configs/Constants';
|
|
10
|
-
import { ViewButtonBottom } from '../../../commons';
|
|
11
|
-
import { ToastBottomHelper } from '../../../utils/Utils';
|
|
12
|
-
import Routes from '../../../utils/Route';
|
|
13
|
-
|
|
14
|
-
jest.mock('axios');
|
|
15
|
-
|
|
16
|
-
const mockedNavigate = jest.fn();
|
|
17
|
-
const mockedGoBack = jest.fn();
|
|
18
|
-
jest.mock('@react-navigation/native', () => {
|
|
19
|
-
return {
|
|
20
|
-
...jest.requireActual('@react-navigation/native'),
|
|
21
|
-
useNavigation: () => ({
|
|
22
|
-
navigate: mockedNavigate,
|
|
23
|
-
goBack: mockedGoBack,
|
|
24
|
-
}),
|
|
25
|
-
useIsFocused: jest.fn(),
|
|
26
|
-
};
|
|
27
|
-
});
|
|
28
|
-
|
|
29
|
-
describe('Test Add LG Device', () => {
|
|
30
|
-
const t = useTranslations();
|
|
31
|
-
let tree;
|
|
32
|
-
let route;
|
|
33
|
-
|
|
34
|
-
beforeEach(() => {
|
|
35
|
-
route = {
|
|
36
|
-
params: {
|
|
37
|
-
unit_id: 1,
|
|
38
|
-
code: 'CODE',
|
|
39
|
-
backend_url: 'https://doamin.com',
|
|
40
|
-
},
|
|
41
|
-
};
|
|
42
|
-
});
|
|
43
|
-
|
|
44
|
-
afterEach(() => {
|
|
45
|
-
axios.get.mockClear();
|
|
46
|
-
axios.post.mockClear();
|
|
47
|
-
});
|
|
48
|
-
|
|
49
|
-
const getText = (instance, id) => {
|
|
50
|
-
return instance.find((el) => el.props.testID === id);
|
|
51
|
-
};
|
|
52
|
-
|
|
53
|
-
test('render', async () => {
|
|
54
|
-
await act(async () => {
|
|
55
|
-
tree = await create(<AddLGDevice route={route} />);
|
|
56
|
-
});
|
|
57
|
-
const instance = tree.root;
|
|
58
|
-
const textAdd = getText(instance, TESTID.ADD_NEW_DEVICE_LG_ADD);
|
|
59
|
-
const textThen = getText(instance, TESTID.ADD_NEW_DEVICE_LG_THEN_SELECT);
|
|
60
|
-
expect(textAdd.props.children).toEqual(t('add_new_device'));
|
|
61
|
-
expect(textThen.props.children).toEqual(t('then_select_a_sub_unit_to_add'));
|
|
62
|
-
|
|
63
|
-
const groupCheckBox = instance.findAllByType(GroupCheckBox);
|
|
64
|
-
expect(groupCheckBox).toHaveLength(1);
|
|
65
|
-
expect(groupCheckBox[0].props.data).toEqual([]);
|
|
66
|
-
});
|
|
67
|
-
|
|
68
|
-
test('fetchDetails success', async () => {
|
|
69
|
-
const response = {
|
|
70
|
-
status: 200,
|
|
71
|
-
data: {
|
|
72
|
-
id: 1,
|
|
73
|
-
name: 'Unit name',
|
|
74
|
-
stations: [{ id: 2, name: 'Station name' }],
|
|
75
|
-
},
|
|
76
|
-
};
|
|
77
|
-
axios.get.mockImplementation(async () => {
|
|
78
|
-
return response;
|
|
79
|
-
});
|
|
80
|
-
|
|
81
|
-
await act(async () => {
|
|
82
|
-
tree = create(<AddLGDevice route={route} />);
|
|
83
|
-
});
|
|
84
|
-
const instance = tree.root;
|
|
85
|
-
expect(axios.get).toHaveBeenCalledWith(API.UNIT.UNIT_DETAIL(1), {});
|
|
86
|
-
|
|
87
|
-
const groupCheckBox = instance.findByType(GroupCheckBox);
|
|
88
|
-
expect(groupCheckBox.props.data).toEqual([
|
|
89
|
-
{ id: 2, name: 'Station name', title: 'Station name' },
|
|
90
|
-
]);
|
|
91
|
-
});
|
|
92
|
-
|
|
93
|
-
test('fetchDetails fail', async () => {
|
|
94
|
-
const response = {
|
|
95
|
-
data: {},
|
|
96
|
-
};
|
|
97
|
-
axios.get.mockImplementation(async () => {
|
|
98
|
-
return response;
|
|
99
|
-
});
|
|
100
|
-
|
|
101
|
-
await act(async () => {
|
|
102
|
-
tree = await create(<AddLGDevice route={route} />);
|
|
103
|
-
});
|
|
104
|
-
const instance = tree.root;
|
|
105
|
-
expect(axios.get).toHaveBeenCalledWith(API.UNIT.UNIT_DETAIL(1), {});
|
|
106
|
-
|
|
107
|
-
const groupCheckBox = instance.findByType(GroupCheckBox);
|
|
108
|
-
expect(groupCheckBox.props.data).toEqual([]);
|
|
109
|
-
});
|
|
110
|
-
|
|
111
|
-
test('ViewButtonBottom', async () => {
|
|
112
|
-
await act(async () => {
|
|
113
|
-
tree = await create(<AddLGDevice route={route} />);
|
|
114
|
-
});
|
|
115
|
-
const instance = tree.root;
|
|
116
|
-
const viewButtonBottom = instance.findByType(ViewButtonBottom);
|
|
117
|
-
|
|
118
|
-
expect(viewButtonBottom.props.leftTitle).toEqual(t('text_back'));
|
|
119
|
-
expect(viewButtonBottom.props.rightTitle).toEqual(t('text_next'));
|
|
120
|
-
});
|
|
121
|
-
|
|
122
|
-
test('ViewButtonBottom onLeftClick', async () => {
|
|
123
|
-
await act(async () => {
|
|
124
|
-
tree = await create(<AddLGDevice route={route} />);
|
|
125
|
-
});
|
|
126
|
-
const instance = tree.root;
|
|
127
|
-
const viewButtonBottom = instance.findByType(ViewButtonBottom);
|
|
128
|
-
await act(async () => {
|
|
129
|
-
viewButtonBottom.props.onLeftClick();
|
|
130
|
-
});
|
|
131
|
-
expect(mockedGoBack).toHaveBeenCalled();
|
|
132
|
-
});
|
|
133
|
-
|
|
134
|
-
test('ViewButtonBottom onRightClick without select stationId', async () => {
|
|
135
|
-
await act(async () => {
|
|
136
|
-
tree = await create(<AddLGDevice route={route} />);
|
|
137
|
-
});
|
|
138
|
-
const instance = tree.root;
|
|
139
|
-
const viewButtonBottom = instance.findByType(ViewButtonBottom);
|
|
140
|
-
await act(async () => {
|
|
141
|
-
viewButtonBottom.props.onRightClick();
|
|
142
|
-
});
|
|
143
|
-
expect(mockedNavigate).not.toHaveBeenCalled();
|
|
144
|
-
});
|
|
145
|
-
|
|
146
|
-
test('ViewButtonBottom onRightClick with stationId', async () => {
|
|
147
|
-
const response = {
|
|
148
|
-
status: 200,
|
|
149
|
-
data: {
|
|
150
|
-
id: 1,
|
|
151
|
-
name: 'Unit name',
|
|
152
|
-
stations: [{ id: 2, name: 'Station name' }],
|
|
153
|
-
},
|
|
154
|
-
};
|
|
155
|
-
axios.get.mockImplementation(async () => {
|
|
156
|
-
return response;
|
|
157
|
-
});
|
|
158
|
-
|
|
159
|
-
const responseToken = {
|
|
160
|
-
status: 200,
|
|
161
|
-
data: {
|
|
162
|
-
access_token: 'ACCESS_TOKEN',
|
|
163
|
-
},
|
|
164
|
-
};
|
|
165
|
-
axios.post.mockImplementationOnce(async () => {
|
|
166
|
-
return responseToken;
|
|
167
|
-
});
|
|
168
|
-
|
|
169
|
-
const responseSync = {
|
|
170
|
-
status: 200,
|
|
171
|
-
data: {},
|
|
172
|
-
};
|
|
173
|
-
axios.post.mockImplementationOnce(async () => {
|
|
174
|
-
return responseSync;
|
|
175
|
-
});
|
|
176
|
-
|
|
177
|
-
const spyToastSuccess = jest.spyOn(ToastBottomHelper, 'success');
|
|
178
|
-
|
|
179
|
-
await act(async () => {
|
|
180
|
-
tree = await create(<AddLGDevice route={route} />);
|
|
181
|
-
});
|
|
182
|
-
const instance = tree.root;
|
|
183
|
-
const groupCheckBox = instance.findByType(GroupCheckBox);
|
|
184
|
-
await act(async () => {
|
|
185
|
-
groupCheckBox.props.onSelect({ id: 2 }); // select stationId
|
|
186
|
-
});
|
|
187
|
-
|
|
188
|
-
const viewButtonBottom = instance.findByType(ViewButtonBottom);
|
|
189
|
-
await act(async () => {
|
|
190
|
-
viewButtonBottom.props.onRightClick();
|
|
191
|
-
});
|
|
192
|
-
|
|
193
|
-
expect(axios.get).toHaveBeenCalledTimes(1);
|
|
194
|
-
expect(axios.post).toHaveBeenCalledTimes(2);
|
|
195
|
-
expect(spyToastSuccess).toBeCalled();
|
|
196
|
-
expect(mockedNavigate).toHaveBeenCalledWith(Routes.Dashboard);
|
|
197
|
-
|
|
198
|
-
spyToastSuccess.mockReset();
|
|
199
|
-
spyToastSuccess.mockRestore();
|
|
200
|
-
});
|
|
201
|
-
|
|
202
|
-
test('ViewButtonBottom onRightClick with stationId but sync failed', async () => {
|
|
203
|
-
const response = {
|
|
204
|
-
status: 200,
|
|
205
|
-
data: {
|
|
206
|
-
id: 1,
|
|
207
|
-
name: 'Unit name',
|
|
208
|
-
stations: [{ id: 2, name: 'Station name' }],
|
|
209
|
-
},
|
|
210
|
-
};
|
|
211
|
-
axios.get.mockImplementation(async () => {
|
|
212
|
-
return response;
|
|
213
|
-
});
|
|
214
|
-
|
|
215
|
-
const responseToken = {
|
|
216
|
-
status: 200,
|
|
217
|
-
data: {
|
|
218
|
-
access_token: 'ACCESS_TOKEN',
|
|
219
|
-
},
|
|
220
|
-
};
|
|
221
|
-
axios.post.mockImplementationOnce(async () => {
|
|
222
|
-
return responseToken;
|
|
223
|
-
});
|
|
224
|
-
|
|
225
|
-
const responseSync = {
|
|
226
|
-
data: {},
|
|
227
|
-
};
|
|
228
|
-
axios.post.mockImplementationOnce(async () => {
|
|
229
|
-
return responseSync;
|
|
230
|
-
});
|
|
231
|
-
|
|
232
|
-
const spyToastSuccess = jest.spyOn(ToastBottomHelper, 'success');
|
|
233
|
-
const spyToastError = jest.spyOn(ToastBottomHelper, 'error');
|
|
234
|
-
|
|
235
|
-
await act(async () => {
|
|
236
|
-
tree = await create(<AddLGDevice route={route} />);
|
|
237
|
-
});
|
|
238
|
-
const instance = tree.root;
|
|
239
|
-
const groupCheckBox = instance.findByType(GroupCheckBox);
|
|
240
|
-
await act(async () => {
|
|
241
|
-
groupCheckBox.props.onSelect({ id: 2 }); // select stationId
|
|
242
|
-
});
|
|
243
|
-
|
|
244
|
-
const viewButtonBottom = instance.findByType(ViewButtonBottom);
|
|
245
|
-
await act(async () => {
|
|
246
|
-
viewButtonBottom.props.onRightClick();
|
|
247
|
-
});
|
|
248
|
-
|
|
249
|
-
expect(axios.get).toHaveBeenCalledTimes(1);
|
|
250
|
-
expect(axios.post).toHaveBeenCalledTimes(2);
|
|
251
|
-
expect(spyToastSuccess).not.toBeCalled();
|
|
252
|
-
expect(spyToastError).toBeCalled();
|
|
253
|
-
expect(mockedNavigate).toHaveBeenCalledWith(Routes.Dashboard);
|
|
254
|
-
|
|
255
|
-
spyToastSuccess.mockReset();
|
|
256
|
-
spyToastSuccess.mockRestore();
|
|
257
|
-
});
|
|
258
|
-
|
|
259
|
-
test('ViewButtonBottom onRightClick with stationId but get token failed, wrong data', async () => {
|
|
260
|
-
const response = {
|
|
261
|
-
status: 200,
|
|
262
|
-
data: {
|
|
263
|
-
id: 1,
|
|
264
|
-
name: 'Unit name',
|
|
265
|
-
stations: [{ id: 2, name: 'Station name' }],
|
|
266
|
-
},
|
|
267
|
-
};
|
|
268
|
-
axios.get.mockImplementation(async () => {
|
|
269
|
-
return response;
|
|
270
|
-
});
|
|
271
|
-
|
|
272
|
-
const responseToken = {
|
|
273
|
-
status: 200,
|
|
274
|
-
data: {
|
|
275
|
-
httpError: {
|
|
276
|
-
request: 'https://kr.lgeapi.com//oauth/1.0/oauth2/token',
|
|
277
|
-
code: 406,
|
|
278
|
-
message: 'NOT_ACCEPTABLE',
|
|
279
|
-
},
|
|
280
|
-
},
|
|
281
|
-
};
|
|
282
|
-
axios.post.mockImplementationOnce(async () => {
|
|
283
|
-
return responseToken;
|
|
284
|
-
});
|
|
285
|
-
|
|
286
|
-
const spyToastSuccess = jest.spyOn(ToastBottomHelper, 'success');
|
|
287
|
-
const spyToastError = jest.spyOn(ToastBottomHelper, 'error');
|
|
288
|
-
|
|
289
|
-
await act(async () => {
|
|
290
|
-
tree = await create(<AddLGDevice route={route} />);
|
|
291
|
-
});
|
|
292
|
-
const instance = tree.root;
|
|
293
|
-
const groupCheckBox = instance.findByType(GroupCheckBox);
|
|
294
|
-
await act(async () => {
|
|
295
|
-
groupCheckBox.props.onSelect({ id: 2 }); // select stationId
|
|
296
|
-
});
|
|
297
|
-
|
|
298
|
-
const viewButtonBottom = instance.findByType(ViewButtonBottom);
|
|
299
|
-
await act(async () => {
|
|
300
|
-
viewButtonBottom.props.onRightClick();
|
|
301
|
-
});
|
|
302
|
-
|
|
303
|
-
expect(axios.get).toHaveBeenCalledTimes(1);
|
|
304
|
-
expect(axios.post).toHaveBeenCalledTimes(1); // called once
|
|
305
|
-
expect(spyToastSuccess).not.toBeCalled();
|
|
306
|
-
expect(spyToastError).toBeCalled();
|
|
307
|
-
expect(mockedNavigate).toHaveBeenCalledWith(Routes.Dashboard);
|
|
308
|
-
|
|
309
|
-
spyToastSuccess.mockReset();
|
|
310
|
-
spyToastSuccess.mockRestore();
|
|
311
|
-
});
|
|
312
|
-
|
|
313
|
-
test('ViewButtonBottom onRightClick with stationId but get token failed, not success', async () => {
|
|
314
|
-
const response = {
|
|
315
|
-
status: 200,
|
|
316
|
-
data: {
|
|
317
|
-
id: 1,
|
|
318
|
-
name: 'Unit name',
|
|
319
|
-
stations: [{ id: 2, name: 'Station name' }],
|
|
320
|
-
},
|
|
321
|
-
};
|
|
322
|
-
axios.get.mockImplementation(async () => {
|
|
323
|
-
return response;
|
|
324
|
-
});
|
|
325
|
-
|
|
326
|
-
const responseToken = {
|
|
327
|
-
data: {},
|
|
328
|
-
};
|
|
329
|
-
axios.post.mockImplementationOnce(async () => {
|
|
330
|
-
return responseToken;
|
|
331
|
-
});
|
|
332
|
-
|
|
333
|
-
const spyToastSuccess = jest.spyOn(ToastBottomHelper, 'success');
|
|
334
|
-
const spyToastError = jest.spyOn(ToastBottomHelper, 'error');
|
|
335
|
-
|
|
336
|
-
await act(async () => {
|
|
337
|
-
tree = await create(<AddLGDevice route={route} />);
|
|
338
|
-
});
|
|
339
|
-
const instance = tree.root;
|
|
340
|
-
const groupCheckBox = instance.findByType(GroupCheckBox);
|
|
341
|
-
await act(async () => {
|
|
342
|
-
groupCheckBox.props.onSelect({ id: 2 }); // select stationId
|
|
343
|
-
});
|
|
344
|
-
|
|
345
|
-
const viewButtonBottom = instance.findByType(ViewButtonBottom);
|
|
346
|
-
await act(async () => {
|
|
347
|
-
viewButtonBottom.props.onRightClick();
|
|
348
|
-
});
|
|
349
|
-
|
|
350
|
-
expect(axios.get).toHaveBeenCalledTimes(1);
|
|
351
|
-
expect(axios.post).toHaveBeenCalledTimes(1); // called once
|
|
352
|
-
expect(spyToastSuccess).not.toBeCalled();
|
|
353
|
-
expect(spyToastError).toBeCalled();
|
|
354
|
-
expect(mockedNavigate).toHaveBeenCalledWith(Routes.Dashboard);
|
|
355
|
-
|
|
356
|
-
spyToastSuccess.mockReset();
|
|
357
|
-
spyToastSuccess.mockRestore();
|
|
358
|
-
});
|
|
359
|
-
});
|