@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.
- package/index.css +1 -1
- package/index.js +1 -1
- package/layouts.js +1 -1
- package/package.json +1 -1
- package/.circleci/config.yml +0 -37
- package/.eslint-rules/imports/enforced.js +0 -20
- package/.eslint-rules/imports/order.js +0 -15
- package/.eslint-rules/overrides.js +0 -12
- package/.eslint-rules/react.js +0 -34
- package/jest-setup.js +0 -22
- package/tests/Accordion.test.js +0 -103
- package/tests/ActionDropdown.test.js +0 -61
- package/tests/Alert.test.js +0 -126
- package/tests/Button.test.js +0 -73
- package/tests/Callout.test.js +0 -20
- package/tests/Checkbox.test.js +0 -43
- package/tests/Collapse.test.js +0 -19
- package/tests/ColorPicker.test.js +0 -117
- package/tests/DatePicker.test.js +0 -111
- package/tests/Dropdown.test.js +0 -185
- package/tests/EmailInput.test.js +0 -166
- package/tests/Input.test.js +0 -75
- package/tests/Label.test.js +0 -61
- package/tests/Modal.test.js +0 -116
- package/tests/PageLoader.test.js +0 -15
- package/tests/Pagination.test.js +0 -125
- package/tests/Pane.test.js +0 -116
- package/tests/Radio.test.js +0 -83
- package/tests/Select.test.js +0 -85
- package/tests/Spinner.test.js +0 -10
- package/tests/Switch.test.js +0 -61
- package/tests/Tab.test.js +0 -60
- package/tests/Table.test.js +0 -204
- package/tests/Tag.test.js +0 -40
- package/tests/Textarea.test.js +0 -51
- package/tests/TimePicker.test.js +0 -92
- package/tests/Toastr.test.js +0 -217
- package/tests/Tooltip.test.js +0 -44
- package/tests/Typography.test.js +0 -20
package/tests/Tab.test.js
DELETED
|
@@ -1,60 +0,0 @@
|
|
|
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
|
-
});
|
package/tests/Table.test.js
DELETED
|
@@ -1,204 +0,0 @@
|
|
|
1
|
-
import React from "react";
|
|
2
|
-
import { Table } from "../lib/components";
|
|
3
|
-
import { render, screen } from "@testing-library/react";
|
|
4
|
-
import userEvent from "@testing-library/user-event";
|
|
5
|
-
|
|
6
|
-
const columnData = [
|
|
7
|
-
{
|
|
8
|
-
dataIndex: 'id',
|
|
9
|
-
key: 'id',
|
|
10
|
-
title: 'ID',
|
|
11
|
-
width: 150
|
|
12
|
-
},
|
|
13
|
-
{
|
|
14
|
-
title: "First Name",
|
|
15
|
-
dataIndex: "first_name",
|
|
16
|
-
key: "first_name",
|
|
17
|
-
width: 150,
|
|
18
|
-
},
|
|
19
|
-
{
|
|
20
|
-
title: "Last Name",
|
|
21
|
-
dataIndex: "last_name",
|
|
22
|
-
key: "last_name",
|
|
23
|
-
width: 150,
|
|
24
|
-
}
|
|
25
|
-
]
|
|
26
|
-
|
|
27
|
-
const rowData = [
|
|
28
|
-
{
|
|
29
|
-
id: 1,
|
|
30
|
-
first_name: "Oliver",
|
|
31
|
-
last_name: "Smith"
|
|
32
|
-
},
|
|
33
|
-
{
|
|
34
|
-
id: 2,
|
|
35
|
-
first_name: "Sam",
|
|
36
|
-
last_name: "Smith"
|
|
37
|
-
},
|
|
38
|
-
{
|
|
39
|
-
id: 3,
|
|
40
|
-
first_name: "Eve",
|
|
41
|
-
last_name: "Smith"
|
|
42
|
-
},
|
|
43
|
-
{
|
|
44
|
-
id: 4,
|
|
45
|
-
first_name: "Mark",
|
|
46
|
-
last_name: "Smith"
|
|
47
|
-
}
|
|
48
|
-
]
|
|
49
|
-
|
|
50
|
-
describe("Table", () => {
|
|
51
|
-
it("should render column data without error", () => {
|
|
52
|
-
render(
|
|
53
|
-
<Table
|
|
54
|
-
columnData={columnData}
|
|
55
|
-
rowData={rowData}
|
|
56
|
-
/>
|
|
57
|
-
)
|
|
58
|
-
const column = screen.getByText("ID")
|
|
59
|
-
expect(column).toBeInTheDocument();
|
|
60
|
-
});
|
|
61
|
-
|
|
62
|
-
it("should render row data without error", () => {
|
|
63
|
-
render(
|
|
64
|
-
<Table
|
|
65
|
-
columnData={columnData}
|
|
66
|
-
rowData={rowData}
|
|
67
|
-
/>
|
|
68
|
-
)
|
|
69
|
-
const row = screen.getByText("1")
|
|
70
|
-
expect(row).toBeInTheDocument();
|
|
71
|
-
});
|
|
72
|
-
|
|
73
|
-
it("should render all the rows", () => {
|
|
74
|
-
render(
|
|
75
|
-
<Table
|
|
76
|
-
columnData={columnData}
|
|
77
|
-
rowData={rowData}
|
|
78
|
-
/>
|
|
79
|
-
)
|
|
80
|
-
const row = screen.getAllByRole("row")
|
|
81
|
-
expect(row.length).toBe(4);
|
|
82
|
-
});
|
|
83
|
-
|
|
84
|
-
it("should render all the columns", () => {
|
|
85
|
-
render(
|
|
86
|
-
<Table
|
|
87
|
-
columnData={columnData}
|
|
88
|
-
rowData={rowData}
|
|
89
|
-
/>
|
|
90
|
-
)
|
|
91
|
-
const column1 = screen.getByText("ID")
|
|
92
|
-
expect(column1).toBeInTheDocument();
|
|
93
|
-
const column2 = screen.getByText("First Name")
|
|
94
|
-
expect(column2).toBeInTheDocument();
|
|
95
|
-
const column3 = screen.getByText("Last Name")
|
|
96
|
-
expect(column3).toBeInTheDocument();
|
|
97
|
-
});
|
|
98
|
-
|
|
99
|
-
it("should have checkbox to select table row if rowSelection is set to true", () => {
|
|
100
|
-
render(
|
|
101
|
-
<Table
|
|
102
|
-
columnData={columnData}
|
|
103
|
-
rowData={rowData}
|
|
104
|
-
rowSelection
|
|
105
|
-
/>
|
|
106
|
-
)
|
|
107
|
-
const checkboxes = screen.getAllByRole("checkbox")
|
|
108
|
-
expect(checkboxes.length).not.toBe(0);
|
|
109
|
-
});
|
|
110
|
-
|
|
111
|
-
it("should not have checkbox to select table row by default", () => {
|
|
112
|
-
render(
|
|
113
|
-
<Table
|
|
114
|
-
columnData={columnData}
|
|
115
|
-
rowData={rowData}
|
|
116
|
-
/>
|
|
117
|
-
)
|
|
118
|
-
const checkbox = screen.queryByRole("checkbox")
|
|
119
|
-
expect(checkbox).not.toBeInTheDocument();
|
|
120
|
-
});
|
|
121
|
-
|
|
122
|
-
it("should call onRowSelect on row selection", () => {
|
|
123
|
-
const onRowSelect = jest.fn()
|
|
124
|
-
render(
|
|
125
|
-
<Table
|
|
126
|
-
columnData={columnData}
|
|
127
|
-
rowData={rowData}
|
|
128
|
-
onRowSelect={onRowSelect}
|
|
129
|
-
rowSelection
|
|
130
|
-
/>
|
|
131
|
-
)
|
|
132
|
-
const checkbox = screen.getAllByRole("checkbox")
|
|
133
|
-
userEvent.click(checkbox[0])
|
|
134
|
-
expect(onRowSelect).toHaveBeenCalledTimes(1);
|
|
135
|
-
});
|
|
136
|
-
|
|
137
|
-
it("should call onRowClick on row click by default", () => {
|
|
138
|
-
const onRowClick = jest.fn()
|
|
139
|
-
render(
|
|
140
|
-
<Table
|
|
141
|
-
columnData={columnData}
|
|
142
|
-
rowData={rowData}
|
|
143
|
-
onRowClick={onRowClick}
|
|
144
|
-
/>
|
|
145
|
-
)
|
|
146
|
-
const row = screen.getByText("1")
|
|
147
|
-
userEvent.click(row)
|
|
148
|
-
expect(onRowClick).toHaveBeenCalledTimes(1);
|
|
149
|
-
});
|
|
150
|
-
|
|
151
|
-
it("should not call onRowClick on row click when allowRowClick is disabled", () => {
|
|
152
|
-
const onRowClick = jest.fn()
|
|
153
|
-
render(
|
|
154
|
-
<Table
|
|
155
|
-
columnData={columnData}
|
|
156
|
-
rowData={rowData}
|
|
157
|
-
onRowClick={onRowClick}
|
|
158
|
-
allowRowClick={false}
|
|
159
|
-
/>
|
|
160
|
-
)
|
|
161
|
-
const row = screen.getByText("1")
|
|
162
|
-
userEvent.click(row)
|
|
163
|
-
expect(onRowClick).toHaveBeenCalledTimes(0);
|
|
164
|
-
});
|
|
165
|
-
|
|
166
|
-
it("should render table with fixed height ", () => {
|
|
167
|
-
render(
|
|
168
|
-
<Table
|
|
169
|
-
columnData={columnData}
|
|
170
|
-
rowData={rowData}
|
|
171
|
-
fixedHeight
|
|
172
|
-
/>
|
|
173
|
-
)
|
|
174
|
-
const row = screen.getByText("1")
|
|
175
|
-
expect(row).toBeInTheDocument();
|
|
176
|
-
});
|
|
177
|
-
|
|
178
|
-
it("should render table with rows equal to page size ", () => {
|
|
179
|
-
render(
|
|
180
|
-
<Table
|
|
181
|
-
columnData={columnData}
|
|
182
|
-
rowData={rowData}
|
|
183
|
-
defaultPageSize={2}
|
|
184
|
-
/>
|
|
185
|
-
)
|
|
186
|
-
const row = screen.getAllByRole("row")
|
|
187
|
-
expect(row.length).toBe(2);
|
|
188
|
-
});
|
|
189
|
-
|
|
190
|
-
it("should call handlePageChange when page is changed ", () => {
|
|
191
|
-
const handlePageChange = jest.fn()
|
|
192
|
-
render(
|
|
193
|
-
<Table
|
|
194
|
-
columnData={columnData}
|
|
195
|
-
rowData={rowData}
|
|
196
|
-
defaultPageSize={2}
|
|
197
|
-
handlePageChange={handlePageChange}
|
|
198
|
-
/>
|
|
199
|
-
)
|
|
200
|
-
const pages = screen.getAllByRole("listitem")
|
|
201
|
-
userEvent.click(pages[2])
|
|
202
|
-
expect(handlePageChange).toBeCalledTimes(1);
|
|
203
|
-
});
|
|
204
|
-
});
|
package/tests/Tag.test.js
DELETED
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
import React from "react";
|
|
2
|
-
import { Tag } from "../lib/components";
|
|
3
|
-
import { render } from "@testing-library/react";
|
|
4
|
-
import userEvent from "@testing-library/user-event";
|
|
5
|
-
|
|
6
|
-
describe("Tag", () => {
|
|
7
|
-
it("should render without error", () => {
|
|
8
|
-
const { getByText } = render(<Tag label="Tag" />);
|
|
9
|
-
expect(getByText("Tag")).toBeInTheDocument();
|
|
10
|
-
});
|
|
11
|
-
|
|
12
|
-
it("should show icon when icon string is provided", () => {
|
|
13
|
-
const { getByTestId } = render(<Tag icon="check" />);
|
|
14
|
-
expect(getByTestId("class-icon")).toBeInTheDocument();
|
|
15
|
-
});
|
|
16
|
-
|
|
17
|
-
it("should show indicator when indicatorColor is provided", () => {
|
|
18
|
-
const { getByTestId } = render(<Tag indicatorColor="green" />);
|
|
19
|
-
expect(getByTestId("tag-indicator")).toBeInTheDocument();
|
|
20
|
-
});
|
|
21
|
-
|
|
22
|
-
it("should show close button if onClose function is provided", () => {
|
|
23
|
-
const { getByTestId } = render(<Tag onClose={() => {}} />);
|
|
24
|
-
expect(getByTestId("tag-close-button")).toBeInTheDocument();
|
|
25
|
-
});
|
|
26
|
-
|
|
27
|
-
it("should call onClose on button click", () => {
|
|
28
|
-
const onClose = jest.fn();
|
|
29
|
-
const { getByTestId } = render(<Tag onClose={onClose} />);
|
|
30
|
-
userEvent.click(getByTestId("tag-close-button"));
|
|
31
|
-
expect(onClose).toHaveBeenCalledTimes(1);
|
|
32
|
-
});
|
|
33
|
-
|
|
34
|
-
it("should not call onClose function if tag is disabled", () => {
|
|
35
|
-
const onClose = jest.fn();
|
|
36
|
-
const { getByTestId } = render(<Tag onClose={onClose} disabled />);
|
|
37
|
-
userEvent.click(getByTestId("tag-close-button"));
|
|
38
|
-
expect(onClose).toHaveBeenCalledTimes(0);
|
|
39
|
-
});
|
|
40
|
-
});
|
package/tests/Textarea.test.js
DELETED
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
import React from "react";
|
|
2
|
-
import { render } from "@testing-library/react";
|
|
3
|
-
import { Textarea } from "../lib/components";
|
|
4
|
-
import userEvent from "@testing-library/user-event";
|
|
5
|
-
|
|
6
|
-
describe("Textarea", () => {
|
|
7
|
-
it("should render without error", () => {
|
|
8
|
-
const { getByLabelText } = render(<Textarea id="text" label="Textarea" />);
|
|
9
|
-
expect(getByLabelText("Textarea")).toBeInTheDocument();
|
|
10
|
-
});
|
|
11
|
-
|
|
12
|
-
it("should update value on input when uncontrolled", () => {
|
|
13
|
-
const { getByLabelText } = render(<Textarea id="text" label="Textarea" />);
|
|
14
|
-
const textarea = getByLabelText("Textarea");
|
|
15
|
-
userEvent.type(textarea, "Test");
|
|
16
|
-
expect(textarea).toHaveValue("Test");
|
|
17
|
-
});
|
|
18
|
-
|
|
19
|
-
it("should call onChange when textarea value changes", () => {
|
|
20
|
-
const onChange = jest.fn();
|
|
21
|
-
const { getByLabelText } = render(
|
|
22
|
-
<Textarea id="text" label="Textarea" onChange={onChange} />
|
|
23
|
-
);
|
|
24
|
-
userEvent.type(getByLabelText("Textarea"), "Test");
|
|
25
|
-
expect(onChange).toHaveBeenCalledTimes(4);
|
|
26
|
-
});
|
|
27
|
-
|
|
28
|
-
it("should display helpText", () => {
|
|
29
|
-
const { getByText } = render(<Textarea id="text" label="Textarea" helpText="Help text" />);
|
|
30
|
-
expect(getByText("Help text")).toBeInTheDocument();
|
|
31
|
-
});
|
|
32
|
-
|
|
33
|
-
it("should display error message", () => {
|
|
34
|
-
const { getByText } = render(
|
|
35
|
-
<Textarea id="text" label="Textarea" error="Error message" />
|
|
36
|
-
);
|
|
37
|
-
expect(getByText("Error message")).toBeInTheDocument();
|
|
38
|
-
});
|
|
39
|
-
|
|
40
|
-
it("should properly handle maxLength", () => {
|
|
41
|
-
const { getByLabelText, getByText } = render(
|
|
42
|
-
<Textarea id="text" label="Textarea" maxLength={5} />
|
|
43
|
-
);
|
|
44
|
-
expect(getByText("0 / 5")).toBeInTheDocument();
|
|
45
|
-
expect(getByLabelText("Textarea")).toHaveAttribute("maxLength", "5");
|
|
46
|
-
|
|
47
|
-
userEvent.type(getByLabelText("Textarea"), "Testing maxLength");
|
|
48
|
-
expect(getByText("5 / 5")).toBeInTheDocument();
|
|
49
|
-
expect(getByLabelText("Textarea")).toHaveValue("Testi");
|
|
50
|
-
});
|
|
51
|
-
});
|
package/tests/TimePicker.test.js
DELETED
|
@@ -1,92 +0,0 @@
|
|
|
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
|
-
});
|
package/tests/Toastr.test.js
DELETED
|
@@ -1,217 +0,0 @@
|
|
|
1
|
-
import React from "react";
|
|
2
|
-
import { Toastr, Button } from "../lib/components";
|
|
3
|
-
import { render, screen } from "@testing-library/react";
|
|
4
|
-
import userEvent from "@testing-library/user-event";
|
|
5
|
-
import { ToastContainer } from "react-toastify";
|
|
6
|
-
|
|
7
|
-
describe("Toastr", () => {
|
|
8
|
-
it("should render Info Toastr without error", async () => {
|
|
9
|
-
render(
|
|
10
|
-
<>
|
|
11
|
-
<ToastContainer/>
|
|
12
|
-
<Button
|
|
13
|
-
label="Info Toastr"
|
|
14
|
-
onClick={() => Toastr.info("This is an info toastr.")}
|
|
15
|
-
/>
|
|
16
|
-
</>
|
|
17
|
-
);
|
|
18
|
-
const button = screen.getByText("Info Toastr");
|
|
19
|
-
userEvent.click(button);
|
|
20
|
-
const infoToastr = await screen.findByText("This is an info toastr.");
|
|
21
|
-
expect(infoToastr).toBeInTheDocument();
|
|
22
|
-
});
|
|
23
|
-
|
|
24
|
-
it("should render Warning Toastr without error", async () => {
|
|
25
|
-
render(
|
|
26
|
-
<>
|
|
27
|
-
<ToastContainer/>
|
|
28
|
-
<Button
|
|
29
|
-
label="Warning Toastr"
|
|
30
|
-
onClick={() => Toastr.warning("This is a warning toastr.")}
|
|
31
|
-
/>
|
|
32
|
-
</>
|
|
33
|
-
);
|
|
34
|
-
const button = screen.getByText("Warning Toastr");
|
|
35
|
-
userEvent.click(button);
|
|
36
|
-
const warningToastr = await screen.findByText("This is a warning toastr.");
|
|
37
|
-
expect(warningToastr).toBeInTheDocument();
|
|
38
|
-
});
|
|
39
|
-
|
|
40
|
-
it("should render Success Toastr without error", async () => {
|
|
41
|
-
render(
|
|
42
|
-
<>
|
|
43
|
-
<ToastContainer/>
|
|
44
|
-
<Button
|
|
45
|
-
label="Success Toastr"
|
|
46
|
-
onClick={() => Toastr.success("This is a success toastr.")}
|
|
47
|
-
/>
|
|
48
|
-
</>
|
|
49
|
-
);
|
|
50
|
-
const button = screen.getByText("Success Toastr");
|
|
51
|
-
userEvent.click(button);
|
|
52
|
-
const successToastr = await screen.findByText("This is a success toastr.");
|
|
53
|
-
expect(successToastr).toBeInTheDocument();
|
|
54
|
-
});
|
|
55
|
-
|
|
56
|
-
it("should render Toastr with CTA without error", async () => {
|
|
57
|
-
render(
|
|
58
|
-
<>
|
|
59
|
-
<ToastContainer/>
|
|
60
|
-
<Button
|
|
61
|
-
label="Toastr with CTA"
|
|
62
|
-
onClick={() =>
|
|
63
|
-
Toastr.error(
|
|
64
|
-
Error("Ticket marked as spam."),
|
|
65
|
-
"Block Customer",
|
|
66
|
-
() => alert("Customer blocked successfully!")
|
|
67
|
-
)
|
|
68
|
-
}
|
|
69
|
-
/>
|
|
70
|
-
</>
|
|
71
|
-
);
|
|
72
|
-
const button = screen.getByText("Toastr with CTA");
|
|
73
|
-
userEvent.click(button);
|
|
74
|
-
const toastr = await screen.findByText("Ticket marked as spam.");
|
|
75
|
-
expect(toastr).toBeInTheDocument();
|
|
76
|
-
const alertMock = jest.spyOn(window,'alert').mockImplementation();
|
|
77
|
-
const callToAction = screen.getByText("Block Customer");
|
|
78
|
-
userEvent.click(callToAction);
|
|
79
|
-
expect(alertMock).toHaveBeenCalledTimes(1);
|
|
80
|
-
});
|
|
81
|
-
|
|
82
|
-
it("should render Error Toastr without error", async () => {
|
|
83
|
-
render(
|
|
84
|
-
<>
|
|
85
|
-
<ToastContainer/>
|
|
86
|
-
<Button
|
|
87
|
-
label="Error Toastr"
|
|
88
|
-
onClick={() =>
|
|
89
|
-
Toastr.error(Error("Some error occured!"))
|
|
90
|
-
}
|
|
91
|
-
/>
|
|
92
|
-
</>
|
|
93
|
-
);
|
|
94
|
-
const button = screen.getByText("Error Toastr");
|
|
95
|
-
userEvent.click(button);
|
|
96
|
-
const errorToastr = await screen.findByText("Some error occured!");
|
|
97
|
-
expect(errorToastr).toBeInTheDocument();
|
|
98
|
-
});
|
|
99
|
-
|
|
100
|
-
it("should render a clickable message when the toastr has a link", async () => {
|
|
101
|
-
render(
|
|
102
|
-
<>
|
|
103
|
-
<ToastContainer/>
|
|
104
|
-
<Button
|
|
105
|
-
label="Info Toastr"
|
|
106
|
-
onClick={() => Toastr.info("https://github.com/bigbinary/neeto-ui")}
|
|
107
|
-
/>
|
|
108
|
-
</>
|
|
109
|
-
);
|
|
110
|
-
const button = screen.getByText("Info Toastr");
|
|
111
|
-
userEvent.click(button);
|
|
112
|
-
const link = await screen.findByRole("link");
|
|
113
|
-
expect(link).toHaveAttribute("href", "https://github.com/bigbinary/neeto-ui");
|
|
114
|
-
})
|
|
115
|
-
|
|
116
|
-
it("should render plain text error toastr", async () => {
|
|
117
|
-
render(
|
|
118
|
-
<>
|
|
119
|
-
<ToastContainer/>
|
|
120
|
-
<Button
|
|
121
|
-
label="String Error"
|
|
122
|
-
onClick={() =>
|
|
123
|
-
Toastr.error("This is a plain text error toastr!")
|
|
124
|
-
}
|
|
125
|
-
/>
|
|
126
|
-
</>
|
|
127
|
-
);
|
|
128
|
-
const button = screen.getByText("String Error");
|
|
129
|
-
userEvent.click(button);
|
|
130
|
-
const errorToastr = await screen.findByText("This is a plain text error toastr!");
|
|
131
|
-
expect(errorToastr).toBeInTheDocument();
|
|
132
|
-
});
|
|
133
|
-
|
|
134
|
-
it("should render Axios Error Toastr without error", async () => {
|
|
135
|
-
const onAxiosStringError = () => {
|
|
136
|
-
try {
|
|
137
|
-
// Dummy axios error object
|
|
138
|
-
const axiosError = {
|
|
139
|
-
isAxiosError: true,
|
|
140
|
-
config: {
|
|
141
|
-
url: "https://api.github.com/users/org",
|
|
142
|
-
},
|
|
143
|
-
response: {
|
|
144
|
-
data: {
|
|
145
|
-
error: "Not Found",
|
|
146
|
-
},
|
|
147
|
-
status: 404,
|
|
148
|
-
},
|
|
149
|
-
};
|
|
150
|
-
throw axiosError;
|
|
151
|
-
} catch (e) {
|
|
152
|
-
Toastr.error(e);
|
|
153
|
-
}
|
|
154
|
-
};
|
|
155
|
-
render(
|
|
156
|
-
<>
|
|
157
|
-
<ToastContainer/>
|
|
158
|
-
<Button label="Throw an axios error" onClick={onAxiosStringError} />
|
|
159
|
-
</>
|
|
160
|
-
);
|
|
161
|
-
const button = screen.getByText("Throw an axios error");
|
|
162
|
-
userEvent.click(button);
|
|
163
|
-
const axiosError = await screen.findByText("Not Found");
|
|
164
|
-
expect(axiosError).toBeInTheDocument();
|
|
165
|
-
});
|
|
166
|
-
|
|
167
|
-
it("should render Axios Error Toastr with array of error messages", async () => {
|
|
168
|
-
const onAxiosArrayError = () => {
|
|
169
|
-
try {
|
|
170
|
-
// Dummy axios error object
|
|
171
|
-
const axiosError = {
|
|
172
|
-
isAxiosError: true,
|
|
173
|
-
config: {
|
|
174
|
-
url: "https://api.github.com/users/org",
|
|
175
|
-
},
|
|
176
|
-
response: {
|
|
177
|
-
data: {
|
|
178
|
-
errors: ["A is required", "B is required"],
|
|
179
|
-
},
|
|
180
|
-
},
|
|
181
|
-
};
|
|
182
|
-
throw axiosError;
|
|
183
|
-
} catch (e) {
|
|
184
|
-
Toastr.error(e);
|
|
185
|
-
}
|
|
186
|
-
};
|
|
187
|
-
render(
|
|
188
|
-
<>
|
|
189
|
-
<ToastContainer/>
|
|
190
|
-
<Button
|
|
191
|
-
label="Throw an axios error with array of error messages"
|
|
192
|
-
onClick={onAxiosArrayError}
|
|
193
|
-
/>
|
|
194
|
-
</>
|
|
195
|
-
);
|
|
196
|
-
const button = screen.getByText("Throw an axios error with array of error messages");
|
|
197
|
-
userEvent.click(button);
|
|
198
|
-
const axiosError = await screen.findByText("A is required B is required");
|
|
199
|
-
expect(axiosError).toBeInTheDocument();
|
|
200
|
-
});
|
|
201
|
-
|
|
202
|
-
it("should render Error Toastr with 'Something went wrong.' when there is no message passed explicitly", async () => {
|
|
203
|
-
render(
|
|
204
|
-
<>
|
|
205
|
-
<ToastContainer/>
|
|
206
|
-
<Button
|
|
207
|
-
label="Error Toastr"
|
|
208
|
-
onClick={() => Toastr.error()}
|
|
209
|
-
/>
|
|
210
|
-
</>
|
|
211
|
-
);
|
|
212
|
-
const button = screen.getByText("Error Toastr");
|
|
213
|
-
userEvent.click(button);
|
|
214
|
-
const errorToastr = await screen.findByText("Something went wrong.");
|
|
215
|
-
expect(errorToastr).toBeInTheDocument();
|
|
216
|
-
});
|
|
217
|
-
});
|