@linzjs/step-ag-grid 7.0.4 → 7.1.0
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/dist/index.js +20522 -267
- package/dist/index.js.map +1 -1
- package/dist/src/index.d.ts +1 -0
- package/dist/src/utils/testQuick.d.ts +62 -0
- package/dist/src/utils/testUtil.d.ts +22 -0
- package/dist/step-ag-grid.esm.js +20225 -8
- package/dist/step-ag-grid.esm.js.map +1 -1
- package/package.json +1 -1
- package/src/components/gridForm/GridFormDropDown.tsx +1 -1
- package/src/components/gridForm/GridFormMultiSelect.tsx +1 -1
- package/src/index.ts +1 -0
- package/src/react-menu3/components/ControlledMenu.tsx +1 -1
- package/src/utils/testQuick.ts +146 -0
- package/src/utils/testUtil.ts +135 -0
package/package.json
CHANGED
|
@@ -247,7 +247,7 @@ export const GridFormDropDown = <RowType extends GridBaseRow>(props: GridFormPop
|
|
|
247
247
|
data-testid={"filteredMenu-free-text-input"}
|
|
248
248
|
defaultValue={filter}
|
|
249
249
|
data-disableenterautosave={true}
|
|
250
|
-
data-
|
|
250
|
+
data-allowtabtosave={true}
|
|
251
251
|
onChange={(e) => setFilter(e.target.value)}
|
|
252
252
|
onKeyDown={handleKeyDown}
|
|
253
253
|
onKeyUp={handleKeyUp}
|
|
@@ -250,7 +250,7 @@ const FilterInput = (props: {
|
|
|
250
250
|
data-testid={"filteredMenu-free-text-input"}
|
|
251
251
|
value={filter}
|
|
252
252
|
data-disableenterautosave={true}
|
|
253
|
-
data-
|
|
253
|
+
data-allowtabtosave={true}
|
|
254
254
|
onChange={(e) => setFilter(e.target.value)}
|
|
255
255
|
onKeyUp={handleKeyUp}
|
|
256
256
|
/>
|
package/src/index.ts
CHANGED
|
@@ -138,7 +138,7 @@ export const ControlledMenuFr = (
|
|
|
138
138
|
|
|
139
139
|
const isTextArea = activeElement.nodeName === "TEXTAREA";
|
|
140
140
|
const suppressEnterAutoSave = activeElement.getAttribute("data-disableenterautosave") || isTextArea;
|
|
141
|
-
const allowTabToSave = activeElement.getAttribute("data-
|
|
141
|
+
const allowTabToSave = activeElement.getAttribute("data-allowtabtosave");
|
|
142
142
|
const invokeSave = (reason: string) => {
|
|
143
143
|
if (!saveButtonRef?.current) return;
|
|
144
144
|
saveButtonRef.current?.setAttribute("data-reason", reason);
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* General query all by selected. Internal use, use quick operations instead.
|
|
3
|
+
*
|
|
4
|
+
* @param selector Selector to use
|
|
5
|
+
* @param container Optional container
|
|
6
|
+
* @return HTMLElement array
|
|
7
|
+
*/
|
|
8
|
+
import { IconName } from "@linzjs/lui/dist/components/LuiIcon/LuiIcon";
|
|
9
|
+
import { wait } from "./util";
|
|
10
|
+
|
|
11
|
+
const queryAllBySelector = <T extends HTMLElement>(selector: string, container: HTMLElement = document.body): T[] =>
|
|
12
|
+
Array.from(container.querySelectorAll<T>(selector));
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Filters for query quick operations.
|
|
16
|
+
*/
|
|
17
|
+
export interface IQueryQuick {
|
|
18
|
+
testId?: string;
|
|
19
|
+
tagName?: "button" | "span" | "div" | "input" | "textarea" | any;
|
|
20
|
+
textEquals?: string;
|
|
21
|
+
textContains?: string;
|
|
22
|
+
icon?: IconName;
|
|
23
|
+
ariaLabel?: string;
|
|
24
|
+
role?: string;
|
|
25
|
+
classes?: string;
|
|
26
|
+
child?: IQueryQuick;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
const escapeSelectorParam = (param: string): string => param.replace(/["\\]/g, "\\$&");
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Build selector for quick operations.
|
|
33
|
+
*
|
|
34
|
+
* @param props Filters to convert to selector.
|
|
35
|
+
* @param container Optional container to search in.
|
|
36
|
+
*/
|
|
37
|
+
const quickSelector = <T extends HTMLElement>(
|
|
38
|
+
props: IQueryQuick,
|
|
39
|
+
container?: HTMLElement,
|
|
40
|
+
): { selector: string; els: T[] } => {
|
|
41
|
+
let selector = "";
|
|
42
|
+
let lastIQueryQuick = props;
|
|
43
|
+
for (let loop: IQueryQuick | undefined = props; loop; loop = loop.child) {
|
|
44
|
+
lastIQueryQuick = loop;
|
|
45
|
+
loop.tagName && (selector += loop.tagName);
|
|
46
|
+
loop.ariaLabel && (selector += `[aria-label='${escapeSelectorParam(loop.ariaLabel)}']`);
|
|
47
|
+
loop.role && (selector += `[role="${escapeSelectorParam(loop.role)}"]`);
|
|
48
|
+
loop.testId && (selector += `[data-testid="${escapeSelectorParam(loop.testId)}"]`);
|
|
49
|
+
loop.icon && (selector += `[data-icon='${loop.icon}']`);
|
|
50
|
+
loop.classes && (selector += loop.classes);
|
|
51
|
+
selector += " ";
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
if (selector.trim() == "") {
|
|
55
|
+
throw "get/query/findQuick needs at least one defined parameter";
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
let els = queryAllBySelector<T>(selector, container);
|
|
59
|
+
|
|
60
|
+
const textMatch = lastIQueryQuick.textEquals?.toLowerCase();
|
|
61
|
+
if (textMatch != null) {
|
|
62
|
+
els = els.filter((el) => el.innerHTML.toLowerCase() === textMatch || el.innerText.toLowerCase() === textMatch);
|
|
63
|
+
}
|
|
64
|
+
const textContains = lastIQueryQuick.textContains?.toLowerCase();
|
|
65
|
+
if (textContains != null) {
|
|
66
|
+
els = els.filter(
|
|
67
|
+
(el) =>
|
|
68
|
+
el.innerHTML.toLowerCase().indexOf(textContains) != -1 ||
|
|
69
|
+
el.innerText.toLowerCase().indexOf(textContains) != -1,
|
|
70
|
+
);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
return { selector, els };
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* Query by filter.
|
|
78
|
+
*
|
|
79
|
+
* @param filter Filter
|
|
80
|
+
* @param container Optional container to look in
|
|
81
|
+
* @return HTMLElement if found else null
|
|
82
|
+
*/
|
|
83
|
+
export const queryQuick = <T extends HTMLElement>(filter: IQueryQuick, container?: HTMLElement): T | null => {
|
|
84
|
+
const { els, selector } = quickSelector<T>(filter, container);
|
|
85
|
+
if (els.length > 1) {
|
|
86
|
+
throw `Found multiple(${els.length}) elements by selector ${selector}`;
|
|
87
|
+
}
|
|
88
|
+
return els[0] ?? null;
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* Query all by filter.
|
|
93
|
+
*
|
|
94
|
+
* @param filter Filter
|
|
95
|
+
* @param container Optional container to look in
|
|
96
|
+
* @return HTMLElement array
|
|
97
|
+
*/
|
|
98
|
+
export const queryAllQuick = <T extends HTMLElement>(filter: IQueryQuick, container?: HTMLElement): T[] =>
|
|
99
|
+
quickSelector<T>(filter, container)?.els;
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* Get all by filter.
|
|
103
|
+
*
|
|
104
|
+
* @param filter Filter
|
|
105
|
+
* @param container Optional container to look in
|
|
106
|
+
* @return HTMLElement array. Throws exception if nothing is found.
|
|
107
|
+
*/
|
|
108
|
+
export const getAllQuick = <T extends HTMLElement>(filter: IQueryQuick, container?: HTMLElement): T[] => {
|
|
109
|
+
const els = queryAllQuick(filter, container);
|
|
110
|
+
if (els.length == 0) {
|
|
111
|
+
throw Error(`getAllQuick not found, selector: ${quickSelector(filter)}`);
|
|
112
|
+
}
|
|
113
|
+
return els as T[];
|
|
114
|
+
};
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* Get by filter.
|
|
118
|
+
*
|
|
119
|
+
* @param filter Filter
|
|
120
|
+
* @param container Optional container to look in
|
|
121
|
+
* @return HTMLElement. Throws exception if not found.
|
|
122
|
+
*/
|
|
123
|
+
export const getQuick = (filter: IQueryQuick, container?: HTMLElement): HTMLElement => {
|
|
124
|
+
const el = queryQuick(filter, container);
|
|
125
|
+
if (el == null) {
|
|
126
|
+
throw Error(`getQuick not found, selector: ${quickSelector(filter).selector}`);
|
|
127
|
+
}
|
|
128
|
+
return el;
|
|
129
|
+
};
|
|
130
|
+
|
|
131
|
+
/**
|
|
132
|
+
* Find by filter. Waits up to 4 seconds to find filter.
|
|
133
|
+
*
|
|
134
|
+
* @param filter Filter
|
|
135
|
+
* @param container Optional container to look in
|
|
136
|
+
* @return HTMLElement. Throws exception if not found.
|
|
137
|
+
*/
|
|
138
|
+
export const findQuick = async <T extends HTMLElement>(filter: IQueryQuick, container?: HTMLElement): Promise<T> => {
|
|
139
|
+
const endTime = Date.now() + 4000;
|
|
140
|
+
while (Date.now() < endTime) {
|
|
141
|
+
const el = queryQuick<T>(filter, container);
|
|
142
|
+
if (el) return el;
|
|
143
|
+
await wait(50);
|
|
144
|
+
}
|
|
145
|
+
throw Error(`findQuick not found, selector: ${quickSelector(filter).selector}`);
|
|
146
|
+
};
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
import { act, within } from "@testing-library/react";
|
|
2
|
+
import userEvent from "@testing-library/user-event";
|
|
3
|
+
import { findQuick, getAllQuick, getQuick, queryQuick } from "./testQuick";
|
|
4
|
+
|
|
5
|
+
export const findRow = async (rowId: number | string, within?: HTMLElement): Promise<HTMLDivElement> => {
|
|
6
|
+
return findQuick<HTMLDivElement>({ tagName: `div[row-id='${rowId}']:not(:empty)` }, within);
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
export const queryRow = async (rowId: number | string, within?: HTMLElement): Promise<HTMLDivElement | null> => {
|
|
10
|
+
return queryQuick<HTMLDivElement>({ tagName: `div[row-id='${rowId}']:not(:empty)` }, within);
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
const _selectRow = async (
|
|
14
|
+
select: "select" | "deselect" | "toggle",
|
|
15
|
+
rowId: string | number,
|
|
16
|
+
within?: HTMLElement,
|
|
17
|
+
): Promise<void> => {
|
|
18
|
+
await act(async () => {
|
|
19
|
+
const row = await findRow(rowId, within);
|
|
20
|
+
const isSelected = !row.className.includes("ag-row-selected");
|
|
21
|
+
if (select === "toggle" || (select === "select" && !isSelected) || (select === "deselect" && isSelected)) {
|
|
22
|
+
userEvent.click(row);
|
|
23
|
+
}
|
|
24
|
+
});
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
export const selectRow = async (rowId: string | number, within?: HTMLElement): Promise<void> =>
|
|
28
|
+
_selectRow("select", rowId, within);
|
|
29
|
+
|
|
30
|
+
export const deselectRow = async (rowId: string | number, within?: HTMLElement): Promise<void> =>
|
|
31
|
+
_selectRow("deselect", rowId, within);
|
|
32
|
+
|
|
33
|
+
export const findCell = async (rowId: number | string, colId: string, within?: HTMLElement): Promise<HTMLElement> => {
|
|
34
|
+
const row = await findRow(rowId, within);
|
|
35
|
+
return await findQuick({ tagName: `[col-id='${colId}']` }, row);
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
export const selectCell = async (rowId: string | number, colId: string, within?: HTMLElement): Promise<void> => {
|
|
39
|
+
await act(async () => {
|
|
40
|
+
const cell = await findCell(rowId, colId, within);
|
|
41
|
+
userEvent.click(cell);
|
|
42
|
+
});
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
export const editCell = async (rowId: number | string, colId: string, within?: HTMLElement): Promise<void> => {
|
|
46
|
+
await act(async () => {
|
|
47
|
+
const cell = await findCell(rowId, colId, within);
|
|
48
|
+
userEvent.dblClick(cell);
|
|
49
|
+
await findOpenMenu();
|
|
50
|
+
});
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
const findOpenMenu = async (): Promise<HTMLElement> => findQuick({ classes: ".szh-menu--state-open" });
|
|
54
|
+
|
|
55
|
+
export const queryMenuOption = async (menuOptionText: string): Promise<HTMLElement | null> => {
|
|
56
|
+
const openMenu = await findOpenMenu();
|
|
57
|
+
const els = await within(openMenu).findAllByRole("menuitem");
|
|
58
|
+
const result = els.find(
|
|
59
|
+
(e: HTMLElement) => e.innerHTML?.trim() === menuOptionText || e.innerText?.trim() === menuOptionText,
|
|
60
|
+
);
|
|
61
|
+
return result ?? null;
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
export const findMenuOption = async (menuOptionText: string): Promise<HTMLElement> => {
|
|
65
|
+
const menuOption = await queryMenuOption(menuOptionText);
|
|
66
|
+
if (menuOption == null) {
|
|
67
|
+
throw Error(`Unable to find menu option ${menuOptionText}`);
|
|
68
|
+
}
|
|
69
|
+
return menuOption;
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
export const clickMenuOption = async (menuOptionText: string): Promise<void> => {
|
|
73
|
+
await act(async () => {
|
|
74
|
+
const menuOption = await findMenuOption(menuOptionText);
|
|
75
|
+
menuOption && userEvent.click(menuOption);
|
|
76
|
+
});
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
export const openAndClickMenuOption = async (
|
|
80
|
+
rowId: number | string,
|
|
81
|
+
colId: string,
|
|
82
|
+
menuOptionText: string,
|
|
83
|
+
within?: HTMLElement,
|
|
84
|
+
): Promise<void> => {
|
|
85
|
+
await editCell(rowId, colId, within);
|
|
86
|
+
await clickMenuOption(menuOptionText);
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
export const getMultiSelectOptions = async () => {
|
|
90
|
+
const openMenu = await findOpenMenu();
|
|
91
|
+
return getAllQuick<HTMLInputElement>({ role: "menuitem", child: { tagName: "input,textarea" } }, openMenu).map(
|
|
92
|
+
(input) => {
|
|
93
|
+
return {
|
|
94
|
+
v: input.value,
|
|
95
|
+
c: input.checked ?? true,
|
|
96
|
+
};
|
|
97
|
+
},
|
|
98
|
+
);
|
|
99
|
+
};
|
|
100
|
+
|
|
101
|
+
export const findMultiSelectOption = async (value: string): Promise<HTMLElement> => {
|
|
102
|
+
const openMenu = await findOpenMenu();
|
|
103
|
+
return getQuick({ role: "menuitem", child: { tagName: `input[value='${value}']` } }, openMenu);
|
|
104
|
+
};
|
|
105
|
+
|
|
106
|
+
export const clickMultiSelectOption = async (value: string): Promise<void> => {
|
|
107
|
+
const menuItem = await findMultiSelectOption(value);
|
|
108
|
+
menuItem.parentElement && userEvent.click(menuItem.parentElement);
|
|
109
|
+
};
|
|
110
|
+
|
|
111
|
+
export const typeOtherInput = async (value: string): Promise<void> => {
|
|
112
|
+
const openMenu = await findOpenMenu();
|
|
113
|
+
const otherInput = await findQuick({ tagName: "input[type='text']" }, openMenu);
|
|
114
|
+
userEvent.type(otherInput, value);
|
|
115
|
+
};
|
|
116
|
+
|
|
117
|
+
export const typeOtherTextArea = async (value: string): Promise<void> => {
|
|
118
|
+
const openMenu = await findOpenMenu();
|
|
119
|
+
const otherTextArea = await findQuick({ tagName: "textarea" }, openMenu);
|
|
120
|
+
userEvent.type(otherTextArea, value);
|
|
121
|
+
};
|
|
122
|
+
|
|
123
|
+
export const closeMenu = (): void => {
|
|
124
|
+
userEvent.click(document.body);
|
|
125
|
+
};
|
|
126
|
+
|
|
127
|
+
export const findActionButton = (text: string, container: HTMLElement): Promise<HTMLElement> =>
|
|
128
|
+
findQuick({ tagName: "button", child: { classes: ".ActionButton-minimalAreaDisplay", textEquals: text } }, container);
|
|
129
|
+
|
|
130
|
+
export const clickActionButton = async (text: string, container: HTMLElement): Promise<void> => {
|
|
131
|
+
await act(async () => {
|
|
132
|
+
const button = await findActionButton(text, container);
|
|
133
|
+
userEvent.click(button);
|
|
134
|
+
});
|
|
135
|
+
};
|