@eohjsc/react-native-smart-city 0.4.39 → 0.4.41

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 (78) hide show
  1. package/android/build.gradle +1 -1
  2. package/package.json +2 -2
  3. package/src/commons/Action/ItemQuickAction.js +1 -0
  4. package/src/commons/ActionGroup/ColorPickerTemplate.js +3 -4
  5. package/src/commons/ActionGroup/NumberUpDownActionTemplate.js +3 -3
  6. package/src/commons/ActionGroup/OnOffSmartLock/OnOffSmartLock.js +2 -2
  7. package/src/commons/ActionGroup/OnOffTemplate/OnOffButtonTemplate.js +4 -5
  8. package/src/commons/ActionGroup/OnOffTemplate/SwitchButtonTemplate.js +4 -4
  9. package/src/commons/ActionGroup/OnOffTemplate/index.js +6 -5
  10. package/src/commons/ActionGroup/OneBigButtonTemplate.js +4 -4
  11. package/src/commons/ActionGroup/OptionsDropdownActionTemplate.js +6 -17
  12. package/src/commons/ActionGroup/SliderRangeTemplate.js +5 -3
  13. package/src/commons/ActionGroup/SmartTiviActionTemplate/SmartTiviActionTemplate.js +7 -7
  14. package/src/commons/ActionGroup/StatesGridActionTemplate.js +6 -20
  15. package/src/commons/ActionGroup/ThreeButtonTemplate/__test__/ThreeButtonTemplate.test.js +6 -6
  16. package/src/commons/ActionGroup/ThreeButtonTemplate/index.js +2 -2
  17. package/src/commons/ActionGroup/TimerActionTemplate.js +3 -2
  18. package/src/commons/ActionGroup/TwoButtonTemplate/index.js +133 -135
  19. package/src/commons/ActionGroup/__test__/ColorPickerTemplate.test.js +37 -14
  20. package/src/commons/ActionGroup/__test__/NumberUpDownTemplate.test.js +71 -31
  21. package/src/commons/ActionGroup/__test__/OnOffButtonTemplate.test.js +11 -11
  22. package/src/commons/ActionGroup/__test__/OnOffSmartLock.test.js +13 -17
  23. package/src/commons/ActionGroup/__test__/OnOffTemplate.test.js +44 -48
  24. package/src/commons/ActionGroup/__test__/OneBigButtonTemplate.test.js +56 -22
  25. package/src/commons/ActionGroup/__test__/OptionsDropdownTemplate.test.js +123 -21
  26. package/src/commons/ActionGroup/__test__/SliderRangeTemplate.test.js +12 -16
  27. package/src/commons/ActionGroup/__test__/StatesGridActionTemplate.test.js +73 -38
  28. package/src/commons/ActionGroup/__test__/SwitchButtonTemplate.test.js +11 -15
  29. package/src/commons/ActionGroup/__test__/TimerActionTemplate.test.js +11 -15
  30. package/src/commons/ActionGroup/__test__/TimerActionTemplateWithutConfigValue.test.js +9 -9
  31. package/src/commons/ActionGroup/__test__/TwoButtonTemplate.test.js +21 -31
  32. package/src/commons/ActionGroup/__test__/index.test.js +36 -21
  33. package/src/commons/ActionGroup/index.js +4 -7
  34. package/src/commons/Dashboard/MyPinnedSharedUnit/__test__/MyPinnedSharedUnit.test.js +0 -5
  35. package/src/commons/Dashboard/MyUnit/index.js +2 -2
  36. package/src/commons/FlatListDnD/__test__/index.test.js +27 -25
  37. package/src/commons/GroupCheckBox/__test__/GroupCheckBox.test.js +1 -22
  38. package/src/commons/HeaderAni/index.js +12 -2
  39. package/src/commons/MediaPlayerDetail/__test__/MediaPlayerFull.test.js +1 -23
  40. package/src/commons/OneTapTemplate/__test__/NumberUpDownActionTemplate.test.js +5 -3
  41. package/src/commons/Processing/index.js +1 -0
  42. package/src/commons/Processing/styles.js +3 -0
  43. package/src/commons/SubUnit/OneTap/ItemOneTap.js +1 -0
  44. package/src/commons/UnitSummary/ConfigHistoryChart/index.js +1 -58
  45. package/src/commons/icon/index.js +57 -0
  46. package/src/configs/AccessibilityLabel.js +1 -0
  47. package/src/hooks/IoT/__test__/useRemoteControl.test.js +52 -51
  48. package/src/hooks/IoT/__test__/useWatchConfigs.test.js +3 -2
  49. package/src/hooks/useMqtt.js +5 -2
  50. package/src/iot/mqtt.js +2 -0
  51. package/src/navigations/UnitStack.js +2 -2
  52. package/src/screens/AddNewGateway/ConnectingDevice.js +2 -2
  53. package/src/screens/AddNewGateway/ShareWifiPassword.js +2 -2
  54. package/src/screens/AllGateway/DeviceModbusDetail/__test__/index.test.js +31 -32
  55. package/src/screens/Automate/AddNewAction/SetupConfigCondition.js +19 -2
  56. package/src/screens/Automate/AddNewAction/__test__/{SetupSensor.test.js → SetupConfigCondition.test.js} +97 -0
  57. package/src/screens/Automate/EditActionsList/__tests__/index.test.js +69 -68
  58. package/src/screens/ChangePosition/__test__/index.test.js +34 -32
  59. package/src/screens/ConfirmUnitDeletion/__test__/ConfirmUnitDeletion.test.js +1 -11
  60. package/src/screens/Device/__test__/detail.test.js +40 -45
  61. package/src/screens/Device/__test__/sensorDisplayItem.test.js +14 -2
  62. package/src/screens/Device/components/ChartWrapper.js +14 -12
  63. package/src/screens/Device/components/SensorDisplayItem.js +18 -2
  64. package/src/screens/Device/components/VisualChart.js +7 -1
  65. package/src/screens/Device/components/__test__/VisualChart.test.js +0 -3
  66. package/src/screens/Device/detail.js +32 -14
  67. package/src/screens/Device/hooks/__test__/useEvaluateValue.test.js +20 -18
  68. package/src/screens/Device/styles.js +3 -0
  69. package/src/screens/Sharing/MemberList.js +16 -3
  70. package/src/screens/Sharing/__test__/SelectPermission.test.js +96 -137
  71. package/src/screens/Template/__test__/EditTemplate.test.js +48 -45
  72. package/src/screens/Unit/SelectAddToFavorites.js +1 -0
  73. package/src/screens/Unit/__test__/SelectAddress.test.js +4 -11
  74. package/src/screens/UnitSummary/components/3PPowerConsumption/__test__/3PPowerConsumption.test.js +1 -11
  75. package/src/utils/Apis/axios.js +1 -0
  76. package/src/utils/I18n/translations/en.js +2 -0
  77. package/src/utils/I18n/translations/vi.js +2 -0
  78. package/src/commons/UnitSummary/ConfigHistoryChart/__test__/ConfigHistoryChart.test.js +0 -289
