@talixo-ds/options-input 1.0.1 → 1.0.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/dist/components/min-max-value-label.d.ts +3 -2
- package/dist/components/min-max-value-label.js +2 -2
- package/dist/components/min-max-value-label.js.map +1 -1
- package/dist/components/options-input-content-item.d.ts +2 -2
- package/dist/components/options-input-content-item.js +10 -10
- package/dist/components/options-input-content-item.js.map +1 -1
- package/dist/components/options-input-dropdown-item.d.ts +4 -3
- package/dist/components/options-input-dropdown-item.js +31 -31
- package/dist/components/options-input-dropdown-item.js.map +1 -1
- package/dist/options-input.d.ts +9 -9
- package/dist/options-input.js +44 -47
- package/dist/options-input.js.map +1 -1
- package/dist/utils.d.ts +1 -0
- package/dist/utils.js +2 -0
- package/dist/utils.js.map +1 -0
- package/package.json +4 -4
- package/src/__tests__/options-input.spec.tsx +147 -0
- package/src/__tests__/utils.spec.ts +12 -0
- package/src/components/__tests__/min-max-value-label.spec.tsx +19 -19
- package/src/components/__tests__/options-input-content-item.spec.tsx +52 -60
- package/src/components/__tests__/options-input-dropdown-item.spec.tsx +74 -85
- package/src/components/min-max-value-label.tsx +10 -15
- package/src/components/options-input-content-item.tsx +47 -54
- package/src/components/options-input-dropdown-item.tsx +133 -138
- package/src/options-input.tsx +247 -251
- package/src/utils.ts +1 -0
- package/tsconfig.build.json +8 -0
- package/__tests__/__snapshots__/options-input.spec.tsx.snap +0 -119
- package/__tests__/options-input.spec.tsx +0 -242
- package/dist/components/__tests__/min-max-value-label.spec.d.ts +0 -1
- package/dist/components/__tests__/min-max-value-label.spec.js +0 -21
- package/dist/components/__tests__/min-max-value-label.spec.js.map +0 -1
- package/dist/components/__tests__/options-input-content-item.spec.d.ts +0 -1
- package/dist/components/__tests__/options-input-content-item.spec.js +0 -49
- package/dist/components/__tests__/options-input-content-item.spec.js.map +0 -1
- package/dist/components/__tests__/options-input-dropdown-item.spec.d.ts +0 -1
- package/dist/components/__tests__/options-input-dropdown-item.spec.js +0 -67
- package/dist/components/__tests__/options-input-dropdown-item.spec.js.map +0 -1
- package/src/components/__tests__/__snapshots__/min-max-value-label.spec.tsx.snap +0 -17
- package/src/components/__tests__/__snapshots__/options-input-content-item.spec.tsx.snap +0 -138
- package/src/components/__tests__/__snapshots__/options-input-dropdown-item.spec.tsx.snap +0 -134
- package/tsconfig.json +0 -8
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { capitalize } from "../utils";
|
|
2
|
+
|
|
3
|
+
test("capitalize util converts string properly", () => {
|
|
4
|
+
const example = "hello world";
|
|
5
|
+
const expected = "Hello world";
|
|
6
|
+
|
|
7
|
+
const result1 = capitalize(example);
|
|
8
|
+
expect(result1).toBe(expected);
|
|
9
|
+
|
|
10
|
+
const result2 = capitalize(expected);
|
|
11
|
+
expect(result2).toBe(expected);
|
|
12
|
+
});
|
|
@@ -1,24 +1,24 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import '@testing-library/jest-dom';
|
|
4
|
-
import { MinMaxValueLabel } from '../min-max-value-label';
|
|
1
|
+
import { render } from "@testing-library/react";
|
|
2
|
+
import { MinMaxValueLabel } from "../min-max-value-label";
|
|
5
3
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
color: 'black',
|
|
10
|
-
};
|
|
4
|
+
describe("MinMaxValueLabel", () => {
|
|
5
|
+
it("should render with min value", () => {
|
|
6
|
+
const { queryByText } = render(<MinMaxValueLabel min={0} color="black" />);
|
|
11
7
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
const renderer = ShallowRenderer.createRenderer();
|
|
8
|
+
expect(queryByText("min: 0")).toBeInTheDocument();
|
|
9
|
+
});
|
|
15
10
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
11
|
+
it("should render with max value", () => {
|
|
12
|
+
const { queryByText } = render(
|
|
13
|
+
<MinMaxValueLabel max={100} color={(theme) => theme.palette.primary.main} />
|
|
14
|
+
);
|
|
20
15
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
16
|
+
expect(queryByText("max: 100")).toBeInTheDocument();
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
it("should render with min and max value", () => {
|
|
20
|
+
const { queryByText } = render(<MinMaxValueLabel max={100} min={0} />);
|
|
21
|
+
|
|
22
|
+
expect(queryByText("min: 0, max: 100")).toBeInTheDocument();
|
|
23
|
+
});
|
|
24
24
|
});
|
|
@@ -1,63 +1,55 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
vi.mock('@mui/icons-material', async (importOriginal) => {
|
|
8
|
-
return {
|
|
9
|
-
...await importOriginal<typeof import('@mui/icons-material')>(),
|
|
10
|
-
luggage: 'div',
|
|
11
|
-
}
|
|
12
|
-
})
|
|
13
|
-
|
|
14
|
-
vi.mock('@talixo-ds/icons', async (importOriginal) => {
|
|
15
|
-
return {
|
|
16
|
-
...await importOriginal<typeof import('@talixo-ds/icons')>(),
|
|
17
|
-
football: 'div',
|
|
18
|
-
}
|
|
19
|
-
})
|
|
1
|
+
import { fireEvent, render, waitFor } from "@testing-library/react";
|
|
2
|
+
import OptionsInputContentItem, {
|
|
3
|
+
type OptionsInputContentItemProps
|
|
4
|
+
} from "../options-input-content-item";
|
|
20
5
|
|
|
21
6
|
const props = {
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
};
|
|
34
|
-
|
|
35
|
-
describe(
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
7
|
+
item: {
|
|
8
|
+
id: "luggage",
|
|
9
|
+
icon: "luggage",
|
|
10
|
+
label: "luggage",
|
|
11
|
+
details: "This is your luggage",
|
|
12
|
+
min: -10,
|
|
13
|
+
max: 10,
|
|
14
|
+
quantity: 0,
|
|
15
|
+
inputQuantity: 0
|
|
16
|
+
},
|
|
17
|
+
displayMinMax: true
|
|
18
|
+
} satisfies OptionsInputContentItemProps;
|
|
19
|
+
|
|
20
|
+
describe("OptionsInputDropdownItem", () => {
|
|
21
|
+
it("should render properly and show tooltip with proper content on hover", async () => {
|
|
22
|
+
const { queryByTestId, queryByText, getByTestId } = render(
|
|
23
|
+
<OptionsInputContentItem {...props} />
|
|
24
|
+
);
|
|
25
|
+
|
|
26
|
+
expect(queryByTestId("LuggageIcon")).toBeInTheDocument();
|
|
27
|
+
expect(queryByText("0")).toBeInTheDocument();
|
|
28
|
+
|
|
29
|
+
const icon = getByTestId("LuggageIcon");
|
|
30
|
+
|
|
31
|
+
fireEvent.mouseOver(icon);
|
|
32
|
+
|
|
33
|
+
await waitFor(() => {
|
|
34
|
+
expect(queryByText("This is your luggage")).toBeInTheDocument();
|
|
35
|
+
expect(queryByText("luggage")).toBeInTheDocument();
|
|
36
|
+
});
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
it("should not render tooltip when there is no label", async () => {
|
|
40
|
+
const { queryByTestId, queryByText, getByTestId } = render(
|
|
41
|
+
<OptionsInputContentItem item={{ ...props.item, label: undefined, quantity: 1 }} />
|
|
42
|
+
);
|
|
43
|
+
|
|
44
|
+
expect(queryByTestId("LuggageIcon")).toBeInTheDocument();
|
|
45
|
+
expect(queryByText("1")).toBeInTheDocument();
|
|
46
|
+
|
|
47
|
+
const icon = getByTestId("LuggageIcon");
|
|
48
|
+
|
|
49
|
+
fireEvent.mouseOver(icon);
|
|
50
|
+
|
|
51
|
+
await waitFor(() => {
|
|
52
|
+
expect(queryByText("This is your luggage")).not.toBeInTheDocument();
|
|
53
|
+
});
|
|
54
|
+
});
|
|
63
55
|
});
|
|
@@ -1,91 +1,80 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
import OptionsInputDropdownItem from '../options-input-dropdown-item';
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
vi.mock('@mui/icons-material', async (importOriginal) => {
|
|
9
|
-
return {
|
|
10
|
-
...await importOriginal<typeof import('@mui/icons-material')>(),
|
|
11
|
-
luggage: 'div',
|
|
12
|
-
}
|
|
13
|
-
})
|
|
14
|
-
|
|
15
|
-
vi.mock('@talixo-ds/icons', async (importOriginal) => {
|
|
16
|
-
return {
|
|
17
|
-
...await importOriginal<typeof import('@talixo-ds/icons')>(),
|
|
18
|
-
football: 'div',
|
|
19
|
-
}
|
|
20
|
-
})
|
|
1
|
+
import { render, fireEvent } from "@testing-library/react";
|
|
2
|
+
import OptionsInputDropdownItem, {
|
|
3
|
+
type OptionsInputDropdownItemProps
|
|
4
|
+
} from "../options-input-dropdown-item";
|
|
21
5
|
|
|
22
6
|
const onChangeMock = vi.fn();
|
|
23
7
|
const onBlurMock = vi.fn();
|
|
24
8
|
|
|
25
9
|
const props = {
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
10
|
+
item: {
|
|
11
|
+
id: "luggage-id",
|
|
12
|
+
icon: "luggage",
|
|
13
|
+
details: "This is your luggage. Please, keep your attention not to lose it.",
|
|
14
|
+
min: -10,
|
|
15
|
+
max: 10,
|
|
16
|
+
quantity: 0,
|
|
17
|
+
inputQuantity: 0
|
|
18
|
+
},
|
|
19
|
+
onBlur: onBlurMock,
|
|
20
|
+
onChange: onChangeMock,
|
|
21
|
+
index: 1
|
|
22
|
+
} satisfies OptionsInputDropdownItemProps;
|
|
23
|
+
|
|
24
|
+
describe("OptionsInputDropdownItem", () => {
|
|
25
|
+
afterEach(() => {
|
|
26
|
+
vi.clearAllMocks();
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
afterAll(() => {
|
|
30
|
+
vi.restoreAllMocks();
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
it("should call onChange on text field edit", () => {
|
|
34
|
+
const { getByTestId } = render(<OptionsInputDropdownItem {...props} />);
|
|
35
|
+
|
|
36
|
+
const input = getByTestId("dropdown-item-input");
|
|
37
|
+
|
|
38
|
+
fireEvent.change(input, { target: { value: "10" } });
|
|
39
|
+
|
|
40
|
+
expect(onChangeMock).toHaveBeenCalledTimes(1);
|
|
41
|
+
expect(onChangeMock).toHaveBeenCalledWith("luggage-id", "10");
|
|
42
|
+
|
|
43
|
+
fireEvent.blur(input);
|
|
44
|
+
expect(onBlurMock).toHaveBeenCalledTimes(1);
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
it("should call onChange on increment button click", () => {
|
|
48
|
+
const { getAllByRole } = render(<OptionsInputDropdownItem {...props} />);
|
|
49
|
+
|
|
50
|
+
const buttons = getAllByRole("button");
|
|
51
|
+
|
|
52
|
+
fireEvent.click(buttons[0]!);
|
|
53
|
+
|
|
54
|
+
expect(onChangeMock).toHaveBeenCalledTimes(1);
|
|
55
|
+
expect(onChangeMock).toHaveBeenCalledWith("luggage-id", 1);
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
it("should call onChange on decrement button click", () => {
|
|
59
|
+
const { getAllByRole } = render(<OptionsInputDropdownItem {...props} />);
|
|
60
|
+
|
|
61
|
+
const buttons = getAllByRole("button");
|
|
62
|
+
|
|
63
|
+
fireEvent.click(buttons[1]!);
|
|
64
|
+
|
|
65
|
+
expect(onChangeMock).toHaveBeenCalledTimes(1);
|
|
66
|
+
expect(onChangeMock).toHaveBeenCalledWith("luggage-id", -1);
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
it("should expand details content", () => {
|
|
70
|
+
const { getByTestId } = render(<OptionsInputDropdownItem {...props} />);
|
|
71
|
+
|
|
72
|
+
expect(getByTestId("option-details")).toHaveTextContent(props.item.details.slice(0, 15));
|
|
73
|
+
|
|
74
|
+
const optionDetailsContainer = getByTestId("option-details-container");
|
|
75
|
+
|
|
76
|
+
fireEvent.mouseEnter(optionDetailsContainer);
|
|
77
|
+
|
|
78
|
+
expect(getByTestId("option-details")).toHaveTextContent(props.item.details);
|
|
79
|
+
});
|
|
91
80
|
});
|
|
@@ -1,20 +1,15 @@
|
|
|
1
|
-
import
|
|
2
|
-
import Typography from '@mui/material/Typography';
|
|
1
|
+
import Typography, { type TypographyProps } from "@mui/material/Typography";
|
|
3
2
|
|
|
4
3
|
export type MinMaxValueLabelProps = {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
4
|
+
min?: number;
|
|
5
|
+
max?: number;
|
|
6
|
+
color?: TypographyProps["color"];
|
|
8
7
|
};
|
|
9
8
|
|
|
10
|
-
export const MinMaxValueLabel = ({
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
{!Number.isNaN(Number(min)) && `min: ${min}`}
|
|
17
|
-
{!Number.isNaN(Number(max)) && !Number.isNaN(Number(min)) && ', '}
|
|
18
|
-
{!Number.isNaN(Number(max)) && `max: ${max}`}
|
|
19
|
-
</Typography>
|
|
9
|
+
export const MinMaxValueLabel = ({ min, max, color }: MinMaxValueLabelProps) => (
|
|
10
|
+
<Typography variant="caption" color={color} sx={{ my: 0 }}>
|
|
11
|
+
{!Number.isNaN(Number(min)) && `min: ${min}`}
|
|
12
|
+
{!Number.isNaN(Number(max)) && !Number.isNaN(Number(min)) && ", "}
|
|
13
|
+
{!Number.isNaN(Number(max)) && `max: ${max}`}
|
|
14
|
+
</Typography>
|
|
20
15
|
);
|
|
@@ -1,64 +1,57 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
import
|
|
6
|
-
import
|
|
7
|
-
import {
|
|
8
|
-
import { OptionsInputOption } from '../types';
|
|
1
|
+
import Tooltip from "@mui/material/Tooltip";
|
|
2
|
+
import Box from "@mui/material/Box";
|
|
3
|
+
import Typography from "@mui/material/Typography";
|
|
4
|
+
import * as DesignSystemIcons from "@talixo-ds/icons/src";
|
|
5
|
+
import { MinMaxValueLabel } from "./min-max-value-label";
|
|
6
|
+
import { capitalize } from "../utils";
|
|
7
|
+
import type { OptionsInputOption } from "../types";
|
|
9
8
|
|
|
10
9
|
export type OptionsInputContentItemProps = {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
10
|
+
item: OptionsInputOption;
|
|
11
|
+
disabled?: boolean;
|
|
12
|
+
displayMinMax?: boolean;
|
|
14
13
|
};
|
|
15
14
|
|
|
16
15
|
const OptionsInputContentItem = ({
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
16
|
+
item: { quantity, details, label, max, min, icon },
|
|
17
|
+
displayMinMax = false,
|
|
18
|
+
disabled = false
|
|
20
19
|
}: OptionsInputContentItemProps) => {
|
|
21
|
-
|
|
22
|
-
|
|
20
|
+
const Icon = DesignSystemIcons[capitalize(icon) as keyof typeof DesignSystemIcons] || null;
|
|
21
|
+
const itemsColor = quantity === 0 || disabled ? "#a4a5b2" : "#000000";
|
|
23
22
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
)}
|
|
57
|
-
<Typography variant="h6" color={itemsColor}>
|
|
58
|
-
{quantity}
|
|
59
|
-
</Typography>
|
|
60
|
-
</Box>
|
|
61
|
-
);
|
|
23
|
+
return (
|
|
24
|
+
<Box display="flex" alignItems="center" gap={0.5} color={itemsColor} data-testid="option-item">
|
|
25
|
+
{label ? (
|
|
26
|
+
<Tooltip
|
|
27
|
+
title={
|
|
28
|
+
<Box display="flex" flexDirection="column">
|
|
29
|
+
<Typography variant="caption" fontWeight={600} sx={{ my: 0 }}>
|
|
30
|
+
{label}
|
|
31
|
+
</Typography>
|
|
32
|
+
{details && (
|
|
33
|
+
<Typography variant="caption" sx={{ my: 0 }}>
|
|
34
|
+
{details}
|
|
35
|
+
</Typography>
|
|
36
|
+
)}
|
|
37
|
+
{displayMinMax && <MinMaxValueLabel min={min} max={max} />}
|
|
38
|
+
</Box>
|
|
39
|
+
}
|
|
40
|
+
placement="top"
|
|
41
|
+
arrow
|
|
42
|
+
>
|
|
43
|
+
<span>
|
|
44
|
+
<Icon fontSize="medium" sx={{ color: itemsColor }} />
|
|
45
|
+
</span>
|
|
46
|
+
</Tooltip>
|
|
47
|
+
) : (
|
|
48
|
+
<Icon fontSize="medium" sx={{ color: itemsColor }} />
|
|
49
|
+
)}
|
|
50
|
+
<Typography variant="h6" color={itemsColor}>
|
|
51
|
+
{quantity}
|
|
52
|
+
</Typography>
|
|
53
|
+
</Box>
|
|
54
|
+
);
|
|
62
55
|
};
|
|
63
56
|
|
|
64
57
|
export default OptionsInputContentItem;
|