@eohjsc/react-native-smart-city 0.7.22 → 0.7.24

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 (61) hide show
  1. package/package.json +1 -1
  2. package/src/commons/ActionGroup/TerminalBoxTemplate.js +3 -0
  3. package/src/commons/ActionTemplate/OnOffButtonAction.js +38 -4
  4. package/src/commons/ActionTemplate/OnOffSimpleAction.js +55 -15
  5. package/src/commons/ActionTemplate/OnOffSmartLockAction.js +46 -8
  6. package/src/commons/ActionTemplate/SwitchButtonAction.js +35 -4
  7. package/src/commons/ActionTemplate/ThreeButtonAction.js +13 -3
  8. package/src/commons/ActionTemplate/__test__/OnOffButtonAction.test.js +46 -7
  9. package/src/commons/ActionTemplate/__test__/OnOffSimpleAction.test.js +66 -6
  10. package/src/commons/ActionTemplate/__test__/OnOffSmartLockAction.test.js +53 -13
  11. package/src/commons/ActionTemplate/__test__/SwitchButtonAction.test.js +46 -7
  12. package/src/commons/ActionTemplate/__test__/index.test.js +6 -2
  13. package/src/commons/ActionTemplate/index.js +65 -10
  14. package/src/commons/MediaPlayerDetail/MediaPlayerFull.js +26 -32
  15. package/src/commons/OneTapTemplate/StatesGridActionTemplate.js +8 -6
  16. package/src/commons/SubUnit/OneTap/__test__/SubUnitAutomate.test.js +6 -0
  17. package/src/commons/SubUnit/OneTap/index.js +5 -0
  18. package/src/commons/UnitSummary/ConfigHistoryChart/index.js +16 -12
  19. package/src/commons/Widgets/IFrameWithConfig/IFrameWithConfig.js +3 -1
  20. package/src/commons/Widgets/IFrameWithConfig/__tests__/IFrameWithConfig.test.js +1 -1
  21. package/src/configs/API.js +6 -0
  22. package/src/configs/AccessibilityLabel.js +2 -0
  23. package/src/screens/ActivityLog/__test__/index.test.js +10 -0
  24. package/src/screens/ActivityLog/hooks/index.js +1 -1
  25. package/src/screens/Automate/AddNewAction/ChooseAction.js +15 -51
  26. package/src/screens/Automate/AddNewAction/SelectControlDevices.js +13 -3
  27. package/src/screens/Automate/AddNewAction/SetupConfigCondition.js +74 -54
  28. package/src/screens/Automate/AddNewAction/__test__/ChooseAction.test.js +114 -4
  29. package/src/screens/Automate/AddNewAction/__test__/SetupConfigCondition.test.js +37 -8
  30. package/src/screens/Automate/AddNewAutoSmart/AddTypeSmart.js +5 -0
  31. package/src/screens/Automate/AddNewAutoSmart/__test__/AddNewAutoSmart.test.js +18 -2
  32. package/src/screens/Automate/Components/InputName.js +7 -6
  33. package/src/screens/Automate/Constants.js +12 -0
  34. package/src/screens/Automate/EditActionsList/UpdateActionScript.js +24 -55
  35. package/src/screens/Automate/EditActionsList/__tests__/UpdateActionScript.test.js +298 -41
  36. package/src/screens/Automate/EditActionsList/__tests__/index.test.js +2 -2
  37. package/src/screens/Automate/EditActionsList/index.js +26 -14
  38. package/src/screens/Automate/MultiUnits.js +9 -1
  39. package/src/screens/Automate/OneTap/__test__/AddNewOneTap.test.js +3 -3
  40. package/src/screens/Automate/ScriptDetail/Components/AddActionScript.js +4 -10
  41. package/src/screens/Automate/ScriptDetail/Components/DeleteScript.js +2 -4
  42. package/src/screens/Automate/ScriptDetail/__test__/index.test.js +78 -0
  43. package/src/screens/Automate/ScriptDetail/index.js +16 -10
  44. package/src/screens/Automate/ScriptDetail/utils.js +39 -15
  45. package/src/screens/Automate/SetSchedule/AddEditConditionSchedule.js +27 -160
  46. package/src/screens/Automate/SetSchedule/EditSchedule.js +269 -0
  47. package/src/screens/Automate/SetSchedule/__test__/AddEditConditionSchedule.test.js +327 -22
  48. package/src/screens/Automate/SetSchedule/__test__/index.test.js +35 -22
  49. package/src/screens/Automate/SetSchedule/components/RepeatOptionsPopup.js +2 -8
  50. package/src/screens/Automate/SetSchedule/index.js +15 -129
  51. package/src/screens/Automate/SetSchedule/styles/indexStyles.js +9 -0
  52. package/src/screens/Automate/__test__/MultiUnits.test.js +6 -1
  53. package/src/screens/Automate/hooks/useAction.js +222 -0
  54. package/src/screens/Device/__test__/detail.test.js +48 -1
  55. package/src/screens/Device/detail.js +46 -3
  56. package/src/screens/PlayBackCamera/__test__/index.test.js +48 -13
  57. package/src/screens/PlayBackCamera/index.js +1 -1
  58. package/src/utils/Apis/axios.js +6 -0
  59. package/src/utils/I18n/translations/en.js +8 -0
  60. package/src/utils/I18n/translations/vi.js +12 -4
  61. package/src/screens/Automate/constants.js +0 -0
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.7.22",
4
+ "version": "0.7.24",
5
5
  "description": "TODO",
