Basically, our grid fetch data every 6 seconds (purge=false). If user clicks on row during that tiny 500ms window between 6th and 7th second, grid will swallow that click and row will not be selected, even if clicked cell has focus. When I try to replicate that behaviour through code with agGrid Api setSelected method, everything works like a charm.
It is problem for Cypress testing, they are flaky because of unpredictable click behaviour - if it happens between that 500ms window, click will be ignored.
export function selectRow(
value: string,
) {
getRow(value).then(($el1) => {
const isSelectedBeforeClick = $el1.closest('.ag-row').hasClass('ag-row-selected');
getRow(value)
.click()
.then(() => {
getRow(value).then(($el2) => {
const isSelectedAfterClick = $el2.closest('.ag-row').hasClass('ag-row-selected');
if (isSelectedBeforeClick === isSelectedAfterClick) {
cy.wait(1000);
getRow(value).click();
}
});
});
});
function getRow(value){
cy.get('my-grid [col-id="test"]').contains(value)
}
With this function it always click on row, but now i have another problem - if there were other rows selected, sometimes they are not being deselected with this method(i have rowSelection set to single), even if click was successful at first and retry click didn't happen, so I end up with two instead of one selected row.
Is there a smarter way of doing this, or does anyone know why it happens?
I'm using Angular 14 with Ag Grid version 27