@onewelcome/react-lib-components 6.0.0 → 6.1.0

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 (194) hide show
  1. package/dist/cjs/Button/Button.module.cjs.js +1 -1
  2. package/dist/cjs/Button/IconButton.module.cjs.js +1 -1
  3. package/dist/cjs/ContextMenu/ContextMenu.cjs.js +1 -1
  4. package/dist/cjs/ContextMenu/ContextMenu.cjs.js.map +1 -1
  5. package/dist/cjs/ContextMenu/ContextMenuItem.module.cjs.js +1 -1
  6. package/dist/cjs/ContextMenu/ContextMenuService.cjs.js +1 -1
  7. package/dist/cjs/ContextMenu/ContextMenuService.cjs.js.map +1 -1
  8. package/dist/cjs/DataGrid/DataGridActions/DataGridColumnsToggle.module.cjs.js +1 -1
  9. package/dist/cjs/Form/Input/Input.module.cjs.js +1 -1
  10. package/dist/cjs/Form/Select/Option.cjs.js +1 -1
  11. package/dist/cjs/Form/Select/Option.cjs.js.map +1 -1
  12. package/dist/cjs/Form/Select/Select.cjs.js +1 -1
  13. package/dist/cjs/Form/Select/Select.cjs.js.map +1 -1
  14. package/dist/cjs/Form/Select/Select.module.cjs.js +1 -1
  15. package/dist/cjs/Form/Select/SelectService.cjs.js +1 -1
  16. package/dist/cjs/Form/Select/SelectService.cjs.js.map +1 -1
  17. package/dist/cjs/Form/Textarea/Textarea.module.cjs.js +1 -1
  18. package/dist/cjs/Link/Link.module.cjs.js +1 -1
  19. package/dist/cjs/Notifications/BaseModal/BaseModal.module.cjs.js +1 -1
  20. package/dist/cjs/Notifications/SlideInModal/SlideInModal.module.cjs.js +1 -1
  21. package/dist/cjs/Notifications/Snackbar/SnackbarItem/SnackbarItem.module.cjs.js +1 -1
  22. package/dist/cjs/Popover/Popover.cjs.js +1 -1
  23. package/dist/cjs/Popover/Popover.cjs.js.map +1 -1
  24. package/dist/cjs/Popover/Popover.module.cjs.js +1 -1
  25. package/dist/cjs/Stepper/Step.cjs.js +1 -1
  26. package/dist/cjs/Stepper/Step.cjs.js.map +1 -1
  27. package/dist/cjs/Stepper/Step.module.cjs.js +1 -1
  28. package/dist/cjs/Stepper/Stepper.cjs.js +1 -1
  29. package/dist/cjs/Stepper/Stepper.cjs.js.map +1 -1
  30. package/dist/cjs/Tabs/TabButton.module.cjs.js +1 -1
  31. package/dist/cjs/TextEllipsis/TextEllipsis.module.cjs.js +1 -1
  32. package/dist/cjs/Tiles/Tile.module.cjs.js +1 -1
  33. package/dist/cjs/Tooltip/Tooltip.module.cjs.js +1 -1
  34. package/dist/cjs/Wizard/BaseWizardSteps/BaseWizardSteps.module.cjs.js +1 -1
  35. package/dist/cjs/src/.scope.d.ts +2 -0
  36. package/dist/cjs/src/components/ContextMenu/ContextMenu.d.ts +1 -1
  37. package/dist/cjs/src/components/ContextMenu/ContextMenuService.d.ts +4 -1
  38. package/dist/cjs/src/components/Form/Select/Option.d.ts +1 -0
  39. package/dist/cjs/src/components/Form/Select/Select.d.ts +20 -0
  40. package/dist/cjs/src/components/Form/Select/Select.interfaces.d.ts +3 -1
  41. package/dist/cjs/src/components/Form/Select/Select.test.d.ts +63 -1
  42. package/dist/cjs/src/components/Form/Select/SelectKeyboardNavigation.test.d.ts +1 -0
  43. package/dist/cjs/src/components/Form/Select/SelectService.d.ts +3 -2
  44. package/dist/cjs/src/components/Stepper/Stepper.d.ts +0 -1
  45. package/dist/cjs/src/hooks/usePosition.cjs.js.map +1 -1
  46. package/dist/cjs/src/hooks/usePosition.d.ts +1 -1
  47. package/dist/esm/Button/Button.module.esm.js +1 -1
  48. package/dist/esm/Button/IconButton.module.esm.js +1 -1
  49. package/dist/esm/ContextMenu/ContextMenu.esm.js +1 -1
  50. package/dist/esm/ContextMenu/ContextMenu.esm.js.map +1 -1
  51. package/dist/esm/ContextMenu/ContextMenuItem.module.esm.js +1 -1
  52. package/dist/esm/ContextMenu/ContextMenuService.esm.js +1 -1
  53. package/dist/esm/ContextMenu/ContextMenuService.esm.js.map +1 -1
  54. package/dist/esm/DataGrid/DataGridActions/DataGridColumnsToggle.module.esm.js +1 -1
  55. package/dist/esm/Form/Input/Input.module.esm.js +1 -1
  56. package/dist/esm/Form/Select/Option.esm.js +1 -1
  57. package/dist/esm/Form/Select/Option.esm.js.map +1 -1
  58. package/dist/esm/Form/Select/Select.esm.js +1 -1
  59. package/dist/esm/Form/Select/Select.esm.js.map +1 -1
  60. package/dist/esm/Form/Select/Select.module.esm.js +1 -1
  61. package/dist/esm/Form/Select/SelectService.esm.js +1 -1
  62. package/dist/esm/Form/Select/SelectService.esm.js.map +1 -1
  63. package/dist/esm/Form/Textarea/Textarea.module.esm.js +1 -1
  64. package/dist/esm/Link/Link.module.esm.js +1 -1
  65. package/dist/esm/Notifications/BaseModal/BaseModal.module.esm.js +1 -1
  66. package/dist/esm/Notifications/SlideInModal/SlideInModal.module.esm.js +1 -1
  67. package/dist/esm/Notifications/Snackbar/SnackbarItem/SnackbarItem.module.esm.js +1 -1
  68. package/dist/esm/Popover/Popover.esm.js +1 -1
  69. package/dist/esm/Popover/Popover.esm.js.map +1 -1
  70. package/dist/esm/Popover/Popover.module.esm.js +1 -1
  71. package/dist/esm/Stepper/Step.esm.js +1 -1
  72. package/dist/esm/Stepper/Step.esm.js.map +1 -1
  73. package/dist/esm/Stepper/Step.module.esm.js +1 -1
  74. package/dist/esm/Stepper/Stepper.esm.js +1 -1
  75. package/dist/esm/Stepper/Stepper.esm.js.map +1 -1
  76. package/dist/esm/Tabs/TabButton.module.esm.js +1 -1
  77. package/dist/esm/TextEllipsis/TextEllipsis.module.esm.js +1 -1
  78. package/dist/esm/Tiles/Tile.module.esm.js +1 -1
  79. package/dist/esm/Tooltip/Tooltip.module.esm.js +1 -1
  80. package/dist/esm/Wizard/BaseWizardSteps/BaseWizardSteps.module.esm.js +1 -1
  81. package/dist/esm/src/.scope.d.ts +2 -0
  82. package/dist/esm/src/components/ContextMenu/ContextMenu.d.ts +1 -1
  83. package/dist/esm/src/components/ContextMenu/ContextMenuService.d.ts +4 -1
  84. package/dist/esm/src/components/Form/Select/Option.d.ts +1 -0
  85. package/dist/esm/src/components/Form/Select/Select.d.ts +20 -0
  86. package/dist/esm/src/components/Form/Select/Select.interfaces.d.ts +3 -1
  87. package/dist/esm/src/components/Form/Select/Select.test.d.ts +63 -1
  88. package/dist/esm/src/components/Form/Select/SelectKeyboardNavigation.test.d.ts +1 -0
  89. package/dist/esm/src/components/Form/Select/SelectService.d.ts +3 -2
  90. package/dist/esm/src/components/Stepper/Stepper.d.ts +0 -1
  91. package/dist/esm/src/hooks/usePosition.d.ts +1 -1
  92. package/dist/esm/src/hooks/usePosition.esm.js.map +1 -1
  93. package/package.json +48 -45
  94. package/src/{hooks/useWrapper.test.ts → .scope.ts} +1 -12
  95. package/src/components/ContextMenu/ContextMenu.tsx +13 -23
  96. package/src/components/ContextMenu/ContextMenuService.ts +47 -1
  97. package/src/components/Form/Select/Option.tsx +3 -1
  98. package/src/components/Form/Select/Select.interfaces.ts +3 -1
  99. package/src/components/Form/Select/Select.module.scss +55 -34
  100. package/src/components/Form/Select/Select.tsx +74 -23
  101. package/src/components/Form/Select/SelectService.ts +26 -10
  102. package/src/components/Link/Link.module.scss +16 -0
  103. package/src/components/Popover/Popover.tsx +19 -2
  104. package/src/components/Stepper/Step.tsx +2 -1
  105. package/src/components/Stepper/Stepper.tsx +0 -2
  106. package/src/components/Tooltip/Tooltip.module.scss +1 -0
  107. package/src/hooks/usePosition.ts +1 -1
  108. package/src/interfaces.ts +2 -2
  109. package/src/mixins.module.scss +2 -4
  110. package/src/components/Breadcrumbs/Breadcrumbs.test.tsx +0 -64
  111. package/src/components/Button/BaseButton.test.tsx +0 -133
  112. package/src/components/Button/Button.test.tsx +0 -150
  113. package/src/components/Button/IconButton.test.tsx +0 -106
  114. package/src/components/ContextMenu/ContextMenu.test.tsx +0 -358
  115. package/src/components/DataGrid/DataGrid.test.tsx +0 -437
  116. package/src/components/DataGrid/DataGridActions/DataGridActions.test.tsx +0 -204
  117. package/src/components/DataGrid/DataGridActions/DataGridColumnsToggle.test.tsx +0 -99
  118. package/src/components/DataGrid/DataGridBody/DataGridBody.test.tsx +0 -140
  119. package/src/components/DataGrid/DataGridBody/DataGridCell.test.tsx +0 -90
  120. package/src/components/DataGrid/DataGridBody/DataGridRow.test.tsx +0 -117
  121. package/src/components/DataGrid/DataGridHeader/DataGridHeader.test.tsx +0 -276
  122. package/src/components/DataGrid/DataGridHeader/DataGridHeaderCell.test.tsx +0 -144
  123. package/src/components/Form/Checkbox/Checkbox.test.tsx +0 -308
  124. package/src/components/Form/Fieldset/Fieldset.test.tsx +0 -127
  125. package/src/components/Form/FileUpload/FileItem/FileItem.test.tsx +0 -103
  126. package/src/components/Form/FileUpload/FileUpload.test.tsx +0 -374
  127. package/src/components/Form/Form.test.tsx +0 -63
  128. package/src/components/Form/FormControl/FormControl.test.tsx +0 -98
  129. package/src/components/Form/FormGroup/FormGroup.test.tsx +0 -127
  130. package/src/components/Form/FormHelperText/FormHelperText.test.tsx +0 -84
  131. package/src/components/Form/FormSelectorWrapper/FormSelectorWrapper.test.tsx +0 -94
  132. package/src/components/Form/Input/Input.test.tsx +0 -267
  133. package/src/components/Form/Label/Label.test.tsx +0 -68
  134. package/src/components/Form/Radio/Radio.test.tsx +0 -130
  135. package/src/components/Form/Select/Option.test.tsx +0 -57
  136. package/src/components/Form/Select/Select.test.tsx +0 -564
  137. package/src/components/Form/Textarea/Textarea.test.tsx +0 -124
  138. package/src/components/Form/Toggle/Toggle.test.tsx +0 -200
  139. package/src/components/Form/Wrapper/CheckboxWrapper/CheckboxWrapper.test.tsx +0 -141
  140. package/src/components/Form/Wrapper/InputWrapper/InputWrapper.test.tsx +0 -211
  141. package/src/components/Form/Wrapper/RadioWrapper/RadioWrapper.test.tsx +0 -117
  142. package/src/components/Form/Wrapper/SelectWrapper/SelectWrapper.test.tsx +0 -186
  143. package/src/components/Form/Wrapper/TextareaWrapper/TextareaWrapper.test.tsx +0 -173
  144. package/src/components/Form/Wrapper/Wrapper/Wrapper.test.tsx +0 -59
  145. package/src/components/Icon/Icon.test.tsx +0 -83
  146. package/src/components/Link/Link.test.tsx +0 -203
  147. package/src/components/Notifications/Banner/Banner.test.tsx +0 -84
  148. package/src/components/Notifications/BaseModal/BaseModal.test.tsx +0 -194
  149. package/src/components/Notifications/BaseModal/BaseModalActions/BaseModalActions.test.tsx +0 -74
  150. package/src/components/Notifications/BaseModal/BaseModalContent/BaseModalContent.test.tsx +0 -71
  151. package/src/components/Notifications/BaseModal/BaseModalHeader/BaseModalHeader.test.tsx +0 -74
  152. package/src/components/Notifications/Dialog/Dialog.test.tsx +0 -118
  153. package/src/components/Notifications/Dialog/DialogActions/DialogActions.test.tsx +0 -61
  154. package/src/components/Notifications/Dialog/DialogTitle/DialogTitle.test.tsx +0 -87
  155. package/src/components/Notifications/DiscardChangesModal/DiscardChangesDialog/DiscardChangesDialog.test.tsx +0 -111
  156. package/src/components/Notifications/DiscardChangesModal/DiscardChangesModal.test.tsx +0 -175
  157. package/src/components/Notifications/Modal/Modal.test.tsx +0 -18
  158. package/src/components/Notifications/NotificationProvider/NotificationContext.test.tsx +0 -449
  159. package/src/components/Notifications/SlideInModal/SlideInModal.test.tsx +0 -90
  160. package/src/components/Notifications/Snackbar/SnackbarContainer/SnackbarContainer.test.tsx +0 -53
  161. package/src/components/Notifications/Snackbar/SnackbarItem/SnackbarItem.test.tsx +0 -77
  162. package/src/components/Notifications/Snackbar/SnackbarProvider/SnackbarProvider.test.tsx +0 -219
  163. package/src/components/Notifications/Snackbar/useSnackbar.test.tsx +0 -136
  164. package/src/components/Pagination/Pagination.test.tsx +0 -183
  165. package/src/components/Popover/Popover.test.tsx +0 -103
  166. package/src/components/ProgressBar/ProgressBar.test.tsx +0 -91
  167. package/src/components/Skeleton/Skeleton.test.tsx +0 -112
  168. package/src/components/StatusIndicator/StatusIndicator.test.tsx +0 -143
  169. package/src/components/Stepper/Stepper.test.tsx +0 -83
  170. package/src/components/Tabs/Tab.test.tsx +0 -49
  171. package/src/components/Tabs/TabButton.test.tsx +0 -65
  172. package/src/components/Tabs/Tabs.test.tsx +0 -291
  173. package/src/components/Tag/Tag.test.tsx +0 -89
  174. package/src/components/TextEllipsis/TextEllipsis.test.tsx +0 -96
  175. package/src/components/Tiles/Tile.test.tsx +0 -183
  176. package/src/components/Tiles/Tiles.test.tsx +0 -162
  177. package/src/components/Tooltip/Tooltip.test.tsx +0 -390
  178. package/src/components/Typography/Typography.test.tsx +0 -177
  179. package/src/components/Wizard/BaseWizardSteps/BaseWizardSteps.test.tsx +0 -90
  180. package/src/components/Wizard/Wizard.test.tsx +0 -218
  181. package/src/components/Wizard/WizardActions/WizardActions.test.tsx +0 -187
  182. package/src/components/Wizard/WizardSteps/WizardSteps.test.tsx +0 -125
  183. package/src/components/_BaseStyling_/BaseStyling.test.tsx +0 -55
  184. package/src/hooks/useAnimation.test.tsx +0 -65
  185. package/src/hooks/useBodyClick.test.tsx +0 -55
  186. package/src/hooks/useDebouncedCallback.test.ts +0 -150
  187. package/src/hooks/useDetermineStatusIcon.test.ts +0 -28
  188. package/src/hooks/useFormSelector.test.ts +0 -56
  189. package/src/hooks/usePosition.test.tsx +0 -510
  190. package/src/hooks/useRepeater.test.tsx +0 -156
  191. package/src/hooks/useScroll.test.tsx +0 -36
  192. package/src/hooks/useSpacing.test.ts +0 -86
  193. package/src/hooks/useUploadFile.test.ts +0 -211
  194. package/src/util/helper.test.tsx +0 -403
