@bigbinary/neetoui 3.2.79 → 3.2.82

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.
@@ -1,117 +0,0 @@
1
- import React from "react";
2
- import { render, screen, fireEvent } from "@testing-library/react";
3
- import { ColorPicker } from "../lib/components";
4
- import userEvent from "@testing-library/user-event";
5
-
6
- describe("ColorPicker", () => {
7
- it("should render without error", () => {
8
- render(<ColorPicker color="#ffffff" />);
9
- expect(screen.getByText("#ffffff")).toBeInTheDocument();
10
- });
11
-
12
- it("should trigger onChange when color is changed", () => {
13
- const hex = "#000000";
14
- const hsl = { a: 1, h: 0, l: 0, s: 0 };
15
- const hsv = { a: 1, h: 0, v: 0, s: 0 };
16
- const rgb = { a: 1, b: 0, g: 0, r: 0 };
17
- const onChange = jest.fn((color) => {
18
- expect(color.hex).toEqual(hex);
19
- expect(color.hsl).toEqual(hsl);
20
- expect(color.hsv).toEqual(hsv);
21
- expect(color.rgb).toEqual(rgb);
22
- });
23
-
24
- render(<ColorPicker color="#ffffff" onChange={onChange} />);
25
- userEvent.click(screen.getByText("#ffffff"));
26
- userEvent.paste(screen.getByRole("textbox"), "000000");
27
- expect(onChange).toHaveBeenCalledTimes(1);
28
- });
29
-
30
- it("should display color palette when colorPaletteProps is provided", () => {
31
- render(<ColorPicker color="#ffffff" colorPaletteProps={{}} />);
32
- userEvent.click(screen.getByText("#ffffff"));
33
- expect(screen.getByTestId("color-palette")).toBeInTheDocument();
34
- });
35
-
36
- it("should trigger onChange when a color is selected from palette", () => {
37
- const selectedColor = "#ffffff";
38
- const DEFAULT_COLORS = {
39
- "red-500": "#f56a58",
40
- "yellow-500": "#f3cd82",
41
- "green-500": "#00ba88",
42
- "blue-500": "#276ef1",
43
- };
44
- const onChange = jest.fn();
45
- render(
46
- <ColorPicker
47
- color={selectedColor}
48
- colorPaletteProps={{
49
- color: {
50
- from: "red-500",
51
- to: "red-500",
52
- },
53
- colorList: Object.keys(DEFAULT_COLORS).map((key) => ({
54
- from: key,
55
- to: key,
56
- })),
57
- onChange,
58
- }}
59
- />
60
- );
61
- userEvent.click(screen.getByText("#ffffff"));
62
- const paletteItems = screen.getAllByTestId("color-palette-item");
63
- userEvent.click(paletteItems[0]);
64
- expect(onChange).toHaveBeenCalledTimes(1);
65
- expect(onChange).toHaveBeenCalledWith("red-500", "red-500");
66
- });
67
-
68
- it("should call onChange when user touches Heu slider", () => {
69
- const touchStart = [{ pageX: 0, pageY: 0 }];
70
-
71
- const hex = "#000000";
72
- const hsl = { a: 1, h: 0, l: 0, s: 0 };
73
- const hsv = { a: 1, h: 0, v: 0, s: 0 };
74
- const rgb = { a: 1, b: 0, g: 0, r: 0 };
75
- const onChange = jest.fn((color) => {
76
- expect(color.hex).toEqual(hex);
77
- expect(color.hsl).toEqual(hsl);
78
- expect(color.hsv).toEqual(hsv);
79
- expect(color.rgb).toEqual(rgb);
80
- });
81
-
82
- render(<ColorPicker color="#ffffff" onChange={onChange} />);
83
- userEvent.click(screen.getByText("#ffffff"));
84
-
85
- fireEvent.touchStart(
86
- screen.getByTestId("color-picker-hue").querySelector(".hue-horizontal"),
87
- { touches: touchStart }
88
- );
89
-
90
- expect(onChange).toHaveBeenCalledTimes(1);
91
- });
92
-
93
- it("should call onChange when user touches Saturation selector", () => {
94
- const touchStart = [{ pageX: 0, pageY: 0 }];
95
-
96
- const hex = "#000000";
97
- const hsl = { a: 1, h: 0, l: 0, s: 0 };
98
- const hsv = { a: 1, h: 0, v: 0, s: 0 };
99
- const rgb = { a: 1, b: 0, g: 0, r: 0 };
100
- const onChange = jest.fn((color) => {
101
- expect(color.hex).toEqual(hex);
102
- expect(color.hsl).toEqual(hsl);
103
- expect(color.hsv).toEqual(hsv);
104
- expect(color.rgb).toEqual(rgb);
105
- });
106
-
107
- render(<ColorPicker color="#ffffff" onChange={onChange} />);
108
- userEvent.click(screen.getByText("#ffffff"));
109
-
110
- fireEvent.touchStart(
111
- screen.getByTestId("color-picker-saturation").querySelector(".saturation-black"),
112
- { touches: touchStart }
113
- );
114
-
115
- expect(onChange).toHaveBeenCalledTimes(1);
116
- });
117
- });
@@ -1,111 +0,0 @@
1
- import React from "react";
2
- import { fireEvent, render, screen } from "@testing-library/react";
3
-
4
- import dayjs from "dayjs";
5
- import DatePicker from "../lib/components/DatePicker";
6
-
7
- const today = dayjs();
8
- const tomorrow = dayjs().add(1, "day");
9
-
10
- describe("DatePicker", () => {
11
- it("should render without error", () => {
12
- render(<DatePicker defaultValue={today} />);
13
- expect(screen.getByRole("textbox")).toHaveValue(today.format("DD/MM/YYYY"));
14
- });
15
-
16
- it("should show label if label is provided", () => {
17
- render(<DatePicker label="DatePicker Label" />);
18
- expect(screen.getByText("DatePicker Label")).toBeInTheDocument();
19
- });
20
-
21
- it("should show error if error is provided", () => {
22
- render(<DatePicker error="DatePicker Error" />);
23
- expect(screen.getByText("DatePicker Error")).toBeInTheDocument();
24
- });
25
-
26
- it("should render time if showTime is true", async () => {
27
- render(<DatePicker defaultValue={today} showTime open />);
28
- expect(await screen.findAllByText("00")).toHaveLength(3);
29
- });
30
-
31
- it("should show only hours if format is HH", async () => {
32
- render(<DatePicker defaultValue={today} timeFormat="HH" showTime open />);
33
- expect(await screen.findAllByText("00")).toHaveLength(1);
34
- });
35
-
36
- it("should show only hours and minutes if format is MM", async () => {
37
- render(
38
- <DatePicker defaultValue={today} timeFormat="HH:mm" showTime open />
39
- );
40
- expect(await screen.findAllByText("00")).toHaveLength(2);
41
- });
42
-
43
- it("should return date in the given format", async () => {
44
- render(
45
- <DatePicker
46
- defaultValue={dayjs("2022-05-24", "YYYY-MM-DD")}
47
- format="DD/MM/YYYY"
48
- />
49
- );
50
- expect(screen.getByRole("textbox")).toHaveValue("24/05/2022");
51
- });
52
-
53
- it("should return date time in the given format", async () => {
54
- render(
55
- <DatePicker
56
- defaultValue={dayjs("2022-05-24", "YYYY-MM-DD")
57
- .hour(12)
58
- .minute(30)
59
- .second(0)}
60
- format="DD/MM/YYYY HH:mm"
61
- showTime
62
- />
63
- );
64
- expect(screen.getByRole("textbox")).toHaveValue("24/05/2022 12:30");
65
- });
66
-
67
- it("should trigger onChange on selecting a date", () => {
68
- const onChange = jest.fn();
69
- render(<DatePicker defaultValue={today} onChange={onChange} open />);
70
- fireEvent.click(screen.getByText(tomorrow.get("D")));
71
- expect(onChange).toHaveBeenCalled();
72
- });
73
-
74
- it("should trigger onOk method on clicking on ok button", () => {
75
- const onOk = jest.fn();
76
- render(<DatePicker open showTime defaultValue={today} onOk={onOk} />);
77
- fireEvent.click(screen.getByText("Ok"));
78
- expect(onOk).toHaveBeenCalled();
79
- });
80
-
81
- it("should show 12 hour format if timeFormat is in 12 hr format", () => {
82
- render(
83
- <DatePicker
84
- defaultValue={dayjs("12/04/2022", "DD/MM/YYYY").hour(14).minute(30)}
85
- dateFormat="DD/MM/YYYY"
86
- showTime
87
- timeFormat="h:mm A"
88
- open
89
- />
90
- );
91
- expect(screen.getByRole("textbox")).toHaveValue("12/04/2022 2:30 PM");
92
- });
93
-
94
- it("should be able to select date in a range", () => {
95
- render(
96
- <DatePicker
97
- defaultValue={[
98
- dayjs("12/04/2022", "DD/MM/YYYY"),
99
- dayjs("14/04/2022", "DD/MM/YYYY"),
100
- ]}
101
- type="range"
102
- open
103
- />
104
- );
105
- fireEvent.click(screen.getAllByText("11")[0]);
106
- fireEvent.click(screen.getAllByText("16")[1]);
107
- const dateInputBox = screen.getAllByRole("textbox");
108
- expect(dateInputBox[0]).toHaveValue("11/04/2022");
109
- expect(dateInputBox[1]).toHaveValue("16/05/2022");
110
- });
111
- });
@@ -1,185 +0,0 @@
1
- import React from "react";
2
- import { Dropdown } from "../lib/components";
3
- import { render, screen } from "@testing-library/react";
4
- import userEvent from "@testing-library/user-event";
5
-
6
- const options = ["option 1", "option 2"].map(option => <li key={option}>{option}</li>)
7
-
8
- describe("Dropdown", () => {
9
- it("should render without error", () => {
10
- const { getByText } = render(
11
- <Dropdown
12
- label="Dropdown"
13
- />)
14
- expect(getByText("Dropdown")).toBeInTheDocument();
15
- });
16
-
17
- it("should show icon when icon component is provided", () => {
18
- const { getByTestId } = render(
19
- <Dropdown icon={() => <svg data-testid="svg-icon" />} />
20
- );
21
- expect(getByTestId("svg-icon")).toBeInTheDocument();
22
- });
23
-
24
- it("should render all the options when clicking dropdown without error", async () => {
25
- const { getByText } = render(
26
- <Dropdown label="Dropdown" >
27
- {options}
28
- </Dropdown>
29
- )
30
- userEvent.click(getByText("Dropdown"))
31
- const listItems = await screen.findAllByText(/option/i)
32
- expect(listItems.length).toBe(2);
33
- });
34
-
35
- it("should render all the options if isOpen is true", async () => {
36
- const { findAllByText } = render(
37
- <Dropdown label="Dropdown" isOpen>
38
- {options}
39
- </Dropdown>
40
- )
41
- const listItems = await findAllByText(/option/i)
42
- expect(listItems.length).toBe(2);
43
- });
44
-
45
- it("should be disabled if disabled is true", () => {
46
- const { getByRole } = render(
47
- <Dropdown label="Dropdown" disabled />
48
- );
49
- expect(getByRole("button")).toBeDisabled();
50
- });
51
-
52
- it("should close the dropdown on select if closeOnSelect is true", () => {
53
- const { getByText } = render(
54
- <Dropdown label="Dropdown" closeOnSelect >
55
- {options}
56
- </Dropdown>
57
- )
58
- userEvent.click(getByText("Dropdown"))
59
- const listItem = getByText("option 1")
60
- userEvent.click(listItem)
61
- expect(screen.queryAllByRole("listitem")).toHaveLength(0);
62
- });
63
-
64
- it("should not close the dropdown on select if closeOnSelect is false", async () => {
65
- const { getByText } = render(
66
- <Dropdown label="Dropdown" closeOnSelect={false} >
67
- {options}
68
- </Dropdown>
69
- )
70
- userEvent.click(getByText("Dropdown"))
71
- const listItem = getByText("option 1")
72
- userEvent.click(listItem)
73
- const listItems = await screen.findAllByRole("listitem")
74
- expect(listItems).toHaveLength(2);
75
- });
76
-
77
- it("should close the dropdown when Esc key is pressed if closeOnEsc is true", () => {
78
- const { getByText } = render(
79
- <Dropdown label="Dropdown" closeOnEsc >
80
- {options}
81
- </Dropdown>
82
- )
83
- userEvent.click(getByText("Dropdown"))
84
- userEvent.keyboard("{esc}");
85
- expect(screen.queryAllByRole("listitem")).toHaveLength(0);
86
- });
87
-
88
- it("should not close the dropdown when Esc key is pressed if closeOnEsc is false", async () => {
89
- const { getByText } = render(
90
- <Dropdown label="Dropdown" closeOnEsc={false} >
91
- {options}
92
- </Dropdown>
93
- )
94
- userEvent.click(getByText("Dropdown"))
95
- userEvent.keyboard("{esc}");
96
- const listItems = await screen.findAllByRole("listitem")
97
- expect(listItems).toHaveLength(2);
98
- });
99
-
100
- it("should close dropdown on clicking outside if closeOnOutsideClick is true", () => {
101
- const { getByText } = render(
102
- <Dropdown label="Dropdown" closeOnOutsideClick >
103
- {options}
104
- </Dropdown>
105
- )
106
- userEvent.click(getByText("Dropdown"))
107
- userEvent.click(document.body);
108
- expect(screen.queryAllByRole("listitem")).toHaveLength(0);
109
- });
110
-
111
- it("should not close on clicking outside if closeOnOutsideClick is false", async () => {
112
- const { getByText } = render(
113
- <Dropdown label="Dropdown" closeOnOutsideClick={false} >
114
- {options}
115
- </Dropdown>
116
- )
117
- userEvent.click(getByText("Dropdown"))
118
- userEvent.click(document.body);
119
- const listItems = await screen.findAllByRole("listitem")
120
- expect(listItems).toHaveLength(2);
121
- });
122
-
123
- it("should open another dropdown on click trigger when it is multilevel ", async () => {
124
- const { getByText } = render(
125
- <Dropdown label="Dropdown" isMultiLevel isOpen>
126
- {options}
127
- <Dropdown
128
- customTarget={<li>Another Dropdown</li>}
129
- >
130
- {options}
131
- </Dropdown>
132
- </Dropdown>
133
- )
134
- userEvent.click(getByText("Another Dropdown"))
135
- const listItems = await screen.findAllByRole("listitem")
136
- expect(listItems).toHaveLength(5);
137
- });
138
-
139
- it("should open another dropdown on hover trigger when it is multilevel ", async () => {
140
- const { getByText } = render(
141
- <Dropdown label="Dropdown" isMultiLevel isOpen>
142
- {options}
143
- <Dropdown
144
- customTarget={<li>Another Dropdown</li>}
145
- trigger="hover"
146
- >
147
- {options}
148
- </Dropdown>
149
- </Dropdown>
150
- )
151
- userEvent.hover(getByText("Another Dropdown"))
152
- const listItems = await screen.findAllByRole("listitem")
153
- expect(listItems).toHaveLength(5);
154
- });
155
-
156
- it("should close the multilevel dropdown when mouse leaves", async () => {
157
- const { getByText } = render(
158
- <Dropdown label="Dropdown" isMultiLevel isOpen>
159
- {options}
160
- <Dropdown
161
- customTarget={<li>Another Dropdown</li>}
162
- trigger="hover"
163
- isOpen
164
- >
165
- {options}
166
- </Dropdown>
167
- </Dropdown>
168
- )
169
- userEvent.unhover(getByText("Another Dropdown"))
170
- const listItems = await screen.findAllByRole("listitem")
171
- expect(listItems).toHaveLength(3);
172
- });
173
-
174
- it("should call onClose when Dropdown is closed", () => {
175
- const onClose = jest.fn();
176
- const { getByText } = render(
177
- <Dropdown label="Dropdown" closeOnOutsideClick onClose={onClose}>
178
- {options}
179
- </Dropdown>
180
- )
181
- userEvent.click(getByText("Dropdown"))
182
- userEvent.click(document.body);
183
- expect(onClose).toHaveBeenCalledTimes(1);
184
- });
185
- });
@@ -1,166 +0,0 @@
1
- import React from "react";
2
- import { EmailInput } from "../lib/components";
3
- import { render, screen } from "@testing-library/react";
4
- import userEvent from "@testing-library/user-event";
5
-
6
- describe("EmailInput", () => {
7
- it("should render without error", () => {
8
- render(<EmailInput />);
9
- expect(screen.getByText("Email(s)")).toBeInTheDocument();
10
- });
11
-
12
- it("should display helpText", () => {
13
- render(<EmailInput helpText="Help text" />);
14
- expect(screen.getByText("Help text")).toBeInTheDocument();
15
- });
16
-
17
- it("should display error message", () => {
18
- render(<EmailInput error="Error message" />);
19
- expect(screen.getByText("Error message")).toBeInTheDocument();
20
- });
21
-
22
- it("should render correct number of emails", () => {
23
- render(
24
- <EmailInput
25
- value={[
26
- { label: "test@example.com", value: "test@example.com", valid: true },
27
- ]}
28
- counter={{ label: "email" }}
29
- />
30
- );
31
- expect(screen.getByText("1 email")).toBeInTheDocument();
32
- });
33
-
34
- it("should render default counter text when no label is provided", () => {
35
- const { rerender } = render(
36
- <EmailInput
37
- value={[
38
- { label: "test@example.com", value: "test@example.com", valid: true },
39
- ]}
40
- counter={{}}
41
- />
42
- );
43
- expect(screen.getByText("1 email")).toBeInTheDocument();
44
- rerender(<EmailInput
45
- value={[
46
- { label: "test@example.com", value: "test@example.com", valid: true },
47
- { label: "test2@example.com", value: "test2@example.com", valid: true },
48
- ]}
49
- counter={{}}
50
- />);
51
- expect(screen.getByText("2 emails")).toBeInTheDocument();
52
- });
53
-
54
- it("should call onBlur when focus from the input field changes", () => {
55
- const onBlur = jest.fn();
56
- render(<EmailInput onBlur={onBlur} />);
57
- const emailInput = screen.getByRole("combobox");
58
- userEvent.click(emailInput);
59
- userEvent.click(document.body);
60
- expect(onBlur).toHaveBeenCalledTimes(1);
61
- });
62
-
63
- it("should call onChange when input loses focus after entering email", () => {
64
- const onChange = jest.fn();
65
- render(<EmailInput onChange={onChange} />);
66
- const emailInput = screen.getByRole("combobox");
67
- userEvent.paste(emailInput, "test@email.com test2@email.com");
68
- userEvent.click(document.body);
69
- expect(onChange).toHaveBeenCalledTimes(1);
70
- expect(onChange).toHaveBeenCalledWith([
71
- { label: "test@email.com", valid: true, value: "test@email.com" },
72
- { label: "test2@email.com", valid: true, value: "test2@email.com" },
73
- ]);
74
- });
75
-
76
- it("should call onInputChange when email input value changes", () => {
77
- const onInputChange = jest.fn();
78
- render(<EmailInput onInputChange={onInputChange} />);
79
- const emailInput = screen.getByRole("combobox");
80
- userEvent.type(emailInput, "test");
81
- expect(onInputChange).toHaveBeenCalledTimes(4);
82
- });
83
-
84
- it("should call onChange when Enter key is pressed", () => {
85
- const onChange = jest.fn();
86
- render(<EmailInput onChange={onChange} />);
87
- const emailInput = screen.getByRole("combobox");
88
- userEvent.type(emailInput, "email@domain.com{enter}");
89
- expect(onChange).toHaveBeenCalledTimes(1);
90
- expect(onChange).toHaveBeenCalledWith([
91
- { label: "email@domain.com", valid: true, value: "email@domain.com" },
92
- ]);
93
- });
94
-
95
- it("should call onChange when Space key is pressed", () => {
96
- const onChange = jest.fn();
97
- render(<EmailInput onChange={onChange} />);
98
- const emailInput = screen.getByRole("combobox");
99
- userEvent.type(emailInput, "email@domain.com{space}");
100
- expect(onChange).toHaveBeenCalledTimes(1);
101
- expect(onChange).toHaveBeenCalledWith([
102
- { label: "email@domain.com", valid: true, value: "email@domain.com" },
103
- ]);
104
- });
105
-
106
- it("should call onChange when Tab key is pressed", () => {
107
- const onChange = jest.fn();
108
- render(<EmailInput onChange={onChange} />);
109
- const emailInput = screen.getByRole("combobox");
110
- userEvent.type(emailInput, "email@domain.com");
111
- userEvent.tab();
112
- expect(onChange).toHaveBeenCalledTimes(1);
113
- expect(onChange).toHaveBeenCalledWith([
114
- { label: "email@domain.com", valid: true, value: "email@domain.com" },
115
- ]);
116
- });
117
-
118
- it("should call onChange when comma key is pressed", () => {
119
- const onChange = jest.fn();
120
- render(<EmailInput onChange={onChange} />);
121
- const emailInput = screen.getByRole("combobox");
122
- userEvent.type(emailInput, "email@domain.com,");
123
- expect(onChange).toHaveBeenCalledTimes(1);
124
- expect(onChange).toHaveBeenCalledWith([
125
- { label: "email@domain.com", valid: true, value: "email@domain.com" },
126
- ]);
127
- });
128
-
129
- it("should remove all invalid emails on clicking filterInvalidEmails label", () => {
130
- const onChange = jest.fn();
131
- render(
132
- <EmailInput
133
- onChange={onChange}
134
- value={[
135
- { label: "test@example.com", value: "test@example.com", valid: true },
136
- { label: "invalidEmail", value: "invalidEmail" },
137
- ]}
138
- filterInvalidEmails={{
139
- label: "Filter invalid emails",
140
- }}
141
- error="Invalid email"
142
- />
143
- );
144
- userEvent.click(screen.getByText("Filter invalid emails"));
145
- expect(onChange).toHaveBeenCalledTimes(1);
146
- expect(onChange).toHaveBeenCalledWith([
147
- { label: "test@example.com", value: "test@example.com", valid: true },
148
- ]);
149
- });
150
-
151
- it("should display filterInvalidEmails label if no label is provided", () => {
152
- const onChange = jest.fn();
153
- render(
154
- <EmailInput
155
- onChange={onChange}
156
- value={[
157
- { label: "test@example.com", value: "test@example.com", valid: true },
158
- { label: "invalidEmail", value: "invalidEmail" },
159
- ]}
160
- filterInvalidEmails={{}}
161
- error="Invalid email"
162
- />
163
- );
164
- expect(screen.getByText("Click here to remove invalid emails.")).toBeInTheDocument();
165
- });
166
- });
@@ -1,75 +0,0 @@
1
- import React from "react";
2
- import { render } from "@testing-library/react";
3
- import { Input } from "../lib/components";
4
- import userEvent from "@testing-library/user-event";
5
-
6
- describe("Input", () => {
7
- it("should render without error", () => {
8
- const { getByLabelText } = render(<Input id="input" label="Input Label" />);
9
- expect(getByLabelText("Input Label")).toBeInTheDocument();
10
- });
11
-
12
- it("should be able to type when uncontrolled", () => {
13
- const { getByLabelText } = render(<Input id="input" label="Input Label" />);
14
- const inputField = getByLabelText("Input Label");
15
- userEvent.type(inputField, "sample content");
16
- expect(inputField).toHaveValue("sample content");
17
- });
18
-
19
- it("should call onChange when textarea value changes", () => {
20
- const onChange = jest.fn();
21
- const { getByLabelText } = render(
22
- <Input id="input" label="Input Label" onChange={onChange} />
23
- );
24
- userEvent.type(getByLabelText("Input Label"), "Test");
25
- expect(onChange).toHaveBeenCalledTimes(4);
26
- });
27
-
28
- it("should display error message", () => {
29
- const { getByText } = render(
30
- <Input label="input" error={"Error message"} />
31
- );
32
- expect(getByText("Error message")).toBeInTheDocument();
33
- });
34
-
35
- it("should display helpText", () => {
36
- const { getByText } = render(<Input label="Input" helpText="Help text" />);
37
- expect(getByText("Help text")).toBeInTheDocument();
38
- });
39
-
40
- it("should be disabled if disabled is true", () => {
41
- const { getByLabelText } = render(
42
- <Input disabled id="input" label="Input Label" />
43
- );
44
- expect(getByLabelText("Input Label")).toBeDisabled();
45
- });
46
-
47
- it("should show suffix", () => {
48
- const { getByText } = render(<Input label="input" suffix="suffix" />);
49
- expect(getByText("suffix")).toBeInTheDocument();
50
- });
51
-
52
- it("should show prefix", () => {
53
- const { getByText } = render(<Input label="input" prefix="prefix" />);
54
- expect(getByText("prefix")).toBeInTheDocument();
55
- });
56
-
57
- it("should render asterisk when required is set to true", () => {
58
- const { getByText } = render(<Input required label="Input" />);
59
- const asterisk = getByText("*");
60
- expect(asterisk).toBeInTheDocument();
61
- });
62
-
63
- it("should properly handle maxLength", () => {
64
- const { getByLabelText, getByText } = render(
65
- <Input id="input" label="Input label" maxLength={5} />
66
- );
67
-
68
- expect(getByText("0 / 5")).toBeInTheDocument();
69
- expect(getByLabelText("Input label")).toHaveAttribute("maxLength", "5");
70
-
71
- userEvent.type(getByLabelText("Input label"), "Testing maxLength");
72
- expect(getByText("5 / 5")).toBeInTheDocument();
73
- expect(getByLabelText("Input label")).toHaveValue("Testi");
74
- });
75
- });