@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,84 +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 from "react";
18
- import { Banner, Props } from "./Banner";
19
- import { render } from "@testing-library/react";
20
-
21
- const defaultParams: Props = {
22
- children: "The service will not be available between 02:00 and 03:00.",
23
- title: "Maintenance is scheduled for next weekend",
24
- type: "info"
25
- };
26
-
27
- const createBanner = (params?: (defaultParams: Props) => Props) => {
28
- let parameters: Props = defaultParams;
29
- if (params) {
30
- parameters = params(defaultParams);
31
- }
32
- const queries = render(
33
- <Banner {...parameters} data-testid="BannerTest">
34
- {defaultParams.children}
35
- </Banner>
36
- );
37
- const BannerComponent = queries.getByTestId("BannerTest");
38
-
39
- return {
40
- ...queries,
41
- BannerComponent
42
- };
43
- };
44
-
45
- describe("Banner should render", () => {
46
- it("renders without crashing", () => {
47
- const { BannerComponent } = createBanner();
48
- expect(BannerComponent).toBeDefined();
49
- const title = BannerComponent.querySelector(".headline");
50
- const content = BannerComponent.querySelector(".content");
51
- const icon = BannerComponent.querySelector(".icon");
52
- expect(BannerComponent).toHaveClass("info");
53
- expect(title).toBeDefined();
54
- expect(title).toHaveTextContent(defaultParams.title);
55
- expect(content).toBeDefined();
56
- expect(content).toHaveTextContent(defaultParams.children);
57
- expect(icon).toBeDefined();
58
- });
59
-
60
- it("renders ariaLabel correctly", () => {
61
- const ariaLabel = "Information regarding your information";
62
- const { BannerComponent } = createBanner(defaultParams => ({ ...defaultParams, ariaLabel }));
63
- expect(BannerComponent).toBeDefined();
64
- expect(BannerComponent).toHaveAttribute("aria-label", ariaLabel);
65
- });
66
-
67
- it("renders ariaLive correctly", () => {
68
- const ariaLive = "polite";
69
- const { BannerComponent } = createBanner(defaultParams => ({ ...defaultParams, ariaLive }));
70
- expect(BannerComponent).toBeDefined();
71
- expect(BannerComponent).toHaveAttribute("aria-live", ariaLive);
72
- });
73
-
74
- it("renders ariaRole correctly", () => {
75
- const ariaRole = "alert";
76
- const { BannerComponent } = createBanner(defaultParams => ({
77
- ...defaultParams,
78
- type: "error",
79
- ariaRole
80
- }));
81
- expect(BannerComponent).toBeDefined();
82
- expect(BannerComponent).toHaveAttribute("role", ariaRole);
83
- });
84
- });
@@ -1,194 +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 { BaseModal, Props } from "./BaseModal";
19
- import { render, getByText, queryByText, fireEvent } from "@testing-library/react";
20
- import userEvent from "@testing-library/user-event";
21
- import { act } from "react-dom/test-utils";
22
-
23
- const classNames = ["class11", "class12"];
24
- const containerClassNames = ["class21", "class22"];
25
-
26
- const defaultParams: Props = {
27
- id: "modal",
28
- open: true,
29
- onClose: jest.fn(),
30
- className: classNames.join(" "),
31
- containerProps: { className: containerClassNames.join(" ") },
32
- children: "This is example dialog content."
33
- };
34
-
35
- const createBaseModal = (params?: (defaultParams: Props) => Props) => {
36
- let parameters: Props = defaultParams;
37
- if (params) {
38
- parameters = params(defaultParams);
39
- }
40
- const queries = render(
41
- <BaseModal {...parameters} data-testid="BaseModal">
42
- <button>Button 1</button>
43
- <button>Button 2</button>
44
- <button>Button 3</button>
45
- <span>{defaultParams.children}</span>
46
- <button>Button 4</button>
47
- <button>Button 5</button>
48
- <button>Button 6</button>
49
- </BaseModal>
50
- );
51
- const slideInModal = queries.getByTestId("BaseModal");
52
-
53
- return {
54
- ...queries,
55
- slideInModal
56
- };
57
- };
58
-
59
- describe("BaseModal", () => {
60
- it("renders without crashing", () => {
61
- const { getByRole } = createBaseModal();
62
- const dialog = getByRole("dialog");
63
-
64
- expect(dialog).toHaveAttribute("aria-modal", "true");
65
- expect(dialog).toHaveAttribute("aria-labelledby", "modal-label");
66
- expect(dialog).toHaveAttribute("aria-describedby", "modal-description");
67
- expect(dialog).toHaveAttribute("data-hidden", "false");
68
- expect(dialog).toHaveAttribute("aria-hidden", "false");
69
- expect(getByText(dialog, defaultParams.children as string)).toBeDefined();
70
- expect(document.body).toHaveStyle("overflow: hidden");
71
- });
72
-
73
- it("should render closed modal without content", () => {
74
- const { queryByRole } = createBaseModal(params => ({ ...params, open: false }));
75
-
76
- const dialogByRole = queryByRole("dialog");
77
- const dialog = document.body.children[1] as HTMLElement;
78
-
79
- expect(dialogByRole).toBeNull();
80
- expect(dialog).toHaveAttribute("aria-hidden", "true");
81
- expect(queryByText(dialog, defaultParams.children as string)).toBeNull();
82
- });
83
-
84
- it("should render closed modal with content when forceContainerOpen is provided", () => {
85
- const { getByRole } = createBaseModal(params => ({
86
- ...params,
87
- open: false,
88
- forceContainerOpen: true
89
- }));
90
-
91
- const modal = getByRole("dialog", { hidden: true });
92
- const container = modal.querySelector(".container") as HTMLElement;
93
-
94
- expect(container).toBeInTheDocument();
95
- expect(container).toHaveAttribute("aria-hidden", "true");
96
- });
97
-
98
- it("propagates containerProps to container element", () => {
99
- const { getByRole } = createBaseModal(params => ({
100
- ...params,
101
- open: true,
102
- containerProps: {
103
- id: "container"
104
- }
105
- }));
106
-
107
- const modal = getByRole("dialog");
108
- const container = modal.querySelector(".container") as HTMLElement;
109
-
110
- expect(container).toBeInTheDocument();
111
- expect(container).toHaveAttribute("id", "container");
112
- });
113
-
114
- it("propagates backdropProps to backdrop element", () => {
115
- const { getByRole } = createBaseModal(params => ({
116
- ...params,
117
- open: true,
118
- backdropProps: {
119
- id: "backdrop"
120
- }
121
- }));
122
-
123
- const modal = getByRole("dialog");
124
- const backdrop = modal.querySelector(".backdrop") as HTMLElement;
125
-
126
- expect(backdrop).toBeInTheDocument();
127
- expect(backdrop).toHaveAttribute("id", "backdrop");
128
- });
129
-
130
- it("should handle clicking on backdrop & ESC key", async () => {
131
- const { getByRole } = createBaseModal();
132
-
133
- const modal = getByRole("dialog");
134
-
135
- const backdrop = modal.querySelector(".backdrop")!;
136
- expect(defaultParams.onClose).toHaveBeenCalledTimes(0);
137
-
138
- await userEvent.click(backdrop);
139
- expect(defaultParams.onClose).toHaveBeenCalledTimes(1);
140
-
141
- fireEvent.keyDown(modal, { key: "Escape" });
142
- expect(defaultParams.onClose).toHaveBeenCalledTimes(2);
143
- });
144
-
145
- it("should repeat focus back to the first button when tabbing through the modal", async () => {
146
- const { getByText } = createBaseModal();
147
-
148
- const firstButton = getByText("Button 1");
149
- const lastButton = getByText("Button 6");
150
-
151
- await act(() => {
152
- firstButton.focus();
153
- });
154
-
155
- await userEvent.tab();
156
- await userEvent.tab();
157
- await userEvent.tab();
158
- await userEvent.tab();
159
- await userEvent.tab();
160
- await userEvent.tab();
161
-
162
- expect(firstButton).toHaveFocus();
163
-
164
- await userEvent.tab({ shift: true });
165
-
166
- expect(lastButton).toHaveFocus();
167
- });
168
- });
169
-
170
- describe("ref should work", () => {
171
- it("should give back the proper data prop, this also checks if the component propagates ...rest properly", () => {
172
- const ExampleComponent = ({
173
- propagateRef
174
- }: {
175
- propagateRef?: (ref: React.RefObject<HTMLElement>) => void;
176
- }) => {
177
- const ref = useRef(null);
178
-
179
- useEffect(() => {
180
- if (ref.current) {
181
- propagateRef && propagateRef(ref);
182
- }
183
- }, [ref]);
184
-
185
- return <BaseModal id="test" children="test" open={true} data-ref="testing" ref={ref} />;
186
- };
187
-
188
- const refCheck = (ref: React.RefObject<HTMLElement>) => {
189
- expect(ref.current).toHaveAttribute("data-ref", "testing");
190
- };
191
-
192
- render(<ExampleComponent propagateRef={refCheck} />);
193
- });
194
- });
@@ -1,74 +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 { BaseModalActions } from "./BaseModalActions";
19
- import { render } from "@testing-library/react";
20
-
21
- describe("BaseModalActions", () => {
22
- it("renders without crashing", () => {
23
- const children = "Content";
24
- const classNames = ["class1", "class2"];
25
- const { container } = render(
26
- <BaseModalActions className={classNames.join(" ")}>{children}</BaseModalActions>
27
- );
28
-
29
- const dialogActionsContainer = container.children[0];
30
- expect(dialogActionsContainer).toHaveClass("actions", classNames[0], classNames[1]);
31
- expect(dialogActionsContainer).toHaveTextContent(children);
32
- });
33
-
34
- it("Shouldn't render cancel button if we don't pass label", () => {
35
- const { container } = render(<BaseModalActions />);
36
- const dialogActionsContainer = container.children[0];
37
- expect(dialogActionsContainer).toHaveClass("actions");
38
- expect(dialogActionsContainer).not.toHaveTextContent("Cancel");
39
- });
40
-
41
- it("Should render a cancel button with a `Close` label", () => {
42
- const cancelAction = { label: "Close" };
43
- const { container } = render(<BaseModalActions cancelAction={cancelAction} />);
44
-
45
- const dialogActionsContainer = container.children[0];
46
- expect(dialogActionsContainer).toHaveClass("actions");
47
- expect(dialogActionsContainer).toHaveTextContent(cancelAction.label);
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 <BaseModalActions onClose={jest.fn()} 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
- });
@@ -1,71 +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 { BaseModalContent, Props } from "./BaseModalContent";
19
- import { render } from "@testing-library/react";
20
- import { descriptionId } from "../BaseModalContext";
21
-
22
- const classNames = ["class1", "class2"];
23
- const initParams: Props = {
24
- id: descriptionId("modal"),
25
- className: classNames.join(" "),
26
- children: "This is example dialog content."
27
- };
28
-
29
- describe("BaseModalContent", () => {
30
- it("renders without crashing", () => {
31
- const { container } = render(<BaseModalContent {...initParams} />);
32
-
33
- const dialogContentContainer = container.children[0];
34
- expect(dialogContentContainer).toHaveClass("content", classNames[0], classNames[1]);
35
- expect(dialogContentContainer).toHaveTextContent(initParams.children as string);
36
- expect(dialogContentContainer).toEqual(document.activeElement);
37
- });
38
-
39
- describe("ref should work", () => {
40
- it("should give back the proper data prop, this also checks if the component propagates ...rest properly", () => {
41
- const ExampleComponent = ({
42
- propagateRef
43
- }: {
44
- propagateRef?: (ref: React.RefObject<HTMLElement>) => void;
45
- }) => {
46
- const ref = useRef(null);
47
-
48
- useEffect(() => {
49
- if (ref.current) {
50
- propagateRef && propagateRef(ref);
51
- }
52
- }, [ref]);
53
-
54
- return <BaseModalContent children="test" data-ref="testing" ref={ref} />;
55
- };
56
-
57
- const refCheck = (ref: React.RefObject<HTMLElement>) => {
58
- expect(ref.current).toHaveAttribute("data-ref", "testing");
59
- };
60
-
61
- render(<ExampleComponent propagateRef={refCheck} />);
62
- });
63
- });
64
-
65
- it("should renders not focused div", () => {
66
- const { container } = render(<BaseModalContent {...initParams} disableAutoFocus />);
67
-
68
- const dialogContentContainer = container.children[0];
69
- expect(dialogContentContainer).not.toEqual(document.activeElement);
70
- });
71
- });
@@ -1,74 +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 { BaseModalHeader, Props } from "./BaseModalHeader";
19
- import { render, getByRole, getByTestId, getByText } from "@testing-library/react";
20
- import { labelId } from "../BaseModalContext";
21
- import userEvent from "@testing-library/user-event";
22
-
23
- const additionalContent = "Additional content";
24
- const initParams: Props = {
25
- id: labelId("modal"),
26
- title: "Example title",
27
- onClose: jest.fn(),
28
- children: <div data-testid="additional-content">{additionalContent}</div>
29
- };
30
-
31
- describe("BaseModalHeader", () => {
32
- it("renders without crashing", async () => {
33
- const { container } = render(<BaseModalHeader {...initParams} />);
34
- const closeBtn = getByRole(container, "button");
35
- expect(initParams.onClose).toBeCalledTimes(0);
36
-
37
- await userEvent.click(closeBtn);
38
-
39
- const dialogContentContainer = container.children[0];
40
- const titleContainer = getByText(container, initParams.title);
41
- expect(dialogContentContainer).toHaveClass("header");
42
- expect(titleContainer).toHaveAttribute("id", "modal-label");
43
- expect(getByTestId(container, "additional-content")).toHaveTextContent(additionalContent);
44
- expect(initParams.onClose).toBeCalledTimes(1);
45
- });
46
- });
47
-
48
- describe("ref should work", () => {
49
- it("should give back the proper data prop, this also checks if the component propagates ...rest properly", () => {
50
- const ExampleComponent = ({
51
- propagateRef
52
- }: {
53
- propagateRef?: (ref: React.RefObject<HTMLElement>) => void;
54
- }) => {
55
- const ref = useRef(null);
56
-
57
- useEffect(() => {
58
- if (ref.current) {
59
- propagateRef && propagateRef(ref);
60
- }
61
- }, [ref]);
62
-
63
- return (
64
- <BaseModalHeader id="test" title="test" onClose={jest.fn()} data-ref="testing" ref={ref} />
65
- );
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
- });
@@ -1,118 +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 { Dialog, Props } from "./Dialog";
19
- import { render, getAllByRole } from "@testing-library/react";
20
- import userEvent from "@testing-library/user-event";
21
-
22
- const initParams: Props = {
23
- id: "modal",
24
- open: true,
25
- onClose: jest.fn(),
26
- title: "Example dialog",
27
- primaryAction: {
28
- label: "Save",
29
- onClick: jest.fn()
30
- },
31
- cancelAction: {
32
- label: "Cancel"
33
- },
34
- secondaryAction: {
35
- label: "Cancel",
36
- onClick: jest.fn()
37
- },
38
- children: "This is example dialog content."
39
- };
40
-
41
- const getButtons = (container: HTMLElement) => getAllByRole(container, "button");
42
-
43
- describe("Dialog", () => {
44
- it("renders without crashing", () => {
45
- const { getByText, debug } = render(<Dialog {...initParams} />);
46
- const [_cancelButton, secondaryButton, primaryButton] = getButtons(document.body);
47
-
48
- expect(getByText(initParams.title)).toBeDefined();
49
- expect(getByText(initParams.children as string)).toBeDefined();
50
- const actionsDiv = primaryButton.closest("div");
51
- expect(actionsDiv?.children[1]).toEqual(primaryButton);
52
- expect(actionsDiv?.children[0]).toEqual(secondaryButton);
53
- expect(primaryButton).toHaveClass("fill");
54
- expect(secondaryButton).toHaveClass("outline");
55
- });
56
-
57
- it("renders only one button", () => {
58
- render(<Dialog {...initParams} secondaryAction={undefined} />);
59
- const buttons = getButtons(document.body);
60
-
61
- expect(buttons).toHaveLength(2);
62
- expect(buttons[1]).toHaveClass("fill");
63
- });
64
-
65
- it("should handle clicking on buttons and ENTER press", async () => {
66
- render(<Dialog {...initParams} />);
67
- const [_cancelButton, secondaryButton, primaryButton] = getButtons(document.body);
68
- expect(initParams.primaryAction.onClick).toHaveBeenCalledTimes(0);
69
- expect(initParams.secondaryAction?.onClick).toHaveBeenCalledTimes(0);
70
- expect(initParams.onClose).toHaveBeenCalledTimes(0);
71
-
72
- const autoSummissionInput = document.body.querySelector("input") as HTMLElement;
73
- await userEvent.type(autoSummissionInput, "{enter}");
74
- expect(initParams.primaryAction.onClick).toHaveBeenCalledTimes(1);
75
-
76
- await userEvent.click(primaryButton);
77
- expect(initParams.primaryAction.onClick).toHaveBeenCalledTimes(2);
78
- await userEvent.click(secondaryButton);
79
- expect(initParams.secondaryAction?.onClick).toHaveBeenCalledTimes(1);
80
- });
81
- });
82
-
83
- describe("ref should work", () => {
84
- it("should give back the proper data prop, this also checks if the component propagates ...rest properly", () => {
85
- const ExampleComponent = ({
86
- propagateRef
87
- }: {
88
- propagateRef?: (ref: React.RefObject<HTMLElement>) => void;
89
- }) => {
90
- const ref = useRef(null);
91
-
92
- useEffect(() => {
93
- if (ref.current) {
94
- propagateRef && propagateRef(ref);
95
- }
96
- }, [ref]);
97
-
98
- return (
99
- <Dialog
100
- children="test"
101
- open={false}
102
- onClose={jest.fn()}
103
- primaryAction={{ label: "test", onClick: jest.fn() }}
104
- title="test"
105
- id="test"
106
- data-ref="testing"
107
- ref={ref}
108
- />
109
- );
110
- };
111
-
112
- const refCheck = (ref: React.RefObject<HTMLElement>) => {
113
- expect(ref.current).toHaveAttribute("data-ref", "testing");
114
- };
115
-
116
- render(<ExampleComponent propagateRef={refCheck} />);
117
- });
118
- });
@@ -1,61 +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 { DialogActions, Props } from "./DialogActions";
19
- import { render } from "@testing-library/react";
20
-
21
- const initParams: Props = {
22
- align: "right",
23
- children: "Content",
24
- onClose: jest.fn()
25
- };
26
-
27
- describe("DialogActions", () => {
28
- it("renders without crashing", () => {
29
- const { container } = render(<DialogActions {...initParams} />);
30
-
31
- const dialogActionsContainer = container.children[0];
32
- expect(dialogActionsContainer).toHaveClass("actions");
33
- expect(dialogActionsContainer).toHaveTextContent(initParams.children as string);
34
- });
35
- });
36
-
37
- describe("ref should work", () => {
38
- it("should give back the proper data prop, this also checks if the component propagates ...rest properly", () => {
39
- const ExampleComponent = ({
40
- propagateRef
41
- }: {
42
- propagateRef?: (ref: React.RefObject<HTMLElement>) => void;
43
- }) => {
44
- const ref = useRef(null);
45
-
46
- useEffect(() => {
47
- if (ref.current) {
48
- propagateRef && propagateRef(ref);
49
- }
50
- }, [ref]);
51
-
52
- return <DialogActions id="test" children="test" open={true} data-ref="testing" ref={ref} />;
53
- };
54
-
55
- const refCheck = (ref: React.RefObject<HTMLElement>) => {
56
- expect(ref.current).toHaveAttribute("data-ref", "testing");
57
- };
58
-
59
- render(<ExampleComponent propagateRef={refCheck} />);
60
- });
61
- });