@@ -1,150 +0,0 @@
1
- /*
2
- * Copyright 2022 OneWelcome B.V.
3
- *
4
- * Licensed under the Apache License, Version 2.0 (the "License");
5
- * you may not use this file except in compliance with the License.
6
- * You may obtain a copy of the License at
7
- *
8
- * http://www.apache.org/licenses/LICENSE-2.0
9
- *
10
- * Unless required by applicable law or agreed to in writing, software
11
- * distributed under the License is distributed on an "AS IS" BASIS,
12
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
- * See the License for the specific language governing permissions and
14
- * limitations under the License.
15
- */
16
-
17
- import React, { useRef, useEffect } from "react";
18
- import { Button, Props } from "./Button";
19
- import { render } from "@testing-library/react";
20
- import { Icon, Icons } from "../Icon/Icon";
21
-
22
- const defaultParams: Props = {};
23
-
24
- const createButton = (params?: (defaultParams: Props) => Props) => {
25
- let parameters: Props = defaultParams;
26
- if (params) {
27
- parameters = params(defaultParams);
28
- }
29
- const queries = render(
30
- <Button {...parameters} data-testid="button">
31
- button content
32
- </Button>
33
- );
34
- const button = queries.getByTestId("button");
35
-
36
- return {
37
- ...queries,
38
- button
39
- };
40
- };
41
-
42
- describe("Button should render", () => {
43
- it("renders without crashing", () => {
44
- const { button } = createButton();
45
-
46
- expect(button).toBeDefined();
47
- });
48
- });
49
-
50
- describe("ref should work", () => {
51
- it("should give back the proper data prop, this also checks if the component propagates ...rest properly", () => {
52
- const ExampleComponent = ({
53
- propagateRef
54
- }: {
55
- propagateRef?: (ref: React.RefObject<HTMLElement>) => void;
56
- }) => {
57
- const ref = useRef(null);
58
-
59
- useEffect(() => {
60
- if (ref.current) {
61
- propagateRef && propagateRef(ref);
62
- }
63
- }, [ref]);
64
-
65
- return <Button {...defaultParams} data-ref="testing" ref={ref} />;
66
- };
67
-
68
- const refCheck = (ref: React.RefObject<HTMLElement>) => {
69
- expect(ref.current).toHaveAttribute("data-ref", "testing");
70
- };
71
-
72
- render(<ExampleComponent propagateRef={refCheck} />);
73
- });
74
- });
75
-
76
- describe("Button should render", () => {
77
- it("renders without crashing", () => {
78
- const { button } = createButton();
79
-
80
- expect(button).toBeDefined();
81
- });
82
- });
83
-
84
- describe("Different variants of the button", () => {
85
- it('should have a class of "primary"', () => {
86
- const { button } = createButton();
87
-
88
- expect(button.classList.contains("primary")).toBe(true);
89
- });
90
-
91
- it('should have a class of "success"', () => {
92
- const { button } = createButton(defaultParams => ({ ...defaultParams, color: "success" }));
93
-
94
- expect(button.classList.contains("success")).toBe(true);
95
- });
96
-
97
- it('should have a class of "danger"', () => {
98
- const { button } = createButton(defaultParams => ({ ...defaultParams, color: "danger" }));
99
-
100
- expect(button.classList.contains("danger")).toBe(true);
101
- });
102
-
103
- it('should have a class of "warning"', () => {
104
- const { button } = createButton(defaultParams => ({ ...defaultParams, color: "warning" }));
105
-
106
- expect(button.classList.contains("warning")).toBe(true);
107
- });
108
-
109
- it('should have a class of "fill"', () => {
110
- const { button } = createButton(defaultParams => ({ ...defaultParams, variant: "fill" }));
111
-
112
- expect(button.classList.contains("fill")).toBe(true);
113
- });
114
-
115
- it('should have a class of "outline"', () => {
116
- const { button } = createButton(defaultParams => ({ ...defaultParams, variant: "outline" }));
117
-
118
- expect(button.classList.contains("outline")).toBe(true);
119
- });
120
-
121
- it('should have a class of "text"', () => {
122
- const { button } = createButton(defaultParams => ({ ...defaultParams, variant: "text" }));
123
-
124
- expect(button.classList.contains("text")).toBe(true);
125
- });
126
- });
127
-
128
- describe("Button contains an icon", () => {
129
- it("Contains an icon at the start", () => {
130
- const { button } = createButton(defaultParams => ({
131
- ...defaultParams,
132
- startIcon: <Icon icon={Icons.Calendar} />
133
- }));
134
-
135
- expect(button.classList.contains("has-icon")).toBe(true);
136
- expect(button.firstElementChild?.nodeName).toBe("I");
137
- expect(button.querySelector("i + span")!.innerHTML).toBe("button content");
138
- });
139
-
140
- it("Contains an icon at the end", () => {
141
- const { button } = createButton(defaultParams => ({
142
- ...defaultParams,
143
- endIcon: <Icon icon={Icons.Calendar} />
144
- }));
145
-
146
- expect(button.classList.contains("has-icon")).toBe(true);
147
- expect(button.lastElementChild?.nodeName).toBe("I");
148
- expect(button.querySelector("span")!.innerHTML).toBe("button content");
149
- });
150
- });
@@ -1,106 +0,0 @@
1
- /*
2
- * Copyright 2022 OneWelcome B.V.
3
- *
4
- * Licensed under the Apache License, Version 2.0 (the "License");
5
- * you may not use this file except in compliance with the License.
6
- * You may obtain a copy of the License at
7
- *
8
- * http://www.apache.org/licenses/LICENSE-2.0
9
- *
10
- * Unless required by applicable law or agreed to in writing, software
11
- * distributed under the License is distributed on an "AS IS" BASIS,
12
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
- * See the License for the specific language governing permissions and
14
- * limitations under the License.
15
- */
16
-
17
- import React, { useRef, useEffect } from "react";
18
- import { IconButton, Props } from "./IconButton";
19
- import { render } from "@testing-library/react";
20
-
21
- const defaultParams: Props = {
22
- title: "iconbutton"
23
- };
24
-
25
- const createIconButton = (params?: (defaultParams: Props) => Props) => {
26
- let parameters: Props = defaultParams;
27
- if (params) {
28
- parameters = params(defaultParams);
29
- }
30
- const queries = render(
31
- <IconButton {...parameters} data-testid="iconButton">
32
- iconButton content
33
- </IconButton>
34
- );
35
- const iconButton = queries.getByTestId("iconButton");
36
-
37
- return {
38
- ...queries,
39
- iconButton
40
- };
41
- };
42
-
43
- describe("IconButton should render", () => {
44
- it("renders without crashing", () => {
45
- const { iconButton } = createIconButton();
46
-
47
- expect(iconButton).toBeDefined();
48
- });
49
- });
50
-
51
- describe("ref should work", () => {
52
- it("should give back the proper data prop, this also checks if the component propagates ...rest properly", () => {
53
- const ExampleComponent = ({
54
- propagateRef
55
- }: {
56
- propagateRef?: (ref: React.RefObject<HTMLElement>) => void;
57
- }) => {
58
- const ref = useRef(null);
59
-
60
- useEffect(() => {
61
- if (ref.current) {
62
- propagateRef && propagateRef(ref);
63
- }
64
- }, [ref]);
65
-
66
- return <IconButton {...defaultParams} data-ref="testing" ref={ref} />;
67
- };
68
-
69
- const refCheck = (ref: React.RefObject<HTMLElement>) => {
70
- expect(ref.current).toHaveAttribute("data-ref", "testing");
71
- };
72
-
73
- render(<ExampleComponent propagateRef={refCheck} />);
74
- });
75
- });
76
-
77
- describe("Different variants of the button", () => {
78
- it('should have a class of "primary"', () => {
79
- const { iconButton } = createIconButton();
80
- expect(iconButton.classList.contains("primary")).toBe(true);
81
- });
82
-
83
- it('should have a class of "fill"', () => {
84
- const { iconButton } = createIconButton(defaultParams => ({
85
- ...defaultParams,
86
- variant: "fill"
87
- }));
88
- expect(iconButton.classList.contains("fill")).toBe(true);
89
- });
90
-
91
- it('should have a class of "outline"', () => {
92
- const { iconButton } = createIconButton(defaultParams => ({
93
- ...defaultParams,
94
- variant: "outline"
95
- }));
96
- expect(iconButton.classList.contains("outline")).toBe(true);
97
- });
98
-
99
- it('should have a class of "text"', () => {
100
- const { iconButton } = createIconButton(defaultParams => ({
101
- ...defaultParams,
102
- variant: "text"
103
- }));
104
- expect(iconButton.classList.contains("text")).toBe(true);
105
- });
106
- });
@@ -1,358 +0,0 @@
1
- /*
2
- * Copyright 2022 OneWelcome B.V.
3
- *
4
- * Licensed under the Apache License, Version 2.0 (the "License");
5
- * you may not use this file except in compliance with the License.
6
- * You may obtain a copy of the License at
7
- *
8
- * http://www.apache.org/licenses/LICENSE-2.0
9
- *
10
- * Unless required by applicable law or agreed to in writing, software
11
- * distributed under the License is distributed on an "AS IS" BASIS,
12
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
- * See the License for the specific language governing permissions and
14
- * limitations under the License.
15
- */
16
-
17
- import React, { useEffect, useRef } from "react";
18
- import { ContextMenu, Props } from "./ContextMenu";
19
- import { render } from "@testing-library/react";
20
- import { Button } from "../Button/Button";
21
- import { ContextMenuItem } from "./ContextMenuItem";
22
- import userEvent from "@testing-library/user-event";
23
-
24
- const onShow = jest.fn();
25
- const onClick = jest.fn();
26
-
27
- const defaultParams: Props = {
28
- id: "example-contextmenu",
29
- trigger: <Button data-testid="trigger">Click me for a context menu</Button>,
30
- children: [
31
- <ContextMenuItem onClick={onClick} data-testid="contextmenuitem" key="1">
32
- Example item 1
33
- </ContextMenuItem>,
34
- <ContextMenuItem onClick={onClick} data-testid="contextmenuitem2" key="2">
35
- Example item 2
36
- </ContextMenuItem>,
37
- <ContextMenuItem onClick={onClick} data-testid="contextmenuitem3" key="3">
38
- Example item 3
39
- </ContextMenuItem>
40
- ],
41
- show: false,
42
- onShow: onShow
43
- };
44
-
45
- const createContextMenu = (params?: (defaultParams: Props) => Props) => {
46
- let parameters: Props = defaultParams;
47
- if (params) {
48
- parameters = params(defaultParams);
49
- }
50
-
51
- const queries = render(<ContextMenu {...parameters} data-testid="contextmenu"></ContextMenu>);
52
-
53
- const contextmenu = queries.getByTestId("contextmenu");
54
- const trigger = queries.getByTestId("trigger");
55
-
56
- return {
57
- ...queries,
58
- contextmenu,
59
- trigger
60
- };
61
- };
62
-
63
- describe("<ContextMenu />", () => {
64
- it("should render without crashing", () => {
65
- const { contextmenu } = createContextMenu();
66
-
67
- expect(contextmenu).toBeTruthy();
68
- });
69
-
70
- it("should execute onShow function", async () => {
71
- const { trigger } = createContextMenu();
72
-
73
- await userEvent.click(trigger);
74
-
75
- expect(onShow).toHaveBeenCalled();
76
- });
77
-
78
- it("should execute onClick function on ContextMenuItem", async () => {
79
- const { getByTestId } = createContextMenu(defaultParams => ({
80
- ...defaultParams,
81
- show: true
82
- }));
83
-
84
- const button = getByTestId("contextmenuitem");
85
-
86
- await userEvent.click(button);
87
-
88
- expect(onClick).toHaveBeenCalled();
89
- });
90
-
91
- it("should set active state based on value prop", async () => {
92
- const onChange = jest.fn();
93
- const { getByTestId } = createContextMenu(defaultParams => ({
94
- ...defaultParams,
95
- show: true,
96
- value: 1,
97
- onChange
98
- }));
99
-
100
- const button = getByTestId("contextmenuitem");
101
- const button1 = getByTestId("contextmenuitem2");
102
- const button2 = getByTestId("contextmenuitem3");
103
-
104
- expect(button).not.toHaveClass("active");
105
- expect(button1).toHaveClass("active");
106
- expect(button2).not.toHaveClass("active");
107
-
108
- await userEvent.click(button);
109
-
110
- expect(onChange).toHaveBeenCalled();
111
- });
112
-
113
- it("should set active state based on showActiveState ContextMenuItem prop", async () => {
114
- const onChange = jest.fn();
115
- const { getByTestId } = createContextMenu(defaultParams => ({
116
- ...defaultParams,
117
- show: true,
118
- children: [
119
- <ContextMenuItem onClick={onClick} data-testid="contextmenuitem" key="1" showActiveState>
120
- Example item 1
121
- </ContextMenuItem>,
122
- <ContextMenuItem onClick={onClick} data-testid="contextmenuitem2" key="2">
123
- Example item 2
124
- </ContextMenuItem>
125
- ]
126
- }));
127
-
128
- const button = getByTestId("contextmenuitem");
129
- const button1 = getByTestId("contextmenuitem2");
130
-
131
- expect(button).toHaveClass("active");
132
- expect(button1).not.toHaveClass("active");
133
- });
134
-
135
- it("should pass custom class to ContextMenuItem", () => {
136
- const { getByRole } = createContextMenu(defaultParams => ({
137
- ...defaultParams,
138
- show: true,
139
- children: [
140
- <ContextMenuItem data-testid="contextmenuitem" key="1" className="custom">
141
- Item 1
142
- </ContextMenuItem>
143
- ]
144
- }));
145
-
146
- const child = getByRole("menuitem");
147
-
148
- expect(child.parentElement).toHaveClass("custom");
149
- });
150
-
151
- it("should render the decorative element", () => {
152
- const { getByText } = createContextMenu(defaultParams => ({
153
- ...defaultParams,
154
- show: true,
155
- decorativeElement: <div>test</div>
156
- }));
157
-
158
- expect(getByText("test")).toBeInTheDocument();
159
- });
160
-
161
- it("should throw an error", () => {
162
- // Prevent throwing an error in the console when this test is executed. We fix this and the end of this test.
163
- const err = console.error;
164
- console.error = jest.fn();
165
-
166
- let actual;
167
-
168
- try {
169
- // @ts-ignore: mandatory props (test for non-typescript react projects)
170
- render(<ContextMenu />);
171
- } catch (e: any) {
172
- actual = e.message;
173
- }
174
-
175
- const expected = "You need to provide an ID to the context menu";
176
-
177
- expect(actual).toEqual(expected);
178
-
179
- console.error = err;
180
- });
181
- });
182
-
183
- describe("ref should work", () => {
184
- it("should give back the proper data prop, this also checks if the component propagates ...rest properly", () => {
185
- const ExampleComponent = ({
186
- propagateRef
187
- }: {
188
- propagateRef?: (ref: React.RefObject<HTMLElement>) => void;
189
- }) => {
190
- const ref = useRef(null);
191
-
192
- useEffect(() => {
193
- if (ref.current) {
194
- propagateRef && propagateRef(ref);
195
- }
196
- }, [ref]);
197
-
198
- return <ContextMenu {...defaultParams} data-ref="testing" ref={ref} />;
199
- };
200
-
201
- const refCheck = (ref: React.RefObject<HTMLElement>) => {
202
- expect(ref.current).toHaveAttribute("data-ref", "testing");
203
- };
204
-
205
- render(<ExampleComponent propagateRef={refCheck} />);
206
- });
207
- });
208
-
209
- describe("accessibility controls", () => {
210
- it("opening works correctly with arrow key down, then navigation should work with arrow keys", async () => {
211
- const { getByTestId, trigger } = createContextMenu();
212
- const firstContextMenuItem = getByTestId("contextmenuitem");
213
- const secondContextMenuItem = getByTestId("contextmenuitem2");
214
- const thirdContextMenuItem = getByTestId("contextmenuitem3");
215
-
216
- await userEvent.tab();
217
- await userEvent.keyboard("{arrowdown}");
218
- await userEvent.keyboard("{arrowdown}");
219
- expect(trigger).toHaveAttribute("aria-expanded", "true");
220
- expect(firstContextMenuItem).toHaveFocus();
221
-
222
- await userEvent.keyboard("{arrowdown}");
223
- expect(secondContextMenuItem).toHaveFocus();
224
-
225
- await userEvent.keyboard("{arrowdown}");
226
- expect(thirdContextMenuItem).toHaveFocus();
227
-
228
- await userEvent.keyboard("{arrowdown}");
229
- expect(firstContextMenuItem).toHaveFocus();
230
-
231
- await userEvent.keyboard("{arrowup}");
232
- expect(thirdContextMenuItem).toHaveFocus();
233
-
234
- await userEvent.keyboard("{arrowup}");
235
- expect(secondContextMenuItem).toHaveFocus();
236
- });
237
-
238
- it("opens correctly with enter key, closing works with escape key.", async () => {
239
- const { trigger } = createContextMenu();
240
-
241
- await userEvent.tab();
242
- await userEvent.keyboard("{enter}");
243
-
244
- expect(trigger).toHaveAttribute("aria-expanded", "true");
245
-
246
- await userEvent.keyboard("{escape}");
247
-
248
- expect(trigger).toHaveAttribute("aria-expanded", "false");
249
- });
250
-
251
- it("opens correctly with space, home and end buttons work", async () => {
252
- const { trigger, getByTestId } = createContextMenu();
253
- const firstContextMenuItem = getByTestId("contextmenuitem");
254
- const thirdContextMenuItem = getByTestId("contextmenuitem3");
255
-
256
- await userEvent.tab();
257
- await userEvent.keyboard("[space]");
258
-
259
- expect(trigger).toHaveAttribute("aria-expanded", "true");
260
-
261
- await userEvent.keyboard("{end}");
262
-
263
- expect(thirdContextMenuItem).toHaveFocus();
264
-
265
- await userEvent.keyboard("{home}");
266
-
267
- expect(firstContextMenuItem).toHaveFocus();
268
- });
269
-
270
- it("opens correctly with space, navigate with arrow keys, select with enter", async () => {
271
- onClick.mockImplementation(e => {
272
- expect(e.target.getAttribute("data-testid")).toBe("contextmenuitem3");
273
- });
274
-
275
- const { trigger, getByTestId } = createContextMenu(defaultParams => ({
276
- ...defaultParams
277
- }));
278
- const thirdContextMenuItem = getByTestId("contextmenuitem3");
279
-
280
- await userEvent.tab();
281
- await userEvent.keyboard("[space]");
282
-
283
- expect(trigger).toHaveAttribute("aria-expanded", "true");
284
-
285
- await userEvent.keyboard("{arrowdown}");
286
- await userEvent.keyboard("{arrowdown}");
287
- await userEvent.keyboard("{arrowdown}");
288
-
289
- expect(thirdContextMenuItem).toHaveFocus();
290
-
291
- await userEvent.keyboard("{enter}");
292
-
293
- expect(onClick).toHaveBeenCalled();
294
- });
295
-
296
- it("opens correctly with enter, navigate with arrow keys, select with space", async () => {
297
- onClick.mockImplementation(e => {
298
- expect(e.target.getAttribute("data-testid")).toBe("contextmenuitem3");
299
- });
300
-
301
- const { trigger, getByTestId } = createContextMenu(defaultParams => ({
302
- ...defaultParams
303
- }));
304
- const thirdContextMenuItem = getByTestId("contextmenuitem3");
305
-
306
- await userEvent.tab();
307
- await userEvent.keyboard("{enter}");
308
-
309
- expect(trigger).toHaveAttribute("aria-expanded", "true");
310
-
311
- await userEvent.keyboard("{arrowdown}");
312
- await userEvent.keyboard("{arrowdown}");
313
- await userEvent.keyboard("{arrowdown}");
314
-
315
- expect(thirdContextMenuItem).toHaveFocus();
316
-
317
- await userEvent.keyboard("[space]");
318
-
319
- expect(onClick).toHaveBeenCalled();
320
-
321
- await userEvent.keyboard("[space]");
322
-
323
- expect(thirdContextMenuItem).toHaveFocus();
324
- });
325
-
326
- it("opens correctly with enter, navigate with arrow keys skipping the decorative element", async () => {
327
- onClick.mockImplementation(e => {
328
- expect(e.target.getAttribute("data-testid")).toBe("contextmenuitem3");
329
- });
330
-
331
- const { trigger, getByTestId, getByText } = createContextMenu(defaultParams => ({
332
- ...defaultParams,
333
- decorativeElement: <div>test</div>
334
- }));
335
- const thirdContextMenuItem = getByTestId("contextmenuitem3");
336
-
337
- await userEvent.tab();
338
- await userEvent.keyboard("{enter}");
339
-
340
- expect(getByText("test")).toBeInTheDocument();
341
-
342
- expect(trigger).toHaveAttribute("aria-expanded", "true");
343
-
344
- await userEvent.keyboard("{arrowdown}");
345
- await userEvent.keyboard("{arrowdown}");
346
- await userEvent.keyboard("{arrowdown}");
347
-
348
- expect(thirdContextMenuItem).toHaveFocus();
349
-
350
- await userEvent.keyboard("[space]");
351
-
352
- expect(onClick).toHaveBeenCalled();
353
-
354
- await userEvent.keyboard("[space]");
355
-
356
- expect(thirdContextMenuItem).toHaveFocus();
357
- });
358
- });