Skip to content

Commit

Permalink
fix: Tailwind the Add User page + cypress tests for user feature (#4378)
Browse files Browse the repository at this point in the history
  • Loading branch information
aeswibon authored Jan 16, 2023
1 parent 3fdc76d commit 62e8902
Show file tree
Hide file tree
Showing 17 changed files with 510 additions and 373 deletions.
5 changes: 4 additions & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@
"*.bs.js",
"*.gen.tsx",
"*.res",
"*.css"
"*.css",
"*.csv",
"*.stories.mdx",
"Dockerfile"
]
}
14 changes: 10 additions & 4 deletions cypress/e2e/external_results_spec/external_result.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,16 @@ describe("Edit Profile Testing", () => {
});

it("import", () => {
cy.wait(100);
cy.contains("Import/Export").click().wait(100);
cy.contains("Import Results").click().wait(100);
// TODO: attach file and save
cy.intercept("POST", "/api/v1/external_result/bulk_upsert").as("import");
cy.get("div").contains("Import/Export").click({ force: true });
cy.get("div").contains("Import Results").click({ force: true });
cy.get("[id=result-upload]")
.selectFile("cypress/fixtures/external-result_sample.csv")
.wait(100);
cy.get("button").contains("Save").click({ force: true });
cy.wait("@import").then((interception) => {
expect(interception.response.statusCode).to.equal(202);
});
});

