Skip to content

Commit

Permalink
added cypress test to verify warranty expiry label
Browse files Browse the repository at this point in the history
  • Loading branch information
GokulramGHV committed Oct 10, 2023
1 parent 59daace commit c6b8259
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 2 deletions.
33 changes: 33 additions & 0 deletions cypress/e2e/assets_spec/assets_manage.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ import { AssetSearchPage } from "../../pageobject/Asset/AssetSearch";
import FacilityPage from "../../pageobject/Facility/FacilityCreation";
import { AssetFilters } from "../../pageobject/Asset/AssetFilters";

function addDaysToDate(numberOfDays: number) {
const inputDate = new Date();
inputDate.setDate(inputDate.getDate() + numberOfDays);
return inputDate.toISOString().split("T")[0];
}

describe("Asset", () => {
const assetPage = new AssetPage();
const loginPage = new LoginPage();
Expand All @@ -26,6 +32,33 @@ describe("Asset", () => {
cy.awaitUrl("/assets");
});

it("Verify Asset Service History Alert", () => {
assetSearchPage.typeSearchKeyword(assetname);
assetSearchPage.pressEnter();
assetSearchPage.verifyBadgeContent(assetname);
assetSearchPage.clickAssetByName(assetname);
assetPage.clickupdatedetailbutton();
assetPage.scrollintoWarrantyDetails();
assetPage.enterWarrantyExpiryDate(addDaysToDate(100)); // greater than 3 months
assetPage.clickassetupdatebutton();
assetPage.verifyWarrantyExpiryLabel("");
assetPage.clickupdatedetailbutton();
assetPage.scrollintoWarrantyDetails();
assetPage.enterWarrantyExpiryDate(addDaysToDate(80)); // less than 3 months
assetPage.clickassetupdatebutton();
assetPage.verifyWarrantyExpiryLabel("3 months");
assetPage.clickupdatedetailbutton();
assetPage.scrollintoWarrantyDetails();
assetPage.enterWarrantyExpiryDate(addDaysToDate(20)); // less than 1 month
assetPage.clickassetupdatebutton();
assetPage.verifyWarrantyExpiryLabel("1 month");
// assetPage.clickupdatedetailbutton(); // Can't check for expired warranty as it will fail since we can set only future dates for warranty expiry
// assetPage.scrollintoWarrantyDetails();
// assetPage.enterWarrantyExpiryDate(addDaysToDate(-10)); // expired
// assetPage.clickassetupdatebutton();
// assetPage.verifyWarrantyExpiryLabel("expired");
});

it("Create & Edit a service history and verify reflection", () => {
assetSearchPage.typeSearchKeyword(assetname);
assetSearchPage.pressEnter();
Expand Down
27 changes: 25 additions & 2 deletions cypress/pageobject/Asset/AssetCreation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -285,16 +285,39 @@ export class AssetPage {
cy.get("#notes").scrollIntoView();
}

enterAssetNotes(text) {
enterAssetNotes(text: string) {
cy.get("#notes").click().clear();
cy.get("#notes").click().type(text);
}

enterAssetservicedate(text) {
enterAssetservicedate(text: string) {
cy.get("input[name='last_serviced_on']").click();
cy.get("#date-input").click().type(text);
}

scrollintoWarrantyDetails() {
cy.get("#warranty-details").scrollIntoView();
}

enterWarrantyExpiryDate(text: string) {
cy.get("#WarrantyAMCExpiry").click();
cy.get("#WarrantyAMCExpiry").click().type(text);
}

verifyWarrantyExpiryLabel(duration: string) {
if (duration === "") {
cy.get("#warranty-amc-expired-red").should("not.exist");
cy.get("#warranty-amc-expiring-soon-orange").should("not.exist");
cy.get("#warranty-amc-expiring-soon-yellow").should("not.exist");
} else if (duration === "expired") {
cy.get("#warranty-amc-expired-red").should("be.visible");
} else if (duration === "1 month") {
cy.get("#warranty-amc-expiring-soon-orange").should("be.visible");
} else if (duration === "3 months") {
cy.get("#warranty-amc-expiring-soon-yellow").should("be.visible");
}
}

clickassetupdatebutton() {
cy.get("#submit").click();
}
Expand Down
2 changes: 2 additions & 0 deletions src/CAREUI/display/Chip.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ interface Props {
text: string;
tooltip?: string;
className?: string;
id?: string;
}

export default function Chip({
Expand All @@ -21,6 +22,7 @@ export default function Chip({
}: Props) {
return (
<span
id={props?.id}
className={classNames(
"inline-flex items-center gap-2 font-medium leading-4",

Expand Down
3 changes: 3 additions & 0 deletions src/Components/Assets/AssetsList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -516,6 +516,7 @@ export const warrantyAmcValidityChip = (
if (warrantyAmcEndDate < today) {
return (
<Chip
id="warranty-amc-expired-red"
variant="danger"
startIcon="l-times-circle"
text="AMC/Warranty Expired"
Expand All @@ -524,6 +525,7 @@ export const warrantyAmcValidityChip = (
} else if (days <= 30) {
return (
<Chip
id="warranty-amc-expiring-soon-orange"
variant="custom"
className="border-orange-300 bg-orange-100 text-orange-900"
startIcon="l-exclamation-circle"
Expand All @@ -533,6 +535,7 @@ export const warrantyAmcValidityChip = (
} else if (days <= 90) {
return (
<Chip
id="warranty-amc-expiring-soon-yellow"
variant="warning"
startIcon="l-exclamation-triangle"
text="AMC/Warranty Expiring Soon"
Expand Down

0 comments on commit c6b8259

Please sign in to comment.