6
6
  "main": "index.js",
7
7
  "files": [
@@ -91,6 +91,9 @@ const TerminalBoxTemplate = ({ item, doAction, isWidgetOrder }) => {
91
91
 
92
92
  const setMessages = useCallback(
93
93
  (configMessages) => {
94
+ if (!Array.isArray(configMessages)) {
95
+ return;
96
+ }
94
97
  let messages = [];
95
98
  configMessages.map((configMessage) => {
96
99
  const type = configMessage.id === from_config.id ? 'from' : 'to';
@@ -1,11 +1,20 @@
1
1
  import React, { useCallback } from 'react';
2
2
  import { TouchableOpacity } from 'react-native';
3
3
  import AccessibilityLabel from '../../configs/AccessibilityLabel';
4
+ import { useTranslations } from '../../hooks/Common/useTranslations';
4
5
  import Text from '../Text';
5
6
  import styles from './OnOffButtonActionStyles';
6
7
 
7
- const OnOffButtonAction = ({ title, configuration, onPress, template }) => {
8
- const { text_on, text_off, action_on, action_off } = configuration;
8
+ const OnOffButtonAction = ({
9
+ title,
10
+ configuration,
11
+ onPress,
12
+ onPressToggle,
13
+ template,
14
+ }) => {
15
+ const t = useTranslations();
16
+ const { action_on, action_off, text_on, text_off } = configuration;
17
+
9
18
  const onPressActionOn = useCallback(() => {
10
19
  onPress &&
11
20
  onPress({
@@ -14,6 +23,7 @@ const OnOffButtonAction = ({ title, configuration, onPress, template }) => {
14
23
  action: action_on,
15
24
  action_off: null,
16
25
  template,
26
+ is_toggle: false,
17
27
  });
18
28
  }, [onPress, configuration, text_on, action_on, template]);
19
29
 
@@ -25,9 +35,21 @@ const OnOffButtonAction = ({ title, configuration, onPress, template }) => {
25
35
  action: action_off,
26
36
  action_on: null,
27
37
  template,
38
+ is_toggle: false,
28
39
  });
29
40
  }, [onPress, configuration, text_off, action_off, template]);
30
41
 
42
+ const onPressActionToggle = useCallback(() => {
43
+ onPressToggle &&
44
+ onPressToggle({
45
+ ...configuration,
46
+ action_on_data: null,
47
+ action_off_data: null,
48
+ template,
49
+ is_toggle: true,
50
+ });
51
+ }, [onPressToggle, configuration, template]);
52
+
31
53
  return (
32
54
  <>
33
55
  <TouchableOpacity
@@ -39,7 +61,7 @@ const OnOffButtonAction = ({ title, configuration, onPress, template }) => {
39
61
  style={styles.textWithLine}
40
62
  accessibilityLabel={AccessibilityLabel.ON_OFF_BUTTON_ACTION_TITLE}
41
63
  >
42
- {title} {text_on}
64
+ {`${title} - ${text_on}`}
43
65
  </Text>
44
66
  </TouchableOpacity>
45
67
  <TouchableOpacity
@@ -51,7 +73,19 @@ const OnOffButtonAction = ({ title, configuration, onPress, template }) => {
51
73
  style={styles.textWithLine}
52
74
  accessibilityLabel={AccessibilityLabel.ON_OFF_BUTTON_ACTION_TITLE}
53
75
  >
54
- {title} {text_off}
76
+ {`${title} - ${text_off}`}
77
+ </Text>
78
+ </TouchableOpacity>
79
+ <TouchableOpacity
80
+ onPress={onPressActionToggle}
81
+ accessibilityLabel={AccessibilityLabel.TOGGLE_BUTTON}
82
+ >
83
+ <Text
84
+ type="H4"
85
+ style={styles.textWithLine}
86
+ accessibilityLabel={AccessibilityLabel.ON_OFF_BUTTON_ACTION_TITLE}
87
+ >
88
+ {`${title} - ${t('toggle')}`}
55
89
  </Text>
56
90
  </TouchableOpacity>
57
91
  </>
@@ -1,34 +1,54 @@
1
- import React from 'react';
1
+ import React, { useCallback } from 'react';
2
2
  import { TouchableOpacity } from 'react-native';
3
- import Text from '../Text';
3
+ import AccessibilityLabel from '../../configs/AccessibilityLabel';
4
4
  import { useTranslations } from '../../hooks/Common/useTranslations';
5
+ import Text from '../Text';
5
6
  import styles from './OnOffSimpleActionStyles';
6
- import AccessibilityLabel from '../../configs/AccessibilityLabel';
7
7
 
8
- const OnOffSimpleAction = ({ configuration, onPress, template }) => {
8
+ const OnOffSimpleAction = ({
9
+ title,
10
+ configuration,
11
+ onPress,
12
+ onPressToggle,
13
+ template,
14
+ }) => {
9
15
  const t = useTranslations();
10
- const { action_on, action_off } = configuration;
11
- const onPressActionOn = () => {
16
+ const { action_on, action_off, text_on, text_off } = configuration;
17
+
18
+ const onPressActionOn = useCallback(() => {
12
19
  onPress &&
13
20
  onPress({
14
21
  ...configuration,
15
- name: t('text_on'),
22
+ name: text_on,
16
23
  action: action_on,
17
24
  action_off: null,
18
25
  template,
26
+ is_toggle: false,
19
27
  });
20
- };
28
+ }, [onPress, configuration, text_on, action_on, template]);
21
29
 
22
- const onPressActionOff = () => {
30
+ const onPressActionOff = useCallback(() => {
23
31
  onPress &&
24
32
  onPress({
25
33
  ...configuration,
26
- name: t('text_off'),
34
+ name: text_off,
27
35
  action: action_off,
28
36
  action_on: null,
29
37
  template,
38
+ is_toggle: false,
30
39
  });
31
- };
40
+ }, [onPress, configuration, text_off, action_off, template]);
41
+
42
+ const onPressActionToggle = useCallback(() => {
43
+ onPressToggle &&
44
+ onPressToggle({
45
+ ...configuration,
46
+ action_on_data: null,
47
+ action_off_data: null,
48
+ template,
49
+ is_toggle: true,
50
+ });
51
+ }, [onPressToggle, configuration, template]);
32
52
 
33
53
  return (
34
54
  <>
@@ -36,16 +56,36 @@ const OnOffSimpleAction = ({ configuration, onPress, template }) => {
36
56
  accessibilityLabel={AccessibilityLabel.ON_OFF_SIMPLE_ACTION_ON}
37
57
  onPress={onPressActionOn}
38
58
  >
39
- <Text type="H4" style={styles.textWithLine}>
40
- {t('text_on')}
59
+ <Text
60
+ type="H4"
61
+ style={styles.textWithLine}
62
+ accessibilityLabel={AccessibilityLabel.ON_OFF_BUTTON_ACTION_TITLE}
63
+ >
64
+ {`${title} - ${text_on}`}
41
65
  </Text>
42
66
  </TouchableOpacity>
43
67
  <TouchableOpacity
44
68
  accessibilityLabel={AccessibilityLabel.ON_OFF_SIMPLE_ACTION_OFF}
45
69
  onPress={onPressActionOff}
46
70
  >
47
- <Text type="H4" style={styles.textWithLine}>
48
- {t('text_off')}
71
+ <Text
72
+ type="H4"
73
+ style={styles.textWithLine}
74
+ accessibilityLabel={AccessibilityLabel.ON_OFF_BUTTON_ACTION_TITLE}
75
+ >
76
+ {`${title} - ${text_off}`}
77
+ </Text>
78
+ </TouchableOpacity>
79
+ <TouchableOpacity
80
+ accessibilityLabel={AccessibilityLabel.ON_OFF_SIMPLE_ACTION_TOGGLE}
81
+ onPress={onPressActionToggle}
82
+ >
83
+ <Text
84
+ type="H4"
85
+ style={styles.textWithLine}
86
+ accessibilityLabel={AccessibilityLabel.ON_OFF_BUTTON_ACTION_TITLE}
87
+ >
88
+ {`${title} - ${t('toggle')}`}
49
89
  </Text>
50
90
  </TouchableOpacity>
51
91
  </>
@@ -1,10 +1,19 @@
1
1
  import React, { useCallback } from 'react';
2
2
  import { TouchableOpacity } from 'react-native';
3
+ import AccessibilityLabel from '../../configs/AccessibilityLabel';
4
+ import { useTranslations } from '../../hooks/Common/useTranslations';
3
5
  import Text from '../Text';
4
6
  import styles from './OnOffSmartLockActionStyles';
5
7
 
6
- const OnOffSmartLockAction = ({ configuration, onPress, template }) => {
7
- const { action_off, action_on, text_off, text_on } = configuration || {};
8
+ const OnOffSmartLockAction = ({
9
+ title,
10
+ configuration,
11
+ onPress,
12
+ onPressToggle,
13
+ template,
14
+ }) => {
15
+ const t = useTranslations();
16
+ const { action_on, action_off, text_on, text_off } = configuration;
8
17
 
9
18
  const onPressActionOpen = useCallback(() => {
10
19
  onPress &&
@@ -14,6 +23,7 @@ const OnOffSmartLockAction = ({ configuration, onPress, template }) => {
14
23
  action: action_on,
15
24
  action_off: null,
16
25
  template,
26
+ is_toggle: false,
17
27
  });
18
28
  }, [onPress, configuration, text_on, action_on, template]);
19
29
 
@@ -25,20 +35,48 @@ const OnOffSmartLockAction = ({ configuration, onPress, template }) => {
25
35
  action: action_off,
26
36
  action_on: null,
27
37
  template,
38
+ is_toggle: false,
28
39
  });
29
40
  }, [onPress, configuration, text_off, action_off, template]);
30
41
 
42
+ const onPressActionToggle = useCallback(() => {
43
+ onPressToggle &&
44
+ onPressToggle({
45
+ ...configuration,
46
+ action_on_data: null,
47
+ action_off_data: null,
48
+ template,
49
+ is_toggle: true,
50
+ });
51
+ }, [onPressToggle, configuration, template]);
52
+
31
53
  return (
32
54
  <>
55
+ <TouchableOpacity onPress={onPressActionOpen}>
56
+ <Text
57
+ type="H4"
58
+ style={styles.textWithLine}
59
+ accessibilityLabel={AccessibilityLabel.ON_OFF_BUTTON_ACTION_TITLE}
60
+ >
61
+ {`${title} - ${text_on}`}
62
+ </Text>
63
+ </TouchableOpacity>
33
64
  <TouchableOpacity onPress={onPressActionClose}>
34
- <Text type="H4" style={styles.textWithLine}>
35
- {text_off}
65
+ <Text
66
+ type="H4"
67
+ style={styles.textWithLine}
68
+ accessibilityLabel={AccessibilityLabel.ON_OFF_BUTTON_ACTION_TITLE}
69
+ >
70
+ {`${title} - ${text_off}`}
36
71
  </Text>
37
72
  </TouchableOpacity>
38
-
39
- <TouchableOpacity onPress={onPressActionOpen}>
40
- <Text type="H4" style={styles.textWithLine}>
41
- {text_on}
73
+ <TouchableOpacity onPress={onPressActionToggle}>
74
+ <Text
75
+ type="H4"
76
+ style={styles.textWithLine}
77
+ accessibilityLabel={AccessibilityLabel.ON_OFF_BUTTON_ACTION_TITLE}
78
+ >
79
+ {`${title} - ${t('toggle')}`}
42
80
  </Text>
43
81
  </TouchableOpacity>
44
82
  </>
@@ -1,11 +1,20 @@
1
1
  import React, { useCallback } from 'react';
2
2
  import { TouchableOpacity } from 'react-native';
3
3
  import AccessibilityLabel from '../../configs/AccessibilityLabel';
4
+ import { useTranslations } from '../../hooks/Common/useTranslations';
4
5
  import Text from '../Text';
5
6
  import styles from './OnOffButtonActionStyles';
6
7
 
7
- const SwitchButtonAction = ({ title, configuration, onPress, template }) => {
8
- const { text_on, text_off, action_on, action_off } = configuration;
8
+ const SwitchButtonAction = ({
9
+ title,
10
+ configuration,
11
+ onPress,
12
+ onPressToggle,
13
+ template,
14
+ }) => {
15
+ const t = useTranslations();
16
+ const { action_on, action_off, text_on, text_off } = configuration;
17
+
9
18
  const onPressActionOn = useCallback(() => {
10
19
  onPress &&
11
20
  onPress({
@@ -14,6 +23,7 @@ const SwitchButtonAction = ({ title, configuration, onPress, template }) => {
14
23
  action: action_on,
15
24
  action_off: null,
16
25
  template,
26
+ is_toggle: false,
17
27
  });
18
28
  }, [onPress, configuration, text_on, action_on, template]);
19
29
 
@@ -25,9 +35,21 @@ const SwitchButtonAction = ({ title, configuration, onPress, template }) => {
25
35
  action: action_off,
26
36
  action_on: null,
27
37
  template,
38
+ is_toggle: false,
28
39
  });
29
40
  }, [onPress, configuration, text_off, action_off, template]);
30
41
 
42
+ const onPressActionToggle = useCallback(() => {
43
+ onPressToggle &&
44
+ onPressToggle({
45
+ ...configuration,
46
+ action_on_data: null,
47
+ action_off_data: null,
48
+ template,
49
+ is_toggle: true,
50
+ });
51
+ }, [onPressToggle, configuration, template]);
52
+
31
53
  return (
32
54
  <>
33
55
  <TouchableOpacity onPress={onPressActionOn}>
@@ -36,7 +58,7 @@ const SwitchButtonAction = ({ title, configuration, onPress, template }) => {
36
58
  style={styles.textWithLine}
37
59
  accessibilityLabel={AccessibilityLabel.ON_OFF_BUTTON_ACTION_TITLE}
38
60
  >
39
- {title} {text_on}
61
+ {`${title} - ${text_on}`}
40
62
  </Text>
41
63
  </TouchableOpacity>
42
64
  <TouchableOpacity onPress={onPressActionOff}>
@@ -45,7 +67,16 @@ const SwitchButtonAction = ({ title, configuration, onPress, template }) => {
45
67
  style={styles.textWithLine}
46
68
  accessibilityLabel={AccessibilityLabel.ON_OFF_BUTTON_ACTION_TITLE}
47
69
  >
48
- {title} {text_off}
70
+ {`${title} - ${text_off}`}
71
+ </Text>
72
+ </TouchableOpacity>
73
+ <TouchableOpacity onPress={onPressActionToggle}>
74
+ <Text
75
+ type="H4"
76
+ style={styles.textWithLine}
77
+ accessibilityLabel={AccessibilityLabel.ON_OFF_BUTTON_ACTION_TITLE}
78
+ >
79
+ {`${title} - ${t('toggle')}`}
49
80
  </Text>
50
81
  </TouchableOpacity>
51
82
  </>
@@ -2,6 +2,7 @@ import React, { useCallback } from 'react';
2
2
  import { TouchableOpacity } from 'react-native';
3
3
  import Text from '../Text';
4
4
  import styles from './ThreeButtonActionStyles';
5
+ import AccessibilityLabel from '../../configs/AccessibilityLabel';
5
6
 
6
7
  const ThreeButtonAction = ({ configuration, onPress, template }) => {
7
8
  const { text1, text2, text3, action1, action2, action3 } = configuration;
@@ -34,19 +35,28 @@ const ThreeButtonAction = ({ configuration, onPress, template }) => {
34
35
 
35
36
  return (
36
37
  <>
37
- <TouchableOpacity onPress={onPressAction1}>
38
+ <TouchableOpacity
39
+ onPress={onPressAction1}
40
+ accessibilityLabel={AccessibilityLabel.BUTTON_TEMPLATE_1}
41
+ >
38
42
  <Text type="H4" style={styles.textWithLine}>
39
43
  {text1}
40
44
  </Text>
41
45
  </TouchableOpacity>
42
46
 
43
- <TouchableOpacity onPress={onPressAction2}>
47
+ <TouchableOpacity
48
+ onPress={onPressAction2}
49
+ accessibilityLabel={AccessibilityLabel.BUTTON_TEMPLATE_2}
50
+ >
44
51
  <Text type="H4" style={styles.textWithLine}>
45
52
  {text2}
46
53
  </Text>
47
54
  </TouchableOpacity>
48
55
 
49
- <TouchableOpacity onPress={onPressAction3}>
56
+ <TouchableOpacity
57
+ onPress={onPressAction3}
58
+ accessibilityLabel={AccessibilityLabel.BUTTON_TEMPLATE_3}
59
+ >
50
60
  <Text type="H4" style={styles.textWithLine}>
51
61
  {text3}
52
62
  </Text>
@@ -8,11 +8,12 @@ import { mockSCStore } from '../../../context/mockStore';
8
8
  import Text from '../../Text';
9
9
  import AccessibilityLabel from '../../../configs/AccessibilityLabel';
10
10
 
11
- const wrapComponent = (configuration, onPress) => (
11
+ const wrapComponent = (configuration, onPress, onPressToggle) => (
12
12
  <SCProvider initState={mockSCStore({})}>
13
13
  <OnOffButtonAction
14
14
  configuration={configuration}
15
15
  onPress={onPress}
16
+ onPressToggle={onPressToggle}
16
17
  title={'Cong tac 1'}
17
18
  template={'on_off_button_action_template'}
18
19
  />
@@ -30,26 +31,64 @@ describe('Test OnOffButtonAction', () => {
30
31
  action_on: '94600cbe-2035-47d5-bd43-89ace5d59796',
31
32
  };
32
33
  const mockFuntion = jest.fn();
34
+ const mockToggle = jest.fn();
33
35
  await act(async () => {
34
- tree = await renderer.create(wrapComponent(configuration, mockFuntion));
36
+ tree = await renderer.create(
37
+ wrapComponent(configuration, mockFuntion, mockToggle)
38
+ );
35
39
  });
36
40
  const instance = tree.root;
37
41
  const touchOpacity = instance.findAllByType(TouchableOpacity);
38
42
 
39
- expect(touchOpacity).toHaveLength(2);
43
+ expect(touchOpacity).toHaveLength(3);
40
44
  await act(async () => {
41
45
  touchOpacity[0].props.onPress();
46
+ });
47
+ expect(mockFuntion).toHaveBeenCalledWith({
48
+ ...configuration,
49
+ name: configuration.text_on,
50
+ action: configuration.action_on,
51
+ action_off: null,
52
+ template: 'on_off_button_action_template',
53
+ is_toggle: false,
54
+ });
55
+ expect(mockToggle).not.toHaveBeenCalled();
56
+
57
+ mockFuntion.mockClear();
58
+ await act(async () => {
42
59
  touchOpacity[1].props.onPress();
43
60
  });
44
- expect(mockFuntion).toHaveBeenCalled();
61
+ expect(mockFuntion).toHaveBeenCalledWith({
62
+ ...configuration,
63
+ name: configuration.text_off,
64
+ action: configuration.action_off,
65
+ action_on: null,
66
+ template: 'on_off_button_action_template',
67
+ is_toggle: false,
68
+ });
69
+ expect(mockToggle).not.toHaveBeenCalled();
70
+
71
+ mockFuntion.mockClear();
72
+ await act(async () => {
73
+ touchOpacity[2].props.onPress();
74
+ });
75
+ expect(mockFuntion).not.toHaveBeenCalled();
76
+ expect(mockToggle).toHaveBeenCalledWith({
77
+ ...configuration,
78
+ action_on_data: null,
79
+ action_off_data: null,
80
+ template: 'on_off_button_action_template',
81
+ is_toggle: true,
82
+ });
45
83
 
46
84
  const textTitle = instance.findAll(
47
85
  (el) =>
48
86
  el.props.accessibilityLabel ===
49
87
  AccessibilityLabel.ON_OFF_BUTTON_ACTION_TITLE && el.type === Text
50
88
  );
51
- expect(textTitle).toHaveLength(2);
52
- expect(textTitle[0].props.children).toEqual(['Cong tac 1', ' ', 'On']);
53
- expect(textTitle[1].props.children).toEqual(['Cong tac 1', ' ', 'Off']);
89
+ expect(textTitle).toHaveLength(3);
90
+ expect(textTitle[0].props.children).toEqual('Cong tac 1 - On');
91
+ expect(textTitle[1].props.children).toEqual('Cong tac 1 - Off');
92
+ expect(textTitle[2].props.children).toEqual('Cong tac 1 - Toggle');
54
93
  });
55
94
  });
@@ -5,10 +5,18 @@ import { TouchableOpacity } from 'react-native';
5
5
  import OnOffSimpleAction from '../OnOffSimpleAction';
6
6
  import { SCProvider } from '../../../context';
7
7
  import { mockSCStore } from '../../../context/mockStore';
8
+ import Text from '../../Text';
9
+ import AccessibilityLabel from '../../../configs/AccessibilityLabel';
8
10
 
9
- const wrapComponent = (configuration, onPress) => (
11
+ const wrapComponent = (configuration, onPress, onPressToggle) => (
10
12
  <SCProvider initState={mockSCStore({})}>
11
- <OnOffSimpleAction configuration={configuration} onPress={onPress} />
13
+ <OnOffSimpleAction
14
+ configuration={configuration}
15
+ onPress={onPress}
16
+ onPressToggle={onPressToggle}
17
+ title={'Cong tac 1'}
18
+ template={'OnOffSimpleActionTemplate'}
19
+ />
12
20
  </SCProvider>
13
21
  );
14
22
 
@@ -16,19 +24,71 @@ describe('Test OnOffSimpleAction', () => {
16
24
  let tree;
17
25
 
18
26
  it('test onPress', async () => {
19
- const configuration = {};
27
+ const configuration = {
28
+ text_on: 'On',
29
+ text_off: 'Off',
30
+ action_off: 'f49e1577-493d-4bae-a9ab-3b0f96a4ec52',
31
+ action_on: '94600cbe-2035-47d5-bd43-89ace5d59796',
32
+ };
20
33
  const mockFuntion = jest.fn();
34
+ const mockToggle = jest.fn();
21
35
  await act(async () => {
22
- tree = await renderer.create(wrapComponent(configuration, mockFuntion));
36
+ tree = await renderer.create(
37
+ wrapComponent(configuration, mockFuntion, mockToggle)
38
+ );
23
39
  });
24
40
  const instance = tree.root;
25
41
  const touchOpacity = instance.findAllByType(TouchableOpacity);
26
42
 
27
- expect(touchOpacity).toHaveLength(2);
43
+ expect(touchOpacity).toHaveLength(3);
28
44
  await act(async () => {
29
45
  touchOpacity[0].props.onPress();
46
+ });
47
+ expect(mockFuntion).toHaveBeenCalledWith({
48
+ ...configuration,
49
+ name: configuration.text_on,
50
+ action: configuration.action_on,
51
+ action_off: null,
52
+ template: 'OnOffSimpleActionTemplate',
53
+ is_toggle: false,
54
+ });
55
+ expect(mockToggle).not.toHaveBeenCalled();
56
+
57
+ mockFuntion.mockClear();
58
+ await act(async () => {
30
59
  touchOpacity[1].props.onPress();
31
60
  });
32
- expect(mockFuntion).toHaveBeenCalled();
61
+ expect(mockFuntion).toHaveBeenCalledWith({
62
+ ...configuration,
63
+ name: configuration.text_off,
64
+ action: configuration.action_off,
65
+ action_on: null,
66
+ template: 'OnOffSimpleActionTemplate',
67
+ is_toggle: false,
68
+ });
69
+ expect(mockToggle).not.toHaveBeenCalled();
70
+
71
+ mockFuntion.mockClear();
72
+ await act(async () => {
73
+ touchOpacity[2].props.onPress();
74
+ });
75
+ expect(mockFuntion).not.toHaveBeenCalled();
76
+ expect(mockToggle).toHaveBeenCalledWith({
77
+ ...configuration,
78
+ action_on_data: null,
79
+ action_off_data: null,
80
+ template: 'OnOffSimpleActionTemplate',
81
+ is_toggle: true,
82
+ });
83
+
84
+ const textTitle = instance.findAll(
85
+ (el) =>
86
+ el.props.accessibilityLabel ===
87
+ AccessibilityLabel.ON_OFF_BUTTON_ACTION_TITLE && el.type === Text
88
+ );
89
+ expect(textTitle).toHaveLength(3);
90
+ expect(textTitle[0].props.children).toEqual('Cong tac 1 - On');
91
+ expect(textTitle[1].props.children).toEqual('Cong tac 1 - Off');
92
+ expect(textTitle[2].props.children).toEqual('Cong tac 1 - Toggle');
33
93
  });
34
94
  });