@kaizen/components 1.61.1 → 1.61.3

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 (113) hide show
  1. package/codemods/utils/__snapshots__/transformSource.spec.ts.snap +2 -2
  2. package/dist/cjs/RichTextEditor/RichTextContent/RichTextContent.cjs +10 -1
  3. package/dist/cjs/__future__/Select/Select.cjs +1 -6
  4. package/dist/cjs/__future__/Select/subcomponents/ListBox/ListBox.cjs +1 -2
  5. package/dist/cjs/__future__/Select/subcomponents/ListBox/ListBox.module.scss.cjs +1 -2
  6. package/dist/esm/RichTextEditor/RichTextContent/RichTextContent.mjs +11 -2
  7. package/dist/esm/__future__/Select/Select.mjs +1 -6
  8. package/dist/esm/__future__/Select/subcomponents/ListBox/ListBox.mjs +1 -2
  9. package/dist/esm/__future__/Select/subcomponents/ListBox/ListBox.module.scss.mjs +1 -2
  10. package/dist/styles.css +46 -44
  11. package/package.json +6 -5
  12. package/src/Avatar/Avatar.spec.tsx +1 -1
  13. package/src/Calendar/utils/setFocusInCalendar.spec.tsx +2 -2
  14. package/src/Checkbox/Checkbox/Checkbox.spec.tsx +2 -2
  15. package/src/Collapsible/Collapsible/Collapsible.spec.tsx +2 -14
  16. package/src/Collapsible/Collapsible/_docs/Collapsible.mdx +0 -2
  17. package/src/Collapsible/Collapsible/_docs/Collapsible.stickersheet.stories.tsx +49 -0
  18. package/src/Collapsible/Collapsible/_docs/Collapsible.stories.tsx +0 -11
  19. package/src/DateInput/DateInputDescription/DateInputDescription.spec.tsx +5 -6
  20. package/src/DateInput/DateInputWithIconButton/DateInputWithIconButton.spec.tsx +4 -6
  21. package/src/DatePicker/DatePicker.spec.tsx +32 -36
  22. package/src/DatePicker/subcomponents/DateInputField/DateInputField.spec.tsx +13 -13
  23. package/src/DatePicker/utils/validateDate.spec.ts +5 -6
  24. package/src/EmptyState/EmptyState.spec.tsx +1 -1
  25. package/src/ErrorPage/ErrorPage.spec.tsx +19 -19
  26. package/src/Filter/FilterBar/FilterBar.spec.tsx +26 -26
  27. package/src/Filter/FilterBar/context/utils/updateDependentFilters.spec.ts +2 -4
  28. package/src/Filter/FilterBar/subcomponents/AddFiltersMenu/AddFiltersMenu.spec.tsx +3 -4
  29. package/src/Filter/FilterBar/subcomponents/FilterBarButton/FilterBarButton.spec.tsx +3 -6
  30. package/src/Filter/FilterBar/subcomponents/FilterBarDatePicker/FilterBarDatePicker.spec.tsx +10 -12
  31. package/src/Filter/FilterBar/subcomponents/FilterBarDateRangePicker/FilterBarDateRangePicker.spec.tsx +9 -10
  32. package/src/Filter/FilterBar/subcomponents/FilterBarMultiSelect/FilterBarMultiSelect.spec.tsx +12 -14
  33. package/src/Filter/FilterBar/subcomponents/FilterBarSelect/FilterBarSelect.spec.tsx +11 -13
  34. package/src/Filter/FilterButton/FilterButtonRemovable/FilterButtonRemovable.spec.tsx +5 -5
  35. package/src/Filter/FilterDatePicker/FilterDatePicker.spec.tsx +12 -15
  36. package/src/Filter/FilterDatePicker/hooks/useDateInputHandlers.spec.ts +12 -15
  37. package/src/Filter/FilterDatePicker/hooks/useDateValidation.spec.ts +3 -5
  38. package/src/Filter/FilterDatePicker/subcomponents/FilterDatePickerField/FilterDatePickerField.spec.tsx +23 -28
  39. package/src/Filter/FilterDatePicker/utils/getDateValidationHandler.spec.tsx +2 -6
  40. package/src/Filter/FilterDatePicker/utils/validateDate.spec.ts +5 -6
  41. package/src/Filter/FilterDateRangePicker/FilterDateRangePicker.spec.tsx +2 -3
  42. package/src/Filter/FilterDateRangePicker/_docs/FilterDateRangePicker.stickersheet.stories.tsx +27 -0
  43. package/src/Filter/FilterDateRangePicker/subcomponents/DateRangeInputField/DateRangeInputField.spec.tsx +9 -11
  44. package/src/Filter/FilterDateRangePicker/subcomponents/DateRangeValidationMessage/DateRangeValidationMessage.spec.tsx +1 -63
  45. package/src/Filter/FilterDateRangePicker/subcomponents/FilterDateRangePickerField/FilterDateRangePickerField.spec.tsx +32 -32
  46. package/src/Filter/FilterDateRangePicker/subcomponents/FilterDateRangePickerField/hooks/useEndDateValidation.spec.ts +3 -8
  47. package/src/Filter/FilterDateRangePicker/subcomponents/FilterDateRangePickerField/hooks/useStartDateValidation.spec.ts +2 -5
  48. package/src/Filter/FilterDateRangePicker/subcomponents/FilterDateRangePickerField/utils/validateEndDateBeforeStartDate.spec.ts +2 -3
  49. package/src/Filter/FilterMultiSelect/FilterMultiSelect.spec.tsx +9 -10
  50. package/src/Filter/FilterMultiSelect/context/MenuTriggerProvider/MenuTriggerProvider.spec.tsx +2 -1
  51. package/src/Filter/FilterMultiSelect/context/SelectionProvider/SelectionProvider.spec.tsx +32 -32
  52. package/src/Filter/FilterMultiSelect/subcomponents/MultiSelectOption/MultiSelectOption.spec.tsx +9 -7
  53. package/src/Filter/FilterMultiSelect/subcomponents/SearchInput/SearchInput.spec.tsx +12 -12
  54. package/src/Filter/FilterMultiSelect/subcomponents/SelectionControlButton/ClearButton/ClearButton.spec.tsx +7 -7
  55. package/src/Filter/FilterMultiSelect/subcomponents/SelectionControlButton/SelectAllButton/SelectAllButton.spec.tsx +9 -9
  56. package/src/Filter/FilterSelect/FilterSelect.spec.tsx +3 -5
  57. package/src/Heading/Heading.spec.tsx +1 -31
  58. package/src/Illustration/subcomponents/VideoPlayer/VideoPlayer.spec.tsx +43 -97
  59. package/src/Illustration/subcomponents/VideoPlayer/VideoPlayer.stickersheet.stories.tsx +68 -0
  60. package/src/Illustration/subcomponents/VideoPlayer/VideoPlayer.stories.tsx +37 -0
  61. package/src/Input/InputRange/InputRange.spec.tsx +2 -2
  62. package/src/Input/InputSearch/InputSearch.spec.tsx +3 -5
  63. package/src/KaizenProvider/KaizenProvider.spec.tsx +2 -2
  64. package/src/KaizenProvider/subcomponents/OptionalIntlProvider/OptionalIntlProvider.spec.tsx +2 -3
  65. package/src/Modal/ConfirmationModal/ConfirmationModal.spec.tsx +7 -7
  66. package/src/Modal/ContextModal/ContextModal.spec.tsx +5 -5
  67. package/src/Modal/GenericModal/GenericModal.spec.tsx +4 -4
  68. package/src/Modal/InputEditModal/InputEditModal.spec.tsx +7 -7
  69. package/src/MultiSelect/subcomponents/MultiSelectOptionField/MultiSelectOptionField.spec.tsx +3 -3
  70. package/src/MultiSelect/subcomponents/MultiSelectOptions/MultiSelectOptions.spec.tsx +3 -3
  71. package/src/MultiSelect/subcomponents/MultiSelectToggle/MultiSelectToggle.spec.tsx +2 -2
  72. package/src/MultiSelect/subcomponents/Popover/Popover.module.scss +1 -0
  73. package/src/Notification/subcomponents/GenericNotification/GenericNotification.stories.tsx +60 -0
  74. package/src/Pagination/Pagination.spec.tsx +2 -2
  75. package/src/RichTextEditor/EditableRichTextContent/EditableRichTextContent.spec.tsx +4 -4
  76. package/src/RichTextEditor/RichTextContent/RichTextContent.tsx +11 -2
  77. package/src/RichTextEditor/utils/commands/addMark.spec.ts +2 -2
  78. package/src/RichTextEditor/utils/commands/fixtures/helpers.ts +4 -3
  79. package/src/RichTextEditor/utils/commands/getMarkAttrs.spec.ts +2 -2
  80. package/src/RichTextEditor/utils/commands/getMarkRange.spec.ts +2 -2
  81. package/src/RichTextEditor/utils/commands/listIsActive.spec.ts +2 -2
  82. package/src/RichTextEditor/utils/commands/markContainsSelection.spec.ts +2 -2
  83. package/src/RichTextEditor/utils/commands/markIsActive.spec.ts +2 -2
  84. package/src/RichTextEditor/utils/commands/removeMark.spec.ts +2 -2
  85. package/src/RichTextEditor/utils/commands/updateMark.spec.ts +2 -2
  86. package/src/RichTextEditor/utils/commands/validateAndRemoveMarks.spec.ts +3 -3
  87. package/src/RichTextEditor/utils/core/createRichTextEditor.spec.ts +11 -11
  88. package/src/RichTextEditor/utils/core/hooks/useRichTextEditor.spec.tsx +2 -2
  89. package/src/SplitButton/SplitButton.spec.tsx +5 -5
  90. package/src/SplitButton/subcomponents/DropdownButton/DropdownButton.spec.tsx +3 -4
  91. package/src/Text/Text.spec.tsx +1 -57
  92. package/src/TextArea/TextArea.spec.tsx +2 -2
  93. package/src/TimeField/TimeField.spec.tsx +2 -2
  94. package/src/TitleBlockZen/TitleBlockZen.spec.tsx +36 -68
  95. package/src/TitleBlockZen/_docs/TitleBlockZen.stories.tsx +78 -8
  96. package/src/TitleBlockZen/subcomponents/MobileActions.spec.tsx +2 -2
  97. package/src/TitleBlockZen/subcomponents/NavigationTabs.spec.tsx +8 -2
  98. package/src/ToggleSwitch/ToggleSwitch/ToggleSwitch.spec.tsx +2 -2
  99. package/src/__actions__/Menu/v1/Menu.spec.tsx +2 -2
  100. package/src/__containers__/GuidanceBlock/v1/GuidanceBlock.spec.tsx +5 -5
  101. package/src/__containers__/GuidanceBlock/v2/GuidanceBlock.spec.tsx +5 -5
  102. package/src/__future__/Select/Select.spec.tsx +8 -8
  103. package/src/__future__/Select/Select.tsx +1 -10
  104. package/src/__future__/Select/subcomponents/ListBox/ListBox.module.scss +3 -3
  105. package/src/__future__/Select/subcomponents/ListBox/ListBox.tsx +1 -1
  106. package/src/__overlays__/Tooltip/v1/Tooltip.spec.tsx +1 -1
  107. package/src/__overlays__/Tooltip/v1/utils/isSemanticElement.spec.tsx +4 -9
  108. package/src/utils/useMediaQueries.spec.tsx +7 -7
  109. package/src/Heading/__snapshots__/Heading.spec.tsx.snap +0 -85
  110. package/src/Illustration/utils/usePausePlay.spec.tsx +0 -85
  111. package/src/Notification/subcomponents/GenericNotification/GenericNotification.spec.tsx +0 -76
  112. package/src/Text/__snapshots__/Text.spec.tsx.snap +0 -49
  113. package/src/__overlays__/Tooltip/v1/subcomponents/AppearanceAnim.spec.tsx +0 -39
