Skip to content

Commit

Permalink
[RFR] Archetypes pagination test (#852)
Browse files Browse the repository at this point in the history
* Archetype Pagination test

Signed-off-by: Shveta Sachdeva <[email protected]>

* Archetype Pagination test

Signed-off-by: Shveta Sachdeva <[email protected]>

* Archetype Pagination test

Signed-off-by: Shveta Sachdeva <[email protected]>

* Archetype Pagination test

Signed-off-by: Shveta Sachdeva <[email protected]>

* Archetype Pagination test

Signed-off-by: Shveta Sachdeva <[email protected]>

* Archetype Pagination test

Signed-off-by: Shveta Sachdeva <[email protected]>

* Archetype Pagination test

Signed-off-by: Shveta Sachdeva <[email protected]>

---------

Signed-off-by: Shveta Sachdeva <[email protected]>
Co-authored-by: Shveta Sachdeva <[email protected]>
  • Loading branch information
sshveta and Shveta Sachdeva authored Dec 1, 2023
1 parent f0f5211 commit 0a2916c
Show file tree
Hide file tree
Showing 3 changed files with 260 additions and 2 deletions.
145 changes: 145 additions & 0 deletions cypress/e2e/models/migration/archetypes/archetype.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
/*
Copyright © 2021 the Konveyor Contributors (https://konveyor.io/)
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
import {
clickByText,
cancelForm,
inputText,
selectFormItems,
selectItemsPerPage,
selectUserPerspective,
submitForm,
click,
} from "../../../../utils/utils";
import { migration, trTag } from "../../../types/constants";
import { navMenu } from "../../../views/menu.view";
import { Stakeholdergroups } from "../controls/stakeholdergroups";
import { Stakeholders } from "../controls/stakeholders";
import * as archetype from "../../../views/archetype.view";
import { sideKebabMenu } from "../../../views/applicationinventory.view";
import { actionMenuItem, confirmButton } from "../../../views/common.view";

export interface Archetype {
name: string;
criteriaTags: string[];
archetypeTags: string[];
description?: string;
stakeholders?: Stakeholders[];
stakeholderGroups?: Stakeholdergroups[];
comments?: string;
}

export class Archetype {
constructor(
name: string,
criteriaTags: string[],
archetypeTags: string[],
description?: string,
stakeholders?: Stakeholders[],
stakeholderGroups?: Stakeholdergroups[],
comments?: string
) {
this.name = name;
this.criteriaTags = criteriaTags;
this.archetypeTags = archetypeTags;
this.description = description;
this.stakeholders = stakeholders;
this.stakeholderGroups = stakeholderGroups;
this.comments = comments;
}

static fullUrl = Cypress.env("tackleUrl") + "/archetypes";

public static open(forceReload = false) {
if (forceReload) {
cy.visit(Archetype.fullUrl);
}
cy.url().then(($url) => {
if (!$url.includes(Archetype.fullUrl)) {
selectUserPerspective(migration);
clickByText(navMenu, "Archetypes");
selectItemsPerPage(100);
}
});
}

protected fillName(name: string): void {
inputText(archetype.name, name);
}

protected selectCriteriaTags(tags: string[]): void {
tags.forEach(function (tag) {
selectFormItems(archetype.criteriaTags, tag);
});
}

protected selectArchetypeTags(tags: string[]): void {
tags.forEach(function (tag) {
selectFormItems(archetype.archetypeTags, tag);
});
}

protected fillDescription(description: string): void {
inputText(archetype.description, description);
}

protected selectStakeholders(stakeholders: Stakeholders[]) {
stakeholders.forEach((stakeholder) => {
inputText(archetype.stakeholders, stakeholder.name);
cy.get("button").contains(stakeholder.name).click();
});
}

protected selectStakeholderGroups(stakeholderGroups: Stakeholdergroups[]) {
stakeholderGroups.forEach((stakeholderGroup) => {
inputText(archetype.stakeholderGroups, stakeholderGroup.name);
cy.get("button").contains(stakeholderGroup.name).click();
});
}

protected fillComment(comments: string): void {
inputText(archetype.comments, comments);
}

create(cancel = false): void {
Archetype.open();
cy.contains("button", "Create new archetype").should("be.enabled").click();
if (cancel) {
cancelForm();
} else {
this.fillName(this.name);
this.selectCriteriaTags(this.criteriaTags);
this.selectArchetypeTags(this.archetypeTags);
if (this.description) this.fillDescription(this.description);
if (this.stakeholders) this.selectStakeholders(this.stakeholders);
if (this.stakeholderGroups) this.selectStakeholderGroups(this.stakeholderGroups);
}
if (this.comments) this.fillComment(this.comments);
submitForm();
}

delete(cancel = false): void {
Archetype.open();
cy.contains(this.name)
.closest(trTag)
.within(() => {
click(sideKebabMenu);
});
cy.get(actionMenuItem).contains("Delete").click();
if (cancel) {
cancelForm();
} else click(confirmButton);
}
}
61 changes: 61 additions & 0 deletions cypress/e2e/tests/migration/archetypes/pagination.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/*
Copyright © 2021 the Konveyor Contributors (https://konveyor.io/)
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
/// <reference types="cypress" />

import {
createMultipleArchetypes,
deleteAllArchetypes,
deleteAllRows,
goToLastPage,
itemsPerPageValidation,
login,
selectItemsPerPage,
validatePagination,
} from "../../../../utils/utils";
import { Archetype } from "../../../models/migration/archetypes/archetype";

describe(["@tier3"], "Archetypes pagination validations", function () {
before("Login and Create Test Data", function () {
login();
createMultipleArchetypes(11);
});

it("Navigation button validations", function () {
Archetype.open();
selectItemsPerPage(10);
validatePagination();
});

it("Items per page validations", function () {
Archetype.open();
itemsPerPageValidation();
});

it("Last page item(s) deletion, impact on page reload validation", function () {
Archetype.open();
selectItemsPerPage(10);
goToLastPage();
deleteAllRows();
// Verify that page is re-directed to previous page
cy.get("td[data-label=Name]").then(($rows) => {
cy.wrap($rows.length).should("eq", 10);
});
});

after("Perform test data clean up", function () {
deleteAllArchetypes();
});
});
56 changes: 54 additions & 2 deletions cypress/utils/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ import {
singleApplicationColumns,
tagFilterName,
} from "../e2e/views/issue.view";
import { Archetype } from "../e2e/models/migration/archetypes/archetype";

const { _ } = Cypress;

Expand Down Expand Up @@ -171,6 +172,7 @@ export function clickJs(fieldId: string, isForced = true, log = false, number =
export function submitForm(): void {
cy.get(commonView.submitButton).should("not.be.disabled");
cy.get(commonView.controlsForm).submit();
cy.wait(2 * SEC);
}

export function cancelForm(): void {
Expand Down Expand Up @@ -917,6 +919,17 @@ export function createMultipleJobFunctions(num): Array<Jobfunctions> {
return jobFunctionsList;
}

export function createMultipleArchetypes(number): Archetype[] {
const randomTagName = "3rd party / Apache Aries";
let archetypesList: Archetype[] = [];
for (let i = 0; i < number; i++) {
const archetype = new Archetype(data.getRandomWord(6), [randomTagName], [randomTagName]);
archetype.create();
archetypesList.push(archetype);
}
return archetypesList;
}

export function createMultipleStakeholderGroups(
numberofstakeholdergroup: number,
stakeholdersList?: Array<Stakeholders>
Expand Down Expand Up @@ -1177,13 +1190,12 @@ export function isTableEmpty(
export function deleteAllRows(tableSelector: string = commonView.commonTable) {
// This method if for pages that have delete button inside Kebab menu
// like Applications and Imports page
selectItemsPerPage(100);
isTableEmpty().then((empty) => {
if (!empty) {
cy.get(tableSelector)
.find(trTag)
.then(($rows) => {
for (let i = 0; i < $rows.length - 2; i++) {
for (let i = 0; i < $rows.length - 1; i++) {
cy.get(sideKebabMenu, { timeout: 10000 }).first().click();
cy.get("ul[role=menu] > li").contains("Delete").click();
cy.get(commonView.confirmButton).click();
Expand Down Expand Up @@ -1239,13 +1251,21 @@ export function deleteAllStakeholders(): void {
deleteAllItems(stakeHoldersTable);
}

export function deleteAllArchetypes() {
Archetype.open();
selectItemsPerPage(100);
deleteAllRows();
}

export function deleteApplicationTableRows(): void {
navigate_to_application_inventory();
selectItemsPerPage(100);
deleteAllRows();
}

export function deleteAppImportsTableRows() {
openManageImportsPage();
selectItemsPerPage(100);
deleteAllRows();
}

Expand Down Expand Up @@ -1383,6 +1403,38 @@ export function validatePagination(): void {
cy.get(firstPageButton).eq(0).click();
}

export function itemsPerPageValidation(tableSelector = commonView.appTable): void {
selectItemsPerPage(10);
cy.wait(2000);

// Verify that only 10 items are displayed
cy.get(tableSelector)
.find("td[data-label=Name]")
.then(($rows) => {
cy.wrap($rows.length).should("eq", 10);
});

selectItemsPerPage(20);
cy.wait(2000);

// Verify that items less than or equal to 20 and greater than 10 are displayed
cy.get(tableSelector)
.find("td[data-label=Name]")
.then(($rows) => {
cy.wrap($rows.length).should("be.lte", 20).and("be.gt", 10);
});
}

export function autoPageChangeValidations(): void {
selectItemsPerPage(10);
goToLastPage();
deleteAllRows();
// Verify that page is re-directed to previous page
cy.get("td[data-label=Name]").then(($rows) => {
cy.wrap($rows.length).should("eq", 10);
});
}

export function goToLastPage(): void {
cy.get(lastPageButton, { timeout: 10 * SEC })
.eq(1)
Expand Down

0 comments on commit 0a2916c

Please sign in to comment.