@eohjsc/react-native-smart-city 0.2.97 → 0.2.98

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 (68) hide show
  1. package/package.json +2 -2
  2. package/src/commons/Action/ItemQuickAction.js +5 -2
  3. package/src/commons/ActionGroup/ColorPickerTemplate.js +1 -1
  4. package/src/commons/ActionGroup/NumberUpDownActionTemplate.js +10 -2
  5. package/src/commons/ActionGroup/OnOffSmartLock/OnOffSmartLock.js +4 -1
  6. package/src/commons/ActionGroup/OnOffSmartLock/SetupGeneratePasscode/index.js +1 -0
  7. package/src/commons/ActionGroup/OnOffTemplate/OnOffSimpleTemplate.js +12 -10
  8. package/src/commons/ActionGroup/OnOffTemplate/index.js +38 -5
  9. package/src/commons/ActionGroup/OptionsDropdownActionTemplate.js +8 -2
  10. package/src/commons/ActionGroup/SliderRangeTemplate.js +1 -1
  11. package/src/commons/ActionGroup/SmartTiviActionTemplate/SmartTiviActionTemplate.js +4 -1
  12. package/src/commons/ActionGroup/StatesGridActionTemplate.js +14 -4
  13. package/src/commons/ActionGroup/TimerActionTemplate.js +9 -1
  14. package/src/commons/ActionGroup/TwoButtonTemplate/index.js +7 -3
  15. package/src/commons/ActionGroup/__test__/OnOffButtonTemplate.test.js +14 -14
  16. package/src/commons/ActionGroup/__test__/OnOffTemplate.test.js +53 -78
  17. package/src/commons/ActionGroup/__test__/OneBigButtonTemplate.test.js +36 -20
  18. package/src/commons/Auth/AccountList.js +1 -1
  19. package/src/commons/Device/HistoryChart.js +4 -0
  20. package/src/commons/Device/PMSensor/PMSensorIndicatior.js +16 -12
  21. package/src/commons/Device/PMSensor/PMSensorIndicatorStyles.js +3 -0
  22. package/src/commons/Device/WaterQualitySensor/ListQualityIndicator.js +1 -0
  23. package/src/commons/FullLoading/index.js +2 -1
  24. package/src/commons/MenuActionAddnew/index.js +1 -0
  25. package/src/commons/MenuActionList/index.js +1 -0
  26. package/src/commons/MenuActionMore/index.js +1 -1
  27. package/src/commons/PreventAccess/__test__/PreventAccess.test.js +62 -0
  28. package/src/commons/PreventAccess/index.js +9 -1
  29. package/src/configs/Constants.js +4 -0
  30. package/src/context/actionType.ts +1 -0
  31. package/src/context/reducer.ts +3 -0
  32. package/src/screens/AQIGuide/index.js +1 -1
  33. package/src/screens/ActivityLog/FilterPopup.js +2 -0
  34. package/src/screens/AddCommon/SelectSubUnit.js +1 -0
  35. package/src/screens/AddCommon/SelectUnit.js +1 -0
  36. package/src/screens/AddLocationMaps/index.js +4 -1
  37. package/src/screens/AddNewAction/SelectSensorDevices.js +6 -1
  38. package/src/screens/AddNewDevice/index.js +1 -0
  39. package/src/screens/AddNewGateway/PlugAndPlay/GatewayWifiList.js +4 -1
  40. package/src/screens/AddNewGateway/SelectGateway.js +1 -0
  41. package/src/screens/AddNewGateway/SetupGatewayWifi.js +1 -0
  42. package/src/screens/AddNewGateway/index.js +1 -0
  43. package/src/screens/AddNewOneTap/index.js +1 -1
  44. package/src/screens/Automate/index.js +2 -0
  45. package/src/screens/Device/detail.js +9 -1
  46. package/src/screens/EmergencyContacts/__test__/EmergencyContactList.test.js +14 -0
  47. package/src/screens/EmergencyContacts/__test__/EmergencyContactsSelectContacts.test.js +19 -1
  48. package/src/screens/EmergencySetting/index.js +4 -1
  49. package/src/screens/Explore/index.js +2 -0
  50. package/src/screens/ManageAccess/index.js +1 -0
  51. package/src/screens/MoveToAnotherSubUnit/index.js +1 -1
  52. package/src/screens/ScriptDetail/index.js +2 -2
  53. package/src/screens/SelectUnit/index.js +1 -0
  54. package/src/screens/SetSchedule/index.js +4 -1
  55. package/src/screens/SharedUnit/index.js +2 -0
  56. package/src/screens/Sharing/MemberList.js +12 -11
  57. package/src/screens/Sharing/SelectPermission.js +1 -0
  58. package/src/screens/Sharing/hooks/index.js +3 -0
  59. package/src/screens/SmartIr/components/SelectBrand.js +1 -1
  60. package/src/screens/SubUnit/ManageSubUnit.js +1 -0
  61. package/src/screens/SyncLGDevice/AddLGDevice.js +1 -0
  62. package/src/screens/TDSGuide/index.js +4 -1
  63. package/src/screens/UVIndexGuide/index.js +1 -1
  64. package/src/screens/Unit/SelectAddress.js +4 -1
  65. package/src/screens/Unit/Station/index.js +1 -0
  66. package/src/screens/Unit/Summaries.js +1 -1
  67. package/src/screens/UnitSummary/__test__/index.test.js +32 -0
  68. package/src/screens/WaterQualityGuide/index.js +1 -1
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.2.97",
4
+ "version": "0.2.98",
5
5
  "description": "TODO",
