@bigbinary/neetoui 3.2.74 → 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/index.js +1 -1
- package/package.json +1 -1
- package/tests/Dropdown.test.js +1 -1
- package/tests/EmailInput.test.js +166 -0
- package/tests/Pagination.test.js +125 -0
- package/tests/TimePicker.test.js +92 -0
package/package.json
CHANGED
package/tests/Dropdown.test.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import React from "react";
|
|
2
2
|
import { Dropdown } from "../lib/components";
|
|
3
|
-
import {
|
|
3
|
+
import { render, screen } from "@testing-library/react";
|
|
4
4
|
import userEvent from "@testing-library/user-event";
|
|
5
5
|
|
|
6
6
|
const options = ["option 1", "option 2"].map(option => <li key={option}>{option}</li>)
|
|
@@ -0,0 +1,166 @@
|
|
|
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
|
+
});
|
|
@@ -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,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
|
+
});
|