@bigbinary/neetoui 3.2.63 → 3.2.66

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.63",
3
+ "version": "3.2.66",
4
4
  "main": "./index.js",
5
5
  "author": "BigBinary",
6
6
  "license": "MIT",
@@ -0,0 +1,102 @@
1
+ import React from "react";
2
+ import { Accordion } from "../lib/components";
3
+ import { render, fireEvent, waitForElementToBeRemoved } from "@testing-library/react";
4
+
5
+
6
+
7
+ describe("Accordion", () => {
8
+ it("should render without error", () => {
9
+ const { getByText } = render(<Accordion>
10
+ <Accordion.Item title="Item 1">
11
+ <p>Content 1</p>
12
+ </Accordion.Item>
13
+ </Accordion>);
14
+ expect(getByText("Item 1")).toBeInTheDocument();
15
+ });
16
+
17
+ it("should not render content when accordion is closed", () => {
18
+ const { queryByText } = render(<Accordion>
19
+ <Accordion.Item title="Item 1">
20
+ <p>Content 1</p>
21
+ </Accordion.Item>
22
+ </Accordion>);
23
+ expect(queryByText("Content 1")).not.toBeInTheDocument();
24
+ });
25
+
26
+ it("should open accordion and render content when accordion title is clicked", () => {
27
+ const { getByText } = render(<Accordion>
28
+ <Accordion.Item title="Item 1">
29
+ <p>Content 1</p>
30
+ </Accordion.Item>
31
+ </Accordion>);
32
+ fireEvent.click(getByText("Item 1"));
33
+ expect(getByText("Content 1")).toBeInTheDocument();
34
+ });
35
+
36
+ it("should toggle accordion when Enter or Space key is pressed", async () => {
37
+ const { getByText, queryByText } = render(<Accordion>
38
+ <Accordion.Item title="Item 1">
39
+ <p>Content 1</p>
40
+ </Accordion.Item>
41
+ </Accordion>);
42
+ fireEvent.click(getByText("Item 1"));
43
+ expect(getByText("Content 1")).toBeInTheDocument();
44
+ fireEvent.keyDown(getByText("Item 1"), { key: " ", bubbles: true });
45
+ await waitForElementToBeRemoved(() => queryByText("Content 1"));
46
+ expect(queryByText("Content 1")).not.toBeInTheDocument();
47
+ fireEvent.keyDown(getByText("Item 1"), { key: "Enter", bubbles: true });
48
+ expect(getByText("Content 1")).toBeInTheDocument();
49
+ });
50
+
51
+ it("should not toggle accordion when any other keys are pressed", () => {
52
+ const { getByText } = render(<Accordion>
53
+ <Accordion.Item title="Item 1">
54
+ <p>Content 1</p>
55
+ </Accordion.Item>
56
+ </Accordion>);
57
+ fireEvent.click(getByText("Item 1"));
58
+ expect(getByText("Content 1")).toBeInTheDocument();
59
+ fireEvent.keyDown(getByText("Item 1"), { key: "a", bubbles: true });
60
+ expect(getByText("Content 1")).toBeInTheDocument();
61
+ });
62
+
63
+ it("should trigger onClick when title is clicked", () => {
64
+ const onClick = jest.fn();
65
+ const { getByText } = render(<Accordion>
66
+ <Accordion.Item title="Item 1" onClick={onClick}>
67
+ <p>Content 1</p>
68
+ </Accordion.Item>
69
+ </Accordion>);
70
+ fireEvent.click(getByText("Item 1"));
71
+ expect(onClick).toHaveBeenCalledTimes(1);
72
+ });
73
+
74
+ it("should only open one accordion at a time", async () => {
75
+ const { getByText, queryByText } = render(<Accordion>
76
+ <Accordion.Item title="Item 1">
77
+ <p>Content 1</p>
78
+ </Accordion.Item>
79
+ <Accordion.Item title="Item 2">
80
+ <p>Content 2</p>
81
+ </Accordion.Item>
82
+ </Accordion>);
83
+ fireEvent.click(getByText("Item 1"));
84
+ expect(getByText("Content 1")).toBeInTheDocument();
85
+ fireEvent.click(getByText("Item 2"));
86
+ await waitForElementToBeRemoved(() => queryByText("Content 1"));
87
+ expect(queryByText("Content 1")).not.toBeInTheDocument();
88
+ expect(getByText("Content 2")).toBeInTheDocument();
89
+ });
90
+
91
+ it("should open the the accordion when defaultActiveKey is provided", () => {
92
+ const { getByText } = render(<Accordion defaultActiveKey={1}>
93
+ <Accordion.Item title="Item 1">
94
+ <p>Content 1</p>
95
+ </Accordion.Item>
96
+ <Accordion.Item title="Item 2">
97
+ <p>Content 2</p>
98
+ </Accordion.Item>
99
+ </Accordion>);
100
+ expect(getByText("Content 2")).toBeInTheDocument();
101
+ });
102
+ });