diff --git a/cypress/e2e/models/migration/archetypes/archetype.ts b/cypress/e2e/models/migration/archetypes/archetype.ts new file mode 100644 index 000000000..09a40cf00 --- /dev/null +++ b/cypress/e2e/models/migration/archetypes/archetype.ts @@ -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); + } +} diff --git a/cypress/e2e/tests/migration/archetypes/pagination.test.ts b/cypress/e2e/tests/migration/archetypes/pagination.test.ts new file mode 100644 index 000000000..ea75919da --- /dev/null +++ b/cypress/e2e/tests/migration/archetypes/pagination.test.ts @@ -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. +*/ +/// + +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(); + }); +}); diff --git a/cypress/utils/utils.ts b/cypress/utils/utils.ts index ec5d0124d..00ca9abe0 100644 --- a/cypress/utils/utils.ts +++ b/cypress/utils/utils.ts @@ -105,6 +105,7 @@ import { singleApplicationColumns, tagFilterName, } from "../e2e/views/issue.view"; +import { Archetype } from "../e2e/models/migration/archetypes/archetype"; const { _ } = Cypress; @@ -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 { @@ -917,6 +919,17 @@ export function createMultipleJobFunctions(num): Array { 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 @@ -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(); @@ -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(); } @@ -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)