@bigbinary/neetoui 3.2.72 → 3.2.75
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/formik.js +1 -1
- package/index.js +1 -1
- package/layouts.js +1 -1
- package/package.json +1 -1
- package/tests/ActionDropdown.test.js +61 -0
- package/tests/DatePicker.test.js +111 -0
- package/tests/Dropdown.test.js +185 -0
- package/tests/EmailInput.test.js +166 -0
- package/tests/Label.test.js +61 -0
- package/tests/Pagination.test.js +125 -0
- package/tests/Pane.test.js +116 -0
- package/tests/Radio.test.js +83 -0
- package/tests/Select.test.js +85 -0
- package/tests/TimePicker.test.js +92 -0
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { Pagination } from "../lib/components";
|
|
3
|
+
import { render } from "@testing-library/react";
|
|
4
|
+
import userEvent from "@testing-library/user-event";
|
|
5
|
+
|
|
6
|
+
const currentPage = 3
|
|
7
|
+
const count = 1000
|
|
8
|
+
const pageSize = 100
|
|
9
|
+
|
|
10
|
+
describe("Pagination", () => {
|
|
11
|
+
it("should render current page number without error", () => {
|
|
12
|
+
const { getByText } = render(
|
|
13
|
+
<Pagination
|
|
14
|
+
count={count}
|
|
15
|
+
pageNo={currentPage}
|
|
16
|
+
pageSize={pageSize}
|
|
17
|
+
/>
|
|
18
|
+
);
|
|
19
|
+
expect(getByText(currentPage)).toBeInTheDocument();
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
it("should invoke navigate callback when the left navigate button is clicked.", () => {
|
|
23
|
+
const navigate = jest.fn()
|
|
24
|
+
const { getByTestId } = render(
|
|
25
|
+
<Pagination
|
|
26
|
+
count={count}
|
|
27
|
+
pageNo={currentPage}
|
|
28
|
+
pageSize={pageSize}
|
|
29
|
+
navigate={navigate}
|
|
30
|
+
/>
|
|
31
|
+
);
|
|
32
|
+
userEvent.click(getByTestId("left-navigate-button"));
|
|
33
|
+
expect(navigate).toHaveBeenCalledTimes(1);
|
|
34
|
+
expect(navigate).toHaveBeenCalledWith(currentPage - 1);
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
it("should invoke navigate callback when the right navigate button is clicked.", () => {
|
|
38
|
+
const navigate = jest.fn()
|
|
39
|
+
const { getByTestId } = render(
|
|
40
|
+
<Pagination
|
|
41
|
+
count={count}
|
|
42
|
+
pageNo={currentPage}
|
|
43
|
+
pageSize={pageSize}
|
|
44
|
+
navigate={navigate}
|
|
45
|
+
/>
|
|
46
|
+
);
|
|
47
|
+
userEvent.click(getByTestId("right-navigate-button"));
|
|
48
|
+
expect(navigate).toHaveBeenCalledTimes(1);
|
|
49
|
+
expect(navigate).toHaveBeenCalledWith(currentPage + 1);
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
it("should invoke navigate callback when any page number is clicked.", () => {
|
|
53
|
+
const navigate = jest.fn()
|
|
54
|
+
const { getByText } = render(
|
|
55
|
+
<Pagination
|
|
56
|
+
count={count}
|
|
57
|
+
pageNo={currentPage}
|
|
58
|
+
pageSize={pageSize}
|
|
59
|
+
navigate={navigate}
|
|
60
|
+
/>
|
|
61
|
+
);
|
|
62
|
+
userEvent.click(getByText("4"));
|
|
63
|
+
expect(navigate).toHaveBeenCalledTimes(1);
|
|
64
|
+
expect(navigate).toHaveBeenCalledWith(4);
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
it("should not render anything when currentPage is 0", () => {
|
|
68
|
+
const { container } = render(
|
|
69
|
+
<Pagination
|
|
70
|
+
count={count}
|
|
71
|
+
pageNo={0}
|
|
72
|
+
pageSize={pageSize}
|
|
73
|
+
/>
|
|
74
|
+
)
|
|
75
|
+
expect(container.firstChild).toBeNull();
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
it("should render only left dots when there are more than 1 page between the extremes of left sibling and the page limit", () => {
|
|
79
|
+
const { getByTestId } = render(
|
|
80
|
+
<Pagination
|
|
81
|
+
count={count}
|
|
82
|
+
pageNo={7}
|
|
83
|
+
pageSize={pageSize}
|
|
84
|
+
/>
|
|
85
|
+
)
|
|
86
|
+
const dots = getByTestId("dots")
|
|
87
|
+
expect(dots).toBeInTheDocument()
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
it("should render only right dots when there are more than 1 page between the extremes of right sibling and the page limit", () => {
|
|
91
|
+
const { getByTestId } = render(
|
|
92
|
+
<Pagination
|
|
93
|
+
count={count}
|
|
94
|
+
pageNo={3}
|
|
95
|
+
pageSize={pageSize}
|
|
96
|
+
/>
|
|
97
|
+
)
|
|
98
|
+
const dots = getByTestId("dots")
|
|
99
|
+
expect(dots).toBeInTheDocument()
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
it("should render both left and right dots when there are more than 1 page between the extremes of both siblings and the page limit", () => {
|
|
103
|
+
const { getAllByTestId } = render(
|
|
104
|
+
<Pagination
|
|
105
|
+
count={count}
|
|
106
|
+
pageNo={5}
|
|
107
|
+
pageSize={pageSize}
|
|
108
|
+
/>
|
|
109
|
+
)
|
|
110
|
+
const dots = getAllByTestId("dots")
|
|
111
|
+
expect(dots.length).toBe(2)
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
it("should not render any dots if the number of pages is less than the page numbers we want to show ", () => {
|
|
115
|
+
const { queryByTestId } = render(
|
|
116
|
+
<Pagination
|
|
117
|
+
count={500}
|
|
118
|
+
pageNo={currentPage}
|
|
119
|
+
pageSize={pageSize}
|
|
120
|
+
/>
|
|
121
|
+
)
|
|
122
|
+
const dots = queryByTestId("dots")
|
|
123
|
+
expect(dots).toBeNull()
|
|
124
|
+
});
|
|
125
|
+
});
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { Pane, Typography, Button } from "../lib/components";
|
|
3
|
+
import { render } from "@testing-library/react";
|
|
4
|
+
import userEvent from "@testing-library/user-event";
|
|
5
|
+
|
|
6
|
+
describe("Pane", () => {
|
|
7
|
+
it("should render without error", () => {
|
|
8
|
+
const { getByText } = render(
|
|
9
|
+
<Pane isOpen>
|
|
10
|
+
<Pane.Header>
|
|
11
|
+
<Typography style="h2">Pane header</Typography>
|
|
12
|
+
</Pane.Header>
|
|
13
|
+
</Pane>
|
|
14
|
+
);
|
|
15
|
+
expect(getByText("Pane header")).toBeInTheDocument();
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
it("should not display content when isOpen is false", () => {
|
|
19
|
+
const { queryByText } = render(
|
|
20
|
+
<Pane>
|
|
21
|
+
<Pane.Header>
|
|
22
|
+
<Typography style="h2">Pane header</Typography>
|
|
23
|
+
</Pane.Header>
|
|
24
|
+
</Pane>
|
|
25
|
+
);
|
|
26
|
+
expect(queryByText("Pane header")).not.toBeInTheDocument();
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
it("should render body", () => {
|
|
30
|
+
const { getByText } = render(
|
|
31
|
+
<Pane isOpen>
|
|
32
|
+
<Pane.Body>
|
|
33
|
+
<Typography style="body2" lineHeight="normal">
|
|
34
|
+
Pane body
|
|
35
|
+
</Typography>
|
|
36
|
+
</Pane.Body>
|
|
37
|
+
</Pane>
|
|
38
|
+
);
|
|
39
|
+
expect(getByText("Pane body")).toBeInTheDocument();
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
it("should render footer", () => {
|
|
43
|
+
const { getByText } = render(
|
|
44
|
+
<Pane isOpen>
|
|
45
|
+
<Pane.Footer>
|
|
46
|
+
<Button label="Submit" />
|
|
47
|
+
</Pane.Footer>
|
|
48
|
+
</Pane>
|
|
49
|
+
);
|
|
50
|
+
expect(getByText("Submit")).toBeInTheDocument();
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
it("should not show close button when closeButton is false", () => {
|
|
54
|
+
const { queryByTestId } = render(
|
|
55
|
+
<Pane isOpen closeButton={false}>
|
|
56
|
+
<Pane.Body>Pane body</Pane.Body>
|
|
57
|
+
</Pane>
|
|
58
|
+
);
|
|
59
|
+
expect(queryByTestId("close-button")).not.toBeInTheDocument();
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
it("should trigger onClose when close button is clicked", () => {
|
|
63
|
+
const onClose = jest.fn();
|
|
64
|
+
const { getByTestId } = render(
|
|
65
|
+
<Pane isOpen onClose={onClose}>
|
|
66
|
+
<Pane.Body>Pane body</Pane.Body>
|
|
67
|
+
</Pane>
|
|
68
|
+
);
|
|
69
|
+
userEvent.click(getByTestId("close-button"));
|
|
70
|
+
expect(onClose).toHaveBeenCalledTimes(1);
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
it("should close the pane when Esc key is pressed", () => {
|
|
74
|
+
const onClose = jest.fn();
|
|
75
|
+
const { container } = render(
|
|
76
|
+
<Pane isOpen onClose={onClose}>
|
|
77
|
+
<Pane.Body>Pane body</Pane.Body>
|
|
78
|
+
</Pane>
|
|
79
|
+
);
|
|
80
|
+
userEvent.type(container, "{esc}");
|
|
81
|
+
expect(onClose).toHaveBeenCalledTimes(1);
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
it("should not close the pane when Esc key is pressed when closeOnEsc is false", () => {
|
|
85
|
+
const onClose = jest.fn();
|
|
86
|
+
const { container } = render(
|
|
87
|
+
<Pane isOpen onClose={onClose} closeOnEsc={false}>
|
|
88
|
+
<Pane.Body>Pane body</Pane.Body>
|
|
89
|
+
</Pane>
|
|
90
|
+
);
|
|
91
|
+
userEvent.type(container, "{esc}");
|
|
92
|
+
expect(onClose).not.toHaveBeenCalled();
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
it("should close pane on clicking outside", () => {
|
|
96
|
+
const onClose = jest.fn();
|
|
97
|
+
const { getByTestId } = render(
|
|
98
|
+
<Pane isOpen onClose={onClose} closeOnOutsideClick>
|
|
99
|
+
<Pane.Body>Pane body</Pane.Body>
|
|
100
|
+
</Pane>
|
|
101
|
+
);
|
|
102
|
+
userEvent.click(getByTestId("backdrop"));
|
|
103
|
+
expect(onClose).toHaveBeenCalledTimes(1);
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
it("should not close pane on clicking outside when closeOnOutsideClick is false", () => {
|
|
107
|
+
const onClose = jest.fn();
|
|
108
|
+
const { getByTestId } = render(
|
|
109
|
+
<Pane isOpen onClose={onClose} closeOnOutsideClick={false}>
|
|
110
|
+
<Pane.Body>Pane body</Pane.Body>
|
|
111
|
+
</Pane>
|
|
112
|
+
);
|
|
113
|
+
userEvent.click(getByTestId("backdrop"));
|
|
114
|
+
expect(onClose).not.toHaveBeenCalled();
|
|
115
|
+
});
|
|
116
|
+
});
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import React, { useState } from "react";
|
|
2
|
+
import { Radio } from "../lib/components";
|
|
3
|
+
import { render } from "@testing-library/react";
|
|
4
|
+
import userEvent from "@testing-library/user-event";
|
|
5
|
+
|
|
6
|
+
const ControlledRadio = () => {
|
|
7
|
+
const [value, setValue] = useState("");
|
|
8
|
+
|
|
9
|
+
return (
|
|
10
|
+
<Radio
|
|
11
|
+
label="Radio"
|
|
12
|
+
onChange={(e) => setValue(e.target.value)}
|
|
13
|
+
value={value}
|
|
14
|
+
>
|
|
15
|
+
<Radio.Item label="option1" name="options" value="option1" />
|
|
16
|
+
<Radio.Item label="option2" name="options" value="option2" />
|
|
17
|
+
</Radio>
|
|
18
|
+
);
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
describe("Radio", () => {
|
|
22
|
+
it("should render without error", () => {
|
|
23
|
+
const { getByText } = render(
|
|
24
|
+
<Radio label="Radio">
|
|
25
|
+
<Radio.Item label="option1" name="options" value="option1" />
|
|
26
|
+
</Radio>
|
|
27
|
+
);
|
|
28
|
+
expect(getByText("Radio")).toBeInTheDocument();
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
it("should call onChange when radio value is changed", () => {
|
|
32
|
+
const onChange = jest.fn((event) => {
|
|
33
|
+
expect(event.target.value).toBe("option1");
|
|
34
|
+
});
|
|
35
|
+
const { getByText } = render(
|
|
36
|
+
<Radio label="Radio" onChange={onChange}>
|
|
37
|
+
<Radio.Item label="option1" name="options" value="option1" />
|
|
38
|
+
</Radio>
|
|
39
|
+
);
|
|
40
|
+
userEvent.click(getByText("option1"));
|
|
41
|
+
expect(onChange).toHaveBeenCalledTimes(1);
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
it("should display error message", () => {
|
|
45
|
+
const { getByText } = render(
|
|
46
|
+
<Radio label="Radio" error="Error message">
|
|
47
|
+
<Radio.Item label="option1" name="options" value="option1" />
|
|
48
|
+
</Radio>
|
|
49
|
+
);
|
|
50
|
+
expect(getByText("Error message")).toBeInTheDocument();
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
it("should be unchecked by default", () => {
|
|
54
|
+
const { getByRole } = render(
|
|
55
|
+
<Radio label="Radio">
|
|
56
|
+
<Radio.Item label="option1" name="options" value="option1" />
|
|
57
|
+
</Radio>
|
|
58
|
+
);
|
|
59
|
+
expect(getByRole("radio")).not.toBeChecked();
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
it("should show controlled behaviour", () => {
|
|
63
|
+
const { getAllByRole } = render(<ControlledRadio />);
|
|
64
|
+
const radio = getAllByRole("radio");
|
|
65
|
+
userEvent.click(radio[0]);
|
|
66
|
+
expect(radio[0]).toBeChecked();
|
|
67
|
+
expect(radio[1]).not.toBeChecked();
|
|
68
|
+
userEvent.click(radio[1]);
|
|
69
|
+
expect(radio[0]).not.toBeChecked();
|
|
70
|
+
expect(radio[1]).toBeChecked();
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
it("should be checked on clicking the radio item", () => {
|
|
74
|
+
const { getByRole } = render(
|
|
75
|
+
<Radio label="Radio">
|
|
76
|
+
<Radio.Item label="option1" name="options" value="option1" />
|
|
77
|
+
</Radio>
|
|
78
|
+
);
|
|
79
|
+
const radio = getByRole("radio");
|
|
80
|
+
userEvent.click(radio);
|
|
81
|
+
expect(radio).toBeChecked();
|
|
82
|
+
});
|
|
83
|
+
});
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { Select } from "../lib/components";
|
|
3
|
+
import { render } from "@testing-library/react";
|
|
4
|
+
import userEvent from "@testing-library/user-event";
|
|
5
|
+
|
|
6
|
+
const options = [
|
|
7
|
+
{
|
|
8
|
+
label: "Option 1",
|
|
9
|
+
value: "option-1",
|
|
10
|
+
},
|
|
11
|
+
{
|
|
12
|
+
label: "Option 2",
|
|
13
|
+
value: "option-2",
|
|
14
|
+
},
|
|
15
|
+
];
|
|
16
|
+
|
|
17
|
+
describe("Select", () => {
|
|
18
|
+
it("should render without error", () => {
|
|
19
|
+
const { getByText } = render(<Select label="Select" options={options} />);
|
|
20
|
+
expect(getByText("Select")).toBeInTheDocument();
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
it("should show option list on clicking", () => {
|
|
24
|
+
const { getByRole, getByText } = render(
|
|
25
|
+
<Select label="Select" options={options} />
|
|
26
|
+
);
|
|
27
|
+
const select = getByRole("combobox");
|
|
28
|
+
userEvent.click(select);
|
|
29
|
+
expect(getByText("Option 1")).toBeInTheDocument();
|
|
30
|
+
expect(getByText("Option 2")).toBeInTheDocument();
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
it("should call onChange on select option", () => {
|
|
34
|
+
const onChange = jest.fn();
|
|
35
|
+
const { getByRole, getByText } = render(
|
|
36
|
+
<Select label="Select" options={options} onChange={onChange} />
|
|
37
|
+
);
|
|
38
|
+
const select = getByRole("combobox");
|
|
39
|
+
userEvent.click(select);
|
|
40
|
+
userEvent.click(getByText("Option 2"));
|
|
41
|
+
expect(onChange).toHaveBeenCalledTimes(1);
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
it("should change selected option value when an option is selected", async () => {
|
|
45
|
+
const { getByRole, getByText } = render(
|
|
46
|
+
<Select label="Select" options={options} />
|
|
47
|
+
);
|
|
48
|
+
const select = getByRole("combobox");
|
|
49
|
+
userEvent.click(select);
|
|
50
|
+
userEvent.click(getByText("Option 2"));
|
|
51
|
+
expect(getByText("Option 2")).toBeInTheDocument();
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
it("should not render label if label is not provided", () => {
|
|
55
|
+
const { queryByTestId } = render(<Select options={options} />);
|
|
56
|
+
expect(queryByTestId("select-label")).not.toBeInTheDocument();
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
it("should show error message if provided", () => {
|
|
60
|
+
const { getByText, getByTestId } = render(
|
|
61
|
+
<Select label="Select" options={options} error="Error message" />
|
|
62
|
+
);
|
|
63
|
+
expect(getByTestId("select-error")).toBeInTheDocument();
|
|
64
|
+
expect(getByText("Error message")).toBeInTheDocument();
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
it("should show help text if provided", () => {
|
|
68
|
+
const { getByText, getByTestId } = render(
|
|
69
|
+
<Select label="Select" options={options} helpText="Help text" />
|
|
70
|
+
);
|
|
71
|
+
expect(getByTestId("select-help-text")).toBeInTheDocument();
|
|
72
|
+
expect(getByText("Help text")).toBeInTheDocument();
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
test("creatable Select should create new element", () => {
|
|
76
|
+
const { getByRole, getByTestId } = render(<Select isCreateable />);
|
|
77
|
+
const select = getByRole("combobox");
|
|
78
|
+
const selectBox = getByTestId("select");
|
|
79
|
+
userEvent.click(select);
|
|
80
|
+
expect(selectBox).toHaveTextContent("No options", { exact: false });
|
|
81
|
+
userEvent.type(select, "hello");
|
|
82
|
+
userEvent.type(select, "{enter}");
|
|
83
|
+
expect(selectBox).toHaveTextContent("hello", { exact: false });
|
|
84
|
+
});
|
|
85
|
+
});
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import dayjs from "dayjs";
|
|
3
|
+
import { TimePicker } from "../lib/components";
|
|
4
|
+
import { screen, render, fireEvent } from "@testing-library/react";
|
|
5
|
+
import userEvent from "@testing-library/user-event";
|
|
6
|
+
|
|
7
|
+
const currentTime = dayjs();
|
|
8
|
+
const { getByRole, getByText, getAllByText, getAllByRole } = screen;
|
|
9
|
+
|
|
10
|
+
describe("TimePicker", () => {
|
|
11
|
+
it("should render without error", () => {
|
|
12
|
+
render(<TimePicker defaultValue={currentTime} />);
|
|
13
|
+
expect(getByRole("textbox")).toHaveValue(currentTime.format("HH:mm"));
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
it("should show seconds section if format contains ss", () => {
|
|
17
|
+
render(<TimePicker defaultValue={currentTime} format="HH:mm:ss" open />);
|
|
18
|
+
expect(getAllByText("00").length).toBe(3);
|
|
19
|
+
expect(getByRole("textbox")).toHaveValue(currentTime.format("HH:mm:ss"));
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
it("should show meridiem if format contains A", () => {
|
|
23
|
+
render(<TimePicker defaultValue={currentTime} format="HH:mm A" open />);
|
|
24
|
+
expect(getByRole("textbox")).toHaveValue(currentTime.format("HH:mm A"));
|
|
25
|
+
expect(getByText("AM")).toBeInTheDocument();
|
|
26
|
+
expect(getByText("PM")).toBeInTheDocument();
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
it("should show label if available", () => {
|
|
30
|
+
render(<TimePicker label="TimePicker Label" />);
|
|
31
|
+
expect(getByText("TimePicker Label")).toBeInTheDocument();
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
it("should show error if available", () => {
|
|
35
|
+
render(<TimePicker error="TimePicker Error" />);
|
|
36
|
+
expect(getByText("TimePicker Error")).toBeInTheDocument();
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
it("should trigger onChange function on clicking ok button", () => {
|
|
40
|
+
const onChange = jest.fn();
|
|
41
|
+
render(<TimePicker defaultValue={currentTime} onChange={onChange} open />);
|
|
42
|
+
fireEvent.click(getAllByText("12")[0]);
|
|
43
|
+
fireEvent.click(getByText("30"));
|
|
44
|
+
fireEvent.click(getByText("Ok"));
|
|
45
|
+
expect(onChange).toHaveBeenCalled();
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
it("should trigger onChange function on typing in textbox", () => {
|
|
49
|
+
const onChange = jest.fn();
|
|
50
|
+
render(<TimePicker onChange={onChange} open />);
|
|
51
|
+
userEvent.paste(getByRole("textbox"), "11:01");
|
|
52
|
+
fireEvent.click(getByText("Ok"));
|
|
53
|
+
expect(onChange).toHaveBeenCalledWith(
|
|
54
|
+
currentTime.hour(11).minute(1).second(0).millisecond(0),
|
|
55
|
+
"11:01"
|
|
56
|
+
);
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
it("should not break component even if onChange is not provided", () => {
|
|
60
|
+
render(<TimePicker open />);
|
|
61
|
+
userEvent.paste(getByRole("textbox"), "11:01");
|
|
62
|
+
fireEvent.click(getByText("Ok"));
|
|
63
|
+
expect(getByRole("textbox")).toHaveValue("11:01");
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
it("should be able to select time in a range", async () => {
|
|
67
|
+
const onChange = jest.fn();
|
|
68
|
+
render(<TimePicker onChange={onChange} type="range" format="HH:mm:ss" />);
|
|
69
|
+
const startTimeInput = getAllByRole("textbox")[0];
|
|
70
|
+
const endTimeInput = getAllByRole("textbox")[1];
|
|
71
|
+
userEvent.click(startTimeInput);
|
|
72
|
+
fireEvent.click(getAllByText("02")[0]);
|
|
73
|
+
fireEvent.click(getAllByText("15")[1]);
|
|
74
|
+
fireEvent.click(getAllByText("00")[2]);
|
|
75
|
+
fireEvent.click(getByText("Ok"));
|
|
76
|
+
|
|
77
|
+
userEvent.click(endTimeInput);
|
|
78
|
+
fireEvent.click(getAllByText("03")[0]);
|
|
79
|
+
fireEvent.click(getAllByText("20")[1]);
|
|
80
|
+
fireEvent.click(getAllByText("10")[2]);
|
|
81
|
+
fireEvent.click(getByText("Ok"));
|
|
82
|
+
|
|
83
|
+
expect(onChange).toHaveBeenCalledTimes(1);
|
|
84
|
+
|
|
85
|
+
expect(startTimeInput).toHaveValue(
|
|
86
|
+
currentTime.hour(2).minute(15).second(0).format("HH:mm:ss")
|
|
87
|
+
);
|
|
88
|
+
expect(endTimeInput).toHaveValue(
|
|
89
|
+
currentTime.hour(3).minute(20).second(10).format("HH:mm:ss")
|
|
90
|
+
);
|
|
91
|
+
});
|
|
92
|
+
});
|