@kaizen/components 1.61.0 → 1.61.2
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.
- package/codemods/utils/__snapshots__/transformSource.spec.ts.snap +2 -2
- package/dist/cjs/RichTextEditor/RichTextContent/RichTextContent.cjs +10 -1
- package/dist/esm/RichTextEditor/RichTextContent/RichTextContent.mjs +11 -2
- package/dist/styles.css +115 -114
- package/package.json +5 -4
- package/src/Avatar/Avatar.spec.tsx +1 -1
- package/src/Calendar/utils/setFocusInCalendar.spec.tsx +2 -2
- package/src/Checkbox/Checkbox/Checkbox.spec.tsx +2 -2
- package/src/Collapsible/Collapsible/Collapsible.spec.tsx +2 -14
- package/src/Collapsible/Collapsible/_docs/Collapsible.stickersheet.stories.tsx +49 -0
- package/src/Collapsible/Collapsible/_docs/Collapsible.stories.tsx +0 -11
- package/src/DateInput/DateInputDescription/DateInputDescription.spec.tsx +5 -6
- package/src/DateInput/DateInputWithIconButton/DateInputWithIconButton.spec.tsx +4 -6
- package/src/DatePicker/DatePicker.spec.tsx +32 -36
- package/src/DatePicker/subcomponents/DateInputField/DateInputField.spec.tsx +13 -13
- package/src/DatePicker/utils/validateDate.spec.ts +5 -6
- package/src/EmptyState/EmptyState.spec.tsx +1 -1
- package/src/ErrorPage/ErrorPage.spec.tsx +19 -19
- package/src/Filter/FilterBar/FilterBar.spec.tsx +26 -26
- package/src/Filter/FilterBar/context/utils/updateDependentFilters.spec.ts +2 -4
- package/src/Filter/FilterBar/subcomponents/AddFiltersMenu/AddFiltersMenu.spec.tsx +3 -4
- package/src/Filter/FilterBar/subcomponents/FilterBarButton/FilterBarButton.spec.tsx +3 -6
- package/src/Filter/FilterBar/subcomponents/FilterBarDatePicker/FilterBarDatePicker.spec.tsx +10 -12
- package/src/Filter/FilterBar/subcomponents/FilterBarDateRangePicker/FilterBarDateRangePicker.spec.tsx +9 -10
- package/src/Filter/FilterBar/subcomponents/FilterBarMultiSelect/FilterBarMultiSelect.spec.tsx +12 -14
- package/src/Filter/FilterBar/subcomponents/FilterBarSelect/FilterBarSelect.spec.tsx +11 -13
- package/src/Filter/FilterButton/FilterButtonRemovable/FilterButtonRemovable.spec.tsx +5 -5
- package/src/Filter/FilterDatePicker/FilterDatePicker.spec.tsx +12 -15
- package/src/Filter/FilterDatePicker/hooks/useDateInputHandlers.spec.ts +12 -15
- package/src/Filter/FilterDatePicker/hooks/useDateValidation.spec.ts +3 -5
- package/src/Filter/FilterDatePicker/subcomponents/FilterDatePickerField/FilterDatePickerField.spec.tsx +23 -28
- package/src/Filter/FilterDatePicker/utils/getDateValidationHandler.spec.tsx +2 -6
- package/src/Filter/FilterDatePicker/utils/validateDate.spec.ts +5 -6
- package/src/Filter/FilterDateRangePicker/FilterDateRangePicker.spec.tsx +2 -3
- package/src/Filter/FilterDateRangePicker/_docs/FilterDateRangePicker.stickersheet.stories.tsx +27 -0
- package/src/Filter/FilterDateRangePicker/subcomponents/DateRangeInputField/DateRangeInputField.spec.tsx +9 -11
- package/src/Filter/FilterDateRangePicker/subcomponents/DateRangeValidationMessage/DateRangeValidationMessage.spec.tsx +1 -63
- package/src/Filter/FilterDateRangePicker/subcomponents/FilterDateRangePickerField/FilterDateRangePickerField.spec.tsx +32 -32
- package/src/Filter/FilterDateRangePicker/subcomponents/FilterDateRangePickerField/hooks/useEndDateValidation.spec.ts +3 -8
- package/src/Filter/FilterDateRangePicker/subcomponents/FilterDateRangePickerField/hooks/useStartDateValidation.spec.ts +2 -5
- package/src/Filter/FilterDateRangePicker/subcomponents/FilterDateRangePickerField/utils/validateEndDateBeforeStartDate.spec.ts +2 -3
- package/src/Filter/FilterMultiSelect/FilterMultiSelect.spec.tsx +9 -10
- package/src/Filter/FilterMultiSelect/context/MenuTriggerProvider/MenuTriggerProvider.spec.tsx +2 -1
- package/src/Filter/FilterMultiSelect/context/SelectionProvider/SelectionProvider.spec.tsx +32 -32
- package/src/Filter/FilterMultiSelect/subcomponents/MultiSelectOption/MultiSelectOption.spec.tsx +9 -7
- package/src/Filter/FilterMultiSelect/subcomponents/SearchInput/SearchInput.spec.tsx +12 -12
- package/src/Filter/FilterMultiSelect/subcomponents/SelectionControlButton/ClearButton/ClearButton.spec.tsx +7 -7
- package/src/Filter/FilterMultiSelect/subcomponents/SelectionControlButton/SelectAllButton/SelectAllButton.spec.tsx +9 -9
- package/src/Filter/FilterSelect/FilterSelect.spec.tsx +2 -2
- package/src/Heading/Heading.spec.tsx +1 -31
- package/src/Illustration/subcomponents/VideoPlayer/VideoPlayer.spec.tsx +43 -97
- package/src/Illustration/subcomponents/VideoPlayer/VideoPlayer.stickersheet.stories.tsx +68 -0
- package/src/Illustration/subcomponents/VideoPlayer/VideoPlayer.stories.tsx +37 -0
- package/src/Input/InputRange/InputRange.spec.tsx +2 -2
- package/src/Input/InputSearch/InputSearch.spec.tsx +3 -5
- package/src/KaizenProvider/KaizenProvider.spec.tsx +2 -2
- package/src/KaizenProvider/subcomponents/OptionalIntlProvider/OptionalIntlProvider.spec.tsx +2 -3
- package/src/Modal/ConfirmationModal/ConfirmationModal.spec.tsx +7 -7
- package/src/Modal/ContextModal/ContextModal.spec.tsx +5 -5
- package/src/Modal/GenericModal/GenericModal.spec.tsx +4 -4
- package/src/Modal/InputEditModal/InputEditModal.spec.tsx +7 -7
- package/src/MultiSelect/subcomponents/MultiSelectOptionField/MultiSelectOptionField.spec.tsx +3 -3
- package/src/MultiSelect/subcomponents/MultiSelectOptions/MultiSelectOptions.spec.tsx +3 -3
- package/src/MultiSelect/subcomponents/MultiSelectToggle/MultiSelectToggle.spec.tsx +2 -2
- package/src/Notification/subcomponents/GenericNotification/GenericNotification.stories.tsx +60 -0
- package/src/Pagination/Pagination.spec.tsx +2 -2
- package/src/RichTextEditor/EditableRichTextContent/EditableRichTextContent.spec.tsx +4 -4
- package/src/RichTextEditor/RichTextContent/RichTextContent.tsx +11 -2
- package/src/RichTextEditor/utils/commands/addMark.spec.ts +2 -2
- package/src/RichTextEditor/utils/commands/fixtures/helpers.ts +4 -3
- package/src/RichTextEditor/utils/commands/getMarkAttrs.spec.ts +2 -2
- package/src/RichTextEditor/utils/commands/getMarkRange.spec.ts +2 -2
- package/src/RichTextEditor/utils/commands/listIsActive.spec.ts +2 -2
- package/src/RichTextEditor/utils/commands/markContainsSelection.spec.ts +2 -2
- package/src/RichTextEditor/utils/commands/markIsActive.spec.ts +2 -2
- package/src/RichTextEditor/utils/commands/removeMark.spec.ts +2 -2
- package/src/RichTextEditor/utils/commands/updateMark.spec.ts +2 -2
- package/src/RichTextEditor/utils/commands/validateAndRemoveMarks.spec.ts +3 -3
- package/src/RichTextEditor/utils/core/createRichTextEditor.spec.ts +11 -11
- package/src/RichTextEditor/utils/core/hooks/useRichTextEditor.spec.tsx +2 -2
- package/src/SplitButton/SplitButton.spec.tsx +5 -5
- package/src/SplitButton/subcomponents/DropdownButton/DropdownButton.spec.tsx +3 -4
- package/src/Text/Text.spec.tsx +1 -57
- package/src/TextArea/TextArea.spec.tsx +2 -2
- package/src/TimeField/TimeField.spec.tsx +2 -2
- package/src/TitleBlockZen/TitleBlockZen.spec.tsx +36 -68
- package/src/TitleBlockZen/_docs/TitleBlockZen.stories.tsx +78 -8
- package/src/TitleBlockZen/subcomponents/MobileActions.spec.tsx +2 -2
- package/src/TitleBlockZen/subcomponents/NavigationTabs.spec.tsx +8 -2
- package/src/ToggleSwitch/ToggleSwitch/ToggleSwitch.spec.tsx +2 -2
- package/src/__actions__/Menu/v1/Menu.spec.tsx +2 -2
- package/src/__containers__/GuidanceBlock/v1/GuidanceBlock.spec.tsx +5 -5
- package/src/__containers__/GuidanceBlock/v2/GuidanceBlock.spec.tsx +5 -5
- package/src/__future__/Select/Select.spec.tsx +4 -4
- package/src/__layout__/Workflow/v3/_docs/Workflow.stories.tsx +8 -2
- package/src/__layout__/Workflow/v3/subcomponents/Footer/components/Root/FooterRoot.module.css +1 -0
- package/src/__layout__/Workflow/v3/subcomponents/Header/components/Root/Root.module.css +1 -1
- package/src/__overlays__/Tooltip/v1/Tooltip.spec.tsx +1 -1
- package/src/__overlays__/Tooltip/v1/utils/isSemanticElement.spec.tsx +4 -9
- package/src/utils/useMediaQueries.spec.tsx +7 -7
- package/src/Heading/__snapshots__/Heading.spec.tsx.snap +0 -85
- package/src/Illustration/utils/usePausePlay.spec.tsx +0 -85
- package/src/Notification/subcomponents/GenericNotification/GenericNotification.spec.tsx +0 -76
- package/src/Text/__snapshots__/Text.spec.tsx.snap +0 -49
- package/src/__overlays__/Tooltip/v1/subcomponents/AppearanceAnim.spec.tsx +0 -39
package/src/Filter/FilterMultiSelect/subcomponents/MultiSelectOption/MultiSelectOption.spec.tsx
CHANGED
|
@@ -3,14 +3,16 @@
|
|
|
3
3
|
import React from "react"
|
|
4
4
|
import { useOption } from "@react-aria/listbox"
|
|
5
5
|
import { render, screen } from "@testing-library/react"
|
|
6
|
+
import { vi, beforeEach, Mock } from "vitest"
|
|
6
7
|
import { ItemType } from "../../types"
|
|
7
8
|
import { MultiSelectOption, MultiSelectOptionProps } from "./MultiSelectOption"
|
|
9
|
+
import styles from "./MultiSelectOption.module.scss"
|
|
8
10
|
|
|
9
|
-
|
|
10
|
-
useOption:
|
|
11
|
+
vi.mock("@react-aria/listbox", () => ({
|
|
12
|
+
useOption: vi.fn(),
|
|
11
13
|
}))
|
|
12
14
|
|
|
13
|
-
|
|
15
|
+
vi.mock("../../context", () => ({
|
|
14
16
|
useSelectionContext: (): { selectionState: Record<string, unknown> } => ({
|
|
15
17
|
selectionState: {},
|
|
16
18
|
}),
|
|
@@ -36,7 +38,7 @@ const MultiSelectOptionWrapper = ({
|
|
|
36
38
|
describe("<MultiSelectOptionWrapper /> - Visual content", () => {
|
|
37
39
|
describe("Given item is unselected", () => {
|
|
38
40
|
beforeEach(() => {
|
|
39
|
-
;(useOption as
|
|
41
|
+
;(useOption as Mock).mockReturnValue({
|
|
40
42
|
optionProps: {},
|
|
41
43
|
isSelected: false,
|
|
42
44
|
isDisabled: false,
|
|
@@ -56,7 +58,7 @@ describe("<MultiSelectOptionWrapper /> - Visual content", () => {
|
|
|
56
58
|
|
|
57
59
|
describe("Given item is disabled", () => {
|
|
58
60
|
beforeEach(() => {
|
|
59
|
-
;(useOption as
|
|
61
|
+
;(useOption as Mock).mockReturnValue({
|
|
60
62
|
optionProps: {},
|
|
61
63
|
isSelected: false,
|
|
62
64
|
isDisabled: true,
|
|
@@ -66,13 +68,13 @@ describe("<MultiSelectOptionWrapper /> - Visual content", () => {
|
|
|
66
68
|
|
|
67
69
|
it("has a disabled class", () => {
|
|
68
70
|
const label = screen.getByLabelText("label-mock")
|
|
69
|
-
expect(label).toHaveClass(
|
|
71
|
+
expect(label).toHaveClass(styles.isDisabled)
|
|
70
72
|
})
|
|
71
73
|
})
|
|
72
74
|
|
|
73
75
|
describe("Given count is provided", () => {
|
|
74
76
|
beforeEach(() => {
|
|
75
|
-
;(useOption as
|
|
77
|
+
;(useOption as Mock).mockReturnValue({
|
|
76
78
|
optionProps: {},
|
|
77
79
|
isSelected: false,
|
|
78
80
|
isDisabled: false,
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import React from "react"
|
|
2
|
-
import { screen, waitFor } from "@testing-library/react"
|
|
2
|
+
import { screen, waitFor, render } from "@testing-library/react"
|
|
3
3
|
import userEvent from "@testing-library/user-event"
|
|
4
|
-
import {
|
|
4
|
+
import { vi, Mock } from "vitest"
|
|
5
5
|
import { useSelectionContext } from "../../context"
|
|
6
6
|
import { SearchInput } from "."
|
|
7
7
|
|
|
8
8
|
const user = userEvent.setup()
|
|
9
9
|
|
|
10
|
-
|
|
11
|
-
useSelectionContext:
|
|
10
|
+
vi.mock("../../context", () => ({
|
|
11
|
+
useSelectionContext: vi.fn(),
|
|
12
12
|
}))
|
|
13
13
|
|
|
14
14
|
const SearchInputWrapper = (): JSX.Element => <SearchInput label="label-mock" />
|
|
@@ -16,10 +16,10 @@ const SearchInputWrapper = (): JSX.Element => <SearchInput label="label-mock" />
|
|
|
16
16
|
describe("<SearchInput /> - interaction", () => {
|
|
17
17
|
describe("Given searchQuery is provided", () => {
|
|
18
18
|
it("shows searchQuery as value", async () => {
|
|
19
|
-
;(useSelectionContext as
|
|
19
|
+
;(useSelectionContext as Mock).mockReturnValue({
|
|
20
20
|
searchQuery: "search-query-mock",
|
|
21
21
|
})
|
|
22
|
-
|
|
22
|
+
render(<SearchInputWrapper />)
|
|
23
23
|
await waitFor(() => {
|
|
24
24
|
expect(screen.getByRole("searchbox")).toHaveValue("search-query-mock")
|
|
25
25
|
})
|
|
@@ -27,12 +27,12 @@ describe("<SearchInput /> - interaction", () => {
|
|
|
27
27
|
})
|
|
28
28
|
|
|
29
29
|
it("triggers setSearchQuery with input value when user types the input", async () => {
|
|
30
|
-
const spy =
|
|
31
|
-
;(useSelectionContext as
|
|
30
|
+
const spy = vi.fn()
|
|
31
|
+
;(useSelectionContext as Mock).mockReturnValue({
|
|
32
32
|
setSearchQuery: spy,
|
|
33
33
|
})
|
|
34
34
|
|
|
35
|
-
|
|
35
|
+
render(<SearchInputWrapper />)
|
|
36
36
|
const search = screen.getByRole("searchbox")
|
|
37
37
|
await user.type(search, "want to search this text")
|
|
38
38
|
|
|
@@ -40,13 +40,13 @@ describe("<SearchInput /> - interaction", () => {
|
|
|
40
40
|
})
|
|
41
41
|
|
|
42
42
|
it("triggers setSearchQuery with input value when clear the input", async () => {
|
|
43
|
-
const spy =
|
|
44
|
-
;(useSelectionContext as
|
|
43
|
+
const spy = vi.fn()
|
|
44
|
+
;(useSelectionContext as Mock).mockReturnValue({
|
|
45
45
|
searchQuery: "search-query-mock",
|
|
46
46
|
setSearchQuery: spy,
|
|
47
47
|
})
|
|
48
48
|
|
|
49
|
-
|
|
49
|
+
render(<SearchInputWrapper />)
|
|
50
50
|
const clearButton = screen.getByRole("button")
|
|
51
51
|
await user.click(clearButton)
|
|
52
52
|
|
|
@@ -1,24 +1,24 @@
|
|
|
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 { Mock, vi } from "vitest"
|
|
4
5
|
import { useSelectionContext } from "../../../context"
|
|
5
6
|
import { ClearButton } from "."
|
|
6
|
-
|
|
7
7
|
const user = userEvent.setup()
|
|
8
8
|
|
|
9
|
-
|
|
10
|
-
useSelectionContext:
|
|
9
|
+
vi.mock("../../../context", () => ({
|
|
10
|
+
useSelectionContext: vi.fn(),
|
|
11
11
|
}))
|
|
12
12
|
|
|
13
13
|
describe("<ClearButton /> - interaction", () => {
|
|
14
14
|
describe("Given selection is not empty", () => {
|
|
15
15
|
it("triggers selectionManager.selSelectedKeys() with focused keys filtered out when button is clicked", async () => {
|
|
16
|
-
const spy =
|
|
16
|
+
const spy = vi.fn()
|
|
17
17
|
const selectedAndFocused = "selectedAndFocused"
|
|
18
18
|
const selectedButNotFocused = "selectedButNotFocused"
|
|
19
19
|
const selectedKeys: string[] = [selectedAndFocused, selectedButNotFocused]
|
|
20
20
|
const filteredKeys: string[] = [selectedAndFocused]
|
|
21
|
-
;(useSelectionContext as
|
|
21
|
+
;(useSelectionContext as Mock).mockReturnValue({
|
|
22
22
|
selectionState: {
|
|
23
23
|
collection: {
|
|
24
24
|
getKeys: () => filteredKeys,
|
|
@@ -43,10 +43,10 @@ describe("<ClearButton /> - interaction", () => {
|
|
|
43
43
|
|
|
44
44
|
describe("Given selection is empty", () => {
|
|
45
45
|
it("does not trigger selectionManager.setSelectedKeys() when clicks on the button", async () => {
|
|
46
|
-
const spy =
|
|
46
|
+
const spy = vi.fn()
|
|
47
47
|
const filteredKeys: string[] = []
|
|
48
48
|
const selectedKeys: string[] = []
|
|
49
|
-
;(useSelectionContext as
|
|
49
|
+
;(useSelectionContext as Mock).mockReturnValue({
|
|
50
50
|
selectionState: {
|
|
51
51
|
collection: {
|
|
52
52
|
getKeys: () => filteredKeys,
|
|
@@ -1,26 +1,26 @@
|
|
|
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 { Mock, vi } from "vitest"
|
|
4
5
|
import { useSelectionContext } from "../../../context"
|
|
5
6
|
import { SelectAllButton } from "."
|
|
6
|
-
|
|
7
7
|
const user = userEvent.setup()
|
|
8
8
|
|
|
9
|
-
|
|
10
|
-
useSelectionContext:
|
|
9
|
+
vi.mock("../../../context", () => ({
|
|
10
|
+
useSelectionContext: vi.fn(),
|
|
11
11
|
}))
|
|
12
12
|
|
|
13
13
|
describe("<SelectAllButton /> - interaction", () => {
|
|
14
14
|
describe("Given not all options are selected", () => {
|
|
15
15
|
it("triggers selectionManager.setSelectedKeys() with currently selected and filtered options when button is clicked", async () => {
|
|
16
|
-
const spy =
|
|
16
|
+
const spy = vi.fn()
|
|
17
17
|
const selectedAndFiltered = "selectedAndFiltered"
|
|
18
18
|
const filteredButNotSelected = "focusedButNotSelected"
|
|
19
19
|
const selectedButNotFiltered = "selectedButNotFiltered"
|
|
20
20
|
const selectedKeys = [selectedAndFiltered, selectedButNotFiltered]
|
|
21
21
|
const filteredKeys = [selectedAndFiltered, filteredButNotSelected]
|
|
22
22
|
|
|
23
|
-
;(useSelectionContext as
|
|
23
|
+
;(useSelectionContext as Mock).mockReturnValue({
|
|
24
24
|
selectionState: {
|
|
25
25
|
collection: {
|
|
26
26
|
getKeys: () => filteredKeys,
|
|
@@ -45,12 +45,12 @@ describe("<SelectAllButton /> - interaction", () => {
|
|
|
45
45
|
|
|
46
46
|
describe("Given all filtered options are selected", () => {
|
|
47
47
|
it("does not trigger selectionManager.setSelectedKeys() when clicks on the button", async () => {
|
|
48
|
-
const spy =
|
|
48
|
+
const spy = vi.fn()
|
|
49
49
|
const selectedAndFiltered1 = "selectedAndFiltered1"
|
|
50
50
|
const selectedAndFiltered2 = "selectedAndFocused2"
|
|
51
51
|
const selectedKeys = [selectedAndFiltered1, selectedAndFiltered2]
|
|
52
52
|
const filteredKeys = [selectedAndFiltered1, selectedAndFiltered2]
|
|
53
|
-
;(useSelectionContext as
|
|
53
|
+
;(useSelectionContext as Mock).mockReturnValue({
|
|
54
54
|
selectionState: {
|
|
55
55
|
collection: {
|
|
56
56
|
getKeys: () => filteredKeys,
|
|
@@ -74,7 +74,7 @@ describe("<SelectAllButton /> - interaction", () => {
|
|
|
74
74
|
|
|
75
75
|
describe("Given some options are disabled", () => {
|
|
76
76
|
it("triggers selectionManager.setSelectedKeys() on non-disabled options", async () => {
|
|
77
|
-
const spy =
|
|
77
|
+
const spy = vi.fn()
|
|
78
78
|
const filtered = "filtered"
|
|
79
79
|
const filteredAndSelected = "filteredAndSelected"
|
|
80
80
|
const filteredAndDisabled = "filteredAndDisabled"
|
|
@@ -82,7 +82,7 @@ describe("<SelectAllButton /> - interaction", () => {
|
|
|
82
82
|
const filteredKeys = [filtered, filteredAndSelected, filteredAndDisabled]
|
|
83
83
|
const disabledKeys = [filteredAndDisabled]
|
|
84
84
|
|
|
85
|
-
;(useSelectionContext as
|
|
85
|
+
;(useSelectionContext as Mock).mockReturnValue({
|
|
86
86
|
selectionState: {
|
|
87
87
|
disabledKeys,
|
|
88
88
|
collection: {
|
|
@@ -180,7 +180,7 @@ const defaultProps: FilterSelectProps = {
|
|
|
180
180
|
items: singleMockItems,
|
|
181
181
|
}
|
|
182
182
|
|
|
183
|
-
/* eslint-disable
|
|
183
|
+
/* eslint-disable vitest/expect-expect */
|
|
184
184
|
describe("FilterSelect generic", () => {
|
|
185
185
|
it("should prevent adding `options` attribute to option", () => {
|
|
186
186
|
/* @ts-expect-error */
|
|
@@ -213,4 +213,4 @@ describe("FilterSelect generic", () => {
|
|
|
213
213
|
})
|
|
214
214
|
})
|
|
215
215
|
})
|
|
216
|
-
/* eslint-enable
|
|
216
|
+
/* eslint-enable vitest/expect-expect */
|
|
@@ -1,37 +1,8 @@
|
|
|
1
1
|
import * as React from "react"
|
|
2
2
|
import { render } from "@testing-library/react"
|
|
3
|
-
import { AllowedHeadingTags, Heading, HeadingVariants } from "
|
|
3
|
+
import { AllowedHeadingTags, Heading, HeadingVariants } from "."
|
|
4
4
|
|
|
5
5
|
describe("<Heading />", () => {
|
|
6
|
-
it("renders the correct classes", () => {
|
|
7
|
-
const headingMock = render(<Heading variant="display-0">Example</Heading>)
|
|
8
|
-
const headingClasslist = headingMock.getByText("Example").classList
|
|
9
|
-
expect(headingClasslist).toContain("heading")
|
|
10
|
-
expect(headingClasslist).toContain("display-0")
|
|
11
|
-
expect(headingClasslist).toContain("large")
|
|
12
|
-
})
|
|
13
|
-
|
|
14
|
-
it("adds a .small class instead of .large if a Heading 3 is used", () => {
|
|
15
|
-
const headingMock = render(
|
|
16
|
-
<Heading variant="heading-3" tag="div">
|
|
17
|
-
Example
|
|
18
|
-
</Heading>
|
|
19
|
-
)
|
|
20
|
-
expect(headingMock.getByText("Example").classList).toContain("small")
|
|
21
|
-
expect(headingMock.getByText("Example").classList).not.toContain("large")
|
|
22
|
-
})
|
|
23
|
-
|
|
24
|
-
it("adds a .dark-reduced-opacity class if the color prop is set to that", () => {
|
|
25
|
-
const headingMock = render(
|
|
26
|
-
<Heading variant="heading-3" color="dark-reduced-opacity">
|
|
27
|
-
Example
|
|
28
|
-
</Heading>
|
|
29
|
-
)
|
|
30
|
-
expect(headingMock.getByText("Example").classList).toContain(
|
|
31
|
-
"dark-reduced-opacity"
|
|
32
|
-
)
|
|
33
|
-
})
|
|
34
|
-
|
|
35
6
|
it("changes rendered HTML element when passed tag", () => {
|
|
36
7
|
const headingMock = render(
|
|
37
8
|
<Heading variant="display-0" tag="div">
|
|
@@ -66,7 +37,6 @@ describe("<Heading />", () => {
|
|
|
66
37
|
it(`renders the correct element for <Heading variant={${variant}} />`, () => {
|
|
67
38
|
const headingMock = render(<Heading variant={variant}>Example</Heading>)
|
|
68
39
|
expect(headingMock.getByText("Example").tagName.toLowerCase()).toBe(el)
|
|
69
|
-
expect(headingMock.baseElement).toMatchSnapshot()
|
|
70
40
|
})
|
|
71
41
|
})
|
|
72
42
|
})
|
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
import React from "react"
|
|
2
2
|
import { render, screen } from "@testing-library/react"
|
|
3
|
-
import
|
|
3
|
+
import { vi } from "vitest"
|
|
4
4
|
import { VideoPlayer } from "./VideoPlayer"
|
|
5
5
|
|
|
6
6
|
const matchMedia = {
|
|
7
7
|
media: "",
|
|
8
8
|
onchange: null,
|
|
9
|
-
addListener:
|
|
10
|
-
removeListener:
|
|
11
|
-
addEventListener:
|
|
12
|
-
removeEventListener:
|
|
9
|
+
addListener: vi.fn(),
|
|
10
|
+
removeListener: vi.fn(),
|
|
11
|
+
addEventListener: vi.fn(),
|
|
12
|
+
removeEventListener: vi.fn(),
|
|
13
13
|
}
|
|
14
14
|
const mockPrefersReducedMotion = {
|
|
15
15
|
matches: true,
|
|
@@ -19,35 +19,36 @@ const mockDoesNotPreferReducedMotion = {
|
|
|
19
19
|
matches: false,
|
|
20
20
|
...matchMedia,
|
|
21
21
|
}
|
|
22
|
-
const mockPlay =
|
|
23
|
-
const mockLoad =
|
|
24
|
-
const mockPause =
|
|
22
|
+
const mockPlay = vi.fn().mockResolvedValue(undefined)
|
|
23
|
+
const mockLoad = vi.fn()
|
|
24
|
+
const mockPause = vi.fn()
|
|
25
25
|
|
|
26
26
|
describe("<VideoPlayer />", () => {
|
|
27
27
|
beforeEach(() => {
|
|
28
28
|
window.HTMLMediaElement.prototype.load = mockLoad
|
|
29
29
|
window.HTMLMediaElement.prototype.play = mockPlay
|
|
30
30
|
window.HTMLMediaElement.prototype.pause = mockPause
|
|
31
|
-
window.matchMedia =
|
|
31
|
+
window.matchMedia = vi
|
|
32
32
|
.fn()
|
|
33
33
|
.mockImplementation(() => mockDoesNotPreferReducedMotion)
|
|
34
34
|
// this will stop throwing the unstable_flushDiscreteUpdates console error cause by react bug
|
|
35
35
|
// https://stackoverflow.com/a/65338472/18285270
|
|
36
36
|
Object.defineProperty(HTMLMediaElement.prototype, "muted", {
|
|
37
|
-
set:
|
|
37
|
+
set: vi.fn(),
|
|
38
38
|
})
|
|
39
39
|
})
|
|
40
40
|
|
|
41
41
|
afterEach(() => {
|
|
42
|
-
|
|
42
|
+
vi.clearAllMocks()
|
|
43
43
|
})
|
|
44
44
|
|
|
45
|
-
it("renders a video player in the document and autoplay",
|
|
45
|
+
it("renders a video player in the document and autoplay", () => {
|
|
46
46
|
render(
|
|
47
47
|
<VideoPlayer
|
|
48
48
|
autoplay
|
|
49
49
|
fallback="illustrations/heart/spot/moods-cautionary.svg"
|
|
50
50
|
source="illustrations/heart/spot/moods-cautionary.webm"
|
|
51
|
+
data-testid="kz-video-player"
|
|
51
52
|
/>
|
|
52
53
|
)
|
|
53
54
|
const videoPlayer = screen.getByTestId("kz-video-player")
|
|
@@ -55,92 +56,37 @@ describe("<VideoPlayer />", () => {
|
|
|
55
56
|
expect(mockPlay).toHaveBeenCalled()
|
|
56
57
|
})
|
|
57
58
|
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
})
|
|
74
|
-
|
|
75
|
-
it("defaults to autoplay when user does not set use-reduced-motion preferences", () => {
|
|
76
|
-
window.matchMedia = jest
|
|
77
|
-
.fn()
|
|
78
|
-
.mockImplementation(() => mockDoesNotPreferReducedMotion)
|
|
79
|
-
render(
|
|
80
|
-
<VideoPlayer
|
|
81
|
-
autoplay
|
|
82
|
-
fallback="illustrations/heart/spot/moods-cautionary.svg"
|
|
83
|
-
source="illustrations/heart/spot/moods-cautionary.webm"
|
|
84
|
-
/>
|
|
85
|
-
)
|
|
86
|
-
const videoPlayer = screen.getByTestId("kz-video-player")
|
|
87
|
-
expect(videoPlayer).toHaveAttribute("autoplay")
|
|
88
|
-
expect(mockPlay).toHaveBeenCalled()
|
|
89
|
-
})
|
|
90
|
-
})
|
|
91
|
-
|
|
92
|
-
describe("when the aspect ratio is set as a prop", () => {
|
|
93
|
-
it("has aspect ratio class", () => {
|
|
94
|
-
window.matchMedia = jest
|
|
95
|
-
.fn()
|
|
96
|
-
.mockImplementation(() => mockDoesNotPreferReducedMotion)
|
|
97
|
-
const { container } = render(
|
|
98
|
-
<VideoPlayer
|
|
99
|
-
aspectRatio="landscape"
|
|
100
|
-
autoplay
|
|
101
|
-
fallback="illustrations/heart/spot/moods-cautionary.svg"
|
|
102
|
-
source="illustrations/heart/spot/moods-cautionary.webm"
|
|
103
|
-
/>
|
|
104
|
-
)
|
|
105
|
-
expect(container.querySelector(".aspectRatioWrapper")).toBeTruthy()
|
|
106
|
-
expect(container.querySelector(".landscape")).toBeTruthy()
|
|
107
|
-
})
|
|
108
|
-
})
|
|
109
|
-
|
|
110
|
-
describe("when the aspect ratio is not set as a prop", () => {
|
|
111
|
-
it("does not have aspect ratio class", () => {
|
|
112
|
-
window.matchMedia = jest
|
|
113
|
-
.fn()
|
|
114
|
-
.mockImplementation(() => mockDoesNotPreferReducedMotion)
|
|
115
|
-
const { container } = render(
|
|
116
|
-
<VideoPlayer
|
|
117
|
-
autoplay
|
|
118
|
-
fallback="illustrations/heart/spot/moods-cautionary.svg"
|
|
119
|
-
source="illustrations/heart/spot/moods-cautionary.webm"
|
|
120
|
-
/>
|
|
121
|
-
)
|
|
122
|
-
expect(container.querySelector(".aspectRatioWrapper")).toBeFalsy()
|
|
123
|
-
expect(container.querySelector(".landscape")).toBeFalsy()
|
|
124
|
-
})
|
|
59
|
+
it("respects the use-reduced-motion preferences of the user", () => {
|
|
60
|
+
window.matchMedia = vi
|
|
61
|
+
.fn()
|
|
62
|
+
.mockImplementation(() => mockPrefersReducedMotion)
|
|
63
|
+
render(
|
|
64
|
+
<VideoPlayer
|
|
65
|
+
autoplay
|
|
66
|
+
fallback="illustrations/heart/spot/moods-cautionary.svg"
|
|
67
|
+
source="illustrations/heart/spot/moods-cautionary.webm"
|
|
68
|
+
data-testid="kz-video-player"
|
|
69
|
+
/>
|
|
70
|
+
)
|
|
71
|
+
const videoPlayer = screen.getByTestId("kz-video-player")
|
|
72
|
+
expect(videoPlayer).not.toHaveAttribute("autoplay")
|
|
73
|
+
expect(mockPause).toHaveBeenCalled()
|
|
125
74
|
})
|
|
126
75
|
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
expect(mockPlay).toHaveBeenCalled()
|
|
144
|
-
})
|
|
76
|
+
it("defaults to autoplay when user does not set use-reduced-motion preferences", () => {
|
|
77
|
+
window.matchMedia = vi
|
|
78
|
+
.fn()
|
|
79
|
+
.mockImplementation(() => mockDoesNotPreferReducedMotion)
|
|
80
|
+
render(
|
|
81
|
+
<VideoPlayer
|
|
82
|
+
autoplay
|
|
83
|
+
fallback="illustrations/heart/spot/moods-cautionary.svg"
|
|
84
|
+
source="illustrations/heart/spot/moods-cautionary.webm"
|
|
85
|
+
data-testid="kz-video-player"
|
|
86
|
+
/>
|
|
87
|
+
)
|
|
88
|
+
const videoPlayer = screen.getByTestId("kz-video-player")
|
|
89
|
+
expect(videoPlayer).toHaveAttribute("autoplay")
|
|
90
|
+
expect(mockPlay).toHaveBeenCalled()
|
|
145
91
|
})
|
|
146
92
|
})
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import React from "react"
|
|
2
|
+
import { Meta } from "@storybook/react"
|
|
3
|
+
import {
|
|
4
|
+
StickerSheet,
|
|
5
|
+
StickerSheetStory,
|
|
6
|
+
} from "~storybook/components/StickerSheet"
|
|
7
|
+
import { VideoPlayer } from "./index"
|
|
8
|
+
|
|
9
|
+
export default {
|
|
10
|
+
title: "Components/Illustrations/VideoPlayer",
|
|
11
|
+
parameters: {
|
|
12
|
+
controls: { disable: true },
|
|
13
|
+
chromatic: { disable: false },
|
|
14
|
+
},
|
|
15
|
+
} satisfies Meta
|
|
16
|
+
|
|
17
|
+
const StickerSheetTemplate: StickerSheetStory = {
|
|
18
|
+
render: ({ isReversed }) => (
|
|
19
|
+
<StickerSheet isReversed={isReversed} title="Aspect Ratio">
|
|
20
|
+
<StickerSheet.Body>
|
|
21
|
+
<StickerSheet.Row rowTitle="default">
|
|
22
|
+
<div className="border border-dashed border-grey-500">
|
|
23
|
+
<VideoPlayer
|
|
24
|
+
autoplay={false}
|
|
25
|
+
fallback="illustrations/heart/scene/brand-moments-positive-outro"
|
|
26
|
+
source="illustrations/heart/scene/brand-moments-positive-outro"
|
|
27
|
+
/>
|
|
28
|
+
</div>
|
|
29
|
+
</StickerSheet.Row>
|
|
30
|
+
<StickerSheet.Row rowTitle="landscape">
|
|
31
|
+
<div className="border border-dashed border-grey-500">
|
|
32
|
+
<VideoPlayer
|
|
33
|
+
autoplay={false}
|
|
34
|
+
aspectRatio="landscape"
|
|
35
|
+
fallback="illustrations/heart/scene/brand-moments-positive-outro"
|
|
36
|
+
source="illustrations/heart/scene/brand-moments-positive-outro"
|
|
37
|
+
/>
|
|
38
|
+
</div>
|
|
39
|
+
</StickerSheet.Row>
|
|
40
|
+
<StickerSheet.Row rowTitle="portrait">
|
|
41
|
+
<div className="border border-dashed border-grey-500">
|
|
42
|
+
<VideoPlayer
|
|
43
|
+
autoplay={false}
|
|
44
|
+
aspectRatio="portrait"
|
|
45
|
+
fallback="illustrations/heart/scene/brand-moments-positive-outro"
|
|
46
|
+
source="illustrations/heart/scene/brand-moments-positive-outro"
|
|
47
|
+
/>
|
|
48
|
+
</div>
|
|
49
|
+
</StickerSheet.Row>
|
|
50
|
+
<StickerSheet.Row rowTitle="square">
|
|
51
|
+
<div className="border border-dashed border-grey-500">
|
|
52
|
+
<VideoPlayer
|
|
53
|
+
autoplay={false}
|
|
54
|
+
aspectRatio="square"
|
|
55
|
+
fallback="illustrations/heart/scene/brand-moments-positive-outro"
|
|
56
|
+
source="illustrations/heart/scene/brand-moments-positive-outro"
|
|
57
|
+
/>
|
|
58
|
+
</div>
|
|
59
|
+
</StickerSheet.Row>
|
|
60
|
+
</StickerSheet.Body>
|
|
61
|
+
</StickerSheet>
|
|
62
|
+
),
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
export const StickerSheetDefault: StickerSheetStory = {
|
|
66
|
+
...StickerSheetTemplate,
|
|
67
|
+
name: "Sticker Sheet (Default)",
|
|
68
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import React from "react"
|
|
2
|
+
import { Meta, StoryObj } from "@storybook/react"
|
|
3
|
+
import { userEvent, within, expect, waitFor } from "@storybook/test"
|
|
4
|
+
import { VideoPlayer } from "./index"
|
|
5
|
+
|
|
6
|
+
const meta = {
|
|
7
|
+
title: "Components/Illustrations/VideoPlayer",
|
|
8
|
+
component: VideoPlayer,
|
|
9
|
+
args: {
|
|
10
|
+
autoplay: false,
|
|
11
|
+
fallback: "illustrations/heart/scene/brand-moments-positive-outro",
|
|
12
|
+
source: "illustrations/heart/scene/brand-moments-positive-outro",
|
|
13
|
+
},
|
|
14
|
+
} satisfies Meta<typeof VideoPlayer>
|
|
15
|
+
|
|
16
|
+
export default meta
|
|
17
|
+
|
|
18
|
+
type Story = StoryObj<typeof meta>
|
|
19
|
+
|
|
20
|
+
export const PausePlay: Story = {
|
|
21
|
+
render: args => <VideoPlayer {...args} />,
|
|
22
|
+
name: "VideoPlayer: Pause/Play",
|
|
23
|
+
play: async ({ canvasElement }) => {
|
|
24
|
+
const canvas = within(canvasElement)
|
|
25
|
+
const element = canvas.getByRole("button")
|
|
26
|
+
|
|
27
|
+
waitFor(() => {
|
|
28
|
+
userEvent.click(element)
|
|
29
|
+
expect(element).toHaveAttribute("aria-label", "Pause animation")
|
|
30
|
+
})
|
|
31
|
+
|
|
32
|
+
waitFor(() => {
|
|
33
|
+
userEvent.click(element)
|
|
34
|
+
expect(element).toHaveAttribute("aria-label", "Play animation")
|
|
35
|
+
})
|
|
36
|
+
},
|
|
37
|
+
}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import React from "react"
|
|
2
2
|
import { render, screen, fireEvent, waitFor } from "@testing-library/react"
|
|
3
|
+
import { vi } from "vitest"
|
|
3
4
|
import { InputRange } from "./index"
|
|
4
|
-
|
|
5
5
|
describe("<InputRange />", () => {
|
|
6
6
|
it("fires onChange after interaction", async () => {
|
|
7
|
-
const onChange =
|
|
7
|
+
const onChange = vi.fn()
|
|
8
8
|
render(
|
|
9
9
|
<InputRange
|
|
10
10
|
id="unique-3"
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import React from "react"
|
|
2
2
|
import { render, waitFor } from "@testing-library/react"
|
|
3
3
|
import userEvent from "@testing-library/user-event"
|
|
4
|
-
import {
|
|
4
|
+
import { vi } from "vitest"
|
|
5
5
|
import { InputSearchProps } from "./InputSearch"
|
|
6
6
|
import { InputSearch } from "."
|
|
7
7
|
|
|
@@ -10,7 +10,7 @@ const user = userEvent.setup()
|
|
|
10
10
|
const defaultInputProps = {
|
|
11
11
|
id: "someInputId",
|
|
12
12
|
value: "somevalue",
|
|
13
|
-
onChange:
|
|
13
|
+
onChange: vi.fn(),
|
|
14
14
|
}
|
|
15
15
|
|
|
16
16
|
const renderInput = (
|
|
@@ -18,9 +18,7 @@ const renderInput = (
|
|
|
18
18
|
): ReturnType<typeof render> => {
|
|
19
19
|
const mergedInputProps = { ...defaultInputProps, ...props }
|
|
20
20
|
|
|
21
|
-
return
|
|
22
|
-
<InputSearch {...mergedInputProps} data-testid="someInputId" />
|
|
23
|
-
)
|
|
21
|
+
return render(<InputSearch {...mergedInputProps} data-testid="someInputId" />)
|
|
24
22
|
}
|
|
25
23
|
|
|
26
24
|
describe("<InputSearch />", () => {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import React from "react"
|
|
2
2
|
import { render } from "@testing-library/react"
|
|
3
|
+
import { vi } from "vitest"
|
|
3
4
|
import { KaizenProvider, KaizenProviderProps } from "./KaizenProvider"
|
|
4
|
-
|
|
5
5
|
const KaizenProviderWrapper = ({
|
|
6
6
|
children,
|
|
7
7
|
...restProps
|
|
@@ -9,7 +9,7 @@ const KaizenProviderWrapper = ({
|
|
|
9
9
|
<KaizenProvider {...restProps}>{children}</KaizenProvider>
|
|
10
10
|
)
|
|
11
11
|
|
|
12
|
-
|
|
12
|
+
vi.mock("./subcomponents/OptionalIntlProvider", () => ({
|
|
13
13
|
OptionalIntlProvider: ({ children }: { children: React.ReactElement }) => (
|
|
14
14
|
<div>{children}</div>
|
|
15
15
|
),
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import React from "react"
|
|
2
2
|
import { render, screen } from "@testing-library/react"
|
|
3
3
|
import { IntlProvider } from "react-intl"
|
|
4
|
+
import { vi } from "vitest"
|
|
4
5
|
import { OptionalIntlProvider } from "."
|
|
5
6
|
|
|
6
|
-
|
|
7
|
+
vi.mock("@cultureamp/i18n-react-intl", () => ({
|
|
7
8
|
StaticIntlProvider: ({ children }: { children: React.ReactElement }) => (
|
|
8
9
|
<div data-testid="mockedIntlProvider">{children}</div>
|
|
9
10
|
),
|
|
@@ -35,5 +36,3 @@ describe("<OptionalIntlProvider>", () => {
|
|
|
35
36
|
expect(childrenResult).toBeInTheDocument()
|
|
36
37
|
})
|
|
37
38
|
})
|
|
38
|
-
|
|
39
|
-
/* eslint-enable jest/expect-expect */
|