Skip to content

Commit

Permalink
Add a facility card visibility check in facility creation cypress test (
Browse files Browse the repository at this point in the history
  • Loading branch information
nihal467 authored Jan 13, 2025
1 parent e6d2296 commit c2ab5ee
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 13 deletions.
3 changes: 3 additions & 0 deletions cypress/e2e/facility_spec/facility_creation.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ describe("Facility Management", () => {
facilityPage.submitFacilityCreationForm();
facilityPage.verifySuccessMessage();

// Wait for facility cards to load
facilityPage.waitForFacilityCardsToLoad();

// Search for the facility and verify in card
facilityPage.searchFacility(testFacility.name);
facilityPage.verifyFacilityNameInCard(testFacility.name);
Expand Down
7 changes: 7 additions & 0 deletions cypress/pageObject/facility/FacilityCreation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,4 +101,11 @@ export class FacilityCreation {
verifyFacilityNameInCard(facilityName: string) {
cy.get('[data-cy="facility-cards"]').should("contain", facilityName);
}

waitForFacilityCardsToLoad(timeout = 10000) {
cy.get('[data-cy="facility-cards"]', { timeout })
.should("be.visible")
.should("not.be.empty");
return this;
}
}
30 changes: 21 additions & 9 deletions cypress/support/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -235,20 +235,32 @@ Cypress.Commands.add(
(
selector: string,
value: string,
options: { clearBeforeTyping?: boolean; skipVerification?: boolean } = {},
options: {
clearBeforeTyping?: boolean;
skipVerification?: boolean;
delay?: number;
} = {},
) => {
const { clearBeforeTyping = false, skipVerification = false } = options;
const {
clearBeforeTyping = false,
skipVerification = false,
delay = 50,
} = options;
const inputField = cy.get(selector);

if (clearBeforeTyping) {
inputField.clear(); // Clear the input field if specified
inputField.clear();
}

inputField.scrollIntoView().should("be.visible").click().type(value);

// Conditionally skip verification based on the skipVerification flag
if (!skipVerification) {
inputField.should("have.value", value); // Verify the value if skipVerification is false
}
inputField
.scrollIntoView()
.should("be.visible")
.click()
.type(value, { delay })
.then(() => {
if (!skipVerification) {
cy.get(selector).should("have.value", value);
}
});
},
);
6 changes: 5 additions & 1 deletion cypress/support/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,11 @@ declare global {
typeIntoField(
selector: string,
value: string,
options?: { clearBeforeTyping?: boolean; skipVerification?: boolean },
options?: {
clearBeforeTyping?: boolean;
skipVerification?: boolean;
delay?: number;
},
): Chainable<Element>;
}
}
Expand Down
5 changes: 2 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit c2ab5ee

Please sign in to comment.