@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/Label.test.js
DELETED
|
@@ -1,61 +0,0 @@
|
|
|
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
|
-
});
|
package/tests/Modal.test.js
DELETED
|
@@ -1,116 +0,0 @@
|
|
|
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
|
-
});
|
package/tests/PageLoader.test.js
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
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
|
-
});
|
package/tests/Pagination.test.js
DELETED
|
@@ -1,125 +0,0 @@
|
|
|
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
|
-
});
|
package/tests/Pane.test.js
DELETED
|
@@ -1,116 +0,0 @@
|
|
|
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
|
-
});
|
package/tests/Radio.test.js
DELETED
|
@@ -1,83 +0,0 @@
|
|
|
1
|
-
import React, { useState } from "react";
|
|
2
|
-
import { Radio } from "../lib/components";
|
|
3
|
-
import { render } from "@testing-library/react";
|
|
4
|
-
import userEvent from "@testing-library/user-event";
|
|
5
|
-
|
|
6
|
-
const ControlledRadio = () => {
|
|
7
|
-
const [value, setValue] = useState("");
|
|
8
|
-
|
|
9
|
-
return (
|
|
10
|
-
<Radio
|
|
11
|
-
label="Radio"
|
|
12
|
-
onChange={(e) => setValue(e.target.value)}
|
|
13
|
-
value={value}
|
|
14
|
-
>
|
|
15
|
-
<Radio.Item label="option1" name="options" value="option1" />
|
|
16
|
-
<Radio.Item label="option2" name="options" value="option2" />
|
|
17
|
-
</Radio>
|
|
18
|
-
);
|
|
19
|
-
};
|
|
20
|
-
|
|
21
|
-
describe("Radio", () => {
|
|
22
|
-
it("should render without error", () => {
|
|
23
|
-
const { getByText } = render(
|
|
24
|
-
<Radio label="Radio">
|
|
25
|
-
<Radio.Item label="option1" name="options" value="option1" />
|
|
26
|
-
</Radio>
|
|
27
|
-
);
|
|
28
|
-
expect(getByText("Radio")).toBeInTheDocument();
|
|
29
|
-
});
|
|
30
|
-
|
|
31
|
-
it("should call onChange when radio value is changed", () => {
|
|
32
|
-
const onChange = jest.fn((event) => {
|
|
33
|
-
expect(event.target.value).toBe("option1");
|
|
34
|
-
});
|
|
35
|
-
const { getByText } = render(
|
|
36
|
-
<Radio label="Radio" onChange={onChange}>
|
|
37
|
-
<Radio.Item label="option1" name="options" value="option1" />
|
|
38
|
-
</Radio>
|
|
39
|
-
);
|
|
40
|
-
userEvent.click(getByText("option1"));
|
|
41
|
-
expect(onChange).toHaveBeenCalledTimes(1);
|
|
42
|
-
});
|
|
43
|
-
|
|
44
|
-
it("should display error message", () => {
|
|
45
|
-
const { getByText } = render(
|
|
46
|
-
<Radio label="Radio" error="Error message">
|
|
47
|
-
<Radio.Item label="option1" name="options" value="option1" />
|
|
48
|
-
</Radio>
|
|
49
|
-
);
|
|
50
|
-
expect(getByText("Error message")).toBeInTheDocument();
|
|
51
|
-
});
|
|
52
|
-
|
|
53
|
-
it("should be unchecked by default", () => {
|
|
54
|
-
const { getByRole } = render(
|
|
55
|
-
<Radio label="Radio">
|
|
56
|
-
<Radio.Item label="option1" name="options" value="option1" />
|
|
57
|
-
</Radio>
|
|
58
|
-
);
|
|
59
|
-
expect(getByRole("radio")).not.toBeChecked();
|
|
60
|
-
});
|
|
61
|
-
|
|
62
|
-
it("should show controlled behaviour", () => {
|
|
63
|
-
const { getAllByRole } = render(<ControlledRadio />);
|
|
64
|
-
const radio = getAllByRole("radio");
|
|
65
|
-
userEvent.click(radio[0]);
|
|
66
|
-
expect(radio[0]).toBeChecked();
|
|
67
|
-
expect(radio[1]).not.toBeChecked();
|
|
68
|
-
userEvent.click(radio[1]);
|
|
69
|
-
expect(radio[0]).not.toBeChecked();
|
|
70
|
-
expect(radio[1]).toBeChecked();
|
|
71
|
-
});
|
|
72
|
-
|
|
73
|
-
it("should be checked on clicking the radio item", () => {
|
|
74
|
-
const { getByRole } = render(
|
|
75
|
-
<Radio label="Radio">
|
|
76
|
-
<Radio.Item label="option1" name="options" value="option1" />
|
|
77
|
-
</Radio>
|
|
78
|
-
);
|
|
79
|
-
const radio = getByRole("radio");
|
|
80
|
-
userEvent.click(radio);
|
|
81
|
-
expect(radio).toBeChecked();
|
|
82
|
-
});
|
|
83
|
-
});
|
package/tests/Select.test.js
DELETED
|
@@ -1,85 +0,0 @@
|
|
|
1
|
-
import React from "react";
|
|
2
|
-
import { Select } from "../lib/components";
|
|
3
|
-
import { render } from "@testing-library/react";
|
|
4
|
-
import userEvent from "@testing-library/user-event";
|
|
5
|
-
|
|
6
|
-
const options = [
|
|
7
|
-
{
|
|
8
|
-
label: "Option 1",
|
|
9
|
-
value: "option-1",
|
|
10
|
-
},
|
|
11
|
-
{
|
|
12
|
-
label: "Option 2",
|
|
13
|
-
value: "option-2",
|
|
14
|
-
},
|
|
15
|
-
];
|
|
16
|
-
|
|
17
|
-
describe("Select", () => {
|
|
18
|
-
it("should render without error", () => {
|
|
19
|
-
const { getByText } = render(<Select label="Select" options={options} />);
|
|
20
|
-
expect(getByText("Select")).toBeInTheDocument();
|
|
21
|
-
});
|
|
22
|
-
|
|
23
|
-
it("should show option list on clicking", () => {
|
|
24
|
-
const { getByRole, getByText } = render(
|
|
25
|
-
<Select label="Select" options={options} />
|
|
26
|
-
);
|
|
27
|
-
const select = getByRole("combobox");
|
|
28
|
-
userEvent.click(select);
|
|
29
|
-
expect(getByText("Option 1")).toBeInTheDocument();
|
|
30
|
-
expect(getByText("Option 2")).toBeInTheDocument();
|
|
31
|
-
});
|
|
32
|
-
|
|
33
|
-
it("should call onChange on select option", () => {
|
|
34
|
-
const onChange = jest.fn();
|
|
35
|
-
const { getByRole, getByText } = render(
|
|
36
|
-
<Select label="Select" options={options} onChange={onChange} />
|
|
37
|
-
);
|
|
38
|
-
const select = getByRole("combobox");
|
|
39
|
-
userEvent.click(select);
|
|
40
|
-
userEvent.click(getByText("Option 2"));
|
|
41
|
-
expect(onChange).toHaveBeenCalledTimes(1);
|
|
42
|
-
});
|
|
43
|
-
|
|
44
|
-
it("should change selected option value when an option is selected", async () => {
|
|
45
|
-
const { getByRole, getByText } = render(
|
|
46
|
-
<Select label="Select" options={options} />
|
|
47
|
-
);
|
|
48
|
-
const select = getByRole("combobox");
|
|
49
|
-
userEvent.click(select);
|
|
50
|
-
userEvent.click(getByText("Option 2"));
|
|
51
|
-
expect(getByText("Option 2")).toBeInTheDocument();
|
|
52
|
-
});
|
|
53
|
-
|
|
54
|
-
it("should not render label if label is not provided", () => {
|
|
55
|
-
const { queryByTestId } = render(<Select options={options} />);
|
|
56
|
-
expect(queryByTestId("select-label")).not.toBeInTheDocument();
|
|
57
|
-
});
|
|
58
|
-
|
|
59
|
-
it("should show error message if provided", () => {
|
|
60
|
-
const { getByText, getByTestId } = render(
|
|
61
|
-
<Select label="Select" options={options} error="Error message" />
|
|
62
|
-
);
|
|
63
|
-
expect(getByTestId("select-error")).toBeInTheDocument();
|
|
64
|
-
expect(getByText("Error message")).toBeInTheDocument();
|
|
65
|
-
});
|
|
66
|
-
|
|
67
|
-
it("should show help text if provided", () => {
|
|
68
|
-
const { getByText, getByTestId } = render(
|
|
69
|
-
<Select label="Select" options={options} helpText="Help text" />
|
|
70
|
-
);
|
|
71
|
-
expect(getByTestId("select-help-text")).toBeInTheDocument();
|
|
72
|
-
expect(getByText("Help text")).toBeInTheDocument();
|
|
73
|
-
});
|
|
74
|
-
|
|
75
|
-
test("creatable Select should create new element", () => {
|
|
76
|
-
const { getByRole, getByTestId } = render(<Select isCreateable />);
|
|
77
|
-
const select = getByRole("combobox");
|
|
78
|
-
const selectBox = getByTestId("select");
|
|
79
|
-
userEvent.click(select);
|
|
80
|
-
expect(selectBox).toHaveTextContent("No options", { exact: false });
|
|
81
|
-
userEvent.type(select, "hello");
|
|
82
|
-
userEvent.type(select, "{enter}");
|
|
83
|
-
expect(selectBox).toHaveTextContent("hello", { exact: false });
|
|
84
|
-
});
|
|
85
|
-
});
|
package/tests/Spinner.test.js
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import React from "react";
|
|
2
|
-
import { Spinner } from "../lib/components";
|
|
3
|
-
import { render } from "@testing-library/react";
|
|
4
|
-
|
|
5
|
-
describe("Spinner", () => {
|
|
6
|
-
it("should render without error", () => {
|
|
7
|
-
const { getByTestId } = render(<Spinner/>);
|
|
8
|
-
expect(getByTestId("spinner")).toBeInTheDocument();
|
|
9
|
-
});
|
|
10
|
-
});
|
package/tests/Switch.test.js
DELETED
|
@@ -1,61 +0,0 @@
|
|
|
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
|
-
});
|