@linzjs/step-ag-grid 15.1.0 → 15.1.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/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@linzjs/step-ag-grid",
3
3
  "repository": "github:linz/step-ag-grid.git",
4
4
  "license": "MIT",
5
- "version": "15.1.0",
5
+ "version": "15.1.2",
6
6
  "keywords": [
7
7
  "aggrid",
8
8
  "ag-grid",
@@ -131,14 +131,14 @@ export const getQuick = (filter: IQueryQuick, container?: HTMLElement): HTMLElem
131
131
  };
132
132
 
133
133
  /**
134
- * Find by filter. Waits up to 4 seconds to find filter.
134
+ * Find by filter. Waits up to 5 seconds to find filter.
135
135
  *
136
136
  * @param filter Filter
137
137
  * @param container Optional container to look in
138
138
  * @return HTMLElement. Throws exception if not found.
139
139
  */
140
140
  export const findQuick = async <T extends HTMLElement>(filter: IQueryQuick, container?: HTMLElement): Promise<T> => {
141
- const endTime = Date.now() + 4000;
141
+ const endTime = Date.now() + 5000;
142
142
  while (Date.now() < endTime) {
143
143
  const el = queryQuick<T>(filter, container);
144
144
  if (el) return el;
@@ -1,20 +1,24 @@
1
- import { act, waitFor, within } from "@testing-library/react";
1
+ import { waitFor, within } from "@testing-library/react";
2
2
  import userEvent from "@testing-library/user-event";
3
3
  import { isEqual } from "lodash-es";
4
4
 
5
5
  import { IQueryQuick, findQuick, getAllQuick, getMatcher, getQuick, queryQuick } from "./testQuick";
6
6
 
7
+ let user = userEvent;
8
+ /**
9
+ * allow external userEvent to be used
10
+ * @param customisedUserEvent
11
+ */
12
+ export const setUpUserEvent = (customisedUserEvent: any) => {
13
+ user = customisedUserEvent;
14
+ };
15
+
7
16
  export const countRows = async (within?: HTMLElement): Promise<number> => {
8
17
  return getAllQuick({ tagName: `div[row-id]:not(:empty)` }, within).length;
9
18
  };
10
19
 
11
20
  export const findRow = async (rowId: number | string, within?: HTMLElement): Promise<HTMLDivElement> => {
12
- //if this is not wrapped in an act console errors are logged during testing
13
- let row!: HTMLDivElement;
14
- await act(async () => {
15
- row = await findQuick<HTMLDivElement>({ tagName: `div[row-id='${rowId}']:not(:empty)` }, within);
16
- });
17
- return row;
21
+ return await findQuick<HTMLDivElement>({ tagName: `div[row-id='${rowId}']:not(:empty)` }, within);
18
22
  };
19
23
 
20
24
  export const queryRow = async (rowId: number | string, within?: HTMLElement): Promise<HTMLDivElement | null> => {
@@ -26,19 +30,17 @@ const _selectRow = async (
26
30
  rowId: string | number,
27
31
  within?: HTMLElement,
28
32
  ): Promise<void> => {
29
- await act(async () => {
30
- const row = await findRow(rowId, within);
31
- const isSelected = row.className.includes("ag-row-selected");
32
- if (select === "toggle" || (select === "select" && !isSelected) || (select === "deselect" && isSelected)) {
33
- const cell = await findCell(rowId, "selection", within);
34
- await userEvent.click(cell);
35
- await waitFor(async () => {
36
- const row = await findRow(rowId, within);
37
- const nowSelected = row.className.includes("ag-row-selected");
38
- if (nowSelected == isSelected) throw `Row ${rowId} won't select`;
39
- });
40
- }
41
- });
33
+ const row = await findRow(rowId, within);
34
+ const isSelected = row.className.includes("ag-row-selected");
35
+ if (select === "toggle" || (select === "select" && !isSelected) || (select === "deselect" && isSelected)) {
36
+ const cell = await findCell(rowId, "selection", within);
37
+ await user.click(cell);
38
+ await waitFor(async () => {
39
+ const row = await findRow(rowId, within);
40
+ const nowSelected = row.className.includes("ag-row-selected");
41
+ if (nowSelected === isSelected) throw `Row ${rowId} won't select`;
42
+ });
43
+ }
42
44
  };
43
45
 
44
46
  export const selectRow = async (rowId: string | number, within?: HTMLElement): Promise<void> =>
@@ -48,13 +50,8 @@ export const deselectRow = async (rowId: string | number, within?: HTMLElement):
48
50
  _selectRow("deselect", rowId, within);
49
51
 
50
52
  export const findCell = async (rowId: number | string, colId: string, within?: HTMLElement): Promise<HTMLElement> => {
51
- //if this is not wrapped in an act console errors are logged during testing
52
- let cell!: HTMLElement;
53
- await act(async () => {
54
- const row = await findRow(rowId, within);
55
- cell = await findQuick({ tagName: `[col-id='${colId}']` }, row);
56
- });
57
- return cell;
53
+ const row = await findRow(rowId, within);
54
+ return await findQuick({ tagName: `[col-id='${colId}']` }, row);
58
55
  };
59
56
 
60
57
  export const findCellContains = async (
@@ -73,17 +70,13 @@ export const findCellContains = async (
73
70
  };
74
71
 
75
72
  export const selectCell = async (rowId: string | number, colId: string, within?: HTMLElement): Promise<void> => {
76
- await act(async () => {
77
- const cell = await findCell(rowId, colId, within);
78
- await userEvent.click(cell);
79
- });
73
+ const cell = await findCell(rowId, colId, within);
74
+ await user.click(cell);
80
75
  };
81
76
 
82
77
  export const editCell = async (rowId: number | string, colId: string, within?: HTMLElement): Promise<void> => {
83
- await act(async () => {
84
- const cell = await findCell(rowId, colId, within);
85
- await userEvent.dblClick(cell);
86
- });
78
+ const cell = await findCell(rowId, colId, within);
79
+ await user.dblClick(cell);
87
80
  await waitFor(findOpenPopover);
88
81
  };
89
82
 
@@ -127,10 +120,8 @@ export const validateMenuOptions = async (
127
120
  };
128
121
 
129
122
  export const clickMenuOption = async (menuOptionText: string | RegExp): Promise<void> => {
130
- await act(async () => {
131
- const menuOption = await findMenuOption(menuOptionText);
132
- await userEvent.click(menuOption);
133
- });
123
+ const menuOption = await findMenuOption(menuOptionText);
124
+ await user.click(menuOption);
134
125
  };
135
126
 
136
127
  export const openAndClickMenuOption = async (
@@ -172,26 +163,25 @@ export const findMultiSelectOption = async (value: string): Promise<HTMLElement>
172
163
 
173
164
  export const clickMultiSelectOption = async (value: string): Promise<void> => {
174
165
  const menuItem = await findMultiSelectOption(value);
175
- menuItem.parentElement && (await userEvent.click(menuItem.parentElement));
176
- };
177
-
178
- const typeInput = async (value: string, filter: IQueryQuick): Promise<void> =>
179
- act(async () => {
180
- const openMenu = await findOpenPopover();
181
- const input = await findQuick(filter, openMenu);
182
- await userEvent.clear(input);
183
- //'typing' an empty string will cause a console error, and it's also unnecessary after the previous clear call
184
- if (value.length > 0) {
185
- await userEvent.type(input, value);
186
- }
187
- });
166
+ menuItem.parentElement && (await user.click(menuItem.parentElement));
167
+ };
168
+
169
+ const typeInput = async (value: string, filter: IQueryQuick): Promise<void> => {
170
+ const openMenu = await findOpenPopover();
171
+ const input = await findQuick(filter, openMenu);
172
+ await user.clear(input);
173
+ //'typing' an empty string will cause a console error, and it's also unnecessary after the previous clear call
174
+ if (value.length > 0) {
175
+ await user.type(input, value);
176
+ }
177
+ };
188
178
 
189
179
  export const typeOnlyInput = async (value: string): Promise<void> =>
190
180
  typeInput(value, { child: { tagName: "input[type='text'], textarea" } });
191
181
 
192
182
  export const typeInputByLabel = async (value: string, labelText: string): Promise<void> => {
193
- const labels = getAllQuick({ child: { tagName: "label" } }).filter((l) => l.textContent == labelText);
194
- if (labels.length == 0) {
183
+ const labels = getAllQuick({ child: { tagName: "label" } }).filter((l) => l.textContent === labelText);
184
+ if (labels.length === 0) {
195
185
  throw Error(`Label not found for text: ${labelText}`);
196
186
  }
197
187
  if (labels.length > 1) {
@@ -212,15 +202,13 @@ export const typeOtherInput = async (value: string): Promise<void> =>
212
202
  export const typeOtherTextArea = async (value: string): Promise<void> =>
213
203
  typeInput(value, { classes: ".subComponent", child: { tagName: "textarea" } });
214
204
 
215
- export const closeMenu = () => userEvent.click(document.body);
216
- export const closePopover = () => userEvent.click(document.body);
205
+ export const closeMenu = () => user.click(document.body);
206
+ export const closePopover = () => user.click(document.body);
217
207
 
218
208
  export const findActionButton = (text: string, container?: HTMLElement): Promise<HTMLElement> =>
219
209
  findQuick({ tagName: "button", child: { classes: ".ActionButton-minimalAreaDisplay", text: text } }, container);
220
210
 
221
211
  export const clickActionButton = async (text: string, container?: HTMLElement): Promise<void> => {
222
- await act(async () => {
223
- const button = await findActionButton(text, container);
224
- await userEvent.click(button);
225
- });
212
+ const button = await findActionButton(text, container);
213
+ await user.click(button);
226
214
  };