@bigbinary/neetoui 3.2.72 → 3.2.73

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bigbinary/neetoui",
3
- "version": "3.2.72",
3
+ "version": "3.2.73",
4
4
  "main": "./index.js",
5
5
  "author": "BigBinary",
6
6
  "license": "MIT",
@@ -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,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,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
+ });
@@ -0,0 +1,85 @@
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
+ });