@bigbinary/neetoui 3.2.74 → 3.2.77
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/.circleci/config.yml +8 -2
- package/formik.js +1 -1
- package/index.js +1 -1
- package/layouts.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/Switch.test.js +61 -0
- package/tests/Tab.test.js +60 -0
- package/tests/TimePicker.test.js +92 -0
- package/tests/Tooltip.test.js +44 -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,61 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { Switch } from "../lib/components";
|
|
3
|
+
import { render } from "@testing-library/react";
|
|
4
|
+
import userEvent from "@testing-library/user-event";
|
|
5
|
+
|
|
6
|
+
describe("Switch", () => {
|
|
7
|
+
it("should render without error", () => {
|
|
8
|
+
const { getByRole } = render(<Switch />);
|
|
9
|
+
const switchButton = getByRole("checkbox");
|
|
10
|
+
expect(switchButton).toBeInTheDocument();
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
it("should be unchecked by default", () => {
|
|
14
|
+
const { getByRole } = render(<Switch />);
|
|
15
|
+
const switchButton = getByRole("checkbox");
|
|
16
|
+
expect(switchButton).not.toBeChecked();
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
it("should be checked on clicking the checkbox", () => {
|
|
20
|
+
const { getByRole } = render(<Switch />);
|
|
21
|
+
const switchButton = getByRole("checkbox");
|
|
22
|
+
userEvent.click(switchButton);
|
|
23
|
+
expect(switchButton).toBeChecked();
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
it("should render label", () => {
|
|
27
|
+
const { getByText } = render(<Switch label="Switch" />);
|
|
28
|
+
const label = getByText("Switch");
|
|
29
|
+
expect(label).toBeInTheDocument();
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
it("should render asterisk when required is set to true", () => {
|
|
33
|
+
const { getByText } = render(<Switch required label="Switch" />);
|
|
34
|
+
const asterisk = getByText("*");
|
|
35
|
+
expect(asterisk).toBeInTheDocument();
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
it("should display error message", () => {
|
|
39
|
+
const { getByText } = render(<Switch error="Error message" />);
|
|
40
|
+
const errorMessage = getByText("Error message");
|
|
41
|
+
expect(errorMessage).toBeInTheDocument();
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
it("should be disabled if disabled is true", () => {
|
|
45
|
+
const { getByRole } = render(<Switch disabled />);
|
|
46
|
+
const switchButton = getByRole("checkbox");
|
|
47
|
+
expect(switchButton).toBeDisabled();
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
it("should render check icon icon when checked is true", () => {
|
|
51
|
+
const { getByTestId } = render(<Switch checked />);
|
|
52
|
+
const checkIcon = getByTestId("check-icon");
|
|
53
|
+
expect(checkIcon).toBeInTheDocument();
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
it("should render close icon icon when checked is false", () => {
|
|
57
|
+
const { getByTestId } = render(<Switch checked={false} />);
|
|
58
|
+
const closeIcon = getByTestId("close-icon");
|
|
59
|
+
expect(closeIcon).toBeInTheDocument();
|
|
60
|
+
});
|
|
61
|
+
});
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { render, screen } from "@testing-library/react";
|
|
3
|
+
import userEvent from "@testing-library/user-event";
|
|
4
|
+
import { Tab } from "../lib/components";
|
|
5
|
+
import { BrowserRouter } from "react-router-dom";
|
|
6
|
+
|
|
7
|
+
describe("Tab", () => {
|
|
8
|
+
it("should render without error", () => {
|
|
9
|
+
render(
|
|
10
|
+
<Tab>
|
|
11
|
+
<Tab.Item>Tab 1</Tab.Item>
|
|
12
|
+
<Tab.Item>Tab 2</Tab.Item>
|
|
13
|
+
</Tab>
|
|
14
|
+
);
|
|
15
|
+
expect(screen.getByText("Tab 1")).toBeInTheDocument();
|
|
16
|
+
expect(screen.getByText("Tab 2")).toBeInTheDocument();
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
it("should render a link when activeClassName is provided", () => {
|
|
20
|
+
render(<BrowserRouter>
|
|
21
|
+
<Tab>
|
|
22
|
+
<Tab.Item activeClassName="active" to="/route">Tab 1</Tab.Item>
|
|
23
|
+
<Tab.Item>Tab 2</Tab.Item>
|
|
24
|
+
</Tab>
|
|
25
|
+
</BrowserRouter>);
|
|
26
|
+
expect(screen.getByRole("link")).toBeInTheDocument();
|
|
27
|
+
expect(screen.getByRole("link")).toHaveAttribute("href", "/route");
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
it("should render icon when provided", () => {
|
|
31
|
+
render(<Tab>
|
|
32
|
+
<Tab.Item icon={() => <svg data-testid="svg-icon" />}>Tab 1</Tab.Item>
|
|
33
|
+
</Tab>);
|
|
34
|
+
expect(screen.getByTestId("svg-icon")).toBeInTheDocument();
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
it("should render icon when icon className is provided", () => {
|
|
38
|
+
render(<Tab>
|
|
39
|
+
<Tab.Item icon="icon">Tab 1</Tab.Item>
|
|
40
|
+
</Tab>);
|
|
41
|
+
expect(screen.getByTestId("tab-icon")).toBeInTheDocument();
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
it("should call onClick when clicked on Tab", () => {
|
|
45
|
+
const onClick = jest.fn();
|
|
46
|
+
render(<Tab>
|
|
47
|
+
<Tab.Item icon="icon" onClick={onClick}>Tab 1</Tab.Item>
|
|
48
|
+
</Tab>);
|
|
49
|
+
userEvent.click(screen.getByText("Tab 1"));
|
|
50
|
+
expect(onClick).toHaveBeenCalled();
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
it("should make the tab active when active prop is true", () => {
|
|
54
|
+
render(<Tab>
|
|
55
|
+
<Tab.Item active>Tab 1</Tab.Item>
|
|
56
|
+
<Tab.Item>Tab 2</Tab.Item>
|
|
57
|
+
</Tab>);
|
|
58
|
+
expect(screen.getByText("Tab 1")).toHaveClass("active");
|
|
59
|
+
});
|
|
60
|
+
});
|
|
@@ -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
|
+
});
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { Tooltip, Typography } from "../lib/components";
|
|
3
|
+
import { render, screen, waitFor } from "@testing-library/react";
|
|
4
|
+
import userEvent from "@testing-library/user-event";
|
|
5
|
+
|
|
6
|
+
describe("Tooltip", () => {
|
|
7
|
+
it("should render on hover ", () => {
|
|
8
|
+
render(
|
|
9
|
+
<Tooltip content="Tooltip">
|
|
10
|
+
<Typography>Text</Typography>
|
|
11
|
+
</Tooltip>
|
|
12
|
+
);
|
|
13
|
+
const text = screen.getByText("Text")
|
|
14
|
+
userEvent.hover(text)
|
|
15
|
+
const tooltip = screen.getByText("Tooltip")
|
|
16
|
+
expect(tooltip).toBeInTheDocument();
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
it("should not render when user stops hovering", async () => {
|
|
20
|
+
render(
|
|
21
|
+
<Tooltip content="Tooltip" >
|
|
22
|
+
<Typography>Text</Typography>
|
|
23
|
+
</Tooltip>
|
|
24
|
+
);
|
|
25
|
+
const text = screen.getByText("Text")
|
|
26
|
+
userEvent.hover(text)
|
|
27
|
+
const tooltip = screen.getByText("Tooltip")
|
|
28
|
+
userEvent.unhover(text)
|
|
29
|
+
await waitFor(() => expect(tooltip).not.toBeVisible())
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
it("should auto hide tooltip after n milliseconds", async () => {
|
|
33
|
+
render(
|
|
34
|
+
<Tooltip content="Tooltip" hideAfter={100}>
|
|
35
|
+
<Typography>Text</Typography>
|
|
36
|
+
</Tooltip>
|
|
37
|
+
);
|
|
38
|
+
|
|
39
|
+
const text = screen.getByText("Text")
|
|
40
|
+
userEvent.hover(text)
|
|
41
|
+
const tooltip = screen.getByText("Tooltip")
|
|
42
|
+
await waitFor(() => expect(tooltip).not.toBeVisible())
|
|
43
|
+
});
|
|
44
|
+
});
|