Skip to content

Commit

Permalink
Fixed importing structure in cypress (#10113)
Browse files Browse the repository at this point in the history
  • Loading branch information
nihal467 authored Jan 23, 2025
1 parent 080906e commit 999a41b
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 21 deletions.
8 changes: 5 additions & 3 deletions cypress/e2e/facility_spec/facility_creation.cy.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { FacilityCreation } from "@/cypress/pageObject/facility/FacilityCreation";
import { generatePhoneNumber } from "@/cypress/utils/commonUtils";
import { generateFacilityData } from "@/cypress/utils/facilityData";
import { FacilityCreation } from "pageObject/facility/FacilityCreation";
import { generatePhoneNumber } from "utils/commonUtils";
import { generateFacilityData } from "utils/facilityData";

const LOCATION_HIERARCHY = {
localBody: "Aluva",
Expand All @@ -12,6 +12,8 @@ describe("Facility Management", () => {
const facilityType = "Primary Health Centre";

beforeEach(() => {
// Set larger viewport to ensure all elements are visible
cy.viewport(1920, 1080);
cy.visit("/login");
cy.loginByApi("nurse");
});
Expand Down
3 changes: 1 addition & 2 deletions cypress/e2e/patient_spec/patient_creation.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,11 @@ import { patientCreation } from "pageObject/Patients/PatientCreation";
import { patientDashboard } from "pageObject/Patients/PatientDashboard";
import { patientVerify } from "pageObject/Patients/PatientVerify";
import { FacilityCreation } from "pageObject/facility/FacilityCreation";

import {
generateAddress,
generateName,
generatePhoneNumber,
} from "@/cypress/utils/commonUtils";
} from "utils/commonUtils";

const facilityCreation = new FacilityCreation();
const ENCOUNTER_TYPE = "Observation";
Expand Down
2 changes: 1 addition & 1 deletion cypress/pageObject/Patients/PatientCreation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ export class PatientCreation {
}

selectLocalBody(localBody: string) {
cy.typeAndSelectOption('[data-cy="select-local_body"]', localBody);
cy.typeAndSelectOption('[data-cy="select-local_body"]', localBody, false);
return this;
}

Expand Down
2 changes: 1 addition & 1 deletion cypress/pageObject/Users/UserCreation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ export class UserCreation {
}

selectLocalBody(localBody: string) {
cy.clickAndSelectOption('[data-cy="select-local_body"]', localBody);
cy.typeAndSelectOption('[data-cy="select-local_body"]', localBody, false);
return this;
}

Expand Down
8 changes: 7 additions & 1 deletion cypress/pageObject/facility/FacilityCreation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,13 @@ export class FacilityCreation {
}

fillLocationHierarchy(location: { localBody: string; ward: string }) {
cy.typeAndSelectOption('[data-cy="select-local_body"]', location.localBody);
// Don't verify selection for local body (false parameter)
cy.typeAndSelectOption(
'[data-cy="select-local_body"]',
location.localBody,
false,
);
// Verify selection for ward (default behavior)
cy.typeAndSelectOption('[data-cy="select-ward"]', location.ward);
return this;
}
Expand Down
35 changes: 23 additions & 12 deletions cypress/support/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,19 +108,30 @@ Cypress.Commands.add("clickCancelButton", (buttonText = "Cancel") => {

Cypress.Commands.add(
"typeAndSelectOption",
(selector: string, value: string) => {
(selector: string, value: string, verify: boolean = true) => {
// Click to open the dropdown
cy.get(selector).click();

// Type in the command input
cy.get("[cmdk-input]").should("be.visible").clear().type(value);

// Select the filtered option from command menu
cy.get("[cmdk-list]")
.find("[cmdk-item]")
.contains(value)
.should("be.visible")
.click();
cy.get(selector)
.click()
.then(() => {
// Type in the command input
cy.get("[cmdk-input]")
.should("be.visible")
.type(value)
.then(() => {
// Select the filtered option from command menu
cy.get("[cmdk-list]")
.find("[cmdk-item]")
.contains(value)
.should("be.visible")
.click()
.then(() => {
// Verify the selected value is present in the selector (if verify is true)
if (verify) {
cy.get(selector).should("contain", value);
}
});
});
});
},
);

Expand Down
3 changes: 2 additions & 1 deletion cypress/support/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ declare global {
clickCancelButton(buttonText?: string): Chainable<Element>;
typeAndSelectOption(
element: string,
referance: string,
reference: string,
skipVerification?: boolean,
): Chainable<Element>;
clickAndMultiSelectOption(
selector: string,
Expand Down

0 comments on commit 999a41b

Please sign in to comment.