@bigbinary/neetoui 3.2.71 → 3.2.74
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/Label.test.js +61 -0
- package/tests/Modal.test.js +116 -0
- package/tests/PageLoader.test.js +15 -0
- package/tests/Pane.test.js +116 -0
- package/tests/Radio.test.js +83 -0
- package/tests/Select.test.js +85 -0
package/package.json
CHANGED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { ActionDropdown } from "../lib/components";
|
|
3
|
+
import { render, screen } from "@testing-library/react";
|
|
4
|
+
import userEvent from "@testing-library/user-event";
|
|
5
|
+
|
|
6
|
+
describe("ActionDropdown", () => {
|
|
7
|
+
it("should render without error", () => {
|
|
8
|
+
render(
|
|
9
|
+
<ActionDropdown label="ActionDropdown">
|
|
10
|
+
<li>Option 1</li>
|
|
11
|
+
<li>Option 2</li>
|
|
12
|
+
</ActionDropdown>
|
|
13
|
+
);
|
|
14
|
+
expect(screen.getByText("ActionDropdown")).toBeInTheDocument();
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
it("should call onClick on button click", () => {
|
|
18
|
+
const onClick = jest.fn();
|
|
19
|
+
render(
|
|
20
|
+
<ActionDropdown label="ActionDropdown" onClick={onClick}>
|
|
21
|
+
<li>Option 1</li>
|
|
22
|
+
<li>Option 2</li>
|
|
23
|
+
</ActionDropdown>
|
|
24
|
+
);
|
|
25
|
+
const button = screen.getByTestId("action-dropdown-btn");
|
|
26
|
+
userEvent.click(button);
|
|
27
|
+
expect(onClick).toHaveBeenCalledTimes(1);
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
it("should not call onClick on button click when disabled", () => {
|
|
31
|
+
const onClick = jest.fn();
|
|
32
|
+
render(
|
|
33
|
+
<ActionDropdown label="ActionDropdown" disabled>
|
|
34
|
+
<li>Option 1</li>
|
|
35
|
+
<li>Option 2</li>
|
|
36
|
+
</ActionDropdown>
|
|
37
|
+
);
|
|
38
|
+
userEvent.click(screen.getByText("ActionDropdown"));
|
|
39
|
+
expect(onClick).toHaveBeenCalledTimes(0);
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
it("should show options on clicking dropdown", async () => {
|
|
43
|
+
render(
|
|
44
|
+
<ActionDropdown
|
|
45
|
+
dropdownProps={{
|
|
46
|
+
buttonProps: {
|
|
47
|
+
"data-testid": "action-dropdown-dropdown",
|
|
48
|
+
},
|
|
49
|
+
}}
|
|
50
|
+
label="ActionDropdown"
|
|
51
|
+
>
|
|
52
|
+
<li>Option 1</li>
|
|
53
|
+
<li>Option 2</li>
|
|
54
|
+
</ActionDropdown>
|
|
55
|
+
);
|
|
56
|
+
const dropdown = screen.getByTestId("action-dropdown-dropdown");
|
|
57
|
+
userEvent.click(dropdown);
|
|
58
|
+
expect(await screen.findByText("Option 1")).toBeInTheDocument();
|
|
59
|
+
expect(await screen.findByText("Option 2")).toBeInTheDocument();
|
|
60
|
+
});
|
|
61
|
+
});
|
|
@@ -0,0 +1,111 @@
|
|
|
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
|
+
});
|
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { Dropdown } from "../lib/components";
|
|
3
|
+
import { fireEvent, 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
|
+
});
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { render } from "@testing-library/react";
|
|
3
|
+
import Label from "../lib/components/Label";
|
|
4
|
+
import userEvent from "@testing-library/user-event";
|
|
5
|
+
|
|
6
|
+
describe("Label", () => {
|
|
7
|
+
it("should render without error", () => {
|
|
8
|
+
const { getByText } = render(<Label>Content</Label>);
|
|
9
|
+
expect(getByText("Content")).toBeInTheDocument();
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
it("should show * when required prop is provided", () => {
|
|
13
|
+
const { getByText } = render(
|
|
14
|
+
<Label required>
|
|
15
|
+
<p>Content</p>
|
|
16
|
+
</Label>
|
|
17
|
+
);
|
|
18
|
+
expect(getByText("Content")).toBeInTheDocument();
|
|
19
|
+
expect(getByText("*")).toBeInTheDocument();
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
it("should show info icon by default when helpIconProps is provided", () => {
|
|
23
|
+
const { getByTestId } = render(
|
|
24
|
+
<Label helpIconProps={{ "data-testid": "icon" }}>
|
|
25
|
+
<p>Content</p>
|
|
26
|
+
</Label>
|
|
27
|
+
);
|
|
28
|
+
expect(getByTestId("icon")).toBeInTheDocument();
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
it("should show tooltip when provided in helpIconProps", () => {
|
|
32
|
+
const { getByText, getByTestId } = render(
|
|
33
|
+
<Label
|
|
34
|
+
helpIconProps={{
|
|
35
|
+
tooltipProps: { content: "Tooltip" },
|
|
36
|
+
"data-testid": "icon"
|
|
37
|
+
}}
|
|
38
|
+
>
|
|
39
|
+
<p>Content</p>
|
|
40
|
+
</Label>
|
|
41
|
+
);
|
|
42
|
+
userEvent.hover(getByTestId("icon"));
|
|
43
|
+
expect(getByText("Tooltip")).toBeInTheDocument();
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
it("should trigger onClick when provided in helpIconProps", () => {
|
|
47
|
+
const onClick = jest.fn();
|
|
48
|
+
const { getByTestId } = render(
|
|
49
|
+
<Label
|
|
50
|
+
helpIconProps={{
|
|
51
|
+
onClick,
|
|
52
|
+
"data-testid": "icon"
|
|
53
|
+
}}
|
|
54
|
+
>
|
|
55
|
+
<p>Content</p>
|
|
56
|
+
</Label>
|
|
57
|
+
);
|
|
58
|
+
userEvent.click(getByTestId("icon"));
|
|
59
|
+
expect(onClick).toHaveBeenCalledTimes(1);
|
|
60
|
+
});
|
|
61
|
+
});
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { Modal, Typography, Button } from "../lib/components";
|
|
3
|
+
import { render } from "@testing-library/react";
|
|
4
|
+
import userEvent from "@testing-library/user-event";
|
|
5
|
+
|
|
6
|
+
describe("Modal", () => {
|
|
7
|
+
it("should render without error", () => {
|
|
8
|
+
const { getByText } = render(
|
|
9
|
+
<Modal isOpen>
|
|
10
|
+
<Modal.Header>
|
|
11
|
+
<Typography style="h2">Modal Header</Typography>
|
|
12
|
+
</Modal.Header>
|
|
13
|
+
</Modal>
|
|
14
|
+
);
|
|
15
|
+
expect(getByText("Modal Header")).toBeInTheDocument();
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
it("should not display content when isOpen is false", () => {
|
|
19
|
+
const { queryByText } = render(
|
|
20
|
+
<Modal>
|
|
21
|
+
<Modal.Header>
|
|
22
|
+
<Typography style="h2">Modal Header</Typography>
|
|
23
|
+
</Modal.Header>
|
|
24
|
+
</Modal>
|
|
25
|
+
);
|
|
26
|
+
expect(queryByText("Modal Header")).not.toBeInTheDocument();
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
it("should render body", () => {
|
|
30
|
+
const { getByText } = render(
|
|
31
|
+
<Modal isOpen>
|
|
32
|
+
<Modal.Body>
|
|
33
|
+
<Typography style="body2" lineHeight="normal">
|
|
34
|
+
Sample body text
|
|
35
|
+
</Typography>
|
|
36
|
+
</Modal.Body>
|
|
37
|
+
</Modal>
|
|
38
|
+
);
|
|
39
|
+
expect(getByText("Sample body text")).toBeInTheDocument();
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
it("should render footer ", () => {
|
|
43
|
+
const { getByText } = render(
|
|
44
|
+
<Modal isOpen>
|
|
45
|
+
<Modal.Footer>
|
|
46
|
+
<Button label="Submit" size="large" />
|
|
47
|
+
</Modal.Footer>
|
|
48
|
+
</Modal>
|
|
49
|
+
);
|
|
50
|
+
expect(getByText("Submit")).toBeInTheDocument();
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
it("should not show close button when closeButton is false", () => {
|
|
54
|
+
const { queryByTestId } = render(
|
|
55
|
+
<Modal isOpen closeButton={false}>
|
|
56
|
+
<Modal.Body>Sample text</Modal.Body>
|
|
57
|
+
</Modal>
|
|
58
|
+
);
|
|
59
|
+
expect(queryByTestId("close-button")).not.toBeInTheDocument();
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
it("should trigger onClose on close button is clicked", () => {
|
|
63
|
+
const onClose = jest.fn();
|
|
64
|
+
const { getByTestId } = render(
|
|
65
|
+
<Modal isOpen onClose={onClose}>
|
|
66
|
+
<Modal.Body>Sample text</Modal.Body>
|
|
67
|
+
</Modal>
|
|
68
|
+
);
|
|
69
|
+
userEvent.click(getByTestId("close-button"));
|
|
70
|
+
expect(onClose).toHaveBeenCalledTimes(1);
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
it("should close the modal when Esc key is pressed", () => {
|
|
74
|
+
const onClose = jest.fn();
|
|
75
|
+
const { container } = render(
|
|
76
|
+
<Modal isOpen onClose={onClose}>
|
|
77
|
+
<Modal.Body>Sample text</Modal.Body>
|
|
78
|
+
</Modal>
|
|
79
|
+
);
|
|
80
|
+
userEvent.type(container, "{esc}");
|
|
81
|
+
expect(onClose).toHaveBeenCalledTimes(1);
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
it("should not close the modal when Esc key is pressed when closeOnEsc is false", () => {
|
|
85
|
+
const onClose = jest.fn();
|
|
86
|
+
const { container } = render(
|
|
87
|
+
<Modal isOpen onClose={onClose} closeOnEsc={false}>
|
|
88
|
+
<Modal.Body>Sample text</Modal.Body>
|
|
89
|
+
</Modal>
|
|
90
|
+
);
|
|
91
|
+
userEvent.type(container, "{esc}");
|
|
92
|
+
expect(onClose).not.toHaveBeenCalled();
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
it("should close modal when clicking outside", () => {
|
|
96
|
+
const onClose = jest.fn();
|
|
97
|
+
const { getByTestId } = render(
|
|
98
|
+
<Modal isOpen onClose={onClose} closeOnOutsideClick>
|
|
99
|
+
<Modal.Body>Sample text</Modal.Body>
|
|
100
|
+
</Modal>
|
|
101
|
+
);
|
|
102
|
+
userEvent.click(getByTestId("backdrop"));
|
|
103
|
+
expect(onClose).toHaveBeenCalledTimes(1);
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
it("should not close modal when clicking outside when closeOnOutsideClick is false", () => {
|
|
107
|
+
const onClose = jest.fn();
|
|
108
|
+
const { getByTestId } = render(
|
|
109
|
+
<Modal isOpen onClose={onClose} closeOnOutsideClick={false}>
|
|
110
|
+
<Modal.Body>Sample text</Modal.Body>
|
|
111
|
+
</Modal>
|
|
112
|
+
);
|
|
113
|
+
userEvent.click(getByTestId("backdrop"));
|
|
114
|
+
expect(onClose).not.toHaveBeenCalled();
|
|
115
|
+
});
|
|
116
|
+
});
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { PageLoader } from "../lib/components";
|
|
3
|
+
import { render } from "@testing-library/react";
|
|
4
|
+
|
|
5
|
+
describe("PageLoader", () => {
|
|
6
|
+
it("should render without error", () => {
|
|
7
|
+
const { getByTestId } = render(<PageLoader data-testid="pageloader"/>);
|
|
8
|
+
expect(getByTestId("pageloader")).toBeInTheDocument();
|
|
9
|
+
});
|
|
10
|
+
|
|
11
|
+
it("should render text without error", () => {
|
|
12
|
+
const { getByText } = render(<PageLoader text="Loading"/>);
|
|
13
|
+
expect(getByText("Loading")).toBeInTheDocument();
|
|
14
|
+
});
|
|
15
|
+
});
|
|
@@ -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
|
+
});
|