@eohjsc/react-native-smart-city 0.5.0 → 0.5.2

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.
Files changed (54) hide show
  1. package/package.json +2 -2
  2. package/src/commons/ActionGroup/OnOffTemplate/OnOffButtonTemplateStyle.js +0 -1
  3. package/src/commons/ActionGroup/OnOffTemplate/OnOffSimpleTemplateStyle.js +1 -0
  4. package/src/commons/ActionGroup/OnOffTemplate/SwitchButtonTemplate.js +60 -48
  5. package/src/commons/ActionGroup/OnOffTemplate/index.js +1 -2
  6. package/src/commons/ActionGroup/SliderRangeTemplate.js +60 -64
  7. package/src/commons/ActionGroup/SliderRangeTemplateStyles.js +2 -4
  8. package/src/commons/ActionGroup/TerminalBoxTemplate.js +6 -6
  9. package/src/commons/ActionGroup/TextBoxTemplate.js +2 -2
  10. package/src/commons/ActionGroup/__test__/SliderRangeTemplate.test.js +72 -16
  11. package/src/commons/ActionGroup/__test__/SwitchButtonTemplate.test.js +33 -25
  12. package/src/commons/ActionGroup/__test__/TextBoxTemplate.test.js +19 -0
  13. package/src/commons/Device/RainningSensor/CurrentRainSensor.js +50 -45
  14. package/src/commons/Form/TextInput.js +2 -0
  15. package/src/commons/Header/Styles/HeaderCustomStyles.js +1 -1
  16. package/src/commons/HeaderAni/index.js +1 -1
  17. package/src/commons/Sharing/WrapHeaderScrollable.js +1 -2
  18. package/src/configs/AccessibilityLabel.js +8 -0
  19. package/src/navigations/AddMemberStack.js +8 -3
  20. package/src/screens/AddCommon/SelectUnit.js +1 -1
  21. package/src/screens/AddCommon/__test__/SelectUnit.test.js +1 -1
  22. package/src/screens/Automate/AddNewAction/SetupScriptDelay.js +1 -1
  23. package/src/screens/Automate/Components/InputName.js +8 -2
  24. package/src/screens/Automate/EditActionsList/index.js +5 -5
  25. package/src/screens/Automate/OneTap/__test__/AddNewOneTap.test.js +17 -3
  26. package/src/screens/Device/components/SensorDisplayItem.js +7 -3
  27. package/src/screens/Device/detail.js +1 -1
  28. package/src/screens/Sharing/Components/CheckBoxConfig.js +44 -0
  29. package/src/screens/Sharing/Components/CheckBoxCustom.js +2 -13
  30. package/src/screens/Sharing/Components/CheckBoxSubUnit.js +35 -0
  31. package/src/screens/Sharing/Components/EndDevice.js +93 -0
  32. package/src/screens/Sharing/Components/Styles/CheckBoxConfigStyles.js +18 -0
  33. package/src/screens/Sharing/Components/Styles/DeviceItemStyles.js +28 -35
  34. package/src/screens/Sharing/Components/index.js +1 -2
  35. package/src/screens/Sharing/InfoMemberUnit.js +1 -2
  36. package/src/screens/Sharing/SelectShareDevice.js +273 -0
  37. package/src/screens/Sharing/Styles/SelectPermissionStyles.js +2 -11
  38. package/src/screens/Sharing/UnitMemberList.js +1 -1
  39. package/src/screens/Sharing/UpdateShareDevice.js +322 -0
  40. package/src/screens/Sharing/__test__/SelectShareDevice.test.js +215 -0
  41. package/src/screens/Sharing/__test__/UnitMemberList.test.js +1 -1
  42. package/src/screens/Sharing/__test__/UpdateShareDevice.test.js +307 -0
  43. package/src/screens/SubUnit/AddSubUnit.js +2 -6
  44. package/src/screens/SubUnit/EditSubUnitStyles.js +2 -1
  45. package/src/screens/Unit/AddMenu.js +1 -1
  46. package/src/screens/Unit/ManageUnitStyles.js +1 -1
  47. package/src/utils/I18n/translations/en.js +2 -0
  48. package/src/utils/I18n/translations/vi.js +2 -0
  49. package/src/utils/Route/index.js +2 -1
  50. package/src/commons/ActionGroup/OnOffTemplate/styles.js +0 -7
  51. package/src/screens/Sharing/Components/DeviceItem.js +0 -146
  52. package/src/screens/Sharing/Components/__test__/DeviceItem.test.js +0 -48
  53. package/src/screens/Sharing/SharingSelectPermission.js +0 -409
  54. package/src/screens/Sharing/__test__/SharingSelectPermission.test.js +0 -292
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@eohjsc/react-native-smart-city",
3
3
  "title": "React Native Smart Home",
