Skip to content

Commit

Permalink
Cypress: Refactor waits in api requests (coronasafe#3900)
Browse files Browse the repository at this point in the history
* Add minor tests for health details

* Refactor Waits in Cypress (coronasafe#3750)

* Remove commented spec tests in shifting filters

* Bump cypress to
  • Loading branch information
rabilrbl authored and aeswibon committed Dec 8, 2022
1 parent 7dc92a5 commit 86d9084
Show file tree
Hide file tree
Showing 15 changed files with 397 additions and 244 deletions.
5 changes: 5 additions & 0 deletions cypress/e2e/assets_spec/assets.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,12 @@ describe("Assets List", () => {
});

it("Search Asset Name", () => {
cy.intercept(/\/api\/v1\/asset/).as("asset");
cy.get("[name='search']").type("TEst");
cy.wait("@asset").then((interception) => {
expect(interception.response.statusCode).to.equal(200);
expect(interception.request.url).to.include("search_text=TEst");
});
});

it("Scan Asset QR", () => {
Expand Down
10 changes: 6 additions & 4 deletions cypress/e2e/assets_spec/filter.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,12 @@ describe("Assets Filter", () => {
});

it("Filter by Facility", () => {
cy.get("[name=Facilities]")
.type("test")
.wait(3000)
.type("{downarrow}{enter}");
cy.intercept(/\/api\/v1\/getallfacilities/).as("facilities");
cy.get("[name=Facilities]").type("test");
cy.wait("@facilities").then((interception) => {
expect(interception.response.statusCode).to.equal(200);
expect(interception.request.url).to.include("search_text=test");
});
});

it("Filter by Asset Type", () => {
Expand Down
31 changes: 20 additions & 11 deletions cypress/e2e/external_results_spec/external_result.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,24 @@ describe("Edit Profile Testing", () => {
});

it("Search by Patient name", () => {
cy.get("[name='search'][placeholder='Search by Patient Name']")
.type("akhil")
.wait(2000)
.url()
.should("include", "akhil");
cy.intercept(/\/api\/v1\/external_result/).as("external_result");
cy.get("[name='search'][placeholder='Search by Patient Name']").type(
"akhil"
);
cy.wait("@external_result").then((interception) => {
expect(interception.response.statusCode).to.equal(200);
expect(interception.request.url).to.include("name=akhil");
});
cy.url().should("include", "akhil");
});

it("Search by phone number", () => {
cy.get("[placeholder='Search by Phone Number']")
.type("4738743424")
.wait(2000)
.url()
.should("include", "%2B91+47387-43424");
cy.intercept(/\/api\/v1\/external_result/).as("external_result");
cy.get("[placeholder='Search by Phone Number']").type("4738743424");
cy.wait("@external_result").then((interception) => {
expect(interception.response.statusCode).to.equal(200);
});
cy.url().should("include", "%2B91+47387-43424");
});

it("upload list", () => {
Expand All @@ -33,7 +38,11 @@ describe("Edit Profile Testing", () => {
});

it("export", () => {
cy.contains("Export").click().wait(1000);
cy.intercept("/api/v1/external_result/?csv=true").as("export");
cy.contains("Export").click();
cy.wait("@export").then((interception) => {
expect(interception.response.statusCode).to.equal(200);
});
});

afterEach(() => {
Expand Down
12 changes: 12 additions & 0 deletions cypress/e2e/external_results_spec/filter.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,19 @@ describe("External Results Filters", () => {

it("filter by srf id", () => {
cy.get("[name='srf_id']").type("432");
});

it("Apply filter", () => {
cy.intercept(/\/api\/v1\/external_result/).as("external_result_filter");
cy.contains("Apply").click();
cy.wait("@external_result_filter").then((interception) => {
expect(interception.response.statusCode).to.equal(200);
expect(interception.request.url).to.include("srf_id=");
expect(interception.request.url).to.include("created_date_before=");
expect(interception.request.url).to.include("created_date_after=");
expect(interception.request.url).to.include("wards=");
expect(interception.request.url).to.include("local_bodies=");
});
});

afterEach(() => {
Expand Down
2 changes: 1 addition & 1 deletion cypress/e2e/facility_spec/facility.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ class facility {
}
}

let current_url = "http://localhost:4000";
let current_url = "/";

describe("Facility", () => {
before(() => {
Expand Down
3 changes: 3 additions & 0 deletions cypress/e2e/patient_spec/patient_crud.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ describe("Patient Creation", () => {
cy.get("[data-testid=ward-respective-lsgi] select").select(
"1: MANAKKAPADY"
);
cy.get("h1").contains("Health Details").click({ force: true });
cy.get("select#test_type").select("ANTIGEN");
cy.get("[name='is_vaccinated']").check();
cy.get("[data-testid=pincode] input").type("159015");
cy.get("[data-testid=blood-group] select").select("O+");
cy.get("[data-testid=emergency-phone-number] input").type(
Expand Down
40 changes: 23 additions & 17 deletions cypress/e2e/resource_spec/filter.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,27 +13,27 @@ describe("Resource filter", () => {
});

it("filter by origin facility", () => {
cy.get("[name='orgin_facility']")
.type("harsha")
.wait(3000)
.type("{downarrow}{enter}");
cy.contains("Apply").click().wait(1000);
cy.intercept(/\/api\/v1\/getallfacilities/).as("facilities_filter");
cy.get("[name='orgin_facility']").type("harsha").wait("@facilities_filter");
cy.get("[name='orgin_facility']").type("{downarrow}{enter}");
cy.contains("Apply").click();
});

it("filter by resource approval facility", () => {
cy.intercept(/\/api\/v1\/getallfacilities/).as("facilities_filter");
cy.get("[name='approving_facility']")
.type("test")
.wait(3000)
.type("{downarrow}{enter}");
cy.contains("Apply").click().wait(1000);
.wait("@facilities_filter");
cy.get("[name='approving_facility']").type("{downarrow}{enter}");
cy.contains("Apply").click();
});

it("filter by assigned facility", () => {
cy.get("[name='assigned_facility']")
.type("center")
.wait(3000)
.type("{downarrow}{enter}");
cy.contains("Apply").click().wait(1000);
cy.intercept(/\/api\/v1\/getallfacilities/).as("facilities_filter");
cy.get("[name='assigned_facility']").type("center");
cy.wait("@facilities_filter");
cy.get("[name='assigned_facility']").type("{downarrow}{enter}");
cy.contains("Apply").click();
});

it("filter by ordering", () => {
Expand All @@ -44,7 +44,8 @@ describe("Resource filter", () => {
"ASC Created Date",
].forEach((select) => {
cy.get("[name='ordering']").select(select);
cy.contains("Apply").click().wait(1000);
cy.intercept(/\/api\/v1\/resource/).as("resource_filter");
cy.contains("Apply").click().wait("@resource_filter");
cy.contains("Filters").click();
});
cy.contains("Cancel").click();
Expand All @@ -53,22 +54,27 @@ describe("Resource filter", () => {
it("filter by emergency case", () => {
["yes", "no"].forEach((select) => {
cy.get("[name='emergency']").select(select);
cy.contains("Apply").click().wait(1000);
cy.intercept(/\/api\/v1\/resource/).as("resource_filter");
cy.contains("Apply").click().wait("@resource_filter");
cy.contains("Filters").click();
});
cy.contains("Cancel").click();
});

it("filter by created date", () => {
cy.intercept(/\/api\/v1\/resource/).as("resource_filter");
cy.get("[name='created_date_after']").type("22/05/2020");
cy.get("[name='created_date_before']").type("09/09/2021");
cy.contains("Apply").click().wait(1000);
cy.contains("Apply").click();
cy.wait("@resource_filter");
});

it("filter by modified date", () => {
cy.intercept(/\/api\/v1\/resource/).as("resource_filter");
cy.get("[name='modified_date_after']").type("22/05/2020");
cy.get("[name='modified_date_before']").type("09/09/2021");
cy.contains("Apply").click().wait(1000);
cy.contains("Apply").click();
cy.wait("@resource_filter");
});

afterEach(() => {
Expand Down
19 changes: 15 additions & 4 deletions cypress/e2e/resource_spec/resources.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,11 @@ describe("Resource Page", () => {

it("checks if all download button works", () => {
cy.get("svg.MuiSvgIcon-root.cursor-pointer").each(($button) => {
cy.wrap($button).click({ force: true }).wait(100);
cy.intercept(/\/api\/v1\/resource/).as("resource_download");
cy.wrap($button).click({ force: true });
cy.wait("@resource_download").then((interception) => {
expect(interception.response.statusCode).to.equal(200);
});
});
});

Expand All @@ -23,11 +27,18 @@ describe("Resource Page", () => {
});

it("switch between active/completed", () => {
cy.contains("Completed").click().wait(2000);
cy.intercept(/\/api\/v1\/resource/).as("resource");
cy.contains("Completed").click();
cy.wait("@resource").then((interception) => {
expect(interception.response.statusCode).to.equal(200);
});
cy.contains("Active").should("have.class", "bg-gray-200");
cy.contains("Completed").should("have.class", "bg-white");

cy.contains("Active").click().wait(2000);
cy.intercept(/\/api\/v1\/resource/).as("resource");
cy.contains("Active").click();
cy.wait("@resource").then((interception) => {
expect(interception.response.statusCode).to.equal(200);
});
cy.contains("Active").should("have.class", "bg-white");
cy.contains("Completed").should("have.class", "bg-gray-200");
});
Expand Down
6 changes: 6 additions & 0 deletions cypress/e2e/sample_test_spec/filter.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,14 @@ describe("Sample Filter", () => {
cy.get("[name='result']").select("POSITIVE");
});

it("Filter by sample type", () => {
cy.get("[name='sample_type']").select("Biopsy");
});

afterEach(() => {
cy.intercept(/\/api\/v1\/test_sample/).as("sample_filter");
cy.contains("Apply").click();
cy.wait("@sample_filter");
cy.saveLocalStorage();
});
});
14 changes: 12 additions & 2 deletions cypress/e2e/sample_test_spec/sample_test.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,22 @@ describe("Sample List", () => {
});

it("Search by District name", () => {
cy.get("[placeholder='District Name']").type("TEst").wait(1000);
cy.intercept(/\/api\/v1\/test_sample/).as("test_sample");
cy.get("[placeholder='District Name']").type("TEst");
cy.wait("@test_sample").then((interception) => {
expect(interception.response.statusCode).to.equal(200);
expect(interception.request.url).to.include("district_name=TEst");
});
cy.url().should("include", "TEst");
});

it("Search by Patient Name", () => {
cy.get("[placeholder='Search by Patient Name']").type("Test").wait(1000);
cy.intercept(/\/api\/v1\/test_sample/).as("test_sample");
cy.get("[placeholder='Search by Patient Name']").type("Test");
cy.wait("@test_sample").then((interception) => {
expect(interception.response.statusCode).to.equal(200);
expect(interception.request.url).to.include("patient_name=Test");
});
cy.url().should("include", "Test");
});

Expand Down
Loading

0 comments on commit 86d9084

Please sign in to comment.