Skip to content

Commit

Permalink
Refactor selectItemsPerPageinReports
Browse files Browse the repository at this point in the history
Signed-off-by: Neilhamza <[email protected]>
  • Loading branch information
Neilhamza committed Aug 22, 2023
1 parent 882c872 commit c69a6ee
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 79 deletions.
64 changes: 3 additions & 61 deletions cypress/e2e/models/migration/reports/reports.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ limitations under the License.
/// <reference types="cypress" />
/// <reference types="cypress-xpath" />

import { selectItemsPerPage } from "../../../../utils/utils";
import { SEC, applicationName, risk } from "../../../types/constants";
import * as commonView from "../../../views/common.view";
import {
Expand All @@ -31,71 +32,12 @@ import {
} from "../../../views/reports.view";

//TODO Update following method to a possible usage of current "selectItemsPerPage" method or reuse it inside following method
export function selectArticleItemsPerPage(items: number, articleTitle: string): void {
export function selectItemsPerPageinReports(items: number, articleTitle: string): void {
cy.log(`Select ${items} per page`);
cy.get(articleTitle)
.closest(articleItem)
.within(() => {
cy.get(commonView.itemsPerPageToggleButton, { timeout: 60 * SEC, log: false }).then(
($toggleBtn) => {
if (!$toggleBtn.is(":disabled")) {
$toggleBtn.trigger("click");
cy.get(commonView.itemsPerPageMenuOptions);
cy.get(`li[data-action="per-page-${items}"]`, { log: false })
.contains(`${items}`)
.click({
force: true,
log: false,
});
cy.wait(2000);
}
}
);
});
}

export function selectItemsPerPageAdoptionCandidate(items: number): void {
cy.log(`Select ${items} per page`);
cy.get(adoptionCandidateDistributionTitle)
.closest(articleItem)
.within(() => {
cy.get(commonView.itemsPerPageToggleButton, { timeout: 60 * SEC, log: false }).then(
($toggleBtn) => {
if (!$toggleBtn.is(":disabled")) {
$toggleBtn.trigger("click");
cy.get(commonView.itemsPerPageMenuOptions);
cy.get(`li[data-action="per-page-${items}"]`, { log: false })
.contains(`${items}`)
.click({
force: true,
log: false,
});
cy.wait(2000);
}
}
);
});
}

export function selectItemsPerPageIdentifiedRisks(items: number): void {
cy.log(`Select ${items} per page`);
cy.get(identiFiedRisksTitle)
.closest(articleItem)
.within(() => {
cy.get(commonView.itemsPerPageToggleButton, { timeout: 60 * SEC, log: false }).then(
($toggleBtn) => {
if (!$toggleBtn.is(":disabled")) {
$toggleBtn.trigger("click");
cy.get(commonView.itemsPerPageMenuOptions, { log: false });
cy.get(`li[data-action="per-page-${items}"]`, { log: false })
.contains(`${items}`)
.click({
force: true,
log: false,
});
}
}
);
selectItemsPerPage(items);
});
}

Expand Down
14 changes: 7 additions & 7 deletions cypress/e2e/tests/migration/reports/filter.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ import * as data from "../../../../utils/data_utils";
import {
expandArticle,
closeArticle,
selectArticleItemsPerPage,
selectItemsPerPageinReports,
} from "../../../models/migration/reports/reports";
import { Stakeholders } from "../../../models/migration/controls/stakeholders";

Expand Down Expand Up @@ -92,7 +92,7 @@ describe(["@tier2"], "Reports filter validations", () => {
cy.wait(3 * SEC);

// Check element filtered for table Adoption Candidate Distribution
selectArticleItemsPerPage(100, adoptionCandidateDistributionTitle);
selectItemsPerPageinReports(100, adoptionCandidateDistributionTitle);

// Wait for DOM to render table and sibling elements
cy.get(adoptionCandidateDistributionTitle)
Expand All @@ -106,7 +106,7 @@ describe(["@tier2"], "Reports filter validations", () => {
expandArticle(identiFiedRisks);
cy.wait(2 * SEC);

selectArticleItemsPerPage(100, identiFiedRisksTitle);
selectItemsPerPageinReports(100, identiFiedRisksTitle);

let applicationsData = getTableColumnData("Application(s)");
cy.wrap(applicationsData).each((application) => {
Expand Down Expand Up @@ -153,7 +153,7 @@ describe(["@tier2"], "Reports filter validations", () => {
expandArticle(identiFiedRisks);
cy.wait(2 * SEC);

selectArticleItemsPerPage(100, identiFiedRisksTitle);
selectItemsPerPageinReports(100, identiFiedRisksTitle);

applySearchFilter(name, validSearchInput, true, 1);
cy.wait(3 * SEC);
Expand Down Expand Up @@ -199,7 +199,7 @@ describe(["@tier2"], "Reports filter validations", () => {
expandArticle(identiFiedRisks);
cy.wait(2 * SEC);

selectArticleItemsPerPage(100, identiFiedRisksTitle);
selectItemsPerPageinReports(100, identiFiedRisksTitle);

// Get a category of assessment questions and apply it as search filter
let categoryString = "Application details";
Expand Down Expand Up @@ -249,7 +249,7 @@ describe(["@tier2"], "Reports filter validations", () => {
expandArticle(identiFiedRisks);
cy.wait(2 * SEC);

selectArticleItemsPerPage(100, identiFiedRisksTitle);
selectItemsPerPageinReports(100, identiFiedRisksTitle);

// Get a question from assessment question's list and apply it as search filter
let questionString = "How is the application tested?";
Expand Down Expand Up @@ -298,7 +298,7 @@ describe(["@tier2"], "Reports filter validations", () => {
expandArticle(identiFiedRisks);
cy.wait(2 * SEC);

selectArticleItemsPerPage(100, identiFiedRisksTitle);
selectItemsPerPageinReports(100, identiFiedRisksTitle);

// select an answer input from existing answers and apply it as search filter
let answerString = "Not tracked";
Expand Down
25 changes: 14 additions & 11 deletions cypress/e2e/tests/migration/reports/pagination.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,18 @@ import {
deleteByList,
} from "../../../../utils/utils";
import { navMenu } from "../../../views/menu.view";
import { migration, reports, SEC } from "../../../types/constants";
import { adoptionCandidateDistribution, migration, reports, SEC } from "../../../types/constants";
import { Assessment } from "../../../models/migration/applicationinventory/assessment";
import {
selectItemsPerPageAdoptionCandidate,
selectItemsPerPageIdentifiedRisks,
expandArticle,
selectItemsPerPageinReports,
} from "../../../models/migration/reports/reports";
import { Stakeholders } from "../../../models/migration/controls/stakeholders";
import * as commonView from "../../../views/common.view";
import {
adoptionCandidateDistributionTitle,
identiFiedRisksTitle,
} from "../../../views/reports.view";

let applicationsList: Array<Assessment> = [];
let stakeholdersList: Array<Stakeholders> = [];
Expand Down Expand Up @@ -66,7 +69,7 @@ describe(["@tier3"], "Reports pagination validations", () => {
cy.wait(3 * SEC);

// select 10 items per page
selectItemsPerPageAdoptionCandidate(10);
selectItemsPerPageinReports(10, adoptionCandidateDistributionTitle);

// Verify next buttons are enabled as there are more than 11 rows present
cy.get(commonView.nextPageButton).each(($nextBtn) => {
Expand Down Expand Up @@ -103,7 +106,7 @@ describe(["@tier3"], "Reports pagination validations", () => {
cy.wait(3 * SEC);

// Select 10 items per page
selectItemsPerPageAdoptionCandidate(10);
selectItemsPerPageinReports(10, adoptionCandidateDistributionTitle);
cy.wait(2 * SEC);

// Verify that only 10 items are displayed
Expand All @@ -112,7 +115,7 @@ describe(["@tier3"], "Reports pagination validations", () => {
});

// Select 20 items per page
selectItemsPerPageAdoptionCandidate(20);
selectItemsPerPageinReports(20, adoptionCandidateDistributionTitle);
cy.wait(2 * SEC);

// Verify that items less than or equal to 20 and greater than 10 are displayed
Expand All @@ -128,7 +131,7 @@ describe(["@tier3"], "Reports pagination validations", () => {
cy.wait(3 * SEC);

// Select 10 items per page
selectItemsPerPageAdoptionCandidate(10);
selectItemsPerPageinReports(10, adoptionCandidateDistributionTitle);
cy.wait(2 * SEC);

// Go to page number 2
Expand All @@ -151,7 +154,7 @@ describe(["@tier3"], "Reports pagination validations", () => {
cy.wait(3 * SEC);

// select 10 items per page
selectItemsPerPageIdentifiedRisks(10);
selectItemsPerPageinReports(10, identiFiedRisksTitle);

// Verify next buttons are enabled as there are more than 11 rows present
cy.get(commonView.nextPageButton).eq(2).should("not.be.disabled");
Expand Down Expand Up @@ -189,7 +192,7 @@ describe(["@tier3"], "Reports pagination validations", () => {
cy.wait(2 * SEC);

// Select 10 items per page
selectItemsPerPageIdentifiedRisks(10);
selectItemsPerPageinReports(10, identiFiedRisksTitle);
cy.wait(2 * SEC);

// Verify that only 10 items are displayed
Expand All @@ -198,7 +201,7 @@ describe(["@tier3"], "Reports pagination validations", () => {
});

// Select 20 items per page
selectItemsPerPageIdentifiedRisks(20);
selectItemsPerPageinReports(20, identiFiedRisksTitle);
cy.wait(2 * SEC);

// Verify that items less than or equal to 20 and greater than 10 are displayed
Expand All @@ -218,7 +221,7 @@ describe(["@tier3"], "Reports pagination validations", () => {
cy.wait(2 * SEC);

// Select 10 items per page
selectItemsPerPageIdentifiedRisks(10);
selectItemsPerPageinReports(10, identiFiedRisksTitle);
cy.wait(2 * SEC);

// Go to page number 2
Expand Down

0 comments on commit c69a6ee

Please sign in to comment.