@scheels-softdev/kendoreact-generics 2.6.1 → 2.6.2
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/GenericDropdown.js +5 -2
- package/_index.test.d.ts +1 -0
- package/_index.test.js +101 -0
- package/package.json +7 -2
package/GenericDropdown.js
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
2
2
|
import { ComboBox } from "@progress/kendo-react-dropdowns";
|
3
|
-
import { filterBy } from "@progress/kendo-data-query";
|
4
|
-
import { useRef, useState } from "react";
|
3
|
+
import { filterBy, process } from "@progress/kendo-data-query";
|
4
|
+
import { useEffect, useRef, useState } from "react";
|
5
5
|
import { Skeleton } from "@progress/kendo-react-indicators";
|
6
6
|
export function GenericDropdown({ data, selectedId, selectedData, onChange, textField, disabled, idField, title, hideClearButton, style, isLoading, }) {
|
7
7
|
if (selectedId !== undefined && selectedData !== undefined) {
|
@@ -47,6 +47,9 @@ export function GenericDropdown({ data, selectedId, selectedData, onChange, text
|
|
47
47
|
const returnVal = data.find((x) => JSON.stringify(Object.assign(Object.assign({}, x), selectedData)) === JSON.stringify(Object.assign({}, x)));
|
48
48
|
return returnVal;
|
49
49
|
};
|
50
|
+
useEffect(() => {
|
51
|
+
setState((current) => (Object.assign(Object.assign({}, current), { subsetData: process(data, current).data })));
|
52
|
+
}, [data]);
|
50
53
|
return (_jsx("div", Object.assign({ "data-testid": "dropdown" }, { children: data.length && !isLoading ? (_jsx(ComboBox, { style: style, label: title, disabled: disabled, data: state.subsetData, textField: textField.toString(), virtual: {
|
51
54
|
// enable virtualization for large datasets
|
52
55
|
total: state.total,
|
package/_index.test.d.ts
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
export {};
|
package/_index.test.js
ADDED
@@ -0,0 +1,101 @@
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
2
|
+
import { GenericDropdown } from "./GenericDropdown";
|
3
|
+
import { fireEvent, render } from "@testing-library/react";
|
4
|
+
describe("GenericDropdown", () => {
|
5
|
+
const data = [];
|
6
|
+
for (let i = 1; i < 20; i++) {
|
7
|
+
data.push({ id: i, name: `Option ${i}` });
|
8
|
+
}
|
9
|
+
test("renders virtualized ordering by index when passed selectedData", () => {
|
10
|
+
// Set initial selectedData to the second item in the data array
|
11
|
+
let selectedData = data[1];
|
12
|
+
// Render the GenericDropdown component with the data, onChange function, textField prop, and selectedData prop
|
13
|
+
let result = render(_jsx(GenericDropdown, { data: data, onChange: () => { }, textField: "name", selectedData: selectedData }));
|
14
|
+
// Get the input element by its role of "combobox"
|
15
|
+
const input = result.getByRole("combobox");
|
16
|
+
expect(input.getAttribute("value")).toBe("Option 2");
|
17
|
+
// Simulate a change event on the input element by setting its target value to "O"
|
18
|
+
fireEvent.change(input, { target: { value: "O" } });
|
19
|
+
// Simulate a key down event on the input element with the key value of "ArrowDown"
|
20
|
+
fireEvent.keyDown(input, { key: "ArrowDown" });
|
21
|
+
// Query the rendered result for elements with the text "Option 1", "Option 2", and "Option 3"
|
22
|
+
let item1 = result.queryByText("Option 1");
|
23
|
+
let item2 = result.queryByText("Option 2");
|
24
|
+
let item3 = result.queryByText("Option 3");
|
25
|
+
// Ensure that item1, item2, and item3 are not undefined (i.e., they are rendered)
|
26
|
+
expect(item1).not.toBeUndefined();
|
27
|
+
expect(item2).not.toBeUndefined();
|
28
|
+
expect(item3).not.toBeUndefined();
|
29
|
+
// Ensure that there are no elements with the text "Option 9" (i.e., it is not rendered)
|
30
|
+
expect(result.queryAllByText("Option 9")).toHaveLength(0);
|
31
|
+
});
|
32
|
+
test("renders virtualized ordering by index when passed selectedId", () => {
|
33
|
+
// Set initial selectedData to the second item in the data array
|
34
|
+
let selectedId = 2;
|
35
|
+
// Render the GenericDropdown component with the data, onChange function, textField prop, and selectedData prop
|
36
|
+
let result = render(_jsx(GenericDropdown, { data: data, onChange: () => { }, textField: "name", selectedId: selectedId }));
|
37
|
+
// Get the input element by its role of "combobox"
|
38
|
+
const input = result.getByRole("combobox");
|
39
|
+
expect(input.getAttribute("value")).toBe("Option 2");
|
40
|
+
// Simulate a change event on the input element by setting its target value to "O"
|
41
|
+
fireEvent.change(input, { target: { value: "O" } });
|
42
|
+
// Simulate a key down event on the input element with the key value of "ArrowDown"
|
43
|
+
fireEvent.keyDown(input, { key: "ArrowDown" });
|
44
|
+
// Query the rendered result for elements with the text "Option 1", "Option 2", and "Option 3"
|
45
|
+
let item1 = result.queryByText("Option 1");
|
46
|
+
let item2 = result.queryByText("Option 2");
|
47
|
+
let item3 = result.queryByText("Option 3");
|
48
|
+
// Ensure that item1, item2, and item3 are not undefined (i.e., they are rendered)
|
49
|
+
expect(item1).not.toBeUndefined();
|
50
|
+
expect(item2).not.toBeUndefined();
|
51
|
+
expect(item3).not.toBeUndefined();
|
52
|
+
// Ensure that there are no elements with the text "Option 9" (i.e., it is not rendered)
|
53
|
+
expect(result.queryAllByText("Option 9")).toHaveLength(0);
|
54
|
+
});
|
55
|
+
test("handles change event when selecting by object", () => {
|
56
|
+
// Set initial selectedData to the second item in the data array
|
57
|
+
let selectedData = data[1];
|
58
|
+
// Render the GenericDropdown component with the data, onChange function, textField prop, and selectedData prop
|
59
|
+
let result = render(_jsx(GenericDropdown, { data: data, onChange: (e) => (selectedData = data[e.value]), textField: "name", selectedData: selectedData }));
|
60
|
+
// Get the input element by its role of "combobox"
|
61
|
+
// Simulate a change event on the input element by setting its target value to "O"
|
62
|
+
let input = result.getByRole("combobox");
|
63
|
+
fireEvent.change(input, { target: { value: "O" } });
|
64
|
+
// Get the item element with the text "Option 2"
|
65
|
+
let item2 = result.getByText("Option 2");
|
66
|
+
// Simulate a click event on the item element
|
67
|
+
fireEvent.click(item2);
|
68
|
+
// Ensure that the input element's value attribute is set to "Option 2"
|
69
|
+
expect(selectedData.id).toBe(2);
|
70
|
+
});
|
71
|
+
test("handles change event when selecting by id", () => {
|
72
|
+
// Set initial selectedData to the second item in the data array
|
73
|
+
let selectedId = 1;
|
74
|
+
// Render the GenericDropdown component with the data, onChange function, textField prop, and selectedData prop
|
75
|
+
let result = render(_jsx(GenericDropdown, { data: data, onChange: (e) => (selectedId = e.value.id), textField: "name", selectedId: selectedId, idField: "id" }));
|
76
|
+
// Get the input element by its role of "combobox"
|
77
|
+
// Simulate a change event on the input element by setting its target value to "O"
|
78
|
+
let input = result.getByRole("combobox");
|
79
|
+
fireEvent.change(input, { target: { value: "O" } });
|
80
|
+
// Get the item element with the text "Option 2"
|
81
|
+
let item2 = result.getByText("Option 2");
|
82
|
+
// Simulate a click event on the item element
|
83
|
+
fireEvent.click(item2);
|
84
|
+
// Ensure that the input element's value attribute is set to "Option 2"
|
85
|
+
expect(selectedId).toBe(2);
|
86
|
+
});
|
87
|
+
test("only displays items that match the search", () => {
|
88
|
+
// Set initial selectedData to the second item in the data array
|
89
|
+
let selectedData = data[1];
|
90
|
+
// Render the GenericDropdown component with the data, onChange function, textField prop, and selectedData prop
|
91
|
+
let result = render(_jsx(GenericDropdown, { data: data, onChange: (e) => (selectedData = data[e.value]), textField: "name", selectedData: selectedData }));
|
92
|
+
let input = result.getByRole("combobox"); // Get the input element by its role of "combobox"
|
93
|
+
fireEvent.change(input, { target: { value: "9" } }); //simulate a change event on the input element
|
94
|
+
// Query the rendered result for elements with the text "Option 1" and "Option 9", and store the results in variables
|
95
|
+
let item1 = result.queryAllByText("Option 1");
|
96
|
+
let item9 = result.queryAllByText("Option 9");
|
97
|
+
// Ensure that there are no elements with the text "Option 1" and at least one element with the text "Option 9"
|
98
|
+
expect(item1).toHaveLength(0);
|
99
|
+
expect(item9.length).toBeGreaterThan(0);
|
100
|
+
});
|
101
|
+
});
|
package/package.json
CHANGED
@@ -1,9 +1,9 @@
|
|
1
1
|
{
|
2
2
|
"name": "@scheels-softdev/kendoreact-generics",
|
3
|
-
"version": "2.6.
|
3
|
+
"version": "2.6.2",
|
4
4
|
"main": "index.js",
|
5
5
|
"scripts": {
|
6
|
-
"test": "
|
6
|
+
"test": "jest",
|
7
7
|
"clean": "rmdir /S /Q dist && mkdir dist",
|
8
8
|
"build": "npm run clean && tsc && copy package.json .\\dist && copy README.md .\\dist "
|
9
9
|
},
|
@@ -19,8 +19,12 @@
|
|
19
19
|
"@progress/kendo-react-grid": "latest",
|
20
20
|
"@progress/kendo-react-indicators": "^5.14.1",
|
21
21
|
"@progress/kendo-react-inputs": "latest",
|
22
|
+
"@testing-library/react": "^14.0.0",
|
23
|
+
"@types/jest": "^29.5.3",
|
22
24
|
"@types/moment": "latest",
|
23
25
|
"@types/react": "latest",
|
26
|
+
"jest": "^29.6.2",
|
27
|
+
"jest-environment-jsdom": "^29.6.2",
|
24
28
|
"moment": "latest",
|
25
29
|
"npmrc": "latest",
|
26
30
|
"react": "latest",
|
@@ -37,6 +41,7 @@
|
|
37
41
|
"moment": "^2.29.4",
|
38
42
|
"react": "^18.2.0",
|
39
43
|
"react-dom": "^18.2.0",
|
44
|
+
"ts-jest": "^29.1.1",
|
40
45
|
"typescript": "^4.9.5"
|
41
46
|
},
|
42
47
|
"description": ""
|