ohcnetwork / care_fe

Care is a Digital Public Good enabling TeleICU & Decentralised Administration of Healthcare Capacity across States.
https://care.ohc.network
MIT License
252 stars 435 forks source link

Replace Hardcoded cy.wait() with cy.intercept in the cypress files #8925

Open nihal467 opened 2 weeks ago

nihal467 commented 2 weeks ago

Describe the bug

Currently there are multiple places in the cypress file, we use the hardcoded cy.wait(), it's creating a lot of flaky test across the test

Expected behavior

Screenshots

Image

Rishith25 commented 2 weeks ago

@nihal467 Is this the required solution for the above issue

Example: Before:

verifyUploadFilePresence(fileName: string) {
    cy.wait(2000);
    cy.get("#file-div").scrollIntoView();
    cy.verifyContentPresence("#file-div", [fileName]);
  }

After:

verifyUploadFilePresence(fileName: string) {
    // Replace cy.wait(2000) with intercepting the file upload API call
    cy.intercept('POST', '/api/upload-file').as('fileUpload'); 
    cy.wait('@fileUpload'); // Wait for the file upload request to finish

    cy.get("#file-div").scrollIntoView(); 
    cy.verifyContentPresence("#file-div", [fileName]);
}

If this is correct I would like to work on this