4
- "version": "0.5.00",
4
+ "version": "0.5.02",
5
5
  "description": "TODO",
6
6
  "main": "index.js",
7
7
  "files": [
@@ -198,7 +198,7 @@
198
198
  "react-native-toast-message": "^2.1.1",
199
199
  "react-native-udp": "4.1.3",
200
200
  "react-native-version-check": "^3.4.2",
201
- "react-native-vlc-media-player": "^1.0.41",
201
+ "react-native-vlc-media-player": "^1.0.67",
202
202
  "react-native-webview": "11.22.7",
203
203
  "react-native-wheel-color-picker": "^1.2.0",
204
204
  "react-native-wheel-scrollview-picker": "^1.2.2",
@@ -7,7 +7,6 @@ export default StyleSheet.create({
7
7
  justifyContent: 'center',
8
8
  alignItems: 'center',
9
9
  padding: 20,
10
- paddingVertical: 50,
11
10
  },
12
11
  bigCircle: {
13
12
  backgroundColor: Colors.Gray2,
@@ -6,6 +6,7 @@ export default StyleSheet.create({
6
6
  paddingVertical: 16,
7
7
  paddingHorizontal: 16,
8
8
  marginHorizontal: 16,
9
+ marginBottom: 16,
9
10
  borderWidth: 1,
10
11
  borderColor: Colors.Gray4,
11
12
  borderRadius: 10,
@@ -1,4 +1,4 @@
1
- import React, { memo, useCallback, useEffect, useState } from 'react';
1
+ import React, { memo, useCallback, useEffect, useMemo, useState } from 'react';
2
2
  import { Switch, View } from 'react-native';
3
3
 
4
4
  import Text from '../../Text';
@@ -7,10 +7,9 @@ import styles from './OnOffButtonTemplateStyle';
7
7
  import AccessibilityLabel from '../../../configs/AccessibilityLabel';
8
8
  import { useConfigGlobalState } from '../../../iot/states';
9
9
 
10
- const SwitchButtonTemplate = memo(
11
- ({ item = {}, isLight = false, doAction }) => {
12
- const { configuration = {}, id } = item;
13
- const {
10
+ const SwitchButtonTemplate = memo(({ item, doAction }) => {
11
+ const {
12
+ configuration: {
14
13
  action_off_data,
15
14
  action_on_data,
16
15
  text_on,
@@ -18,54 +17,67 @@ const SwitchButtonTemplate = memo(
18
17
  color_on,
19
18
  color_off,
20
19
  config,
21
- } = configuration;
20
+ is_on_value,
21
+ } = {},
22
+ id,
23
+ } = item;
22
24
 
23
- const [configValues] = useConfigGlobalState('configValues');
24
- const configValue = configValues[config];
25
- const [_isOn, setIsOn] = useState(configValue?.value);
25
+ const [configValues] = useConfigGlobalState('configValues');
26
+ const configValue = configValues[config]?.value;
27
+ const [isOn, setIsOn] = useState();
28
+ const getIsOnValue = useCallback(() => {
29
+ if (is_on_value && is_on_value.length > 0) {
30
+ return is_on_value.includes(configValue);
31
+ }
32
+ return !!configValue;
33
+ }, [configValue, is_on_value]);
26
34
 
27
- const onChangeSwitch = useCallback(() => {
28
- if (_isOn) {
29
- setIsOn(false);
35
+ useEffect(() => {
36
+ setIsOn(getIsOnValue());
37
+ }, [getIsOnValue]);
38
+
39
+ const onValueChange = useCallback(() => {
40
+ setIsOn((prevIsOn) => {
41
+ const newState = !prevIsOn;
42
+ if (newState) {
43
+ doAction(action_on_data, null);
44
+ } else {
30
45
  doAction(action_off_data, null);
31
- return;
32
46
  }
33
- doAction(action_on_data, null);
34
- setIsOn(true);
35
- }, [action_off_data, action_on_data, doAction, _isOn]);
36
-
37
- useEffect(() => {
38
- configValue && setIsOn(configValue?.value);
39
- }, [configValue]);
47
+ return newState;
48
+ });
49
+ }, [action_off_data, action_on_data, doAction]);
40
50
 
41
- return (
42
- <>
43
- <View style={styles.barrierControlContainer}>
44
- <Switch
45
- trackColor={{ false: color_off, true: color_on }}
46
- ios_backgroundColor={_isOn ? color_on : color_off}
47
- onValueChange={onChangeSwitch}
48
- value={!!_isOn}
49
- />
50
- <Text
51
- style={[
52
- styles.textBig,
53
- { color: _isOn ? Colors.Gray8 : Colors.Gray6 },
54
- ]}
55
- accessibilityLabel={`${AccessibilityLabel.SENSOR_STATUS}-${id}`}
56
- >
57
- {_isOn ? text_on : text_off}
58
- </Text>
59
- </View>
51
+ const trackColor = useMemo(
52
+ () => ({ false: color_off, true: color_on }),
53
+ [color_off, color_on]
54
+ );
55
+ const backgroundColor = useMemo(
56
+ () => (isOn ? color_on : color_off),
57
+ [color_off, color_on, isOn]
58
+ );
60
59
 
61
- {!!item.title && !isLight && (
62
- <Text type="H3" semibold center>
63
- {item.title}
64
- </Text>
65
- )}
66
- </>
67
- );
68
- }
69
- );
60
+ return (
61
+ <>
62
+ <View style={styles.barrierControlContainer}>
63
+ <Switch
64
+ trackColor={trackColor}
65
+ ios_backgroundColor={backgroundColor}
66
+ onValueChange={onValueChange}
67
+ value={isOn}
68
+ />
69
+ <Text
70
+ style={[
71
+ styles.textBig,
72
+ { color: isOn ? Colors.Gray8 : Colors.Gray6 },
73
+ ]}
74
+ accessibilityLabel={`${AccessibilityLabel.SENSOR_STATUS}-${id}`}
75
+ >
76
+ {isOn ? text_on : text_off}
77
+ </Text>
78
+ </View>
79
+ </>
80
+ );
81
+ });
70
82
 
71
83
  export default SwitchButtonTemplate;
@@ -7,7 +7,6 @@ import { useConfigGlobalState } from '../../../iot/states';
7
7
  import { useUnwatchLGDeviceConfigControl } from '../../../hooks/IoT';
8
8
  import OnOffButtonTemplate from './OnOffButtonTemplate';
9
9
  import OnOffSimpleTemplate from './OnOffSimpleTemplate';
10
- import styles from './styles';
11
10
 
12
11
  const getComponent = (template) => {
13
12
  switch (template) {
@@ -97,7 +96,7 @@ const OnOffTemplate = memo(({ item = {}, doAction, sensor = {} }) => {
97
96
  }, [item.template]);
98
97
 
99
98
  return (
100
- <View style={styles.wrap}>
99
+ <View>
101
100
  <Component
102
101
  isOn={isOn}
103
102
  triggerAction={triggerAction}
@@ -1,15 +1,7 @@
1
- import React, {
2
- memo,
3
- useCallback,
4
- useState,
5
- useEffect,
6
- useMemo,
7
- useRef,
8
- } from 'react';
1
+ import React, { memo, useCallback, useState, useEffect, useRef } from 'react';
9
2
  import { Slider } from '@miblanchard/react-native-slider';
10
3
 
11
4
  import { View } from 'react-native';
12
- import { useTranslations } from '../../hooks/Common/useTranslations';
13
5
  import styles from './SliderRangeTemplateStyles';
14
6
  import Text from '../Text';
15
7
  import { Colors } from '../../configs';
@@ -18,101 +10,105 @@ import { DEVICE_TYPE } from '../../configs/Constants';
18
10
  import _TextInput from '../Form/TextInput';
19
11
 
20
12
  const SliderRangeTemplate = memo(
21
- ({ item = {}, doAction, sensor, isWidgetOrder }) => {
22
- const t = useTranslations();
23
- const { configuration = {}, title, label } = item;
13
+ ({ item, doAction, sensor, isWidgetOrder }) => {
14
+ const { configuration, label = 'Slider range' } = item;
24
15
  const [configValues] = useConfigGlobalState('configValues');
25
- const {
26
- config = undefined,
27
- min_value = 0,
28
- max_value = 100,
29
- action_data,
30
- } = configuration;
31
- const timeout = useRef(null);
16
+ const { config, min_value, max_value, action_data } = configuration;
17
+ const [value, setValue] = useState();
18
+ const [processing, setProcessing] = useState(false);
19
+ const timeout = useRef();
32
20
 
33
- const getPercent = useCallback(() => {
34
- return configValues[config]?.value || 0;
35
- }, [config, configValues]);
21
+ const onSlidingStart = useCallback(() => {
22
+ setProcessing(true);
23
+ }, []);
36
24
 
37
- const [valueBrightness, setValueBrightness] = useState(getPercent());
25
+ const onSlidingChange = useCallback(async (number) => {
26
+ setValue(number[0]);
27
+ }, []);
38
28
 
39
- const onChangeBrightness = useCallback(
40
- async (value) => {
41
- const value_brness = value[0];
29
+ const onSlidingComplete = useCallback(
30
+ async (number) => {
31
+ clearTimeout(timeout.current);
42
32
  await doAction(
43
33
  action_data,
44
- JSON.stringify({ value_brness: value_brness, value: value_brness })
34
+ JSON.stringify({ value_brness: number[0], value: number[0] })
45
35
  );
36
+ timeout.current = setTimeout(() => {
37
+ setProcessing(false);
38
+ }, 3000);
46
39
  },
47
40
  [action_data, doAction]
48
41
  );
49
42
 
50
- useEffect(() => {
51
- const value = configValues[config]?.value || 0;
52
- if (sensor?.device_type !== DEVICE_TYPE.LG_THINQ) {
53
- setValueBrightness(value);
54
- }
55
- }, [config, configValues, sensor?.device_type]);
43
+ const onFocus = useCallback(() => {
44
+ setProcessing(true);
45
+ }, []);
56
46
 
57
- const getTextInputValue = useMemo(() => {
58
- if ([null, undefined, NaN].includes(valueBrightness)) {
59
- /* istanbul ignore next */
60
- return 0;
47
+ const onEndEditing = useCallback(async () => {
48
+ clearTimeout(timeout.current);
49
+ if (value) {
50
+ const data = parseInt(value, 10);
51
+ await doAction(
52
+ action_data,
53
+ JSON.stringify({
54
+ value_brness: data,
55
+ value: data,
56
+ })
57
+ );
61
58
  }
59
+ timeout.current = setTimeout(() => {
60
+ setProcessing(false);
61
+ }, 3000);
62
+ }, [action_data, doAction, value]);
62
63
 
63
- return valueBrightness;
64
- }, [valueBrightness]);
65
-
66
- const onValueChange = (value) => setValueBrightness(value[0]);
64
+ useEffect(() => {
65
+ if (!processing) {
66
+ if (sensor?.device_type !== DEVICE_TYPE.LG_THINQ) {
67
+ const configValue = configValues[config]?.value || 0;
68
+ setValue(configValue);
69
+ }
70
+ }
71
+ }, [config, configValues, processing, sensor?.device_type]);
67
72
 
68
- const onInputChange = (value) => {
69
- if (isNaN(value)) {
73
+ const onInputChange = (text) => {
74
+ if (text === '' || isNaN(text)) {
75
+ setValue(min_value);
70
76
  return;
71
77
  }
72
- setValueBrightness(value);
73
- if (timeout.current) {
74
- /* istanbul ignore next */
75
- clearTimeout(timeout.current);
76
- }
77
- if (value !== '') {
78
- timeout.current = setTimeout(() => {
79
- doAction(
80
- action_data,
81
- JSON.stringify({
82
- value_brness: parseInt(value, 10),
83
- value: parseInt(value, 10),
84
- })
85
- );
86
- }, 300);
87
- }
78
+
79
+ const numericValue = Number(text);
80
+ setValue(Math.min(max_value, Math.max(min_value, numericValue)));
88
81
  };
89
82
 
90
83
  return (
91
84
  <View
92
85
  style={(isWidgetOrder && styles.wrapOrderItem) || styles.viewBrightness}
93
86
  >
94
- <Text type="H4">{title || label || t('brightness')}</Text>
87
+ <Text type="H4">{label}</Text>
95
88
  <View style={styles.wrap}>
96
89
  <Slider
97
90
  step={1}
98
91
  minimumValue={min_value}
99
92
  maximumValue={max_value}
100
- value={valueBrightness < min_value ? min_value : valueBrightness}
101
- onValueChange={onValueChange}
102
- onSlidingComplete={onChangeBrightness}
93
+ value={value}
103
94
  minimumTrackTintColor={Colors.Primary}
104
95
  maximumTrackTintColor={Colors.Gray3}
105
96
  trackStyle={styles.trackSlider}
106
97
  thumbStyle={styles.thumbSlider}
107
98
  containerStyle={styles.slider}
99
+ onSlidingStart={onSlidingStart}
100
+ onValueChange={onSlidingChange}
101
+ onSlidingComplete={onSlidingComplete}
108
102
  />
109
103
  <_TextInput
110
104
  keyboardType="numeric"
111
105
  style={styles.text}
112
106
  wrapStyle={styles.wrapInputStyle}
113
107
  textInputStyle={styles.textInputStyle}
114
- value={getTextInputValue.toString()}
108
+ value={String(value)}
109
+ onFocus={onFocus}
115
110
  onChange={onInputChange}
111
+ onEndEditing={onEndEditing}
116
112
  />
117
113
  </View>
118
114
  </View>
@@ -29,11 +29,11 @@ export default StyleSheet.create({
29
29
  marginTop: 8,
30
30
  },
31
31
  slider: {
32
- width: '77%',
32
+ width: '75%',
33
33
  },
34
34
  wrapInputStyle: {
35
35
  marginTop: 0,
36
- width: '23%',
36
+ width: '25%',
37
37
  },
38
38
  textInputStyle: {
39
39
  marginTop: 0,
@@ -41,8 +41,6 @@ export default StyleSheet.create({
41
41
  borderRadius: 4,
42
42
  paddingTop: 5,
43
43
  paddingBottom: 5,
44
- paddingHorizontal: 20,
45
-
46
44
  shadowColor: Colors.Gray13,
47
45
  borderColor: Colors.Gray5,
48
46
  borderWidth: 1,
@@ -96,8 +96,8 @@ const TerminalBoxTemplate = ({ item, doAction, isWidgetOrder }) => {
96
96
  const type = configMessage.id === from_config.id ? 'from' : 'to';
97
97
  messages = [
98
98
  ...messages,
99
- ...configMessage.data.map((item) => {
100
- return { x: item.x, y: item.y, type };
99
+ ...configMessage.data.map((object) => {
100
+ return { x: object.x, y: object.y, type };
101
101
  }),
102
102
  ];
103
103
  });
@@ -147,14 +147,14 @@ const TerminalBoxTemplate = ({ item, doAction, isWidgetOrder }) => {
147
147
  }
148
148
  style={styles.scrollView}
149
149
  >
150
- {allMessages.map((item, index) => {
150
+ {allMessages.map((object, index) => {
151
151
  return (
152
152
  <View
153
153
  key={index}
154
- style={item.type === 'to' ? styles.to : styles.from}
154
+ style={object.type === 'to' ? styles.to : styles.from}
155
155
  >
156
- <Text>{item.y}</Text>
157
- <Text>{moment(item.x).format('DD/MM/YYYY HH:mm:ss')}</Text>
156
+ <Text>{object.y}</Text>
157
+ <Text>{moment(object.x).format('DD/MM/YYYY HH:mm:ss')}</Text>
158
158
  </View>
159
159
  );
160
160
  })}
@@ -30,8 +30,8 @@ const TextBoxTemplate = ({ item, doAction, isWidgetOrder }) => {
30
30
  setValue(e);
31
31
  };
32
32
  const valueText = useMemo(() => {
33
- return configValues[config.id]?.value || '';
34
- }, [config.id, configValues]);
33
+ return configValues[config?.id]?.value || ''; // config undefined when is_configuration_ready = False
34
+ }, [config?.id, configValues]);
35
35
 
36
36
  return (
37
37
  <View style={(isWidgetOrder && styles.wrapOrderItem) || styles.wrap}>
@@ -7,6 +7,7 @@ import { mockSCStore } from '../../../context/mockStore';
7
7
  import { useConfigGlobalState } from '../../../iot/states';
8
8
  import { Slider } from '@miblanchard/react-native-slider';
9
9
  import _TextInput from '../../Form/TextInput';
10
+ import { DEVICE_TYPE } from '../../../configs/Constants';
10
11
 
11
12
  jest.mock('../../../iot/Monitor');
12
13
  const mockDoAction = jest.fn();
@@ -14,9 +15,14 @@ jest.mock('../../../iot/states', () => ({
14
15
  useConfigGlobalState: jest.fn(),
15
16
  }));
16
17
 
17
- const wrapComponent = (item, doAction, sensor) => (
18
+ const wrapComponent = (item, doAction, sensor, isWidgetOrder = false) => (
18
19
  <SCProvider initState={mockSCStore({})}>
19
- <SliderRangeTemplate item={item} doAction={doAction} sensor={sensor} />
20
+ <SliderRangeTemplate
21
+ item={item}
22
+ doAction={doAction}
23
+ sensor={sensor}
24
+ isWidgetOrder={isWidgetOrder}
25
+ />
20
26
  </SCProvider>
21
27
  );
22
28
 
@@ -37,26 +43,37 @@ describe('Test SliderRangeTemplate', () => {
37
43
  watchMultiConfigs.mockClear();
38
44
  mockDoAction.mockClear();
39
45
  displayItem = {
40
- template: 'ColorPickerTemplate',
46
+ template: 'slider_range_template',
47
+ is_configuration_ready: true,
41
48
  configuration: {
42
49
  config: 5,
43
50
  action_data: actionData,
51
+ min_value: 0,
52
+ max_value: 100,
44
53
  },
45
- title: '',
54
+ label: '',
46
55
  };
47
56
  });
48
57
 
49
58
  it('render template SliderRangeTemplate', async () => {
59
+ jest.useFakeTimers();
50
60
  useConfigGlobalState.mockImplementation(() => [{}, jest.fn()]);
51
61
  const sensor = { is_managed_by_backend: true, name: 'Sensor' };
52
62
  await act(async () => {
53
63
  wrapper = await create(wrapComponent(displayItem, mockDoAction, sensor));
54
64
  });
55
65
  const instance = wrapper.root;
56
- const silderRange = instance.findAllByType(Slider);
57
- expect(silderRange).toHaveLength(1);
66
+ const sliderRange = instance.findByType(Slider);
67
+ expect(sliderRange.props.value).toBe(0);
68
+ await act(async () => {
69
+ await sliderRange.props.onSlidingStart();
70
+ });
71
+ await act(async () => {
72
+ await sliderRange.props.onValueChange([50]);
73
+ });
58
74
  await act(async () => {
59
- await silderRange[0].props.onSlidingComplete([50]);
75
+ await sliderRange.props.onSlidingComplete([50]);
76
+ jest.runAllTimers();
60
77
  });
61
78
  expect(mockDoAction).toHaveBeenCalledWith(
62
79
  actionData,
@@ -78,8 +95,8 @@ describe('Test SliderRangeTemplate', () => {
78
95
  wrapper = await create(wrapComponent(displayItem, mockDoAction, sensor));
79
96
  });
80
97
  const instance = wrapper.root;
81
- const silderRange = instance.findByType(Slider);
82
- expect(silderRange.props.value).toBe(50);
98
+ const sliderRange = instance.findByType(Slider);
99
+ expect(sliderRange.props.value).toBe(50);
83
100
  });
84
101
 
85
102
  it('test change input invalid number', async () => {
@@ -91,22 +108,25 @@ describe('Test SliderRangeTemplate', () => {
91
108
  },
92
109
  jest.fn(),
93
110
  ]);
94
- const sensor = { is_managed_by_backend: true, name: 'Sensor' };
95
111
 
96
112
  await act(async () => {
97
- wrapper = await create(wrapComponent(displayItem, mockDoAction, sensor));
113
+ wrapper = await create(wrapComponent(displayItem, mockDoAction));
98
114
  });
99
115
  const instance = wrapper.root;
100
116
  const textInput = instance.findByType(_TextInput);
101
117
  expect(textInput.props.value).toEqual('50');
102
118
 
103
119
  await act(async () => {
104
- await textInput.props.onChange('aaaa');
120
+ await textInput.props.onChange('');
121
+ });
122
+ await act(async () => {
123
+ await textInput.props.onEndEditing('');
105
124
  });
106
125
  expect(textInput.props.value).toEqual('50'); // not change value
107
126
  });
108
127
 
109
- it('test change input called doAction', async () => {
128
+ it('test change input text called doAction', async () => {
129
+ jest.useFakeTimers();
110
130
  useConfigGlobalState.mockImplementation(() => [
111
131
  {
112
132
  5: {
@@ -115,19 +135,21 @@ describe('Test SliderRangeTemplate', () => {
115
135
  },
116
136
  jest.fn(),
117
137
  ]);
118
- const sensor = { is_managed_by_backend: true, name: 'Sensor' };
119
138
 
120
139
  await act(async () => {
121
- wrapper = await create(wrapComponent(displayItem, mockDoAction, sensor));
140
+ wrapper = await create(wrapComponent(displayItem, mockDoAction));
122
141
  });
123
142
 
124
143
  const instance = wrapper.root;
125
144
  let textInput = instance.findByType(_TextInput);
126
-
145
+ await act(async () => {
146
+ await textInput.props.onFocus();
147
+ });
127
148
  await act(async () => {
128
149
  await textInput.props.onChange('60');
129
150
  });
130
151
  await act(async () => {
152
+ await textInput.props.onEndEditing('60');
131
153
  jest.runAllTimers();
132
154
  });
133
155
  expect(mockDoAction).toHaveBeenCalledWith(
@@ -135,4 +157,38 @@ describe('Test SliderRangeTemplate', () => {
135
157
  JSON.stringify({ value_brness: 60, value: 60 })
136
158
  );
137
159
  });
160
+
161
+ it('render template SliderRangeTemplate not ready', async () => {
162
+ useConfigGlobalState.mockImplementation(() => [
163
+ {
164
+ 5: {
165
+ value: 50,
166
+ },
167
+ },
168
+ jest.fn(),
169
+ ]);
170
+ const sensor = { is_managed_by_backend: true, name: 'Sensor' };
171
+ displayItem.is_configuration_ready = false;
172
+ displayItem.configuration = {};
173
+ displayItem.label = undefined;
174
+ await act(async () => {
175
+ wrapper = await create(wrapComponent(displayItem, mockDoAction, sensor));
176
+ });
177
+ const instance = wrapper.root;
178
+ const sliderRange = instance.findByType(Slider);
179
+ expect(sliderRange.props.value).toBe(0);
180
+ });
181
+
182
+ it('render template SliderRangeTemplate sensor device_type LG_THINQ and isWidgetOrder change position', async () => {
183
+ useConfigGlobalState.mockImplementation(() => [{}, jest.fn()]);
184
+ const sensor = { device_type: DEVICE_TYPE.LG_THINQ };
185
+ await act(async () => {
186
+ wrapper = await create(
187
+ wrapComponent(displayItem, mockDoAction, sensor, true)
188
+ );
189
+ });
190
+ const instance = wrapper.root;
191
+ const sliderRange = instance.findByType(Slider);
192
+ expect(sliderRange.props.value).toBe(0);
193
+ });
138
194
  });