@bigbinary/neetoui 3.2.78 → 3.2.79

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/jest-setup.js CHANGED
@@ -1,7 +1,22 @@
1
1
  import "@testing-library/jest-dom";
2
2
 
3
-
4
3
  // Fixes element.getTotalLength is not a function. Refer: https://github.com/framer/motion/issues/204
5
4
  if (!SVGElement.prototype.getTotalLength) {
6
5
  SVGElement.prototype.getTotalLength = () => 1;
7
- }
6
+ }
7
+
8
+ //Fixes ReferenceError: ResizeObserver is not defined
9
+ global.ResizeObserver = require('resize-observer-polyfill')
10
+
11
+ //Fixes TypeError: window.matchMedia is not a function
12
+ Object.defineProperty(window, 'matchMedia', {
13
+ writable: true,
14
+ value: jest.fn().mockImplementation((query) => ({
15
+ matches: false,
16
+ media: query,
17
+ onchange: null,
18
+ addListener: jest.fn(), // Deprecated
19
+ removeListener: jest.fn(), // Deprecated
20
+ }
21
+ )),
22
+ });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bigbinary/neetoui",
3
- "version": "3.2.78",
3
+ "version": "3.2.79",
4
4
  "main": "./index.js",
5
5
  "author": "BigBinary",
6
6
  "license": "MIT",
