@kaizen/components 1.61.1 → 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 +220 -220
- 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/__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
|
@@ -1,23 +1,11 @@
|
|
|
1
1
|
import React from "react"
|
|
2
2
|
import { queryByTestId, render, waitFor } from "@testing-library/react"
|
|
3
3
|
import userEvent from "@testing-library/user-event"
|
|
4
|
+
import { vi } from "vitest"
|
|
4
5
|
import { Collapsible } from "./Collapsible"
|
|
5
|
-
|
|
6
6
|
const user = userEvent.setup()
|
|
7
7
|
|
|
8
8
|
describe("<Collapsible />", () => {
|
|
9
|
-
it("includes the 'sticky' class on buttons when the 'sticky' prop is specified", () => {
|
|
10
|
-
const { getByTestId } = render(
|
|
11
|
-
<Collapsible id="1" title="First panel" sticky={{ top: "0px" }}>
|
|
12
|
-
First panel content
|
|
13
|
-
</Collapsible>
|
|
14
|
-
)
|
|
15
|
-
|
|
16
|
-
const collapsibleContainer = getByTestId("collapsible-header-1")
|
|
17
|
-
|
|
18
|
-
expect(collapsibleContainer.classList.contains("sticky")).toBeTruthy()
|
|
19
|
-
})
|
|
20
|
-
|
|
21
9
|
it("toggles the height of the section on click of the button", async () => {
|
|
22
10
|
const { getByTestId } = render(
|
|
23
11
|
<Collapsible id="1" open title="First panel">
|
|
@@ -74,7 +62,7 @@ describe("<Collapsible />", () => {
|
|
|
74
62
|
})
|
|
75
63
|
|
|
76
64
|
it("runs the onToggle callback", async () => {
|
|
77
|
-
const onToggle =
|
|
65
|
+
const onToggle = vi.fn()
|
|
78
66
|
|
|
79
67
|
const { getByTestId } = render(
|
|
80
68
|
<Collapsible id="1" open title="First panel" onToggle={onToggle}>
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import React from "react"
|
|
2
2
|
import { Meta } from "@storybook/react"
|
|
3
|
+
import { within } from "@storybook/test"
|
|
3
4
|
import { Heading } from "~components/Heading"
|
|
5
|
+
import { Text } from "~components/Text"
|
|
4
6
|
import {
|
|
5
7
|
StickerSheet,
|
|
6
8
|
StickerSheetStory,
|
|
@@ -73,3 +75,50 @@ export const StickerSheetRTL: StickerSheetStory = {
|
|
|
73
75
|
name: "Sticker Sheet (RTL)",
|
|
74
76
|
parameters: { textDirection: "rtl" },
|
|
75
77
|
}
|
|
78
|
+
|
|
79
|
+
export const Sticky: StickerSheetStory = {
|
|
80
|
+
render: () => (
|
|
81
|
+
<StickerSheet>
|
|
82
|
+
<StickerSheet.Body>
|
|
83
|
+
<StickerSheet.Row rowTitle="Sticky header">
|
|
84
|
+
<div style={{ height: "300px", overflow: "auto" }}>
|
|
85
|
+
<Collapsible
|
|
86
|
+
open
|
|
87
|
+
title="Sticky"
|
|
88
|
+
sticky={{ top: "-1px" }}
|
|
89
|
+
style={{ maxWidth: "300px" }}
|
|
90
|
+
>
|
|
91
|
+
<Text variant="body">
|
|
92
|
+
Lorem ipsum dolor sit amet, consectetur adipiscing elit.
|
|
93
|
+
Phasellus ac scelerisque sem, vel ultricies justo. Donec eu
|
|
94
|
+
porttitor ante, nec gravida orci. Nulla facilisi. Cras varius
|
|
95
|
+
erat id fermentum mattis. Mauris bibendum vestibulum erat, quis
|
|
96
|
+
blandit metus viverra sit amet. Vivamus pretium vitae turpis ut
|
|
97
|
+
condimentum. Sed vulputate magna nisl, in cursus urna hendrerit
|
|
98
|
+
et. Aenean semper, est non feugiat sodales, nisl ligula aliquet
|
|
99
|
+
lorem, sit amet scelerisque arcu quam a sapien. Donec in viverra
|
|
100
|
+
urna.
|
|
101
|
+
</Text>
|
|
102
|
+
<Text variant="body" data-testid="bottom-content">
|
|
103
|
+
Lorem ipsum dolor sit amet, consectetur adipiscing elit.
|
|
104
|
+
Phasellus ac scelerisque sem, vel ultricies justo. Donec eu
|
|
105
|
+
porttitor ante, nec gravida orci. Nulla facilisi. Cras varius
|
|
106
|
+
erat id fermentum mattis. Mauris bibendum vestibulum erat, quis
|
|
107
|
+
blandit metus viverra sit amet. Vivamus pretium vitae turpis ut
|
|
108
|
+
condimentum. Sed vulputate magna nisl, in cursus urna hendrerit
|
|
109
|
+
et. Aenean semper, est non feugiat sodales, nisl ligula aliquet
|
|
110
|
+
lorem, sit amet scelerisque arcu quam a sapien. Donec in viverra
|
|
111
|
+
urna.
|
|
112
|
+
</Text>
|
|
113
|
+
</Collapsible>
|
|
114
|
+
</div>
|
|
115
|
+
</StickerSheet.Row>
|
|
116
|
+
</StickerSheet.Body>
|
|
117
|
+
</StickerSheet>
|
|
118
|
+
),
|
|
119
|
+
play: async ({ canvasElement }) => {
|
|
120
|
+
const canvas = within(canvasElement)
|
|
121
|
+
const element = canvas.getByTestId("bottom-content")
|
|
122
|
+
element.scrollIntoView({ behavior: "instant", block: "end" })
|
|
123
|
+
},
|
|
124
|
+
}
|
|
@@ -88,17 +88,6 @@ export const CustomHeader: Story = {
|
|
|
88
88
|
),
|
|
89
89
|
}
|
|
90
90
|
|
|
91
|
-
export const Sticky: Story = {
|
|
92
|
-
args: {
|
|
93
|
-
title: "Sticky header",
|
|
94
|
-
},
|
|
95
|
-
render: ({ title }) => (
|
|
96
|
-
<Collapsible open title={title} sticky={{ top: "-1px" }}>
|
|
97
|
-
This does not work in Storybook docs, so use this as a code example only.
|
|
98
|
-
</Collapsible>
|
|
99
|
-
),
|
|
100
|
-
}
|
|
101
|
-
|
|
102
91
|
const controlledSourceCode = `
|
|
103
92
|
const [isOpen, setIsOpen] = useState<boolean>(false)
|
|
104
93
|
return (<Collapsible {...args} open={isOpen} onToggle={setIsOpen} />)
|
|
@@ -1,19 +1,18 @@
|
|
|
1
1
|
import React from "react"
|
|
2
|
-
import { waitFor } from "@testing-library/react"
|
|
2
|
+
import { waitFor, render } from "@testing-library/react"
|
|
3
3
|
import { enUS } from "date-fns/locale"
|
|
4
|
-
import { renderWithIntl } from "~tests"
|
|
5
4
|
import { DateInputDescription } from "./DateInputDescription"
|
|
6
5
|
|
|
7
6
|
describe("DateInputDescription", () => {
|
|
8
7
|
it("returns template string when description is undefined", async () => {
|
|
9
|
-
const { container } =
|
|
8
|
+
const { container } = render(<DateInputDescription locale={enUS} />)
|
|
10
9
|
await waitFor(() => {
|
|
11
10
|
expect(container).toHaveTextContent("Input format:mm/dd/yyyy")
|
|
12
11
|
})
|
|
13
12
|
})
|
|
14
13
|
|
|
15
14
|
it("returns template string when description is empty string", async () => {
|
|
16
|
-
const { container } =
|
|
15
|
+
const { container } = render(
|
|
17
16
|
<DateInputDescription description="" locale={enUS} />
|
|
18
17
|
)
|
|
19
18
|
await waitFor(() => {
|
|
@@ -22,7 +21,7 @@ describe("DateInputDescription", () => {
|
|
|
22
21
|
})
|
|
23
22
|
|
|
24
23
|
it("returns template string when description is a string", async () => {
|
|
25
|
-
const { container } =
|
|
24
|
+
const { container } = render(
|
|
26
25
|
<DateInputDescription
|
|
27
26
|
description="Custom description here"
|
|
28
27
|
locale={enUS}
|
|
@@ -36,7 +35,7 @@ describe("DateInputDescription", () => {
|
|
|
36
35
|
})
|
|
37
36
|
|
|
38
37
|
it("returns template string when description is an element", async () => {
|
|
39
|
-
const { container } =
|
|
38
|
+
const { container } = render(
|
|
40
39
|
<DateInputDescription
|
|
41
40
|
description={<span>Custom description span</span>}
|
|
42
41
|
locale={enUS}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import React, { useRef } from "react"
|
|
2
2
|
import { render, screen } from "@testing-library/react"
|
|
3
3
|
import userEvent from "@testing-library/user-event"
|
|
4
|
+
import { vi } from "vitest"
|
|
4
5
|
import {
|
|
5
6
|
DateInputWithIconButton,
|
|
6
7
|
DateInputWithIconButtonProps,
|
|
@@ -11,7 +12,7 @@ const user = userEvent.setup()
|
|
|
11
12
|
const defaultProps: DateInputWithIconButtonProps = {
|
|
12
13
|
id: "test__date-input-with-icon-button",
|
|
13
14
|
labelText: "Due date",
|
|
14
|
-
onButtonClick:
|
|
15
|
+
onButtonClick: vi.fn(),
|
|
15
16
|
}
|
|
16
17
|
|
|
17
18
|
const DateInputWithIconButtonWrapper = (
|
|
@@ -52,10 +53,7 @@ describe("<DateInputWithIconButton />", () => {
|
|
|
52
53
|
|
|
53
54
|
describe("Refs", () => {
|
|
54
55
|
it("correctly passes through input and button refs", async () => {
|
|
55
|
-
const onButtonClick =
|
|
56
|
-
void,
|
|
57
|
-
[string | null | undefined, string | null | undefined]
|
|
58
|
-
>()
|
|
56
|
+
const onButtonClick = vi.fn()
|
|
59
57
|
|
|
60
58
|
const Wrapper = (): JSX.Element => {
|
|
61
59
|
const inputRef = useRef<HTMLInputElement>(null)
|
|
@@ -74,7 +72,7 @@ describe("<DateInputWithIconButton />", () => {
|
|
|
74
72
|
ref={ref}
|
|
75
73
|
id="test__date-input-field--ref"
|
|
76
74
|
labelText="label"
|
|
77
|
-
onButtonClick={
|
|
75
|
+
onButtonClick={vi.fn()}
|
|
78
76
|
/>
|
|
79
77
|
<button type="button" onClick={handleClick}>
|
|
80
78
|
Click me
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import React, { useEffect, useState } from "react"
|
|
2
|
-
import { screen, waitFor, within } from "@testing-library/react"
|
|
2
|
+
import { render, screen, waitFor, within } from "@testing-library/react"
|
|
3
3
|
import userEvent from "@testing-library/user-event"
|
|
4
|
-
import {
|
|
4
|
+
import { vi } from "vitest"
|
|
5
5
|
import { DatePicker } from "./DatePicker"
|
|
6
6
|
import { DatePickerProps } from "."
|
|
7
7
|
|
|
@@ -27,14 +27,14 @@ const DatePickerWrapper = ({
|
|
|
27
27
|
|
|
28
28
|
describe("<DatePicker />", () => {
|
|
29
29
|
it("should not show the calendar initially", async () => {
|
|
30
|
-
|
|
30
|
+
render(<DatePickerWrapper />)
|
|
31
31
|
await waitFor(() => {
|
|
32
32
|
expect(screen.queryByRole("dialog")).not.toBeInTheDocument()
|
|
33
33
|
})
|
|
34
34
|
})
|
|
35
35
|
|
|
36
36
|
it("should have an empty input value when a date is not provided", async () => {
|
|
37
|
-
|
|
37
|
+
render(<DatePickerWrapper />)
|
|
38
38
|
await waitFor(() => {
|
|
39
39
|
const input = screen.getByLabelText("Input label", { selector: "input" })
|
|
40
40
|
expect(input).toHaveValue("")
|
|
@@ -42,7 +42,7 @@ describe("<DatePicker />", () => {
|
|
|
42
42
|
})
|
|
43
43
|
|
|
44
44
|
it("should pre-fill the input when an initial date is provided", async () => {
|
|
45
|
-
|
|
45
|
+
render(<DatePickerWrapper selectedDay={new Date("2022-03-01")} />)
|
|
46
46
|
await waitFor(() => {
|
|
47
47
|
expect(screen.getByDisplayValue("Mar 1, 2022")).toBeInTheDocument()
|
|
48
48
|
})
|
|
@@ -68,7 +68,7 @@ describe("<DatePicker />", () => {
|
|
|
68
68
|
)
|
|
69
69
|
}
|
|
70
70
|
|
|
71
|
-
|
|
71
|
+
render(<DelayedSelectedDate />)
|
|
72
72
|
expect(screen.getByRole("combobox")).toBeInTheDocument()
|
|
73
73
|
expect(screen.getByRole("combobox")).toHaveValue("")
|
|
74
74
|
await waitFor(() => {
|
|
@@ -77,7 +77,7 @@ describe("<DatePicker />", () => {
|
|
|
77
77
|
})
|
|
78
78
|
|
|
79
79
|
it("allows you to tab through input, button and calendar", async () => {
|
|
80
|
-
|
|
80
|
+
render(<DatePickerWrapper />)
|
|
81
81
|
const input = screen.getByLabelText("Input label", { selector: "input" })
|
|
82
82
|
|
|
83
83
|
await user.tab()
|
|
@@ -112,9 +112,7 @@ describe("<DatePicker />", () => {
|
|
|
112
112
|
}, 6000)
|
|
113
113
|
|
|
114
114
|
it("should validate and close the calendar when the user presses the Enter key while focus is in the input", async () => {
|
|
115
|
-
|
|
116
|
-
<DatePickerWrapper disabledDates={[new Date("2022-05-01")]} />
|
|
117
|
-
)
|
|
115
|
+
render(<DatePickerWrapper disabledDates={[new Date("2022-05-01")]} />)
|
|
118
116
|
|
|
119
117
|
const input = screen.getByLabelText("Input label", { selector: "input" })
|
|
120
118
|
await user.click(input)
|
|
@@ -139,7 +137,7 @@ describe("<DatePicker />", () => {
|
|
|
139
137
|
describe("<DatePicker /> - Focus element", () => {
|
|
140
138
|
describe("Click on input", () => {
|
|
141
139
|
beforeEach(async () => {
|
|
142
|
-
|
|
140
|
+
render(<DatePickerWrapper selectedDay={new Date("2022-03-01")} />)
|
|
143
141
|
|
|
144
142
|
const input = screen.getByLabelText("Input label", { selector: "input" })
|
|
145
143
|
await user.click(input)
|
|
@@ -181,7 +179,7 @@ describe("<DatePicker /> - Focus element", () => {
|
|
|
181
179
|
|
|
182
180
|
describe("Keydown arrow on input", () => {
|
|
183
181
|
it("shows focus within the calendar", async () => {
|
|
184
|
-
|
|
182
|
+
render(<DatePickerWrapper selectedDay={new Date("2022-03-01")} />)
|
|
185
183
|
|
|
186
184
|
const input = screen.getByLabelText("Input label", { selector: "input" })
|
|
187
185
|
await user.tab()
|
|
@@ -200,7 +198,7 @@ describe("<DatePicker /> - Focus element", () => {
|
|
|
200
198
|
})
|
|
201
199
|
|
|
202
200
|
it("returns focus to the input when the user escapes from the calendar", async () => {
|
|
203
|
-
|
|
201
|
+
render(<DatePickerWrapper selectedDay={new Date("2022-03-01")} />)
|
|
204
202
|
|
|
205
203
|
const input = screen.getByLabelText("Input label", { selector: "input" })
|
|
206
204
|
await user.tab()
|
|
@@ -222,7 +220,7 @@ describe("<DatePicker /> - Focus element", () => {
|
|
|
222
220
|
|
|
223
221
|
describe("Click on calendar button", () => {
|
|
224
222
|
beforeEach(async () => {
|
|
225
|
-
|
|
223
|
+
render(<DatePickerWrapper selectedDay={new Date("2022-03-01")} />)
|
|
226
224
|
|
|
227
225
|
const calendarButton = screen.getByRole("button", {
|
|
228
226
|
name: "Change date, Mar 1, 2022",
|
|
@@ -258,7 +256,7 @@ describe("<DatePicker /> - Focus element", () => {
|
|
|
258
256
|
let calendarButton: HTMLElement
|
|
259
257
|
|
|
260
258
|
beforeEach(async () => {
|
|
261
|
-
|
|
259
|
+
render(<DatePickerWrapper selectedDay={new Date("2022-03-01")} />)
|
|
262
260
|
|
|
263
261
|
calendarButton = screen.getByRole("button", {
|
|
264
262
|
name: "Change date, Mar 1, 2022",
|
|
@@ -305,7 +303,7 @@ describe("<DatePicker /> - Focus element", () => {
|
|
|
305
303
|
|
|
306
304
|
describe("<DatePicker /> - Input format", () => {
|
|
307
305
|
it("formats values when focus is on the input", async () => {
|
|
308
|
-
|
|
306
|
+
render(<DatePickerWrapper selectedDay={new Date("2022-03-01")} />)
|
|
309
307
|
|
|
310
308
|
const input = screen.getByLabelText("Input label", { selector: "input" })
|
|
311
309
|
expect(input).toHaveValue("Mar 1, 2022")
|
|
@@ -318,7 +316,7 @@ describe("<DatePicker /> - Input format", () => {
|
|
|
318
316
|
})
|
|
319
317
|
|
|
320
318
|
it("formats values when the input loses focus - onBlur", async () => {
|
|
321
|
-
|
|
319
|
+
render(<DatePickerWrapper selectedDay={new Date("2022-03-01")} />)
|
|
322
320
|
|
|
323
321
|
const input = screen.getByLabelText("Input label", { selector: "input" })
|
|
324
322
|
expect(input).toHaveValue("Mar 1, 2022")
|
|
@@ -340,7 +338,7 @@ describe("<DatePicker /> - Input format", () => {
|
|
|
340
338
|
describe("<DatePicker /> - Validation", () => {
|
|
341
339
|
describe("Custom Validation", () => {
|
|
342
340
|
it("displays custom validation message when provided (overrides inbuilt validation)", async () => {
|
|
343
|
-
|
|
341
|
+
render(
|
|
344
342
|
<DatePickerWrapper
|
|
345
343
|
status="error"
|
|
346
344
|
validationMessage="Custom validation message"
|
|
@@ -358,8 +356,8 @@ describe("<DatePicker /> - Validation", () => {
|
|
|
358
356
|
})
|
|
359
357
|
|
|
360
358
|
it("does not show inbuilt validation message when onValidate is set", async () => {
|
|
361
|
-
const onValidate =
|
|
362
|
-
|
|
359
|
+
const onValidate = vi.fn()
|
|
360
|
+
render(
|
|
363
361
|
<DatePickerWrapper
|
|
364
362
|
selectedDay={new Date("potato")}
|
|
365
363
|
onValidate={onValidate}
|
|
@@ -377,8 +375,8 @@ describe("<DatePicker /> - Validation", () => {
|
|
|
377
375
|
})
|
|
378
376
|
|
|
379
377
|
it("triggers validation when initial selected date is invalid", async () => {
|
|
380
|
-
const onValidate =
|
|
381
|
-
|
|
378
|
+
const onValidate = vi.fn()
|
|
379
|
+
render(
|
|
382
380
|
<DatePickerWrapper
|
|
383
381
|
onValidate={onValidate}
|
|
384
382
|
selectedDay={new Date("potato")}
|
|
@@ -390,8 +388,8 @@ describe("<DatePicker /> - Validation", () => {
|
|
|
390
388
|
})
|
|
391
389
|
|
|
392
390
|
it("triggers validation when initial selected date is disabled", async () => {
|
|
393
|
-
const onValidate =
|
|
394
|
-
|
|
391
|
+
const onValidate = vi.fn()
|
|
392
|
+
render(
|
|
395
393
|
<DatePickerWrapper
|
|
396
394
|
onValidate={onValidate}
|
|
397
395
|
disabledBefore={new Date("2022-05-15")}
|
|
@@ -404,8 +402,8 @@ describe("<DatePicker /> - Validation", () => {
|
|
|
404
402
|
})
|
|
405
403
|
|
|
406
404
|
it("does not trigger validation when initial selected date is empty", async () => {
|
|
407
|
-
const onValidate =
|
|
408
|
-
|
|
405
|
+
const onValidate = vi.fn()
|
|
406
|
+
render(
|
|
409
407
|
<DatePickerWrapper onValidate={onValidate} selectedDay={undefined} />
|
|
410
408
|
)
|
|
411
409
|
await waitFor(() => {
|
|
@@ -414,8 +412,8 @@ describe("<DatePicker /> - Validation", () => {
|
|
|
414
412
|
})
|
|
415
413
|
|
|
416
414
|
it("does not trigger validation when initial selected date is valid", async () => {
|
|
417
|
-
const onValidate =
|
|
418
|
-
|
|
415
|
+
const onValidate = vi.fn()
|
|
416
|
+
render(
|
|
419
417
|
<DatePickerWrapper
|
|
420
418
|
onValidate={onValidate}
|
|
421
419
|
selectedDay={new Date("2022-05-05")}
|
|
@@ -427,8 +425,8 @@ describe("<DatePicker /> - Validation", () => {
|
|
|
427
425
|
})
|
|
428
426
|
|
|
429
427
|
it("triggers validation when selected date is updated to invalid", async () => {
|
|
430
|
-
const onValidate =
|
|
431
|
-
|
|
428
|
+
const onValidate = vi.fn()
|
|
429
|
+
render(
|
|
432
430
|
<DatePickerWrapper
|
|
433
431
|
onValidate={onValidate}
|
|
434
432
|
defaultMonth={new Date("2022-03-01")}
|
|
@@ -451,7 +449,7 @@ describe("<DatePicker /> - Validation", () => {
|
|
|
451
449
|
|
|
452
450
|
describe("Inbuilt Validation", () => {
|
|
453
451
|
it("displays error message when selected day is invalid", async () => {
|
|
454
|
-
|
|
452
|
+
render(<DatePickerWrapper selectedDay={new Date("potato")} />)
|
|
455
453
|
|
|
456
454
|
await waitFor(() => {
|
|
457
455
|
const icon = screen.getByLabelText("error message")
|
|
@@ -461,7 +459,7 @@ describe("<DatePicker /> - Validation", () => {
|
|
|
461
459
|
})
|
|
462
460
|
|
|
463
461
|
it("displays error message when selected day is disabled", async () => {
|
|
464
|
-
|
|
462
|
+
render(
|
|
465
463
|
<DatePickerWrapper
|
|
466
464
|
disabledBefore={new Date("2022-05-15")}
|
|
467
465
|
selectedDay={new Date("2022-05-05")}
|
|
@@ -476,7 +474,7 @@ describe("<DatePicker /> - Validation", () => {
|
|
|
476
474
|
})
|
|
477
475
|
|
|
478
476
|
it("displays error message when input date is invalid", async () => {
|
|
479
|
-
|
|
477
|
+
render(<DatePickerWrapper />)
|
|
480
478
|
|
|
481
479
|
const input = screen.getByLabelText("Input label", { selector: "input" })
|
|
482
480
|
await user.type(input, "05/05/2022Blah")
|
|
@@ -491,9 +489,7 @@ describe("<DatePicker /> - Validation", () => {
|
|
|
491
489
|
})
|
|
492
490
|
|
|
493
491
|
it("displays error message when input date is disabled", async () => {
|
|
494
|
-
|
|
495
|
-
<DatePickerWrapper disabledBefore={new Date("2022-05-15")} />
|
|
496
|
-
)
|
|
492
|
+
render(<DatePickerWrapper disabledBefore={new Date("2022-05-15")} />)
|
|
497
493
|
|
|
498
494
|
const input = screen.getByLabelText("Input label", { selector: "input" })
|
|
499
495
|
await user.type(input, "05/05/2022")
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import React, { useRef } 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
4
|
import { enUS } from "date-fns/locale"
|
|
5
|
-
import {
|
|
5
|
+
import { vi } from "vitest"
|
|
6
6
|
import { DateInputField, DateInputFieldProps } from "./DateInputField"
|
|
7
7
|
|
|
8
8
|
const user = userEvent.setup()
|
|
@@ -10,8 +10,8 @@ const user = userEvent.setup()
|
|
|
10
10
|
const defaultProps: DateInputFieldProps = {
|
|
11
11
|
id: "test__date-input-field",
|
|
12
12
|
labelText: "Bacon expiry",
|
|
13
|
-
onButtonClick:
|
|
14
|
-
onKeyDown:
|
|
13
|
+
onButtonClick: vi.fn(),
|
|
14
|
+
onKeyDown: vi.fn(),
|
|
15
15
|
value: undefined,
|
|
16
16
|
locale: enUS,
|
|
17
17
|
}
|
|
@@ -23,7 +23,7 @@ const DateInputFieldWrapper = (
|
|
|
23
23
|
describe("<DateInputField />", () => {
|
|
24
24
|
describe("Input", () => {
|
|
25
25
|
it("associates the description with the input", async () => {
|
|
26
|
-
|
|
26
|
+
render(<DateInputFieldWrapper />)
|
|
27
27
|
await waitFor(() => {
|
|
28
28
|
expect(
|
|
29
29
|
screen.getByRole("textbox", {
|
|
@@ -37,7 +37,7 @@ describe("<DateInputField />", () => {
|
|
|
37
37
|
|
|
38
38
|
describe("Icon button", () => {
|
|
39
39
|
it("has helpful label", async () => {
|
|
40
|
-
|
|
40
|
+
render(<DateInputFieldWrapper />)
|
|
41
41
|
await waitFor(() => {
|
|
42
42
|
expect(
|
|
43
43
|
screen.getByRole("button", { name: "Choose date" })
|
|
@@ -46,7 +46,7 @@ describe("<DateInputField />", () => {
|
|
|
46
46
|
})
|
|
47
47
|
|
|
48
48
|
it("has helpful label showing the current date when one is selected", async () => {
|
|
49
|
-
|
|
49
|
+
render(
|
|
50
50
|
<DateInputFieldWrapper
|
|
51
51
|
value="Mar 1, 2022"
|
|
52
52
|
onChange={(): void => undefined}
|
|
@@ -62,7 +62,7 @@ describe("<DateInputField />", () => {
|
|
|
62
62
|
|
|
63
63
|
describe("States", () => {
|
|
64
64
|
it("disables both input and icon button", async () => {
|
|
65
|
-
|
|
65
|
+
render(<DateInputFieldWrapper disabled />)
|
|
66
66
|
const input = screen.getByRole("textbox", { name: "Bacon expiry" })
|
|
67
67
|
const calendarButton = screen.getByRole("button", { name: "Choose date" })
|
|
68
68
|
await waitFor(() => {
|
|
@@ -74,7 +74,7 @@ describe("<DateInputField />", () => {
|
|
|
74
74
|
|
|
75
75
|
describe("Validation", () => {
|
|
76
76
|
it("shows validation message", async () => {
|
|
77
|
-
|
|
77
|
+
render(
|
|
78
78
|
<DateInputFieldWrapper
|
|
79
79
|
status="error"
|
|
80
80
|
validationMessage="There is an error"
|
|
@@ -87,7 +87,7 @@ describe("<DateInputField />", () => {
|
|
|
87
87
|
})
|
|
88
88
|
|
|
89
89
|
it("does not show validation message when field is disabled", async () => {
|
|
90
|
-
|
|
90
|
+
render(
|
|
91
91
|
<DateInputFieldWrapper
|
|
92
92
|
status="error"
|
|
93
93
|
validationMessage="There is an error"
|
|
@@ -106,7 +106,7 @@ describe("<DateInputField />", () => {
|
|
|
106
106
|
|
|
107
107
|
describe("Refs", () => {
|
|
108
108
|
it("correctly passes through input and button refs", async () => {
|
|
109
|
-
const onButtonClick =
|
|
109
|
+
const onButtonClick = vi.fn()
|
|
110
110
|
|
|
111
111
|
const Wrapper = (): JSX.Element => {
|
|
112
112
|
const inputRef = useRef<HTMLInputElement>(null)
|
|
@@ -125,7 +125,7 @@ describe("<DateInputField />", () => {
|
|
|
125
125
|
ref={ref}
|
|
126
126
|
id="test__date-input-field--ref"
|
|
127
127
|
labelText="Adventure time"
|
|
128
|
-
onButtonClick={
|
|
128
|
+
onButtonClick={vi.fn()}
|
|
129
129
|
locale={enUS}
|
|
130
130
|
/>
|
|
131
131
|
<button type="button" onClick={handleClick}>
|
|
@@ -135,7 +135,7 @@ describe("<DateInputField />", () => {
|
|
|
135
135
|
)
|
|
136
136
|
}
|
|
137
137
|
|
|
138
|
-
|
|
138
|
+
render(<Wrapper />)
|
|
139
139
|
|
|
140
140
|
await user.click(screen.getByText("Click me"))
|
|
141
141
|
expect(onButtonClick).toHaveBeenCalledWith(
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import { screen, waitFor } from "@testing-library/react"
|
|
2
|
-
import { renderWithIntl } from "~tests"
|
|
1
|
+
import { screen, waitFor, render } from "@testing-library/react"
|
|
3
2
|
import { validateDate } from "./validateDate"
|
|
4
3
|
|
|
5
4
|
describe("validateDate", () => {
|
|
@@ -40,7 +39,7 @@ describe("validateDate", () => {
|
|
|
40
39
|
})
|
|
41
40
|
expect(newDate).toBeUndefined()
|
|
42
41
|
|
|
43
|
-
|
|
42
|
+
render(validationMessage)
|
|
44
43
|
await waitFor(() => {
|
|
45
44
|
expect(screen.getByText("Date is invalid")).toBeVisible()
|
|
46
45
|
})
|
|
@@ -64,7 +63,7 @@ describe("validateDate", () => {
|
|
|
64
63
|
})
|
|
65
64
|
expect(newDate).toBeUndefined()
|
|
66
65
|
|
|
67
|
-
|
|
66
|
+
render(validationMessage)
|
|
68
67
|
await waitFor(() => {
|
|
69
68
|
expect(screen.getByText("Date is invalid")).toBeVisible()
|
|
70
69
|
})
|
|
@@ -88,7 +87,7 @@ describe("validateDate", () => {
|
|
|
88
87
|
})
|
|
89
88
|
expect(newDate).toBeUndefined()
|
|
90
89
|
|
|
91
|
-
|
|
90
|
+
render(validationMessage)
|
|
92
91
|
await waitFor(() => {
|
|
93
92
|
expect(screen.getByText("potato is an invalid date")).toBeVisible()
|
|
94
93
|
})
|
|
@@ -117,7 +116,7 @@ describe("validateDate", () => {
|
|
|
117
116
|
})
|
|
118
117
|
expect(newDate).toBeUndefined()
|
|
119
118
|
|
|
120
|
-
|
|
119
|
+
render(validationMessage)
|
|
121
120
|
await waitFor(() => {
|
|
122
121
|
expect(
|
|
123
122
|
screen.getByText("03/01/2022 is not available, try another date")
|
|
@@ -2,7 +2,7 @@ import React from "react"
|
|
|
2
2
|
import { cleanup, render } from "@testing-library/react"
|
|
3
3
|
import { EmptyState, EmptyStateProps } from "./EmptyState"
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
vi.mock("~components/Illustration", () => ({
|
|
6
6
|
EmptyStatesPositive: (): JSX.Element => (
|
|
7
7
|
<div>EmptyStatesPositive_Component</div>
|
|
8
8
|
),
|