it("export", () => {
Expand Down
67 changes: 35 additions & 32 deletions cypress/e2e/facility_spec/facility.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ class facility {
cy.awaitUrl("/facility/create");
this.fillForm({
...facility,
type: 1,
features: [1, 3],
latitude: 800,
longitude: 500,
});
Expand All @@ -20,8 +18,6 @@ class facility {
cy.url().should("include", "update");
this.fillForm({
...facility,
type: 3,
features: [3, 4],
latitude: 900,
longitude: 600,
});
Expand All @@ -36,6 +32,10 @@ class facility {
address,
pincode,
tel,
state,
district,
localbody,
ward,
oxygen_capacity,
oxygen_requirement,
type_b_cylinders,
Expand All @@ -48,68 +48,68 @@ class facility {
longitude,
}) {
cy.get("[id=facility-type] > div > button").click();
cy.get(`ul > li:nth-child(${type})`).click();
cy.get("div").contains(type).click();

cy.get("[id=facility-name]").should("exist").type(name);
cy.get("input[id=facility-name]").should("exist").type(name);

cy.get("[id=facility-features] > div > div > button").click();
cy.get(`ul > li:nth-child(${features[0]})`).click();
cy.get(`ul > li:nth-child(${features[1]})`).click();
cy.get("li").contains(features[0]).click();
cy.get("li").contains(features[1]).click();
cy.get("body").click();

cy.get("[id=facility-state] > div > button").click();
cy.get("ul > li:nth-child(2)").click();
cy.get("div").contains(state).click();

cy.get("[id=facility-district] > div > button").click();
cy.get("ul > li:nth-child(3)").click();
cy.get("div").contains(district).click();

cy.get("[id=facility-localbody] > div > button").click();
cy.get("ul > li:nth-child(3)").click();
cy.get("div").contains(localbody).click();

cy.get("[id=facility-ward] > div > button").click();
cy.get("ul > li:nth-child(2)").click();
cy.get("div").contains(ward).click();

cy.get("[id=facility-address]").type(address);
cy.get("textarea[id=facility-address]").should("exist").type(address);

cy.get("[id=facility-pincode]").should("exist").clear().type(pincode);
cy.get("input[id=facility-pincode]").should("exist").clear().type(pincode);

cy.get("input[type=tel]").should("exist").type(tel);

cy.get("[id=facility-oxygen_capacity]").clear().type(oxygen_capacity);
cy.get("[id=facility-expected_oxygen_requirement]")
cy.get("input[id=facility-oxygen_capacity]").clear().type(oxygen_capacity);
cy.get("input[id=facility-expected_oxygen_requirement]")
.should("exist")
.clear()
.type(oxygen_requirement);

cy.get("[id=facility-type_b_cylinders]")
cy.get("input[id=facility-type_b_cylinders]")
.should("exist")
.clear()
.type(type_b_cylinders);
cy.get("[id=facility-expected_type_b_cylinders]")
cy.get("input[id=facility-expected_type_b_cylinders]")
.should("exist")
.clear()
.type(expected_type_b_cylinders);

cy.get("[id=facility-type_c_cylinders]")
cy.get("input[id=facility-type_c_cylinders]")
.should("exist")
.clear()
.type(type_c_cylinders);
cy.get("[id=facility-expected_type_c_cylinders]")
cy.get("input[id=facility-expected_type_c_cylinders]")
.should("exist")
.clear()
.type(expected_type_c_cylinders);

cy.get("[id=facility-type_d_cylinders]")
cy.get("input[id=facility-type_d_cylinders]")
.should("exist")
.clear()
.type(type_d_cylinders);
cy.get("[id=facility-expected_type_d_cylinders]")
cy.get("input[id=facility-expected_type_d_cylinders]")
.should("exist")
.clear()
.type(expected_type_d_cylinders);

cy.get("[id=facility-location-button]").click();
cy.get("body").wait(6000).click(latitude, longitude);
cy.get("body").wait(7000).click(latitude, longitude);
cy.get("body").click();
}
}
Expand All @@ -131,11 +131,11 @@ describe("Facility", () => {
facility.create({
type: "Private Hospital",
name: "cypress facility",
features: [1, 3],
features: ["CT Scan", "X-Ray"],
state: "Kerala",
district: "Ernakulam",
localbody: "Alangad  Block Panchayat, Ernakulam District",
ward: "1: MANAKKAPADY",
localbody: "Alangad",
ward: "MANAKKAPADY",
address: "some address",
pincode: "884656",
tel: "9985784535",
Expand All @@ -151,12 +151,14 @@ describe("Facility", () => {
longitude: "1.494140625",
});

cy.verifyNotification("Facility added successfully");

// add bed type
cy.url().should("include", "bed");
cy.get("[id=bed-type] > div > button").click();
cy.get("ul > li:nth-child(2)").click();
cy.get("[id=total-capacity]").type("150");
cy.get("[id=currently-occupied]").type("100");
cy.get("div").contains("Non-Covid Ordinary Beds").click();
cy.get("input[id=total-capacity]").should("exist").type("150");
cy.get("input[id=currently-occupied]").should("exist").type("100");
cy.get("[id=bed-capacity-save]").click();
cy.verifyNotification("Bed capacity added successfully");

Expand Down Expand Up @@ -185,11 +187,11 @@ describe("Facility", () => {
facility.update({
type: "TeleMedicine",
name: " update",
features: [1, 4],
features: ["X-Ray", "Neonatal Care"],
state: "Kerala",
district: "Ernakulam",
localbody: "Alangad  Block Panchayat, Ernakulam District",
ward: "1: MANAKKAPADY",
localbody: "Aikaranad",
ward: "PAZHAMTHOTTAM",
address: " update",
pincode: "584675",
tel: "9985784535",
Expand All @@ -204,6 +206,7 @@ describe("Facility", () => {
latitude: "-16.97274101999901",
longitude: "11.77734375",
});
cy.verifyNotification("Facility updated successfully");
cy.url().then((url) => {
current_url = url;
});
Expand Down
67 changes: 55 additions & 12 deletions cypress/e2e/users_spec/user_crud.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,42 +30,81 @@ describe("User management", () => {

it("create user", () => {
cy.contains("Add New User").click();
cy.get("[name='user_type']").select("Volunteer");
cy.get("[id='user_type'] > div > button").click();
cy.get("div").contains("Ward Admin").click();
cy.get("[id='state'] > div > button").click();
cy.get("div").contains("Kerala").click();
cy.get("[id='district'] > div > button").click();
cy.get("div").contains("Ernakulam").click();
cy.get("[id='localbody'] > div > button").click();
cy.get("div").contains("Aikaranad").click();
cy.intercept(/\/api\/v1\/facility/).as("facility");
cy.get("[name='facilities']")
.type("cypress_testing_facility")
.wait("@facility");
cy.get("[name='facilities']").type("{enter}");
cy.wait(1000);
cy.get("input[type='checkbox']").click();
cy.wait(1000);
cy.get("[placeholder='Phone Number']").type(phone_number);
cy.wait(1000);
cy.get("[placeholder='WhatsApp Phone Number']").type(alt_phone_number, {
force: true,
});
cy.intercept(/\/api\/v1\/facility/).as("facility");
cy.get("[name='facilities']").type("Mysore").wait("@facility");
cy.get("[name='facilities']").type("{downarrow}{enter}");
cy.intercept(/users/).as("checkUsername");
cy.intercept(/users/).as("check_availability");
cy.get("[id='date_of_birth']").click();
cy.get("div").contains("20").click();
cy.get("[id='year-0']").click();
cy.get("[id='date-1']").click();
cy.get("[name='username']").type(username, { force: true });
cy.wait("@checkUsername").its("response.statusCode").should("eq", 200);
cy.get("[name='dob']").type("02/03/2001");
cy.wait("@check_availability").its("response.statusCode").should("eq", 200);
cy.get("[name='password']").type("#@Cypress_test123");
cy.get("[name='c_password']").type("#@Cypress_test123");
cy.get("[name='first_name']").type("Cypress Test");
cy.get("[name='last_name']").type("Tester");
cy.get("[name='email']").type("cypress@tester.com");
cy.get("[name='gender']").select("Male");
cy.get("[name='state']").select("Kerala");
cy.get("[name='district']").select("Ernakulam");
cy.get("button[type='submit']").contains("Save User").click();
cy.get("[id='gender'] > div > button").click();
cy.get("div").contains("Male").click();
cy.get("button[id='submit']").contains("Save User").click({
force: true,
});
cy.verifyNotification("User added successfully");
});

it("view user and verify details", () => {
cy.contains("Advanced Filters").click();
cy.get("[name='first_name']").type("Cypress Test");
cy.get("[name='last_name']").type("Tester");
cy.get("[id='role'] > div > button").click();
cy.get("div")
.contains(/^Ward Admin$/)
.click();
cy.get("input[name='district']").type("Ernakulam").wait(1000);
cy.get("input[name='district']").type("{downarrow}{enter}");
cy.get("[placeholder='Phone Number']").type(phone_number);
cy.get("[placeholder='WhatsApp Phone Number']").type(alt_phone_number);
cy.contains("Apply").click();
cy.intercept(/\/api\/v1\/users/).as("getUsers");
cy.wait(1000);
cy.get("[name='username']").type(username, { force: true });
// TODO: some verify task
cy.wait("@getUsers");
cy.wait(1000);
cy.get("dd[id='count']").contains(/^1$/).click();
cy.get("div[id='usr_0']").within(() => {
cy.intercept(`/api/v1/users/${username}/get_facilities/`).as(
"userFacility"
);
cy.get("div[id='role']").contains(/^WardAdmin$/);
cy.get("div[id='name']").contains("Cypress Test Tester");
cy.get("div[id='district']").contains(/^Ernakulam$/);
cy.get("div[id='local_body']").contains("Aikaranad");
cy.get("div[id='created_by']").contains(/^devdistrictadmin$/);
cy.get("div[id='home_facility']").contains("No Home Facility");
cy.get("div[id='facilities'] > div > button").click().wait(1000);
cy.wait("@userFacility").then(() => {
cy.get("div").contains("cypress_testing_facility");
});
});
});

it("link facility for user", () => {
Expand Down Expand Up @@ -138,6 +177,7 @@ describe("Edit Profile Testing", () => {
.type("User 1")
.trigger("change", { force: true });
cy.get("form").get("button[type='submit']").contains("Update").click();
cy.wait(1000);
cy.get("dt").contains("First Name").siblings().first().contains("User 1");
});

Expand All @@ -153,6 +193,7 @@ describe("Edit Profile Testing", () => {
.type("User 1")
.trigger("change", { force: true });
cy.get("form").get("button[type='submit']").contains("Update").click();
cy.wait(1000);
cy.get("dt").contains("Last Name").siblings().first().contains("User 1");
});

Expand Down Expand Up @@ -188,6 +229,7 @@ describe("Edit Profile Testing", () => {
.should("have.attr", "value", `+91 ${whatsapp_num}`);
cy.wait(1000);
cy.get("form").get("button[type='submit']").contains("Update").click();
cy.wait(1000);
cy.get("dt")
.contains("Whatsapp No")
.siblings()
Expand Down Expand Up @@ -227,6 +269,7 @@ describe("Edit Profile Testing", () => {
.should("have.attr", "value", `+91 ${phone_num}`);
cy.wait(1000);
cy.get("form").get("button[type='submit']").contains("Update").click();
cy.wait(1000);
cy.get("dt")
.contains("Contact No")
.siblings()
Expand Down
3 changes: 3 additions & 0 deletions cypress/fixtures/external-result_sample.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
id,name,age,age_in,result,srf_id,gender,address,district,local_body,local_body_type,ward,mobile_number,is_repeat,patient_status,sample_type,test_type,sample_collection_date,result_date,lab_name,source,patient_category
1,Test 1,38,years,Negative,165/EKM/202010122,F,"CSN HQ
Kochi, Kerala",Ernakulam,Karukutty,Grama Panchayath,7,9207054148,NO,Symptomatic,Nasopharyngeal swab/Nasal swab/Oropharyngeal swab/Throat swab/Sputum/BAL/ETA/ Nasopharyngeal Orophar,4,2020-10-14,2020-10-10,Gh Muvattupuzha,,Cat 17: All individuals who wish to get themselves tested
29 changes: 14 additions & 15 deletions src/Common/constants.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,25 +32,24 @@ export type UserRole =
| "StateReadOnlyAdmin"
| "StateAdmin";

const readOnly = true;
export const USER_TYPE_OPTIONS: {
id: UserRole;
role: string;
readOnly?: true | undefined;
readOnly?: boolean;
}[] = [
{ id: "Pharmacist", role: "Pharmacist" },
{ id: "Volunteer", role: "Volunteer" },
{ id: "StaffReadOnly", role: "Staff", readOnly },
{ id: "Staff", role: "Staff" },
{ id: "Doctor", role: "Doctor" },
{ id: "WardAdmin", role: "Ward Admin" },
{ id: "LocalBodyAdmin", role: "Local Body Admin" },
{ id: "DistrictLabAdmin", role: "District Lab Admin" },
{ id: "DistrictReadOnlyAdmin", role: "District Admin", readOnly },
{ id: "DistrictAdmin", role: "District Admin" },
{ id: "StateLabAdmin", role: "State Lab Admin" },
{ id: "StateReadOnlyAdmin", role: "State Admin", readOnly },
{ id: "StateAdmin", role: "State Admin" },
{ id: "Pharmacist", role: "Pharmacist", readOnly: false },
{ id: "Volunteer", role: "Volunteer", readOnly: false },
{ id: "StaffReadOnly", role: "Staff", readOnly: true },
{ id: "Staff", role: "Staff", readOnly: false },
{ id: "Doctor", role: "Doctor", readOnly: false },
{ id: "WardAdmin", role: "Ward Admin", readOnly: false },
{ id: "LocalBodyAdmin", role: "Local Body Admin", readOnly: false },
{ id: "DistrictLabAdmin", role: "District Lab Admin", readOnly: false },
{ id: "DistrictReadOnlyAdmin", role: "District Admin", readOnly: true },
{ id: "DistrictAdmin", role: "District Admin", readOnly: false },
{ id: "StateLabAdmin", role: "State Lab Admin", readOnly: false },
{ id: "StateReadOnlyAdmin", role: "State Admin", readOnly: true },
{ id: "StateAdmin", role: "State Admin", readOnly: false },
];

export const USER_TYPES = USER_TYPE_OPTIONS.map((o) => o.id);
Expand Down
Loading

0 comments on commit 62e8902

Please sign in to comment.