@eohjsc/react-native-smart-city 0.6.0 → 0.6.1
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 +44 -6
- package/package.json +1 -1
- package/src/commons/Device/PowerConsumptionChart.js +6 -1
- package/src/commons/Device/ProgressBar/__test__/ProgressBar.test.js +2 -3
- package/src/commons/Device/ProgressBar/index.js +36 -38
- package/src/commons/Device/ProgressBar/styles.js +18 -24
- package/src/commons/Form/CurrencyInput.js +2 -0
- package/src/commons/Widgets/IFrame/IFrame.js +54 -0
- package/src/commons/Widgets/IFrame/IFrameStyles.js +35 -0
- package/src/commons/Widgets/IFrame/__tests__/IFrame.test.js +74 -0
- package/src/commons/Widgets/IFrame/index.js +0 -0
- package/src/commons/Widgets/IFrameWithConfig/IFrameWithConfig.js +163 -0
- package/src/commons/Widgets/IFrameWithConfig/IFrameWithConfigStyles.js +9 -0
- package/src/commons/Widgets/IFrameWithConfig/__tests__/IFrameWithConfig.test.js +284 -0
- package/src/commons/Widgets/IFrameWithConfig/index.js +0 -0
- package/src/commons/Widgets/Widget.js +0 -0
- package/src/commons/Widgets/index.js +0 -0
- package/src/configs/AccessibilityLabel.js +3 -0
- package/src/configs/Constants.js +5 -0
- package/src/hooks/Common/useDevicesStatus.js +0 -1
- package/src/screens/Device/components/SensorDisplayItem.js +23 -1
- package/src/screens/Device/components/__test__/VisualChart.test.js +2 -9
- package/src/screens/UnitSummary/components/PowerConsumption/__test__/PowerConsumption.test.js +19 -0
package/README.md
CHANGED
|
@@ -21,6 +21,8 @@
|
|
|
21
21
|
|
|
22
22
|
1. StackNavigator
|
|
23
23
|
|
|
24
|
+
- You can see the screens or components that the library is supporting in the folder `/@eohjsc/react-native-smart-city/index.js`
|
|
25
|
+
|
|
24
26
|
```javascript
|
|
25
27
|
import {
|
|
26
28
|
UnitStack,
|
|
@@ -38,12 +40,9 @@ import {
|
|
|
38
40
|
import Config from 'react-native-config';
|
|
39
41
|
import { createStackNavigator } from '@react-navigation/stack';
|
|
40
42
|
|
|
41
|
-
// TODO: What to do with the module?
|
|
42
43
|
const Stack = createStackNavigator();
|
|
43
44
|
|
|
44
45
|
const YourStack = () => {
|
|
45
|
-
|
|
46
|
-
|
|
47
46
|
useEffect(() => {
|
|
48
47
|
const config = {
|
|
49
48
|
apiRoot: Config.API_ROOT,
|
|
@@ -58,8 +57,8 @@ const YourStack = () => {
|
|
|
58
57
|
language,
|
|
59
58
|
setCurrentSensorDisplay,
|
|
60
59
|
appName: Config.APP_NAME,
|
|
61
|
-
packageName: Config.APP_PACKAGE_NAME,
|
|
62
|
-
versionCode: Config.APP_VERSION_CODE,
|
|
60
|
+
packageName: Config.APP_PACKAGE_NAME, // Your package name is required
|
|
61
|
+
versionCode: Config.APP_VERSION_CODE, // Your app version is required
|
|
63
62
|
};
|
|
64
63
|
initSCConfig(config);
|
|
65
64
|
}, [language, setCurrentSensorDisplay]);
|
|
@@ -132,7 +131,46 @@ const MyScreen = () => {
|
|
|
132
131
|
};
|
|
133
132
|
```
|
|
134
133
|
|
|
135
|
-
3.
|
|
134
|
+
3. Use navigate to the screens included in the '@eohjsc/react-native-smart-city' library
|
|
135
|
+
|
|
136
|
+
- You can see the list of screens, currently supported by the library in the folder `/@eohjsc/react-native-smart-city/src/navigations/`
|
|
137
|
+
|
|
138
|
+
```javascript
|
|
139
|
+
import { useNavigation } from '@react-navigation/native';
|
|
140
|
+
const { navigate } = useNavigation();
|
|
141
|
+
const automate_id = 1;
|
|
142
|
+
const unit_id = 1;
|
|
143
|
+
const sensor_id = 1;
|
|
144
|
+
|
|
145
|
+
const handleNavigateScriptDetail = () => {
|
|
146
|
+
navigate('UnitStack', {
|
|
147
|
+
screen: 'ScriptDetail',
|
|
148
|
+
params: {
|
|
149
|
+
id: automate_id,
|
|
150
|
+
},
|
|
151
|
+
});
|
|
152
|
+
};
|
|
153
|
+
|
|
154
|
+
const handleNavigateDeviceDetail = () => {
|
|
155
|
+
navigate('UnitStack', {
|
|
156
|
+
screen: 'DeviceDetail',
|
|
157
|
+
params: {
|
|
158
|
+
unitId: unit_id,
|
|
159
|
+
sensorId: sensor_id,
|
|
160
|
+
},
|
|
161
|
+
});
|
|
162
|
+
};
|
|
163
|
+
|
|
164
|
+
<TouchableOpacity onPress={handleNavigateScriptDetail}>
|
|
165
|
+
<Text>{'Navigate to the "ScriptDetail" screen'}</Text>
|
|
166
|
+
</TouchableOpacity>;
|
|
167
|
+
|
|
168
|
+
<TouchableOpacity onPress={handleNavigateDeviceDetail}>
|
|
169
|
+
<Text>{'Navigate to the "DeviceDetail" screen'}</Text>
|
|
170
|
+
</TouchableOpacity>;
|
|
171
|
+
```
|
|
172
|
+
|
|
173
|
+
4. Trigger quick action
|
|
136
174
|
|
|
137
175
|
```javascript
|
|
138
176
|
import React from 'react';
|
package/package.json
CHANGED
|
@@ -11,6 +11,7 @@ import DateTimeRangeChange from '../DateTimeRangeChange';
|
|
|
11
11
|
import HorizontalBarChart from './HorizontalBarChart';
|
|
12
12
|
import ChartAggregationOption from '../ChartAggregationOption';
|
|
13
13
|
import { formatMoney } from '../../utils/Utils';
|
|
14
|
+
import AccessibilityLabel from '../../configs/AccessibilityLabel';
|
|
14
15
|
|
|
15
16
|
const PowerConsumptionChart = memo(
|
|
16
17
|
({
|
|
@@ -101,6 +102,7 @@ const PowerConsumptionChart = memo(
|
|
|
101
102
|
onPress={onCalculateCost}
|
|
102
103
|
style={styles.buttonCalculate}
|
|
103
104
|
textSemiBold={false}
|
|
105
|
+
accessibilityLabel={AccessibilityLabel.BUTTON_CALCULATE_COST}
|
|
104
106
|
/>
|
|
105
107
|
</View>
|
|
106
108
|
</View>
|
|
@@ -108,7 +110,10 @@ const PowerConsumptionChart = memo(
|
|
|
108
110
|
{renderChart}
|
|
109
111
|
{!!chartConfig.price && (
|
|
110
112
|
<Text type="H4">
|
|
111
|
-
{t('total_power_price')}
|
|
113
|
+
{t('total_power_price')}{' '}
|
|
114
|
+
<Text bold accessibilityLabel={AccessibilityLabel.TOTAL_PRICE}>
|
|
115
|
+
{formatMoney(totalPrice)}
|
|
116
|
+
</Text>
|
|
112
117
|
</Text>
|
|
113
118
|
)}
|
|
114
119
|
</View>
|
|
@@ -18,8 +18,7 @@ describe('Test ProgressBar', () => {
|
|
|
18
18
|
it('render ProgressBar', async () => {
|
|
19
19
|
const item = {
|
|
20
20
|
label: 'Value bar',
|
|
21
|
-
configuration: { max_value: 100 },
|
|
22
|
-
value: 8,
|
|
21
|
+
configuration: { min_value: 0, max_value: 100 },
|
|
23
22
|
};
|
|
24
23
|
const data = [{ value: 10, unit: 'oC' }];
|
|
25
24
|
await act(async () => {
|
|
@@ -28,6 +27,6 @@ describe('Test ProgressBar', () => {
|
|
|
28
27
|
const instance = tree.root;
|
|
29
28
|
const texts = instance.findAllByType(Text);
|
|
30
29
|
expect(texts[0].props.children).toBe('Value bar');
|
|
31
|
-
expect(texts[1].props.children).toEqual('
|
|
30
|
+
expect(texts[1].props.children).toEqual('0 oC');
|
|
32
31
|
});
|
|
33
32
|
});
|
|
@@ -3,53 +3,51 @@ import { View } from 'react-native';
|
|
|
3
3
|
import * as Progress from 'react-native-progress';
|
|
4
4
|
|
|
5
5
|
import { Colors } from '../../../configs';
|
|
6
|
-
import { useTranslations } from '../../../hooks/Common/useTranslations';
|
|
7
6
|
import Text from '../../Text';
|
|
8
7
|
import styles from './styles';
|
|
9
8
|
|
|
10
9
|
const ProgressBar = memo(({ data = [], item, isWidgetOrder }) => {
|
|
11
|
-
const
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
const
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
let { value = 0, measure, unit } = data.length ? data[0] : {};
|
|
21
|
-
const isNotValue = ['', null, undefined, NaN].includes(value);
|
|
22
|
-
|
|
23
|
-
if (isNotValue) {
|
|
24
|
-
value = minValue;
|
|
25
|
-
}
|
|
10
|
+
const {
|
|
11
|
+
configuration: { max_value, min_value },
|
|
12
|
+
label,
|
|
13
|
+
} = item;
|
|
14
|
+
const { value = 0, unit } = data.length ? data[0] : {};
|
|
15
|
+
const isNotValue = useMemo(
|
|
16
|
+
() => ['', null, undefined, NaN].includes(value),
|
|
17
|
+
[value]
|
|
18
|
+
);
|
|
26
19
|
|
|
27
|
-
const
|
|
28
|
-
const
|
|
20
|
+
const displayedValue = isNotValue ? min_value : value;
|
|
21
|
+
const distance = max_value - min_value;
|
|
22
|
+
const percent = (displayedValue - min_value) / distance;
|
|
29
23
|
|
|
30
24
|
return (
|
|
31
|
-
|
|
32
|
-
<Text
|
|
33
|
-
{
|
|
25
|
+
<>
|
|
26
|
+
<Text type="H3" semibold color={Colors.Gray9} style={styles.textLabel}>
|
|
27
|
+
{label}
|
|
34
28
|
</Text>
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
29
|
+
<View style={isWidgetOrder ? styles.wrapOrderItem : styles.container}>
|
|
30
|
+
<View style={styles.boxProgress}>
|
|
31
|
+
<View style={styles.boxMaxMinValue}>
|
|
32
|
+
<Text style={styles.textMaxMinValue}>{`${min_value} ${unit}`}</Text>
|
|
33
|
+
<Text style={styles.textMaxMinValue}>{`${max_value} ${unit}`}</Text>
|
|
34
|
+
</View>
|
|
35
|
+
<Progress.Bar
|
|
36
|
+
style={styles.progressBar}
|
|
37
|
+
width={null}
|
|
38
|
+
height={40}
|
|
39
|
+
progress={percent}
|
|
40
|
+
unfilledColor={Colors.Blue15}
|
|
41
|
+
/>
|
|
42
|
+
</View>
|
|
43
|
+
<View>
|
|
44
|
+
<Text
|
|
45
|
+
bold
|
|
46
|
+
style={styles.textValue}
|
|
47
|
+
>{`${displayedValue} ${unit}`}</Text>
|
|
48
|
+
</View>
|
|
51
49
|
</View>
|
|
52
|
-
|
|
50
|
+
</>
|
|
53
51
|
);
|
|
54
52
|
});
|
|
55
53
|
|
|
@@ -4,44 +4,38 @@ import { Colors } from '../../../configs';
|
|
|
4
4
|
|
|
5
5
|
export default StyleSheet.create({
|
|
6
6
|
container: {
|
|
7
|
+
display: 'flex',
|
|
8
|
+
flexDirection: 'row',
|
|
9
|
+
},
|
|
10
|
+
boxProgress: {
|
|
7
11
|
flex: 1,
|
|
8
|
-
flexDirection: 'column',
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
marginBottom: 12,
|
|
12
|
+
flexDirection: 'column',
|
|
13
|
+
padding: 15,
|
|
14
|
+
},
|
|
15
|
+
boxMaxMinValue: {
|
|
16
|
+
flexDirection: 'row',
|
|
17
|
+
justifyContent: 'space-between',
|
|
15
18
|
},
|
|
16
19
|
wrapOrderItem: {
|
|
17
20
|
flex: 1,
|
|
18
|
-
padding:
|
|
19
|
-
flexDirection: '
|
|
21
|
+
padding: 15,
|
|
22
|
+
flexDirection: 'row',
|
|
20
23
|
},
|
|
21
24
|
textLabel: {
|
|
22
|
-
marginLeft:
|
|
25
|
+
marginLeft: 15,
|
|
23
26
|
paddingTop: 8,
|
|
24
27
|
},
|
|
25
|
-
|
|
26
|
-
marginTop: 20,
|
|
28
|
+
textMaxMinValue: {
|
|
27
29
|
marginBottom: 2,
|
|
28
30
|
textAlign: 'left',
|
|
29
|
-
|
|
30
|
-
|
|
31
|
+
},
|
|
32
|
+
textValue: {
|
|
33
|
+
paddingTop: 48,
|
|
34
|
+
marginRight: 8,
|
|
31
35
|
},
|
|
32
36
|
progressBar: {
|
|
33
|
-
flex: 1,
|
|
34
37
|
color: Colors.Blue16,
|
|
35
38
|
borderWidth: 0,
|
|
36
39
|
borderRadius: 10,
|
|
37
40
|
},
|
|
38
|
-
wrapProgressBar: {
|
|
39
|
-
flex: 1,
|
|
40
|
-
flexDirection: 'row',
|
|
41
|
-
justifyContent: 'flex-start',
|
|
42
|
-
alignItems: 'center',
|
|
43
|
-
},
|
|
44
|
-
textValue: {
|
|
45
|
-
marginLeft: 8,
|
|
46
|
-
},
|
|
47
41
|
});
|
|
@@ -15,6 +15,7 @@ import {
|
|
|
15
15
|
import AndroidKeyboardAdjust from 'react-native-android-keyboard-adjust';
|
|
16
16
|
import Text from '../Text';
|
|
17
17
|
import { Colors } from '../../configs';
|
|
18
|
+
import AccessibilityLabel from '../../configs/AccessibilityLabel';
|
|
18
19
|
|
|
19
20
|
const formatNumber = (input, options) => {
|
|
20
21
|
const {
|
|
@@ -151,6 +152,7 @@ const CurrencyInput = ({
|
|
|
151
152
|
onSubmitEditing={onSubmitEditing}
|
|
152
153
|
style={styles.input}
|
|
153
154
|
maxLength={10}
|
|
155
|
+
accessibilityLabel={AccessibilityLabel.INPUT_CALCULATE_COST}
|
|
154
156
|
/>
|
|
155
157
|
<Text
|
|
156
158
|
semibold
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import React, { memo, useCallback, useEffect, useRef, useState } from 'react';
|
|
2
|
+
|
|
3
|
+
import { styles } from './IFrameStyles';
|
|
4
|
+
import IconComponent from '../../IconComponent';
|
|
5
|
+
import WebView from 'react-native-webview';
|
|
6
|
+
import { TouchableOpacity, View } from 'react-native';
|
|
7
|
+
|
|
8
|
+
const IFrame = memo(
|
|
9
|
+
({ item = {}, widgetStyle, isWidgetBox, isSetting, isEditing }) => {
|
|
10
|
+
const ref = useRef();
|
|
11
|
+
const [urlWithEnv, setUrlWithEnv] = useState();
|
|
12
|
+
|
|
13
|
+
const { configuration } = item;
|
|
14
|
+
const { url } = configuration || {};
|
|
15
|
+
|
|
16
|
+
const reload = useCallback(() => {
|
|
17
|
+
ref.current.reload();
|
|
18
|
+
}, []);
|
|
19
|
+
|
|
20
|
+
useEffect(() => {
|
|
21
|
+
if (!url) {
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
if (!url.includes('?')) {
|
|
25
|
+
setUrlWithEnv(
|
|
26
|
+
`${url}?eraOrigin=${window.location.origin}&eraWidget=${item?.id}`
|
|
27
|
+
);
|
|
28
|
+
} else {
|
|
29
|
+
setUrlWithEnv(
|
|
30
|
+
`${url}&eraOrigin=${window.location.origin}&eraWidget=${item?.id}`
|
|
31
|
+
);
|
|
32
|
+
}
|
|
33
|
+
}, [item?.id, url]);
|
|
34
|
+
|
|
35
|
+
return (
|
|
36
|
+
<View>
|
|
37
|
+
<TouchableOpacity
|
|
38
|
+
style={isEditing ? styles.reloadButtonEditing : styles.reloadButton}
|
|
39
|
+
onClick={reload}
|
|
40
|
+
>
|
|
41
|
+
<IconComponent icon="ReloadOutlined" />
|
|
42
|
+
</TouchableOpacity>
|
|
43
|
+
<WebView
|
|
44
|
+
source={{ uri: urlWithEnv }}
|
|
45
|
+
style={styles.iframe}
|
|
46
|
+
ref={ref}
|
|
47
|
+
title={item?.title}
|
|
48
|
+
/>
|
|
49
|
+
</View>
|
|
50
|
+
);
|
|
51
|
+
}
|
|
52
|
+
);
|
|
53
|
+
|
|
54
|
+
export default IFrame;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { StyleSheet } from 'react-native';
|
|
2
|
+
import { Colors } from '../../../configs';
|
|
3
|
+
|
|
4
|
+
export const styles = StyleSheet.create({
|
|
5
|
+
iframe: {
|
|
6
|
+
display: 'flex',
|
|
7
|
+
width: '100%',
|
|
8
|
+
height: '100%',
|
|
9
|
+
paddingHorizontal: 16,
|
|
10
|
+
},
|
|
11
|
+
reloadButton: {
|
|
12
|
+
position: 'absolute',
|
|
13
|
+
right: 16,
|
|
14
|
+
top: 5,
|
|
15
|
+
border: '1px solid #E6E6E6',
|
|
16
|
+
backgroundColor: Colors.White,
|
|
17
|
+
},
|
|
18
|
+
reloadButtonEditing: {
|
|
19
|
+
position: 'absolute',
|
|
20
|
+
right: 77,
|
|
21
|
+
top: 0,
|
|
22
|
+
width: 36,
|
|
23
|
+
marginLeft: 2,
|
|
24
|
+
paddingTop: 5,
|
|
25
|
+
paddingBottom: 5,
|
|
26
|
+
justifyContent: 'center',
|
|
27
|
+
alignItems: 'center',
|
|
28
|
+
borderRadius: 4,
|
|
29
|
+
backgroundColor: Colors.White,
|
|
30
|
+
border: '1px solid #E6E6E6',
|
|
31
|
+
},
|
|
32
|
+
settingWidget: {
|
|
33
|
+
width: 256,
|
|
34
|
+
},
|
|
35
|
+
});
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import React, { useRef } from 'react';
|
|
2
|
+
import { act } from 'react-test-renderer';
|
|
3
|
+
|
|
4
|
+
import IFrame from '../IFrame';
|
|
5
|
+
import WebView from 'react-native-webview';
|
|
6
|
+
import { TouchableOpacity } from 'react-native';
|
|
7
|
+
import { render } from '../../../../../jest/render';
|
|
8
|
+
|
|
9
|
+
describe('Test IFrame', () => {
|
|
10
|
+
let item;
|
|
11
|
+
beforeEach(() => {
|
|
12
|
+
item = {
|
|
13
|
+
id: 1,
|
|
14
|
+
configuration: {
|
|
15
|
+
url: 'http://localhost:3000/',
|
|
16
|
+
},
|
|
17
|
+
};
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
test('test with widget box', async () => {
|
|
21
|
+
const { root } = await render(<IFrame isWidgetBox item={item} />);
|
|
22
|
+
|
|
23
|
+
const iframes = root.findAllByType(WebView);
|
|
24
|
+
expect(iframes).toHaveLength(1);
|
|
25
|
+
|
|
26
|
+
expect(iframes[0].props.source?.uri).toEqual(
|
|
27
|
+
'http://localhost:3000/?eraOrigin=http://localhost&eraWidget=1'
|
|
28
|
+
);
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
test('test with query string', async () => {
|
|
32
|
+
item.configuration.url = 'http://localhost:3000/?test=1';
|
|
33
|
+
const { root } = await render(<IFrame isWidgetBox item={item} />);
|
|
34
|
+
|
|
35
|
+
const iframes = root.findAllByType(WebView);
|
|
36
|
+
expect(iframes).toHaveLength(1);
|
|
37
|
+
|
|
38
|
+
expect(iframes[0].props.source?.uri).toEqual(
|
|
39
|
+
'http://localhost:3000/?test=1&eraOrigin=http://localhost&eraWidget=1'
|
|
40
|
+
);
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
test('test no url', async () => {
|
|
44
|
+
item.configuration.url = null;
|
|
45
|
+
const { root } = await render(<IFrame isWidgetBox item={item} />);
|
|
46
|
+
|
|
47
|
+
const iframes = root.findAllByType(WebView);
|
|
48
|
+
expect(iframes).toHaveLength(1);
|
|
49
|
+
|
|
50
|
+
expect(iframes[0].props.source?.uri).toEqual(undefined);
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
test('test reload', async () => {
|
|
54
|
+
const ref = {
|
|
55
|
+
current: {},
|
|
56
|
+
};
|
|
57
|
+
useRef.mockReturnValue(ref);
|
|
58
|
+
|
|
59
|
+
const mockReload = jest.fn();
|
|
60
|
+
const { root } = await render(<IFrame isWidgetBox item={item} />);
|
|
61
|
+
ref.current = {
|
|
62
|
+
reload: mockReload,
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
const buttons = root.findAllByType(TouchableOpacity);
|
|
66
|
+
expect(buttons).toHaveLength(1);
|
|
67
|
+
|
|
68
|
+
await act(async () => {
|
|
69
|
+
buttons[0].props.onClick();
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
expect(mockReload).toHaveBeenCalledTimes(1);
|
|
73
|
+
});
|
|
74
|
+
});
|
|
File without changes
|
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
import moment from 'moment';
|
|
2
|
+
import React, { memo, useCallback, useEffect, useRef, useState } from 'react';
|
|
3
|
+
|
|
4
|
+
import { styles as useIframeStyle } from '../IFrame/IFrameStyles';
|
|
5
|
+
import { styles } from './IFrameWithConfigStyles';
|
|
6
|
+
import IconComponent from '../../IconComponent';
|
|
7
|
+
import { useConfigGlobalState } from '../../../iot/states';
|
|
8
|
+
import { useFetchConfigHistory } from '../../UnitSummary/ConfigHistoryChart';
|
|
9
|
+
import API from '../../../configs/API';
|
|
10
|
+
import WebView from 'react-native-webview';
|
|
11
|
+
import { TouchableOpacity, View } from 'react-native';
|
|
12
|
+
|
|
13
|
+
const IFrameWithConfig = memo(
|
|
14
|
+
({ item = {}, widgetStyle, isWidgetBox, isSetting, isEditing }) => {
|
|
15
|
+
const ref = useRef();
|
|
16
|
+
|
|
17
|
+
const { configuration } = item;
|
|
18
|
+
const { url } = configuration || {};
|
|
19
|
+
|
|
20
|
+
const [height, setHeight] = useState(200);
|
|
21
|
+
const [urlWithEnv, setUrlWithEnv] = useState();
|
|
22
|
+
const [isReady, setIsReady] = useState(false);
|
|
23
|
+
|
|
24
|
+
const [configValues] = useConfigGlobalState('configValues');
|
|
25
|
+
const [chartData, setChartData] = useState(configuration?.history_configs);
|
|
26
|
+
const fetchDataDisplayHistory = useFetchConfigHistory(
|
|
27
|
+
configuration?.history_configs,
|
|
28
|
+
setChartData,
|
|
29
|
+
API.CONFIG.DISPLAY_HISTORY_V4()
|
|
30
|
+
);
|
|
31
|
+
|
|
32
|
+
const postMessage = useCallback((message) => {
|
|
33
|
+
ref.current?.injectJavaScript(
|
|
34
|
+
'window.postMessage(' + JSON.stringify(message) + ', "*")'
|
|
35
|
+
);
|
|
36
|
+
}, []);
|
|
37
|
+
|
|
38
|
+
useEffect(() => {
|
|
39
|
+
if (!isReady || !ref.current) {
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
if (!configuration?.history_configs?.length) {
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
postMessage({
|
|
46
|
+
source: 'eraIframeWidget',
|
|
47
|
+
type: 'histories',
|
|
48
|
+
data: chartData,
|
|
49
|
+
eraWidgetId: item.id,
|
|
50
|
+
});
|
|
51
|
+
}, [
|
|
52
|
+
chartData,
|
|
53
|
+
configuration?.history_configs?.length,
|
|
54
|
+
configuration.realtime_configs,
|
|
55
|
+
isReady,
|
|
56
|
+
item.id,
|
|
57
|
+
postMessage,
|
|
58
|
+
]);
|
|
59
|
+
|
|
60
|
+
useEffect(() => {
|
|
61
|
+
const appendix = `eraOrigin=http://localhost:3000&eraWidget=${item?.id}`;
|
|
62
|
+
if (!url.includes('?')) {
|
|
63
|
+
setUrlWithEnv(`${url}?${appendix}`);
|
|
64
|
+
} else {
|
|
65
|
+
setUrlWithEnv(`${url}&${appendix}`);
|
|
66
|
+
}
|
|
67
|
+
}, [item?.id, url]);
|
|
68
|
+
|
|
69
|
+
const onMessage = useCallback(
|
|
70
|
+
async (event) => {
|
|
71
|
+
const eventData = event.nativeEvent.data
|
|
72
|
+
? JSON.parse(event.nativeEvent.data)
|
|
73
|
+
: {};
|
|
74
|
+
if (
|
|
75
|
+
eventData?.source !== 'eraIframeWidget' ||
|
|
76
|
+
eventData?.eraWidgetId !== item.id
|
|
77
|
+
) {
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
const { type, data } = eventData;
|
|
81
|
+
|
|
82
|
+
switch (type) {
|
|
83
|
+
case 'ready':
|
|
84
|
+
postMessage({
|
|
85
|
+
source: 'eraIframeWidget',
|
|
86
|
+
type: 'configuration',
|
|
87
|
+
data: configuration,
|
|
88
|
+
eraWidgetId: item.id,
|
|
89
|
+
});
|
|
90
|
+
setIsReady(true);
|
|
91
|
+
break;
|
|
92
|
+
case 'requestHistories':
|
|
93
|
+
await fetchDataDisplayHistory(moment(data[0]), moment(data[1]));
|
|
94
|
+
break;
|
|
95
|
+
case 'requestAdjustMobileHeight':
|
|
96
|
+
setHeight(data);
|
|
97
|
+
break;
|
|
98
|
+
}
|
|
99
|
+
},
|
|
100
|
+
[configuration, fetchDataDisplayHistory, item.id, postMessage]
|
|
101
|
+
);
|
|
102
|
+
|
|
103
|
+
useEffect(() => {
|
|
104
|
+
if (!isReady || !ref?.current) {
|
|
105
|
+
return;
|
|
106
|
+
}
|
|
107
|
+
if (!configuration?.realtime_configs?.length) {
|
|
108
|
+
return;
|
|
109
|
+
}
|
|
110
|
+
const values = {};
|
|
111
|
+
configuration?.realtime_configs.map((config) => {
|
|
112
|
+
return (values[config.id] = configValues[config.id]);
|
|
113
|
+
});
|
|
114
|
+
postMessage({
|
|
115
|
+
source: 'eraIframeWidget',
|
|
116
|
+
type: 'values',
|
|
117
|
+
data: values,
|
|
118
|
+
eraWidgetId: item.id,
|
|
119
|
+
});
|
|
120
|
+
}, [
|
|
121
|
+
isReady,
|
|
122
|
+
configValues,
|
|
123
|
+
configuration?.realtime_configs,
|
|
124
|
+
item.id,
|
|
125
|
+
postMessage,
|
|
126
|
+
]);
|
|
127
|
+
|
|
128
|
+
const reload = useCallback(() => {
|
|
129
|
+
setIsReady(false);
|
|
130
|
+
ref.current.reload();
|
|
131
|
+
}, []);
|
|
132
|
+
|
|
133
|
+
return (
|
|
134
|
+
<View
|
|
135
|
+
style={
|
|
136
|
+
isSetting
|
|
137
|
+
? styles.settingWidget
|
|
138
|
+
: { ...styles.wrapper, height: height }
|
|
139
|
+
}
|
|
140
|
+
>
|
|
141
|
+
<TouchableOpacity
|
|
142
|
+
className={
|
|
143
|
+
isEditing
|
|
144
|
+
? useIframeStyle.reloadButtonEditing
|
|
145
|
+
: useIframeStyle.reloadButton
|
|
146
|
+
}
|
|
147
|
+
onClick={reload}
|
|
148
|
+
>
|
|
149
|
+
<IconComponent name="ReloadOutlined" />
|
|
150
|
+
</TouchableOpacity>
|
|
151
|
+
<WebView
|
|
152
|
+
source={{ uri: urlWithEnv }}
|
|
153
|
+
className={useIframeStyle.iframe}
|
|
154
|
+
ref={ref}
|
|
155
|
+
title={item?.title}
|
|
156
|
+
onMessage={onMessage}
|
|
157
|
+
/>
|
|
158
|
+
</View>
|
|
159
|
+
);
|
|
160
|
+
}
|
|
161
|
+
);
|
|
162
|
+
|
|
163
|
+
export default IFrameWithConfig;
|
|
@@ -0,0 +1,284 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { act } from 'react-test-renderer';
|
|
3
|
+
|
|
4
|
+
import IFrameWithConfig from '../IFrameWithConfig';
|
|
5
|
+
import { useConfigGlobalState } from '../../../../iot/states';
|
|
6
|
+
import { render } from '../../../../../jest/render';
|
|
7
|
+
import API from '../../../../configs/API';
|
|
8
|
+
import MockAdapter from 'axios-mock-adapter';
|
|
9
|
+
import api from '../../../../utils/Apis/axios';
|
|
10
|
+
import WebView from 'react-native-webview';
|
|
11
|
+
import { TouchableOpacity, View } from 'react-native';
|
|
12
|
+
import { refFunctions } from '../../../../../__mocks__/react-native-webview';
|
|
13
|
+
|
|
14
|
+
jest.mock('../../../../iot/states', () => {
|
|
15
|
+
return {
|
|
16
|
+
...jest.requireActual('../../../../iot/states'),
|
|
17
|
+
useConfigGlobalState: jest.fn(),
|
|
18
|
+
};
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
describe('Test IFrame With Config', () => {
|
|
22
|
+
let item;
|
|
23
|
+
let configValues = {
|
|
24
|
+
1: {
|
|
25
|
+
value: 0.5,
|
|
26
|
+
},
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
beforeEach(() => {
|
|
30
|
+
item = {
|
|
31
|
+
id: 1,
|
|
32
|
+
configuration: {
|
|
33
|
+
url: 'http://localhost:3000/',
|
|
34
|
+
realtime_configs: [{ id: 1 }],
|
|
35
|
+
},
|
|
36
|
+
};
|
|
37
|
+
useConfigGlobalState.mockImplementation(() => [configValues]);
|
|
38
|
+
refFunctions.injectJavaScript.mockClear();
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
test('test with widget box', async () => {
|
|
42
|
+
const { root } = await render(<IFrameWithConfig isWidgetBox item={item} />);
|
|
43
|
+
|
|
44
|
+
const iframes = root.findAllByType(WebView);
|
|
45
|
+
expect(iframes).toHaveLength(1);
|
|
46
|
+
|
|
47
|
+
expect(iframes[0].props.source?.uri).toEqual(
|
|
48
|
+
'http://localhost:3000/?eraOrigin=http://localhost:3000&eraWidget=1'
|
|
49
|
+
);
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
test('test with query string', async () => {
|
|
53
|
+
item.configuration.url = 'http://localhost:3000/?test=1';
|
|
54
|
+
const { root } = await render(<IFrameWithConfig isWidgetBox item={item} />);
|
|
55
|
+
|
|
56
|
+
const iframes = root.findAllByType(WebView);
|
|
57
|
+
expect(iframes).toHaveLength(1);
|
|
58
|
+
|
|
59
|
+
expect(iframes[0].props.source?.uri).toEqual(
|
|
60
|
+
'http://localhost:3000/?test=1&eraOrigin=http://localhost:3000&eraWidget=1'
|
|
61
|
+
);
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
test('test reload', async () => {
|
|
65
|
+
const { root } = await render(<IFrameWithConfig isWidgetBox item={item} />);
|
|
66
|
+
|
|
67
|
+
const buttons = root.findAllByType(TouchableOpacity);
|
|
68
|
+
expect(buttons).toHaveLength(1);
|
|
69
|
+
|
|
70
|
+
await act(async () => {
|
|
71
|
+
buttons[0].props.onClick();
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
expect(refFunctions.reload).toHaveBeenCalledTimes(1);
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
test('test iframe is ready', async () => {
|
|
78
|
+
const { root } = await render(<IFrameWithConfig isWidgetBox item={item} />);
|
|
79
|
+
const webview = root.findByType(WebView);
|
|
80
|
+
|
|
81
|
+
await act(async () => {
|
|
82
|
+
await webview.props.onMessage({
|
|
83
|
+
nativeEvent: {
|
|
84
|
+
data: JSON.stringify({
|
|
85
|
+
type: 'ready',
|
|
86
|
+
eraWidgetId: 1,
|
|
87
|
+
source: 'eraIframeWidget',
|
|
88
|
+
}),
|
|
89
|
+
origin: 'http://localhost',
|
|
90
|
+
},
|
|
91
|
+
});
|
|
92
|
+
});
|
|
93
|
+
expectSendMessage(
|
|
94
|
+
{
|
|
95
|
+
source: 'eraIframeWidget',
|
|
96
|
+
type: 'configuration',
|
|
97
|
+
data: item.configuration,
|
|
98
|
+
eraWidgetId: 1,
|
|
99
|
+
},
|
|
100
|
+
'http://localhost:3000'
|
|
101
|
+
);
|
|
102
|
+
expectSendMessage(
|
|
103
|
+
{
|
|
104
|
+
source: 'eraIframeWidget',
|
|
105
|
+
type: 'values',
|
|
106
|
+
data: configValues,
|
|
107
|
+
eraWidgetId: 1,
|
|
108
|
+
},
|
|
109
|
+
'http://localhost:3000'
|
|
110
|
+
);
|
|
111
|
+
unexpectSendMessage(
|
|
112
|
+
{
|
|
113
|
+
source: 'eraIframeWidget',
|
|
114
|
+
type: 'histories',
|
|
115
|
+
data: [{ id: 1 }],
|
|
116
|
+
eraWidgetId: 1,
|
|
117
|
+
},
|
|
118
|
+
'http://localhost:3000'
|
|
119
|
+
);
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
test('test iframe request more height', async () => {
|
|
123
|
+
const { root } = await render(<IFrameWithConfig isWidgetBox item={item} />);
|
|
124
|
+
const webview = root.findByType(WebView);
|
|
125
|
+
|
|
126
|
+
await act(async () => {
|
|
127
|
+
await webview.props.onMessage({
|
|
128
|
+
nativeEvent: {
|
|
129
|
+
data: JSON.stringify({
|
|
130
|
+
type: 'requestAdjustMobileHeight',
|
|
131
|
+
data: 100,
|
|
132
|
+
eraWidgetId: 1,
|
|
133
|
+
source: 'eraIframeWidget',
|
|
134
|
+
}),
|
|
135
|
+
origin: 'http://localhost',
|
|
136
|
+
},
|
|
137
|
+
});
|
|
138
|
+
});
|
|
139
|
+
|
|
140
|
+
const wrapper = root.findAllByType(View)[0];
|
|
141
|
+
expect(wrapper.props.style.height).toEqual(100);
|
|
142
|
+
});
|
|
143
|
+
|
|
144
|
+
test('test iframe receive message from unexpected origin', async () => {
|
|
145
|
+
const { root } = await render(<IFrameWithConfig isWidgetBox item={item} />);
|
|
146
|
+
const webview = root.findByType(WebView);
|
|
147
|
+
|
|
148
|
+
await act(async () => {
|
|
149
|
+
webview.props.onMessage({
|
|
150
|
+
nativeEvent: {
|
|
151
|
+
data: JSON.stringify({
|
|
152
|
+
type: 'ready',
|
|
153
|
+
eraWidgetId: 2,
|
|
154
|
+
source: 'eraIframeWidget',
|
|
155
|
+
}),
|
|
156
|
+
origin: 'http://localhost',
|
|
157
|
+
},
|
|
158
|
+
});
|
|
159
|
+
});
|
|
160
|
+
expect(refFunctions.injectJavaScript).toHaveBeenCalledTimes(0);
|
|
161
|
+
|
|
162
|
+
await act(async () => {
|
|
163
|
+
webview.props.onMessage({
|
|
164
|
+
nativeEvent: {
|
|
165
|
+
data: JSON.stringify({
|
|
166
|
+
type: 'ready',
|
|
167
|
+
eraWidgetId: 1,
|
|
168
|
+
source: 'eraIframeWidget-wrong',
|
|
169
|
+
}),
|
|
170
|
+
origin: 'http://localhost',
|
|
171
|
+
},
|
|
172
|
+
});
|
|
173
|
+
});
|
|
174
|
+
expect(refFunctions.injectJavaScript).toHaveBeenCalledTimes(0);
|
|
175
|
+
});
|
|
176
|
+
|
|
177
|
+
test('test iframe init chart data', async () => {
|
|
178
|
+
item.configuration.history_configs = [{ id: 1 }];
|
|
179
|
+
item.configuration.realtime_configs = [];
|
|
180
|
+
|
|
181
|
+
const { root } = await render(<IFrameWithConfig isWidgetBox item={item} />);
|
|
182
|
+
const webview = root.findByType(WebView);
|
|
183
|
+
|
|
184
|
+
await act(async () => {
|
|
185
|
+
webview.props.onMessage({
|
|
186
|
+
nativeEvent: {
|
|
187
|
+
data: JSON.stringify({
|
|
188
|
+
type: 'ready',
|
|
189
|
+
eraWidgetId: 1,
|
|
190
|
+
source: 'eraIframeWidget',
|
|
191
|
+
}),
|
|
192
|
+
origin: 'http://localhost',
|
|
193
|
+
},
|
|
194
|
+
});
|
|
195
|
+
});
|
|
196
|
+
unexpectSendMessage(
|
|
197
|
+
{
|
|
198
|
+
source: 'eraIframeWidget',
|
|
199
|
+
type: 'configValues',
|
|
200
|
+
data: configValues,
|
|
201
|
+
eraWidgetId: 1,
|
|
202
|
+
},
|
|
203
|
+
'http://localhost:3000'
|
|
204
|
+
);
|
|
205
|
+
expectSendMessage(
|
|
206
|
+
{
|
|
207
|
+
source: 'eraIframeWidget',
|
|
208
|
+
type: 'histories',
|
|
209
|
+
data: [{ id: 1 }],
|
|
210
|
+
eraWidgetId: 1,
|
|
211
|
+
},
|
|
212
|
+
'http://localhost:3000'
|
|
213
|
+
);
|
|
214
|
+
});
|
|
215
|
+
|
|
216
|
+
test('test iframe request chart data', async () => {
|
|
217
|
+
item.configuration.history_configs = [{ id: 1 }];
|
|
218
|
+
item.configuration.realtime_configs = [];
|
|
219
|
+
|
|
220
|
+
const { root } = await render(<IFrameWithConfig isWidgetBox item={item} />);
|
|
221
|
+
const webview = root.findByType(WebView);
|
|
222
|
+
|
|
223
|
+
await act(async () => {
|
|
224
|
+
webview.props.onMessage({
|
|
225
|
+
nativeEvent: {
|
|
226
|
+
data: JSON.stringify({
|
|
227
|
+
type: 'ready',
|
|
228
|
+
eraWidgetId: 1,
|
|
229
|
+
source: 'eraIframeWidget',
|
|
230
|
+
}),
|
|
231
|
+
origin: 'http://localhost',
|
|
232
|
+
},
|
|
233
|
+
});
|
|
234
|
+
});
|
|
235
|
+
|
|
236
|
+
const mockAxios = new MockAdapter(api.axiosInstance);
|
|
237
|
+
mockAxios.onGet(API.CONFIG.DISPLAY_HISTORY_V4()).reply(200, {
|
|
238
|
+
configs: [
|
|
239
|
+
{
|
|
240
|
+
id: 1,
|
|
241
|
+
head: [],
|
|
242
|
+
tail: [{ x: 1000, y: 100 }],
|
|
243
|
+
middle: { ready: [], not_ready: [] },
|
|
244
|
+
},
|
|
245
|
+
],
|
|
246
|
+
});
|
|
247
|
+
refFunctions.injectJavaScript.mockClear();
|
|
248
|
+
|
|
249
|
+
await act(async () => {
|
|
250
|
+
await webview.props.onMessage({
|
|
251
|
+
nativeEvent: {
|
|
252
|
+
data: JSON.stringify({
|
|
253
|
+
type: 'requestHistories',
|
|
254
|
+
eraWidgetId: 1,
|
|
255
|
+
source: 'eraIframeWidget',
|
|
256
|
+
data: [1, 2],
|
|
257
|
+
}),
|
|
258
|
+
origin: 'http://localhost',
|
|
259
|
+
},
|
|
260
|
+
});
|
|
261
|
+
});
|
|
262
|
+
|
|
263
|
+
expectSendMessage(
|
|
264
|
+
{
|
|
265
|
+
source: 'eraIframeWidget',
|
|
266
|
+
type: 'histories',
|
|
267
|
+
data: [{ id: 1, data: [{ x: 1000, y: 100 }] }],
|
|
268
|
+
eraWidgetId: 1,
|
|
269
|
+
},
|
|
270
|
+
'http://localhost:3000'
|
|
271
|
+
);
|
|
272
|
+
});
|
|
273
|
+
|
|
274
|
+
const expectSendMessage = (message) => {
|
|
275
|
+
expect(refFunctions.injectJavaScript).toHaveBeenCalledWith(
|
|
276
|
+
'window.postMessage(' + JSON.stringify(message) + ', "*")'
|
|
277
|
+
);
|
|
278
|
+
};
|
|
279
|
+
const unexpectSendMessage = (message) => {
|
|
280
|
+
expect(refFunctions.injectJavaScript).not.toHaveBeenCalledWith(
|
|
281
|
+
'window.postMessage(' + JSON.stringify(message) + ', "*")'
|
|
282
|
+
);
|
|
283
|
+
};
|
|
284
|
+
});
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
@@ -413,6 +413,9 @@ export default {
|
|
|
413
413
|
COMPASS_VALUE: 'COMPASS_VALUE',
|
|
414
414
|
GROUP_CHECKBOX_ITEM: 'GROUP_CHECKBOX_ITEM',
|
|
415
415
|
TOTAL_POWER_BOX_TITLE: 'TOTAL_POWER_BOX_TITLE',
|
|
416
|
+
INPUT_CALCULATE_COST: 'INPUT_CALCULATE_COST',
|
|
417
|
+
BUTTON_CALCULATE_COST: 'BUTTON_CALCULATE_COST',
|
|
418
|
+
TOTAL_PRICE: 'TOTAL_PRICE',
|
|
416
419
|
EMERGENCY_POPUP: 'EMERGENCY_POPUP',
|
|
417
420
|
RESOLVED_EMERGENCY_POPUP: 'RESOLVED_EMERGENCY_POPUP',
|
|
418
421
|
TOTAL_POWER_CONSUMPTION: 'TOTAL_POWER_CONSUMPTION',
|
package/src/configs/Constants.js
CHANGED
|
@@ -33,7 +33,6 @@ const useDevicesStatus = (unit, devices) => {
|
|
|
33
33
|
);
|
|
34
34
|
success && setAction(Action.SET_DEVICES_STATUS, data);
|
|
35
35
|
timeoutId = setTimeout(() => getDevicesStatus(_unit, _devices), 10000);
|
|
36
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
37
36
|
},
|
|
38
37
|
[setAction]
|
|
39
38
|
);
|
|
@@ -13,7 +13,7 @@ import ListQualityIndicator from '../../../commons/Device/WaterQualitySensor/Lis
|
|
|
13
13
|
import Compass from '../../../commons/Device/WindDirection/Compass';
|
|
14
14
|
import Anemometer from '../../../commons/Device/WindSpeed/Anemometer';
|
|
15
15
|
import MediaPlayerDetail from '../../../commons/MediaPlayerDetail';
|
|
16
|
-
import { AccessibilityLabel } from '../../../configs/Constants';
|
|
16
|
+
import { AccessibilityLabel, WIDGET_TYPE } from '../../../configs/Constants';
|
|
17
17
|
import { useSCContextSelector } from '../../../context';
|
|
18
18
|
import { useRemoteControl } from '../../../hooks/IoT';
|
|
19
19
|
import { useConfigGlobalState } from '../../../iot/states';
|
|
@@ -24,6 +24,8 @@ import VisualChart from './VisualChart';
|
|
|
24
24
|
import { standardizeCameraScreenSize } from '../../../utils/Utils';
|
|
25
25
|
import { Device } from '../../../configs';
|
|
26
26
|
import DonutCharts from './DonutChart';
|
|
27
|
+
import IFrame from '../../../commons/Widgets/IFrame/IFrame';
|
|
28
|
+
import IFrameWithConfig from '../../../commons/Widgets/IFrameWithConfig/IFrameWithConfig';
|
|
27
29
|
|
|
28
30
|
const { standardizeWidth, standardizeHeight } = standardizeCameraScreenSize(
|
|
29
31
|
Device.screenWidth - 32
|
|
@@ -175,6 +177,26 @@ export const SensorDisplayItem = ({
|
|
|
175
177
|
isWidgetOrder={isWidgetOrder}
|
|
176
178
|
/>
|
|
177
179
|
);
|
|
180
|
+
case WIDGET_TYPE.iframe:
|
|
181
|
+
return (
|
|
182
|
+
<IFrame
|
|
183
|
+
doAction={doAction}
|
|
184
|
+
sensor={sensor}
|
|
185
|
+
id={idTemplate}
|
|
186
|
+
item={item}
|
|
187
|
+
isWidgetOrder={isWidgetOrder}
|
|
188
|
+
/>
|
|
189
|
+
);
|
|
190
|
+
case WIDGET_TYPE.iframeWithConfig:
|
|
191
|
+
return (
|
|
192
|
+
<IFrameWithConfig
|
|
193
|
+
doAction={doAction}
|
|
194
|
+
sensor={sensor}
|
|
195
|
+
id={idTemplate}
|
|
196
|
+
item={item}
|
|
197
|
+
isWidgetOrder={isWidgetOrder}
|
|
198
|
+
/>
|
|
199
|
+
);
|
|
178
200
|
case 'history':
|
|
179
201
|
return (
|
|
180
202
|
<VisualChart
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import MockAdapter from 'axios-mock-adapter';
|
|
3
3
|
import moment from 'moment';
|
|
4
|
-
import { act
|
|
4
|
+
import { act } from 'react-test-renderer';
|
|
5
5
|
|
|
6
6
|
import VisualChart from '../VisualChart';
|
|
7
7
|
import { API } from '../../../../configs';
|
|
@@ -11,14 +11,7 @@ import api from '../../../../utils/Apis/axios';
|
|
|
11
11
|
import ChartAggregationOption from '../../../../commons/ChartAggregationOption';
|
|
12
12
|
import DateTimeRangeChange from '../../../../commons/DateTimeRangeChange';
|
|
13
13
|
import Highcharts from '../../../../commons/Highcharts';
|
|
14
|
-
|
|
15
|
-
const render = async (component) => {
|
|
16
|
-
let tree;
|
|
17
|
-
await act(async () => {
|
|
18
|
-
tree = await create(component);
|
|
19
|
-
});
|
|
20
|
-
return tree;
|
|
21
|
-
};
|
|
14
|
+
import { render } from '../../../../../jest/render';
|
|
22
15
|
|
|
23
16
|
const mockAxios = new MockAdapter(api.axiosInstance);
|
|
24
17
|
|
package/src/screens/UnitSummary/components/PowerConsumption/__test__/PowerConsumption.test.js
CHANGED
|
@@ -146,6 +146,25 @@ describe('Test PowerConsumption', () => {
|
|
|
146
146
|
const instance = tree.root;
|
|
147
147
|
const Todays = instance.findByType(Today);
|
|
148
148
|
expect(Todays).toBeDefined();
|
|
149
|
+
|
|
150
|
+
const input_calculate_cost = instance.find(
|
|
151
|
+
(el) =>
|
|
152
|
+
el.props.accessibilityLabel === AccessibilityLabel.INPUT_CALCULATE_COST
|
|
153
|
+
);
|
|
154
|
+
await act(async () => {
|
|
155
|
+
input_calculate_cost.props.onChangeText('1000');
|
|
156
|
+
});
|
|
157
|
+
const button_calculate_cost = instance.find(
|
|
158
|
+
(el) =>
|
|
159
|
+
el.props.accessibilityLabel === AccessibilityLabel.BUTTON_CALCULATE_COST
|
|
160
|
+
);
|
|
161
|
+
await act(async () => {
|
|
162
|
+
button_calculate_cost.props.onPress();
|
|
163
|
+
});
|
|
164
|
+
const totalPrice = instance.find(
|
|
165
|
+
(el) => el.props.accessibilityLabel === AccessibilityLabel.TOTAL_PRICE
|
|
166
|
+
);
|
|
167
|
+
expect(totalPrice.props.children).toEqual('57.380 đ');
|
|
149
168
|
});
|
|
150
169
|
|
|
151
170
|
it('render with unsuccess fetch', async () => {
|