6
6
  "main": "index.js",
7
7
  "files": [
@@ -190,7 +190,7 @@
190
190
  "react-native-unimodules": "^0.11.0",
191
191
  "react-native-version-check": "^3.4.2",
192
192
  "react-native-vlc-media-player": "^1.0.39",
193
- "react-native-webview": "^10.9.3",
193
+ "react-native-webview": "11.17.2",
194
194
  "react-native-wheel-color-picker": "^1.2.0",
195
195
  "react-native-wheel-scrollview-picker": "^1.2.2",
196
196
  "react-native-wifi-reborn": "^4.5.0",
@@ -43,8 +43,9 @@ const ItemQuickAction = memo(({ sensor, wrapperStyle, setStatus, unit }) => {
43
43
  useEffect(() => {
44
44
  sensor.quick_action &&
45
45
  sensor.quick_action.config_id &&
46
+ sensor.device_type !== 'GOOGLE_HOME' &&
46
47
  watchMultiConfigs([sensor.quick_action.config_id]);
47
- }, [sensor.quick_action]);
48
+ }, [sensor.quick_action, sensor?.device_type]);
48
49
 
49
50
  useEffect(() => {
50
51
  if (!sensor.quick_action) {
@@ -59,7 +60,9 @@ const ItemQuickAction = memo(({ sensor, wrapperStyle, setStatus, unit }) => {
59
60
  const userId = useSCContextSelector((state) => state?.auth.account.user.id);
60
61
  const onActionPress = useCallback(() => {
61
62
  sendRemoteCommand(sensor, action, null, userId);
62
- sensor.quick_action && watchMultiConfigs([sensor.quick_action.config_id]);
63
+ sensor.quick_action &&
64
+ sensor.device_type !== 'GOOGLE_HOME' &&
65
+ watchMultiConfigs([sensor.quick_action.config_id]);
63
66
  setIsSendingCommand(true);
64
67
 
65
68
  if (!sensor.quick_action) {
@@ -35,7 +35,7 @@ const ColorPickerTemplate = memo(({ actionGroup, doAction, sensor }) => {
35
35
  }, [configuration.config, configValues, configuration]);
36
36
 
37
37
  useEffect(() => {
38
- if (sensor?.is_managed_by_backend) {
38
+ if (sensor?.is_managed_by_backend && sensor.device_type !== 'GOOGLE_HOME') {
39
39
  watchMultiConfigs([configuration.config]);
40
40
  }
41
41
  }, [sensor, configuration.config]);
@@ -54,9 +54,17 @@ const NumberUpDownActionTemplate = ({ actionGroup, doAction, sensor }) => {
54
54
  return;
55
55
  }
56
56
 
57
- config && watchMultiConfigs([config]);
57
+ config &&
58
+ sensor.device_type !== 'GOOGLE_HOME' &&
59
+ watchMultiConfigs([config]);
58
60
  },
59
- [config, doAction, keep_track_config, sensor.is_managed_by_backend]
61
+ [
62
+ config,
63
+ doAction,
64
+ keep_track_config,
65
+ sensor.is_managed_by_backend,
66
+ sensor.device_type,
67
+ ]
60
68
  );
61
69
 
62
70
  const doActionUp = useCallback(async () => {
@@ -35,7 +35,9 @@ const OnOffSmartLock = memo(({ actionGroup, doAction, sensor }) => {
35
35
  doAction(action_off_data, JSON.stringify(dataUnlock), actionName);
36
36
  }
37
37
  if (sensor?.is_managed_by_backend) {
38
- configuration.config && watchMultiConfigs([configuration.config]);
38
+ configuration.config &&
39
+ sensor.device_type !== 'GOOGLE_HOME' &&
40
+ watchMultiConfigs([configuration.config]);
39
41
  }
40
42
  }
41
43
  }, [
@@ -47,6 +49,7 @@ const OnOffSmartLock = memo(({ actionGroup, doAction, sensor }) => {
47
49
  sensor?.name,
48
50
  configuration,
49
51
  sensor?.is_managed_by_backend,
52
+ sensor?.device_type,
50
53
  ]);
51
54
 
52
55
  useEffect(() => {
@@ -180,6 +180,7 @@ const SetupGeneratePasscode = memo(() => {
180
180
  showsVerticalScrollIndicator={false}
181
181
  showsHorizontalScrollIndicator={false}
182
182
  style={styles.scrollview}
183
+ scrollIndicatorInsets={{ right: 1 }}
183
184
  >
184
185
  <View style={styles.wrap}>
185
186
  <ButtonWrapper
@@ -11,23 +11,25 @@ const OnOffSimpleTemplate = ({
11
11
  triggerAction,
12
12
  actionGroup,
13
13
  disabled,
14
+ valueOfSwitch,
15
+ checkValueOfSwitch,
14
16
  }) => {
15
- const isEnabled = !!isOn;
16
-
17
17
  return (
18
18
  <View style={styles.wrap}>
19
19
  <View style={styles.iconAndText}>
20
20
  <IconOutline name="poweroff" size={20} style={styles.marginRight} />
21
21
  <Text type="H4">{actionGroup.title}</Text>
22
22
  </View>
23
- <Switch
24
- trackColor={{ false: Colors.Gray4, true: Colors.Primary }}
25
- thumbColor={isEnabled ? Colors.White : Colors.Gray6}
26
- ios_backgroundColor={Colors.Gray4}
27
- onValueChange={triggerAction}
28
- value={isEnabled}
29
- disabled={disabled}
30
- />
23
+ {isOn !== null && (
24
+ <Switch
25
+ trackColor={{ false: Colors.Gray4, true: Colors.Primary }}
26
+ thumbColor={isOn ? Colors.White : Colors.Gray6}
27
+ ios_backgroundColor={Colors.Gray4}
28
+ onValueChange={triggerAction}
29
+ value={checkValueOfSwitch ? !!isOn : valueOfSwitch}
30
+ disabled={disabled}
31
+ />
32
+ )}
31
33
  </View>
32
34
  );
33
35
  };
@@ -1,10 +1,19 @@
1
- import React, { memo, useCallback, useEffect, useMemo, useState } from 'react';
1
+ import React, {
2
+ memo,
3
+ useCallback,
4
+ useContext,
5
+ useEffect,
6
+ useMemo,
7
+ useState,
8
+ } from 'react';
2
9
  import { DEVICE_TYPE } from '../../../configs/Constants';
3
10
 
4
11
  import { watchMultiConfigs } from '../../../iot/Monitor';
5
12
  import { useConfigGlobalState } from '../../../iot/states';
6
13
  import OnOffButtonTemplate from './OnOffButtonTemplate';
7
14
  import OnOffSimpleTemplate from './OnOffSimpleTemplate';
15
+ import { SCContext } from '../../../context';
16
+ import { Action } from '../../../context/actionType';
8
17
 
9
18
  const getComponent = (template) => {
10
19
  switch (template) {
@@ -20,9 +29,14 @@ const getComponent = (template) => {
20
29
  const OnOffTemplate = memo(({ actionGroup, doAction, sensor }) => {
21
30
  const { configuration } = actionGroup;
22
31
  const { action_data, action_on_data, action_off_data } = configuration;
23
- const [isOn, setIsOn] = useState(true);
32
+ const [isOn, setIsOn] = useState(null);
33
+ const [valueOfSwitch, setValueOfSwitch] = useState(false);
34
+ const [checkValueOfSwitch, setCheckValueOfSwitch] = useState(true);
35
+ //checkValueOfSwitch to check the value real-time of Switch when re-entering the screen
36
+
24
37
  // eslint-disable-next-line no-unused-vars
25
38
  const [configValues, _] = useConfigGlobalState('configValues');
39
+ const { setAction } = useContext(SCContext);
26
40
 
27
41
  const actionName = useCallback(
28
42
  (text) => {
@@ -34,6 +48,10 @@ const OnOffTemplate = memo(({ actionGroup, doAction, sensor }) => {
34
48
  [actionGroup?.title, sensor?.name]
35
49
  );
36
50
  const triggerAction = useCallback(() => {
51
+ if (actionGroup?.template === 'OnOffSimpleActionTemplate') {
52
+ setAction(Action.IS_FULL_LOADING, true);
53
+ }
54
+ setCheckValueOfSwitch(false);
37
55
  switch (sensor?.device_type) {
38
56
  case DEVICE_TYPE.ZIGBEE:
39
57
  if (action_on_data && action_off_data) {
@@ -61,6 +79,7 @@ const OnOffTemplate = memo(({ actionGroup, doAction, sensor }) => {
61
79
  }
62
80
  }
63
81
  if (action_on_data && action_off_data) {
82
+ setValueOfSwitch(!isOn);
64
83
  if (isOn) {
65
84
  doAction(action_off_data, null, actionName('off'));
66
85
  } else {
@@ -68,20 +87,32 @@ const OnOffTemplate = memo(({ actionGroup, doAction, sensor }) => {
68
87
  }
69
88
  }
70
89
  if (sensor?.is_managed_by_backend) {
71
- configuration.config && watchMultiConfigs([configuration.config]);
90
+ configuration?.config &&
91
+ sensor?.device_type !== 'GOOGLE_HOME' &&
92
+ watchMultiConfigs([configuration?.config]);
93
+ if (actionGroup?.template === 'OnOffSimpleActionTemplate') {
94
+ const cleanTimeout = setTimeout(() => {
95
+ setAction(Action.IS_FULL_LOADING, false);
96
+ clearTimeout(cleanTimeout);
97
+ }, 2000);
98
+ }
99
+ } else {
100
+ setValueOfSwitch(isOn);
72
101
  }
73
102
  return;
74
103
  }
75
104
  }, [
105
+ actionGroup.template,
76
106
  actionName,
77
107
  action_data,
78
108
  action_off_data,
79
109
  action_on_data,
80
- configuration.config,
110
+ configuration?.config,
81
111
  doAction,
82
112
  isOn,
83
113
  sensor?.device_type,
84
114
  sensor?.is_managed_by_backend,
115
+ setAction,
85
116
  ]);
86
117
 
87
118
  useEffect(() => {
@@ -103,7 +134,7 @@ const OnOffTemplate = memo(({ actionGroup, doAction, sensor }) => {
103
134
  if (sensor?.device_type === DEVICE_TYPE.LG_THINQ) {
104
135
  return;
105
136
  }
106
- if (sensor?.is_managed_by_backend) {
137
+ if (sensor?.is_managed_by_backend && sensor.device_type !== 'GOOGLE_HOME') {
107
138
  watchMultiConfigs([configuration.config]);
108
139
  }
109
140
  }, [sensor, configuration.config]);
@@ -119,6 +150,8 @@ const OnOffTemplate = memo(({ actionGroup, doAction, sensor }) => {
119
150
  triggerAction={triggerAction}
120
151
  actionGroup={actionGroup}
121
152
  disabled={!action_data && !action_on_data && !action_off_data}
153
+ valueOfSwitch={valueOfSwitch}
154
+ checkValueOfSwitch={checkValueOfSwitch}
122
155
  />
123
156
  </>
124
157
  );
@@ -67,7 +67,9 @@ const OptionsDropdownActionTemplate = ({ actionGroup, doAction, sensor }) => {
67
67
  actionName
68
68
  );
69
69
  if (sensor?.is_managed_by_backend) {
70
- configuration.config && watchMultiConfigs([configuration.config]);
70
+ configuration.config &&
71
+ sensor.device_type !== 'GOOGLE_HOME' &&
72
+ watchMultiConfigs([configuration.config]);
71
73
  }
72
74
  hideAlertAction();
73
75
  }, [
@@ -79,6 +81,7 @@ const OptionsDropdownActionTemplate = ({ actionGroup, doAction, sensor }) => {
79
81
  selectedIndex,
80
82
  sensor?.is_managed_by_backend,
81
83
  sensor?.name,
84
+ sensor?.device_type,
82
85
  title,
83
86
  ]);
84
87
 
@@ -145,7 +148,10 @@ const OptionsDropdownActionTemplate = ({ actionGroup, doAction, sensor }) => {
145
148
  rightButtonClick={onDone}
146
149
  >
147
150
  <View style={styles.wrapRename}>
148
- <ScrollView style={styles.scrollView}>
151
+ <ScrollView
152
+ style={styles.scrollView}
153
+ scrollIndicatorInsets={{ right: 1 }}
154
+ >
149
155
  {!action_data && (
150
156
  <Text
151
157
  color={Colors.Gray6}
@@ -37,7 +37,7 @@ const SliderRangeTemplate = memo(({ actionGroup, doAction, sensor }) => {
37
37
  }, [configuration.config, configValues, configuration]);
38
38
 
39
39
  useEffect(() => {
40
- if (sensor?.is_managed_by_backend) {
40
+ if (sensor?.is_managed_by_backend && sensor.device_type !== 'GOOGLE_HOME') {
41
41
  watchMultiConfigs([configuration.config]);
42
42
  }
43
43
  }, [sensor, configuration.config]);
@@ -91,7 +91,10 @@ const SmartTiviActionTemplate = memo(
91
91
  }, []);
92
92
  return (
93
93
  <>
94
- <ScrollView scrollEnabled={scrollEnabled}>
94
+ <ScrollView
95
+ scrollEnabled={scrollEnabled}
96
+ scrollIndicatorInsets={{ right: 1 }}
97
+ >
95
98
  <View style={styles.wrap}>
96
99
  <View style={styles.rowOnOff}>
97
100
  <CircleButton
@@ -45,10 +45,20 @@ const GridItem = ({ item, index, length, doAction, sensor, title }) => {
45
45
  actionName = actionName.replace(/\s+/g, ' ').trim();
46
46
  doAction(actionData, null, actionName);
47
47
  if (sensor?.is_managed_by_backend) {
48
- config && watchMultiConfigs([config]);
48
+ config &&
49
+ sensor.device_type !== 'GOOGLE_HOME' &&
50
+ watchMultiConfigs([config]);
49
51
  }
50
52
  },
51
- [config, doAction, sensor?.is_managed_by_backend, sensor?.name, text, title]
53
+ [
54
+ config,
55
+ doAction,
56
+ sensor?.is_managed_by_backend,
57
+ sensor?.name,
58
+ sensor?.device_type,
59
+ text,
60
+ title,
61
+ ]
52
62
  );
53
63
 
54
64
  const iconKit = !!icon_kit_data && icon_kit_data.icon;
@@ -114,10 +124,10 @@ const StatesGridActionTemplate = ({ actionGroup, doAction, sensor }) => {
114
124
  }, [configuration, configValues]);
115
125
 
116
126
  useEffect(() => {
117
- if (sensor?.is_managed_by_backend) {
127
+ if (sensor?.is_managed_by_backend && sensor.device_type !== 'GOOGLE_HOME') {
118
128
  watchMultiConfigs(configuration.options.map((option) => option.config));
119
129
  }
120
- }, [sensor.is_managed_by_backend, configuration.options]);
130
+ }, [sensor.is_managed_by_backend, sensor.device_type, configuration.options]);
121
131
 
122
132
  return (
123
133
  <View style={styles.wrap}>
@@ -94,6 +94,7 @@ const TimerActionTemplate = ({ actionGroup, doAction, sensor }) => {
94
94
  if (sensor.is_managed_by_backend) {
95
95
  hour !== undefined &&
96
96
  minute !== undefined &&
97
+ sensor.device_type !== 'GOOGLE_HOME' &&
97
98
  watchMultiConfigs([
98
99
  configuration.config_hour,
99
100
  configuration.config_minute,
@@ -106,13 +107,17 @@ const TimerActionTemplate = ({ actionGroup, doAction, sensor }) => {
106
107
  configuration.config_minute,
107
108
  doAction,
108
109
  sensor.is_managed_by_backend,
110
+ sensor.device_type,
109
111
  ]
110
112
  );
111
113
 
112
114
  const doActionHour = useCallback(
113
115
  (hour) => {
114
116
  doAction(configuration.action_data, hour);
115
- if (sensor.is_managed_by_backend) {
117
+ if (
118
+ sensor.is_managed_by_backend &&
119
+ sensor.device_type !== 'GOOGLE_HOME'
120
+ ) {
116
121
  hour && watchMultiConfigs([configuration.config_hour]);
117
122
  }
118
123
  },
@@ -121,6 +126,7 @@ const TimerActionTemplate = ({ actionGroup, doAction, sensor }) => {
121
126
  configuration.config_hour,
122
127
  doAction,
123
128
  sensor.is_managed_by_backend,
129
+ sensor.device_type,
124
130
  ]
125
131
  );
126
132
 
@@ -201,6 +207,8 @@ const TimerActionTemplate = ({ actionGroup, doAction, sensor }) => {
201
207
  onConfirm={onConfirmTime}
202
208
  onCancel={onHideTime}
203
209
  display="spinner"
210
+ cancelTextIOS={t('cancel')}
211
+ confirmTextIOS={t('confirm')}
204
212
  />
205
213
  <BottomScrollPicker
206
214
  min={configuration.min}
@@ -37,7 +37,9 @@ const TwoButtonTemplate = memo(({ actionGroup, doAction, sensor }) => {
37
37
  }
38
38
  }
39
39
  if (sensor?.is_managed_by_backend) {
40
- configuration.config && watchMultiConfigs([configuration.config]);
40
+ configuration.config &&
41
+ sensor.device_type !== 'GOOGLE_HOME' &&
42
+ watchMultiConfigs([configuration.config]);
41
43
  }
42
44
  }, [
43
45
  actionName,
@@ -46,6 +48,7 @@ const TwoButtonTemplate = memo(({ actionGroup, doAction, sensor }) => {
46
48
  doAction,
47
49
  isOn,
48
50
  sensor?.is_managed_by_backend,
51
+ sensor?.device_type,
49
52
  ]);
50
53
 
51
54
  const triggerAction2 = useCallback(() => {
@@ -56,7 +59,7 @@ const TwoButtonTemplate = memo(({ actionGroup, doAction, sensor }) => {
56
59
  doAction(button2?.action_on_data, null, actionName('start'));
57
60
  }
58
61
  }
59
- if (sensor?.is_managed_by_backend) {
62
+ if (sensor?.is_managed_by_backend && sensor.device_type !== 'GOOGLE_HOME') {
60
63
  configuration.config && watchMultiConfigs([configuration.config]);
61
64
  }
62
65
  }, [
@@ -67,6 +70,7 @@ const TwoButtonTemplate = memo(({ actionGroup, doAction, sensor }) => {
67
70
  doAction,
68
71
  isStart,
69
72
  sensor?.is_managed_by_backend,
73
+ sensor?.device_type,
70
74
  ]);
71
75
 
72
76
  useEffect(() => {
@@ -98,7 +102,7 @@ const TwoButtonTemplate = memo(({ actionGroup, doAction, sensor }) => {
98
102
  if (sensor?.device_type === DEVICE_TYPE.LG_THINQ) {
99
103
  return;
100
104
  }
101
- if (sensor?.is_managed_by_backend) {
105
+ if (sensor?.is_managed_by_backend && sensor.device_type !== 'GOOGLE_HOME') {
102
106
  watchMultiConfigs([configuration.config]);
103
107
  }
104
108
  }, [sensor, configuration.config]);
@@ -1,6 +1,14 @@
1
1
  import React, { useState } from 'react';
2
2
  import { act, create } from 'react-test-renderer';
3
- import Index from '../OnOffTemplate';
3
+ import OnOffTemplate from '../OnOffTemplate';
4
+ import { mockSCStore } from '../../../context/mockStore';
5
+ import { SCProvider } from '../../../context';
6
+
7
+ const wrapComponent = (actionGroup, mockDoAction) => (
8
+ <SCProvider initState={mockSCStore({})}>
9
+ <OnOffTemplate actionGroup={actionGroup} doAction={mockDoAction} />
10
+ </SCProvider>
11
+ );
4
12
 
5
13
  jest.mock('react', () => ({
6
14
  ...jest.requireActual('react'),
@@ -49,21 +57,15 @@ describe('Test OneBigButtonTemplate', () => {
49
57
  const assertRender = (state, text) => {
50
58
  useState.mockImplementationOnce((init) => [state, setState]);
51
59
  const mockDoAction = jest.fn();
60
+
52
61
  act(() => {
53
- wrapper = create(
54
- <Index actionGroup={actionGroup} doAction={mockDoAction} />
55
- );
62
+ wrapper = create(wrapComponent(actionGroup, mockDoAction));
56
63
  });
57
64
 
58
65
  const renderJson = wrapper.toJSON();
59
66
 
60
- expect(renderJson?.children[0].children[0].children[1].children).toEqual(
61
- undefined
62
- );
63
-
64
- expect(
65
- renderJson?.children[0].children[0].children[1].children
66
- ).not.toEqual([text]);
67
+ expect(renderJson?.props?.visible).toEqual(false);
68
+ expect(renderJson?.type).toEqual('Modal');
67
69
  };
68
70
 
69
71
  test('render state on', () => {
@@ -78,9 +80,7 @@ describe('Test OneBigButtonTemplate', () => {
78
80
  useState.mockImplementationOnce((init) => [state, setState]);
79
81
  const mockDoAction = jest.fn();
80
82
  act(() => {
81
- wrapper = create(
82
- <Index actionGroup={actionGroup} doAction={mockDoAction} />
83
- );
83
+ wrapper = create(wrapComponent(actionGroup, mockDoAction));
84
84
  });
85
85
 
86
86
  expect(mockDoAction).not.toHaveBeenCalled();