Skip to content

Commit

Permalink
refactored the pagination
Browse files Browse the repository at this point in the history
  • Loading branch information
nihal467 committed Nov 20, 2024
1 parent f79a2a4 commit c245e57
Show file tree
Hide file tree
Showing 9 changed files with 36 additions and 66 deletions.
11 changes: 5 additions & 6 deletions cypress/e2e/assets_spec/AssetHomepage.cy.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
import { advanceFilters } from "pageobject/utils/advanceFilterHelpers";
import { pageNavigation } from "pageobject/utils/paginationHelpers";
import { v4 as uuidv4 } from "uuid";

import { AssetPage } from "../../pageobject/Asset/AssetCreation";
import { AssetFilters } from "../../pageobject/Asset/AssetFilters";
import { AssetPagination } from "../../pageobject/Asset/AssetPagination";
import { AssetQRScanPage } from "../../pageobject/Asset/AssetQRScan";
import { AssetSearchPage } from "../../pageobject/Asset/AssetSearch";
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 assetPage = new AssetPage();
const loginPage = new LoginPage();
Expand Down Expand Up @@ -79,10 +78,10 @@ describe("Asset Tab", () => {
// Verify the pagination in the page

it("Next/Previous Page", () => {
assetPagination.navigateToNextPage();
assetPagination.verifyNextUrl();
assetPagination.navigateToPreviousPage();
assetPagination.verifyPreviousUrl();
pageNavigation.navigateToNextPage();
pageNavigation.verifyCurrentPageNumber(2);
pageNavigation.navigateToPreviousPage();
pageNavigation.verifyCurrentPageNumber(1);
});

it("Import new asset", () => {
Expand Down
12 changes: 6 additions & 6 deletions cypress/e2e/facility_spec/FacilityHomepage.cy.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// FacilityCreation
import { AssetPagination } from "../../pageobject/Asset/AssetPagination";
import { pageNavigation } from "pageobject/utils/paginationHelpers";

import FacilityPage from "../../pageobject/Facility/FacilityCreation";
import FacilityHome from "../../pageobject/Facility/FacilityHome";
import FacilityNotify from "../../pageobject/Facility/FacilityNotify";
Expand All @@ -15,7 +16,6 @@ describe("Facility Homepage Function", () => {
const facilityPage = new FacilityPage();
const manageUserPage = new ManageUserPage();
const userPage = new UserPage();
const assetPagination = new AssetPagination();
const facilitiesAlias = "downloadFacilitiesCSV";
const doctorsAlias = "downloadDoctorsCSV";
const triagesAlias = "downloadTriagesCSV";
Expand Down Expand Up @@ -83,10 +83,10 @@ describe("Facility Homepage Function", () => {

it("Search a facility in homepage and pagination", () => {
// pagination of the facility page
assetPagination.navigateToNextPage();
assetPagination.verifyNextUrl();
assetPagination.navigateToPreviousPage();
assetPagination.verifyPreviousUrl();
pageNavigation.navigateToNextPage();
pageNavigation.verifyCurrentPageNumber(2);
pageNavigation.navigateToPreviousPage();
pageNavigation.verifyCurrentPageNumber(1);
// search for a facility
manageUserPage.typeFacilitySearch(facilityName);
facilityPage.verifyFacilityBadgeContent(facilityName);
Expand Down
7 changes: 3 additions & 4 deletions cypress/e2e/facility_spec/FacilityLocation.cy.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { pageNavigation } from "pageobject/utils/paginationHelpers";
import { v4 as uuidv4 } from "uuid";

import { AssetPage } from "../../pageobject/Asset/AssetCreation";
import { AssetPagination } from "../../pageobject/Asset/AssetPagination";
import FacilityPage from "../../pageobject/Facility/FacilityCreation";
import FacilityHome from "../../pageobject/Facility/FacilityHome";
import FacilityLocation from "../../pageobject/Facility/FacilityLocation";
Expand All @@ -12,7 +12,6 @@ describe("Location Management Section", () => {
const userCreationPage = new UserCreationPage();
const facilityPage = new FacilityPage();
const facilityLocation = new FacilityLocation();
const assetPagination = new AssetPagination();
const facilityHome = new FacilityHome();

const EXPECTED_LOCATION_ERROR_MESSAGES = [
Expand Down Expand Up @@ -172,8 +171,8 @@ describe("Location Management Section", () => {
facilityLocation.setMultipleBeds(numberOfModifiedBeds);
assetPage.clickassetupdatebutton();
// pagination
assetPagination.navigateToNextPage();
assetPagination.navigateToPreviousPage();
pageNavigation.navigateToNextPage();
pageNavigation.navigateToPreviousPage();
facilityLocation.closeNotification();
});

Expand Down
7 changes: 4 additions & 3 deletions cypress/e2e/patient_spec/PatientHomepage.cy.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { advanceFilters } from "pageobject/utils/advanceFilterHelpers";
import { pageNavigation } from "pageobject/utils/paginationHelpers";

import LoginPage from "../../pageobject/Login/LoginPage";
import PatientHome from "../../pageobject/Patient/PatientHome";
Expand Down Expand Up @@ -163,15 +164,15 @@ describe("Patient Homepage present functionalities", () => {
.invoke("text")
.then((patientOne: string) => {
firstPatientPageOne = patientOne.trim();
patientHome.clickNextPage();
patientHome.verifySecondPageUrl();
pageNavigation.navigateToNextPage();
pageNavigation.verifyCurrentPageNumber(2);
cy.get('[data-cy="patient"]')
.first()
.invoke("text")
.then((patientTwo: string) => {
const firstPatientPageTwo = patientTwo.trim();
expect(firstPatientPageOne).not.to.eq(firstPatientPageTwo);
patientHome.clickPreviousPage();
pageNavigation.navigateToPreviousPage();
});
});
});
Expand Down
9 changes: 5 additions & 4 deletions cypress/e2e/users_spec/UsersHomepage.cy.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { advanceFilters } from "pageobject/utils/advanceFilterHelpers";
import { pageNavigation } from "pageobject/utils/paginationHelpers";

import LoginPage from "../../pageobject/Login/LoginPage";
import { UserPage } from "../../pageobject/Users/UserSearch";
Expand Down Expand Up @@ -84,10 +85,10 @@ describe("User Homepage", () => {
});

it("Next/Previous Page Navigation", () => {
userPage.navigateToNextPage();
userPage.verifyCurrentPageNumber(2);
userPage.navigateToPreviousPage();
userPage.verifyCurrentPageNumber(1);
pageNavigation.navigateToNextPage();
pageNavigation.verifyCurrentPageNumber(2);
pageNavigation.navigateToPreviousPage();
pageNavigation.verifyCurrentPageNumber(1);
});

afterEach(() => {
Expand Down
19 changes: 0 additions & 19 deletions cypress/pageobject/Asset/AssetPagination.ts
Original file line number Diff line number Diff line change
@@ -1,19 +0,0 @@
export class AssetPagination {
navigateToNextPage() {
// only works for desktop mode
cy.get("button#next-pages").click();
}

verifyNextUrl() {
cy.url().should("include", "page=2");
}

navigateToPreviousPage() {
// only works for desktop mode
cy.get("button#prev-pages").click();
}

verifyPreviousUrl() {
cy.url().should("include", "page=1");
}
}
12 changes: 0 additions & 12 deletions cypress/pageobject/Patient/PatientHome.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,4 @@
class PatientHome {
clickNextPage() {
cy.get("#next-pages").click();
}

verifySecondPageUrl() {
cy.url().should("include", "/patients?page=2");
}

clickPreviousPage() {
cy.get("#prev-pages").click();
}

clickPatientExport() {
cy.get("#patient-export").click();
}
Expand Down
12 changes: 0 additions & 12 deletions cypress/pageobject/Users/UserSearch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,18 +76,6 @@ export class UserPage {
cy.get(`[data-testid="${testId}"]`).should("not.be.visible");
}

navigateToNextPage() {
cy.get("button#next-pages").click();
}

navigateToPreviousPage() {
cy.get("button#prev-pages").click();
}

verifyCurrentPageNumber(pageNumber: number) {
cy.url().should("include", `page=${pageNumber}`);
}

verifyMultipleBadgesWithSameId(alreadylinkedusersviews: string[]) {
cy.get("#user-view-name").then(($elements) => {
const userViews = $elements
Expand Down
13 changes: 13 additions & 0 deletions cypress/pageobject/utils/paginationHelpers.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
export const pageNavigation = {
navigateToNextPage() {
cy.get("button#next-pages").click();
},

verifyCurrentPageNumber(pageNumber: number) {
cy.url().should("include", `page=${pageNumber}`);
},

navigateToPreviousPage() {
cy.get("button#prev-pages").click();
},
};

0 comments on commit c245e57

Please sign in to comment.