@linzjs/step-ag-grid 33.0.0 → 34.0.1

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.
@@ -49,7 +49,9 @@ const GridInlineTextTemplate: StoryFn<typeof Grid<IFormTestRow>> = (props: GridP
49
49
  editorParams: {
50
50
  placeholder: 'Enter some text...',
51
51
  onSave: ({ selectedRowIds, value }) => {
52
- setRowData(rowData.map((data) => (selectedRowIds.includes(data.id) ? { ...data, text1: value } : data)));
52
+ setRowData((current) =>
53
+ current.map((data) => (selectedRowIds.includes(data.id) ? { ...data, text1: value } : data)),
54
+ );
53
55
  return true;
54
56
  },
55
57
  },
@@ -70,14 +72,16 @@ const GridInlineTextTemplate: StoryFn<typeof Grid<IFormTestRow>> = (props: GridP
70
72
  return null;
71
73
  },
72
74
  onSave: ({ selectedRowIds, value }) => {
73
- setRowData(rowData.map((data) => (selectedRowIds.includes(data.id) ? { ...data, text2: value } : data)));
75
+ setRowData((current) =>
76
+ current.map((data) => (selectedRowIds.includes(data.id) ? { ...data, text2: value } : data)),
77
+ );
74
78
  return true;
75
79
  },
76
80
  },
77
81
  },
78
82
  ),
79
83
  GridPopoverMenu(
80
- {},
84
+ { colId: 'menu' },
81
85
  {
82
86
  multiEdit: true,
83
87
  editorParams: {
@@ -102,25 +106,27 @@ const GridInlineTextTemplate: StoryFn<typeof Grid<IFormTestRow>> = (props: GridP
102
106
  },
103
107
  ),
104
108
  ],
105
- [rowData],
109
+ [],
106
110
  );
107
111
 
108
112
  const addRowAction = useCallback(async () => {
109
113
  await wait(1000);
110
114
 
111
- const lastRow = rowData[rowData.length - 1];
112
115
  // eslint-disable-next-line @typescript-eslint/require-await
113
116
  await selectRowsWithFlashDiff(async () => {
114
- setRowData([
115
- ...rowData,
116
- {
117
- id: (lastRow?.id ?? 0) + 1,
118
- text1: '?',
119
- text2: '?',
120
- },
121
- ]);
117
+ setRowData((current) => {
118
+ const lastRow = current[current.length - 1];
119
+ return [
120
+ ...current,
121
+ {
122
+ id: (lastRow?.id ?? 0) + 1,
123
+ text1: '?',
124
+ text2: '?',
125
+ },
126
+ ];
127
+ });
122
128
  });
123
- }, [rowData, selectRowsWithFlashDiff]);
129
+ }, [selectRowsWithFlashDiff]);
124
130
 
