Skip to content

Commit

Permalink
add test to search asset by qr and serial number (#6266)
Browse files Browse the repository at this point in the history
* add search by qr and ID

* made variables values dynamic
  • Loading branch information
nihal467 authored Sep 12, 2023
1 parent 7cda789 commit 2da1eee
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});

Expand All @@ -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
Expand Down
47 changes: 42 additions & 5 deletions cypress/pageobject/Asset/AssetSearch.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,58 @@
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) {
cy.get("[data-testid=created-asset-list]")
.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
);
}
}

0 comments on commit 2da1eee

Please sign in to comment.