@pingux/astro 2.32.0-alpha.1 → 2.32.0-alpha.11

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 (143) hide show
  1. package/lib/cjs/components/AccordionGroup/AccordionGroup.stories.js +1 -1
  2. package/lib/cjs/components/Badge/Badge.stories.js +1 -1
  3. package/lib/cjs/components/Badge/Convenience/ConvenienceBadges.stories.js +1 -1
  4. package/lib/cjs/components/Bracket/Bracket.stories.js +1 -1
  5. package/lib/cjs/components/Breadcrumbs/Breadcrumbs.stories.js +1 -1
  6. package/lib/cjs/components/Button/Button.stories.d.ts +1 -1
  7. package/lib/cjs/components/Button/Button.stories.js +1 -1
  8. package/lib/cjs/components/Calendar/Calendar.stories.js +1 -1
  9. package/lib/cjs/components/Calendar/Calendar.test.js +9 -32
  10. package/lib/cjs/components/Callout/Callout.stories.js +1 -1
  11. package/lib/cjs/components/Card/Card.stories.js +1 -1
  12. package/lib/cjs/components/CodeView/CodeView.stories.js +1 -1
  13. package/lib/cjs/components/CollapsiblePanel/CollapsiblePanel.stories.js +1 -1
  14. package/lib/cjs/components/CopyText/CopyText.stories.js +1 -1
  15. package/lib/cjs/components/HelpHint/HelpHint.stories.js +1 -1
  16. package/lib/cjs/components/Icon/Icon.stories.js +1 -1
  17. package/lib/cjs/components/IconBadge/IconBadge.stories.js +1 -1
  18. package/lib/cjs/components/IconButton/IconButton.stories.js +1 -1
  19. package/lib/cjs/components/ImageUploadField/ImageUploadField.test.js +47 -14
  20. package/lib/cjs/components/Label/Label.test.js +10 -7
  21. package/lib/cjs/components/Link/Link.stories.js +1 -1
  22. package/lib/cjs/components/Loader/Loader.stories.js +1 -1
  23. package/lib/cjs/components/Menu/Menu.stories.js +1 -1
  24. package/lib/cjs/components/Messages/Messages.js +42 -9
  25. package/lib/cjs/components/Messages/Messages.stories.js +1 -1
  26. package/lib/cjs/components/Messages/Messages.test.js +7 -4
  27. package/lib/cjs/components/Modal/Modal.stories.js +1 -1
  28. package/lib/cjs/components/NavBar/NavBar.stories.js +1 -1
  29. package/lib/cjs/components/OverlayPanel/OverlayPanel.stories.js +3 -17
  30. package/lib/cjs/components/PanelHeader/PanelHeader.stories.js +1 -1
  31. package/lib/cjs/components/PanelHeader/PanelHeader.test.js +7 -3
  32. package/lib/cjs/components/PopoverMenu/PopoverMenu.stories.js +1 -1
  33. package/lib/cjs/components/RequirementsList/RequirementsList.stories.js +1 -1
  34. package/lib/cjs/components/ScrollBox/ScrollBox.stories.js +1 -1
  35. package/lib/cjs/components/Separator/Separator.stories.js +1 -1
  36. package/lib/cjs/components/Stepper/Stepper.stories.js +1 -1
  37. package/lib/cjs/components/TreeView/TreeView.js +99 -11
  38. package/lib/cjs/components/TreeView/TreeView.stories.js +23 -10
  39. package/lib/cjs/components/TreeView/TreeView.styles.js +22 -2
  40. package/lib/cjs/components/TreeView/TreeView.test.js +91 -11
  41. package/lib/cjs/components/TreeView/TreeViewItem.js +112 -14
  42. package/lib/cjs/components/TreeView/TreeViewKeyboardDelegate.js +200 -0
  43. package/lib/cjs/components/TreeView/TreeViewKeyboardDelegate.test.js +511 -0
  44. package/lib/cjs/components/TreeView/TreeViewRow.js +20 -5
  45. package/lib/cjs/components/TreeView/TreeViewSection.js +164 -16
  46. package/lib/cjs/components/TreeView/TreeViewWrapper.js +40 -0
  47. package/lib/cjs/hooks/useComponentToggle/index.d.ts +1 -0
  48. package/lib/cjs/hooks/useComponentToggle/useComponentToggle.d.ts +32 -0
  49. package/lib/cjs/hooks/useComponentToggle/useComponentToggle.js +4 -20
  50. package/lib/cjs/hooks/useComponentToggle/useComponentToggle.test.d.ts +1 -0
  51. package/lib/cjs/hooks/useComponentToggle/useComponentToggle.test.js +8 -9
  52. package/lib/cjs/hooks/useFallbackImage/index.d.ts +1 -0
  53. package/lib/cjs/hooks/useFallbackImage/useFallbackImage.d.ts +10 -0
  54. package/lib/cjs/hooks/useFallbackImage/useFallbackImage.js +1 -2
  55. package/lib/cjs/hooks/useFallbackImage/useFallbackImage.test.d.ts +1 -0
  56. package/lib/cjs/hooks/useFallbackImage/useFallbackImage.test.js +9 -9
  57. package/lib/cjs/hooks/useImageUploadState/index.d.ts +1 -0
  58. package/lib/cjs/hooks/useImageUploadState/useImageUploadState.d.ts +28 -0
  59. package/lib/cjs/hooks/useImageUploadState/useImageUploadState.js +9 -6
  60. package/lib/cjs/hooks/useModalState/index.d.ts +1 -0
  61. package/lib/cjs/hooks/useModalState/useModalState.d.ts +21 -0
  62. package/lib/cjs/hooks/useModalState/useModalState.js +0 -9
  63. package/lib/cjs/hooks/useModalState/useModalState.test.d.ts +1 -0
  64. package/lib/cjs/recipes/AttributeMapping.stories.js +1 -1
  65. package/lib/cjs/recipes/ConditionFilter.stories.js +1 -1
  66. package/lib/cjs/recipes/MaskedValue.stories.js +1 -1
  67. package/lib/cjs/recipes/MultipagePopup.stories.js +1 -1
  68. package/lib/cjs/recipes/OneWayToBidirectionalArrow.stories.js +1 -1
  69. package/lib/cjs/recipes/PanelContent.stories.js +1 -1
  70. package/lib/cjs/recipes/Slider.stories.js +1 -1
  71. package/lib/cjs/recipes/TrialExperienceIndustryButtons.stories.js +1 -1
  72. package/lib/cjs/recipes/TrialExperienceStatusBar.stories.js +1 -1
  73. package/lib/cjs/utils/designUtils/figmaLinks.d.ts +7 -0
  74. package/lib/cjs/utils/testUtils/setupTests.d.ts +4 -0
  75. package/lib/cjs/utils/testUtils/testAxe.d.ts +2 -0
  76. package/lib/cjs/utils/testUtils/testTheme.d.ts +21 -0
  77. package/lib/cjs/utils/testUtils/testWrapper.d.ts +5 -0
  78. package/lib/cjs/utils/testUtils/testWrapper.js +3 -2
  79. package/lib/cjs/utils/testUtils/universalComponentTest.d.ts +5 -0
  80. package/lib/cjs/utils/testUtils/universalComponentTest.js +86 -0
  81. package/lib/components/AccordionGroup/AccordionGroup.stories.js +1 -1
  82. package/lib/components/Badge/Badge.stories.js +1 -1
  83. package/lib/components/Badge/Convenience/ConvenienceBadges.stories.js +1 -1
  84. package/lib/components/Bracket/Bracket.stories.js +1 -1
  85. package/lib/components/Breadcrumbs/Breadcrumbs.stories.js +1 -1
  86. package/lib/components/Button/Button.stories.js +1 -1
  87. package/lib/components/Calendar/Calendar.stories.js +1 -1
  88. package/lib/components/Calendar/Calendar.test.js +9 -32
  89. package/lib/components/Callout/Callout.stories.js +1 -1
  90. package/lib/components/Card/Card.stories.js +1 -1
  91. package/lib/components/CodeView/CodeView.stories.js +1 -1
  92. package/lib/components/CollapsiblePanel/CollapsiblePanel.stories.js +1 -1
  93. package/lib/components/CopyText/CopyText.stories.js +1 -1
  94. package/lib/components/HelpHint/HelpHint.stories.js +1 -1
  95. package/lib/components/Icon/Icon.stories.js +1 -1
  96. package/lib/components/IconBadge/IconBadge.stories.js +1 -1
  97. package/lib/components/IconButton/IconButton.stories.js +1 -1
  98. package/lib/components/ImageUploadField/ImageUploadField.test.js +47 -14
  99. package/lib/components/Label/Label.test.js +8 -5
  100. package/lib/components/Link/Link.stories.js +1 -1
  101. package/lib/components/Loader/Loader.stories.js +1 -1
  102. package/lib/components/Menu/Menu.stories.js +1 -1
  103. package/lib/components/Messages/Messages.js +47 -15
  104. package/lib/components/Messages/Messages.stories.js +1 -1
  105. package/lib/components/Messages/Messages.test.js +7 -4
  106. package/lib/components/Modal/Modal.stories.js +1 -1
  107. package/lib/components/NavBar/NavBar.stories.js +1 -1
  108. package/lib/components/OverlayPanel/OverlayPanel.stories.js +4 -18
  109. package/lib/components/PanelHeader/PanelHeader.stories.js +1 -1
  110. package/lib/components/PanelHeader/PanelHeader.test.js +7 -3
  111. package/lib/components/PopoverMenu/PopoverMenu.stories.js +1 -1
  112. package/lib/components/RequirementsList/RequirementsList.stories.js +1 -1
  113. package/lib/components/ScrollBox/ScrollBox.stories.js +1 -1
  114. package/lib/components/Separator/Separator.stories.js +1 -1
  115. package/lib/components/Stepper/Stepper.stories.js +1 -1
  116. package/lib/components/TreeView/TreeView.js +100 -12
  117. package/lib/components/TreeView/TreeView.stories.js +23 -10
  118. package/lib/components/TreeView/TreeView.styles.js +22 -2
  119. package/lib/components/TreeView/TreeView.test.js +92 -12
  120. package/lib/components/TreeView/TreeViewItem.js +111 -14
  121. package/lib/components/TreeView/TreeViewKeyboardDelegate.js +176 -0
  122. package/lib/components/TreeView/TreeViewKeyboardDelegate.test.js +496 -0
  123. package/lib/components/TreeView/TreeViewRow.js +20 -5
  124. package/lib/components/TreeView/TreeViewSection.js +161 -16
  125. package/lib/components/TreeView/TreeViewWrapper.js +31 -0
  126. package/lib/hooks/useComponentToggle/useComponentToggle.js +4 -21
  127. package/lib/hooks/useComponentToggle/useComponentToggle.test.js +8 -9
  128. package/lib/hooks/useFallbackImage/useFallbackImage.js +1 -2
  129. package/lib/hooks/useFallbackImage/useFallbackImage.test.js +6 -6
  130. package/lib/hooks/useImageUploadState/useImageUploadState.js +9 -6
  131. package/lib/hooks/useModalState/useModalState.js +0 -10
  132. package/lib/recipes/AttributeMapping.stories.js +1 -1
  133. package/lib/recipes/ConditionFilter.stories.js +1 -1
  134. package/lib/recipes/MaskedValue.stories.js +1 -1
  135. package/lib/recipes/MultipagePopup.stories.js +1 -1
  136. package/lib/recipes/OneWayToBidirectionalArrow.stories.js +1 -1
  137. package/lib/recipes/PanelContent.stories.js +1 -1
  138. package/lib/recipes/Slider.stories.js +1 -1
  139. package/lib/recipes/TrialExperienceIndustryButtons.stories.js +1 -1
  140. package/lib/recipes/TrialExperienceStatusBar.stories.js +1 -1
  141. package/lib/utils/testUtils/testWrapper.js +3 -2
  142. package/lib/utils/testUtils/universalComponentTest.js +74 -0
  143. package/package.json +5 -1