125
131
  return (
126
132
  <>
@@ -1,13 +1,16 @@
1
1
  import { Meta, StoryFn, StoryObj } from '@storybook/react-vite';
2
- import { useMemo, useState } from 'react';
3
- import { expect } from 'storybook/test';
2
+ import { useCallback, useMemo, useState } from 'react';
3
+ import { expect, userEvent, within } from 'storybook/test';
4
4
 
5
5
  import {
6
+ ActionButton,
6
7
  ColDefT,
7
8
  compareNaturalInsensitive,
8
9
  Grid,
9
10
  GridCell,
10
11
  GridContextProvider,
12
+ GridInlineTextInput,
13
+ GridPopoverTextInput,
11
14
  GridProps,
12
15
  GridUpdatingContextProvider,
13
16
  GridWrapper,
@@ -94,7 +97,7 @@ const GridReadOnlyTemplate: StoryFn<typeof Grid<ITestRow>> = (props: GridProps<I
94
97
  };
95
98
 
96
99
  const meta: Meta<typeof GridReadOnlyTemplate> = {
97
- title: 'Components / Grids',
100
+ title: 'Components / Grid Sorting',
98
101
  component: GridReadOnlyTemplate,
99
102
  args: {
100
103
  selectable: false,
@@ -180,3 +183,410 @@ export const Sorting: Story = {
180
183
  await test('customComparatorNumeric', ['21', '11', '3', '3', '2.21', '2.1', '2.01', '1', '-1.1', '–']);
181
184
  },
182
185
  };
186
+
187
+ // PostSortRowsHook retains the previously displayed row order after an edit or a row deletion, rather than
188
+ // immediately re-sorting - the grid is only re-sorted once the user re-triggers a sort on the stale column.
189
+ // 'numeric' is edited through a real inline editor (GridInlineTextInput) and 'priority' through a real popup
190
+ // editor (GridPopoverTextInput) - both drive the same rowData-diff path PostSortRowsHook reacts to, but only
191
+ // exercising it through the actual editing UI (rather than calling setRowData directly) also exercises
192
+ // GridContextProvider's save flow (updatingCells/refreshClientSideRowModel) that the hook has to cope with.
193
+ interface ICategory {
194
+ label: string;
195
+ order: number;
196
+ }
197
+
198
+ interface ISortRetentionRow {
199
+ id: number;
200
+ numeric?: number;
201
+ priority?: number;
202
+ // Object-valued column, sorted via a custom comparator rather than a plain field value - exercises
203
+ // PostSortRowsHook's stale-detection against a real AgGrid instance (not just a mocked api in unit
204
+ // tests), since a naive `===`/JSON comparison would see a brand-new object on every render.
205
+ category?: ICategory;
206
+ }
207
+
208
+ const sortRetentionInitialRows: ISortRetentionRow[] = [
209
+ { id: 3001, numeric: 30, priority: 3, category: { label: 'Red', order: 3 } },
210
+ { id: 3002, numeric: 10, priority: 5, category: { label: 'Blue', order: 5 } },
211
+ { id: 3003, numeric: 50, priority: 1, category: { label: 'Green', order: 1 } },
212
+ { id: 3004, numeric: 20, priority: 4, category: { label: 'Yellow', order: 4 } },
213
+ { id: 3005, numeric: 40, priority: 2, category: { label: 'Purple', order: 2 } },
214
+ ];
215
+
216
+ const GridSortRetentionTemplate: StoryFn<typeof Grid<ISortRetentionRow>> = (props: GridProps<ISortRetentionRow>) => {
217
+ const [rowData, setRowData] = useState<ISortRetentionRow[]>(sortRetentionInitialRows);
218
+
219
+ const saveNumeric = useCallback(
220
+ ({ selectedRowIds, value }: { selectedRowIds: ISortRetentionRow['id'][]; value: string }) => {
221
+ const numeric = Number(value);
222
+ if (Number.isNaN(numeric)) return false;
223
+ setRowData((current) => current.map((row) => (selectedRowIds.includes(row.id) ? { ...row, numeric } : row)));
224
+ return true;
225
+ },
226
+ [],
227
+ );
228
+
229
+ const savePriority = useCallback(({ selectedRows, value }: { selectedRows: ISortRetentionRow[]; value: string }) => {
230
+ const priority = Number(value);
231
+ if (Number.isNaN(priority)) return false;
232
+ const ids = selectedRows.map((row) => row.id);
233
+ setRowData((current) => current.map((row) => (ids.includes(row.id) ? { ...row, priority } : row)));
234
+ return true;
235
+ }, []);
236
+
237
+ const columnDefs: ColDefT<ISortRetentionRow>[] = useMemo(
238
+ () => [
239
+ GridCell({ field: 'id', headerName: 'Id', lockVisible: true }),
240
+ GridInlineTextInput(
241
+ { field: 'numeric', headerName: 'Numeric (inline edit)' },
242
+ { editorParams: { placeholder: 'Enter numeric...', onSave: saveNumeric } },
243
+ ),
244
+ GridPopoverTextInput(
245
+ { field: 'priority', headerName: 'Priority (popup edit)' },
246
+ { editorParams: { placeholder: 'Enter priority...', onSave: savePriority } },
247
+ ),
248
+ GridCell({
249
+ colId: 'category',
250
+ headerName: 'Category (object, custom comparator)',
251
+ valueGetter: ({ data }) => data?.category,
252
+ valueFormatter: ({ value }: { value?: ICategory | null }) => (value ? `${value.label} (${value.order})` : ''),
253
+ comparator: (a?: ICategory | null, b?: ICategory | null) => (a?.order ?? 0) - (b?.order ?? 0),
254
+ }),
255
+ ],
256
+ [saveNumeric, savePriority],
257
+ );
258
+
259
+ const deleteRow = useCallback(
260
+ (id: number) => () => setRowData((current) => current.filter((row) => row.id !== id)),
261
+ [],
262
+ );
263
+
264
+ // Simulates two rows' values changing in a single rowData update (e.g. a drag-reorder or a bulk-edit of two
265
+ // rows at once) - PostSortRowsHook treats this as an ambiguous "swap" rather than a retainable single edit.
266
+ const swapRows = useCallback(
267
+ (id1: number, id2: number) => () =>
268
+ setRowData((current) => {
269
+ const row1 = current.find((row) => row.id === id1);
270
+ const row2 = current.find((row) => row.id === id2);
271
+ if (!row1 || !row2) return current;
272
+ return current.map((row) => {
273
+ if (row.id === id1) return { ...row, numeric: row2.numeric };
274
+ if (row.id === id2) return { ...row, numeric: row1.numeric };
275
+ return row;
276
+ });
277
+ }),
278
+ [],
279
+ );
280
+
281
+ const addRow = useCallback(
282
+ (id: number, numeric: number, priority: number) => () =>
283
+ setRowData((current) => [...current, { id, numeric, priority }]),
284
+ [],
285
+ );
286
+
287
+ // Assigns a brand-new category object with the same `order` - a naive `===`/JSON comparison would see
288
+ // this as a change (new object reference), but the column's comparator says the row hasn't moved.
289
+ const relabelCategory = useCallback(
290
+ (id: number, label: string) => () =>
291
+ setRowData((current) =>
292
+ current.map((row) =>
293
+ row.id === id && row.category ? { ...row, category: { ...row.category, label } } : row,
294
+ ),
295
+ ),
296
+ [],
297
+ );
298
+
299
+ // Assigns a new `order` - a genuine change per the comparator, so the row's rank actually changes.
300
+ const reorderCategory = useCallback(
301
+ (id: number, order: number) => () =>
302
+ setRowData((current) =>
303
+ current.map((row) => (row.id === id ? { ...row, category: { label: row.category?.label ?? '', order } } : row)),
304
+ ),
305
+ [],
306
+ );
307
+
308
+ return (
309
+ <>
310
+ <Grid
311
+ data-testid={'sortRetention'}
312
+ {...props}
313
+ columnDefs={columnDefs}
314
+ rowData={rowData}
315
+ domLayout={'autoHeight'}
316
+ singleClickEdit={true}
317
+ selectable={true}
318
+ />
319
+ <div style={{ display: 'flex', flexWrap: 'wrap', gap: 8, marginTop: 8 }}>
320
+ <ActionButton
321
+ dataTestId={'delete-row-3004'}
322
+ icon={'ic_delete_outline'}
323
+ name={'Delete row 3004'}
324
+ onClick={deleteRow(3004)}
325
+ />
326
+ <ActionButton
327
+ dataTestId={'swap-rows-3004-3001'}
328
+ icon={'ic_swap_vertical'}
329
+ name={'Swap rows 3004 and 3001'}
330
+ onClick={swapRows(3004, 3001)}
331
+ />
332
+ <ActionButton
333
+ dataTestId={'add-row-3006'}
334
+ icon={'ic_add'}
335
+ name={'Add row 3006'}
336
+ onClick={addRow(3006, 25, 3.5)}
337
+ />
338
+ <ActionButton
339
+ dataTestId={'relabel-category-3002'}
340
+ icon={'ic_refresh'}
341
+ name={"Relabel row 3002's category (same order)"}
342
+ onClick={relabelCategory(3002, 'Cyan')}
343
+ />
344
+ <ActionButton
345
+ dataTestId={'reorder-category-3003'}
346
+ icon={'ic_refresh'}
347
+ name={"Reorder row 3003's category to last"}
348
+ onClick={reorderCategory(3003, 99)}
349
+ />
350
+ </div>
351
+ </>
352
+ );
353
+ };
354
+
355
+ const findRowCell = (rowId: number, colId: string, canvasElement: HTMLElement): HTMLElement => {
356
+ const idCells = Array.from(canvasElement.querySelectorAll<HTMLElement>('[col-id="id"].ag-cell'));
357
+ const idCell = idCells.find((el) => el.textContent === String(rowId));
358
+ if (!idCell) throw new Error(`Row ${rowId} not found`);
359
+ const row = idCell.closest('.ag-row');
360
+ const cell = row?.querySelector<HTMLElement>(`[col-id="${colId}"].ag-cell`);
361
+ if (!cell) throw new Error(`Cell col=${colId} not found for row ${rowId}`);
362
+ return cell;
363
+ };
364
+
365
+ // Drives the real editing UI (a single click starts editing - singleClickEdit is set on the grid) rather than
366
+ // calling setRowData directly, so the save flows through GridContextProvider's updatingCells/
367
+ // refreshClientSideRowModel just like a real user edit would - both the inline editor (numeric) and the popup
368
+ // editor (priority) go through this same helper.
369
+ const editViaCell = async (
370
+ rowId: number,
371
+ colId: string,
372
+ value: string,
373
+ placeholder: string,
374
+ canvasElement: HTMLElement,
375
+ ) => {
376
+ const cell = findRowCell(rowId, colId, canvasElement);
377
+ await userEvent.click(cell);
378
+ const input = await within(canvasElement.ownerDocument.body).findByPlaceholderText(placeholder);
379
+ // The popup editor mounts its input asynchronously (GridPopoverHook opens on a post-mount effect), so it can
380
+ // exist in the DOM slightly before it's actually focusable - click it directly first rather than relying on
381
+ // clear() to focus it, which can otherwise race and throw "The element to be cleared could not be focused."
382
+ await userEvent.click(input);
383
+ await userEvent.clear(input);
384
+ await userEvent.type(input, value);
385
+ await userEvent.keyboard('{Enter}');
386
+ // The editor's save-on-Enter doesn't always finish closing itself in this test environment (the input can stay
387
+ // mounted/focused) - clicking the row's id cell forces a blur, which reliably completes it before we continue.
388
+ await userEvent.click(findRowCell(rowId, 'id', canvasElement));
389
+ };
390
+
391
+ const editNumericInline = (rowId: number, value: string, canvasElement: HTMLElement) =>
392
+ editViaCell(rowId, 'numeric', value, 'Enter numeric...', canvasElement);
393
+
394
+ const editPriorityPopup = (rowId: number, value: string, canvasElement: HTMLElement) =>
395
+ editViaCell(rowId, 'priority', value, 'Enter priority...', canvasElement);
396
+
397
+ export const Sorting_RetainsOrderAfterEdit: Story = {
398
+ render: GridSortRetentionTemplate,
399
+ play: async ({ canvasElement }) => {
400
+ await waitForGridReady({ canvasElement });
401
+ await waitForGridRows({ grid: canvasElement });
402
+
403
+ await clickColumnHeaderToSort('numeric', canvasElement);
404
+ await wait(500);
405
+ await expect(gridColumnValues('id', canvasElement)).toEqual(['3002', '3004', '3001', '3005', '3003']);
406
+
407
+ // Editing row 3002's value to the largest in the set, through the real inline editor (GridInlineTextInput),
408
+ // must NOT immediately re-sort it to the end - the hook retains the existing display order until the user
409
+ // re-triggers the sort, and flags the sort as stale.
410
+ await editNumericInline(3002, '999', canvasElement);
411
+ await wait(300);
412
+ await expect(gridColumnValues('id', canvasElement)).toEqual(['3002', '3004', '3001', '3005', '3003']);
413
+ await expect(canvasElement.querySelector('.Grid-sortIsStale')).toBeInTheDocument();
414
+
415
+ // Clicking the now-stale sort column re-triggers a real sort and clears the stale indicator. It must also
416
+ // actually move the rows to their genuinely-sorted position (3002 is now the largest value, so it must end
417
+ // up last) - not just clear the flag while leaving the retained (now-wrong) order on screen. Regression check:
418
+ // the restore used to call applyColumnState() synchronously from inside AgGrid's own sort pass, where it was
419
+ // a no-op, clearing the flag without ever triggering the follow-up resort.
420
+ await clickColumnHeaderToSort('numeric', canvasElement);
421
+ await wait(500);
422
+ await expect(canvasElement.querySelector('.Grid-sortIsStale')).not.toBeInTheDocument();
423
+ await expect(gridColumnValues('id', canvasElement)).toEqual(['3004', '3001', '3005', '3003', '3002']);
424
+ },
425
+ };
426
+
427
+ export const Sorting_RetainsOrderAfterPopupEdit: Story = {
428
+ render: GridSortRetentionTemplate,
429
+ play: async ({ canvasElement }) => {
430
+ await waitForGridReady({ canvasElement });
431
+ await waitForGridRows({ grid: canvasElement });
432
+
433
+ // Same scenario as Sorting_RetainsOrderAfterEdit, but sorted by and edited through 'priority' - a real popup
434
+ // editor (GridPopoverTextInput) rather than an inline one. The popup editor's save flows through the same
435
+ // GridContextProvider.updatingCells path, but via a floating popover instead of an in-cell input, and is
436
+ // worth covering independently in case that UI difference ever affects the save/refresh timing.
437
+ await clickColumnHeaderToSort('priority', canvasElement);
438
+ await wait(500);
439
+ await expect(gridColumnValues('id', canvasElement)).toEqual(['3003', '3005', '3001', '3004', '3002']);
440
+
441
+ await editPriorityPopup(3003, '99', canvasElement);
442
+ await wait(300);
443
+ await expect(gridColumnValues('id', canvasElement)).toEqual(['3003', '3005', '3001', '3004', '3002']);
444
+ await expect(canvasElement.querySelector('.Grid-sortIsStale')).toBeInTheDocument();
445
+
446
+ await clickColumnHeaderToSort('priority', canvasElement);
447
+ await wait(500);
448
+ await expect(canvasElement.querySelector('.Grid-sortIsStale')).not.toBeInTheDocument();
449
+ await expect(gridColumnValues('id', canvasElement)).toEqual(['3005', '3001', '3004', '3002', '3003']);
450
+ },
451
+ };
452
+
453
+ export const Sorting_RetainsOrderAcrossTwoEdits: Story = {
454
+ render: GridSortRetentionTemplate,
455
+ play: async ({ canvasElement }) => {
456
+ await waitForGridReady({ canvasElement });
457
+ await waitForGridRows({ grid: canvasElement });
458
+
459
+ await clickColumnHeaderToSort('numeric', canvasElement);
460
+ await wait(500);
461
+ await expect(gridColumnValues('id', canvasElement)).toEqual(['3002', '3004', '3001', '3005', '3003']);
462
+
463
+ // First edit: row 3002 becomes the largest value - order must retain, sort flagged stale.
464
+ await editNumericInline(3002, '999', canvasElement);
465
+ await wait(300);
466
+ await expect(gridColumnValues('id', canvasElement)).toEqual(['3002', '3004', '3001', '3005', '3003']);
467
+ await expect(canvasElement.querySelector('.Grid-sortIsStale')).toBeInTheDocument();
468
+
469
+ // Regression check: editing a second, DIFFERENT row must also retain the existing order and stay stale. The
470
+ // hook previously refreshed the first edited row's stored hash as part of retaining it, which made a later
471
+ // AgGrid-forced re-sort pass (unrelated to this second edit) think nothing had changed and silently accept
472
+ // AgGrid's freshly-recomputed (properly sorted, not retained) order without flagging staleness.
473
+ await editNumericInline(3004, '888', canvasElement);
474
+ await wait(300);
475
+ await expect(gridColumnValues('id', canvasElement)).toEqual(['3002', '3004', '3001', '3005', '3003']);
476
+ await expect(canvasElement.querySelector('.Grid-sortIsStale')).toBeInTheDocument();
477
+ },
478
+ };
479
+
480
+ export const Sorting_SwapDoesNotFlagStale: Story = {
481
+ render: GridSortRetentionTemplate,
482
+ play: async ({ canvas, canvasElement }) => {
483
+ await waitForGridReady({ canvasElement });
484
+ await waitForGridRows({ grid: canvasElement });
485
+
486
+ await clickColumnHeaderToSort('numeric', canvasElement);
487
+ await wait(500);
488
+ await expect(gridColumnValues('id', canvasElement)).toEqual(['3002', '3004', '3001', '3005', '3003']);
489
+
490
+ // Two rows' values changing in the same update (3004 and 3001 exchange numeric values) reads as an ambiguous
491
+ // swap rather than a retainable single-row edit - the hook treats it as the two rows having traded places
492
+ // (matching what a drag-reorder producing the same diff would mean) and does not flag it as stale.
493
+ const swapButton = await canvas.findByTestId('swap-rows-3004-3001');
494
+ await userEvent.click(swapButton);
495
+ await wait(300);
496
+ await expect(gridColumnValues('id', canvasElement)).toEqual(['3002', '3001', '3004', '3005', '3003']);
497
+ await expect(canvasElement.querySelector('.Grid-sortIsStale')).not.toBeInTheDocument();
498
+ },
499
+ };
500
+
501
+ export const Sorting_RetainsOrderWithNewRow: Story = {
502
+ render: GridSortRetentionTemplate,
503
+ play: async ({ canvas, canvasElement }) => {
504
+ await waitForGridReady({ canvasElement });
505
+ await waitForGridRows({ grid: canvasElement });
506
+
507
+ await clickColumnHeaderToSort('numeric', canvasElement);
508
+ await wait(500);
509
+ await expect(gridColumnValues('id', canvasElement)).toEqual(['3002', '3004', '3001', '3005', '3003']);
510
+
511
+ // A newly added row is appended at the end of the retained order rather than inserted at its sorted
512
+ // position, and flags the sort as stale.
513
+ const addButton = await canvas.findByTestId('add-row-3006');
514
+ await userEvent.click(addButton);
515
+ await wait(300);
516
+ await expect(gridColumnValues('id', canvasElement)).toEqual(['3002', '3004', '3001', '3005', '3003', '3006']);
517
+ await expect(canvasElement.querySelector('.Grid-sortIsStale')).toBeInTheDocument();
518
+
519
+ // Re-triggering the sort places it correctly (3006's value of 25 sorts between 3004's 20 and 3001's 30).
520
+ await clickColumnHeaderToSort('numeric', canvasElement);
521
+ await wait(500);
522
+ await expect(canvasElement.querySelector('.Grid-sortIsStale')).not.toBeInTheDocument();
523
+ await expect(gridColumnValues('id', canvasElement)).toEqual(['3002', '3004', '3006', '3001', '3005', '3003']);
524
+ },
525
+ };
526
+
527
+ export const Sorting_RetainsOrderAfterDeletion: Story = {
528
+ render: GridSortRetentionTemplate,
529
+ play: async ({ canvas, canvasElement }) => {
530
+ await waitForGridReady({ canvasElement });
531
+ await waitForGridRows({ grid: canvasElement });
532
+
533
+ await clickColumnHeaderToSort('numeric', canvasElement);
534
+ await wait(500);
535
+ await expect(gridColumnValues('id', canvasElement)).toEqual(['3002', '3004', '3001', '3005', '3003']);
536
+
537
+ // Deleting row 3004 with nothing else changing must retain the sorted order of the remaining rows, and must
538
+ // not itself be treated as making the sort stale.
539
+ const deleteButton = await canvas.findByTestId('delete-row-3004');
540
+ await userEvent.click(deleteButton);
541
+ await wait(300);
542
+ await expect(gridColumnValues('id', canvasElement)).toEqual(['3002', '3001', '3005', '3003']);
543
+ await expect(canvasElement.querySelector('.Grid-sortIsStale')).not.toBeInTheDocument();
544
+
545
+ // Regression check: an edit that doesn't change a row's rank must not be flagged as stale, even right after a
546
+ // deletion. Before the deletion path refreshed the hook's row-order bookkeeping, a stale id left behind by the
547
+ // deleted row corrupted this check and caused a false stale flag on the very next edit.
548
+ await editNumericInline(3005, '41', canvasElement);
549
+ await wait(300);
550
+ await expect(gridColumnValues('id', canvasElement)).toEqual(['3002', '3001', '3005', '3003']);
551
+ await expect(canvasElement.querySelector('.Grid-sortIsStale')).not.toBeInTheDocument();
552
+ },
553
+ };
554
+
555
+ // Unlike the other retention stories (plain numbers/strings), this sorts on an object-valued column via a
556
+ // custom `comparator` rather than `equals` - going through a real AgGrid instance rather than a mocked api,
557
+ // this is what actually exercises PostSortRowsHook's comparator-fallback path end to end.
558
+ export const Sorting_RetainsOrderWithObjectComparatorColumn: Story = {
559
+ render: GridSortRetentionTemplate,
560
+ play: async ({ canvas, canvasElement }) => {
561
+ await waitForGridReady({ canvasElement });
562
+ await waitForGridRows({ grid: canvasElement });
563
+
564
+ await clickColumnHeaderToSort('category', canvasElement);
565
+ await wait(500);
566
+ await expect(gridColumnValues('id', canvasElement)).toEqual(['3003', '3005', '3001', '3004', '3002']);
567
+
568
+ // Relabeling row 3002's category assigns a brand-new object with the same `order` - `===` (or a JSON
569
+ // comparison) would call this "changed", but the comparator says the row hasn't moved, so it must not
570
+ // flag the sort as stale.
571
+ const relabelButton = await canvas.findByTestId('relabel-category-3002');
572
+ await userEvent.click(relabelButton);
573
+ await wait(300);
574
+ await expect(gridColumnValues('id', canvasElement)).toEqual(['3003', '3005', '3001', '3004', '3002']);
575
+ await expect(canvasElement.querySelector('.Grid-sortIsStale')).not.toBeInTheDocument();
576
+
577
+ // Reordering row 3003's category to the highest value is a genuine change per the comparator - order
578
+ // must retain (3003 stays first) and the sort is flagged stale, exactly like the numeric/priority
579
+ // edits above.
580
+ const reorderButton = await canvas.findByTestId('reorder-category-3003');
581
+ await userEvent.click(reorderButton);
582
+ await wait(300);
583
+ await expect(gridColumnValues('id', canvasElement)).toEqual(['3003', '3005', '3001', '3004', '3002']);
584
+ await expect(canvasElement.querySelector('.Grid-sortIsStale')).toBeInTheDocument();
585
+
586
+ // Re-triggering the sort moves it to its genuinely-sorted position (order 99 sorts last).
587
+ await clickColumnHeaderToSort('category', canvasElement);
588
+ await wait(500);
589
+ await expect(canvasElement.querySelector('.Grid-sortIsStale')).not.toBeInTheDocument();
590
+ await expect(gridColumnValues('id', canvasElement)).toEqual(['3005', '3001', '3004', '3002', '3003']);
591
+ },
592
+ };
@@ -23,7 +23,7 @@ export const clickColumnHeaderToSort = async (colId: string, within: HTMLElement
23
23
  };
24
24
 
25
25
  export const getNumberOfGridRows = (props?: { grid?: HTMLElement }): number => {
26
- return queryAllQuick({ classes: '.ag-row' }, props?.grid).length;
26
+ return queryAllQuick({ classes: '.ag-center-cols-viewport .ag-row' }, props?.grid).length;
27
27
  };
28
28
 
29
29
  export const gridColumnValues = (colId: string, within: HTMLElement): string[] => {