jeudi 10 novembre 2022

Cypress test to check all checkboxes except one

I am trying to create a Cypress test where it selects a list of checkboxes and clicks them individually and asserts if it it's checked and when it's not checked. The issues it the first checkbox in this list is a checkbox that selects all the other checkboxes and my assert breaks because the select all checkbox is always asserted to the opposite value compared to the other checkboxes for example the loop would click the first checkbox that would select all the checkboxes (including itself) and then the loop would continue down the list and click every individual checkbox and would deselect it so that means the select all checkbox is checked while the other checkboxes aren't. The other problem is that they all share the same class and I can't seem to use data-cy="" to select the individual checkboxes either, is there a way where I can make the cypress test to skip the first checkbox or maybe make the assertion skip the first one.

This is my test that I am using:

getCy('table')
  .find('.checkbox-base')
  .each($el => {
    cy.wrap($el)
      .click()
      .invoke('attr', 'aria-checked')
      .should('contain', true);
  })

And here is the component with the column of checkboxes:

     <Column
        header={<ToggleAllCell store={Store} />}
        width={60}
        data={data}
        cellClassName="wrap"
        cell={({ rowIndex }) => (
          <ToggleCell option={data[rowIndex]} store={Store} />
        )}
      />



Aucun commentaire:

Enregistrer un commentaire