From 28847279edda16a91212880e5ca41307c1716917 Mon Sep 17 00:00:00 2001 From: Alejandro Brugarolas <117646518+abrugaro@users.noreply.github.com> Date: Wed, 22 Nov 2023 19:42:04 +0100 Subject: [PATCH] [RFR] [JF] Adapt filter tests and refactor filter method (#827) * refactor filter method Signed-off-by: Alejandro Brugarolas * add utils Signed-off-by: Alejandro Brugarolas * refactors Signed-off-by: Alejandro Brugarolas * fix pr Signed-off-by: Alejandro Brugarolas * fix pr Signed-off-by: Alejandro Brugarolas --------- Signed-off-by: Alejandro Brugarolas --- .../controls/stakeholdergroups/filter.test.ts | 76 ++++------- .../filter_applications.test.ts | 5 +- .../e2e/tests/rbac/disable_keycloak.test.ts | 2 +- .../tests/upgrade/create_upgrade_data.test.ts | 10 +- cypress/e2e/types/constants.ts | 1 + cypress/e2e/views/common.view.ts | 9 ++ cypress/utils/utils.ts | 120 ++++++------------ 7 files changed, 81 insertions(+), 142 deletions(-) diff --git a/cypress/e2e/tests/migration/controls/stakeholdergroups/filter.test.ts b/cypress/e2e/tests/migration/controls/stakeholdergroups/filter.test.ts index 371215863..26fbe8071 100644 --- a/cypress/e2e/tests/migration/controls/stakeholdergroups/filter.test.ts +++ b/cypress/e2e/tests/migration/controls/stakeholdergroups/filter.test.ts @@ -41,125 +41,103 @@ import { Stakeholdergroups } from "../../../../models/migration/controls/stakeho import * as commonView from "../../../../../e2e/views/common.view"; import * as data from "../../../../../utils/data_utils"; -var stakeholdersList: Array = []; -var stakeholdergroupsList: Array = []; -var invalidSearchInput = data.getRandomNumber(); +let stakeholdersList: Array = []; +let stakeholderGroupsList: Array = []; +const invalidSearchInput = `${data.getRandomNumber()}`; describe(["@tier2"], "Stakeholder groups filter validations", function () { before("Login and Create Test Data", function () { login(); - // Create multiple stakeholder groups and stakeholders stakeholdersList = createMultipleStakeholders(2); - stakeholdergroupsList = createMultipleStakeholderGroups(2, stakeholdersList); + stakeholderGroupsList = createMultipleStakeholderGroups(2, stakeholdersList); }); beforeEach("Interceptors", function () { - // Interceptors - cy.intercept("GET", "/hub/stakeholdergroups*").as("getStakeholdergroups"); + cy.intercept("GET", "/hub/stakeholdergroups*").as("getStakeholderGroups"); }); it("Bug MTA-1715: Name filter validations", function () { - // Navigate to stakeholder groups tab Stakeholdergroups.openList(); - cy.get("@getStakeholdergroups"); + cy.get("@getStakeholderGroups"); - // Enter an existing name substring and apply it as search filter - var validSearchInput = stakeholdergroupsList[0].name.substring(0, 5); + const validSearchInput = stakeholderGroupsList[0].name.substring(0, 5); applySearchFilter(name, validSearchInput); - // Assert that stakeholder groups row(s) containing the search text is/are displayed - exists(stakeholdergroupsList[0].name); - if (stakeholdergroupsList[1].name.indexOf(validSearchInput) >= 0) { + exists(stakeholderGroupsList[0].name); + if (stakeholderGroupsList[1].name.indexOf(validSearchInput) >= 0) { exists(stakeholdersList[1].name); } - // Clear all filters clickByText(button, clearAllFilters); - cy.get("@getStakeholdergroups"); + cy.get("@getStakeholderGroups"); - // Enter a non-existing name substring and apply it as search filter applySearchFilter(name, invalidSearchInput); - // Assert that no search results are found cy.get("h2").contains("No stakeholder groups available"); - // Clear all filters clickByText(button, clearAllFilters); - cy.get("@getStakeholdergroups"); + cy.get("@getStakeholderGroups"); }); it("Bug MTA-1715: Description filter validations", function () { - // Navigate to stakeholder groups tab Stakeholdergroups.openList(); - cy.get("@getStakeholdergroups"); + cy.get("@getStakeholderGroups"); - // Enter an existing description substring and apply it as search filter - var validSearchInput = stakeholdergroupsList[0].description.substring(0, 3); + const validSearchInput = stakeholderGroupsList[0].description.substring(0, 3); applySearchFilter(description, validSearchInput); // Assert that stakeholder groups row(s) containing the search text is/are displayed - exists(stakeholdergroupsList[0].description); - if (stakeholdergroupsList[1].description.indexOf(validSearchInput) >= 0) { - exists(stakeholdergroupsList[1].description); + exists(stakeholderGroupsList[0].description); + if (stakeholderGroupsList[1].description.indexOf(validSearchInput) >= 0) { + exists(stakeholderGroupsList[1].description); } - // Clear all filters clickByText(button, clearAllFilters); - cy.get("@getStakeholdergroups"); + cy.get("@getStakeholderGroups"); - // Enter a non-existing description substring and apply it as search filter applySearchFilter(description, invalidSearchInput); - // Assert that no search results are found cy.get("h2").contains("No stakeholder groups available"); - // Clear all filters clickByText(button, clearAllFilters); - cy.get("@getStakeholdergroups"); + cy.get("@getStakeholderGroups"); }); it("Bug MTA-1715: Member filter validations", function () { - // Navigate to stakeholder groups tab Stakeholdergroups.openList(); - cy.get("@getStakeholdergroups"); + cy.get("@getStakeholderGroups"); - // Enter an existing member substring and apply it as search filter - var validSearchInput = stakeholdergroupsList[0].members[0].substring(0, 3); + const validSearchInput = stakeholderGroupsList[0].members[0].substring(0, 3); applySearchFilter(stakeholders, validSearchInput); - // Assert that stakeholder groups row(s) containing the search text is/are displayed selectItemsPerPage(100); cy.get(tdTag) - .contains(stakeholdergroupsList[0].name) + .contains(stakeholderGroupsList[0].name) .parent(trTag) .within(() => { click(commonView.expandRow); }) .get("div > dd") - .should("contain", stakeholdergroupsList[0].members[0]); + .should("contain", stakeholderGroupsList[0].members[0]); - if (stakeholdergroupsList[1].members[0].indexOf(validSearchInput) >= 0) { - exists(stakeholdergroupsList[1].members[0]); + if (stakeholderGroupsList[1].members[0].indexOf(validSearchInput) >= 0) { + exists(stakeholderGroupsList[1].members[0]); } - // Clear all filters clickByText(button, clearAllFilters); - cy.get("@getStakeholdergroups"); + cy.get("@getStakeholderGroups"); - // Enter a non-existing member substring and apply it as search filter applySearchFilter(stakeholders, invalidSearchInput); - // Assert that no search results are found cy.get("h2").contains("No stakeholder groups available"); - // Clear all filters clickByText(button, clearAllFilters); - cy.get("@getStakeholdergroups"); + cy.get("@getStakeholderGroups"); }); after("Perform test data clean up", function () { deleteByList(stakeholdersList); - deleteByList(stakeholdergroupsList); + deleteByList(stakeholderGroupsList); }); }); diff --git a/cypress/e2e/tests/migration/migration-waves/filter_applications.test.ts b/cypress/e2e/tests/migration/migration-waves/filter_applications.test.ts index d22dde92c..82b53020f 100644 --- a/cypress/e2e/tests/migration/migration-waves/filter_applications.test.ts +++ b/cypress/e2e/tests/migration/migration-waves/filter_applications.test.ts @@ -30,6 +30,7 @@ import { clearAllFilters, businessService, owner, + businessServiceLower, } from "../../../types/constants"; import * as data from "../../../../utils/data_utils"; import { MigrationWave } from "../../../models/migration/migration-waves/migration-wave"; @@ -108,13 +109,13 @@ describe( cy.contains(manageApplications).click(); // Apply BS associated with applicationsList[1].name as search filter - applySearchFilter(businessService, applicationsList[1].business, true, 1); + applySearchFilter(businessServiceLower, applicationsList[1].business, true, 1); cy.get("td").should("contain", applicationsList[1].name); cy.get("td").should("not.contain", applicationsList[0].name); clickByText(button, clearAllFilters); // Apply BS associated with applicationsList[0].name as search filter - applySearchFilter(businessService, applicationsList[0].business, true, 1); + applySearchFilter(businessServiceLower, applicationsList[0].business, true, 1); cy.get("td").should("not.contain", applicationsList[1].name); cy.get("td").should("contain", applicationsList[0].name); clickByText(button, clearAllFilters); diff --git a/cypress/e2e/tests/rbac/disable_keycloak.test.ts b/cypress/e2e/tests/rbac/disable_keycloak.test.ts index 2b4f991ad..d22d97874 100644 --- a/cypress/e2e/tests/rbac/disable_keycloak.test.ts +++ b/cypress/e2e/tests/rbac/disable_keycloak.test.ts @@ -47,7 +47,7 @@ describe(["@tier4"], "Perform certain operations after disabling Keycloak", func }); it.skip("Bug MTA-1152: Auth disabled, Verify presence of Review application button", function () { - Application.validateReviewButton(this.rbacRules); + // Application.validateReviewButton(this.rbacRules); }); after("Re-enable Keycloak", function () { diff --git a/cypress/e2e/tests/upgrade/create_upgrade_data.test.ts b/cypress/e2e/tests/upgrade/create_upgrade_data.test.ts index 034d71b11..cc4c20ee1 100644 --- a/cypress/e2e/tests/upgrade/create_upgrade_data.test.ts +++ b/cypress/e2e/tests/upgrade/create_upgrade_data.test.ts @@ -15,12 +15,7 @@ limitations under the License. */ /// -import { - getRandomAnalysisData, - getRandomApplicationData, - login, - preservecookies, -} from "../../../utils/utils"; +import { getRandomAnalysisData, getRandomApplicationData, login } from "../../../utils/utils"; import { TagCategory } from "../../models/migration/controls/tagcategory"; import * as data from "../../../utils/data_utils"; import { Tag } from "../../models/migration/controls/tags"; @@ -45,9 +40,6 @@ describe(["@pre-upgrade"], "Creating pre-requisites before an upgrade", () => { }); beforeEach("Persist session", function () { - // Save the session and token cookie for maintaining one login session - preservecookies(); - cy.fixture("application").then(function (appData) { this.appData = appData; }); diff --git a/cypress/e2e/types/constants.ts b/cypress/e2e/types/constants.ts index e2d616cd5..227b03c23 100644 --- a/cypress/e2e/types/constants.ts +++ b/cypress/e2e/types/constants.ts @@ -26,6 +26,7 @@ export const analyzeButton = "Analyze"; export const artifact = "Artifact"; export const businessServices = "Business services"; export const businessService = "Business Service"; +export const businessServiceLower = "Business service"; export const button = "button"; export const category = "Category"; export const clearAllFilters = "Clear all filters"; diff --git a/cypress/e2e/views/common.view.ts b/cypress/e2e/views/common.view.ts index 7f15065d4..51c9393fb 100644 --- a/cypress/e2e/views/common.view.ts +++ b/cypress/e2e/views/common.view.ts @@ -62,3 +62,12 @@ export const nextButton = "button[cy-data='next']"; export const span = "span"; export const liTag = "li"; export const searchInput = "#search-input"; +/** + * ul[role=listbox] > li is for the Application Inventory page. + * span.pf-c-check__label is for the Copy assessment page. + */ +export const standardFilter = "ul[role=listbox] > li, span.pf-v5-c-check__label"; +export const specialFilter = "div.pf-v5-c-select__menu > fieldset > label > span"; +export const filterDropDownContainer = + "div.pf-v5-c-toolbar__group.pf-m-toggle-group.pf-m-filter-group.pf-m-show"; +export const filterDropDown = "div.pf-v5-c-select"; diff --git a/cypress/utils/utils.ts b/cypress/utils/utils.ts index 822bff6b2..09e85836d 100644 --- a/cypress/utils/utils.ts +++ b/cypress/utils/utils.ts @@ -49,6 +49,7 @@ import { owner, JiraType, migration, + businessServiceLower, } from "../e2e/types/constants"; import { actionButton, @@ -62,12 +63,16 @@ import { closeSuccessNotification, confirmButton, divHeader, + filterDropDown, + filterDropDownContainer, firstPageButton, lastPageButton, modal, nextPageButton, pageNumInput, prevPageButton, + specialFilter, + standardFilter, } from "../e2e/views/common.view"; import { tagLabels, tagMenuButton } from "../e2e/views/tags.view"; import { Credentials } from "../e2e/models/administration/credentials/credentials"; @@ -268,23 +273,6 @@ export function selectFormItems(fieldId: string, item: string): void { cy.contains("button", item).click(); } -export function selectReactFormItems( - locator: string, - item: string, - formId?: string, - fieldId?: string -): void { - if (!formId) { - formId = "FormGroup"; - } - if (!fieldId) { - fieldId = "fieldId"; - } - cy.waitForReact(); - cy.react(formId, { props: { fieldId: locator } }).click(); - cy.contains("button", item).click(); -} - export function checkSuccessAlert(fieldId: string, message: string, close = false): void { validateTextPresence(fieldId, message); if (close) { @@ -367,60 +355,44 @@ export function applySelectFilter(filterId, filterName, filterText, isValid = tr export function applySearchFilter( filterName: string, - searchText: any, - identifiedRisk?: boolean, + searchText: string | string[], + identifiedRisk = false, value?: number ): void { selectFilter(filterName, identifiedRisk, value); - if ( - filterName == businessService || - filterName == tag || - filterName == credentialType || - filterName == artifact || - filterName == repositoryType || - filterName == owner - ) { - cy.get("div.pf-v5-c-toolbar__group.pf-m-toggle-group.pf-m-filter-group.pf-m-show") - .find("div.pf-v5-c-select") - .click(); - if ( - filterName == businessService || - filterName == repositoryType || - filterName == artifact || - filterName == owner - ) { - // ul[role=listbox] > li is for the Application Inventory page. - // span.pf-c-check__label is for the Copy assessment page. - cy.get("ul[role=listbox] > li, span.pf-v5-c-check__label").contains(searchText).click(); - } - if (filterName == tag || filterName == credentialType) { - if (Array.isArray(searchText)) { - searchText.forEach(function (searchTextValue) { - cy.get("div.pf-v5-c-select__menu > fieldset > label > span") - .contains(searchTextValue) - .click(); - }); - } else { - cy.get("div.pf-v5-c-select__menu").contains(searchText).click(); - } - } - } else { - if (Array.isArray(searchText)) { - searchText.forEach(function (searchTextValue) { - if (identifiedRisk) { - filterInputText(searchTextValue, 1); - } else { - filterInputText(searchTextValue, 0); - } - }); - } else { - if (identifiedRisk) { - filterInputText(searchText, 1); - } else { - filterInputText(searchText, 0); - } - } + const isStandardKnownFilter = [ + businessServiceLower, + businessService, + repositoryType, + artifact, + owner, + ].includes(filterName); + const isSpecialKnownFilter = [tag, credentialType].includes(filterName); + + if (!Array.isArray(searchText)) { + searchText = [searchText]; + } + + if (!isStandardKnownFilter && !isSpecialKnownFilter) { + searchText.forEach((searchTextValue) => filterInputText(searchTextValue, +identifiedRisk)); + cy.wait(4000); + return; + } + + cy.get(filterDropDownContainer).find(filterDropDown).click(); + + if (isStandardKnownFilter) { + searchText.forEach((searchTextValue) => { + cy.get(standardFilter).contains(searchTextValue).click(); + }); + } + + if (isSpecialKnownFilter) { + searchText.forEach((searchTextValue) => { + cy.get(specialFilter).contains(searchTextValue).click(); + }); } + cy.wait(4000); } @@ -1272,16 +1244,6 @@ export function deleteAllStakeholders(): void { deleteAllItems(stakeHoldersTable); } -export async function deleteAllCredentials() { - Credentials.openList(); - deleteAllItems(); -} - -export function deleteAllJobfunctions(cancel = false): void { - Jobfunctions.openList(); - deleteAllItems(); -} - export function deleteApplicationTableRows(): void { navigate_to_application_inventory(); deleteAllRows(); @@ -1547,10 +1509,6 @@ export function enumKeys(obj: O): return Object.keys(obj).filter((k) => Number.isNaN(+k)) as K[]; } -export function isRwxEnabled(): boolean { - return Cypress.env("rwx_enabled"); -} - export function getUrl(): string { return window.location.href; }