@eohjsc/react-native-smart-city 0.3.4 → 0.3.5

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 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.3.04",
4
+ "version": "0.3.05",
5
5
  "description": "TODO",
6
6
  "main": "index.js",
7
7
  "files": [
@@ -1,5 +1,5 @@
1
1
  import React, { useCallback, useEffect, useState } from 'react';
2
- import { View, TouchableOpacity } from 'react-native';
2
+ import { View, TouchableOpacity, ActivityIndicator } from 'react-native';
3
3
  import { IconOutline } from '@ant-design/icons-react-native';
4
4
  import { Colors } from '../../configs';
5
5
 
@@ -7,7 +7,7 @@ import Text from '../Text';
7
7
  import { useConfigGlobalState } from '../../iot/states';
8
8
  import styles from './NumberUpDownActionTemplateStyle';
9
9
  import { watchMultiConfigs } from '../../iot/Monitor';
10
- import { TESTID } from '../../configs/Constants';
10
+ import { DEVICE_TYPE, TESTID } from '../../configs/Constants';
11
11
 
12
12
  const NumberUpDownActionTemplate = ({ actionGroup, doAction, sensor }) => {
13
13
  const { configuration, title } = actionGroup;
@@ -25,6 +25,19 @@ const NumberUpDownActionTemplate = ({ actionGroup, doAction, sensor }) => {
25
25
  const [value, setValue] = useState();
26
26
  const valueDefault = 28;
27
27
 
28
+ useEffect(() => {
29
+ if (sensor?.device_type === DEVICE_TYPE.LG_THINQ) {
30
+ return;
31
+ }
32
+ if (
33
+ !!config &&
34
+ sensor?.is_managed_by_backend &&
35
+ sensor.device_type !== 'GOOGLE_HOME'
36
+ ) {
37
+ watchMultiConfigs([config]);
38
+ }
39
+ }, [sensor, config]);
40
+
28
41
  useEffect(() => {
29
42
  if (!config) {
30
43
  setValue(valueDefault);
@@ -34,11 +47,9 @@ const NumberUpDownActionTemplate = ({ actionGroup, doAction, sensor }) => {
34
47
  const configValue = configValues[config];
35
48
  if (configValue !== null && configValue !== undefined) {
36
49
  setValue(configValue);
37
- } else {
38
- setValue(valueDefault);
39
50
  }
40
51
  // eslint-disable-next-line react-hooks/exhaustive-deps
41
- }, []);
52
+ }, [JSON.stringify(configValues)]);
42
53
 
43
54
  const doActionAndWatchConfig = useCallback(
44
55
  async (actionData, actionValue, actionName) => {
@@ -113,7 +124,11 @@ const NumberUpDownActionTemplate = ({ actionGroup, doAction, sensor }) => {
113
124
  </TouchableOpacity>
114
125
 
115
126
  <Text testID={'abcd'} type="H2">
116
- {text_format.replace('{number}', value)}
127
+ {value !== undefined ? (
128
+ text_format.replace('{number}', value)
129
+ ) : (
130
+ <ActivityIndicator />
131
+ )}
117
132
  </Text>
118
133
 
119
134
  <TouchableOpacity
@@ -1,8 +1,8 @@
1
1
  import React from 'react';
2
- import { TouchableOpacity } from 'react-native';
2
+ import { ActivityIndicator, TouchableOpacity } from 'react-native';
3
3
  import { act, create } from 'react-test-renderer';
4
4
  import Text from '../../../commons/Text';
5
- import { TESTID } from '../../../configs/Constants';
5
+ import { DEVICE_TYPE, TESTID } from '../../../configs/Constants';
6
6
  import { watchMultiConfigs } from '../../../iot/Monitor';
7
7
  import NumberUpDownActionTemplate from '../NumberUpDownActionTemplate';
8
8
 
@@ -48,7 +48,10 @@ describe('Test NumberUpDownActionTemplate', () => {
48
48
  <NumberUpDownActionTemplate
49
49
  actionGroup={actionGroup}
50
50
  doAction={mockDoAction}
51
- sensor={{ is_managed_by_backend: true }}
51
+ sensor={{
52
+ is_managed_by_backend: true,
53
+ device_type: DEVICE_TYPE.LG_THINQ,
54
+ }}
52
55
  />
53
56
  );
54
57
  });
@@ -288,4 +291,41 @@ describe('Test NumberUpDownActionTemplate', () => {
288
291
  const text = instance.findByType(Text);
289
292
  expect(text.props.children).toEqual('25 *C');
290
293
  });
294
+ test('render template have title', async () => {
295
+ const mockDoAction = jest.fn();
296
+ actionGroup.title = 'title';
297
+ await act(async () => {
298
+ wrapper = await create(
299
+ <NumberUpDownActionTemplate
300
+ actionGroup={actionGroup}
301
+ doAction={mockDoAction}
302
+ sensor={{
303
+ is_managed_by_backend: true,
304
+ device_type: DEVICE_TYPE.LG_THINQ,
305
+ }}
306
+ />
307
+ );
308
+ });
309
+ const instance = wrapper.root;
310
+ const text = instance.findAllByType(Text);
311
+ expect(text).toHaveLength(2);
312
+ });
313
+ test('render template watch config not exits', async () => {
314
+ const mockDoAction = jest.fn();
315
+ actionGroup.configuration.config = 100;
316
+ await act(async () => {
317
+ wrapper = await create(
318
+ <NumberUpDownActionTemplate
319
+ actionGroup={actionGroup}
320
+ doAction={mockDoAction}
321
+ sensor={{
322
+ is_managed_by_backend: true,
323
+ }}
324
+ />
325
+ );
326
+ });
327
+ const instance = wrapper.root;
328
+ const text = instance.findAllByType(ActivityIndicator);
329
+ expect(text).toHaveLength(1);
330
+ });
291
331
  });
@@ -1,5 +1,5 @@
1
1
  import React from 'react';
2
- import { TouchableOpacity, Switch } from 'react-native';
2
+ import { TouchableOpacity, Switch, ActivityIndicator } from 'react-native';
3
3
  import renderer, { act } from 'react-test-renderer';
4
4
  import DateTimePickerModal from 'react-native-modal-datetime-picker';
5
5
  import moment from 'moment';
@@ -344,7 +344,7 @@ describe('Test ActionGroup', () => {
344
344
  expect(mockDoAction).toHaveBeenCalledTimes(1);
345
345
  });
346
346
 
347
- test('render ActionGroup NumberUpDownActionTemplate', async () => {
347
+ test('render ActionGroup NumberUpDownActionTemplate watch config value null', async () => {
348
348
  const mockDoAction = jest.fn();
349
349
  const actionGroup = {
350
350
  template: 'NumberUpDownActionTemplate',
@@ -362,11 +362,8 @@ describe('Test ActionGroup', () => {
362
362
  );
363
363
  });
364
364
  const instance = wrapper.root;
365
- const text = instance.findAllByType(Text);
366
- expect(text[0].props.children).toEqual('28 *C');
367
-
368
- const touchs = instance.findAllByType(TouchableOpacity);
369
- expect(touchs).toHaveLength(2);
365
+ const activity = instance.findAllByType(ActivityIndicator);
366
+ expect(activity.length).toEqual(1);
370
367
  });
371
368
 
372
369
  test('render ActionGroup StatesGridActionTemplate', async () => {
@@ -1,60 +0,0 @@
1
- import React from 'react';
2
- import { TouchableOpacity } from 'react-native';
3
- import { act, create } from 'react-test-renderer';
4
- import Text from '../../../commons/Text';
5
- import { watchMultiConfigs } from '../../../iot/Monitor';
6
- import NumberUpDownActionTemplate from '../NumberUpDownActionTemplate';
7
-
8
- jest.mock('../../../iot/Monitor');
9
-
10
- jest.mock('../../../iot/states', () => ({
11
- useConfigGlobalState: () => [{ 5: null }, null],
12
- }));
13
-
14
- describe('Test NumberUpDownActionTemplate', () => {
15
- const action_data = {
16
- color: '#00979D',
17
- command_prefer_over_bluetooth: true,
18
- command_prefer_over_googlehome: false,
19
- command_prefer_over_internet: false,
20
- googlehome_actions: [],
21
- icon: 'caret-up',
22
- id: 20,
23
- key: '5ed1d4dc-a905-47cd-b0c9-f979644bd21a',
24
- };
25
-
26
- let actionGroup;
27
- let wrapper;
28
-
29
- beforeEach(() => {
30
- watchMultiConfigs.mockClear();
31
- actionGroup = {
32
- configuration: {
33
- config: 5,
34
- action_data,
35
- min_value: 16,
36
- max_value: 30,
37
- text_format: '{number} *C',
38
- },
39
- };
40
- });
41
-
42
- test('render template', async () => {
43
- const mockDoAction = jest.fn();
44
- await act(async () => {
45
- wrapper = await create(
46
- <NumberUpDownActionTemplate
47
- actionGroup={actionGroup}
48
- doAction={mockDoAction}
49
- sensor={{ is_managed_by_backend: true }}
50
- />
51
- );
52
- });
53
- const instance = wrapper.root;
54
- const text = instance.findByType(Text);
55
- expect(text.props.children).toEqual('28 *C');
56
-
57
- const touchs = instance.findAllByType(TouchableOpacity);
58
- expect(touchs).toHaveLength(2);
59
- });
60
- });