@@ -1,13 +1,13 @@
1
1
  import React from "react"
2
2
  import { render, screen, waitFor } from "@testing-library/react"
3
3
  import userEvent from "@testing-library/user-event"
4
+ import { vi } from "vitest"
4
5
  import { ToggleSwitch, ToggleSwitchProps } from "./ToggleSwitch"
5
-
6
6
  const user = userEvent.setup()
7
7
 
8
8
  const defaultToggleSwitchProps = {
9
9
  id: "someToggleSwitchId",
10
- onToggle: jest.fn(),
10
+ onToggle: vi.fn(),
11
11
  }
12
12
 
13
13
  const renderToggleSwitch = (
@@ -23,7 +23,7 @@ describe("Dropdown", () => {
23
23
  })
24
24
 
25
25
  it("shows menu & handles onClick set by the consumer when clicking on the button", async () => {
26
- const onButtonClick = jest.fn<void, []>()
26
+ const onButtonClick = vi.fn()
27
27
 
28
28
  render(
29
29
  <Menu button={<Button label="Button" onClick={onButtonClick} />}>
@@ -42,7 +42,7 @@ describe("Dropdown", () => {
42
42
  })
43
43
  })
44
44
  it("shows menu & handles onMouseDown set by the consumer when mousing down on the button", async () => {
45
- const onMouseDown = jest.fn<void, []>()
45
+ const onMouseDown = vi.fn()
46
46
 
47
47
  render(
48
48
  <Menu button={<Button label="Button" onMouseDown={onMouseDown} />}>
@@ -1,25 +1,25 @@
1
1
  import React from "react"
2
2
  import { cleanup, render, waitFor } from "@testing-library/react"
3
3
  import userEvent from "@testing-library/user-event"
4
+ import { vi } from "vitest"
4
5
  import { Informative } from "~components/Illustration"
5
6
  import { GuidanceBlock } from "./GuidanceBlock"
6
-
7
7
  const user = userEvent.setup()
8
8
 
9
9
  // eslint-disable-next-line ssr-friendly/no-dom-globals-in-module-scope
10
- window.matchMedia = jest.fn().mockImplementation(() => ({
10
+ window.matchMedia = vi.fn().mockImplementation(() => ({
11
11
  matches: false,
12
12
  media: "",
13
13
  onchange: null,
14
- addListener: jest.fn(),
15
- removeListener: jest.fn(),
14
+ addListener: vi.fn(),
15
+ removeListener: vi.fn(),
16
16
  }))
17
17
 
18
18
  describe("GuidanceBlock", () => {
19
19
  afterEach(cleanup)
20
20
 
21
21
  it("calls the action function when action button is clicked", async () => {
22
- const onAction = jest.fn()
22
+ const onAction = vi.fn()
23
23
  const { container } = render(
24
24
  <GuidanceBlock
25
25
  illustration={<Informative alt="" />}
@@ -1,25 +1,25 @@
1
1
  import React from "react"
2
2
  import { cleanup, render, waitFor } from "@testing-library/react"
3
3
  import userEvent from "@testing-library/user-event"
4
+ import { vi } from "vitest"
4
5
  import { Informative } from "~components/Illustration"
5
6
  import { GuidanceBlock } from "./GuidanceBlock"
6
-
7
7
  const user = userEvent.setup()
8
8
 
9
9
  // eslint-disable-next-line ssr-friendly/no-dom-globals-in-module-scope
10
- window.matchMedia = jest.fn().mockImplementation(() => ({
10
+ window.matchMedia = vi.fn().mockImplementation(() => ({
11
11
  matches: false,
12
12
  media: "",
13
13
  onchange: null,
14
- addListener: jest.fn(),
15
- removeListener: jest.fn(),
14
+ addListener: vi.fn(),
15
+ removeListener: vi.fn(),
16
16
  }))
17
17
 
18
18
  describe("GuidanceBlock", () => {
19
19
  afterEach(cleanup)
20
20
 
21
21
  it("calls the action function when action button is clicked", async () => {
22
- const onAction = jest.fn()
22
+ const onAction = vi.fn()
23
23
  const { container } = render(
24
24
  <GuidanceBlock
25
25
  illustration={<Informative alt="" />}
@@ -1,9 +1,9 @@
1
1
  import React from "react"
2
2
  import { render, waitFor, screen, within } from "@testing-library/react"
3
3
  import userEvent from "@testing-library/user-event"
4
+ import { vi } from "vitest"
4
5
  import { Select, SelectProps } from "./Select"
5
6
  import { singleMockItems } from "./_docs/mockData"
6
-
7
7
  const user = userEvent.setup()
8
8
 
9
9
  const SelectWrapper = ({
@@ -87,7 +87,7 @@ describe("<Select />", () => {
87
87
  })
88
88
 
89
89
  it("fires the onOpenChange callback when the trigger is interacted", async () => {
90
- const onOpenChange = jest.fn()
90
+ const onOpenChange = vi.fn()
91
91
  const { getByRole } = render(
92
92
  <SelectWrapper
93
93
  selectedKey="batch-brew"
@@ -194,11 +194,11 @@ describe("<Select />", () => {
194
194
  })
195
195
 
196
196
  describe("Given the menu is opened", () => {
197
- it("moves the focus to the first focusable element inside the menu initially", async () => {
197
+ it("focuses the listbox initially", async () => {
198
198
  const { getByRole } = render(<SelectWrapper defaultOpen />)
199
199
  expect(getByRole("listbox")).toBeVisible()
200
200
  await waitFor(() => {
201
- expect(getByRole("option", { name: "Short black" })).toHaveFocus()
201
+ expect(getByRole("listbox")).toHaveFocus()
202
202
  })
203
203
  })
204
204
  it("is closed when hits the escape key", async () => {
@@ -267,7 +267,7 @@ describe("<Select />", () => {
267
267
 
268
268
  describe("Selection - Mouse interaction", () => {
269
269
  it("fires onSelectionChange when clicks on a option", async () => {
270
- const spy = jest.fn()
270
+ const spy = vi.fn()
271
271
  const { getByRole } = render(
272
272
  <SelectWrapper defaultOpen onSelectionChange={spy} />
273
273
  )
@@ -305,12 +305,12 @@ describe("<Select />", () => {
305
305
  })
306
306
  })
307
307
 
308
- it("keeps the focus ring at the first element when hits arrow up key on it", async () => {
308
+ it("focuses the last item in the list on up arrow press", async () => {
309
309
  const { getByRole } = render(<SelectWrapper />)
310
310
  await user.tab()
311
311
  await user.keyboard("{ArrowUp}")
312
312
  await waitFor(() => {
313
- expect(getByRole("option", { name: "Short black" })).toHaveFocus()
313
+ expect(getByRole("option", { name: "Magic" })).toHaveFocus()
314
314
  })
315
315
  })
316
316
 
@@ -335,7 +335,7 @@ describe("<Select />", () => {
335
335
  })
336
336
 
337
337
  it("fires onSelectionChange when hits enter on a option", async () => {
338
- const spy = jest.fn()
338
+ const spy = vi.fn()
339
339
  const { getByRole } = render(<SelectWrapper onSelectionChange={spy} />)
340
340
 
341
341
  await user.tab()
@@ -191,16 +191,7 @@ export const Select = <Option extends SelectOption = SelectOption>({
191
191
  trigger(selectToggleProps, selectToggleProps.ref)
192
192
  )}
193
193
  {state.isOpen && (
194
- <Popover
195
- id={popoverId}
196
- portalContainer={portalContainer}
197
- refs={refs}
198
- focusOnProps={{
199
- onEscapeKey: state.close,
200
- onClickOutside: state.close,
201
- noIsolation: true,
202
- }}
203
- >
194
+ <Popover id={popoverId} portalContainer={portalContainer} refs={refs}>
204
195
  <SelectProvider<Option> state={state}>
205
196
  <SelectPopoverContents menuProps={menuProps}>
206
197
  {children}
@@ -5,8 +5,8 @@
5
5
  padding: 0;
6
6
  display: grid;
7
7
  max-height: 22rem;
8
+ }
8
9
 
9
- &.focus {
10
- outline: none;
11
- }
10
+ .listBox:focus-visible {
11
+ outline: none;
12
12
  }
@@ -23,7 +23,7 @@ export const ListBox = <Option extends SelectOption>({
23
23
  const { state } = useSelectContext<Option>()
24
24
  const ref = React.useRef<HTMLUListElement>(null)
25
25
  const { listBoxProps } = useListBox(
26
- { ...menuProps, disallowEmptySelection: true, autoFocus: "first" },
26
+ { ...menuProps, disallowEmptySelection: true },
27
27
  state,
28
28
  ref
29
29
  )
@@ -48,7 +48,7 @@ describe("<Tooltip />", () => {
48
48
  // Non-semantic elements without roles should not have aria-description on them.
49
49
  // They won't read to all screen readers as expected and may be reported in Storybook's accessibility tab (which uses Axe under the hood)
50
50
  it("doesn't add an accessible description when wrapping a non-semantic element", async () => {
51
- const warn = jest.spyOn(console, "warn").mockImplementation()
51
+ const warn = vi.spyOn(console, "warn").mockImplementation(vi.fn())
52
52
 
53
53
  render(
54
54
  <Tooltip
@@ -1,13 +1,13 @@
1
1
  import React from "react"
2
+ import { vi } from "vitest"
2
3
  import { ArrowRightIcon } from "~components/Icon"
3
4
  import { Button, IconButton } from "~components/__actions__/v2"
4
5
  import { isSemanticElement } from "./isSemanticElement"
5
-
6
6
  describe("isSemanticElement", () => {
7
7
  it("returns true if provided a native element with a semantic role", () => {
8
8
  expect(
9
9
  isSemanticElement(
10
- <button onClick={jest.fn()} type="button">
10
+ <button onClick={vi.fn()} type="button">
11
11
  click
12
12
  </button>
13
13
  )
@@ -28,19 +28,14 @@ describe("isSemanticElement", () => {
28
28
  it("will return true if provided a non-semantic element with a semantic role", () => {
29
29
  expect(
30
30
  isSemanticElement(
31
- <span
32
- tabIndex={0}
33
- role="button"
34
- onKeyDown={jest.fn}
35
- onClick={jest.fn()}
36
- >
31
+ <span tabIndex={0} role="button" onKeyDown={vi.fn()} onClick={vi.fn()}>
37
32
  custom semantic el
38
33
  </span>
39
34
  )
40
35
  ).toBe(true)
41
36
  expect(
42
37
  isSemanticElement(
43
- <div tabIndex={0} role="button" onKeyDown={jest.fn} onClick={jest.fn()}>
38
+ <div tabIndex={0} role="button" onKeyDown={vi.fn()} onClick={vi.fn()}>
44
39
  custom semantic el
45
40
  </div>
46
41
  )
@@ -1,7 +1,7 @@
1
1
  import React from "react"
2
2
  import { render, screen } from "@testing-library/react"
3
+ import { vi } from "vitest"
3
4
  import { useMediaQueries, subtractOnePixel } from "./useMediaQueries"
4
-
5
5
  const ExampleComponent = (): JSX.Element => {
6
6
  const { queries, components } = useMediaQueries({
7
7
  prefersReducedMotion: "(prefers-reduced-motion: reduce)",
@@ -27,15 +27,15 @@ const ExampleComponent = (): JSX.Element => {
27
27
  export const mockMatchMedia = (matches: boolean = false): void => {
28
28
  Object.defineProperty(window, "matchMedia", {
29
29
  writable: true,
30
- value: jest.fn().mockImplementation(query => ({
30
+ value: vi.fn().mockImplementation(query => ({
31
31
  matches,
32
32
  media: query,
33
33
  onchange: null,
34
- addListener: jest.fn(), // Deprecated
35
- removeListener: jest.fn(), // Deprecated
36
- addEventListener: jest.fn(),
37
- removeEventListener: jest.fn(),
38
- dispatchEvent: jest.fn(),
34
+ addListener: vi.fn(), // Deprecated
35
+ removeListener: vi.fn(), // Deprecated
36
+ addEventListener: vi.fn(),
37
+ removeEventListener: vi.fn(),
38
+ dispatchEvent: vi.fn(),
39
39
  })),
40
40
  })
41
41
  }
@@ -1,85 +0,0 @@
1
- // Jest Snapshot v1, https://goo.gl/fbAQLP
2
-
3
- exports[`<Heading /> defaults to the correct HTML element renders the correct element for <Heading variant={display-0} /> 1`] = `
4
- <body>
5
- <div>
6
- <h1
7
- class="heading display-0 dark large"
8
- >
9
- Example
10
- </h1>
11
- </div>
12
- </body>
13
- `;
14
-
15
- exports[`<Heading /> defaults to the correct HTML element renders the correct element for <Heading variant={heading-1} /> 1`] = `
16
- <body>
17
- <div>
18
- <h1
19
- class="heading heading-1 dark large"
20
- >
21
- Example
22
- </h1>
23
- </div>
24
- </body>
25
- `;
26
-
27
- exports[`<Heading /> defaults to the correct HTML element renders the correct element for <Heading variant={heading-2} /> 1`] = `
28
- <body>
29
- <div>
30
- <h2
31
- class="heading heading-2 dark large"
32
- >
33
- Example
34
- </h2>
35
- </div>
36
- </body>
37
- `;
38
-
39
- exports[`<Heading /> defaults to the correct HTML element renders the correct element for <Heading variant={heading-3} /> 1`] = `
40
- <body>
41
- <div>
42
- <h3
43
- class="heading heading-3 dark small"
44
- >
45
- Example
46
- </h3>
47
- </div>
48
- </body>
49
- `;
50
-
51
- exports[`<Heading /> defaults to the correct HTML element renders the correct element for <Heading variant={heading-4} /> 1`] = `
52
- <body>
53
- <div>
54
- <h4
55
- class="heading heading-4 dark small"
56
- >
57
- Example
58
- </h4>
59
- </div>
60
- </body>
61
- `;
62
-
63
- exports[`<Heading /> defaults to the correct HTML element renders the correct element for <Heading variant={heading-5} /> 1`] = `
64
- <body>
65
- <div>
66
- <h5
67
- class="heading heading-5 dark small"
68
- >
69
- Example
70
- </h5>
71
- </div>
72
- </body>
73
- `;
74
-
75
- exports[`<Heading /> defaults to the correct HTML element renders the correct element for <Heading variant={heading-6} /> 1`] = `
76
- <body>
77
- <div>
78
- <h6
79
- class="heading heading-6 dark small"
80
- >
81
- Example
82
- </h6>
83
- </div>
84
- </body>
85
- `;
@@ -1,85 +0,0 @@
1
- import React, { RefObject, act } from "react"
2
- import { render, renderHook } from "@testing-library/react"
3
- import { LaunchIcon, PauseIcon } from "~components/Icon"
4
- import { usePausePlay, usePausePlayHook } from "./usePausePlay"
5
-
6
- describe("usePausePlay()", () => {
7
- beforeEach(() => {
8
- jest.clearAllMocks()
9
- })
10
-
11
- let hookResult: usePausePlayHook
12
- const mockPause = jest.fn()
13
- const mockPlay = jest.fn()
14
-
15
- describe("when toggling a currently playing video", () => {
16
- beforeEach(() => {
17
- const fakeRef = {
18
- current: {
19
- pause: mockPause,
20
- play: mockPlay,
21
- paused: false, // It's playing
22
- },
23
- } as unknown as RefObject<HTMLVideoElement>
24
-
25
- const { result } = renderHook(() => usePausePlay(fakeRef))
26
-
27
- act(() => {
28
- result.current.toggle()
29
- })
30
-
31
- hookResult = result.current
32
- })
33
-
34
- it("pauses the video", () => {
35
- expect(mockPause).toHaveBeenCalled()
36
- })
37
-
38
- it("returns the play icon", () => {
39
- const { baseElement: original } = render(hookResult.icon)
40
- const { baseElement: comparison } = render(
41
- <LaunchIcon role="presentation" />
42
- )
43
- expect(original).toEqual(comparison)
44
- })
45
-
46
- it("returns the 'Play animation' label", () => {
47
- expect(hookResult.label).toEqual("Play animation")
48
- })
49
- })
50
-
51
- describe("when toggling a currently paused video", () => {
52
- beforeEach(() => {
53
- const fakeRef = {
54
- current: {
55
- pause: mockPause,
56
- play: mockPlay,
57
- paused: true, // It's not playing
58
- },
59
- } as unknown as RefObject<HTMLVideoElement>
60
-
61
- const { result } = renderHook(() => usePausePlay(fakeRef))
62
-
63
- act(() => {
64
- result.current.toggle()
65
- })
66
-
67
- hookResult = result.current
68
- })
69
- it("starts the video again", () => {
70
- expect(mockPlay).toHaveBeenCalled()
71
- })
72
-
73
- it("returns the pause icon", () => {
74
- const { baseElement: original } = render(hookResult.icon)
75
- const { baseElement: comparison } = render(
76
- <PauseIcon role="presentation" />
77
- )
78
- expect(original).toEqual(comparison)
79
- })
80
-
81
- it("returns the 'Pause animation' label", () => {
82
- expect(hookResult.label).toEqual("Pause animation")
83
- })
84
- })
85
- })
@@ -1,76 +0,0 @@
1
- import React, { act } from "react"
2
- import { fireEvent, waitFor } from "@testing-library/dom"
3
- import { render } from "@testing-library/react"
4
- import ReactTestUtils from "react-dom/test-utils"
5
- import { GenericNotification } from "./GenericNotification"
6
-
7
- describe("<GenericNotification />", () => {
8
- afterEach(() => {
9
- jest.runAllTimers()
10
- })
11
-
12
- beforeEach(() => {
13
- jest.useFakeTimers()
14
- })
15
-
16
- it('begins "hidden" but transitions out of it immediately', async () => {
17
- const { container } = render(
18
- <GenericNotification type="positive" style="inline" title="Success">
19
- This is my positive notification
20
- </GenericNotification>
21
- )
22
-
23
- await waitFor(() => {
24
- expect(container.querySelector(".hidden")).toBeInTheDocument()
25
- })
26
-
27
- await act(async () => {
28
- jest.advanceTimersByTime(50)
29
- })
30
-
31
- await waitFor(() => {
32
- expect(container.querySelector(".hidden")).not.toBeInTheDocument()
33
- })
34
- })
35
-
36
- it("hides the notification and triggers the onHide callback when the cancel button is clicked", async () => {
37
- const onHide = jest.fn()
38
- const { container, getByTestId } = render(
39
- <GenericNotification
40
- type="positive"
41
- style="inline"
42
- title="Success"
43
- onHide={onHide}
44
- >
45
- Notification Text
46
- </GenericNotification>
47
- )
48
-
49
- // The element should start in a "hidden" state
50
- expect(container.querySelector(".hidden")).toBeTruthy()
51
-
52
- // After clicking, the element should fade out, but the onHide not trigger yet.
53
- const cancelButton = getByTestId("close-button")
54
- const notification = container.querySelector(".notification")
55
-
56
- fireEvent(cancelButton, new MouseEvent("click"))
57
-
58
- await waitFor(() => {
59
- expect(notification).toBeTruthy()
60
- })
61
-
62
- // Cannot use @testing-library/react `fireEvent` as it relies on jsdom events
63
- // TransitionEvent has not been implemented yet, using `ReactTestUtils.Simulate` is a workaround
64
- act(() => {
65
- notification &&
66
- ReactTestUtils.Simulate.transitionEnd(notification, {
67
- propertyName: "margin-top",
68
- } as any)
69
- })
70
-
71
- await waitFor(() => {
72
- expect(notification).not.toBeInTheDocument()
73
- })
74
- await waitFor(() => expect(onHide).toHaveBeenCalledTimes(1))
75
- })
76
- })
@@ -1,49 +0,0 @@
1
- // Jest Snapshot v1, https://goo.gl/fbAQLP
2
-
3
- exports[`<Text /> defaults to the correct HTML element renders the correct element for <Text variant={body} /> 1`] = `
4
- <body>
5
- <div>
6
- <p
7
- class="text body dark"
8
- >
9
- Example
10
- </p>
11
- </div>
12
- </body>
13
- `;
14
-
15
- exports[`<Text /> defaults to the correct HTML element renders the correct element for <Text variant={extra-small} /> 1`] = `
16
- <body>
17
- <div>
18
- <p
19
- class="text extra-small dark"
20
- >
21
- Example
22
- </p>
23
- </div>
24
- </body>
25
- `;
26
-
27
- exports[`<Text /> defaults to the correct HTML element renders the correct element for <Text variant={intro-lede} /> 1`] = `
28
- <body>
29
- <div>
30
- <p
31
- class="text intro-lede dark"
32
- >
33
- Example
34
- </p>
35
- </div>
36
- </body>
37
- `;
38
-
39
- exports[`<Text /> defaults to the correct HTML element renders the correct element for <Text variant={small} /> 1`] = `
40
- <body>
41
- <div>
42
- <p
43
- class="text small dark"
44
- >
45
- Example
46
- </p>
47
- </div>
48
- </body>
49
- `;
@@ -1,39 +0,0 @@
1
- import React from "react"
2
- import { render } from "@testing-library/react"
3
- import useDebounce from "use-debounce"
4
- import { AnimationProvider } from "./AppearanceAnim"
5
-
6
- jest.mock("use-debounce")
7
-
8
- const useDebouncedCallback = useDebounce.useDebouncedCallback as jest.Mock
9
- let mockReturnValue: Record<string, any>
10
-
11
- describe("<AnimationProvider />", () => {
12
- beforeEach(() => {
13
- mockReturnValue = jest.fn()
14
- mockReturnValue.cancel = (): void => undefined
15
- useDebouncedCallback.mockImplementation(() => mockReturnValue)
16
- })
17
-
18
- describe("When no animationDuration prop is given", () => {
19
- it("calls useDebouncedCallback with a 400 ms delay", () => {
20
- render(<AnimationProvider isVisible />)
21
- expect(useDebouncedCallback).toHaveBeenCalledWith(
22
- expect.anything(),
23
- 400,
24
- expect.anything()
25
- )
26
- })
27
- })
28
- describe("When an animationDuration prop is given", () => {
29
- it("calls useDebouncedCallback with the animationDuration value", () => {
30
- const expected = 1000
31
- render(<AnimationProvider isVisible animationDuration={expected} />)
32
- expect(useDebouncedCallback).toHaveBeenCalledWith(
33
- expect.anything(),
34
- expected,
35
- expect.anything()
36
- )
37
- })
38
- })
39
- })