@simplybusiness/mobius 8.0.1 → 9.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +45 -0
- package/dist/cjs/index.js +4773 -0
- package/dist/cjs/index.js.map +7 -0
- package/dist/cjs/meta.json +4948 -0
- package/dist/esm/index.js +542 -694
- package/dist/esm/index.js.map +4 -4
- package/dist/esm/meta.json +300 -532
- package/dist/esm/tsconfig.build.tsbuildinfo +1 -1
- package/dist/types/src/hooks/index.d.ts +0 -7
- package/dist/types/src/utils/htmlDialogPolyfill.d.ts +1 -0
- package/dist/types/src/utils/index.d.ts +0 -1
- package/dist/types/src/utils/mockMatchMedia.d.ts +1 -0
- package/dist/types/vitest.config.d.ts +2 -0
- package/package.json +14 -18
- package/src/components/Accordion/Accordion.stories.tsx +1 -1
- package/src/components/Accordion/Accordion.test.tsx +12 -12
- package/src/components/Accordion/Accordion.tsx +1 -1
- package/src/components/Accordion/AccordionList.stories.tsx +1 -1
- package/src/components/Accordion/AccordionList.test.tsx +6 -6
- package/src/components/AddressLookup/AddressLookup.stories.tsx +1 -1
- package/src/components/AddressLookup/AddressLookup.test.tsx +19 -20
- package/src/components/AddressLookup/LoqateAddressLookupService.test.tsx +7 -6
- package/src/components/Alert/Alert.stories.tsx +1 -1
- package/src/components/Box/Box.stories.tsx +1 -1
- package/src/components/Breadcrumbs/Breadcrumbs.stories.tsx +1 -1
- package/src/components/Button/Button.stories.tsx +3 -4
- package/src/components/Button/Button.test.tsx +4 -4
- package/src/components/Checkbox/Checkbox.stories.tsx +1 -1
- package/src/components/Checkbox/Checkbox.test.tsx +2 -2
- package/src/components/Checkbox/CheckboxGroup.stories.tsx +1 -1
- package/src/components/Checkbox/CheckboxGroup.test.tsx +5 -5
- package/src/components/Combobox/Combobox.stories.tsx +1 -1
- package/src/components/Combobox/Combobox.test.tsx +67 -78
- package/src/components/Combobox/Combobox.tsx +2 -1
- package/src/components/Combobox/useComboboxOptions.test.ts +30 -30
- package/src/components/Combobox/useComboboxOptions.ts +1 -1
- package/src/components/Container/Container.stories.tsx +1 -1
- package/src/components/DateField/DateField.stories.tsx +1 -1
- package/src/components/DateField/DateField.test.tsx +1 -1
- package/src/components/Divider/Divider.stories.tsx +1 -1
- package/src/components/Drawer/Drawer.stories.tsx +1 -1
- package/src/components/Drawer/Drawer.test.tsx +6 -6
- package/src/components/DropdownMenu/DropdownMenu.stories.tsx +8 -10
- package/src/components/DropdownMenu/DropdownMenu.test.tsx +1 -1
- package/src/components/ErrorMessage/ErrorMessage.stories.tsx +1 -1
- package/src/components/ExpandableText/ExpandableText.test.tsx +14 -14
- package/src/components/Fieldset/Fieldset.stories.tsx +1 -1
- package/src/components/Flex/Flex.stories.tsx +1 -1
- package/src/components/Grid/Grid.stories.tsx +4 -7
- package/src/components/Icon/Icon.stories.tsx +1 -1
- package/src/components/Image/Image.stories.tsx +1 -1
- package/src/components/Label/Label.stories.tsx +1 -1
- package/src/components/Link/Link.stories.tsx +1 -1
- package/src/components/Link/Link.test.tsx +1 -1
- package/src/components/LinkButton/LinkButton.stories.tsx +1 -1
- package/src/components/LinkButton/LinkButton.test.tsx +2 -2
- package/src/components/List/List.stories.tsx +1 -1
- package/src/components/LoadingIndicator/LoadingIndicator.stories.tsx +1 -1
- package/src/components/Logo/Logo.stories.tsx +1 -1
- package/src/components/Modal/Modal.stories.tsx +1 -1
- package/src/components/Modal/Modal.test.tsx +6 -6
- package/src/components/NumberField/NumberField.stories.tsx +1 -1
- package/src/components/NumberField/NumberField.test.tsx +5 -5
- package/src/components/PasswordField/PasswordField.stories.tsx +1 -1
- package/src/components/Popover/Popover.stories.tsx +4 -8
- package/src/components/Popover/Popover.test.tsx +4 -4
- package/src/components/Popover/Popover.tsx +1 -1
- package/src/components/Progress/Progress.stories.tsx +1 -1
- package/src/components/Radio/Radio.stories.tsx +1 -1
- package/src/components/Radio/Radio.test.tsx +9 -9
- package/src/components/SVG/SVG.stories.tsx +1 -1
- package/src/components/Segment/Segment.stories.tsx +1 -1
- package/src/components/Select/Select.stories.tsx +1 -1
- package/src/components/Select/Select.test.tsx +1 -1
- package/src/components/Slider/Slider.stories.tsx +1 -1
- package/src/components/Slider/Slider.test.tsx +6 -6
- package/src/components/Slider/helpers.test.ts +1 -1
- package/src/components/Stack/Stack.stories.tsx +1 -1
- package/src/components/Switch/Switch.stories.tsx +1 -1
- package/src/components/Switch/Switch.test.tsx +1 -1
- package/src/components/Table/Table.stories.tsx +1 -1
- package/src/components/Text/Text.stories.tsx +1 -1
- package/src/components/TextArea/TextArea.stories.tsx +1 -1
- package/src/components/TextArea/TextArea.test.tsx +3 -3
- package/src/components/TextField/TextField.stories.tsx +1 -1
- package/src/components/TextOrHTML/TextOrHTML.stories.tsx +1 -1
- package/src/components/Title/Title.stories.tsx +1 -1
- package/src/components/Toast/Toast.stories.tsx +1 -1
- package/src/components/Toast/Toast.test.tsx +6 -6
- package/src/components/Trust/Trust.stories.tsx +1 -1
- package/src/components/VisuallyHidden/VisuallyHidden.stories.tsx +1 -1
- package/src/hooks/index.tsx +0 -7
- package/src/hooks/useBreakpoint/useBreakpoint.ssr.test.tsx +18 -0
- package/src/hooks/useBreakpoint/useBreakpoint.stories.tsx +1 -1
- package/src/hooks/useBreakpoint/useBreakpoint.test.tsx +65 -5
- package/src/hooks/useBreakpoint/useBreakpoint.tsx +25 -39
- package/src/hooks/useButton/useButton.test.tsx +4 -4
- package/src/hooks/useDialog/useDialog.ts +1 -1
- package/src/hooks/useLabel/useLabel.test.tsx +1 -1
- package/src/hooks/useTextField/useTextField.test.tsx +4 -4
- package/src/public-whitelist.test.ts +1 -0
- package/src/utils/delay.test.ts +4 -4
- package/src/utils/{jestHTMLDialogPolyfill.ts → htmlDialogPolyfill.ts} +5 -5
- package/src/utils/index.ts +0 -1
- package/src/utils/mockMatchMedia.ts +16 -0
- package/dist/types/src/hooks/useBodyScrollLock/index.d.ts +0 -1
- package/dist/types/src/hooks/useBodyScrollLock/useBodyScrollLock.d.ts +0 -3
- package/dist/types/src/hooks/useDebouncedValue/index.d.ts +0 -1
- package/dist/types/src/hooks/useDebouncedValue/useDebouncedValue.d.ts +0 -1
- package/dist/types/src/hooks/useOnClickOutside/index.d.ts +0 -1
- package/dist/types/src/hooks/useOnClickOutside/useOnClickOutside.d.ts +0 -2
- package/dist/types/src/hooks/useOnUnmount/index.d.ts +0 -1
- package/dist/types/src/hooks/useOnUnmount/useOnUnmount.d.ts +0 -1
- package/dist/types/src/hooks/usePrefersReducedMotion/index.d.ts +0 -1
- package/dist/types/src/hooks/usePrefersReducedMotion/usePrefersReducedMotion.d.ts +0 -1
- package/dist/types/src/hooks/useRenderCount/index.d.ts +0 -1
- package/dist/types/src/hooks/useRenderCount/useRenderCount.d.ts +0 -1
- package/dist/types/src/hooks/useWindowEvent/index.d.ts +0 -1
- package/dist/types/src/hooks/useWindowEvent/useWindowEvent.d.ts +0 -1
- package/dist/types/src/utils/jestHTMLDialogPolyfill.d.ts +0 -1
- package/dist/types/src/utils/jestMockMatchMedia.d.ts +0 -1
- package/src/hooks/useBodyScrollLock/index.ts +0 -1
- package/src/hooks/useBodyScrollLock/useBodyScrollLock.test.ts +0 -34
- package/src/hooks/useBodyScrollLock/useBodyScrollLock.ts +0 -30
- package/src/hooks/useDebouncedValue/index.tsx +0 -1
- package/src/hooks/useDebouncedValue/useDebouncedValue.test.tsx +0 -62
- package/src/hooks/useDebouncedValue/useDebouncedValue.tsx +0 -25
- package/src/hooks/useOnClickOutside/index.tsx +0 -1
- package/src/hooks/useOnClickOutside/useOnClickOutside.test.tsx +0 -189
- package/src/hooks/useOnClickOutside/useOnClickOutside.tsx +0 -44
- package/src/hooks/useOnUnmount/index.tsx +0 -1
- package/src/hooks/useOnUnmount/useOnUnmount.test.tsx +0 -37
- package/src/hooks/useOnUnmount/useOnUnmount.tsx +0 -8
- package/src/hooks/usePrefersReducedMotion/index.tsx +0 -1
- package/src/hooks/usePrefersReducedMotion/usePrefersReducedMotion.test.tsx +0 -48
- package/src/hooks/usePrefersReducedMotion/usePrefersReducedMotion.tsx +0 -22
- package/src/hooks/useRenderCount/index.ts +0 -1
- package/src/hooks/useRenderCount/useRenderCount.test.ts +0 -26
- package/src/hooks/useRenderCount/useRenderCount.ts +0 -9
- package/src/hooks/useWindowEvent/index.tsx +0 -1
- package/src/hooks/useWindowEvent/useWindowEvent.test.tsx +0 -188
- package/src/hooks/useWindowEvent/useWindowEvent.tsx +0 -41
- package/src/utils/jestMockMatchMedia.ts +0 -16
|
@@ -147,7 +147,7 @@ describe("DateField", () => {
|
|
|
147
147
|
|
|
148
148
|
describe("DateField validation on blur", () => {
|
|
149
149
|
it("calls onBlur handler with correct event on blur", async () => {
|
|
150
|
-
const handleChange =
|
|
150
|
+
const handleChange = vi.fn();
|
|
151
151
|
|
|
152
152
|
render(
|
|
153
153
|
<DateField
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { Meta, StoryObj } from "@storybook/react
|
|
1
|
+
import type { Meta, StoryObj } from "@storybook/react";
|
|
2
2
|
import { StoryContainer } from "../../utils/StoryContainer";
|
|
3
3
|
import type { DividerProps } from "./Divider";
|
|
4
4
|
import { Divider } from "./Divider";
|
|
@@ -2,10 +2,10 @@ import { render, screen, waitFor } from "@testing-library/react";
|
|
|
2
2
|
import userEvent from "@testing-library/user-event";
|
|
3
3
|
import { useState } from "react";
|
|
4
4
|
import { Drawer } from ".";
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
5
|
+
import { htmlDialogPolyfill } from "../../utils/htmlDialogPolyfill";
|
|
6
|
+
import { mockMatchMedia } from "../../utils/mockMatchMedia";
|
|
7
7
|
|
|
8
|
-
|
|
8
|
+
htmlDialogPolyfill();
|
|
9
9
|
|
|
10
10
|
const DRAWER_CLASS_NAME = "mobius-drawer";
|
|
11
11
|
const DRAWER_CLOSE_CLASS_NAME = "mobius-drawer__close";
|
|
@@ -13,11 +13,11 @@ const DRAWER_TEST_CLASS_NAME = "my-test-class-name";
|
|
|
13
13
|
|
|
14
14
|
describe("Drawer", () => {
|
|
15
15
|
beforeEach(() => {
|
|
16
|
-
|
|
16
|
+
mockMatchMedia(true);
|
|
17
17
|
});
|
|
18
18
|
|
|
19
19
|
afterAll(() => {
|
|
20
|
-
|
|
20
|
+
vi.resetAllMocks();
|
|
21
21
|
});
|
|
22
22
|
|
|
23
23
|
it("should render without errors", () => {
|
|
@@ -158,7 +158,7 @@ describe("Drawer", () => {
|
|
|
158
158
|
});
|
|
159
159
|
|
|
160
160
|
it("should fire onOpen callback if supplied", async () => {
|
|
161
|
-
const onOpen =
|
|
161
|
+
const onOpen = vi.fn();
|
|
162
162
|
|
|
163
163
|
const App = () => {
|
|
164
164
|
const [isOpen, setIsOpen] = useState<boolean>(false);
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { chevronDown } from "@simplybusiness/icons";
|
|
2
|
-
import type { Meta, StoryObj } from "@storybook/react
|
|
2
|
+
import type { Meta, StoryObj } from "@storybook/react";
|
|
3
3
|
import classNames from "classnames/dedupe";
|
|
4
4
|
import type { Ref } from "react";
|
|
5
5
|
import type { DropdownMenuProps } from ".";
|
|
@@ -7,6 +7,8 @@ import { DropdownMenu } from ".";
|
|
|
7
7
|
import { excludeControls } from "../../utils";
|
|
8
8
|
import { StoryContainer } from "../../utils/StoryContainer";
|
|
9
9
|
import { Icon } from "../Icon";
|
|
10
|
+
// eslint-disable-next-line no-restricted-imports -- story-only styles
|
|
11
|
+
import "./DropdownMenu.story.styles.css";
|
|
10
12
|
|
|
11
13
|
type StoryType = StoryObj<typeof DropdownMenu>;
|
|
12
14
|
|
|
@@ -15,15 +17,11 @@ const meta: Meta<typeof DropdownMenu> = {
|
|
|
15
17
|
component: DropdownMenu,
|
|
16
18
|
argTypes: excludeControls("trigger", "style"),
|
|
17
19
|
decorators: [
|
|
18
|
-
Story =>
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
<Story />
|
|
24
|
-
</StoryContainer>
|
|
25
|
-
);
|
|
26
|
-
},
|
|
20
|
+
Story => (
|
|
21
|
+
<StoryContainer>
|
|
22
|
+
<Story />
|
|
23
|
+
</StoryContainer>
|
|
24
|
+
),
|
|
27
25
|
],
|
|
28
26
|
};
|
|
29
27
|
|
|
@@ -5,27 +5,27 @@ import { ExpandableText } from "./ExpandableText";
|
|
|
5
5
|
// Mock window.matchMedia for usePrefersReducedMotion
|
|
6
6
|
Object.defineProperty(window, "matchMedia", {
|
|
7
7
|
writable: true,
|
|
8
|
-
value:
|
|
8
|
+
value: vi.fn().mockImplementation(query => ({
|
|
9
9
|
matches: false,
|
|
10
10
|
media: query,
|
|
11
11
|
onchange: null,
|
|
12
|
-
addListener:
|
|
13
|
-
removeListener:
|
|
14
|
-
addEventListener:
|
|
15
|
-
removeEventListener:
|
|
16
|
-
dispatchEvent:
|
|
12
|
+
addListener: vi.fn(), // deprecated
|
|
13
|
+
removeListener: vi.fn(), // deprecated
|
|
14
|
+
addEventListener: vi.fn(),
|
|
15
|
+
removeEventListener: vi.fn(),
|
|
16
|
+
dispatchEvent: vi.fn(),
|
|
17
17
|
})),
|
|
18
18
|
});
|
|
19
19
|
|
|
20
20
|
// Mock useBreakpoint hook
|
|
21
21
|
const mockBreakpoint = {
|
|
22
|
-
down:
|
|
23
|
-
up:
|
|
24
|
-
only:
|
|
25
|
-
between:
|
|
22
|
+
down: vi.fn(),
|
|
23
|
+
up: vi.fn(),
|
|
24
|
+
only: vi.fn(),
|
|
25
|
+
between: vi.fn(),
|
|
26
26
|
};
|
|
27
27
|
|
|
28
|
-
|
|
28
|
+
vi.mock("../../hooks/useBreakpoint", () => ({
|
|
29
29
|
useBreakpoint: () => mockBreakpoint,
|
|
30
30
|
}));
|
|
31
31
|
|
|
@@ -35,7 +35,7 @@ describe("ExpandableText", () => {
|
|
|
35
35
|
const shortText = "Short text.";
|
|
36
36
|
|
|
37
37
|
beforeEach(() => {
|
|
38
|
-
|
|
38
|
+
vi.clearAllMocks();
|
|
39
39
|
mockBreakpoint.down.mockReturnValue(true);
|
|
40
40
|
|
|
41
41
|
// Mock scrollHeight and clientHeight to simulate truncation
|
|
@@ -161,7 +161,7 @@ describe("ExpandableText", () => {
|
|
|
161
161
|
|
|
162
162
|
it("calls onToggle callback when state changes", async () => {
|
|
163
163
|
const user = userEvent.setup();
|
|
164
|
-
const onToggle =
|
|
164
|
+
const onToggle = vi.fn();
|
|
165
165
|
render(<ExpandableText text={longText} onToggle={onToggle} />);
|
|
166
166
|
|
|
167
167
|
const readMoreButton = await screen.findByRole("button");
|
|
@@ -217,7 +217,7 @@ describe("ExpandableText", () => {
|
|
|
217
217
|
|
|
218
218
|
it("prevents event propagation on accordion click", async () => {
|
|
219
219
|
const user = userEvent.setup();
|
|
220
|
-
const containerClickHandler =
|
|
220
|
+
const containerClickHandler = vi.fn();
|
|
221
221
|
|
|
222
222
|
render(
|
|
223
223
|
<div onClick={containerClickHandler}>
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { Meta, StoryObj } from "@storybook/react
|
|
1
|
+
import type { Meta, StoryObj } from "@storybook/react";
|
|
2
2
|
import { excludeControls } from "../../utils";
|
|
3
3
|
import { StoryContainer } from "../../utils/StoryContainer";
|
|
4
4
|
import { TextField } from "../TextField";
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { Meta, StoryObj } from "@storybook/react
|
|
1
|
+
import type { Meta, StoryObj } from "@storybook/react";
|
|
2
2
|
import type { ReactNode } from "react";
|
|
3
3
|
import type { GridItemProps, GridProps } from ".";
|
|
4
4
|
import { Grid } from ".";
|
|
@@ -6,6 +6,8 @@ import { Box } from "../Box";
|
|
|
6
6
|
import { Flex } from "../Flex";
|
|
7
7
|
import type { GridItem } from "./Item";
|
|
8
8
|
import { sizeOptions } from "../../utils";
|
|
9
|
+
// eslint-disable-next-line no-restricted-imports -- story-only styles
|
|
10
|
+
import "./Grid.story.styles.css";
|
|
9
11
|
|
|
10
12
|
type StoryType = StoryObj<typeof Grid>;
|
|
11
13
|
|
|
@@ -68,12 +70,7 @@ const meta: Meta<typeof Grid> = {
|
|
|
68
70
|
options: ["", "start", "end", "center", "stretch"],
|
|
69
71
|
},
|
|
70
72
|
},
|
|
71
|
-
decorators: [
|
|
72
|
-
Story => {
|
|
73
|
-
require("./Grid.story.styles.css");
|
|
74
|
-
return <Story />;
|
|
75
|
-
},
|
|
76
|
-
],
|
|
73
|
+
decorators: [Story => <Story />],
|
|
77
74
|
};
|
|
78
75
|
|
|
79
76
|
type SharedProps = {
|
|
@@ -48,7 +48,7 @@ describe("Test for LinkButton", () => {
|
|
|
48
48
|
});
|
|
49
49
|
|
|
50
50
|
it("should call onClick callback if supplied", async () => {
|
|
51
|
-
const onClick =
|
|
51
|
+
const onClick = vi.fn();
|
|
52
52
|
render(
|
|
53
53
|
<LinkButton href="#" onClick={onClick}>
|
|
54
54
|
Link
|
|
@@ -59,7 +59,7 @@ describe("Test for LinkButton", () => {
|
|
|
59
59
|
});
|
|
60
60
|
|
|
61
61
|
it("throws when href is empty", () => {
|
|
62
|
-
const spy =
|
|
62
|
+
const spy = vi.spyOn(console, "error");
|
|
63
63
|
spy.mockImplementation(() => {});
|
|
64
64
|
|
|
65
65
|
render(
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { home, loading, refreshArrow } from "@simplybusiness/icons";
|
|
2
|
-
import type { Meta, StoryObj } from "@storybook/react
|
|
2
|
+
import type { Meta, StoryObj } from "@storybook/react";
|
|
3
3
|
import type { LoadingIndicatorProps } from "./LoadingIndicator";
|
|
4
4
|
import { LoadingIndicator } from "./LoadingIndicator";
|
|
5
5
|
|
|
@@ -2,10 +2,10 @@ import { useState } from "react";
|
|
|
2
2
|
import { render, screen, waitFor } from "@testing-library/react";
|
|
3
3
|
import userEvent from "@testing-library/user-event";
|
|
4
4
|
import { Modal } from ".";
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
5
|
+
import { htmlDialogPolyfill } from "../../utils/htmlDialogPolyfill";
|
|
6
|
+
import { mockMatchMedia } from "../../utils/mockMatchMedia";
|
|
7
7
|
|
|
8
|
-
|
|
8
|
+
htmlDialogPolyfill();
|
|
9
9
|
|
|
10
10
|
const MODAL_CLASS_NAME = "mobius-modal";
|
|
11
11
|
const MODAL_CLOSE_CLASS_NAME = "mobius-modal__close";
|
|
@@ -13,11 +13,11 @@ const MODAL_TEST_CLASS_NAME = "my-test-class-name";
|
|
|
13
13
|
|
|
14
14
|
describe("Modal", () => {
|
|
15
15
|
beforeEach(() => {
|
|
16
|
-
|
|
16
|
+
mockMatchMedia(true);
|
|
17
17
|
});
|
|
18
18
|
|
|
19
19
|
afterAll(() => {
|
|
20
|
-
|
|
20
|
+
vi.resetAllMocks();
|
|
21
21
|
});
|
|
22
22
|
|
|
23
23
|
it("should render without errors", () => {
|
|
@@ -153,7 +153,7 @@ describe("Modal", () => {
|
|
|
153
153
|
});
|
|
154
154
|
|
|
155
155
|
it("should fire onOpen callback if supplied", async () => {
|
|
156
|
-
const onOpen =
|
|
156
|
+
const onOpen = vi.fn();
|
|
157
157
|
|
|
158
158
|
const App = () => {
|
|
159
159
|
const [isOpen, setIsOpen] = useState<boolean>(false);
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { Meta, StoryObj } from "@storybook/react
|
|
1
|
+
import type { Meta, StoryObj } from "@storybook/react";
|
|
2
2
|
import { excludeControls } from "../../utils";
|
|
3
3
|
import { StoryContainer } from "../../utils/StoryContainer";
|
|
4
4
|
import type { NumberFieldProps } from "./NumberField";
|
|
@@ -120,7 +120,7 @@ describe("NumberField", () => {
|
|
|
120
120
|
});
|
|
121
121
|
|
|
122
122
|
it("prevents setting a value < minValue (if set)", () => {
|
|
123
|
-
const mockChange =
|
|
123
|
+
const mockChange = vi.fn();
|
|
124
124
|
render(
|
|
125
125
|
<NumberField
|
|
126
126
|
id="test"
|
|
@@ -145,7 +145,7 @@ describe("NumberField", () => {
|
|
|
145
145
|
});
|
|
146
146
|
|
|
147
147
|
it("prevents setting a value > maxValue (if set)", () => {
|
|
148
|
-
const mockChange =
|
|
148
|
+
const mockChange = vi.fn();
|
|
149
149
|
render(
|
|
150
150
|
<NumberField
|
|
151
151
|
id="test"
|
|
@@ -170,7 +170,7 @@ describe("NumberField", () => {
|
|
|
170
170
|
});
|
|
171
171
|
|
|
172
172
|
it("validates step increments on blur", () => {
|
|
173
|
-
const mockChange =
|
|
173
|
+
const mockChange = vi.fn();
|
|
174
174
|
render(
|
|
175
175
|
<NumberField
|
|
176
176
|
id="test"
|
|
@@ -193,7 +193,7 @@ describe("NumberField", () => {
|
|
|
193
193
|
});
|
|
194
194
|
|
|
195
195
|
it("allows any values during typing (including invalid step increments)", () => {
|
|
196
|
-
const mockChange =
|
|
196
|
+
const mockChange = vi.fn();
|
|
197
197
|
render(
|
|
198
198
|
<NumberField
|
|
199
199
|
id="test"
|
|
@@ -219,7 +219,7 @@ describe("NumberField", () => {
|
|
|
219
219
|
});
|
|
220
220
|
|
|
221
221
|
it("allows typing intermediate values to reach final valid step value", () => {
|
|
222
|
-
const mockChange =
|
|
222
|
+
const mockChange = vi.fn();
|
|
223
223
|
render(
|
|
224
224
|
<NumberField
|
|
225
225
|
id="test"
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { Meta, StoryObj } from "@storybook/react
|
|
1
|
+
import type { Meta, StoryObj } from "@storybook/react";
|
|
2
2
|
import { excludeControls } from "../../utils";
|
|
3
3
|
import { StoryContainer } from "../../utils/StoryContainer";
|
|
4
4
|
import type { PasswordFieldProps } from "./PasswordField";
|
|
@@ -1,8 +1,10 @@
|
|
|
1
|
-
import type { Meta, StoryObj } from "@storybook/react
|
|
1
|
+
import type { Meta, StoryObj } from "@storybook/react";
|
|
2
2
|
import { circleQuestion } from "@simplybusiness/icons";
|
|
3
3
|
import type { PopoverProps } from "..";
|
|
4
4
|
import { Button, Flex, Popover, Icon } from "..";
|
|
5
5
|
import { excludeControls } from "../../utils";
|
|
6
|
+
// eslint-disable-next-line no-restricted-imports -- story-only styles
|
|
7
|
+
import "./Popover.story.styles.css";
|
|
6
8
|
|
|
7
9
|
type StoryType = StoryObj<typeof Popover>;
|
|
8
10
|
|
|
@@ -12,13 +14,7 @@ const meta: Meta<typeof Popover> = {
|
|
|
12
14
|
argTypes: {
|
|
13
15
|
...excludeControls("trigger", "anchor", "children"),
|
|
14
16
|
},
|
|
15
|
-
decorators: [
|
|
16
|
-
Story => {
|
|
17
|
-
require("./Popover.story.styles.css");
|
|
18
|
-
|
|
19
|
-
return <Story />;
|
|
20
|
-
},
|
|
21
|
-
],
|
|
17
|
+
decorators: [Story => <Story />],
|
|
22
18
|
};
|
|
23
19
|
|
|
24
20
|
export const Default: StoryType = {
|
|
@@ -131,8 +131,8 @@ describe("Popover", () => {
|
|
|
131
131
|
it("calls onOpen when Popover is opened", async () => {
|
|
132
132
|
const sampleText = "Sample Text";
|
|
133
133
|
const triggerText = "Click me";
|
|
134
|
-
const onOpen =
|
|
135
|
-
const onClose =
|
|
134
|
+
const onOpen = vi.fn();
|
|
135
|
+
const onClose = vi.fn();
|
|
136
136
|
|
|
137
137
|
render(
|
|
138
138
|
<Popover
|
|
@@ -157,8 +157,8 @@ describe("Popover", () => {
|
|
|
157
157
|
it("calls onClose when Popover is closed", async () => {
|
|
158
158
|
const sampleText = "Sample Text";
|
|
159
159
|
const triggerText = "Click me";
|
|
160
|
-
const onOpen =
|
|
161
|
-
const onClose =
|
|
160
|
+
const onOpen = vi.fn();
|
|
161
|
+
const onClose = vi.fn();
|
|
162
162
|
|
|
163
163
|
render(
|
|
164
164
|
<Popover
|
|
@@ -13,7 +13,7 @@ import { cross } from "@simplybusiness/icons";
|
|
|
13
13
|
import classNames from "classnames/dedupe";
|
|
14
14
|
import type { ReactElement, ReactNode, RefAttributes } from "react";
|
|
15
15
|
import { cloneElement, useRef, useState } from "react";
|
|
16
|
-
import { useWindowEvent } from "
|
|
16
|
+
import { useWindowEvent } from "@simplybusiness/mobius-hooks";
|
|
17
17
|
import type { DOMProps } from "../../types";
|
|
18
18
|
import { Button } from "../Button";
|
|
19
19
|
import { Icon } from "../Icon";
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { Meta, StoryObj } from "@storybook/react
|
|
1
|
+
import type { Meta, StoryObj } from "@storybook/react";
|
|
2
2
|
import { excludeControls } from "../../utils";
|
|
3
3
|
import { StoryContainer } from "../../utils/StoryContainer";
|
|
4
4
|
import type { ProgressProps } from "./Progress";
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { rocketLaunch, screwdriverWrench, truck } from "@simplybusiness/icons";
|
|
2
|
-
import type { Meta, StoryObj } from "@storybook/react
|
|
2
|
+
import type { Meta, StoryObj } from "@storybook/react";
|
|
3
3
|
import { excludeControls } from "../../utils";
|
|
4
4
|
import { StoryContainer } from "../../utils/StoryContainer";
|
|
5
5
|
import { Divider } from "../Divider";
|
|
@@ -242,7 +242,7 @@ describe("Radio", () => {
|
|
|
242
242
|
});
|
|
243
243
|
|
|
244
244
|
it("should call onChange with the selected value when clicked", async () => {
|
|
245
|
-
const callback =
|
|
245
|
+
const callback = vi.fn();
|
|
246
246
|
const handleChange = (e: HTMLElementEvent<HTMLInputElement>) => {
|
|
247
247
|
callback(e.target.value);
|
|
248
248
|
};
|
|
@@ -271,7 +271,7 @@ describe("Radio", () => {
|
|
|
271
271
|
});
|
|
272
272
|
|
|
273
273
|
it("should be selectable via keyboard", async () => {
|
|
274
|
-
const callback =
|
|
274
|
+
const callback = vi.fn();
|
|
275
275
|
const redOptionText = "Red";
|
|
276
276
|
const blueOptionText = "Blue";
|
|
277
277
|
const redOptionValue = redOptionText.toLowerCase();
|
|
@@ -424,7 +424,7 @@ describe("Radio", () => {
|
|
|
424
424
|
});
|
|
425
425
|
|
|
426
426
|
it("sets classes for interaction states", async () => {
|
|
427
|
-
const callback =
|
|
427
|
+
const callback = vi.fn();
|
|
428
428
|
render(
|
|
429
429
|
<RadioGroup label="Color" onChange={callback}>
|
|
430
430
|
<Radio value="red">Red</Radio>
|
|
@@ -766,7 +766,7 @@ describe("when first child is not an Icon", () => {
|
|
|
766
766
|
|
|
767
767
|
describe("controlled vs uncontrolled RadioGroup onChange behavior", () => {
|
|
768
768
|
it("should call onChange exactly once when a radio button is clicked in controlled mode", async () => {
|
|
769
|
-
const onChange =
|
|
769
|
+
const onChange = vi.fn();
|
|
770
770
|
const redValue = "red";
|
|
771
771
|
const blueValue = "blue";
|
|
772
772
|
|
|
@@ -797,7 +797,7 @@ describe("controlled vs uncontrolled RadioGroup onChange behavior", () => {
|
|
|
797
797
|
});
|
|
798
798
|
|
|
799
799
|
it("should call onChange exactly once when a radio button is clicked in uncontrolled mode", async () => {
|
|
800
|
-
const onChange =
|
|
800
|
+
const onChange = vi.fn();
|
|
801
801
|
const redValue = "red";
|
|
802
802
|
const blueValue = "blue";
|
|
803
803
|
|
|
@@ -876,7 +876,7 @@ describe.skip("focus behavior", () => {
|
|
|
876
876
|
describe("overflow detection", () => {
|
|
877
877
|
describe("Radio onOverflow callback", () => {
|
|
878
878
|
it("should call onOverflow with vertical overflow when content height exceeds container", () => {
|
|
879
|
-
const onOverflow =
|
|
879
|
+
const onOverflow = vi.fn();
|
|
880
880
|
|
|
881
881
|
const { container, rerender } = render(
|
|
882
882
|
<Radio value="test" label="Test Label" onOverflow={onOverflow} />,
|
|
@@ -905,7 +905,7 @@ describe("overflow detection", () => {
|
|
|
905
905
|
});
|
|
906
906
|
|
|
907
907
|
it("should call onOverflow with horizontal overflow when content width exceeds container", () => {
|
|
908
|
-
const onOverflow =
|
|
908
|
+
const onOverflow = vi.fn();
|
|
909
909
|
|
|
910
910
|
const { container, rerender } = render(
|
|
911
911
|
<Radio value="test" label="Test Label" onOverflow={onOverflow} />,
|
|
@@ -939,7 +939,7 @@ describe("overflow detection", () => {
|
|
|
939
939
|
});
|
|
940
940
|
|
|
941
941
|
it("should call onOverflow with both overflow types when content exceeds in both dimensions", () => {
|
|
942
|
-
const onOverflow =
|
|
942
|
+
const onOverflow = vi.fn();
|
|
943
943
|
|
|
944
944
|
const { container, rerender } = render(
|
|
945
945
|
<Radio value="test" label="Test Label" onOverflow={onOverflow} />,
|
|
@@ -973,7 +973,7 @@ describe("overflow detection", () => {
|
|
|
973
973
|
});
|
|
974
974
|
|
|
975
975
|
it("should not call onOverflow when content fits within container and state has not changed", () => {
|
|
976
|
-
const onOverflow =
|
|
976
|
+
const onOverflow = vi.fn();
|
|
977
977
|
|
|
978
978
|
const { container, rerender } = render(
|
|
979
979
|
<Radio value="test" label="Test Label" onOverflow={onOverflow} />,
|
|
@@ -19,7 +19,7 @@ describe("Select", () => {
|
|
|
19
19
|
});
|
|
20
20
|
|
|
21
21
|
it("should call onChange when clicked", async () => {
|
|
22
|
-
const valueCallback =
|
|
22
|
+
const valueCallback = vi.fn();
|
|
23
23
|
const callback = (e: ChangeEvent<HTMLSelectElement>) =>
|
|
24
24
|
valueCallback(e.target.value);
|
|
25
25
|
const { getByLabelText } = render(
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { Meta, StoryObj } from "@storybook/react
|
|
1
|
+
import type { Meta, StoryObj } from "@storybook/react";
|
|
2
2
|
import { excludeControls } from "../../utils";
|
|
3
3
|
import { StoryContainer } from "../../utils/StoryContainer";
|
|
4
4
|
import type { SliderProps } from "./Slider";
|
|
@@ -55,8 +55,8 @@ describe("Slider", () => {
|
|
|
55
55
|
*/
|
|
56
56
|
describe("events", () => {
|
|
57
57
|
it("should call events on input change", async () => {
|
|
58
|
-
const onChange =
|
|
59
|
-
const onChangeEnd =
|
|
58
|
+
const onChange = vi.fn();
|
|
59
|
+
const onChangeEnd = vi.fn();
|
|
60
60
|
|
|
61
61
|
const { container } = render(
|
|
62
62
|
<Slider
|
|
@@ -82,8 +82,8 @@ describe("Slider", () => {
|
|
|
82
82
|
});
|
|
83
83
|
|
|
84
84
|
it("should not call onChange when value is already min", async () => {
|
|
85
|
-
const onChange =
|
|
86
|
-
const onChangeEnd =
|
|
85
|
+
const onChange = vi.fn();
|
|
86
|
+
const onChangeEnd = vi.fn();
|
|
87
87
|
|
|
88
88
|
const { container } = render(
|
|
89
89
|
<Slider
|
|
@@ -105,8 +105,8 @@ describe("Slider", () => {
|
|
|
105
105
|
});
|
|
106
106
|
|
|
107
107
|
it("should not call onChange when value is already max", async () => {
|
|
108
|
-
const onChange =
|
|
109
|
-
const onChangeEnd =
|
|
108
|
+
const onChange = vi.fn();
|
|
109
|
+
const onChangeEnd = vi.fn();
|
|
110
110
|
|
|
111
111
|
const { container } = render(
|
|
112
112
|
<Slider
|