@bigbinary/neetoui 3.2.73 → 3.3.0-beta.0

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.
@@ -1,185 +0,0 @@
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
- });
@@ -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
- });
@@ -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
- });
@@ -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
- });
@@ -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
- });
@@ -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/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
- });
@@ -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
- });
@@ -1,20 +0,0 @@
1
- import React from "react";
2
- import { Typography } from "../lib/components";
3
- import { render } from "@testing-library/react";
4
-
5
- describe("Typography", () => {
6
- it("should render without error", () => {
7
- const { getByText } = render(<Typography style="body1">Typography</Typography>);
8
- expect(getByText("Typography")).toBeInTheDocument();
9
- });
10
-
11
- it("should render a heading when style is of heading type", () => {
12
- const { getByRole } = render(<Typography style="h1">Typography</Typography>);
13
- expect(getByRole("heading", { level: 1 })).toBeInTheDocument();
14
- });
15
-
16
- it("should override default tag when component prop is given", () => {
17
- const { getByRole } = render(<Typography style="h1" component="h2">Typography</Typography>);
18
- expect(getByRole("heading", { level: 2 })).toBeInTheDocument();
19
- });
20
- });