@bigbinary/neetoui 3.2.65 → 3.2.68

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.65",
3
+ "version": "3.2.68",
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.1.9",
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",
@@ -1,6 +1,7 @@
1
1
  import React from "react";
2
2
  import { Accordion } from "../lib/components";
3
- import { render, fireEvent, waitForElementToBeRemoved } from "@testing-library/react";
3
+ import { render, waitForElementToBeRemoved } from "@testing-library/react";
4
+ import userEvent from "@testing-library/user-event";
4
5
 
5
6
 
6
7
 
@@ -29,7 +30,7 @@ describe("Accordion", () => {
29
30
  <p>Content 1</p>
30
31
  </Accordion.Item>
31
32
  </Accordion>);
32
- fireEvent.click(getByText("Item 1"));
33
+ userEvent.click(getByText("Item 1"));
33
34
  expect(getByText("Content 1")).toBeInTheDocument();
34
35
  });
35
36
 
@@ -39,12 +40,12 @@ describe("Accordion", () => {
39
40
  <p>Content 1</p>
40
41
  </Accordion.Item>
41
42
  </Accordion>);
42
- fireEvent.click(getByText("Item 1"));
43
+ userEvent.click(getByText("Item 1"));
43
44
  expect(getByText("Content 1")).toBeInTheDocument();
44
- fireEvent.keyDown(getByText("Item 1"), { key: " ", bubbles: true });
45
+ userEvent.keyboard("{space}");
45
46
  await waitForElementToBeRemoved(() => queryByText("Content 1"));
46
47
  expect(queryByText("Content 1")).not.toBeInTheDocument();
47
- fireEvent.keyDown(getByText("Item 1"), { key: "Enter", bubbles: true });
48
+ userEvent.keyboard("{enter}");
48
49
  expect(getByText("Content 1")).toBeInTheDocument();
49
50
  });
50
51
 
@@ -54,9 +55,9 @@ describe("Accordion", () => {
54
55
  <p>Content 1</p>
55
56
  </Accordion.Item>
56
57
  </Accordion>);
57
- fireEvent.click(getByText("Item 1"));
58
+ userEvent.click(getByText("Item 1"));
58
59
  expect(getByText("Content 1")).toBeInTheDocument();
59
- fireEvent.keyDown(getByText("Item 1"), { key: "a", bubbles: true });
60
+ userEvent.type(getByText("Item 1"), "a");
60
61
  expect(getByText("Content 1")).toBeInTheDocument();
61
62
  });
62
63
 
@@ -67,7 +68,7 @@ describe("Accordion", () => {
67
68
  <p>Content 1</p>
68
69
  </Accordion.Item>
69
70
  </Accordion>);
70
- fireEvent.click(getByText("Item 1"));
71
+ userEvent.click(getByText("Item 1"));
71
72
  expect(onClick).toHaveBeenCalledTimes(1);
72
73
  });
73
74
 
@@ -80,9 +81,9 @@ describe("Accordion", () => {
80
81
  <p>Content 2</p>
81
82
  </Accordion.Item>
82
83
  </Accordion>);
83
- fireEvent.click(getByText("Item 1"));
84
+ userEvent.click(getByText("Item 1"));
84
85
  expect(getByText("Content 1")).toBeInTheDocument();
85
- fireEvent.click(getByText("Item 2"));
86
+ userEvent.click(getByText("Item 2"));
86
87
  await waitForElementToBeRemoved(() => queryByText("Content 1"));
87
88
  expect(queryByText("Content 1")).not.toBeInTheDocument();
88
89
  expect(getByText("Content 2")).toBeInTheDocument();
@@ -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
+ });
@@ -1,7 +1,8 @@
1
1
  import React from "react";
2
2
  import { Button } from "../lib/components";
3
- import { render, fireEvent } from "@testing-library/react";
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
- fireEvent.click(getByText("Button"));
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
- fireEvent.click(getByText("Button"));
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
- fireEvent.click(getByText("Button"));
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
- fireEvent.mouseEnter(getByText("Button"), { bubbles: true });
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
+ });
@@ -0,0 +1,51 @@
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
+ });
@@ -0,0 +1,20 @@
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
+ });