Skip to content

Commit

Permalink
Fixed Cypress Tests (#4062)
Browse files Browse the repository at this point in the history
  • Loading branch information
khavinshankar authored Dec 12, 2022
1 parent cd1d3e9 commit ef4ba6f
Show file tree
Hide file tree
Showing 19 changed files with 55 additions and 48 deletions.
4 changes: 4 additions & 0 deletions .github/workflows/cypress.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@ jobs:
wait-on: "http://localhost:4000"
wait-on-timeout: 300
browser: electron
record: true
env:
CYPRESS_RECORD_KEY: ${{ secrets.CYPRESS_RECORD_KEY }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Remove cypress failed label on success 🏷️
uses: actions-ecosystem/action-remove-labels@v1
Expand Down
2 changes: 1 addition & 1 deletion cypress.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import { defineConfig } from "cypress";
import fs from "fs";

export default defineConfig({
projectId: "wf7d2m",
defaultCommandTimeout: 10000,

e2e: {
setupNodeEvents(on, _) {
// implement node event listeners here
Expand Down
3 changes: 2 additions & 1 deletion cypress/e2e/assets_spec/filter.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,10 @@ describe("Assets Filter", () => {
});

it("Filter by Facility", () => {
cy.intercept(/\/api\/v1\/getallfacilities/).as("facilities");
cy.get("[name=Facilities]").type("test");
cy.intercept(/\/api\/v1\/getallfacilities/).as("facilities");
cy.wait("@facilities").then((interception) => {
console.log("url", interception.response.url);
expect(interception.response.statusCode).to.equal(200);
expect(interception.request.url).to.include("search_text=test");
});
Expand Down
5 changes: 1 addition & 4 deletions cypress/e2e/external_results_spec/external_result.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,9 @@ describe("Edit Profile Testing", () => {

it("Search by Patient name", () => {
cy.intercept(/\/api\/v1\/external_result/).as("external_result");
cy.get("[name='search'][placeholder='Search by Patient Name']").type(
"akhil"
);
cy.get("[name='patient_name_search']").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");
});
Expand Down
1 change: 1 addition & 0 deletions cypress/e2e/facility_spec/facility.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ class facility {
}

static update(facility) {
cy.get("[id=manage-facility-dropdown]").should("exist").click();
cy.get("[id=update-facility]").click();
cy.url().should("include", "update");
this.fillForm(facility);
Expand Down
8 changes: 3 additions & 5 deletions cypress/e2e/facility_spec/inventory.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,9 @@ describe("Inventory Management Section", () => {
beforeEach(() => {
cy.restoreLocalStorage();
cy.awaitUrl("/");
cy.get("a")
.should("contain", "Facility")
.contains("Facility")
.click({ force: true });
cy.contains("Manage Inventory").click();
cy.get("[name='facility-details']").first().click();
cy.get("[id=manage-facility-dropdown]").should("exist").click();
cy.get("[id=inventory-management]").click();
});

it("Adds Inventory", () => {
Expand Down
8 changes: 3 additions & 5 deletions cypress/e2e/facility_spec/locations.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,9 @@ describe("Location Management Section", () => {
beforeEach(() => {
cy.restoreLocalStorage();
cy.awaitUrl("/");
cy.get("a")
.should("contain", "Facility")
.contains("Facility")
.click({ force: true });
cy.contains("Manage Locations").click();
cy.get("[name='facility-details']").first().click();
cy.get("[id=manage-facility-dropdown]").should("exist").click();
cy.get("[id=location-management]").click();
});

it("Adds Location", () => {
Expand Down
5 changes: 1 addition & 4 deletions cypress/e2e/patient_spec/patient_crud.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,7 @@ describe("Patient Creation", () => {
});

it("Create", () => {
cy.get("a")
.should("contain", "Facility")
.contains("Facility")
.click({ force: true });
cy.get("[name='facility-details']").first().click();
cy.get("button").should("contain", "Add Details of a Patient");
cy.get("button")
.contains("Add Details of a Patient")
Expand Down
10 changes: 5 additions & 5 deletions cypress/e2e/resource_spec/resources.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,6 @@ describe("Resource Page", () => {
});
});

it("switch between list view and board view", () => {
cy.contains("List View").click();
cy.contains("Board View").click();
});

it("switch between active/completed", () => {
cy.intercept(/\/api\/v1\/resource/).as("resource");
cy.contains("Completed").click();
Expand All @@ -43,6 +38,11 @@ describe("Resource Page", () => {
cy.contains("Completed").should("have.class", "bg-gray-200");
});

it("switch between list view and board view", () => {
cy.contains("List View").click();
cy.contains("Board View").click();
});

afterEach(() => {
cy.saveLocalStorage();
});
Expand Down
6 changes: 2 additions & 4 deletions cypress/e2e/sample_test_spec/sample_test.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,18 @@ describe("Sample List", () => {

it("Search by District name", () => {
cy.intercept(/\/api\/v1\/test_sample/).as("test_sample");
cy.get("[placeholder='District Name']").type("TEst");
cy.get("[name='district_name_search']").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.intercept(/\/api\/v1\/test_sample/).as("test_sample");
cy.get("[placeholder='Search by Patient Name']").type("Test");
cy.get("[name='patient_name_search']").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
6 changes: 3 additions & 3 deletions cypress/e2e/shifting_spec/filter.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ describe("Shifting section filter", () => {
cy.contains("Apply").click();
});

it("filter by assigned to facility", () => {
cy.intercept(/\/api\/v1\/getallfacilities/).as("facilities_filter");
cy.get("[name='assigned_to']").type("test").wait("@facilities_filter");
it("filter by assigned to user", () => {
cy.intercept(/\/api\/v1\/users/).as("users_filter");
cy.get("[name='assigned_to']").type("test").wait("@users_filter");
cy.get("[name='assigned_to']").type("{downarrow}{enter}");
cy.contains("Apply").click();
});
Expand Down
2 changes: 1 addition & 1 deletion cypress/e2e/shifting_spec/shifting.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ describe("Shifting Page", () => {
});

it("search patient", () => {
cy.get("[name='search']").type("Akhil");
cy.get("[name='patient_name_search']").type("Akhil");
cy.url().should("include", "Akhil");
});

Expand Down
20 changes: 11 additions & 9 deletions cypress/e2e/users_spec/user_crud.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ describe("User management", () => {
cy.get("[name='facilities']").type("{downarrow}{enter}");
cy.intercept(/users/).as("checkUsername");
cy.get("[name='username']").type(username, { force: true });
cy.wait("@checkUsername").its("response.statusCode").should("eq", 404);
cy.wait("@checkUsername").its("response.statusCode").should("eq", 200);
cy.get("[name='dob']").type("02/03/2001");
cy.get("[name='password']").type("#@Cypress_test123");
cy.get("[name='c_password']").type("#@Cypress_test123");
Expand All @@ -64,7 +64,7 @@ describe("User management", () => {
cy.get("[placeholder='Phone Number']").type(phone_number);
cy.get("[placeholder='WhatsApp Phone Number']").type(alt_phone_number);
cy.contains("Apply").click();
cy.get("[name='search']").type(username, { force: true });
cy.get("[name='username']").type(username, { force: true });
// TODO: some verify task
});

Expand All @@ -76,11 +76,11 @@ describe("User management", () => {
cy.get("[placeholder='WhatsApp Phone Number']").type(alt_phone_number);
cy.contains("Apply").click();
cy.intercept(/\/api\/v1\/users/).as("getUsers");
cy.get("[name='search']").type(username, { force: true });
cy.get("[name='username']").type(username, { force: true });
cy.wait("@getUsers");
cy.wait(500);
const linkFacilityString = "Click here to show linked facilities";
cy.get("a")
cy.get("div")
.should("contain", linkFacilityString)
.contains(linkFacilityString)
.click({ force: true })
Expand Down Expand Up @@ -136,7 +136,8 @@ describe("Edit Profile Testing", () => {

it("Valid First-Name field of " + username, () => {
cy.get("input[name=firstName]")
.type(backspace + "User 1")
.clear()
.type("User 1")
.trigger("change", { force: true });
cy.get("form").get("button[type='submit']").contains("UPDATE").click();
cy.get("dt").contains("First Name").siblings().first().contains("User 1");
Expand All @@ -150,7 +151,8 @@ describe("Edit Profile Testing", () => {

it("Valid Last-Name field of " + username, () => {
cy.get("input[name=lastName]")
.type(backspace + "User 1")
.clear()
.type("User 1")
.trigger("change", { force: true });
cy.get("form").get("button[type='submit']").contains("UPDATE").click();
cy.get("dt").contains("Last Name").siblings().first().contains("User 1");
Expand Down Expand Up @@ -192,7 +194,7 @@ describe("Edit Profile Testing", () => {
.contains("Whatsapp No")
.siblings()
.first()
.contains(`+91 ${whatsapp_num}`);
.contains(`+91 ${whatsapp_num}`.replace(/[ -]/g, ""));
});

it("Invalid Phone Number of " + username, () => {
Expand Down Expand Up @@ -231,7 +233,7 @@ describe("Edit Profile Testing", () => {
.contains("Contact No")
.siblings()
.first()
.contains(`+91 ${phone_num}`);
.contains(`+91 ${phone_num}`.replace(/[ -]/g, ""));
});

afterEach(() => {
Expand All @@ -243,7 +245,7 @@ describe("Delete User", () => {
it("deletes user", () => {
cy.loginByApi("devdistrictadmin", "Coronasafe@123");
cy.awaitUrl("/user");
cy.get("[name='search']").type(username);
cy.get("[name='username']").type(username);
cy.get("button").should("contain", "Delete").contains("Delete").click();
cy.get("button.font-medium.btn.btn-danger").click();
});
Expand Down
7 changes: 5 additions & 2 deletions src/Components/Common/components/Menu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,13 @@ import { ButtonVariant } from "./ButtonV2";
import { DropdownTransition } from "./HelperComponents";

export default function DropdownMenu(props: {
id?: string;
title: string;
icon: JSX.Element;
children: JSX.Element | JSX.Element[];
}) {
return (
<div className="text-right">
<div id={props.id} className="text-right">
<Menu as="div" className="relative inline-block text-left w-full">
<Menu.Button className="text-white flex w-full lg:justify-between justify-center items-center outline-offset-1 Button button-primary-default button-size-default button-shape-square">
<div className="flex gap-2 items-center">
Expand Down Expand Up @@ -53,8 +54,10 @@ export function DropdownItem({
}: DropdownItemProps) {
const isAuthorized = useIsAuthorized(authorizeFor);

console.log({ ...props });

return (
<Menu.Item>
<Menu.Item as="div">
<div
{...props}
className={[
Expand Down
2 changes: 1 addition & 1 deletion src/Components/ExternalResult/ResultList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ export default function ResultList() {
<div className="mt-2">
<SearchInput
label="Search by name"
name="name"
name="patient_name_search"
onChange={(e) => updateQuery({ [e.name]: e.value })}
value={qParams.name}
placeholder="Search patient"
Expand Down
3 changes: 3 additions & 0 deletions src/Components/Facility/FacilityCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ export const FacilityCard = (props: { facility: any; userType: any }) => {
{userType !== "Staff" ? (
<ButtonV2
className="flex gap-3 bg-white"
name="facility-notify"
shadow
ghost
onClick={() => setNotifyModalFor(facility.id)}
Expand Down Expand Up @@ -189,6 +190,7 @@ export const FacilityCard = (props: { facility: any; userType: any }) => {
<div className="flex gap-2 ">
<ButtonV2
className="flex gap-3 bg-white"
name="facility-details"
shadow
ghost
onClick={() => navigate(`/facility/${facility.id}`)}
Expand All @@ -198,6 +200,7 @@ export const FacilityCard = (props: { facility: any; userType: any }) => {
</ButtonV2>
<ButtonV2
className="flex gap-3 bg-white"
name="facility-patients"
shadow
ghost
onClick={() =>
Expand Down
5 changes: 5 additions & 0 deletions src/Components/Facility/FacilityHome.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -450,17 +450,20 @@ export const FacilityHome = (props: any) => {
<div className="flex flex-col justify-between mt-4">
<div className="w-full md:w-auto">
<DropdownMenu
id="manage-facility-dropdown"
title="Manage Facility"
icon={<CareIcon className="care-l-setting h-5" />}
>
<DropdownItem
id="update-facility"
onClick={() => navigate(`/facility/${facilityId}/update`)}
authorizeFor={NonReadOnlyUsers}
icon={<CareIcon className="care-l-edit-alt h-5" />}
>
Update Facility
</DropdownItem>
<DropdownItem
id="configure-facility"
onClick={() =>
navigate(`/facility/${facilityId}/middleware/update`)
}
Expand All @@ -470,12 +473,14 @@ export const FacilityHome = (props: any) => {
Configure Facility
</DropdownItem>
<DropdownItem
id="inventory-management"
onClick={() => navigate(`/facility/${facilityId}/inventory`)}
icon={<CareIcon className="care-l-clipboard-alt w-5 " />}
>
Inventory Management
</DropdownItem>
<DropdownItem
id="location-management"
onClick={() => navigate(`/facility/${facilityId}/location`)}
authorizeFor={NonReadOnlyUsers}
icon={<CareIcon className="care-l-location-point h-5" />}
Expand Down
4 changes: 2 additions & 2 deletions src/Components/Patient/SampleViewAdmin.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -370,13 +370,13 @@ export default function SampleViewAdmin() {

<div className="w-full flex flex-col gap-3 p-2">
<SearchInput
name="patient_name"
name="patient_name_search"
value={qParams.patient_name}
onChange={(e) => updateQuery({ [e.name]: e.value })}
placeholder="Search patient"
/>
<SearchInput
name="district_name"
name="district_name_search"
value={qParams.district_name}
onChange={(e) => updateQuery({ [e.name]: e.value })}
placeholder="Search by district"
Expand Down
2 changes: 1 addition & 1 deletion src/Components/Shifting/BoardView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ export default function BoardView() {
</div>
<div className="w-full flex pt-2 lg:space-x-4 items-center flex-col lg:flex-row justify-between">
<SearchInput
name="patient_name"
name="patient_name_search"
value={qParams.patient_name}
onChange={(e) => updateQuery({ [e.name]: e.value })}
placeholder="Search patient"
Expand Down

0 comments on commit ef4ba6f

Please sign in to comment.