@@ -0,0 +1,75 @@
1
+ import React from "react";
2
+ import { render } from "@testing-library/react";
3
+ import { Input } from "../lib/components";
4
+ import userEvent from "@testing-library/user-event";
5
+
6
+ describe("Input", () => {
7
+ it("should render without error", () => {
8
+ const { getByLabelText } = render(<Input id="input" label="Input Label" />);
9
+ expect(getByLabelText("Input Label")).toBeInTheDocument();
10
+ });
11
+
12
+ it("should be able to type when uncontrolled", () => {
13
+ const { getByLabelText } = render(<Input id="input" label="Input Label" />);
14
+ const inputField = getByLabelText("Input Label");
15
+ userEvent.type(inputField, "sample content");
16
+ expect(inputField).toHaveValue("sample content");
17
+ });
18
+
19
+ it("should call onChange when textarea value changes", () => {
20
+ const onChange = jest.fn();
21
+ const { getByLabelText } = render(
22
+ <Input id="input" label="Input Label" onChange={onChange} />
23
+ );
24
+ userEvent.type(getByLabelText("Input Label"), "Test");
25
+ expect(onChange).toHaveBeenCalledTimes(4);
26
+ });
27
+
28
+ it("should display error message", () => {
29
+ const { getByText } = render(
30
+ <Input label="input" error={"Error message"} />
31
+ );
32
+ expect(getByText("Error message")).toBeInTheDocument();
33
+ });
34
+
35
+ it("should display helpText", () => {
36
+ const { getByText } = render(<Input label="Input" helpText="Help text" />);
37
+ expect(getByText("Help text")).toBeInTheDocument();
38
+ });
39
+
40
+ it("should be disabled if disabled is true", () => {
41
+ const { getByLabelText } = render(
42
+ <Input disabled id="input" label="Input Label" />
43
+ );
44
+ expect(getByLabelText("Input Label")).toBeDisabled();
45
+ });
46
+
47
+ it("should show suffix", () => {
48
+ const { getByText } = render(<Input label="input" suffix="suffix" />);
49
+ expect(getByText("suffix")).toBeInTheDocument();
50
+ });
51
+
52
+ it("should show prefix", () => {
53
+ const { getByText } = render(<Input label="input" prefix="prefix" />);
54
+ expect(getByText("prefix")).toBeInTheDocument();
55
+ });
56
+
57
+ it("should render asterisk when required is set to true", () => {
58
+ const { getByText } = render(<Input required label="Input" />);
59
+ const asterisk = getByText("*");
60
+ expect(asterisk).toBeInTheDocument();
61
+ });
62
+
63
+ it("should properly handle maxLength", () => {
64
+ const { getByLabelText, getByText } = render(
65
+ <Input id="input" label="Input label" maxLength={5} />
66
+ );
67
+
68
+ expect(getByText("0 / 5")).toBeInTheDocument();
69
+ expect(getByLabelText("Input label")).toHaveAttribute("maxLength", "5");
70
+
71
+ userEvent.type(getByLabelText("Input label"), "Testing maxLength");
72
+ expect(getByText("5 / 5")).toBeInTheDocument();
73
+ expect(getByLabelText("Input label")).toHaveValue("Testi");
74
+ });
75
+ });
@@ -0,0 +1,204 @@
1
+ import React from "react";
2
+ import { Table } from "../lib/components";
3
+ import { render, screen } from "@testing-library/react";
4
+ import userEvent from "@testing-library/user-event";
5
+
6
+ const columnData = [
7
+ {
8
+ dataIndex: 'id',
9
+ key: 'id',
10
+ title: 'ID',
11
+ width: 150
12
+ },
13
+ {
14
+ title: "First Name",
15
+ dataIndex: "first_name",
16
+ key: "first_name",
17
+ width: 150,
18
+ },
19
+ {
20
+ title: "Last Name",
21
+ dataIndex: "last_name",
22
+ key: "last_name",
23
+ width: 150,
24
+ }
25
+ ]
26
+
27
+ const rowData = [
28
+ {
29
+ id: 1,
30
+ first_name: "Oliver",
31
+ last_name: "Smith"
32
+ },
33
+ {
34
+ id: 2,
35
+ first_name: "Sam",
36
+ last_name: "Smith"
37
+ },
38
+ {
39
+ id: 3,
40
+ first_name: "Eve",
41
+ last_name: "Smith"
42
+ },
43
+ {
44
+ id: 4,
45
+ first_name: "Mark",
46
+ last_name: "Smith"
47
+ }
48
+ ]
49
+
50
+ describe("Table", () => {
51
+ it("should render column data without error", () => {
52
+ render(
53
+ <Table
54
+ columnData={columnData}
55
+ rowData={rowData}
56
+ />
57
+ )
58
+ const column = screen.getByText("ID")
59
+ expect(column).toBeInTheDocument();
60
+ });
61
+
62
+ it("should render row data without error", () => {
63
+ render(
64
+ <Table
65
+ columnData={columnData}
66
+ rowData={rowData}
67
+ />
68
+ )
69
+ const row = screen.getByText("1")
70
+ expect(row).toBeInTheDocument();
71
+ });
72
+
73
+ it("should render all the rows", () => {
74
+ render(
75
+ <Table
76
+ columnData={columnData}
77
+ rowData={rowData}
78
+ />
79
+ )
80
+ const row = screen.getAllByRole("row")
81
+ expect(row.length).toBe(4);
82
+ });
83
+
84
+ it("should render all the columns", () => {
85
+ render(
86
+ <Table
87
+ columnData={columnData}
88
+ rowData={rowData}
89
+ />
90
+ )
91
+ const column1 = screen.getByText("ID")
92
+ expect(column1).toBeInTheDocument();
93
+ const column2 = screen.getByText("First Name")
94
+ expect(column2).toBeInTheDocument();
95
+ const column3 = screen.getByText("Last Name")
96
+ expect(column3).toBeInTheDocument();
97
+ });
98
+
99
+ it("should have checkbox to select table row if rowSelection is set to true", () => {
100
+ render(
101
+ <Table
102
+ columnData={columnData}
103
+ rowData={rowData}
104
+ rowSelection
105
+ />
106
+ )
107
+ const checkboxes = screen.getAllByRole("checkbox")
108
+ expect(checkboxes.length).not.toBe(0);
109
+ });
110
+
111
+ it("should not have checkbox to select table row by default", () => {
112
+ render(
113
+ <Table
114
+ columnData={columnData}
115
+ rowData={rowData}
116
+ />
117
+ )
118
+ const checkbox = screen.queryByRole("checkbox")
119
+ expect(checkbox).not.toBeInTheDocument();
120
+ });
121
+
122
+ it("should call onRowSelect on row selection", () => {
123
+ const onRowSelect = jest.fn()
124
+ render(
125
+ <Table
126
+ columnData={columnData}
127
+ rowData={rowData}
128
+ onRowSelect={onRowSelect}
129
+ rowSelection
130
+ />
131
+ )
132
+ const checkbox = screen.getAllByRole("checkbox")
133
+ userEvent.click(checkbox[0])
134
+ expect(onRowSelect).toHaveBeenCalledTimes(1);
135
+ });
136
+
137
+ it("should call onRowClick on row click by default", () => {
138
+ const onRowClick = jest.fn()
139
+ render(
140
+ <Table
141
+ columnData={columnData}
142
+ rowData={rowData}
143
+ onRowClick={onRowClick}
144
+ />
145
+ )
146
+ const row = screen.getByText("1")
147
+ userEvent.click(row)
148
+ expect(onRowClick).toHaveBeenCalledTimes(1);
149
+ });
150
+
151
+ it("should not call onRowClick on row click when allowRowClick is disabled", () => {
152
+ const onRowClick = jest.fn()
153
+ render(
154
+ <Table
155
+ columnData={columnData}
156
+ rowData={rowData}
157
+ onRowClick={onRowClick}
158
+ allowRowClick={false}
159
+ />
160
+ )
161
+ const row = screen.getByText("1")
162
+ userEvent.click(row)
163
+ expect(onRowClick).toHaveBeenCalledTimes(0);
164
+ });
165
+
166
+ it("should render table with fixed height ", () => {
167
+ render(
168
+ <Table
169
+ columnData={columnData}
170
+ rowData={rowData}
171
+ fixedHeight
172
+ />
173
+ )
174
+ const row = screen.getByText("1")
175
+ expect(row).toBeInTheDocument();
176
+ });
177
+
178
+ it("should render table with rows equal to page size ", () => {
179
+ render(
180
+ <Table
181
+ columnData={columnData}
182
+ rowData={rowData}
183
+ defaultPageSize={2}
184
+ />
185
+ )
186
+ const row = screen.getAllByRole("row")
187
+ expect(row.length).toBe(2);
188
+ });
189
+
190
+ it("should call handlePageChange when page is changed ", () => {
191
+ const handlePageChange = jest.fn()
192
+ render(
193
+ <Table
194
+ columnData={columnData}
195
+ rowData={rowData}
196
+ defaultPageSize={2}
197
+ handlePageChange={handlePageChange}
198
+ />
199
+ )
200
+ const pages = screen.getAllByRole("listitem")
201
+ userEvent.click(pages[2])
202
+ expect(handlePageChange).toBeCalledTimes(1);
203
+ });
204
+ });