@bigbinary/neetoui 3.2.64 → 3.2.67
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/.eslint-rules/imports/enforced.js +20 -0
- package/.eslint-rules/imports/order.js +15 -0
- package/.eslint-rules/overrides.js +12 -0
- package/.eslint-rules/react.js +34 -0
- package/formik.js +1 -1
- package/formik.js.LICENSE.txt +0 -15
- package/index.js +1 -1
- package/jest-setup.js +7 -1
- package/layouts.js +1 -1
- package/package.json +2 -2
- package/tests/Accordion.test.js +103 -0
- package/tests/Alert.test.js +126 -0
- package/tests/Button.test.js +6 -5
- package/tests/Collapse.test.js +19 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bigbinary/neetoui",
|
|
3
|
-
"version": "3.2.
|
|
3
|
+
"version": "3.2.67",
|
|
4
4
|
"main": "./index.js",
|
|
5
5
|
"author": "BigBinary",
|
|
6
6
|
"license": "MIT",
|
|
@@ -52,7 +52,7 @@
|
|
|
52
52
|
"@storybook/react": "^6.4.19",
|
|
53
53
|
"@testing-library/jest-dom": "^5.16.2",
|
|
54
54
|
"@testing-library/react": "^12.1.3",
|
|
55
|
-
"@testing-library/user-event": "^13.
|
|
55
|
+
"@testing-library/user-event": "^13.5.0",
|
|
56
56
|
"autoprefixer": "^9.0.0",
|
|
57
57
|
"babel-eslint": "^10.1.0",
|
|
58
58
|
"babel-jest": "^27.3.1",
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { Accordion } from "../lib/components";
|
|
3
|
+
import { render, waitForElementToBeRemoved } from "@testing-library/react";
|
|
4
|
+
import userEvent from "@testing-library/user-event";
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
describe("Accordion", () => {
|
|
9
|
+
it("should render without error", () => {
|
|
10
|
+
const { getByText } = render(<Accordion>
|
|
11
|
+
<Accordion.Item title="Item 1">
|
|
12
|
+
<p>Content 1</p>
|
|
13
|
+
</Accordion.Item>
|
|
14
|
+
</Accordion>);
|
|
15
|
+
expect(getByText("Item 1")).toBeInTheDocument();
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
it("should not render content when accordion is closed", () => {
|
|
19
|
+
const { queryByText } = render(<Accordion>
|
|
20
|
+
<Accordion.Item title="Item 1">
|
|
21
|
+
<p>Content 1</p>
|
|
22
|
+
</Accordion.Item>
|
|
23
|
+
</Accordion>);
|
|
24
|
+
expect(queryByText("Content 1")).not.toBeInTheDocument();
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
it("should open accordion and render content when accordion title is clicked", () => {
|
|
28
|
+
const { getByText } = render(<Accordion>
|
|
29
|
+
<Accordion.Item title="Item 1">
|
|
30
|
+
<p>Content 1</p>
|
|
31
|
+
</Accordion.Item>
|
|
32
|
+
</Accordion>);
|
|
33
|
+
userEvent.click(getByText("Item 1"));
|
|
34
|
+
expect(getByText("Content 1")).toBeInTheDocument();
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
it("should toggle accordion when Enter or Space key is pressed", async () => {
|
|
38
|
+
const { getByText, queryByText } = render(<Accordion>
|
|
39
|
+
<Accordion.Item title="Item 1">
|
|
40
|
+
<p>Content 1</p>
|
|
41
|
+
</Accordion.Item>
|
|
42
|
+
</Accordion>);
|
|
43
|
+
userEvent.click(getByText("Item 1"));
|
|
44
|
+
expect(getByText("Content 1")).toBeInTheDocument();
|
|
45
|
+
userEvent.keyboard("{space}");
|
|
46
|
+
await waitForElementToBeRemoved(() => queryByText("Content 1"));
|
|
47
|
+
expect(queryByText("Content 1")).not.toBeInTheDocument();
|
|
48
|
+
userEvent.keyboard("{enter}");
|
|
49
|
+
expect(getByText("Content 1")).toBeInTheDocument();
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
it("should not toggle accordion when any other keys are pressed", () => {
|
|
53
|
+
const { getByText } = render(<Accordion>
|
|
54
|
+
<Accordion.Item title="Item 1">
|
|
55
|
+
<p>Content 1</p>
|
|
56
|
+
</Accordion.Item>
|
|
57
|
+
</Accordion>);
|
|
58
|
+
userEvent.click(getByText("Item 1"));
|
|
59
|
+
expect(getByText("Content 1")).toBeInTheDocument();
|
|
60
|
+
userEvent.type(getByText("Item 1"), "a");
|
|
61
|
+
expect(getByText("Content 1")).toBeInTheDocument();
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
it("should trigger onClick when title is clicked", () => {
|
|
65
|
+
const onClick = jest.fn();
|
|
66
|
+
const { getByText } = render(<Accordion>
|
|
67
|
+
<Accordion.Item title="Item 1" onClick={onClick}>
|
|
68
|
+
<p>Content 1</p>
|
|
69
|
+
</Accordion.Item>
|
|
70
|
+
</Accordion>);
|
|
71
|
+
userEvent.click(getByText("Item 1"));
|
|
72
|
+
expect(onClick).toHaveBeenCalledTimes(1);
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
it("should only open one accordion at a time", async () => {
|
|
76
|
+
const { getByText, queryByText } = render(<Accordion>
|
|
77
|
+
<Accordion.Item title="Item 1">
|
|
78
|
+
<p>Content 1</p>
|
|
79
|
+
</Accordion.Item>
|
|
80
|
+
<Accordion.Item title="Item 2">
|
|
81
|
+
<p>Content 2</p>
|
|
82
|
+
</Accordion.Item>
|
|
83
|
+
</Accordion>);
|
|
84
|
+
userEvent.click(getByText("Item 1"));
|
|
85
|
+
expect(getByText("Content 1")).toBeInTheDocument();
|
|
86
|
+
userEvent.click(getByText("Item 2"));
|
|
87
|
+
await waitForElementToBeRemoved(() => queryByText("Content 1"));
|
|
88
|
+
expect(queryByText("Content 1")).not.toBeInTheDocument();
|
|
89
|
+
expect(getByText("Content 2")).toBeInTheDocument();
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
it("should open the the accordion when defaultActiveKey is provided", () => {
|
|
93
|
+
const { getByText } = render(<Accordion defaultActiveKey={1}>
|
|
94
|
+
<Accordion.Item title="Item 1">
|
|
95
|
+
<p>Content 1</p>
|
|
96
|
+
</Accordion.Item>
|
|
97
|
+
<Accordion.Item title="Item 2">
|
|
98
|
+
<p>Content 2</p>
|
|
99
|
+
</Accordion.Item>
|
|
100
|
+
</Accordion>);
|
|
101
|
+
expect(getByText("Content 2")).toBeInTheDocument();
|
|
102
|
+
});
|
|
103
|
+
});
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { Alert } from "../lib/components";
|
|
3
|
+
import { render } from "@testing-library/react";
|
|
4
|
+
import userEvent from "@testing-library/user-event";
|
|
5
|
+
|
|
6
|
+
describe("Alert", () => {
|
|
7
|
+
it("should render without error", () => {
|
|
8
|
+
const { getByText } = render(
|
|
9
|
+
<Alert title="Alert title" message="Alert message" isOpen />
|
|
10
|
+
);
|
|
11
|
+
expect(getByText("Alert title")).toBeInTheDocument();
|
|
12
|
+
expect(getByText("Alert message")).toBeInTheDocument();
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
it("should not display content when isOpen is false", () => {
|
|
16
|
+
const { queryByText } = render(
|
|
17
|
+
<Alert title="Alert title" message="Alert message" isOpen={false} />
|
|
18
|
+
);
|
|
19
|
+
expect(queryByText("Alert title")).not.toBeInTheDocument();
|
|
20
|
+
expect(queryByText("Alert message")).not.toBeInTheDocument();
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
it("should call onClose when close button is clicked", () => {
|
|
24
|
+
const onClose = jest.fn();
|
|
25
|
+
const { getByTestId } = render(
|
|
26
|
+
<Alert
|
|
27
|
+
title="Alert title"
|
|
28
|
+
message="Alert message"
|
|
29
|
+
isOpen
|
|
30
|
+
onClose={onClose}
|
|
31
|
+
/>
|
|
32
|
+
);
|
|
33
|
+
userEvent.click(getByTestId("close-button"));
|
|
34
|
+
expect(onClose).toHaveBeenCalledTimes(1);
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
it("should call onSubmit when submit button is clicked", () => {
|
|
38
|
+
const onSubmit = jest.fn();
|
|
39
|
+
const { getByText } = render(
|
|
40
|
+
<Alert
|
|
41
|
+
title="Alert title"
|
|
42
|
+
message="Alert message"
|
|
43
|
+
isOpen
|
|
44
|
+
onSubmit={onSubmit}
|
|
45
|
+
submitButtonLabel="Submit"
|
|
46
|
+
/>
|
|
47
|
+
);
|
|
48
|
+
userEvent.click(getByText("Submit"));
|
|
49
|
+
expect(onSubmit).toHaveBeenCalledTimes(1);
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
it("should call onClose when cancel button is clicked", () => {
|
|
53
|
+
const onClose = jest.fn();
|
|
54
|
+
const { getByText } = render(
|
|
55
|
+
<Alert
|
|
56
|
+
title="Alert title"
|
|
57
|
+
message="Alert message"
|
|
58
|
+
isOpen
|
|
59
|
+
onClose={onClose}
|
|
60
|
+
cancelButtonLabel="Cancel"
|
|
61
|
+
/>
|
|
62
|
+
);
|
|
63
|
+
userEvent.click(getByText("Cancel"));
|
|
64
|
+
expect(onClose).toHaveBeenCalledTimes(1);
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
it("should close the alert when Esc key is pressed", () => {
|
|
68
|
+
const onClose = jest.fn();
|
|
69
|
+
const { container } = render(
|
|
70
|
+
<Alert
|
|
71
|
+
title="Alert title"
|
|
72
|
+
message="Alert message"
|
|
73
|
+
isOpen
|
|
74
|
+
onClose={onClose}
|
|
75
|
+
closeOnEsc
|
|
76
|
+
/>
|
|
77
|
+
);
|
|
78
|
+
userEvent.type(container, "{esc}");
|
|
79
|
+
expect(onClose).toHaveBeenCalledTimes(1);
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
it("should not close the alert when Esc key is pressed when closeOnEsc is false", () => {
|
|
83
|
+
const onClose = jest.fn();
|
|
84
|
+
const { container } = render(
|
|
85
|
+
<Alert
|
|
86
|
+
title="Alert title"
|
|
87
|
+
message="Alert message"
|
|
88
|
+
isOpen
|
|
89
|
+
onClose={onClose}
|
|
90
|
+
closeOnEsc={false}
|
|
91
|
+
/>
|
|
92
|
+
);
|
|
93
|
+
userEvent.type(container, "{esc}");
|
|
94
|
+
expect(onClose).not.toHaveBeenCalled();
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
it("should close alert when clicking outside", () => {
|
|
98
|
+
const onClose = jest.fn();
|
|
99
|
+
const { getByTestId } = render(
|
|
100
|
+
<Alert
|
|
101
|
+
title="Alert title"
|
|
102
|
+
message="Alert message"
|
|
103
|
+
isOpen
|
|
104
|
+
onClose={onClose}
|
|
105
|
+
closeOnOutsideClick
|
|
106
|
+
/>
|
|
107
|
+
);
|
|
108
|
+
userEvent.click(getByTestId("backdrop"));
|
|
109
|
+
expect(onClose).toHaveBeenCalledTimes(1);
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
it("should not close alert when clicking outside when closeOnOutsideClick is false", () => {
|
|
113
|
+
const onClose = jest.fn();
|
|
114
|
+
const { getByTestId } = render(
|
|
115
|
+
<Alert
|
|
116
|
+
title="Alert title"
|
|
117
|
+
message="Alert message"
|
|
118
|
+
isOpen
|
|
119
|
+
onClose={onClose}
|
|
120
|
+
closeOnOutsideClick={false}
|
|
121
|
+
/>
|
|
122
|
+
);
|
|
123
|
+
userEvent.click(getByTestId("backdrop"));
|
|
124
|
+
expect(onClose).not.toHaveBeenCalled();
|
|
125
|
+
});
|
|
126
|
+
});
|
package/tests/Button.test.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import React from "react";
|
|
2
2
|
import { Button } from "../lib/components";
|
|
3
|
-
import { render
|
|
3
|
+
import { render } from "@testing-library/react";
|
|
4
4
|
import { BrowserRouter } from "react-router-dom";
|
|
5
|
+
import userEvent from "@testing-library/user-event";
|
|
5
6
|
|
|
6
7
|
describe("Button", () => {
|
|
7
8
|
it("should render without error", () => {
|
|
@@ -12,7 +13,7 @@ describe("Button", () => {
|
|
|
12
13
|
it("should call onClick on button click", () => {
|
|
13
14
|
const onClick = jest.fn();
|
|
14
15
|
const { getByText } = render(<Button label="Button" onClick={onClick} />);
|
|
15
|
-
|
|
16
|
+
userEvent.click(getByText("Button"));
|
|
16
17
|
expect(onClick).toHaveBeenCalledTimes(1);
|
|
17
18
|
});
|
|
18
19
|
|
|
@@ -21,7 +22,7 @@ describe("Button", () => {
|
|
|
21
22
|
const { getByText } = render(
|
|
22
23
|
<Button label="Button" onClick={onClick} disabled />
|
|
23
24
|
);
|
|
24
|
-
|
|
25
|
+
userEvent.click(getByText("Button"));
|
|
25
26
|
expect(onClick).toHaveBeenCalledTimes(0);
|
|
26
27
|
});
|
|
27
28
|
|
|
@@ -30,7 +31,7 @@ describe("Button", () => {
|
|
|
30
31
|
const { getByText } = render(
|
|
31
32
|
<Button label="Button" onClick={onClick} loading />
|
|
32
33
|
);
|
|
33
|
-
|
|
34
|
+
userEvent.click(getByText("Button"));
|
|
34
35
|
expect(onClick).toHaveBeenCalledTimes(0);
|
|
35
36
|
});
|
|
36
37
|
|
|
@@ -38,7 +39,7 @@ describe("Button", () => {
|
|
|
38
39
|
const { getByText } = render(
|
|
39
40
|
<Button label="Button" tooltipProps={{ content: "Tooltip" }} />
|
|
40
41
|
);
|
|
41
|
-
|
|
42
|
+
userEvent.hover(getByText("Button"));
|
|
42
43
|
expect(getByText("Tooltip")).toBeInTheDocument();
|
|
43
44
|
});
|
|
44
45
|
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { render } from "@testing-library/react";
|
|
3
|
+
import Collapse from "../lib/components/Accordion/Collapse";
|
|
4
|
+
|
|
5
|
+
describe("Collapse", () => {
|
|
6
|
+
it("should render without error", () => {
|
|
7
|
+
const { getByText } = render(<Collapse open>
|
|
8
|
+
<p>Content</p>
|
|
9
|
+
</Collapse>);
|
|
10
|
+
expect(getByText("Content")).toBeInTheDocument();
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
it("should not display content when collapsed", () => {
|
|
14
|
+
const { queryByText } = render(<Collapse>
|
|
15
|
+
<p>Content</p>
|
|
16
|
+
</Collapse>);
|
|
17
|
+
expect(queryByText("Content")).not.toBeInTheDocument();
|
|
18
|
+
});
|
|
19
|
+
});
|