@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
|
@@ -11,12 +11,12 @@ const defaultProps = {
|
|
|
11
11
|
ariaLabelNextPage: "Next page",
|
|
12
12
|
ariaLabelPreviousPage: "Previous page",
|
|
13
13
|
ariaLabelPage: "Page",
|
|
14
|
-
onPageChange:
|
|
14
|
+
onPageChange: vi.fn(),
|
|
15
15
|
}
|
|
16
16
|
|
|
17
17
|
describe("<Pagination />", () => {
|
|
18
18
|
it("calls onPageChange when clicking page number", async () => {
|
|
19
|
-
const onPageChange =
|
|
19
|
+
const onPageChange = vi.fn()
|
|
20
20
|
|
|
21
21
|
render(<Pagination {...defaultProps} onPageChange={onPageChange} />)
|
|
22
22
|
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import React from "react"
|
|
2
2
|
import { render } from "@testing-library/react"
|
|
3
|
+
import { vi } from "vitest"
|
|
3
4
|
import { RichTextContentProps } from "../RichTextContent"
|
|
4
5
|
import { EditableRichTextContent } from "./EditableRichTextContent"
|
|
6
|
+
const mockFn = vi.fn()
|
|
5
7
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
jest.mock("../RichTextContent", () => ({
|
|
8
|
+
vi.mock("../RichTextContent", () => ({
|
|
9
9
|
__esModule: true,
|
|
10
10
|
RichTextContent: (props: RichTextContentProps): JSX.Element => {
|
|
11
11
|
mockFn(props)
|
|
@@ -26,7 +26,7 @@ describe("Content props are passed", () => {
|
|
|
26
26
|
<EditableRichTextContent
|
|
27
27
|
content={content}
|
|
28
28
|
labelText=""
|
|
29
|
-
onClick={
|
|
29
|
+
onClick={vi.fn()}
|
|
30
30
|
contentProps={{ id: "sampleId" }}
|
|
31
31
|
/>
|
|
32
32
|
)
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import React, { useState, HTMLAttributes } from "react"
|
|
1
|
+
import React, { useState, HTMLAttributes, useId, useEffect } from "react"
|
|
2
2
|
import classnames from "classnames"
|
|
3
3
|
import { OverrideClassName } from "~components/types/OverrideClassName"
|
|
4
4
|
import { createSchemaWithAll } from "../RichTextEditor/schema"
|
|
@@ -14,6 +14,13 @@ export type RichTextContentProps = {
|
|
|
14
14
|
export const RichTextContent = (props: RichTextContentProps): JSX.Element => {
|
|
15
15
|
const { content, classNameOverride, ...restProps } = props
|
|
16
16
|
const [schema] = useState<ProseMirrorModel.Schema>(createSchemaWithAll())
|
|
17
|
+
const editorId = useId()
|
|
18
|
+
|
|
19
|
+
useEffect(() => {
|
|
20
|
+
// prosemirror only allows us to set this to false (which has caused a strange bug in the platform)
|
|
21
|
+
// so we have to hack a bit to remove the attribute completely
|
|
22
|
+
document.getElementById(editorId)?.removeAttribute("contenteditable")
|
|
23
|
+
}, [])
|
|
17
24
|
|
|
18
25
|
const [editorRef] = useRichTextEditor(
|
|
19
26
|
ProseMirrorState.EditorState.create({
|
|
@@ -23,7 +30,9 @@ export const RichTextContent = (props: RichTextContentProps): JSX.Element => {
|
|
|
23
30
|
}),
|
|
24
31
|
schema,
|
|
25
32
|
}),
|
|
26
|
-
|
|
33
|
+
{
|
|
34
|
+
id: editorId,
|
|
35
|
+
},
|
|
27
36
|
{
|
|
28
37
|
editable: false,
|
|
29
38
|
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { findByText, waitFor } from "@testing-library/dom"
|
|
2
|
+
import { vi } from "vitest"
|
|
2
3
|
import { createRichTextEditor } from "../core"
|
|
3
4
|
import { addMark } from "./addMark"
|
|
4
5
|
import {
|
|
@@ -7,9 +8,8 @@ import {
|
|
|
7
8
|
simulateTextInsert,
|
|
8
9
|
} from "./fixtures/helpers"
|
|
9
10
|
import { testEditorState, testSchema } from "./fixtures/test-state"
|
|
10
|
-
|
|
11
11
|
describe("addMark()", () => {
|
|
12
|
-
const onChange =
|
|
12
|
+
const onChange = vi.fn()
|
|
13
13
|
const attributes = { "aria-labelledby": "label-text-123" }
|
|
14
14
|
|
|
15
15
|
it("creates an empty wrapper of the given Mark type if no selection is provided", async () => {
|
|
@@ -5,14 +5,15 @@ import {
|
|
|
5
5
|
Transaction,
|
|
6
6
|
} from "prosemirror-state"
|
|
7
7
|
import { findChildrenByType } from "prosemirror-utils"
|
|
8
|
+
// eslint-disable-next-line import/no-extraneous-dependencies
|
|
9
|
+
import { vi } from "vitest"
|
|
8
10
|
import { ProseMirrorModel } from "../../prosemirror"
|
|
9
|
-
|
|
10
11
|
/*
|
|
11
12
|
** This is used handle the JSDom type error issue you may encounter in testing
|
|
12
13
|
** See https://github.com/jsdom/jsdom/issues/3002
|
|
13
14
|
*/
|
|
14
15
|
export const mockRangeForBoundingRect = (): void => {
|
|
15
|
-
|
|
16
|
+
vi.spyOn(document, "createRange").mockImplementation(() => {
|
|
16
17
|
const range = new Range()
|
|
17
18
|
|
|
18
19
|
range.getBoundingClientRect = () => ({
|
|
@@ -30,7 +31,7 @@ export const mockRangeForBoundingRect = (): void => {
|
|
|
30
31
|
range.getClientRects = () => ({
|
|
31
32
|
item: () => null,
|
|
32
33
|
length: 0,
|
|
33
|
-
[Symbol.iterator]:
|
|
34
|
+
[Symbol.iterator]: vi.fn(),
|
|
34
35
|
})
|
|
35
36
|
|
|
36
37
|
return range
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { waitFor } from "@testing-library/dom"
|
|
2
2
|
import { EditorState } from "prosemirror-state"
|
|
3
|
+
import { vi } from "vitest"
|
|
3
4
|
import { createRichTextEditor } from "../core"
|
|
4
5
|
import { simulateSelectionByText } from "./fixtures/helpers"
|
|
5
6
|
import { testEditorStateWithMarks, testSchema } from "./fixtures/test-state"
|
|
6
7
|
import { getMarkAttrs } from "./getMarkAttrs"
|
|
7
|
-
|
|
8
8
|
describe("getMarkAttrs()", () => {
|
|
9
|
-
const onChange =
|
|
9
|
+
const onChange = vi.fn()
|
|
10
10
|
const attributes = { "aria-labelledby": "label-text-123" }
|
|
11
11
|
|
|
12
12
|
it("returns an empty object if the selected Mark has no attributes", async () => {
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { waitFor } from "@testing-library/dom"
|
|
2
2
|
import { EditorState } from "prosemirror-state"
|
|
3
|
+
import { vi } from "vitest"
|
|
3
4
|
import { createRichTextEditor } from "../core"
|
|
4
5
|
import { simulateSelectionByText } from "./fixtures/helpers"
|
|
5
6
|
import { testEditorStateWithMarks } from "./fixtures/test-state"
|
|
6
7
|
import { getMarkRange } from "./getMarkRange"
|
|
7
|
-
|
|
8
8
|
describe("getMarkRange()", () => {
|
|
9
|
-
const onChange =
|
|
9
|
+
const onChange = vi.fn()
|
|
10
10
|
const attributes = { "aria-labelledby": "label-text-123" }
|
|
11
11
|
|
|
12
12
|
it("returns the entire range of the Mark provided from a resolved position", async () => {
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { waitFor } from "@testing-library/dom"
|
|
2
2
|
import { EditorState } from "prosemirror-state"
|
|
3
|
+
import { vi } from "vitest"
|
|
3
4
|
import { createRichTextEditor } from "../core"
|
|
4
5
|
import { simulateSelectionByText } from "./fixtures/helpers"
|
|
5
6
|
import { testEditorStateWitList, testSchema } from "./fixtures/test-state"
|
|
6
7
|
import { listIsActive } from "./listIsActive"
|
|
7
|
-
|
|
8
8
|
describe("listIsActive()", () => {
|
|
9
|
-
const onChange =
|
|
9
|
+
const onChange = vi.fn()
|
|
10
10
|
const attributes = { "aria-labelledby": "label-text-123" }
|
|
11
11
|
const listNodes = [testSchema.nodes.bulletList, testSchema.nodes.orderedList]
|
|
12
12
|
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { waitFor } from "@testing-library/dom"
|
|
2
2
|
import { EditorState } from "prosemirror-state"
|
|
3
|
+
import { vi } from "vitest"
|
|
3
4
|
import { createRichTextEditor } from "../core"
|
|
4
5
|
import { simulateSelectionByText } from "./fixtures/helpers"
|
|
5
6
|
import { testEditorStateWithMarks, testSchema } from "./fixtures/test-state"
|
|
6
7
|
import { markContainsSelection } from "./markContainsSelection"
|
|
7
|
-
|
|
8
8
|
describe("markContainsSelection()", () => {
|
|
9
|
-
const onChange =
|
|
9
|
+
const onChange = vi.fn()
|
|
10
10
|
const attributes = { "aria-labelledby": "label-text-123" }
|
|
11
11
|
|
|
12
12
|
it("will return true if the current select contains the provided Mark", async () => {
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { waitFor } from "@testing-library/dom"
|
|
2
2
|
import { EditorState } from "prosemirror-state"
|
|
3
|
+
import { vi } from "vitest"
|
|
3
4
|
import { createRichTextEditor } from "../core"
|
|
4
5
|
import {
|
|
5
6
|
simulateRangeSelection,
|
|
@@ -7,9 +8,8 @@ import {
|
|
|
7
8
|
} from "./fixtures/helpers"
|
|
8
9
|
import { testEditorStateWithMarks, testSchema } from "./fixtures/test-state"
|
|
9
10
|
import { markIsActive } from "./markIsActive"
|
|
10
|
-
|
|
11
11
|
describe("markIsActive()", () => {
|
|
12
|
-
const onChange =
|
|
12
|
+
const onChange = vi.fn()
|
|
13
13
|
const attributes = { "aria-labelledby": "label-text-123" }
|
|
14
14
|
|
|
15
15
|
it("returns true if the provided Mark Type matches the current selection", async () => {
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { findByText, getByText, waitFor } from "@testing-library/dom"
|
|
2
|
+
import { vi } from "vitest"
|
|
2
3
|
import { createRichTextEditor } from "../core"
|
|
3
4
|
import { simulateSelectionByText } from "./fixtures/helpers"
|
|
4
5
|
import { testEditorStateWithMarks, testSchema } from "./fixtures/test-state"
|
|
5
6
|
import { removeMark } from "./removeMark"
|
|
6
|
-
|
|
7
7
|
describe("removeMark()", () => {
|
|
8
|
-
const onChange =
|
|
8
|
+
const onChange = vi.fn()
|
|
9
9
|
const attributes = { "aria-labelledby": "label-text-123" }
|
|
10
10
|
|
|
11
11
|
it("removes the given <strong> Mark from a paragraph in the document", async () => {
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { getByRole, getByText, waitFor } from "@testing-library/dom"
|
|
2
|
+
import { vi } from "vitest"
|
|
2
3
|
import { createRichTextEditor } from "../core"
|
|
3
4
|
import { simulateSelectionByText } from "./fixtures/helpers"
|
|
4
5
|
import { testEditorStateWithMarks, testSchema } from "./fixtures/test-state"
|
|
5
6
|
import { updateMark } from "./updateMark"
|
|
6
|
-
|
|
7
7
|
describe("updateMark()", () => {
|
|
8
|
-
const onChange =
|
|
8
|
+
const onChange = vi.fn()
|
|
9
9
|
const attributes = { "aria-labelledby": "label-text-123" }
|
|
10
10
|
|
|
11
11
|
it("can update existing Mark with a nested Mark", async () => {
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { findByText, waitFor } from "@testing-library/dom"
|
|
2
|
+
import { vi } from "vitest"
|
|
2
3
|
import { createRichTextEditor } from "../core"
|
|
3
4
|
import { testEditorStateWithMarks, testSchema } from "./fixtures/test-state"
|
|
4
5
|
import { validateAndRemoveMarks } from "./validateAndRemoveMarks"
|
|
5
|
-
|
|
6
6
|
describe("validateAndRemoveMarks()", () => {
|
|
7
|
-
const onChange =
|
|
7
|
+
const onChange = vi.fn()
|
|
8
8
|
const attributes = { "aria-labelledby": "label-text-123" }
|
|
9
9
|
|
|
10
10
|
it("removes all Marks of the given type that fail the validator method", async () => {
|
|
@@ -16,7 +16,7 @@ describe("validateAndRemoveMarks()", () => {
|
|
|
16
16
|
initialEditorState: testEditorStateWithMarks,
|
|
17
17
|
})
|
|
18
18
|
// The current mockData will always return true so using the mock to represent bad attributes
|
|
19
|
-
const failingValidatorMethod =
|
|
19
|
+
const failingValidatorMethod = vi.fn().mockImplementation(() => false)
|
|
20
20
|
|
|
21
21
|
expect(node.querySelectorAll("a").length).toBeGreaterThan(0)
|
|
22
22
|
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import { findByText, queryByText, getByText } from "@testing-library/dom"
|
|
2
2
|
import { Command, EditorState } from "prosemirror-state"
|
|
3
|
+
import { vi } from "vitest"
|
|
3
4
|
import { createRichTextEditor } from "./createRichTextEditor"
|
|
4
5
|
import { testEditorState } from "./fixtures/testState"
|
|
5
|
-
|
|
6
6
|
describe("createRichTextEditor()", () => {
|
|
7
7
|
const attributes = { "aria-labelledby": "label-text-123" }
|
|
8
8
|
|
|
9
9
|
it("initializes an editor with the correct content", async () => {
|
|
10
10
|
const node = document.createElement("div")
|
|
11
|
-
const onChange =
|
|
11
|
+
const onChange = vi.fn()
|
|
12
12
|
|
|
13
13
|
createRichTextEditor({
|
|
14
14
|
node,
|
|
@@ -23,7 +23,7 @@ describe("createRichTextEditor()", () => {
|
|
|
23
23
|
|
|
24
24
|
it("returns the expected API shape", async () => {
|
|
25
25
|
const node = document.createElement("div")
|
|
26
|
-
const onChange =
|
|
26
|
+
const onChange = vi.fn()
|
|
27
27
|
|
|
28
28
|
const returnValue = createRichTextEditor({
|
|
29
29
|
node,
|
|
@@ -39,7 +39,7 @@ describe("createRichTextEditor()", () => {
|
|
|
39
39
|
|
|
40
40
|
it("destroys the instance", async () => {
|
|
41
41
|
const node = document.createElement("div")
|
|
42
|
-
const onChange =
|
|
42
|
+
const onChange = vi.fn()
|
|
43
43
|
|
|
44
44
|
const { destroy } = createRichTextEditor({
|
|
45
45
|
node,
|
|
@@ -58,7 +58,7 @@ describe("createRichTextEditor()", () => {
|
|
|
58
58
|
|
|
59
59
|
it("updates the DOM when commands are dispatched", async () => {
|
|
60
60
|
const node = document.createElement("div")
|
|
61
|
-
const onChange =
|
|
61
|
+
const onChange = vi.fn()
|
|
62
62
|
|
|
63
63
|
const command: Command = (state, dispatch) => {
|
|
64
64
|
// Insert text at the current selection point, which is the start because
|
|
@@ -87,7 +87,7 @@ describe("createRichTextEditor()", () => {
|
|
|
87
87
|
|
|
88
88
|
it("calls onChange when the editor state changes", async () => {
|
|
89
89
|
const node = document.createElement("div")
|
|
90
|
-
const onChange =
|
|
90
|
+
const onChange = vi.fn()
|
|
91
91
|
const command: Command = (state, dispatch) => {
|
|
92
92
|
if (!dispatch) return false
|
|
93
93
|
dispatch(state.tr.insertText("Prepended content. "))
|
|
@@ -110,7 +110,7 @@ describe("createRichTextEditor()", () => {
|
|
|
110
110
|
|
|
111
111
|
it("calls onChange with the updated state", async () => {
|
|
112
112
|
const node = document.createElement("div")
|
|
113
|
-
const onChange =
|
|
113
|
+
const onChange = vi.fn()
|
|
114
114
|
const command: Command = (state, dispatch) => {
|
|
115
115
|
if (!dispatch) return false
|
|
116
116
|
dispatch(state.tr.insertText("Prepended content. "))
|
|
@@ -155,7 +155,7 @@ describe("createRichTextEditor()", () => {
|
|
|
155
155
|
|
|
156
156
|
it("defaults to editable", async () => {
|
|
157
157
|
const node = document.createElement("div")
|
|
158
|
-
const onChange =
|
|
158
|
+
const onChange = vi.fn()
|
|
159
159
|
|
|
160
160
|
createRichTextEditor({
|
|
161
161
|
node,
|
|
@@ -169,7 +169,7 @@ describe("createRichTextEditor()", () => {
|
|
|
169
169
|
|
|
170
170
|
it("respects initial isEditable value", async () => {
|
|
171
171
|
const node = document.createElement("div")
|
|
172
|
-
const onChange =
|
|
172
|
+
const onChange = vi.fn()
|
|
173
173
|
|
|
174
174
|
createRichTextEditor({
|
|
175
175
|
node,
|
|
@@ -185,7 +185,7 @@ describe("createRichTextEditor()", () => {
|
|
|
185
185
|
it("updates editable status", async () => {
|
|
186
186
|
let editable = true
|
|
187
187
|
const node = document.createElement("div")
|
|
188
|
-
const onChange =
|
|
188
|
+
const onChange = vi.fn()
|
|
189
189
|
const noopCommand: Command = (state, dispatch) => {
|
|
190
190
|
if (!dispatch) return false
|
|
191
191
|
dispatch(state.tr)
|
|
@@ -211,7 +211,7 @@ describe("createRichTextEditor()", () => {
|
|
|
211
211
|
it("aria-labelledby is present", async () => {
|
|
212
212
|
const editable = true
|
|
213
213
|
const node = document.createElement("div")
|
|
214
|
-
const onChange =
|
|
214
|
+
const onChange = vi.fn()
|
|
215
215
|
const noopCommand: Command = (state, dispatch) => {
|
|
216
216
|
if (!dispatch) return false
|
|
217
217
|
dispatch(state.tr)
|
|
@@ -2,9 +2,9 @@ import React, { useEffect } from "react"
|
|
|
2
2
|
import { render, screen, waitFor } from "@testing-library/react"
|
|
3
3
|
import userEvent from "@testing-library/user-event"
|
|
4
4
|
import { Command, EditorState } from "prosemirror-state"
|
|
5
|
+
import { vi } from "vitest"
|
|
5
6
|
import { testEditorState } from "../fixtures/testState"
|
|
6
7
|
import { useRichTextEditor } from "./useRichTextEditor"
|
|
7
|
-
|
|
8
8
|
const user = userEvent.setup()
|
|
9
9
|
|
|
10
10
|
const Scenario = ({
|
|
@@ -76,7 +76,7 @@ describe("useRichTextEditor()", () => {
|
|
|
76
76
|
})
|
|
77
77
|
|
|
78
78
|
it("updates the editorState when commands are dispatched", async () => {
|
|
79
|
-
const onChange =
|
|
79
|
+
const onChange = vi.fn()
|
|
80
80
|
render(<Scenario onChange={onChange} />)
|
|
81
81
|
|
|
82
82
|
await waitFor(() => {
|
|
@@ -1,7 +1,7 @@
|
|
|
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 } from "vitest"
|
|
5
5
|
import { MenuItem, MenuList } from "~components/__actions__/v2"
|
|
6
6
|
import { SplitButton, SplitButtonProps } from "./SplitButton"
|
|
7
7
|
|
|
@@ -13,7 +13,7 @@ const SplitButtonWrapper = (
|
|
|
13
13
|
<SplitButton
|
|
14
14
|
actionButtonProps={{
|
|
15
15
|
label: "Action Text",
|
|
16
|
-
onClick:
|
|
16
|
+
onClick: vi.fn(),
|
|
17
17
|
}}
|
|
18
18
|
dropdownButtonProps={{
|
|
19
19
|
"aria-label": "Dropdown Label",
|
|
@@ -30,7 +30,7 @@ const SplitButtonWrapper = (
|
|
|
30
30
|
|
|
31
31
|
describe("<SplitButton />", () => {
|
|
32
32
|
it("renders the correct structure", async () => {
|
|
33
|
-
|
|
33
|
+
render(<SplitButtonWrapper />)
|
|
34
34
|
await waitFor(() => {
|
|
35
35
|
expect(screen.getByText("Action Text")).toBeInTheDocument()
|
|
36
36
|
})
|
|
@@ -46,7 +46,7 @@ describe("<SplitButton />", () => {
|
|
|
46
46
|
})
|
|
47
47
|
|
|
48
48
|
it("disables both buttons when disabled is true", async () => {
|
|
49
|
-
|
|
49
|
+
render(<SplitButtonWrapper disabled />)
|
|
50
50
|
await waitFor(() => {
|
|
51
51
|
expect(screen.getByText("Action Text").closest("button")).toBeDisabled()
|
|
52
52
|
})
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import React from "react"
|
|
2
|
-
import { screen, waitFor } from "@testing-library/react"
|
|
3
|
-
import { renderWithIntl } from "~tests"
|
|
2
|
+
import { screen, waitFor, render } from "@testing-library/react"
|
|
4
3
|
import { DropdownButton, DropdownButtonProps } from "./DropdownButton"
|
|
5
4
|
|
|
6
5
|
const DropdownButtonWrapper = (
|
|
@@ -9,7 +8,7 @@ const DropdownButtonWrapper = (
|
|
|
9
8
|
|
|
10
9
|
describe("<DropdownButton />", () => {
|
|
11
10
|
it("renders icon with default aria-label", async () => {
|
|
12
|
-
|
|
11
|
+
render(<DropdownButtonWrapper />)
|
|
13
12
|
await waitFor(() => {
|
|
14
13
|
const button = screen.getByRole("button", { name: "Additional actions" })
|
|
15
14
|
expect(button.getAttribute("aria-label")).toBe("Additional actions")
|
|
@@ -18,7 +17,7 @@ describe("<DropdownButton />", () => {
|
|
|
18
17
|
})
|
|
19
18
|
|
|
20
19
|
it("renders custom aria-label", async () => {
|
|
21
|
-
|
|
20
|
+
render(<DropdownButtonWrapper aria-label="Custom aria label" />)
|
|
22
21
|
await waitFor(() => {
|
|
23
22
|
const button = screen.getByRole("button", { name: "Custom aria label" })
|
|
24
23
|
expect(button.getAttribute("aria-label")).toBe("Custom aria label")
|
package/src/Text/Text.spec.tsx
CHANGED
|
@@ -1,30 +1,8 @@
|
|
|
1
1
|
import * as React from "react"
|
|
2
2
|
import { render } from "@testing-library/react"
|
|
3
|
-
import {
|
|
3
|
+
import { AllowedTextTags, Text, TextVariants } from "."
|
|
4
4
|
|
|
5
5
|
describe("<Text />", () => {
|
|
6
|
-
describe("renders the correct variant classes", () => {
|
|
7
|
-
const testCases: TextVariants[] = [
|
|
8
|
-
"intro-lede",
|
|
9
|
-
"body",
|
|
10
|
-
"small",
|
|
11
|
-
"extra-small",
|
|
12
|
-
]
|
|
13
|
-
|
|
14
|
-
testCases.forEach(variant => {
|
|
15
|
-
it(`renders the correct element for <Text variant={${variant}} />`, () => {
|
|
16
|
-
const textMock = render(
|
|
17
|
-
<Text variant={variant} tag="div">
|
|
18
|
-
Example
|
|
19
|
-
</Text>
|
|
20
|
-
)
|
|
21
|
-
const textClasslist = textMock.getByText("Example").classList
|
|
22
|
-
expect(textClasslist).toContain("text")
|
|
23
|
-
expect(textClasslist).toContain(variant)
|
|
24
|
-
})
|
|
25
|
-
})
|
|
26
|
-
})
|
|
27
|
-
|
|
28
6
|
describe("changes rendered HTML element when passed tag", () => {
|
|
29
7
|
const testCases: TextVariants[] = [
|
|
30
8
|
"intro-lede",
|
|
@@ -45,30 +23,6 @@ describe("<Text />", () => {
|
|
|
45
23
|
})
|
|
46
24
|
})
|
|
47
25
|
|
|
48
|
-
describe("renders the correct color classes", () => {
|
|
49
|
-
const testCases: AllowedTextColors[] = [
|
|
50
|
-
"dark",
|
|
51
|
-
"dark-reduced-opacity",
|
|
52
|
-
"white",
|
|
53
|
-
"white-reduced-opacity",
|
|
54
|
-
"positive",
|
|
55
|
-
"negative",
|
|
56
|
-
]
|
|
57
|
-
|
|
58
|
-
testCases.forEach(color => {
|
|
59
|
-
it(`renders the correct class for <Text color={${color}} />`, () => {
|
|
60
|
-
const textMock = render(
|
|
61
|
-
<Text variant="body" color={color} tag="div">
|
|
62
|
-
Example
|
|
63
|
-
</Text>
|
|
64
|
-
)
|
|
65
|
-
const textClasslist = textMock.getByText("Example").classList
|
|
66
|
-
expect(textClasslist).toContain("text")
|
|
67
|
-
expect(textClasslist).toContain(color)
|
|
68
|
-
})
|
|
69
|
-
})
|
|
70
|
-
})
|
|
71
|
-
|
|
72
26
|
it("passes through data attributes", () => {
|
|
73
27
|
const { getByTestId } = render(
|
|
74
28
|
<Text variant="intro-lede" data-testid="test-id">
|
|
@@ -91,17 +45,7 @@ describe("<Text />", () => {
|
|
|
91
45
|
it(`renders the correct element for <Text variant={${variant}} />`, () => {
|
|
92
46
|
const textMock = render(<Text variant={variant}>Example</Text>)
|
|
93
47
|
expect(textMock.getByText("Example").tagName.toLowerCase()).toBe(el)
|
|
94
|
-
expect(textMock.baseElement).toMatchSnapshot()
|
|
95
48
|
})
|
|
96
49
|
})
|
|
97
50
|
})
|
|
98
|
-
|
|
99
|
-
it("allows consumers to provide a className", () => {
|
|
100
|
-
const { getByText } = render(
|
|
101
|
-
<Text variant="body" classNameOverride="example-classname">
|
|
102
|
-
Example
|
|
103
|
-
</Text>
|
|
104
|
-
)
|
|
105
|
-
expect(getByText("Example").classList).toContain("example-classname")
|
|
106
|
-
})
|
|
107
51
|
})
|
|
@@ -1,8 +1,8 @@
|
|
|
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 { vi } from "vitest"
|
|
4
5
|
import { TextArea } from "./TextArea"
|
|
5
|
-
|
|
6
6
|
const user = userEvent.setup()
|
|
7
7
|
|
|
8
8
|
describe("<TextArea />", () => {
|
|
@@ -22,7 +22,7 @@ describe("<TextArea />", () => {
|
|
|
22
22
|
})
|
|
23
23
|
|
|
24
24
|
it("calls the `onChange` event when the value is updated", async () => {
|
|
25
|
-
const mockFn =
|
|
25
|
+
const mockFn = vi.fn()
|
|
26
26
|
const { getByRole } = render(<TextArea onChange={mockFn} />)
|
|
27
27
|
|
|
28
28
|
await user.type(getByRole("textbox"), "Hello")
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import React, { useState } 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 { TimeField, TimeFieldProps } from "./TimeField"
|
|
5
6
|
import { ValueType } from "./types"
|
|
6
|
-
|
|
7
7
|
const user = userEvent.setup()
|
|
8
8
|
|
|
9
|
-
const mockOnChange =
|
|
9
|
+
const mockOnChange = vi.fn()
|
|
10
10
|
const LABEL = "Launch Time Label"
|
|
11
11
|
|
|
12
12
|
const pressArrowKey =
|