@bigbinary/neetoui 3.2.77 → 3.3.0-beta.1

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,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
- });
@@ -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,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
- });
@@ -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
- });
@@ -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
- });
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/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
- });