Skip to content

Add and migrate all tests to use new locators#3954

Open
nstepien wants to merge 12 commits intomainfrom
new-locators
Open

Add and migrate all tests to use new locators#3954
nstepien wants to merge 12 commits intomainfrom
new-locators

Conversation

@nstepien
Copy link
Collaborator

Enjoy.
Might have other tweaks here and there.

@nstepien nstepien self-assigned this Feb 10, 2026
@codecov-commenter
Copy link

codecov-commenter commented Feb 11, 2026

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 97.61%. Comparing base (3c52d8f) to head (db99740).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3954      +/-   ##
==========================================
- Coverage   97.61%   97.61%   -0.01%     
==========================================
  Files          36       36              
  Lines        1470     1469       -1     
  Branches      477      480       +3     
==========================================
- Hits         1435     1434       -1     
  Misses         35       35              
Files with missing lines Coverage Δ
src/DataGrid.tsx 98.99% <100.00%> (+<0.01%) ⬆️
src/GroupedColumnHeaderRow.tsx 100.00% <100.00%> (ø)
src/ScrollToCell.tsx 100.00% <100.00%> (ø)
src/utils/selectedCellUtils.ts 98.96% <100.00%> (ø)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

const scrollToRowIdx =
rowIdx !== undefined && isRowIdxWithinViewportBounds(rowIdx) ? rowIdx : undefined;
rowIdx !== undefined && isRowIdxWithinViewportBounds(rowIdx)
? rowIdx + headerAndTopSummaryRowsCount
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like we forgot to take into account headerAndTopSummaryRowsCount here


const observer = new IntersectionObserver(removeScrollToCell, {
root: gridRef.current!,
threshold: 1.0
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This didn't work well when targeting a column/row only, as the target <div> would be taller/wider than the grid, so the intersection ratio would stay below 0.
In such cases, the <div> might not get removed, ScrollToCell would still render, and the useLayoutEffect above would keep running on re-renders.


useLayoutEffect(() => {
function removeScrollToCell() {
if (grid.scrollLeft === scrollLeft && grid.scrollTop === scrollTop) {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If scrolling is 'smooth', the scroll position won't immediately change, so this condition will be immediately true.
We can look into it further if it's causing issues.

await expect.element(cell1).toHaveTextContent('col1');
await expect.element(cell2).toHaveTextContent('col3');
await expect.element(cell3).toHaveTextContent('col2');
await expect.element(cell4).toHaveTextContent('col4');
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Better than testing the text content of the whole header row

function testSelection(rowIdx: number, isSelected: boolean) {
return expect
.element(getRowByText(rowIdx))
.element(rows.nth(rowIdx))
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not super safe if we start scrolling, as the row index may not match with the rendered rows because of virtualization, but it works in this test suite so 🤷‍♂️

'@typescript-eslint/parameter-properties': 1,
'@typescript-eslint/prefer-as-const': 1,
'@typescript-eslint/prefer-destructuring': [1, { array: false }],
'@typescript-eslint/prefer-destructuring': [1, { array: false, object: true }],
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know why, but it seems like we need to specify the default again if we only configure a subset of the options

cleanDir: true
},
platform: 'browser',
platform: 'neutral',
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To support both SSR and browser rendering.
No change in the build output though, but just to be safe.

"module": "NodeNext",
"moduleResolution": "NodeNext",
"skipLibCheck": true
"moduleResolution": "NodeNext"
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Restored alphabetical order

// TODO: remove when `userEvent.pointer` is supported
const resizeColumn: BrowserCommand<[name: string, resizeBy: number | readonly number[]]> = async (
context,
{ page, iframe },
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

https://vitest.dev/api/browser/commands.html#custom-playwright-commands

If you need to query an element, you should prefer using context.iframe instead because it is more stable and faster.

await page.mouse.up();
};

const scrollGrid: BrowserCommand<[{ scrollLeft?: number; scrollTop?: number }]> = async (
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed since the scrollGrid is enough.

@nstepien nstepien marked this pull request as ready for review February 11, 2026 14:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants