From 16b0bd848d7cde1f4e0624f4907e6bfba656280e Mon Sep 17 00:00:00 2001 From: Mohammed Nihal <57055998+nihal467@users.noreply.github.com> Date: Tue, 12 Sep 2023 00:42:20 +0530 Subject: [PATCH] add search by qr and ID --- .../{asset_tab.cy.ts => asset_homepage.cy.ts} | 28 +++++++++-- cypress/pageobject/Asset/AssetSearch.ts | 47 +++++++++++++++++-- 2 files changed, 65 insertions(+), 10 deletions(-) rename cypress/e2e/assets_spec/{asset_tab.cy.ts => asset_homepage.cy.ts} (54%) diff --git a/cypress/e2e/assets_spec/asset_tab.cy.ts b/cypress/e2e/assets_spec/asset_homepage.cy.ts similarity index 54% rename from cypress/e2e/assets_spec/asset_tab.cy.ts rename to cypress/e2e/assets_spec/asset_homepage.cy.ts index 0abf11fcaf0..90fc28f5c6f 100644 --- a/cypress/e2e/assets_spec/asset_tab.cy.ts +++ b/cypress/e2e/assets_spec/asset_homepage.cy.ts @@ -5,15 +5,17 @@ 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"; describe("Asset Tab", () => { const assetSearchPage = new AssetSearchPage(); const assetQRScanPage = new AssetQRScanPage(); const assetPagination = new AssetPagination(); const assetFilters = new AssetFilters(); + const loginPage = new LoginPage(); before(() => { - cy.loginByApi("devdistrictadmin", "Coronasafe@123"); + loginPage.loginAsDisctrictAdmin(); cy.saveLocalStorage(); }); @@ -24,11 +26,27 @@ 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("dummy camera 10"); assetSearchPage.pressEnter(); - assetSearchPage.verifyUrlChanged(initialUrl); + assetSearchPage.verifyBadgeContent( + "Name/Serial No./QR ID: dummy camera 10" + ); + assetSearchPage.clickAssetByName("Dummy Camera 10"); + assetSearchPage.clickUpdateButton(); + assetSearchPage.clearAndTypeQRCode("340543-05935-04953-05234-04"); + assetSearchPage.clearAndTypeSerialNumber("8989898989898"); + assetSearchPage.clickAssetSubmitButton(); + assetSearchPage.visitAssetsPage(); + assetSearchPage.typeSearchKeyword("340543-05935-04953-05234-04"); + assetSearchPage.pressEnter(); + assetSearchPage.verifyAssetListContains("Dummy Camera 10"); + assetSearchPage.verifyBadgeContent( + "Name/Serial No./QR ID: 340543-05935-04953-05234-04" + ); + assetSearchPage.typeSearchKeyword("8989898989898"); + assetSearchPage.verifyAssetListContains("Dummy Camera 10"); + assetSearchPage.verifyBadgeContent("Name/Serial No./QR ID: 8989898989898"); }); // scan a asset qr code diff --git a/cypress/pageobject/Asset/AssetSearch.ts b/cypress/pageobject/Asset/AssetSearch.ts index 315a414a62b..0fc4f79b799 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( + "have.text", + 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 + ); + } }