@@ -0,0 +1,176 @@
1
+ import _findInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/find";
2
+ import _findIndexInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/find-index";
3
+ var focusPrevious = function focusPrevious(index, refArray, flatKeyList) {
4
+ if (index !== 0) {
5
+ var key = flatKeyList[index - 1].key;
6
+ var _refArray$find = _findInstanceProperty(refArray).call(refArray, function (item) {
7
+ return item.key === key;
8
+ }),
9
+ thisRef = _refArray$find.thisRef;
10
+ thisRef.current.focus();
11
+ }
12
+ };
13
+ var focusNext = function focusNext(index, refArray, flatKeyList) {
14
+ if (index !== flatKeyList.length - 1) {
15
+ var key = flatKeyList[index + 1].key;
16
+ var _refArray$find2 = _findInstanceProperty(refArray).call(refArray, function (item) {
17
+ return item.key === key;
18
+ }),
19
+ thisRef = _refArray$find2.thisRef;
20
+ thisRef.current.focus();
21
+ }
22
+ };
23
+ export var verifyIndex = function verifyIndex(thisIndex, interval, length) {
24
+ var newIndex = thisIndex + interval;
25
+ if (newIndex < 0) {
26
+ return 0;
27
+ }
28
+ if (newIndex >= length) {
29
+ return length - 1;
30
+ }
31
+ return newIndex;
32
+ };
33
+ export var onHomePress = function onHomePress(key, flatKeyArray, refArray) {
34
+ var _thisRef$current;
35
+ var firstKey = flatKeyArray[0];
36
+ if (firstKey.key === key) {
37
+ return;
38
+ }
39
+ var _refArray$find3 = _findInstanceProperty(refArray).call(refArray, function (_item) {
40
+ return _item.key === firstKey.key;
41
+ }),
42
+ thisRef = _refArray$find3.thisRef;
43
+ (_thisRef$current = thisRef.current) === null || _thisRef$current === void 0 ? void 0 : _thisRef$current.focus();
44
+ };
45
+ export var onEndPress = function onEndPress(key, flatKeyArray, refArray) {
46
+ var _thisRef$current2;
47
+ var lastKey = flatKeyArray[flatKeyArray.length - 1];
48
+ if (lastKey.key === key) {
49
+ return;
50
+ }
51
+ var _refArray$find4 = _findInstanceProperty(refArray).call(refArray, function (_item) {
52
+ return _item.key === lastKey.key;
53
+ }),
54
+ thisRef = _refArray$find4.thisRef;
55
+ (_thisRef$current2 = thisRef.current) === null || _thisRef$current2 === void 0 ? void 0 : _thisRef$current2.focus();
56
+ };
57
+ export var pageUpOrDown = function pageUpOrDown(key, flatKeyArray, refArray, pageLength) {
58
+ var _thisRef$current3;
59
+ var thisIndex = _findIndexInstanceProperty(flatKeyArray).call(flatKeyArray, function (item) {
60
+ return item.key === key;
61
+ });
62
+ var newIndex = verifyIndex(thisIndex, pageLength, flatKeyArray.length);
63
+ var foundKey = flatKeyArray[newIndex].key;
64
+ var _refArray$find5 = _findInstanceProperty(refArray).call(refArray, function (_item) {
65
+ return _item.key === foundKey;
66
+ }),
67
+ thisRef = _refArray$find5.thisRef;
68
+ (_thisRef$current3 = thisRef.current) === null || _thisRef$current3 === void 0 ? void 0 : _thisRef$current3.focus();
69
+ };
70
+ export var onEnterPress = function onEnterPress(e, state, key) {
71
+ state.toggleKey(key);
72
+ e.preventDefault();
73
+ e.stopPropagation();
74
+ };
75
+ export var onLeftPress = function onLeftPress(e, focusManager, state, key, isExpanded, refArray) {
76
+ var isEventTargetAKey = _findInstanceProperty(refArray).call(refArray, function (_item) {
77
+ return _item.thisRef.current === e.target;
78
+ });
79
+ if (isExpanded && isEventTargetAKey) {
80
+ state.toggleKey(key);
81
+ }
82
+ if (isExpanded && !isEventTargetAKey) {
83
+ focusManager.focusPrevious();
84
+ }
85
+ e.preventDefault();
86
+ e.stopPropagation();
87
+ };
88
+ export var onSpacePress = function onSpacePress(e, tree, key, isSelected) {
89
+ if (isSelected) {
90
+ tree.setSelectedKeys([]);
91
+ } else {
92
+ tree.setSelectedKeys([key]);
93
+ }
94
+ e.preventDefault();
95
+ e.stopPropagation();
96
+ };
97
+ export var onUpPress = function onUpPress(e, key, refArray, flatKeyList) {
98
+ var foundIndex = _findIndexInstanceProperty(flatKeyList).call(flatKeyList, function (item) {
99
+ return item.key === key;
100
+ });
101
+ focusPrevious(foundIndex, refArray, flatKeyList);
102
+ e.preventDefault();
103
+ e.stopPropagation();
104
+ };
105
+ export var onTabPress = function onTabPress(e, refArray, focusManager, isSection) {
106
+ var isEventTargetAKey = _findInstanceProperty(refArray).call(refArray, function (_item) {
107
+ return _item.thisRef.current === e.target;
108
+ });
109
+ if (isEventTargetAKey && isSection) {
110
+ focusManager.focusNext();
111
+ e.preventDefault();
112
+ e.stopPropagation();
113
+ }
114
+ };
115
+ export var onRightPress = function onRightPress(e, focusManager, state, key, isExpanded, refArray) {
116
+ if (!isExpanded) {
117
+ state.toggleKey(key);
118
+ return;
119
+ }
120
+ var isEventTargetAKey = _findInstanceProperty(refArray).call(refArray, function (_item) {
121
+ return _item.thisRef.current === e.target;
122
+ });
123
+ if (isExpanded && isEventTargetAKey) {
124
+ focusManager.focusNext();
125
+ }
126
+ e.preventDefault();
127
+ e.stopPropagation();
128
+ };
129
+ export var onDownPress = function onDownPress(e, key, refArray, flatKeyList) {
130
+ // find the key
131
+ var foundIndex = _findIndexInstanceProperty(flatKeyList).call(flatKeyList, function (item) {
132
+ return item.key === key;
133
+ });
134
+ focusNext(foundIndex, refArray, flatKeyList);
135
+ // check if first or last
136
+ e.preventDefault();
137
+ e.stopPropagation();
138
+ };
139
+ export var onRightLeftItemPress = function onRightLeftItemPress(e) {
140
+ e.preventDefault();
141
+ e.stopPropagation();
142
+ };
143
+ export var onPageUpPress = function onPageUpPress(e, key, flatKeyArray, refArray, pageLength) {
144
+ pageUpOrDown(key, flatKeyArray, refArray, -Math.abs(pageLength));
145
+ e.preventDefault();
146
+ e.stopPropagation();
147
+ };
148
+ export var onPageDownPress = function onPageDownPress(e, key, flatKeyArray, refArray, pageLength) {
149
+ pageUpOrDown(key, flatKeyArray, refArray, Math.abs(pageLength));
150
+ e.preventDefault();
151
+ e.stopPropagation();
152
+ };
153
+ export var sectionPressHandlers = {
154
+ onEnterPress: onEnterPress,
155
+ onSpacePress: onSpacePress,
156
+ onLeftPress: onLeftPress,
157
+ onRightPress: onRightPress,
158
+ onUpPress: onUpPress,
159
+ onDownPress: onDownPress,
160
+ onTabPress: onTabPress,
161
+ onPageUpPress: onPageUpPress,
162
+ onPageDownPress: onPageDownPress,
163
+ onHomePress: onHomePress,
164
+ onEndPress: onEndPress
165
+ };
166
+ export var itemPressHandlers = {
167
+ onSpacePress: onSpacePress,
168
+ onDownPress: onDownPress,
169
+ onUpPress: onUpPress,
170
+ onRightLeftItemPress: onRightLeftItemPress,
171
+ onTabPress: onTabPress,
172
+ onPageUpPress: onPageUpPress,
173
+ onPageDownPress: onPageDownPress,
174
+ onHomePress: onHomePress,
175
+ onEndPress: onEndPress
176
+ };
@@ -0,0 +1,496 @@
1
+ import _extends from "@babel/runtime-corejs3/helpers/esm/extends";
2
+ import _concatInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/concat";
3
+ import React, { useRef } from 'react';
4
+ import PropTypes from 'prop-types';
5
+ import { isIterableProp } from '../../utils/devUtils/props/isIterable';
6
+ import { fireEvent, render, screen } from '../../utils/testUtils/testWrapper';
7
+ import { onKeyDownItem } from './TreeViewItem';
8
+ import { onLeftPress } from './TreeViewKeyboardDelegate';
9
+ import { onKeyDownSection } from './TreeViewSection';
10
+ import { jsx as ___EmotionJSX } from "@emotion/react";
11
+ var testId = 'test-keyboard-tree';
12
+ var toggleKey = jest.fn();
13
+ var setSelectedKeys = jest.fn();
14
+ var focusPrevious = jest.fn();
15
+ var focusNext = jest.fn();
16
+ var refFocus = jest.fn();
17
+ var state = {
18
+ toggleKey: toggleKey
19
+ };
20
+ var tree = {
21
+ setSelectedKeys: setSelectedKeys
22
+ };
23
+ var focusManager = {
24
+ focusPrevious: focusPrevious,
25
+ focusNext: focusNext
26
+ };
27
+ export var refArray = [{
28
+ key: 'testprior',
29
+ thisRef: {
30
+ current: {
31
+ focus: refFocus
32
+ }
33
+ }
34
+ }, {
35
+ key: 'test',
36
+ thisRef: {
37
+ current: {
38
+ focus: refFocus
39
+ }
40
+ }
41
+ }, {
42
+ key: 'testsecond',
43
+ thisRef: {
44
+ current: {
45
+ focus: refFocus
46
+ }
47
+ }
48
+ }];
49
+ export var flatKeyArray = [{
50
+ key: 'testprior'
51
+ }, {
52
+ key: 'test'
53
+ }, {
54
+ key: 'testsecond'
55
+ }];
56
+ var defaultProps = {
57
+ 'data-testid': testId,
58
+ focusManager: focusManager,
59
+ state: state,
60
+ tree: tree,
61
+ key: 'test',
62
+ flatKeyArray: flatKeyArray,
63
+ refArray: refArray
64
+ };
65
+ var TestComponent = function TestComponent(props) {
66
+ var focusManagerProp = props.focusManager,
67
+ stateProp = props.state,
68
+ treeProp = props.tree,
69
+ isSelected = props.isSelected,
70
+ isExpanded = props.isExpanded,
71
+ _props$isInRefArray = props.isInRefArray,
72
+ isInRefArray = _props$isInRefArray === void 0 ? true : _props$isInRefArray,
73
+ flatKeyArrayProp = props.flatKeyArray,
74
+ refArrayProp = props.refArray;
75
+ var thisRef = useRef(null);
76
+ var testOnKeyDown = function testOnKeyDown(e) {
77
+ props.onKeyDown(e, stateProp, 'test', treeProp, isSelected, isExpanded, focusManagerProp, flatKeyArrayProp, refArrayProp, 5, true);
78
+ };
79
+ var testOnKeyDownAddRef = function testOnKeyDownAddRef(e) {
80
+ var _context;
81
+ props.onKeyDown(e, stateProp, 'test', treeProp, isSelected, isExpanded, focusManagerProp, flatKeyArrayProp, _concatInstanceProperty(_context = []).call(_context, refArrayProp, [{
82
+ key: 'button',
83
+ thisRef: thisRef
84
+ }]), 5, true);
85
+ };
86
+ return ___EmotionJSX("div", null, ___EmotionJSX("button", {
87
+ ref: thisRef,
88
+ onKeyDown: function onKeyDown(e) {
89
+ return isInRefArray ? testOnKeyDownAddRef(e) : testOnKeyDown(e);
90
+ }
91
+ }, "let us test keypresses"));
92
+ };
93
+ TestComponent.propTypes = {
94
+ isInRefArray: PropTypes.bool,
95
+ isEventTargetAKey: PropTypes.bool,
96
+ state: PropTypes.shape({
97
+ toggleKey: PropTypes.func
98
+ }),
99
+ tree: PropTypes.shape({
100
+ setSelectedKeys: PropTypes.func
101
+ }),
102
+ focusManager: PropTypes.shape({
103
+ focusPrevious: PropTypes.func,
104
+ focusNext: PropTypes.func
105
+ }),
106
+ isExpanded: PropTypes.bool,
107
+ isSelected: PropTypes.bool,
108
+ onKeyDown: PropTypes.func,
109
+ flatKeyArray: isIterableProp,
110
+ refArray: isIterableProp
111
+ };
112
+ var getComponent = function getComponent() {
113
+ var props = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
114
+ return render(___EmotionJSX(TestComponent, _extends({}, defaultProps, props)));
115
+ };
116
+ afterEach(function () {
117
+ jest.clearAllMocks();
118
+ });
119
+ afterAll(function () {
120
+ jest.restoreAllMocks();
121
+ });
122
+ test('OnEnterPress calls when enter is pressed', function () {
123
+ getComponent({
124
+ onKeyDown: onKeyDownSection
125
+ });
126
+ var button = screen.getByRole('button');
127
+ fireEvent.keyDown(button, {
128
+ key: 'Enter',
129
+ keyCode: 13
130
+ });
131
+ fireEvent.keyUp(button, {
132
+ key: 'Enter',
133
+ keyCode: 13
134
+ });
135
+ expect(toggleKey).toHaveBeenCalled();
136
+ });
137
+ test('onSpacePress calls when space is pressed', function () {
138
+ getComponent({
139
+ onKeyDown: onKeyDownSection
140
+ });
141
+ var button = screen.getByRole('button');
142
+ fireEvent.keyDown(button, {
143
+ key: 'Space',
144
+ keyCode: 32
145
+ });
146
+ fireEvent.keyUp(button, {
147
+ key: 'Space',
148
+ keyCode: 32
149
+ });
150
+ expect(setSelectedKeys).toHaveBeenCalled();
151
+ });
152
+ test('onSpacePress calls when space is pressed, and selected', function () {
153
+ getComponent({
154
+ onKeyDown: onKeyDownSection,
155
+ isSelected: true
156
+ });
157
+ var button = screen.getByRole('button');
158
+ fireEvent.keyDown(button, {
159
+ key: 'Space',
160
+ keyCode: 32
161
+ });
162
+ fireEvent.keyUp(button, {
163
+ key: 'Space',
164
+ keyCode: 32
165
+ });
166
+ expect(setSelectedKeys).toHaveBeenCalled();
167
+ });
168
+ test('onSpacePress calls when space is pressed, item', function () {
169
+ getComponent({
170
+ onKeyDown: onKeyDownItem,
171
+ isInRefArray: false
172
+ });
173
+ var button = screen.getByRole('button');
174
+ fireEvent.keyDown(button, {
175
+ key: 'Space',
176
+ keyCode: 32
177
+ });
178
+ fireEvent.keyUp(button, {
179
+ key: 'Space',
180
+ keyCode: 32
181
+ });
182
+ expect(setSelectedKeys).toHaveBeenCalled();
183
+ });
184
+ test('onLeftPress calls when Left Arrow is pressed and expanded', function () {
185
+ getComponent({
186
+ isExpanded: true,
187
+ onKeyDown: onKeyDownSection,
188
+ isInRefArray: false
189
+ });
190
+ var button = screen.getByRole('button');
191
+ fireEvent.keyDown(button, {
192
+ key: 'ArrowLeft',
193
+ keyCode: 37
194
+ });
195
+ fireEvent.keyUp(button, {
196
+ key: 'ArrowLeft',
197
+ keyCode: 37
198
+ });
199
+ expect(toggleKey).not.toHaveBeenCalled();
200
+ expect(focusPrevious).toHaveBeenCalled();
201
+ });
202
+ test('onLeftPress does not call when Left Arrow is pressed and NOT expanded', function () {
203
+ getComponent({
204
+ onKeyDown: onKeyDownSection
205
+ });
206
+ var button = screen.getByRole('button');
207
+ fireEvent.keyDown(button, {
208
+ key: 'ArrowLeft',
209
+ keyCode: 37
210
+ });
211
+ fireEvent.keyUp(button, {
212
+ key: 'ArrowLeft',
213
+ keyCode: 37
214
+ });
215
+ expect(toggleKey).not.toHaveBeenCalled();
216
+ expect(focusPrevious).not.toHaveBeenCalled();
217
+ });
218
+ test('onRightPress calls when Right Arrow is pressed and NOT expanded', function () {
219
+ getComponent({
220
+ onKeyDown: onKeyDownSection,
221
+ isInRefArray: false
222
+ });
223
+ var button = screen.getByRole('button');
224
+ fireEvent.keyDown(button, {
225
+ key: 'ArrowRight',
226
+ keyCode: 39
227
+ });
228
+ fireEvent.keyUp(button, {
229
+ key: 'ArrowRight',
230
+ keyCode: 39
231
+ });
232
+ expect(toggleKey).toHaveBeenCalled();
233
+ expect(focusNext).not.toHaveBeenCalled();
234
+ });
235
+ test('onRightPress calls correct callback when Right Arrow is pressed and expanded', function () {
236
+ getComponent({
237
+ onKeyDown: onKeyDownSection,
238
+ isExpanded: true,
239
+ isInRefArray: false
240
+ });
241
+ var button = screen.getByRole('button');
242
+ fireEvent.keyDown(button, {
243
+ key: 'ArrowRight',
244
+ keyCode: 39
245
+ });
246
+ fireEvent.keyUp(button, {
247
+ key: 'ArrowRight',
248
+ keyCode: 39
249
+ });
250
+ expect(toggleKey).not.toHaveBeenCalled();
251
+ expect(focusNext).not.toHaveBeenCalled();
252
+ });
253
+ test('onLeftPress calls when Left Arrow is pressed and expanded', function () {
254
+ getComponent({
255
+ isExpanded: true,
256
+ onKeyDown: onKeyDownSection
257
+ });
258
+ var button = screen.getByRole('button');
259
+ fireEvent.keyDown(button, {
260
+ key: 'ArrowRight',
261
+ keyCode: 39
262
+ });
263
+ fireEvent.keyUp(button, {
264
+ key: 'ArrowRight',
265
+ keyCode: 39
266
+ });
267
+ expect(toggleKey).not.toHaveBeenCalled();
268
+ });
269
+ test('onDownPress calls when down Arrow is pressed and expanded', function () {
270
+ getComponent({
271
+ onKeyDown: onKeyDownSection
272
+ });
273
+ var button = screen.getByRole('button');
274
+ fireEvent.keyDown(button, {
275
+ key: 'ArrowDown',
276
+ keyCode: 40
277
+ });
278
+ fireEvent.keyUp(button, {
279
+ key: 'ArrowDown',
280
+ keyCode: 40
281
+ });
282
+ expect(refFocus).toHaveBeenCalled();
283
+ });
284
+ test('onUpPress calls when down Arrow is pressed and expanded', function () {
285
+ getComponent({
286
+ onKeyDown: onKeyDownSection
287
+ });
288
+ var button = screen.getByRole('button');
289
+ fireEvent.keyDown(button, {
290
+ key: 'ArrowUp',
291
+ keyCode: 38
292
+ });
293
+ fireEvent.keyUp(button, {
294
+ key: 'ArrowUp',
295
+ keyCode: 38
296
+ });
297
+ expect(refFocus).toHaveBeenCalled();
298
+ });
299
+ test('onUpPress calls when down Arrow is pressed and expanded for items', function () {
300
+ getComponent({
301
+ onKeyDown: onKeyDownItem
302
+ });
303
+ var button = screen.getByRole('button');
304
+ fireEvent.keyDown(button, {
305
+ key: 'ArrowUp',
306
+ keyCode: 38
307
+ });
308
+ fireEvent.keyUp(button, {
309
+ key: 'ArrowUp',
310
+ keyCode: 38
311
+ });
312
+ expect(refFocus).toHaveBeenCalled();
313
+ });
314
+ test('onPageUpPress calls when page up is pressed', function () {
315
+ getComponent({
316
+ onKeyDown: onKeyDownItem
317
+ });
318
+ var button = screen.getByRole('button');
319
+ fireEvent.keyDown(button, {
320
+ key: 'PageUp',
321
+ keyCode: 33
322
+ });
323
+ fireEvent.keyUp(button, {
324
+ key: 'PageUp',
325
+ keyCode: 33
326
+ });
327
+ expect(refFocus).toHaveBeenCalled();
328
+ });
329
+ test('onPageUpPress calls when page up is pressed, on section', function () {
330
+ getComponent({
331
+ onKeyDown: onKeyDownSection
332
+ });
333
+ var button = screen.getByRole('button');
334
+ fireEvent.keyDown(button, {
335
+ key: 'PageUp',
336
+ keyCode: 33
337
+ });
338
+ fireEvent.keyUp(button, {
339
+ key: 'PageUp',
340
+ keyCode: 33
341
+ });
342
+ expect(refFocus).toHaveBeenCalled();
343
+ });
344
+ test('onPageDownPress calls when page up is pressed', function () {
345
+ getComponent({
346
+ onKeyDown: onKeyDownItem
347
+ });
348
+ var button = screen.getByRole('button');
349
+ fireEvent.keyDown(button, {
350
+ key: 'PageDown',
351
+ keyCode: 34
352
+ });
353
+ fireEvent.keyUp(button, {
354
+ key: 'PageDown',
355
+ keyCode: 34
356
+ });
357
+ expect(refFocus).toHaveBeenCalled();
358
+ });
359
+ test('onPageDownPress calls when page up is pressed, on section', function () {
360
+ getComponent({
361
+ onKeyDown: onKeyDownSection
362
+ });
363
+ var button = screen.getByRole('button');
364
+ fireEvent.keyDown(button, {
365
+ key: 'PageDown',
366
+ keyCode: 34
367
+ });
368
+ fireEvent.keyUp(button, {
369
+ key: 'PageDown',
370
+ keyCode: 34
371
+ });
372
+ expect(refFocus).toHaveBeenCalled();
373
+ });
374
+ test('onDownPress calls when down Arrow is pressed and expanded, for items', function () {
375
+ getComponent({
376
+ onKeyDown: onKeyDownItem
377
+ });
378
+ var button = screen.getByRole('button');
379
+ fireEvent.keyDown(button, {
380
+ key: 'ArrowDown',
381
+ keyCode: 40
382
+ });
383
+ fireEvent.keyUp(button, {
384
+ key: 'ArrowDown',
385
+ keyCode: 40
386
+ });
387
+ expect(refFocus).toHaveBeenCalled();
388
+ });
389
+ test('onTabPress calls correct callbacks', function () {
390
+ getComponent({
391
+ onKeyDown: onKeyDownItem
392
+ });
393
+ var button = screen.getByRole('button');
394
+ fireEvent.keyDown(button, {
395
+ key: 'Tab',
396
+ keyCode: 9
397
+ });
398
+ fireEvent.keyUp(button, {
399
+ key: 'Tab',
400
+ keyCode: 9
401
+ });
402
+ expect(focusNext).not.toHaveBeenCalled();
403
+ });
404
+ test('onTabPress calls correct callbacks', function () {
405
+ getComponent({
406
+ onKeyDown: onKeyDownSection
407
+ });
408
+ var button = screen.getByRole('button');
409
+ fireEvent.keyDown(button, {
410
+ key: 'Tab',
411
+ keyCode: 9
412
+ });
413
+ fireEvent.keyUp(button, {
414
+ key: 'Tab',
415
+ keyCode: 9
416
+ });
417
+ expect(focusNext).toHaveBeenCalled();
418
+ });
419
+ test('onEndPress calls correct callbacks', function () {
420
+ getComponent({
421
+ onKeyDown: onKeyDownSection
422
+ });
423
+ var button = screen.getByRole('button');
424
+ fireEvent.keyDown(button, {
425
+ key: 'End',
426
+ keyCode: 35
427
+ });
428
+ fireEvent.keyUp(button, {
429
+ key: 'End',
430
+ keyCode: 35
431
+ });
432
+ expect(refFocus).toHaveBeenCalled();
433
+ });
434
+ test('onEndPress calls correct callbacks', function () {
435
+ getComponent({
436
+ onKeyDown: onKeyDownItem
437
+ });
438
+ var button = screen.getByRole('button');
439
+ fireEvent.keyDown(button, {
440
+ key: 'End',
441
+ keyCode: 35
442
+ });
443
+ fireEvent.keyUp(button, {
444
+ key: 'End',
445
+ keyCode: 35
446
+ });
447
+ expect(refFocus).toHaveBeenCalled();
448
+ });
449
+ test('onHomePress calls correct callbacks', function () {
450
+ getComponent({
451
+ onKeyDown: onKeyDownSection
452
+ });
453
+ var button = screen.getByRole('button');
454
+ fireEvent.keyDown(button, {
455
+ key: 'Home',
456
+ keyCode: 36
457
+ });
458
+ fireEvent.keyUp(button, {
459
+ key: 'Home',
460
+ keyCode: 36
461
+ });
462
+ expect(refFocus).toHaveBeenCalled();
463
+ });
464
+ test('onHomePress calls correct callbacks', function () {
465
+ getComponent({
466
+ onKeyDown: onKeyDownItem
467
+ });
468
+ var button = screen.getByRole('button');
469
+ fireEvent.keyDown(button, {
470
+ key: 'Home',
471
+ keyCode: 36
472
+ });
473
+ fireEvent.keyUp(button, {
474
+ key: 'Home',
475
+ keyCode: 36
476
+ });
477
+ expect(refFocus).toHaveBeenCalled();
478
+ });
479
+ test('onLeftPress calls correct callbacks, when correct props are provided', function () {
480
+ var thisRefArray = [{
481
+ thisRef: {
482
+ current: 'test target'
483
+ }
484
+ }];
485
+ var thisEvent = {
486
+ target: 'test target',
487
+ preventDefault: function preventDefault() {
488
+ return jest.fn();
489
+ },
490
+ stopPropagation: function stopPropagation() {
491
+ return jest.fn();
492
+ }
493
+ };
494
+ onLeftPress(thisEvent, focusManager, state, 'test', true, thisRefArray);
495
+ expect(toggleKey).toHaveBeenCalled();
496
+ });