@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
|
@@ -23,6 +23,7 @@ import WaterQualityGuide from '../screens/WaterQualityGuide';
|
|
|
23
23
|
import DeviceInfo from '../screens/DeviceInfo';
|
|
24
24
|
import AddNewOneTap from '../screens/AddNewOneTap';
|
|
25
25
|
import AddNewScriptAction from '../screens/AddNewScriptAction';
|
|
26
|
+
import AddNewAutoSmart from '../screens/AddNewAutoSmart';
|
|
26
27
|
import PlaybackCamera from '../screens/PlayBackCamera';
|
|
27
28
|
import AllCamera from '../screens/AllCamera';
|
|
28
29
|
import ManageAccessScreen from '../screens/ManageAccess';
|
|
@@ -30,6 +31,7 @@ import GuestInfo from '../screens/GuestInfo';
|
|
|
30
31
|
import ScriptDetail from '../screens/ScriptDetail';
|
|
31
32
|
import EditActionsList from '../screens/EditActionsList';
|
|
32
33
|
import SelectDevice from '../screens/AddNewAction/SelectDevice';
|
|
34
|
+
import SelectAction from '../screens/AddNewAction/SelectAction';
|
|
33
35
|
|
|
34
36
|
import _ from 'lodash';
|
|
35
37
|
|
|
@@ -194,6 +196,13 @@ export const UnitStack = memo((props) => {
|
|
|
194
196
|
headerShown: false,
|
|
195
197
|
}}
|
|
196
198
|
/>
|
|
199
|
+
<Stack.Screen
|
|
200
|
+
name={Route.AddNewAutoSmart}
|
|
201
|
+
component={AddNewAutoSmart}
|
|
202
|
+
options={{
|
|
203
|
+
headerShown: false,
|
|
204
|
+
}}
|
|
205
|
+
/>
|
|
197
206
|
<Stack.Screen
|
|
198
207
|
name={Route.ScriptDetail}
|
|
199
208
|
component={ScriptDetail}
|
|
@@ -220,6 +229,11 @@ export const UnitStack = memo((props) => {
|
|
|
220
229
|
component={SelectDevice}
|
|
221
230
|
options={{ headerShown: false }}
|
|
222
231
|
/>
|
|
232
|
+
<Stack.Screen
|
|
233
|
+
name={Route.SelectAction}
|
|
234
|
+
component={SelectAction}
|
|
235
|
+
options={{ headerShown: false }}
|
|
236
|
+
/>
|
|
223
237
|
</Stack.Navigator>
|
|
224
238
|
);
|
|
225
239
|
});
|
|
@@ -5,6 +5,14 @@ import { act, create } from 'react-test-renderer';
|
|
|
5
5
|
import AQIGuide from '..';
|
|
6
6
|
import Text from '../../../commons/Text';
|
|
7
7
|
import { TESTID } from '../../../configs/Constants';
|
|
8
|
+
import { SCProvider } from '../../../context';
|
|
9
|
+
import { mockSCStore } from '../../../context/mockStore';
|
|
10
|
+
|
|
11
|
+
const wrapComponent = () => (
|
|
12
|
+
<SCProvider initState={mockSCStore({})}>
|
|
13
|
+
<AQIGuide />
|
|
14
|
+
</SCProvider>
|
|
15
|
+
);
|
|
8
16
|
|
|
9
17
|
jest.mock('react-redux', () => ({
|
|
10
18
|
...jest.requireActual('react-redux'),
|
|
@@ -29,7 +37,7 @@ describe('test AQIGuide', () => {
|
|
|
29
37
|
test('render', async () => {
|
|
30
38
|
let tree;
|
|
31
39
|
act(() => {
|
|
32
|
-
tree = create(
|
|
40
|
+
tree = create(wrapComponent());
|
|
33
41
|
});
|
|
34
42
|
|
|
35
43
|
const instance = tree.root;
|
|
@@ -21,9 +21,9 @@ import SvgVeryTired from '../../../assets/images/Feeling/very-tired.svg';
|
|
|
21
21
|
import { useSCContextSelector } from '../../context';
|
|
22
22
|
|
|
23
23
|
const AQIGuide = memo(() => {
|
|
24
|
+
const t = useTranslations();
|
|
24
25
|
useTitleHeader(t('AQI Guide'));
|
|
25
26
|
const language = useSCContextSelector((state) => state.language);
|
|
26
|
-
const t = useTranslations();
|
|
27
27
|
const data = useMemo(
|
|
28
28
|
() => ({
|
|
29
29
|
titles: [
|
|
@@ -4,6 +4,8 @@ import { create } from 'react-test-renderer';
|
|
|
4
4
|
import { act } from '@testing-library/react-hooks';
|
|
5
5
|
import ActivityLog from '../';
|
|
6
6
|
import { Constants } from '../../../configs';
|
|
7
|
+
import { SCProvider } from '../../../context';
|
|
8
|
+
import { mockSCStore } from '../../../context/mockStore';
|
|
7
9
|
|
|
8
10
|
const mockUseSelector = jest.fn();
|
|
9
11
|
const mockSetState = jest.fn();
|
|
@@ -34,41 +36,28 @@ jest.mock('@react-navigation/core', () => {
|
|
|
34
36
|
|
|
35
37
|
jest.mock('axios');
|
|
36
38
|
|
|
39
|
+
const wrapComponent = () => (
|
|
40
|
+
<SCProvider initState={mockSCStore({})}>
|
|
41
|
+
<ActivityLog />
|
|
42
|
+
</SCProvider>
|
|
43
|
+
);
|
|
44
|
+
|
|
37
45
|
describe('Test Activity log', () => {
|
|
38
46
|
let tree;
|
|
39
47
|
Date.now = jest.fn(() => new Date('2021-07-02T15:48:24.917932Z'));
|
|
40
|
-
const data = [
|
|
41
|
-
{
|
|
42
|
-
date: '02/07/2021',
|
|
43
|
-
data: [
|
|
44
|
-
{
|
|
45
|
-
id: 2,
|
|
46
|
-
action: 'Gara Up',
|
|
47
|
-
name: 'Kevin Love',
|
|
48
|
-
created_at: '2021-07-01T15:48:24.917932Z',
|
|
49
|
-
},
|
|
50
|
-
{
|
|
51
|
-
id: 1,
|
|
52
|
-
action: 'Gara Down',
|
|
53
|
-
name: 'Stephen Holloway',
|
|
54
|
-
created_at: '2021-07-01T15:48:24.791769Z',
|
|
55
|
-
},
|
|
56
|
-
],
|
|
57
|
-
},
|
|
58
|
-
];
|
|
59
48
|
|
|
60
49
|
afterEach(() => {
|
|
61
50
|
mockSetState.mockClear();
|
|
62
51
|
});
|
|
63
52
|
|
|
64
|
-
it('render empty list', () => {
|
|
53
|
+
it('render empty list', async () => {
|
|
65
54
|
useState.mockImplementationOnce((init) => [init, mockSetState]);
|
|
66
55
|
useState.mockImplementationOnce((init) => [init, mockSetState]);
|
|
67
56
|
useState.mockImplementationOnce((init) => [init, mockSetState]);
|
|
68
57
|
useState.mockImplementationOnce((init) => [false, mockSetState]);
|
|
69
58
|
useState.mockImplementationOnce((init) => [false, mockSetState]);
|
|
70
|
-
act(() => {
|
|
71
|
-
tree = create(
|
|
59
|
+
await act(() => {
|
|
60
|
+
tree = create(wrapComponent());
|
|
72
61
|
});
|
|
73
62
|
const instance = tree.root;
|
|
74
63
|
const SectionListElement = instance.findAllByType(SectionList);
|
|
@@ -81,28 +70,14 @@ describe('Test Activity log', () => {
|
|
|
81
70
|
});
|
|
82
71
|
});
|
|
83
72
|
|
|
84
|
-
it('render
|
|
85
|
-
useState.mockImplementationOnce((init) => [data, mockSetState]);
|
|
86
|
-
useState.mockImplementationOnce((init) => [false, mockSetState]);
|
|
87
|
-
useState.mockImplementationOnce((init) => [init, mockSetState]);
|
|
88
|
-
useState.mockImplementationOnce((init) => [false, mockSetState]);
|
|
89
|
-
useState.mockImplementationOnce((init) => [false, mockSetState]);
|
|
90
|
-
act(() => {
|
|
91
|
-
tree = create(<ActivityLog />);
|
|
92
|
-
});
|
|
93
|
-
const instance = tree.root;
|
|
94
|
-
const SectionListElement = instance.findAllByType(SectionList);
|
|
95
|
-
expect(SectionListElement).toHaveLength(1);
|
|
96
|
-
});
|
|
97
|
-
|
|
98
|
-
it('render ActivityIndicator', () => {
|
|
73
|
+
it('render ActivityIndicator', async () => {
|
|
99
74
|
useState.mockImplementationOnce((init) => [[], mockSetState]);
|
|
100
75
|
useState.mockImplementationOnce((init) => [true, mockSetState]);
|
|
101
76
|
useState.mockImplementationOnce((init) => [init, mockSetState]);
|
|
102
77
|
useState.mockImplementationOnce((init) => [false, mockSetState]);
|
|
103
78
|
useState.mockImplementationOnce((init) => [false, mockSetState]);
|
|
104
|
-
act(() => {
|
|
105
|
-
tree = create(
|
|
79
|
+
await act(() => {
|
|
80
|
+
tree = create(wrapComponent());
|
|
106
81
|
});
|
|
107
82
|
const instance = tree.root;
|
|
108
83
|
const ActivityIndicatorElement = instance.findAllByType(ActivityIndicator);
|
|
@@ -56,8 +56,8 @@ const AddCommonSelectSubUnit = ({ route }) => {
|
|
|
56
56
|
switch (addType) {
|
|
57
57
|
case 'AddNewGateway':
|
|
58
58
|
navigation.navigate(Routes.ScanChipQR, {
|
|
59
|
-
station: subUnits[selectedIndex]
|
|
60
|
-
unit_name: unit
|
|
59
|
+
station: subUnits[selectedIndex]?.id,
|
|
60
|
+
unit_name: unit?.name,
|
|
61
61
|
...route.params,
|
|
62
62
|
});
|
|
63
63
|
break;
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import renderer, { act } from 'react-test-renderer';
|
|
3
|
+
|
|
4
|
+
import AddCommonSelectSubUnit from '../SelectSubUnit';
|
|
5
|
+
import { ViewButtonBottom } from '../../../commons';
|
|
6
|
+
import { SCProvider } from '../../../context';
|
|
7
|
+
import { mockSCStore } from '../../../context/mockStore';
|
|
8
|
+
|
|
9
|
+
jest.mock('axios');
|
|
10
|
+
|
|
11
|
+
const mockedGoBack = jest.fn();
|
|
12
|
+
const mockedNavigate = jest.fn();
|
|
13
|
+
jest.mock('@react-navigation/native', () => {
|
|
14
|
+
return {
|
|
15
|
+
...jest.requireActual('@react-navigation/native'),
|
|
16
|
+
useNavigation: () => ({
|
|
17
|
+
navigate: mockedNavigate,
|
|
18
|
+
goBack: mockedGoBack,
|
|
19
|
+
}),
|
|
20
|
+
useIsFocused: () => ({}),
|
|
21
|
+
};
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
const wrapComponent = (route) => (
|
|
25
|
+
<SCProvider initState={mockSCStore({})}>
|
|
26
|
+
<AddCommonSelectSubUnit route={route} />
|
|
27
|
+
</SCProvider>
|
|
28
|
+
);
|
|
29
|
+
|
|
30
|
+
describe('Test SelectSubUnit', () => {
|
|
31
|
+
beforeEach(() => {
|
|
32
|
+
mockedNavigate.mockClear();
|
|
33
|
+
mockedGoBack.mockClear();
|
|
34
|
+
});
|
|
35
|
+
let tree;
|
|
36
|
+
test('test ViewButtonBottom leftClick', async () => {
|
|
37
|
+
const route = { params: { addType: 'AddNewGateway' } };
|
|
38
|
+
await act(async () => {
|
|
39
|
+
tree = renderer.create(wrapComponent(route));
|
|
40
|
+
});
|
|
41
|
+
const instance = tree.root;
|
|
42
|
+
const viewButtonBottom = instance.findByType(ViewButtonBottom);
|
|
43
|
+
act(() => {
|
|
44
|
+
viewButtonBottom.props.onLeftClick();
|
|
45
|
+
});
|
|
46
|
+
expect(mockedGoBack).toHaveBeenCalled();
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
test('test ViewButtonBottom onRightClick', async () => {
|
|
50
|
+
const route = { params: { addType: 'AddNewGateway' } };
|
|
51
|
+
await act(async () => {
|
|
52
|
+
tree = renderer.create(wrapComponent(route));
|
|
53
|
+
});
|
|
54
|
+
const instance = tree.root;
|
|
55
|
+
const viewButtonBottom = instance.findByType(ViewButtonBottom);
|
|
56
|
+
act(() => {
|
|
57
|
+
viewButtonBottom.props.onRightClick();
|
|
58
|
+
});
|
|
59
|
+
expect(mockedNavigate).toHaveBeenCalled();
|
|
60
|
+
});
|
|
61
|
+
});
|
|
@@ -6,6 +6,8 @@ import axios from 'axios';
|
|
|
6
6
|
import AddCommonSelectUnit from '../SelectUnit';
|
|
7
7
|
import Text from '../../../commons/Text';
|
|
8
8
|
import { TESTID } from '../../../configs/Constants';
|
|
9
|
+
import { SCProvider } from '../../../context';
|
|
10
|
+
import { mockSCStore } from '../../../context/mockStore';
|
|
9
11
|
|
|
10
12
|
jest.mock('axios');
|
|
11
13
|
|
|
@@ -21,6 +23,12 @@ jest.mock('@react-navigation/native', () => {
|
|
|
21
23
|
};
|
|
22
24
|
});
|
|
23
25
|
|
|
26
|
+
const wrapComponent = (route) => (
|
|
27
|
+
<SCProvider initState={mockSCStore({})}>
|
|
28
|
+
<AddCommonSelectUnit route={route} />
|
|
29
|
+
</SCProvider>
|
|
30
|
+
);
|
|
31
|
+
|
|
24
32
|
describe('Test SelectUnit container', () => {
|
|
25
33
|
beforeEach(() => {
|
|
26
34
|
mockedNavigate.mockClear();
|
|
@@ -29,17 +37,17 @@ describe('Test SelectUnit container', () => {
|
|
|
29
37
|
let tree;
|
|
30
38
|
const list_type = ['AddSubUnit', 'AddDevice', 'AddMember', 'AddLGDevice', ''];
|
|
31
39
|
const result = [
|
|
32
|
-
'
|
|
33
|
-
'
|
|
34
|
-
'
|
|
35
|
-
'
|
|
36
|
-
'
|
|
40
|
+
'Add new sub-unit',
|
|
41
|
+
'Add new device',
|
|
42
|
+
'Select a unit',
|
|
43
|
+
'Select a unit',
|
|
44
|
+
'Add new sub-unit',
|
|
37
45
|
];
|
|
38
46
|
list_type.forEach(function (type, i) {
|
|
39
47
|
test(`create SelectUnit ${type} container`, () => {
|
|
40
48
|
const route = { params: { addType: type } };
|
|
41
49
|
act(() => {
|
|
42
|
-
tree = renderer.create(
|
|
50
|
+
tree = renderer.create(wrapComponent(route));
|
|
43
51
|
});
|
|
44
52
|
const instance = tree.root;
|
|
45
53
|
const button = instance.findAllByType(TouchableOpacity);
|
|
@@ -76,7 +84,7 @@ describe('Test SelectUnit container', () => {
|
|
|
76
84
|
});
|
|
77
85
|
|
|
78
86
|
await act(async () => {
|
|
79
|
-
tree = renderer.create(
|
|
87
|
+
tree = renderer.create(wrapComponent(route));
|
|
80
88
|
});
|
|
81
89
|
|
|
82
90
|
const instance = tree.root;
|
|
@@ -149,7 +157,7 @@ describe('test single SelectUnit', () => {
|
|
|
149
157
|
});
|
|
150
158
|
|
|
151
159
|
await act(async () => {
|
|
152
|
-
tree = renderer.create(
|
|
160
|
+
tree = renderer.create(wrapComponent(route));
|
|
153
161
|
});
|
|
154
162
|
|
|
155
163
|
const instance = tree.root;
|
|
@@ -190,7 +198,7 @@ describe('test single SelectUnit', () => {
|
|
|
190
198
|
});
|
|
191
199
|
|
|
192
200
|
await act(async () => {
|
|
193
|
-
tree = renderer.create(
|
|
201
|
+
tree = renderer.create(wrapComponent(route));
|
|
194
202
|
});
|
|
195
203
|
|
|
196
204
|
const instance = tree.root;
|
|
@@ -209,7 +217,7 @@ describe('test single SelectUnit', () => {
|
|
|
209
217
|
test('click goBack', async () => {
|
|
210
218
|
const route = { params: { addType: 'AddSubUnit' } };
|
|
211
219
|
await act(async () => {
|
|
212
|
-
tree = renderer.create(
|
|
220
|
+
tree = renderer.create(wrapComponent(route));
|
|
213
221
|
});
|
|
214
222
|
|
|
215
223
|
const instance = tree.root;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import renderer, { act } from 'react-test-renderer';
|
|
3
|
+
import { TouchableWithoutFeedback } from 'react-native';
|
|
4
|
+
|
|
5
|
+
import Device from '..';
|
|
6
|
+
import { SCProvider } from '../../../../context';
|
|
7
|
+
import { mockSCStore } from '../../../../context/mockStore';
|
|
8
|
+
|
|
9
|
+
const wrapComponent = (svgMain, sensor, title, isSelectDevice, onPress) => (
|
|
10
|
+
<SCProvider initState={mockSCStore({})}>
|
|
11
|
+
<Device
|
|
12
|
+
svgMain={svgMain}
|
|
13
|
+
title={title}
|
|
14
|
+
sensor={sensor}
|
|
15
|
+
isSelectDevice={isSelectDevice}
|
|
16
|
+
onPress={onPress}
|
|
17
|
+
/>
|
|
18
|
+
</SCProvider>
|
|
19
|
+
);
|
|
20
|
+
|
|
21
|
+
describe('Test SelectDevice', () => {
|
|
22
|
+
let tree;
|
|
23
|
+
|
|
24
|
+
test('onPressDevice', () => {
|
|
25
|
+
const sensor = { id: 1, name: 'sensor', icon_kit: 'icon_kit' };
|
|
26
|
+
const mockFuntion = jest.fn();
|
|
27
|
+
act(() => {
|
|
28
|
+
tree = renderer.create(
|
|
29
|
+
wrapComponent(sensor.icon_kit, sensor, sensor.name, true, mockFuntion)
|
|
30
|
+
);
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
const instance = tree.root;
|
|
34
|
+
const touchableWithoutFeedback = instance.findByType(
|
|
35
|
+
TouchableWithoutFeedback
|
|
36
|
+
);
|
|
37
|
+
act(() => {
|
|
38
|
+
touchableWithoutFeedback.props.onPress();
|
|
39
|
+
});
|
|
40
|
+
expect(mockFuntion).toHaveBeenCalledWith(sensor);
|
|
41
|
+
});
|
|
42
|
+
});
|
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
import React, {
|
|
2
|
+
memo,
|
|
3
|
+
useCallback,
|
|
4
|
+
useEffect,
|
|
5
|
+
useState,
|
|
6
|
+
useContext,
|
|
7
|
+
} from 'react';
|
|
8
|
+
import { ScrollView, View } from 'react-native';
|
|
9
|
+
import { useNavigation } from '@react-navigation/native';
|
|
10
|
+
|
|
11
|
+
import { useTranslations } from '../../hooks/Common/useTranslations';
|
|
12
|
+
import { SCContext } from '../../context';
|
|
13
|
+
import { Action } from '../../context/actionType';
|
|
14
|
+
import { HeaderCustom } from '../../commons/Header';
|
|
15
|
+
import BottomButtonView from '../../commons/BottomButtonView';
|
|
16
|
+
import Text from '../../commons/Text';
|
|
17
|
+
import ActionTemplate from '../../commons/ActionTemplate';
|
|
18
|
+
import { axiosGet, axiosPost } from '../../utils/Apis/axios';
|
|
19
|
+
import { API } from '../../configs';
|
|
20
|
+
import { TESTID } from '../../configs/Constants';
|
|
21
|
+
import Routes from '../../utils/Route';
|
|
22
|
+
import styles from './Styles/SelectActionStyles';
|
|
23
|
+
import moment from 'moment';
|
|
24
|
+
|
|
25
|
+
const SelectAction = memo(({ route }) => {
|
|
26
|
+
const t = useTranslations();
|
|
27
|
+
const { navigate } = useNavigation();
|
|
28
|
+
const { unit, device, stationName, automateId, scriptName } = route.params;
|
|
29
|
+
const { setAction } = useContext(SCContext);
|
|
30
|
+
const [data, setData] = useState([]);
|
|
31
|
+
const [actions, setActions] = useState({
|
|
32
|
+
name: '',
|
|
33
|
+
action: '',
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
const fetchData = useCallback(async () => {
|
|
37
|
+
const { success, data } = await axiosGet(
|
|
38
|
+
API.SENSOR.DISPLAY_ACTIONS(device.id),
|
|
39
|
+
{},
|
|
40
|
+
true
|
|
41
|
+
);
|
|
42
|
+
if (success) {
|
|
43
|
+
setData(data);
|
|
44
|
+
}
|
|
45
|
+
}, [device.id]);
|
|
46
|
+
|
|
47
|
+
const onSave = useCallback(async () => {
|
|
48
|
+
if (automateId) {
|
|
49
|
+
const { success } = await axiosPost(
|
|
50
|
+
API.AUTOMATE.ADD_SCRIPT_ACTION(automateId),
|
|
51
|
+
{
|
|
52
|
+
action: actions.action,
|
|
53
|
+
}
|
|
54
|
+
);
|
|
55
|
+
if (success) {
|
|
56
|
+
navigate(Routes.ScriptDetail, {
|
|
57
|
+
id: automateId,
|
|
58
|
+
name: scriptName,
|
|
59
|
+
havePermission: true,
|
|
60
|
+
unit,
|
|
61
|
+
dateNow: moment().valueOf(), // TODO will remove dateNow later
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
} else {
|
|
65
|
+
setAction(Action.LIST_ACTION, {
|
|
66
|
+
action: actions.action,
|
|
67
|
+
unit_name: unit.name,
|
|
68
|
+
action_name: actions.name,
|
|
69
|
+
sensor_name: device.name,
|
|
70
|
+
sensor_icon_kit: device.icon_kit,
|
|
71
|
+
station_name: stationName,
|
|
72
|
+
});
|
|
73
|
+
navigate(Routes.AddNewScriptAction, {
|
|
74
|
+
automateType: 'one-tap',
|
|
75
|
+
name: scriptName,
|
|
76
|
+
unit,
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
}, [
|
|
80
|
+
actions.action,
|
|
81
|
+
actions.name,
|
|
82
|
+
automateId,
|
|
83
|
+
device.icon_kit,
|
|
84
|
+
device.name,
|
|
85
|
+
navigate,
|
|
86
|
+
scriptName,
|
|
87
|
+
setAction,
|
|
88
|
+
stationName,
|
|
89
|
+
unit,
|
|
90
|
+
]);
|
|
91
|
+
|
|
92
|
+
useEffect(() => {
|
|
93
|
+
fetchData();
|
|
94
|
+
}, [fetchData]);
|
|
95
|
+
|
|
96
|
+
const handleOnSelectAction = (action) => {
|
|
97
|
+
setActions({ ...action });
|
|
98
|
+
};
|
|
99
|
+
|
|
100
|
+
const RenderActionItem = ({ data }) => {
|
|
101
|
+
const actionTemplate = [];
|
|
102
|
+
|
|
103
|
+
data.forEach((item) => {
|
|
104
|
+
switch (item.template) {
|
|
105
|
+
case 'on_off_button_action_template':
|
|
106
|
+
case 'one_button_action_template':
|
|
107
|
+
case 'three_button_action_template':
|
|
108
|
+
actionTemplate.push(item);
|
|
109
|
+
break;
|
|
110
|
+
}
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
return (
|
|
114
|
+
<>
|
|
115
|
+
{actionTemplate.length > 0 && (
|
|
116
|
+
<ActionTemplate
|
|
117
|
+
action={actions}
|
|
118
|
+
data={actionTemplate}
|
|
119
|
+
onSelectAction={handleOnSelectAction}
|
|
120
|
+
/>
|
|
121
|
+
)}
|
|
122
|
+
</>
|
|
123
|
+
);
|
|
124
|
+
};
|
|
125
|
+
|
|
126
|
+
return (
|
|
127
|
+
<View style={styles.wrap}>
|
|
128
|
+
<HeaderCustom isShowClose />
|
|
129
|
+
<ScrollView
|
|
130
|
+
style={styles.wrap}
|
|
131
|
+
contentContainerStyle={styles.contentContainerStyle}
|
|
132
|
+
>
|
|
133
|
+
<Text bold type="H2" style={styles.title}>
|
|
134
|
+
{t('set_up {name}', {
|
|
135
|
+
name: device.name,
|
|
136
|
+
})}
|
|
137
|
+
</Text>
|
|
138
|
+
|
|
139
|
+
<RenderActionItem data={data} testID={TESTID.ACTION_ITEM} />
|
|
140
|
+
</ScrollView>
|
|
141
|
+
|
|
142
|
+
<BottomButtonView
|
|
143
|
+
style={styles.bottomButtonView}
|
|
144
|
+
mainTitle={t('save')}
|
|
145
|
+
onPressMain={onSave}
|
|
146
|
+
typeMain={actions?.action ? 'primary' : 'disabled'}
|
|
147
|
+
/>
|
|
148
|
+
</View>
|
|
149
|
+
);
|
|
150
|
+
});
|
|
151
|
+
|
|
152
|
+
export default SelectAction;
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import React, { memo, useState, useEffect, useCallback } from 'react';
|
|
2
2
|
import { ScrollView, View } from 'react-native';
|
|
3
|
-
import {
|
|
3
|
+
import { useNavigation } from '@react-navigation/native';
|
|
4
|
+
|
|
5
|
+
import { useTranslations } from '../../hooks/Common/useTranslations';
|
|
4
6
|
import Text from '../../commons/Text';
|
|
5
7
|
import NavBar from '../../commons/NavBar';
|
|
6
8
|
import { fetchWithCache } from '../../utils/Apis/axios';
|
|
@@ -8,27 +10,30 @@ import { API } from '../../configs';
|
|
|
8
10
|
import Device from './Device';
|
|
9
11
|
import BottomButtonView from '../../commons/BottomButtonView';
|
|
10
12
|
import { HeaderCustom } from '../../commons/Header';
|
|
13
|
+
import Routes from '../../utils/Route';
|
|
11
14
|
import styles from './Styles/SelectDeviceStyles';
|
|
12
15
|
|
|
13
16
|
const SelectDevice = memo(({ route }) => {
|
|
14
|
-
const
|
|
17
|
+
const t = useTranslations();
|
|
18
|
+
const { unit, automateId, scriptName } = route.params;
|
|
15
19
|
|
|
16
20
|
const [listStation, setListStation] = useState([]);
|
|
17
21
|
const [listMenuItem, setListMenuItem] = useState([]);
|
|
18
22
|
const [indexStation, setIndexStation] = useState(0);
|
|
19
23
|
const [station, setStation] = useState([]);
|
|
20
|
-
const [
|
|
24
|
+
const [selectedDevice, setSelectedDevice] = useState();
|
|
25
|
+
const { navigate } = useNavigation();
|
|
21
26
|
|
|
22
27
|
const onSnapToItem = useCallback(
|
|
23
28
|
(item, index) => {
|
|
24
29
|
setIndexStation(index);
|
|
25
30
|
},
|
|
26
31
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
27
|
-
[
|
|
32
|
+
[unit.id, indexStation]
|
|
28
33
|
);
|
|
29
34
|
|
|
30
35
|
const fetchDetails = useCallback(async () => {
|
|
31
|
-
await fetchWithCache(API.UNIT.DEVICE_CONTROL(
|
|
36
|
+
await fetchWithCache(API.UNIT.DEVICE_CONTROL(unit.id), {}, (response) => {
|
|
32
37
|
const { success, data } = response;
|
|
33
38
|
|
|
34
39
|
if (success) {
|
|
@@ -42,22 +47,28 @@ const SelectDevice = memo(({ route }) => {
|
|
|
42
47
|
setListStation(listMenu.concat([{ text: '' }]));
|
|
43
48
|
}
|
|
44
49
|
});
|
|
45
|
-
}, [
|
|
50
|
+
}, [unit.id]);
|
|
46
51
|
|
|
47
52
|
useEffect(() => {
|
|
48
53
|
fetchDetails();
|
|
49
54
|
}, [fetchDetails]);
|
|
50
55
|
|
|
51
56
|
const onPressDevice = (sensor) => {
|
|
52
|
-
if (
|
|
53
|
-
|
|
57
|
+
if (selectedDevice && selectedDevice.id === sensor.id) {
|
|
58
|
+
setSelectedDevice(false);
|
|
54
59
|
} else {
|
|
55
|
-
|
|
60
|
+
setSelectedDevice(sensor);
|
|
56
61
|
}
|
|
57
62
|
};
|
|
58
63
|
|
|
59
64
|
const onPressContinue = () => {
|
|
60
|
-
|
|
65
|
+
navigate(Routes.SelectAction, {
|
|
66
|
+
unit,
|
|
67
|
+
device: selectedDevice,
|
|
68
|
+
automateId: automateId,
|
|
69
|
+
stationName: station[indexStation]?.name,
|
|
70
|
+
scriptName,
|
|
71
|
+
});
|
|
61
72
|
};
|
|
62
73
|
|
|
63
74
|
return (
|
|
@@ -87,7 +98,9 @@ const SelectDevice = memo(({ route }) => {
|
|
|
87
98
|
svgMain={sensor.icon || 'sensor'}
|
|
88
99
|
title={sensor.name}
|
|
89
100
|
sensor={sensor}
|
|
90
|
-
isSelectDevice={
|
|
101
|
+
isSelectDevice={
|
|
102
|
+
selectedDevice && selectedDevice.id === sensor.id
|
|
103
|
+
}
|
|
91
104
|
onPress={onPressDevice}
|
|
92
105
|
/>
|
|
93
106
|
))}
|
|
@@ -98,6 +111,7 @@ const SelectDevice = memo(({ route }) => {
|
|
|
98
111
|
style={styles.bottomButtonView}
|
|
99
112
|
mainTitle={t('continue')}
|
|
100
113
|
onPressMain={onPressContinue}
|
|
114
|
+
typeMain={selectedDevice ? 'primary' : 'disabled'}
|
|
101
115
|
/>
|
|
102
116
|
</View>
|
|
103
117
|
);
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { StyleSheet } from 'react-native';
|
|
2
|
+
import { getBottomSpace } from 'react-native-iphone-x-helper';
|
|
3
|
+
import { Colors } from '../../../configs';
|
|
4
|
+
|
|
5
|
+
export default StyleSheet.create({
|
|
6
|
+
wrap: {
|
|
7
|
+
flex: 1,
|
|
8
|
+
backgroundColor: Colors.White,
|
|
9
|
+
},
|
|
10
|
+
title: {
|
|
11
|
+
marginHorizontal: 16,
|
|
12
|
+
},
|
|
13
|
+
contentContainerStyle: {
|
|
14
|
+
paddingBottom: getBottomSpace() + 100,
|
|
15
|
+
},
|
|
16
|
+
bottomButtonView: {
|
|
17
|
+
paddingTop: 24,
|
|
18
|
+
paddingBottom: 32,
|
|
19
|
+
|
|
20
|
+
backgroundColor: Colors.White,
|
|
21
|
+
borderColor: Colors.ShadownTransparent,
|
|
22
|
+
borderTopWidth: 1,
|
|
23
|
+
},
|
|
24
|
+
});
|