@@ -12,9 +12,9 @@ jest.mock('../../../iot/states', () => ({
12
12
  useConfigGlobalState: jest.fn(),
13
13
  }));
14
14
 
15
- const wrapComponent = (actionGroup, mockDoAction) => (
15
+ const wrapComponent = (item, mockDoAction) => (
16
16
  <SCProvider initState={mockSCStore({})}>
17
- <OnOffTemplate actionGroup={actionGroup} doAction={mockDoAction} />
17
+ <OnOffTemplate item={item} doAction={mockDoAction} />
18
18
  </SCProvider>
19
19
  );
20
20
 
@@ -26,7 +26,7 @@ jest.mock('@react-navigation/native', () => {
26
26
  });
27
27
 
28
28
  describe('Test OneBigButtonTemplate', () => {
29
- const action_on_data = {
29
+ const actionOnData = {
30
30
  color: '#00979D',
31
31
  command_prefer_over_bluetooth: true,
32
32
  command_prefer_over_googlehome: false,
@@ -37,7 +37,7 @@ describe('Test OneBigButtonTemplate', () => {
37
37
  key: '5ed1d4dc-a905-47cd-b0c9-f979644bd21a',
38
38
  };
39
39
 
40
- const action_off_data = {
40
+ const actionOffData = {
41
41
  color: '#00979D',
42
42
  command_prefer_over_bluetooth: true,
43
43
  command_prefer_over_googlehome: false,
@@ -47,14 +47,14 @@ describe('Test OneBigButtonTemplate', () => {
47
47
  id: 20,
48
48
  key: '5ed1d4dc-a905-47cd-b0c9-f979644bd21a',
49
49
  };
50
- const actionGroup = {
50
+ const displayItem = {
51
51
  configuration: {
52
52
  action_on: '5ed1d4dc-a905-47cd-b0c9-f979644bd21a',
53
- action_on_data: action_on_data,
53
+ action_on_data: actionOnData,
54
54
  icon_on: 'caret-up',
55
55
  text_on: 'ON',
56
56
  action_off: '5ed1d4dc-a905-47cd-b0c9-f979644bd21b',
57
- action_off_data: action_off_data,
57
+ action_off_data: actionOffData,
58
58
  icon_off: 'caret-up',
59
59
  text_off: 'OFF',
60
60
  config: 1,
@@ -72,7 +72,7 @@ describe('Test OneBigButtonTemplate', () => {
72
72
  const mockDoAction = jest.fn();
73
73
 
74
74
  await act(async () => {
75
- wrapper = create(wrapComponent(actionGroup, mockDoAction));
75
+ wrapper = create(wrapComponent(displayItem, mockDoAction));
76
76
  });
77
77
 
78
78
  const instance = wrapper.root;
@@ -115,7 +115,7 @@ describe('Test OneBigButtonTemplate', () => {
115
115
  ]);
116
116
  const mockDoAction = jest.fn();
117
117
  await act(async () => {
118
- wrapper = create(wrapComponent(actionGroup, mockDoAction));
118
+ wrapper = create(wrapComponent(displayItem, mockDoAction));
119
119
  });
120
120
  const instance = wrapper.root;
121
121
  const button = instance.findByType(TouchableOpacity);
@@ -126,10 +126,10 @@ describe('Test OneBigButtonTemplate', () => {
126
126
  };
127
127
 
128
128
  it('action state on', async () => {
129
- await assertActionCall(true, action_on_data, { state: 0, value: 0 });
129
+ await assertActionCall(true, actionOnData, { state: 0, value: 0 });
130
130
  });
131
131
 
132
132
  it('action state off', async () => {
133
- await assertActionCall(false, action_off_data, { state: 1, value: 1 });
133
+ await assertActionCall(false, actionOffData, { state: 1, value: 1 });
134
134
  });
135
135
  });
@@ -20,21 +20,17 @@ jest.mock('@react-navigation/native', () => {
20
20
  };
21
21
  });
22
22
 
23
- const wrapComponent = (actionGroup, doAction, sensor) => (
23
+ const wrapComponent = (item, doAction, sensor) => (
24
24
  <SCProvider initState={mockSCStore({})}>
25
- <OnOffSmartLock
26
- actionGroup={actionGroup}
27
- doAction={doAction}
28
- sensor={sensor}
29
- />
25
+ <OnOffSmartLock item={item} doAction={doAction} sensor={sensor} />
30
26
  </SCProvider>
31
27
  );
32
28
 
33
29
  describe('Test OnOffTemplate', () => {
34
30
  let wrapper;
35
- let actionGroup;
31
+ let displayItem;
36
32
 
37
- const action_on_data = {
33
+ const actionOnData = {
38
34
  color: '#00979D',
39
35
  command_prefer_over_bluetooth: true,
40
36
  command_prefer_over_googlehome: false,
@@ -44,7 +40,7 @@ describe('Test OnOffTemplate', () => {
44
40
  id: 20,
45
41
  key: 'key-2',
46
42
  };
47
- const action_off_data = {
43
+ const actionOffData = {
48
44
  color: '#00979D',
49
45
  command_prefer_over_bluetooth: true,
50
46
  command_prefer_over_googlehome: false,
@@ -58,12 +54,12 @@ describe('Test OnOffTemplate', () => {
58
54
  beforeEach(() => {
59
55
  watchMultiConfigs.mockClear();
60
56
  mockDoAction.mockClear();
61
- actionGroup = {
57
+ displayItem = {
62
58
  template: 'OnOffSmartLockActionTemplate',
63
59
  configuration: {
64
60
  config: 5,
65
- action_on_data: action_on_data,
66
- action_off_data: action_off_data,
61
+ action_on_data: actionOnData,
62
+ action_off_data: actionOffData,
67
63
  icon: 'up',
68
64
  is_on_value: '2',
69
65
  },
@@ -78,7 +74,7 @@ describe('Test OnOffTemplate', () => {
78
74
  ]);
79
75
  const sensor = { is_managed_by_backend: true, name: 'Sensor' };
80
76
  await act(async () => {
81
- wrapper = await create(wrapComponent(actionGroup, mockDoAction, sensor));
77
+ wrapper = await create(wrapComponent(displayItem, mockDoAction, sensor));
82
78
  });
83
79
  const instance = wrapper.root;
84
80
  const button = instance.find(
@@ -87,18 +83,18 @@ describe('Test OnOffTemplate', () => {
87
83
  await act(async () => {
88
84
  await button.props.onPress();
89
85
  });
90
- expect(mockDoAction).toBeCalledWith(action_on_data, '{"door_lock":0}');
86
+ expect(mockDoAction).toBeCalledWith(actionOnData, '{"door_lock":0}');
91
87
  });
92
88
 
93
89
  it('render with template OnOffSmartLockActionTemplate doAction unlock', async () => {
94
- actionGroup.configuration.is_on_value = null;
90
+ displayItem.configuration.is_on_value = null;
95
91
  const sensor = { is_managed_by_backend: false, name: 'Sensor' };
96
92
  useConfigGlobalState.mockImplementation(() => [
97
93
  { 5: { value: 0 } },
98
94
  jest.fn(),
99
95
  ]);
100
96
  await act(async () => {
101
- wrapper = await create(wrapComponent(actionGroup, mockDoAction, sensor));
97
+ wrapper = await create(wrapComponent(displayItem, mockDoAction, sensor));
102
98
  });
103
99
  const instance = wrapper.root;
104
100
  const button = instance.find(
@@ -107,6 +103,6 @@ describe('Test OnOffTemplate', () => {
107
103
  await act(async () => {
108
104
  await button.props.onPress();
109
105
  });
110
- expect(mockDoAction).toBeCalledWith(action_off_data, '{"door_lock":1}');
106
+ expect(mockDoAction).toBeCalledWith(actionOffData, '{"door_lock":1}');
111
107
  });
112
108
  });
@@ -10,13 +10,9 @@ import OnOffSimpleTemplate from '../OnOffTemplate/OnOffSimpleTemplate';
10
10
  import { mockSCStore } from '../../../context/mockStore';
11
11
  import { SCProvider } from '../../../context';
12
12
 
13
- const wrapComponent = (actionGroup, mockDoAction, sensor) => (
13
+ const wrapComponent = (item, mockDoAction, sensor) => (
14
14
  <SCProvider initState={mockSCStore({})}>
15
- <OnOffTemplate
16
- actionGroup={actionGroup}
17
- doAction={mockDoAction}
18
- sensor={sensor}
19
- />
15
+ <OnOffTemplate item={item} doAction={mockDoAction} sensor={sensor} />
20
16
  </SCProvider>
21
17
  );
22
18
 
@@ -34,11 +30,11 @@ jest.mock('@react-navigation/native', () => {
34
30
  });
35
31
 
36
32
  describe('Test OnOffTemplate', () => {
37
- let actionGroup;
33
+ let displayItem;
38
34
  let tree;
39
35
  let sensor;
40
36
 
41
- const action_data = {
37
+ const actionData = {
42
38
  color: '#00979D',
43
39
  command_prefer_over_bluetooth: true,
44
40
  command_prefer_over_googlehome: false,
@@ -48,7 +44,7 @@ describe('Test OnOffTemplate', () => {
48
44
  id: 20,
49
45
  key: 'key-1',
50
46
  };
51
- const action_on_data = {
47
+ const actionOnData = {
52
48
  color: '#00979D',
53
49
  command_prefer_over_bluetooth: true,
54
50
  command_prefer_over_googlehome: false,
@@ -58,7 +54,7 @@ describe('Test OnOffTemplate', () => {
58
54
  id: 20,
59
55
  key: 'key-2',
60
56
  };
61
- const action_off_data = {
57
+ const actionOffData = {
62
58
  color: '#00979D',
63
59
  command_prefer_over_bluetooth: true,
64
60
  command_prefer_over_googlehome: false,
@@ -73,12 +69,12 @@ describe('Test OnOffTemplate', () => {
73
69
  watchMultiConfigs.mockClear();
74
70
  jest.useFakeTimers();
75
71
 
76
- actionGroup = {
72
+ displayItem = {
77
73
  template: 'OnOffSimpleActionTemplate',
78
74
  configuration: {
79
75
  config: 5,
80
- action_on_data: action_on_data,
81
- action_off_data: action_off_data,
76
+ action_on_data: actionOnData,
77
+ action_off_data: actionOffData,
82
78
  icon: 'up',
83
79
  is_on_value: [2],
84
80
  },
@@ -91,7 +87,7 @@ describe('Test OnOffTemplate', () => {
91
87
  it('render with template OnOffSimpleActionTemplate', async () => {
92
88
  const mockDoAction = jest.fn();
93
89
  await act(async () => {
94
- tree = await create(wrapComponent(actionGroup, mockDoAction, {}));
90
+ tree = await create(wrapComponent(displayItem, mockDoAction, {}));
95
91
  });
96
92
  const instance = tree.root;
97
93
  const template = instance.findAllByType(OnOffSimpleTemplate);
@@ -99,10 +95,10 @@ describe('Test OnOffTemplate', () => {
99
95
  });
100
96
 
101
97
  it('render with template on_off_button_action_template', async () => {
102
- actionGroup.template = 'on_off_button_action_template';
98
+ displayItem.template = 'on_off_button_action_template';
103
99
  const mockDoAction = jest.fn();
104
100
  await act(async () => {
105
- tree = await create(wrapComponent(actionGroup, mockDoAction, {}));
101
+ tree = await create(wrapComponent(displayItem, mockDoAction, {}));
106
102
  });
107
103
  const instance = tree.root;
108
104
  const template = instance.findAllByType(OnOffButtonTemplate);
@@ -110,10 +106,10 @@ describe('Test OnOffTemplate', () => {
110
106
  });
111
107
 
112
108
  it('render with wrong template', async () => {
113
- actionGroup.template = 'wrong_template';
109
+ displayItem.template = 'wrong_template';
114
110
  const mockDoAction = jest.fn();
115
111
  await act(async () => {
116
- tree = await create(wrapComponent(actionGroup, mockDoAction, {}));
112
+ tree = await create(wrapComponent(displayItem, mockDoAction, {}));
117
113
  });
118
114
  const instance = tree.root;
119
115
 
@@ -131,7 +127,7 @@ describe('Test OnOffTemplate', () => {
131
127
  it('render with template OnOffSimpleActionTemplate with is_managed_by_backend', async () => {
132
128
  const mockDoAction = jest.fn();
133
129
  await act(async () => {
134
- tree = await create(wrapComponent(actionGroup, mockDoAction, {}));
130
+ tree = await create(wrapComponent(displayItem, mockDoAction, {}));
135
131
  });
136
132
  const instance = tree.root;
137
133
  const template = instance.findAllByType(OnOffSimpleTemplate);
@@ -142,7 +138,7 @@ describe('Test OnOffTemplate', () => {
142
138
  it('template OnOffSimpleActionTemplate doAction with is_on_value, match configValue', async () => {
143
139
  const mockDoAction = jest.fn();
144
140
  await act(async () => {
145
- tree = await create(wrapComponent(actionGroup, mockDoAction, sensor));
141
+ tree = await create(wrapComponent(displayItem, mockDoAction, sensor));
146
142
  });
147
143
 
148
144
  const instance = tree.root;
@@ -152,15 +148,15 @@ describe('Test OnOffTemplate', () => {
152
148
  await act(async () => {
153
149
  await template.props.triggerAction();
154
150
  });
155
- expect(mockDoAction).toHaveBeenCalledWith(action_off_data, undefined);
151
+ expect(mockDoAction).toHaveBeenCalledWith(actionOffData, undefined);
156
152
  expect(watchMultiConfigs).toBeCalledTimes(0);
157
153
  });
158
154
 
159
155
  it('template OnOffSimpleActionTemplate doAction with is_on_value, not match configValue', async () => {
160
- actionGroup.configuration.is_on_value = [1];
156
+ displayItem.configuration.is_on_value = [1];
161
157
  const mockDoAction = jest.fn();
162
158
  await act(async () => {
163
- tree = await create(wrapComponent(actionGroup, mockDoAction, sensor));
159
+ tree = await create(wrapComponent(displayItem, mockDoAction, sensor));
164
160
  });
165
161
  const instance = tree.root;
166
162
  const template = instance.findByType(OnOffSimpleTemplate);
@@ -169,13 +165,13 @@ describe('Test OnOffTemplate', () => {
169
165
  await act(async () => {
170
166
  await template.props.triggerAction();
171
167
  });
172
- expect(mockDoAction).toHaveBeenCalledWith(action_on_data, undefined);
168
+ expect(mockDoAction).toHaveBeenCalledWith(actionOnData, undefined);
173
169
  });
174
170
 
175
171
  it('template OnOffSimpleActionTemplate doAction with is_on_value and is_managed_by_backend', async () => {
176
172
  const mockDoAction = jest.fn();
177
173
  await act(async () => {
178
- tree = await create(wrapComponent(actionGroup, mockDoAction, sensor));
174
+ tree = await create(wrapComponent(displayItem, mockDoAction, sensor));
179
175
  });
180
176
  const instance = tree.root;
181
177
  const template = instance.findByType(OnOffSimpleTemplate);
@@ -184,16 +180,16 @@ describe('Test OnOffTemplate', () => {
184
180
  await act(async () => {
185
181
  await template.props.triggerAction();
186
182
  });
187
- expect(mockDoAction).toHaveBeenCalledWith(action_off_data, undefined);
183
+ expect(mockDoAction).toHaveBeenCalledWith(actionOffData, undefined);
188
184
  expect(watchMultiConfigs).toBeCalledTimes(0);
189
185
  });
190
186
 
191
187
  it('render with template OnOffSimpleActionTemplate with just action_data', async () => {
192
- actionGroup = {
188
+ displayItem = {
193
189
  template: 'OnOffSimpleActionTemplate',
194
190
  configuration: {
195
191
  config: 5,
196
- action_data: action_data,
192
+ action_data: actionData,
197
193
  icon: 'up',
198
194
  is_on_value: [2],
199
195
  },
@@ -201,7 +197,7 @@ describe('Test OnOffTemplate', () => {
201
197
  };
202
198
  const mockDoAction = jest.fn();
203
199
  await act(async () => {
204
- tree = await create(wrapComponent(actionGroup, mockDoAction, {}));
200
+ tree = await create(wrapComponent(displayItem, mockDoAction, {}));
205
201
  });
206
202
  const instance = tree.root;
207
203
  const template = instance.findAllByType(OnOffSimpleTemplate);
@@ -211,16 +207,16 @@ describe('Test OnOffTemplate', () => {
211
207
  await act(async () => {
212
208
  await template[0].props.triggerAction();
213
209
  });
214
- expect(mockDoAction).toHaveBeenCalledWith(action_data, undefined);
210
+ expect(mockDoAction).toHaveBeenCalledWith(actionData, undefined);
215
211
  });
216
212
 
217
213
  it('render with template OnOffSimpleActionTemplate with just action_data lg_thinq', async () => {
218
214
  jest.useFakeTimers();
219
- actionGroup = {
215
+ displayItem = {
220
216
  template: 'OnOffSimpleActionTemplate',
221
217
  configuration: {
222
218
  config: 5,
223
- action_data: action_data,
219
+ action_data: actionData,
224
220
  icon: 'up',
225
221
  is_on_value: [2],
226
222
  },
@@ -229,7 +225,7 @@ describe('Test OnOffTemplate', () => {
229
225
  const mockDoAction = jest.fn();
230
226
  await act(async () => {
231
227
  tree = await create(
232
- wrapComponent(actionGroup, mockDoAction, {
228
+ wrapComponent(displayItem, mockDoAction, {
233
229
  device_type: DEVICE_TYPE.LG_THINQ,
234
230
  is_managed_by_backend: true,
235
231
  })
@@ -246,16 +242,16 @@ describe('Test OnOffTemplate', () => {
246
242
  await act(async () => {
247
243
  jest.runAllTimers();
248
244
  });
249
- expect(mockDoAction).toHaveBeenCalledWith(action_data, undefined);
245
+ expect(mockDoAction).toHaveBeenCalledWith(actionData, undefined);
250
246
  });
251
247
 
252
248
  it('render with template OnOffSimpleActionTemplate with action_data zigbee trigger off', async () => {
253
- actionGroup = {
249
+ displayItem = {
254
250
  template: 'OnOffSimpleActionTemplate',
255
251
  configuration: {
256
252
  config: 5,
257
- action_on_data: action_on_data,
258
- action_off_data: action_off_data,
253
+ action_on_data: actionOnData,
254
+ action_off_data: actionOffData,
259
255
  icon: 'up',
260
256
  is_on_value: [2],
261
257
  allow_config_store_value: true,
@@ -265,7 +261,7 @@ describe('Test OnOffTemplate', () => {
265
261
  const mockDoAction = jest.fn();
266
262
  await act(async () => {
267
263
  tree = await create(
268
- wrapComponent(actionGroup, mockDoAction, {
264
+ wrapComponent(displayItem, mockDoAction, {
269
265
  device_type: DEVICE_TYPE.ZIGBEE,
270
266
  })
271
267
  );
@@ -276,19 +272,19 @@ describe('Test OnOffTemplate', () => {
276
272
  await act(async () => {
277
273
  await template[0].props.triggerAction();
278
274
  });
279
- expect(mockDoAction).toHaveBeenCalledWith(action_off_data, {
275
+ expect(mockDoAction).toHaveBeenCalledWith(actionOffData, {
280
276
  config_id: 5,
281
277
  config_value: 0,
282
278
  });
283
279
  });
284
280
 
285
281
  it('render with template OnOffSimpleActionTemplate with action_data zigbee trigger on', async () => {
286
- actionGroup = {
282
+ displayItem = {
287
283
  template: 'OnOffSimpleActionTemplate',
288
284
  configuration: {
289
285
  config: 5,
290
- action_on_data: action_on_data,
291
- action_off_data: action_off_data,
286
+ action_on_data: actionOnData,
287
+ action_off_data: actionOffData,
292
288
  icon: 'up',
293
289
  is_on_value: [1],
294
290
  allow_config_store_value: true,
@@ -298,7 +294,7 @@ describe('Test OnOffTemplate', () => {
298
294
  const mockDoAction = jest.fn();
299
295
  await act(async () => {
300
296
  tree = await create(
301
- wrapComponent(actionGroup, mockDoAction, {
297
+ wrapComponent(displayItem, mockDoAction, {
302
298
  device_type: DEVICE_TYPE.ZIGBEE,
303
299
  })
304
300
  );
@@ -309,14 +305,14 @@ describe('Test OnOffTemplate', () => {
309
305
  await act(async () => {
310
306
  await template[0].props.triggerAction();
311
307
  });
312
- expect(mockDoAction).toHaveBeenCalledWith(action_on_data, {
308
+ expect(mockDoAction).toHaveBeenCalledWith(actionOnData, {
313
309
  config_id: 5,
314
310
  config_value: 1,
315
311
  });
316
312
  });
317
313
 
318
314
  it('render with template OnOffSimpleActionTemplate with zigbee device wrong action_data', async () => {
319
- actionGroup = {
315
+ displayItem = {
320
316
  template: 'OnOffSimpleActionTemplate',
321
317
  configuration: {
322
318
  config: 5,
@@ -329,7 +325,7 @@ describe('Test OnOffTemplate', () => {
329
325
  const mockDoAction = jest.fn();
330
326
  await act(async () => {
331
327
  tree = await create(
332
- wrapComponent(actionGroup, mockDoAction, {
328
+ wrapComponent(displayItem, mockDoAction, {
333
329
  device_type: DEVICE_TYPE.ZIGBEE,
334
330
  })
335
331
  );
@@ -344,7 +340,7 @@ describe('Test OnOffTemplate', () => {
344
340
  });
345
341
 
346
342
  it('render with template OnOffSimpleActionTemplate disabled', async () => {
347
- actionGroup = {
343
+ displayItem = {
348
344
  template: 'OnOffSimpleActionTemplate',
349
345
  configuration: {
350
346
  config: 5,
@@ -355,7 +351,7 @@ describe('Test OnOffTemplate', () => {
355
351
  };
356
352
  const mockDoAction = jest.fn();
357
353
  await act(async () => {
358
- tree = await create(wrapComponent(actionGroup, mockDoAction, {}));
354
+ tree = await create(wrapComponent(displayItem, mockDoAction, {}));
359
355
  });
360
356
  const instance = tree.root;
361
357
  const template = instance.findAllByType(OnOffSimpleTemplate);
@@ -5,11 +5,12 @@ import { TouchableOpacity } from 'react-native';
5
5
  import OneBigButtonTemplate from '../OneBigButtonTemplate';
6
6
  import { mockSCStore } from '../../../context/mockStore';
7
7
  import { SCProvider } from '../../../context';
8
+ import Text from '../../Text';
8
9
 
9
- const wrapComponent = (actionGroup, mockDoAction, sensor) => (
10
+ const wrapComponent = (displayItem, mockDoAction, sensor) => (
10
11
  <SCProvider initState={mockSCStore({})}>
11
12
  <OneBigButtonTemplate
12
- actionGroup={actionGroup}
13
+ item={displayItem}
13
14
  doAction={mockDoAction}
14
15
  sensor={sensor}
15
16
  />
@@ -17,27 +18,32 @@ const wrapComponent = (actionGroup, mockDoAction, sensor) => (
17
18
  );
18
19
 
19
20
  describe('Test OneBigButtonTemplate', () => {
20
- const action_data = {
21
- color: '#00979D',
22
- command_prefer_over_bluetooth: true,
23
- command_prefer_over_googlehome: false,
24
- command_prefer_over_internet: false,
25
- googlehome_actions: [],
26
- icon: 'caret-up',
27
- id: 20,
28
- key: '5ed1d4dc-a905-47cd-b0c9-f979644bd21a',
29
- };
30
- const actionGroup = {
31
- configuration: {
32
- action: '5ed1d4dc-a905-47cd-b0c9-f979644bd21a',
33
- action_data: action_data,
34
- icon: 'caret-up',
35
- text: 'UP',
36
- },
37
- };
21
+ let actionData;
22
+ let displayItem;
38
23
  let tree;
39
24
  let sensor;
40
25
 
26
+ beforeEach(() => {
27
+ actionData = {
28
+ color: '#00979D',
29
+ command_prefer_over_bluetooth: true,
30
+ command_prefer_over_googlehome: false,
31
+ command_prefer_over_internet: false,
32
+ googlehome_actions: [],
33
+ icon: 'caret-up',
34
+ id: 20,
35
+ key: '5ed1d4dc-a905-47cd-b0c9-f979644bd21a',
36
+ };
37
+ displayItem = {
38
+ configuration: {
39
+ action: '5ed1d4dc-a905-47cd-b0c9-f979644bd21a',
40
+ action_data: actionData,
41
+ icon: 'caret-up',
42
+ text: 'UP',
43
+ },
44
+ };
45
+ });
46
+
41
47
  beforeEach(() => {
42
48
  sensor = { name: 'Sensor' };
43
49
  });
@@ -45,7 +51,7 @@ describe('Test OneBigButtonTemplate', () => {
45
51
  it('render OneBigButtonTemplate', async () => {
46
52
  const mockDoAction = jest.fn();
47
53
  await act(async () => {
48
- tree = await create(wrapComponent(actionGroup, mockDoAction, sensor));
54
+ tree = await create(wrapComponent(displayItem, mockDoAction, sensor));
49
55
  });
50
56
  const instance = tree.root;
51
57
  const buttons = instance.findAllByType(TouchableOpacity);
@@ -56,6 +62,34 @@ describe('Test OneBigButtonTemplate', () => {
56
62
  });
57
63
 
58
64
  expect(mockDoAction).toHaveBeenCalledTimes(1);
59
- expect(mockDoAction).toHaveBeenCalledWith(action_data, null);
65
+ expect(mockDoAction).toHaveBeenCalledWith(actionData, null);
66
+ });
67
+
68
+ it('render with title', async () => {
69
+ const mockDoAction = jest.fn();
70
+ displayItem.title = 'xxx';
71
+
72
+ await act(async () => {
73
+ tree = await create(wrapComponent(displayItem, mockDoAction, sensor));
74
+ });
75
+ const instance = tree.root;
76
+ const texts = instance.findAll(
77
+ (el) => el.type === Text && el.props.type === 'H3'
78
+ );
79
+ expect(texts).toHaveLength(1);
80
+
81
+ expect(texts[0].props.children).toEqual('xxx');
82
+ });
83
+ it('render with no configuration', async () => {
84
+ const mockDoAction = jest.fn();
85
+ delete displayItem.configuration;
86
+
87
+ await act(async () => {
88
+ tree = await create(wrapComponent(displayItem, mockDoAction, sensor));
89
+ });
90
+ const instance = tree.root;
91
+ const texts = instance.findAllByType(Text);
92
+
93
+ expect(texts[0].props.children).toEqual(undefined);
60
94
  });
61
95
  });