How to select a grid row when testing with jest

1 Answer 354 Views
Grid
Ewald
Top achievements
Rank 1
Iron
Ewald asked on 01 Oct 2023, 10:46 PM

I have a simple kendo grid, where I set its selected field to true.

When I open the application in the browser, the 'aria-selected' is set to true. However, when I use jest the aria-selected of all cells is set to false.

Also when I do a fireEvent.click() on the rowElement*, it doesn't trigger the onSelectionChange of the Kendo Grid React component.

Is there anything special that I need to do to be able to correctly interact with the grid in my jest tests?

 

* the rowElement is found by

return await findByRole(this.gridElement, (content, element) => {
	if (element?.tagName === 'TR') {
		return (element as any).attributes['aria-rowindex'].value === (rowIndex + 1).toString();
	} else {
		return false;
	}
});


1 Answer, 1 is accepted

Sort by
0
Wissam
Telerik team
answered on 04 Oct 2023, 11:40 AM

Hello, Ewald,

Thank you for the provided sample for testing.

I tested the `aria-selected` classes of the Grid with the developer responsible for accessibility, and we found out that the `aria-selected` class is not set for the TR element because we are using an incorrect class internally. Basically, when disabling cell selection (row selection is used), the TR element should have the `aria-selected` class set to true but currently it is not present at all. On the other hand, when cell selection is enabled, the selected `td` element representing the cell will have its `aria-selected` class set to true and this is working as expected.

Therefore, I logged an issue for this bug, you can track it using the link below. Apologies for the inconvenience caused to you by this issue:

In addition, I added 1000 Telerik Points to your account as a small token of gratitude for your report.

However, I could see that you mentioned that the TR element in the browser has an aria-selected property set to true. Therefore, could you please send me a runnable example of the Grid such that this is reproduced since I was not able to reproduce that when testing the component?

For more information about the Grid selection, and the difference between cell and row selection, you can check the following example:

As for the issue related to the `fireEvent.click()` method, could you please provide me with a sample of how this test is used so that I can inspect it further?

Regards,
Wissam
Progress Telerik

Stay tuned by visiting our public roadmap and feedback portal pages! Or perhaps, if you are new to our Kendo family, check out our getting started resources!

Ewald
Top achievements
Rank 1
Iron
commented on 05 Oct 2023, 03:04 AM

You are absolutely correct. I don't see the aria-selected set to true. Not sure how I came to that conclusion. The TD elements have an area-selected, but that is set to false, even when the row is selected. Is that expected?
Ewald
Top achievements
Rank 1
Iron
commented on 05 Oct 2023, 03:07 AM

Happy to share with you the code that I am using. Can I share it with you in private?

Wissam
Telerik team
commented on 09 Oct 2023, 05:02 PM

Hi, Ewald,

Yes, this is expected because the `aria-selected` of the td element is used for cell selection, while the `aria-selected` of the tr element is used for the row selection.

For sharing the code, you can send a ticket in the private thread and benefit from 24 hour response time by following the steps below:

Regards,
Wissam
Progress Telerik

Tags
Grid
Asked by
Ewald
Top achievements
Rank 1
Iron
Answers by
Wissam
Telerik team
Share this question
or