diff --git a/cypress/e2e/assets_spec/asset_tab.cy.ts b/cypress/e2e/assets_spec/asset_homepage.cy.ts similarity index 55% rename from cypress/e2e/assets_spec/asset_tab.cy.ts rename to cypress/e2e/assets_spec/asset_homepage.cy.ts index 0abf11fcaf0..6e9ceb9676b 100644 --- a/cypress/e2e/assets_spec/asset_tab.cy.ts +++ b/cypress/e2e/assets_spec/asset_homepage.cy.ts @@ -5,15 +5,21 @@ import { AssetSearchPage } from "../../pageobject/Asset/AssetSearch"; import { AssetQRScanPage } from "../../pageobject/Asset/AssetQRScan"; import { AssetPagination } from "../../pageobject/Asset/AssetPagination"; import { AssetFilters } from "../../pageobject/Asset/AssetFilters"; +import LoginPage from "../../pageobject/Login/LoginPage"; +import { v4 as uuidv4 } from "uuid"; describe("Asset Tab", () => { const assetSearchPage = new AssetSearchPage(); const assetQRScanPage = new AssetQRScanPage(); const assetPagination = new AssetPagination(); const assetFilters = new AssetFilters(); + const loginPage = new LoginPage(); + const assetName = "Dummy Camera 10"; + const qrCode = uuidv4(); + const serialNumber = Math.floor(Math.random() * 10 ** 10).toString(); before(() => { - cy.loginByApi("devdistrictadmin", "Coronasafe@123"); + loginPage.loginAsDisctrictAdmin(); cy.saveLocalStorage(); }); @@ -24,11 +30,23 @@ describe("Asset Tab", () => { // search for a element - it("Search Asset Name", () => { - const initialUrl = cy.url(); - assetSearchPage.typeSearchKeyword("dummy camera 30"); + it("Search Asset Name/QR_ID/Serial_number", () => { + assetSearchPage.typeSearchKeyword(assetName); assetSearchPage.pressEnter(); - assetSearchPage.verifyUrlChanged(initialUrl); + assetSearchPage.verifyBadgeContent(assetName); + assetSearchPage.clickAssetByName(assetName); + assetSearchPage.clickUpdateButton(); + assetSearchPage.clearAndTypeQRCode(qrCode); + assetSearchPage.clearAndTypeSerialNumber(serialNumber); + assetSearchPage.clickAssetSubmitButton(); + assetSearchPage.visitAssetsPage(); + assetSearchPage.typeSearchKeyword(qrCode); + assetSearchPage.pressEnter(); + assetSearchPage.verifyAssetListContains(assetName); + assetSearchPage.verifyBadgeContent(qrCode); + assetSearchPage.typeSearchKeyword(serialNumber); + assetSearchPage.verifyAssetListContains(assetName); + assetSearchPage.verifyBadgeContent(serialNumber); }); // scan a asset qr code diff --git a/cypress/pageobject/Asset/AssetSearch.ts b/cypress/pageobject/Asset/AssetSearch.ts index 315a414a62b..fea6a975983 100644 --- a/cypress/pageobject/Asset/AssetSearch.ts +++ b/cypress/pageobject/Asset/AssetSearch.ts @@ -1,16 +1,22 @@ export class AssetSearchPage { typeSearchKeyword(keyword: string) { - cy.get("[name='search']").type(keyword); + cy.get("#search").clear(); + cy.get("#search").click().type(keyword); } pressEnter() { cy.get("[name='search']").type("{enter}"); } - verifyUrlChanged(initialUrl: string) { - cy.url().should((currentUrl) => { - expect(currentUrl).not.to.equal(initialUrl); - }); + clickAssetByName(assetName: string) { + cy.get("[data-testid='created-asset-list']").contains(assetName).click(); + } + + verifyBadgeContent(expectedText: string) { + cy.get("[data-testid='Name/Serial No./QR ID']").should( + "contain", + expectedText + ); } verifyAssetIsPresent(assetName: string) { @@ -18,4 +24,35 @@ export class AssetSearchPage { .first() .should("contain", assetName); } + + clickUpdateButton() { + cy.get("[data-testid='asset-update-button']").contains("Update").click(); + } + + clearAndTypeQRCode(qrCode: string) { + cy.get("#qr_code_id").clear(); + cy.get("#qr_code_id").click().type(qrCode); + } + + clearAndTypeSerialNumber(serialNumber: string) { + cy.get("#serial-number").clear(); + cy.get("#serial-number").click().type(serialNumber); + } + + clickAssetSubmitButton() { + cy.intercept("GET", "**/api/v1/asset/**").as("getAssets"); + cy.get("#submit").click(); + cy.wait("@getAssets").its("response.statusCode").should("eq", 200); + } + + visitAssetsPage() { + cy.visit("/assets"); + } + + verifyAssetListContains(dummyCameraText: string) { + cy.get("[data-testid='created-asset-list']").should( + "contain", + dummyCameraText + ); + } }