@eohjsc/react-native-smart-city 0.3.48 → 0.3.49
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +4 -4
- package/src/Images/DevMode/file_copy.svg +3 -0
- package/src/Images/DevMode/inforCode.png +0 -0
- package/src/Images/DevMode/inforCode@2x.png +0 -0
- package/src/Images/DevMode/inforCode@3x.png +0 -0
- package/src/commons/Action/__test__/ItemQuickAction.test.js +0 -7
- package/src/commons/ActionGroup/__test__/ColorPickerTemplate.test.js +1 -8
- package/src/commons/ActionGroup/__test__/OnOffTemplate.test.js +1 -1
- package/src/commons/ActionGroup/__test__/SliderRangeTemplate.test.js +1 -8
- package/src/commons/ActionTemplate/__test__/index.test.js +0 -7
- package/src/commons/Dashboard/MyPinnedSharedUnit/index.js +3 -3
- package/src/commons/Dashboard/MyUnit/__test__/MyUnit.test.js +1 -1
- package/src/commons/Dashboard/MyUnit/index.js +30 -4
- package/src/commons/DevMode/Styles/ItemStyles.js +1 -1
- package/src/commons/Device/PMSensor/PMSensorIndicatior.js +2 -1
- package/src/commons/FourButtonFilterHistory/__test__/FourButtonFilterHistory.test.js +0 -7
- package/src/commons/Header/HeaderCustom.js +13 -6
- package/src/commons/MediaPlayer/__test__/index.test.js +0 -7
- package/src/commons/MediaPlayerDetail/__test__/MediaPlayerFull.test.js +0 -1
- package/src/commons/MenuActionMore/index.js +4 -1
- package/src/commons/NavBar/index.js +1 -1
- package/src/commons/OneTapTemplate/OptionsDropdownActionTemplate.js +1 -1
- package/src/commons/OneTapTemplate/__test__/NumberUpDownActionTemplate.test.js +0 -7
- package/src/commons/OneTapTemplate/__test__/OptionsDropdownActionTemplate.test.js +0 -7
- package/src/commons/OneTapTemplate/__test__/StatesGridActionTemplate.test.js +0 -7
- package/src/commons/RowItem/index.js +6 -1
- package/src/commons/SelectUnit/index.js +4 -1
- package/src/commons/StatusBox/styles.js +8 -3
- package/src/commons/SubUnit/__test__/Favorites.test.js +0 -7
- package/src/commons/SubUnit/__test__/ShortDetail.test.js +0 -7
- package/src/commons/Tabbar/__test__/index.test.js +0 -7
- package/src/commons/Unit/__test__/HeaderUnit.test.js +0 -5
- package/src/commons/UnitSummary/ConfigHistoryChart/__test__/ConfigHistoryChart.test.js +0 -7
- package/src/configs/API.js +28 -0
- package/src/configs/AccessibilityLabel.js +13 -0
- package/src/configs/Colors.js +4 -0
- package/src/configs/Constants.js +6 -0
- package/src/configs/Images.js +1 -0
- package/src/context/actionType.ts +8 -1
- package/src/context/mockStore.ts +8 -2
- package/src/context/reducer.ts +27 -4
- package/src/hooks/IoT/__test__/useWatchConfigs.test.js +46 -0
- package/src/hooks/IoT/useBluetoothConnection.js +78 -4
- package/src/hooks/IoT/useBluetoothDeviceConnected.js +1 -1
- package/src/iot/RemoteControl/Bluetooth.js +0 -16
- package/src/iot/RemoteControl/__test__/Bluetooth.test.js +0 -25
- package/src/navigations/Main.js +39 -0
- package/src/navigations/UnitStack.js +18 -5
- package/src/screens/ActivityLog/__test__/FilterPopup.test.js +0 -7
- package/src/screens/ActivityLog/__test__/ItemLog.test.js +0 -7
- package/src/screens/ActivityLog/__test__/index.test.js +0 -7
- package/src/screens/AddLocationMaps/__test__/index.test.js +0 -7
- package/src/screens/AddNewAction/SelectAction.js +22 -18
- package/src/screens/AddNewAction/__test__/SelectAction.test.js +35 -16
- package/src/screens/AddNewAction/__test__/SelectSensorDevices.test.js +0 -7
- package/src/screens/AddNewDevice/__test__/AddNewDevice.test.js +0 -4
- package/src/screens/AddNewGateway/ConnectingZigbeeDevice.js +17 -4
- package/src/screens/AddNewGateway/__test__/AddNewGateway.test.js +0 -4
- package/src/screens/AddNewGateway/__test__/ConnectingModbusDevice.test.js +0 -4
- package/src/screens/AddNewGateway/__test__/ConnectingWifiDevice.test.js +0 -4
- package/src/screens/AddNewGateway/__test__/ConnectingZigbeeDevice.test.js +4 -7
- package/src/screens/AddNewGateway/__test__/RenameNewDevices.test.js +0 -7
- package/src/screens/AddNewGateway/__test__/SelectDeviceType.test.js +0 -4
- package/src/screens/AddNewGateway/__test__/SelectModbusGateway.test.js +0 -4
- package/src/screens/AddNewGateway/__test__/SelectZigbeeGateway.test.js +0 -4
- package/src/screens/AddNewOneTap/__test__/AddNewOneTap.test.js +0 -7
- package/src/screens/ConfirmUnitDeletion/__test__/ConfirmUnitDeletion.test.js +0 -1
- package/src/screens/Device/EditDevice/__test__/EditDevice.test.js +0 -7
- package/src/screens/Device/__test__/detail.test.js +1 -1
- package/src/screens/Device/detail.js +11 -3
- package/src/screens/Device/hooks/useDisconnectedDevice.js +26 -7
- package/src/screens/EmergencyContacts/__test__/hooks.test.js +79 -0
- package/src/screens/Gateway/DetailConfigActionModbus/__test__/index.test.js +138 -0
- package/src/screens/Gateway/DetailConfigActionModbus/index.js +180 -0
- package/src/screens/Gateway/DetailConfigActionModbus/styles.js +9 -0
- package/src/screens/Gateway/DetailConfigActionZigbee/__test__/index.test.js +73 -0
- package/src/screens/Gateway/DetailConfigActionZigbee/index.js +62 -0
- package/src/screens/Gateway/DetailConfigActionZigbee/styles.js +9 -0
- package/src/screens/Gateway/DeviceGatewayInfo/__test__/index.test.js +73 -0
- package/src/screens/Gateway/DeviceGatewayInfo/index.js +96 -0
- package/src/screens/Gateway/DeviceGatewayInfo/styles.js +9 -0
- package/src/screens/Gateway/DeviceModbusDetail/__test__/index.test.js +393 -0
- package/src/screens/Gateway/DeviceModbusDetail/index.js +176 -0
- package/src/screens/Gateway/DeviceModbusDetail/styles.js +12 -0
- package/src/screens/Gateway/DeviceZigbeeDetail/__test__/index.test.js +265 -0
- package/src/screens/Gateway/DeviceZigbeeDetail/index.js +148 -0
- package/src/screens/Gateway/DeviceZigbeeDetail/styles.js +12 -0
- package/src/screens/Gateway/GatewayConnectionMethods/__test__/index.test.js +37 -0
- package/src/screens/Gateway/GatewayConnectionMethods/index.js +73 -0
- package/src/screens/Gateway/GatewayConnectionMethods/styles.js +45 -0
- package/src/screens/Gateway/GatewayDetail/__test__/index.test.js +298 -0
- package/src/screens/Gateway/GatewayDetail/index.js +148 -0
- package/src/screens/Gateway/GatewayDetail/styles.js +12 -0
- package/src/screens/Gateway/GatewayInfo/__test__/index.test.js +137 -0
- package/src/screens/Gateway/GatewayInfo/index.js +115 -0
- package/src/screens/Gateway/GatewayInfo/styles.js +9 -0
- package/src/screens/Gateway/__test__/index.test.js +58 -0
- package/src/screens/Gateway/components/Detail/__test__/index.test.js +46 -0
- package/src/screens/Gateway/components/Detail/index.js +62 -0
- package/src/screens/Gateway/components/Detail/styles.js +27 -0
- package/src/screens/Gateway/components/DetailActionModbus/__test__/index.test.js +49 -0
- package/src/screens/Gateway/components/DetailActionModbus/index.js +52 -0
- package/src/screens/Gateway/components/DetailActionModbus/styles.js +32 -0
- package/src/screens/Gateway/components/DetailConfigAction/__test__/index.test.js +59 -0
- package/src/screens/Gateway/components/DetailConfigAction/index.js +69 -0
- package/src/screens/Gateway/components/DetailConfigAction/styles.js +21 -0
- package/src/screens/Gateway/components/GatewayItem/__test__/index.test.js +1 -1
- package/src/screens/Gateway/components/GatewayItem/styles.js +4 -33
- package/src/screens/Gateway/components/Information/__test__/index.test.js +70 -0
- package/src/screens/Gateway/components/Information/index.js +116 -0
- package/src/screens/Gateway/components/Information/styles.js +59 -0
- package/src/screens/Gateway/components/RowItem/__test__/index.test.js +67 -0
- package/src/screens/Gateway/components/RowItem/index.js +65 -0
- package/src/screens/Gateway/components/RowItem/styles.js +25 -0
- package/src/screens/Gateway/components/TabPaneCT/__test__/index.test.js +98 -0
- package/src/screens/Gateway/components/TabPaneCT/index.js +134 -0
- package/src/screens/Gateway/components/TabPaneCT/styles.js +58 -0
- package/src/screens/Gateway/hooks/__test__/index.test.js +93 -0
- package/src/screens/Gateway/hooks/useGateway.js +110 -16
- package/src/screens/Gateway/index.js +19 -3
- package/src/screens/Gateway/styles.js +6 -8
- package/src/screens/Gateway/utils/index.js +16 -0
- package/src/screens/GuestInfo/__test__/index.test.js +0 -7
- package/src/screens/HanetCamera/__test__/CaptureFaceID.test.js +0 -7
- package/src/screens/HanetCamera/__test__/Detail.test.js +0 -7
- package/src/screens/HanetCamera/__test__/ManageAccess.test.js +0 -7
- package/src/screens/HanetCamera/__test__/MemberInfo.test.js +0 -7
- package/src/screens/ManageAccess/__test__/ManageAccess.test.js +0 -6
- package/src/screens/ManageAccess/hooks/__test__/useManageAccess.test.js +0 -7
- package/src/screens/MoveToAnotherSubUnit/__test__/index.test.js +0 -7
- package/src/screens/Notification/__test__/Notification.test.js +0 -7
- package/src/screens/PlayBackCamera/__test__/index.test.js +0 -1
- package/src/screens/ScriptDetail/__test__/index.test.js +0 -7
- package/src/screens/SelectUnit/__test__/index.test.js +0 -1
- package/src/screens/SetSchedule/__test__/index.test.js +0 -7
- package/src/screens/Sharing/Components/__test__/DeviceItem.test.js +0 -7
- package/src/screens/Sharing/Components/__test__/ItemChangeRole.test.js +0 -7
- package/src/screens/Sharing/Components/__test__/TitleCheckBox.test.js +0 -7
- package/src/screens/Sharing/__test__/InfoMemberUnit.test.js +0 -6
- package/src/screens/Sharing/hooks/__test__/index.test.js +80 -0
- package/src/screens/SmartAccount/ListDevice/__test__/DeviceItem.test.js +0 -7
- package/src/screens/SmartIr/__test__/ButtonsBottom.test.js +0 -6
- package/src/screens/SmartIr/__test__/GroupButtonByType.test.js +1 -6
- package/src/screens/SmartIr/__test__/SelectBrand.test.js +1 -6
- package/src/screens/SmartIr/__test__/SelectDeviceType.test.js +1 -6
- package/src/screens/SubUnit/AddSubUnit.js +1 -0
- package/src/screens/SubUnit/ManageSubUnit.js +4 -1
- package/src/screens/SubUnit/hooks/__test__/useEmergencyContacts.test.js +34 -0
- package/src/screens/SubUnit/hooks/__test__/useManageSubUnit.test.js +0 -7
- package/src/screens/SyncLGDevice/__test__/AddLGDevice.test.js +0 -7
- package/src/screens/Unit/__test__/AddMenu.test.js +0 -7
- package/src/screens/Unit/__test__/CheckSendEmail.test.js +1 -1
- package/src/screens/Unit/__test__/ChooseLocation.test.js +0 -7
- package/src/screens/Unit/__test__/Detail.test.js +1 -8
- package/src/screens/Unit/__test__/SelectAddToFavorites.test.js +0 -7
- package/src/screens/Unit/__test__/SelectAddress.test.js +0 -7
- package/src/screens/Unit/__test__/SmartAccount.test.js +0 -7
- package/src/screens/Unit/__test__/SmartAccountItem.test.js +0 -7
- package/src/screens/Unit/__test__/Summaries.test.js +0 -7
- package/src/screens/Unit/hook/useUnitConnectRemoteDevices.js +4 -3
- package/src/screens/UnitSummary/components/RunningDevices/__test__/index.test.js +2 -2
- package/src/utils/I18n/translations/en.json +28 -0
- package/src/utils/I18n/translations/vi.json +28 -0
- package/src/utils/Route/index.js +8 -0
|
@@ -5,6 +5,24 @@ import Gateway from '..';
|
|
|
5
5
|
import { SCProvider } from '../../../context';
|
|
6
6
|
import { mockSCStore } from '../../../context/mockStore';
|
|
7
7
|
import { AccessibilityLabel } from '../../../configs/Constants';
|
|
8
|
+
import MockAdapter from 'axios-mock-adapter';
|
|
9
|
+
import api from '../../../utils/Apis/axios';
|
|
10
|
+
import GatewayItem from '../components/GatewayItem';
|
|
11
|
+
import API from '../../../configs/API';
|
|
12
|
+
import Routes from '../../../utils/Route';
|
|
13
|
+
const mock = new MockAdapter(api.axiosInstance);
|
|
14
|
+
|
|
15
|
+
const mockNavigate = jest.fn();
|
|
16
|
+
jest.mock('@react-navigation/native', () => {
|
|
17
|
+
return {
|
|
18
|
+
...jest.requireActual('@react-navigation/native'),
|
|
19
|
+
useNavigation: () => ({
|
|
20
|
+
navigate: mockNavigate,
|
|
21
|
+
}),
|
|
22
|
+
useRoute: jest.fn(),
|
|
23
|
+
useIsFocused: () => true,
|
|
24
|
+
};
|
|
25
|
+
});
|
|
8
26
|
|
|
9
27
|
const wrapComponent = (route) => (
|
|
10
28
|
<SCProvider initState={mockSCStore({})}>
|
|
@@ -14,6 +32,11 @@ const wrapComponent = (route) => (
|
|
|
14
32
|
|
|
15
33
|
describe('Test Gateway screen', () => {
|
|
16
34
|
let tree;
|
|
35
|
+
afterEach(() => {
|
|
36
|
+
mock.reset();
|
|
37
|
+
mock.resetHistory();
|
|
38
|
+
mockNavigate.mockClear();
|
|
39
|
+
});
|
|
17
40
|
it('Test render', async () => {
|
|
18
41
|
await act(async () => {
|
|
19
42
|
tree = await create(wrapComponent());
|
|
@@ -27,6 +50,41 @@ describe('Test Gateway screen', () => {
|
|
|
27
50
|
expect(flatLists).toHaveLength(1);
|
|
28
51
|
});
|
|
29
52
|
|
|
53
|
+
it('render Gateway goDetail', async () => {
|
|
54
|
+
mock
|
|
55
|
+
.onGet(API.DEV_MODE.GATEWAY.LIST())
|
|
56
|
+
.reply(200, { results: [{ id: 1, name: 'device 1' }] });
|
|
57
|
+
await act(async () => {
|
|
58
|
+
tree = await create(wrapComponent());
|
|
59
|
+
});
|
|
60
|
+
const instance = tree.root;
|
|
61
|
+
const flatList = instance.findByType(FlatList);
|
|
62
|
+
const gatewayItems = flatList.findAllByType(GatewayItem);
|
|
63
|
+
expect(gatewayItems).toHaveLength(1);
|
|
64
|
+
await act(async () => {
|
|
65
|
+
await gatewayItems[0].props.onPress();
|
|
66
|
+
});
|
|
67
|
+
expect(mockNavigate).toBeCalledWith(Routes.GatewayDetail, {
|
|
68
|
+
item: { id: 1, name: 'device 1' },
|
|
69
|
+
});
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
it('render Gateway onRefresh', async () => {
|
|
73
|
+
await act(async () => {
|
|
74
|
+
tree = await create(wrapComponent());
|
|
75
|
+
});
|
|
76
|
+
const instance = tree.root;
|
|
77
|
+
const flatList = instance.findByType(FlatList);
|
|
78
|
+
expect(flatList.props.data).toEqual([]);
|
|
79
|
+
mock
|
|
80
|
+
.onGet(API.DEV_MODE.GATEWAY.LIST())
|
|
81
|
+
.reply(200, { results: [{ id: 1, name: 'device 1' }] });
|
|
82
|
+
await act(async () => {
|
|
83
|
+
await flatList.props.onRefresh();
|
|
84
|
+
});
|
|
85
|
+
expect(flatList.props.data).toEqual([{ id: 1, name: 'device 1' }]);
|
|
86
|
+
});
|
|
87
|
+
|
|
30
88
|
it('Test render empty', async () => {
|
|
31
89
|
await act(async () => {
|
|
32
90
|
tree = await create(wrapComponent());
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { create, act } from 'react-test-renderer';
|
|
3
|
+
import { SCProvider } from '../../../../../context';
|
|
4
|
+
import { mockSCStore } from '../../../../../context/mockStore';
|
|
5
|
+
import { HeaderCustom } from '../../../../../commons';
|
|
6
|
+
import MenuActionMore from '../../../../../commons/MenuActionMore';
|
|
7
|
+
import Detail from '../../../components/Detail';
|
|
8
|
+
import TabPaneCT from '../../../components/TabPaneCT';
|
|
9
|
+
|
|
10
|
+
const wrapComponent = (listMenuItem) => (
|
|
11
|
+
<SCProvider initState={mockSCStore({})}>
|
|
12
|
+
<Detail listMenuItem={listMenuItem} />
|
|
13
|
+
</SCProvider>
|
|
14
|
+
);
|
|
15
|
+
const mockDoAction = jest.fn();
|
|
16
|
+
|
|
17
|
+
describe('Test Detail', () => {
|
|
18
|
+
let tree;
|
|
19
|
+
it('test render Detail', async () => {
|
|
20
|
+
await act(async () => {
|
|
21
|
+
tree = await create(wrapComponent());
|
|
22
|
+
});
|
|
23
|
+
const instance = tree.root;
|
|
24
|
+
const headerCustom = instance.findAllByType(HeaderCustom);
|
|
25
|
+
const tabPaneCT = instance.findAllByType(TabPaneCT);
|
|
26
|
+
const menuActionMore = instance.findAllByType(MenuActionMore);
|
|
27
|
+
expect(headerCustom).toHaveLength(1);
|
|
28
|
+
expect(tabPaneCT).toHaveLength(1);
|
|
29
|
+
expect(menuActionMore).toHaveLength(1);
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
it('test render Detail and MenuActionMore onPress', async () => {
|
|
33
|
+
const listMenuItem = [
|
|
34
|
+
{ id: 1, text: 'information', doAction: mockDoAction },
|
|
35
|
+
];
|
|
36
|
+
await act(async () => {
|
|
37
|
+
tree = await create(wrapComponent(listMenuItem));
|
|
38
|
+
});
|
|
39
|
+
const instance = tree.root;
|
|
40
|
+
const menuActionMore = instance.findAllByType(MenuActionMore);
|
|
41
|
+
await act(async () => {
|
|
42
|
+
await menuActionMore[0].props.onItemClick(listMenuItem[0]);
|
|
43
|
+
});
|
|
44
|
+
expect(mockDoAction).toBeCalledTimes(1);
|
|
45
|
+
});
|
|
46
|
+
});
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import React, { useCallback, memo } from 'react';
|
|
2
|
+
import { View } from 'react-native';
|
|
3
|
+
import { HeaderCustom } from '../../../../commons';
|
|
4
|
+
import MenuActionMore from '../../../../commons/MenuActionMore';
|
|
5
|
+
import { usePopover } from '../../../../hooks/Common';
|
|
6
|
+
import TabPaneCT from '../TabPaneCT';
|
|
7
|
+
import styles from './styles';
|
|
8
|
+
|
|
9
|
+
const Detail = ({
|
|
10
|
+
listMenuItem = [],
|
|
11
|
+
listTabs = [],
|
|
12
|
+
title = '',
|
|
13
|
+
isDevice = false,
|
|
14
|
+
setSelectedIndex,
|
|
15
|
+
selectedIndex,
|
|
16
|
+
onPressRow,
|
|
17
|
+
isConfig,
|
|
18
|
+
isAction,
|
|
19
|
+
onRefresh = () => {},
|
|
20
|
+
refresh = false,
|
|
21
|
+
}) => {
|
|
22
|
+
const { childRef, showingPopover, showPopoverWithRef, hidePopover } =
|
|
23
|
+
usePopover();
|
|
24
|
+
|
|
25
|
+
const onItemClick = useCallback((itemMenu) => {
|
|
26
|
+
itemMenu?.doAction();
|
|
27
|
+
}, []);
|
|
28
|
+
|
|
29
|
+
return (
|
|
30
|
+
<View style={styles.wrap}>
|
|
31
|
+
<HeaderCustom
|
|
32
|
+
title={title}
|
|
33
|
+
isShowRight
|
|
34
|
+
titleStyles={styles.title}
|
|
35
|
+
isDisableRefresh
|
|
36
|
+
showPopoverWithRef={showPopoverWithRef}
|
|
37
|
+
/>
|
|
38
|
+
<TabPaneCT
|
|
39
|
+
listTabs={listTabs}
|
|
40
|
+
selectedIndex={selectedIndex}
|
|
41
|
+
setSelectedIndex={setSelectedIndex}
|
|
42
|
+
isDevice={isDevice}
|
|
43
|
+
onPressRow={onPressRow}
|
|
44
|
+
isConfig={isConfig}
|
|
45
|
+
isAction={isAction}
|
|
46
|
+
onRefresh={onRefresh}
|
|
47
|
+
refresh={refresh}
|
|
48
|
+
/>
|
|
49
|
+
<MenuActionMore
|
|
50
|
+
isVisible={showingPopover}
|
|
51
|
+
hideMore={hidePopover}
|
|
52
|
+
onItemClick={onItemClick}
|
|
53
|
+
listMenuItem={listMenuItem}
|
|
54
|
+
childRef={childRef}
|
|
55
|
+
isTextCenter={false}
|
|
56
|
+
wrapStyle={styles.wrapStyle}
|
|
57
|
+
/>
|
|
58
|
+
</View>
|
|
59
|
+
);
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
export default memo(Detail);
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { StyleSheet, Platform } from 'react-native';
|
|
2
|
+
import { Colors } from '../../../../configs';
|
|
3
|
+
|
|
4
|
+
export default StyleSheet.create({
|
|
5
|
+
wrap: {
|
|
6
|
+
flex: 1,
|
|
7
|
+
backgroundColor: Colors.White,
|
|
8
|
+
},
|
|
9
|
+
wrapStyle: {
|
|
10
|
+
borderRadius: 8,
|
|
11
|
+
borderBottomRightRadius: 8,
|
|
12
|
+
borderBottomLeftRadius: 8,
|
|
13
|
+
width: 'auto',
|
|
14
|
+
marginTop: Platform.select({
|
|
15
|
+
android: -70,
|
|
16
|
+
ios: 0,
|
|
17
|
+
}),
|
|
18
|
+
marginLeft: -15,
|
|
19
|
+
},
|
|
20
|
+
title: {
|
|
21
|
+
textAlign: 'left',
|
|
22
|
+
fontSize: 16,
|
|
23
|
+
lineHeight: 24,
|
|
24
|
+
fontWeight: 'bold',
|
|
25
|
+
color: Colors.Black,
|
|
26
|
+
},
|
|
27
|
+
});
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { create, act } from 'react-test-renderer';
|
|
3
|
+
import { SCProvider } from '../../../../../context';
|
|
4
|
+
import { mockSCStore } from '../../../../../context/mockStore';
|
|
5
|
+
import { HeaderCustom } from '../../../../../commons';
|
|
6
|
+
import DetailActionModbus from '../../../components/DetailActionModbus';
|
|
7
|
+
import { FlatList, TouchableOpacity } from 'react-native';
|
|
8
|
+
|
|
9
|
+
const wrapComponent = (listData, title, onPressRow) => (
|
|
10
|
+
<SCProvider initState={mockSCStore({})}>
|
|
11
|
+
<DetailActionModbus
|
|
12
|
+
listData={listData}
|
|
13
|
+
title={title}
|
|
14
|
+
onPressRow={onPressRow}
|
|
15
|
+
/>
|
|
16
|
+
</SCProvider>
|
|
17
|
+
);
|
|
18
|
+
const mockOnPress = jest.fn();
|
|
19
|
+
|
|
20
|
+
describe('Test DetailActionModbus', () => {
|
|
21
|
+
let tree;
|
|
22
|
+
let listData = [{ id: 1, len1: 1, len2: 2, ex: '', delay: 0 }];
|
|
23
|
+
it('test render DetailActionModbus', async () => {
|
|
24
|
+
await act(async () => {
|
|
25
|
+
tree = await create(wrapComponent(listData, 'action on'));
|
|
26
|
+
});
|
|
27
|
+
const instance = tree.root;
|
|
28
|
+
const headerCustom = instance.findAllByType(HeaderCustom);
|
|
29
|
+
const flatList = instance.findAllByType(FlatList);
|
|
30
|
+
expect(headerCustom[0].props.title).toEqual('action on');
|
|
31
|
+
expect(headerCustom).toHaveLength(1);
|
|
32
|
+
expect(flatList).toHaveLength(1);
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
it('test render DetailActionModbus and renderItem onPress', async () => {
|
|
36
|
+
await act(async () => {
|
|
37
|
+
tree = await create(
|
|
38
|
+
wrapComponent(listData, 'action on', () => mockOnPress)
|
|
39
|
+
);
|
|
40
|
+
});
|
|
41
|
+
const instance = tree.root;
|
|
42
|
+
const flatList = instance.findAllByType(FlatList);
|
|
43
|
+
const touchableOpacity = flatList[0].findAllByType(TouchableOpacity);
|
|
44
|
+
await act(async () => {
|
|
45
|
+
touchableOpacity[0].props.onPress();
|
|
46
|
+
});
|
|
47
|
+
expect(mockOnPress).toHaveBeenCalled();
|
|
48
|
+
});
|
|
49
|
+
});
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import React, { useCallback, memo, useMemo } from 'react';
|
|
2
|
+
import { View, FlatList, Image, TouchableOpacity } from 'react-native';
|
|
3
|
+
import { Text, HeaderCustom } from '../../../../commons';
|
|
4
|
+
import styles from './styles';
|
|
5
|
+
import Images from '../../../../configs/Images';
|
|
6
|
+
|
|
7
|
+
const DetailActionModbus = ({
|
|
8
|
+
listData = [],
|
|
9
|
+
title,
|
|
10
|
+
contentContainerStyle,
|
|
11
|
+
onPressRow = () => {},
|
|
12
|
+
}) => {
|
|
13
|
+
const renderItem = useCallback(
|
|
14
|
+
({ item, index }) => {
|
|
15
|
+
return (
|
|
16
|
+
<TouchableOpacity style={styles.itemAction} onPress={onPressRow(item)}>
|
|
17
|
+
<Text>{item?.actionName}</Text>
|
|
18
|
+
<Image style={styles.arrowRight} source={Images.arrowLeft} />
|
|
19
|
+
</TouchableOpacity>
|
|
20
|
+
);
|
|
21
|
+
},
|
|
22
|
+
[onPressRow]
|
|
23
|
+
);
|
|
24
|
+
|
|
25
|
+
const customData = useMemo(() => {
|
|
26
|
+
return listData?.map((item, index) => ({
|
|
27
|
+
...item,
|
|
28
|
+
actionName: `Action name ${index + 1}`,
|
|
29
|
+
}));
|
|
30
|
+
}, [listData]);
|
|
31
|
+
|
|
32
|
+
return (
|
|
33
|
+
<View style={styles.wrap}>
|
|
34
|
+
<HeaderCustom title={title} titleStyles={styles.title} />
|
|
35
|
+
<View style={styles.bodyInfo}>
|
|
36
|
+
<FlatList
|
|
37
|
+
contentContainerStyle={[
|
|
38
|
+
styles.contentContainerStyle,
|
|
39
|
+
contentContainerStyle,
|
|
40
|
+
]}
|
|
41
|
+
keyExtractor={(item) => item?.id}
|
|
42
|
+
data={customData}
|
|
43
|
+
renderItem={renderItem}
|
|
44
|
+
extraData={customData}
|
|
45
|
+
numColumns={1}
|
|
46
|
+
/>
|
|
47
|
+
</View>
|
|
48
|
+
</View>
|
|
49
|
+
);
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
export default memo(DetailActionModbus);
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { StyleSheet } from 'react-native';
|
|
2
|
+
import { Colors } from '../../../../configs';
|
|
3
|
+
|
|
4
|
+
export default StyleSheet.create({
|
|
5
|
+
wrap: {
|
|
6
|
+
flex: 1,
|
|
7
|
+
backgroundColor: Colors.White,
|
|
8
|
+
},
|
|
9
|
+
title: {
|
|
10
|
+
textAlign: 'left',
|
|
11
|
+
paddingLeft: 16,
|
|
12
|
+
fontSize: 16,
|
|
13
|
+
lineHeight: 24,
|
|
14
|
+
fontWeight: 'bold',
|
|
15
|
+
color: Colors.Black,
|
|
16
|
+
},
|
|
17
|
+
contentContainerStyle: {
|
|
18
|
+
paddingVertical: 8,
|
|
19
|
+
},
|
|
20
|
+
bodyInfo: { paddingHorizontal: 16, flex: 1 },
|
|
21
|
+
itemAction: {
|
|
22
|
+
flex: 1,
|
|
23
|
+
flexDirection: 'row',
|
|
24
|
+
justifyContent: 'space-between',
|
|
25
|
+
alignItems: 'center',
|
|
26
|
+
},
|
|
27
|
+
arrowRight: {
|
|
28
|
+
width: 12,
|
|
29
|
+
height: 15,
|
|
30
|
+
transform: [{ rotate: '180deg' }],
|
|
31
|
+
},
|
|
32
|
+
});
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { FlatList } from 'react-native';
|
|
3
|
+
import { create, act } from 'react-test-renderer';
|
|
4
|
+
|
|
5
|
+
import { SCProvider } from '../../../../../context';
|
|
6
|
+
import { mockSCStore } from '../../../../../context/mockStore';
|
|
7
|
+
import { HeaderCustom, Text } from '../../../../../commons';
|
|
8
|
+
import DetailConfigAction from '../../../components/DetailConfigAction';
|
|
9
|
+
|
|
10
|
+
const wrapComponent = (
|
|
11
|
+
listData,
|
|
12
|
+
title,
|
|
13
|
+
subTitle,
|
|
14
|
+
onRowOne,
|
|
15
|
+
isDetailConfigModbus = false
|
|
16
|
+
) => (
|
|
17
|
+
<SCProvider initState={mockSCStore({})}>
|
|
18
|
+
<DetailConfigAction
|
|
19
|
+
listData={listData}
|
|
20
|
+
title={title}
|
|
21
|
+
subTitle={subTitle}
|
|
22
|
+
isDetailConfigModbus={isDetailConfigModbus}
|
|
23
|
+
onRowOne={onRowOne}
|
|
24
|
+
/>
|
|
25
|
+
</SCProvider>
|
|
26
|
+
);
|
|
27
|
+
|
|
28
|
+
describe('Test DetailConfigAction', () => {
|
|
29
|
+
let tree;
|
|
30
|
+
let listData = [{ id: 1, len1: 1, len2: 2, ex: '', delay: 0 }];
|
|
31
|
+
it('test render DetailConfigAction headerCustom isDetailConfigModbus=false', async () => {
|
|
32
|
+
await act(async () => {
|
|
33
|
+
tree = await create(
|
|
34
|
+
wrapComponent(listData, 'config 1', 'sensor 1', false)
|
|
35
|
+
);
|
|
36
|
+
});
|
|
37
|
+
const instance = tree.root;
|
|
38
|
+
const headerCustom = instance.findAllByType(HeaderCustom);
|
|
39
|
+
const flatList = instance.findAllByType(FlatList);
|
|
40
|
+
const textTitles = headerCustom[0].findAllByType(Text);
|
|
41
|
+
expect(textTitles[0].props.children).toEqual('config 1');
|
|
42
|
+
expect(textTitles[1].props.children).toEqual('sensor 1');
|
|
43
|
+
expect(flatList).toHaveLength(1);
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
it('test render DetailConfigAction headerCustom isDetailConfigModbus=true', async () => {
|
|
47
|
+
await act(async () => {
|
|
48
|
+
tree = await create(
|
|
49
|
+
wrapComponent(listData, 'config 1', 'sensor 1', false, true)
|
|
50
|
+
);
|
|
51
|
+
});
|
|
52
|
+
const instance = tree.root;
|
|
53
|
+
const headerCustom = instance.findAllByType(HeaderCustom);
|
|
54
|
+
const flatList = instance.findAllByType(FlatList);
|
|
55
|
+
const textTitles = headerCustom[0].findAllByType(Text);
|
|
56
|
+
expect(textTitles[0].props.children).toEqual('config 1');
|
|
57
|
+
expect(flatList).toHaveLength(1);
|
|
58
|
+
});
|
|
59
|
+
});
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import React, { useCallback, memo } from 'react';
|
|
2
|
+
import { View, FlatList } from 'react-native';
|
|
3
|
+
import { Colors } from '../../../../configs';
|
|
4
|
+
import { Text, HeaderCustom } from '../../../../commons';
|
|
5
|
+
import styles from './styles';
|
|
6
|
+
import RowItem from '../RowItem';
|
|
7
|
+
|
|
8
|
+
const DetailConfigAction = ({
|
|
9
|
+
listData = [],
|
|
10
|
+
title,
|
|
11
|
+
subTitle,
|
|
12
|
+
isDetailConfigModbus = false,
|
|
13
|
+
contentContainerStyle,
|
|
14
|
+
onRowOne,
|
|
15
|
+
}) => {
|
|
16
|
+
const renderItem = useCallback(
|
|
17
|
+
({ item, index }) => {
|
|
18
|
+
return (
|
|
19
|
+
<RowItem
|
|
20
|
+
title={item?.title}
|
|
21
|
+
subTitle={item?.data}
|
|
22
|
+
onRowOne={onRowOne}
|
|
23
|
+
/>
|
|
24
|
+
);
|
|
25
|
+
},
|
|
26
|
+
[onRowOne]
|
|
27
|
+
);
|
|
28
|
+
|
|
29
|
+
const TitleCustom = useCallback(() => {
|
|
30
|
+
if (isDetailConfigModbus) {
|
|
31
|
+
return (
|
|
32
|
+
<Text type="H4" bold>
|
|
33
|
+
{title}
|
|
34
|
+
</Text>
|
|
35
|
+
);
|
|
36
|
+
}
|
|
37
|
+
return (
|
|
38
|
+
<>
|
|
39
|
+
<Text type="H4" bold>
|
|
40
|
+
{title}
|
|
41
|
+
</Text>
|
|
42
|
+
<Text type="Label" color={Colors.Gray20}>
|
|
43
|
+
{subTitle}
|
|
44
|
+
</Text>
|
|
45
|
+
</>
|
|
46
|
+
);
|
|
47
|
+
}, [isDetailConfigModbus, subTitle, title]);
|
|
48
|
+
|
|
49
|
+
return (
|
|
50
|
+
<View style={styles.wrap}>
|
|
51
|
+
<HeaderCustom customTitle={<TitleCustom />} titleStyles={styles.title} />
|
|
52
|
+
<View style={styles.bodyInfo}>
|
|
53
|
+
<FlatList
|
|
54
|
+
contentContainerStyle={[
|
|
55
|
+
styles.contentContainerStyle,
|
|
56
|
+
contentContainerStyle,
|
|
57
|
+
]}
|
|
58
|
+
keyExtractor={(item) => item?.id}
|
|
59
|
+
data={listData}
|
|
60
|
+
renderItem={renderItem}
|
|
61
|
+
extraData={listData}
|
|
62
|
+
numColumns={1}
|
|
63
|
+
/>
|
|
64
|
+
</View>
|
|
65
|
+
</View>
|
|
66
|
+
);
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
export default memo(DetailConfigAction);
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { StyleSheet } from 'react-native';
|
|
2
|
+
import { Colors } from '../../../../configs';
|
|
3
|
+
|
|
4
|
+
export default StyleSheet.create({
|
|
5
|
+
wrap: {
|
|
6
|
+
flex: 1,
|
|
7
|
+
backgroundColor: Colors.White,
|
|
8
|
+
},
|
|
9
|
+
title: {
|
|
10
|
+
textAlign: 'left',
|
|
11
|
+
paddingLeft: 16,
|
|
12
|
+
fontSize: 16,
|
|
13
|
+
lineHeight: 24,
|
|
14
|
+
fontWeight: 'bold',
|
|
15
|
+
color: Colors.Black,
|
|
16
|
+
},
|
|
17
|
+
contentContainerStyle: {
|
|
18
|
+
paddingVertical: 8,
|
|
19
|
+
},
|
|
20
|
+
bodyInfo: { paddingHorizontal: 16, flex: 1 },
|
|
21
|
+
});
|
|
@@ -3,6 +3,7 @@ import { Colors, Constants } from '../../../../configs';
|
|
|
3
3
|
|
|
4
4
|
export default StyleSheet.create({
|
|
5
5
|
wrap: {
|
|
6
|
+
height: 'auto',
|
|
6
7
|
padding: 16,
|
|
7
8
|
marginBottom: 16,
|
|
8
9
|
backgroundColor: Colors.White,
|
|
@@ -12,8 +13,8 @@ export default StyleSheet.create({
|
|
|
12
13
|
borderColor: Colors.Neutral.Neutral3,
|
|
13
14
|
},
|
|
14
15
|
button: {
|
|
15
|
-
flex: 1,
|
|
16
16
|
justifyContent: 'space-between',
|
|
17
|
+
height: 'auto',
|
|
17
18
|
},
|
|
18
19
|
viewTitle: {
|
|
19
20
|
marginBottom: 6,
|
|
@@ -24,39 +25,9 @@ export default StyleSheet.create({
|
|
|
24
25
|
textTitle: {
|
|
25
26
|
lineHeight: 20,
|
|
26
27
|
height: 40,
|
|
27
|
-
fontWeight: 600,
|
|
28
|
-
textOverflow: 'ellipsis',
|
|
28
|
+
fontWeight: '600',
|
|
29
29
|
},
|
|
30
30
|
textValue: {
|
|
31
|
-
fontWeight: 400,
|
|
32
|
-
},
|
|
33
|
-
viewStatus: {
|
|
34
|
-
width: 65,
|
|
35
|
-
paddingHorizontal: 8,
|
|
36
|
-
paddingVertical: 4,
|
|
37
|
-
borderRadius: 54,
|
|
38
|
-
backgroundColor: Colors.White,
|
|
39
|
-
borderColor: Colors.Neutral.Neutral3,
|
|
40
|
-
borderWidth: 1,
|
|
41
|
-
},
|
|
42
|
-
textStatus: {
|
|
43
|
-
fontStyle: 'normal',
|
|
44
|
-
fontWeight: 600,
|
|
45
|
-
letterSpacing: 0.04,
|
|
46
|
-
fontSize: 12,
|
|
47
|
-
lineHeight: 16,
|
|
48
|
-
textTransform: 'uppercase',
|
|
49
|
-
textAlign: 'center',
|
|
50
|
-
},
|
|
51
|
-
listGateways: {
|
|
52
|
-
width: '100%',
|
|
53
|
-
paddingVertical: 16,
|
|
54
|
-
},
|
|
55
|
-
textOnline: {
|
|
56
|
-
fontStyle: 'bold',
|
|
57
|
-
},
|
|
58
|
-
viewOnline: {
|
|
59
|
-
backgroundColor: Colors.LightGreen,
|
|
60
|
-
borderWidth: 0,
|
|
31
|
+
fontWeight: '400',
|
|
61
32
|
},
|
|
62
33
|
});
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { create, act } from 'react-test-renderer';
|
|
3
|
+
import { SCProvider } from '../../../../../context';
|
|
4
|
+
import { mockSCStore } from '../../../../../context/mockStore';
|
|
5
|
+
import { HeaderCustom } from '../../../../../commons';
|
|
6
|
+
import Information from '../../../components/Information';
|
|
7
|
+
import { AccessibilityLabel } from '../../../../../configs/Constants';
|
|
8
|
+
import { FlatList } from 'react-native';
|
|
9
|
+
|
|
10
|
+
const mockHandleDeleteGateway = jest.fn();
|
|
11
|
+
const mockHandleConnectionMethods = jest.fn();
|
|
12
|
+
|
|
13
|
+
const wrapComponent = (
|
|
14
|
+
listInformation,
|
|
15
|
+
handleDeleteGateway,
|
|
16
|
+
handleConnectionMethods,
|
|
17
|
+
isDevice = false,
|
|
18
|
+
isModbus = false
|
|
19
|
+
) => (
|
|
20
|
+
<SCProvider initState={mockSCStore({})}>
|
|
21
|
+
<Information
|
|
22
|
+
listInformation={listInformation}
|
|
23
|
+
handleDeleteGateway={handleDeleteGateway}
|
|
24
|
+
handleConnectionMethods={handleConnectionMethods}
|
|
25
|
+
isDevice={isDevice}
|
|
26
|
+
isModbus={isModbus}
|
|
27
|
+
/>
|
|
28
|
+
</SCProvider>
|
|
29
|
+
);
|
|
30
|
+
|
|
31
|
+
describe('Test Information', () => {
|
|
32
|
+
let tree;
|
|
33
|
+
let listInformation = [{ id: 1, name: 'row1', data: 'dataRow1' }];
|
|
34
|
+
it('test render Information', async () => {
|
|
35
|
+
await act(async () => {
|
|
36
|
+
tree = await create(
|
|
37
|
+
wrapComponent(
|
|
38
|
+
listInformation,
|
|
39
|
+
mockHandleDeleteGateway,
|
|
40
|
+
mockHandleConnectionMethods
|
|
41
|
+
)
|
|
42
|
+
);
|
|
43
|
+
});
|
|
44
|
+
const instance = tree.root;
|
|
45
|
+
const headerCustom = instance.findAllByType(HeaderCustom);
|
|
46
|
+
const viewAlert = instance.findByProps({
|
|
47
|
+
accessibilityLabel: AccessibilityLabel.GATEWAY_INFO_ALERT,
|
|
48
|
+
});
|
|
49
|
+
const flatList = instance.findAllByType(FlatList);
|
|
50
|
+
expect(headerCustom).toHaveLength(1);
|
|
51
|
+
expect(flatList).toHaveLength(1);
|
|
52
|
+
expect(viewAlert.props.children[1].props.children).toEqual(
|
|
53
|
+
'Go to EoH web to see firmware configuration'
|
|
54
|
+
);
|
|
55
|
+
const buttonConnect = instance.findByProps({
|
|
56
|
+
accessibilityLabel:
|
|
57
|
+
AccessibilityLabel.GATEWAY_INFO_BUTTON_GOTO_CONNECTION_METHODS,
|
|
58
|
+
});
|
|
59
|
+
expect(
|
|
60
|
+
buttonConnect.props.children.props.children[0].props.children[0].props
|
|
61
|
+
.children
|
|
62
|
+
).toEqual('Connection methods');
|
|
63
|
+
const buttonDelete = instance.findByProps({
|
|
64
|
+
accessibilityLabel: AccessibilityLabel.GATEWAY_INFO_BUTTON_DELETE_GATEWAY,
|
|
65
|
+
});
|
|
66
|
+
expect(buttonDelete.props.children.props.children).toEqual(
|
|
67
|
+
'Delete gateway'
|
|
68
|
+
);
|
|
69
|
+
});
|
|
70
|
+
});
|