Skip to content

Commit

Permalink
Added cypress test for asset creation (#5632)
Browse files Browse the repository at this point in the history
* Added test for patient creation

* Fixed patient creation suite

* Fixed edit and update test cases and removed unwanted changes

* Tried a fix

* Added tests for asset creation

* Nits

* Update Facility name

* Update facility name

* Trying a fix for the failure

* FIxed failing test

* Reverted unwanted changes

---------
  • Loading branch information
ShivamJhaa authored Jun 13, 2023
1 parent 5f0db99 commit 5ee4f15
Show file tree
Hide file tree
Showing 5 changed files with 114 additions and 11 deletions.
62 changes: 61 additions & 1 deletion cypress/e2e/assets_spec/assets.cy.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
/// <reference types="cypress" />

import { cy, describe, before, beforeEach, it } from "local-cypress";
import { v4 as uuidv4 } from "uuid";

describe("Assets List", () => {
const phone_number = "9" + parseInt((Math.random() * 10 ** 9).toString());
const serial_no = parseInt((Math.random() * 10 ** 10).toString());

describe("Asset", () => {
before(() => {
cy.loginByApi("devdistrictadmin", "Coronasafe@123");
cy.saveLocalStorage();
Expand All @@ -13,6 +17,62 @@ describe("Assets List", () => {
cy.awaitUrl("/assets");
});

it("Create an Asset", () => {
cy.get("button").should("contain", "Create Asset");
cy.get("[data-testid=create-asset-buttom] button").click();
cy.get("input[name='facilities']")
.type("Dummy Facility 1")
.then(() => {
cy.get("[role='option']").contains("Dummy Facility 1").click();
});
cy.get("button").should("contain", "Select");
cy.get("button").get("#submit").click();
cy.get("[data-testid=asset-name-input] input").type("New Test Asset");
cy.get("[data-testid=asset-location-input] input").type(
"Camera Location{enter}"
);
cy.get("[data-testid=asset-type-input] button")
.click()
.then(() => {
cy.get("li").contains("Internal").click();
});
cy.get("[data-testid=asset-class-input] button")
.click()
.then(() => {
cy.get("li").contains("ONVIF Camera").click();
});
cy.get("[data-testid=asset-description-input] textarea").type(
"Test Description"
);
cy.get("[data-testid=asset-working-status-input] li")
.contains("Working")
.click();
const qr_id = uuidv4();
cy.get("[data-testid=asset-qr-id-input] input").type(qr_id);
cy.get("[data-testid=asset-manufacturer-input] input").type(
"Manufacturer's Name"
);
cy.get("[data-testid=asset-warranty-input] input").type("2025-12-25");
cy.get("[data-testid=asset-support-name-input] input").type(
"Customer Support's Name"
);
cy.get("#customer-support-phone-div").type(phone_number);
cy.get("[data-testid=asset-support-email-input] input").type(
"[email protected]"
);
cy.get("[data-testid=asset-vendor-name-input] input").type("Vendor's Name");
cy.get("[data-testid=asset-serial-number-input] input").type(serial_no);
cy.get("[data-testid=asset-last-serviced-on-input] input").type(
"2021-12-25"
);
cy.get("[data-testid=asset-notes-input] textarea").type(
"Test note for asset creation!"
);
cy.wait(500);
cy.get("#submit").contains("Create Asset").click();
cy.verifyNotification("Asset created successfully");
});

it("Search Asset Name", () => {
const initialUrl = cy.url();
cy.get("[name='search']").type("dummy camera 30");
Expand Down
1 change: 1 addition & 0 deletions cypress/e2e/patient_spec/patient_crud.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ describe("Patient Creation with consultation", () => {
cy.get("button#submit").should("be.visible").click();
cy.get("[data-testid='return-to-patient-dashboard']").click();
});

afterEach(() => {
cy.saveLocalStorage();
});
Expand Down
5 changes: 4 additions & 1 deletion src/Components/Assets/AssetsList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,10 @@ const AssetsList = () => {
<i className="fas fa-search mr-1"></i> Scan Asset QR
</ButtonV2>
</div>
<div className="flex flex-col md:flex-row w-full">
<div
className="flex flex-col md:flex-row w-full"
data-testid="create-asset-buttom"
>
<ButtonV2
authorizeFor={NonReadOnlyUsers}
className="w-full inline-flex items-center justify-center"
Expand Down
56 changes: 47 additions & 9 deletions src/Components/Facility/AssetCreate.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -510,7 +510,11 @@ const AssetCreate = (props: AssetProps) => {
{/* General Details Section */}
{sectionTitle("General Details")}
{/* Asset Name */}
<div className="col-span-6" ref={fieldRef["name"]}>
<div
className="col-span-6"
ref={fieldRef["name"]}
data-testid="asset-name-input"
>
<TextFormField
name="name"
label="Asset Name"
Expand All @@ -525,7 +529,11 @@ const AssetCreate = (props: AssetProps) => {
<FieldLabel className="text-sm w-max" required>
Asset Location
</FieldLabel>
<div ref={fieldRef["location"]} className="col-span-6">
<div
ref={fieldRef["location"]}
className="col-span-6"
data-testid="asset-location-input"
>
<LocationSelect
name="Facilities"
setSelected={(selectedId) =>
Expand All @@ -540,7 +548,11 @@ const AssetCreate = (props: AssetProps) => {
</div>
{/* Asset Type */}
<div className="col-span-6 flex flex-col lg:flex-row gap-x-12 xl:gap-x-16 transition-all">
<div ref={fieldRef["asset_type"]} className="flex-1">
<div
ref={fieldRef["asset_type"]}
className="flex-1"
data-testid="asset-type-input"
>
<SelectFormField
label="Asset Type"
name="asset_type"
Expand Down Expand Up @@ -569,7 +581,11 @@ const AssetCreate = (props: AssetProps) => {
</div>

{/* Asset Class */}
<div ref={fieldRef["asset_class"]} className="flex-1">
<div
ref={fieldRef["asset_class"]}
className="flex-1"
data-testid="asset-class-input"
>
<SelectFormField
disabled={!!(props.assetId && asset_class)}
placeholder={props.assetId ? t("none") : undefined}
Expand All @@ -591,7 +607,10 @@ const AssetCreate = (props: AssetProps) => {
</div>
</div>
{/* Description */}
<div className="col-span-6">
<div
className="col-span-6"
data-testid="asset-description-input"
>
<TextAreaFormField
name="asset_description"
label="Description"
Expand All @@ -602,7 +621,10 @@ const AssetCreate = (props: AssetProps) => {
/>
</div>
{/* Divider */}
<div className="col-span-6">
<div
className="col-span-6"
data-testid="asset-divider-input"
>
<hr
className={
"transition-all " +
Expand All @@ -613,7 +635,11 @@ const AssetCreate = (props: AssetProps) => {
/>
</div>
{/* Working Status */}
<div ref={fieldRef["is_working"]} className="col-span-6">
<div
ref={fieldRef["is_working"]}
className="col-span-6"
data-testid="asset-working-status-input"
>
<SwitchV2
className="col-span-6"
required
Expand Down Expand Up @@ -666,7 +692,7 @@ const AssetCreate = (props: AssetProps) => {
</div>
{/* Asset QR ID */}
<div className="col-span-6 flex flex-row items-center gap-3">
<div className="w-full">
<div className="w-full" data-testid="asset-qr-id-input">
<TextFormField
id="qr_code_id"
name="qr_code_id"
Expand All @@ -692,6 +718,7 @@ const AssetCreate = (props: AssetProps) => {
<div
className="col-span-6 sm:col-span-3"
ref={fieldRef["manufacturer"]}
data-testid="asset-manufacturer-input"
>
<TextFormField
id="manufacturer"
Expand All @@ -708,6 +735,7 @@ const AssetCreate = (props: AssetProps) => {
<div
className="col-span-6 sm:col-span-3"
ref={fieldRef["warranty_amc_end_of_validity"]}
data-testid="asset-warranty-input"
>
<TextFormField
name="WarrantyAMCExpiry"
Expand Down Expand Up @@ -737,6 +765,7 @@ const AssetCreate = (props: AssetProps) => {
<div
className="col-span-6 sm:col-span-3"
ref={fieldRef["support_name"]}
data-testid="asset-support-name-input"
>
<TextFormField
id="support-name"
Expand All @@ -753,6 +782,7 @@ const AssetCreate = (props: AssetProps) => {
<div
className="col-span-6 sm:col-span-3"
ref={fieldRef["support_phone"]}
id="customer-support-phone-div"
>
<PhoneNumberFormField
name="support_phone"
Expand All @@ -768,6 +798,7 @@ const AssetCreate = (props: AssetProps) => {
<div
className="col-span-6 sm:col-span-3"
ref={fieldRef["support_email"]}
data-testid="asset-support-email-input"
>
<TextFormField
id="support-email"
Expand All @@ -786,6 +817,7 @@ const AssetCreate = (props: AssetProps) => {
<div
className="col-span-6 sm:col-span-3"
ref={fieldRef["vendor_name"]}
data-testid="asset-vendor-name-input"
>
<TextFormField
id="vendor-name"
Expand All @@ -802,6 +834,7 @@ const AssetCreate = (props: AssetProps) => {
<div
className="col-span-6 sm:col-span-3"
ref={fieldRef["serial_number"]}
data-testid="asset-serial-number-input"
>
<TextFormField
id="serial-number"
Expand All @@ -820,6 +853,7 @@ const AssetCreate = (props: AssetProps) => {
<div
className="col-span-6 sm:col-span-3"
ref={fieldRef["last_serviced_on"]}
data-testid="asset-last-serviced-on-input"
>
<TextFormField
name="last_serviced_on"
Expand Down Expand Up @@ -847,7 +881,11 @@ const AssetCreate = (props: AssetProps) => {
</div>

{/* Notes */}
<div className="col-span-6 mt-6" ref={fieldRef["notes"]}>
<div
className="col-span-6 mt-6"
ref={fieldRef["notes"]}
data-testid="asset-notes-input"
>
<TextAreaFormField
name="notes"
label="Notes"
Expand Down
1 change: 1 addition & 0 deletions vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ export default defineConfig({
// workaround for react-phone-input-2 https://github.com/vitejs/vite/issues/2139#issuecomment-1405624744
defaultIsModuleExports(id) {
try {
// eslint-disable-next-line @typescript-eslint/no-var-requires
const module = require(id);
if (module?.default) {
return false;
Expand Down

0 comments on commit 5ee4f15

Please sign in to comment.