Skip to content

Commit

Permalink
[RFR] Refactored filter function to get multiple values (#1080)
Browse files Browse the repository at this point in the history
* Refactored filter function to get multiple values

Signed-off-by: Igor Braginsky <[email protected]>

* Fixed issue when targets are multiple

Signed-off-by: Igor Braginsky <[email protected]>

* Changed issues comparison, now uses issue`s name only

Signed-off-by: Igor Braginsky <[email protected]>

---------

Signed-off-by: Igor Braginsky <[email protected]>
  • Loading branch information
ibragins authored Apr 30, 2024
1 parent caf4bd8 commit 132feb5
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 24 deletions.
38 changes: 35 additions & 3 deletions cypress/e2e/models/migration/dynamic-report/issues/issues.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {
click,
clickByText,
getUniqueElementsFromSecondArray,
getUrl,
inputText,
performWithin,
Expand Down Expand Up @@ -54,6 +55,29 @@ export class Issues {
clickByText(button, applicationName);
}

public static applyAndValidateFilter(
filterType: issueFilter,
filterValues: string[],
issuesExpected: AppIssue[],
issuesNotExpected?: AppIssue[],
isSingle = false
) {
filterValues.forEach((value) => {
Issues.applyFilter(filterType, value, isSingle);
});
issuesExpected.forEach((issue) => {
Issues.validateFilter(issue, isSingle);
});

if (issuesNotExpected.length > 0) {
getUniqueElementsFromSecondArray(issuesExpected, issuesNotExpected).forEach(
(issue: AppIssue) => {
validateTextPresence(issueColumns.issue, issue.name, false);
}
);
}
}

public static validateFilter(issue: AppIssue, isSingle = false): void {
cy.contains(issue.name)
.closest(trTag)
Expand All @@ -62,9 +86,10 @@ export class Issues {
validateTextPresence(issueColumns.category, issue.category);
validateTextPresence(issueColumns.source, issue.source);
cy.get(issueColumns.target).within(() => {
issue.targets.forEach((currentTarget) => {
validateTextPresence(liTag, currentTarget);
});
validateTextPresence(liTag, issue.targets[0]);
if (issue.targets.length > 1) {
clickByText(span, /more/i);
}
});
validateNumberPresence(issueColumns.effort, issue.effort);
if (!isSingle) {
Expand All @@ -73,6 +98,13 @@ export class Issues {
validateAnyNumberPresence(singleApplicationColumns.files);
}
});
if (issue.targets.length > 1) {
for (let i = 1; i < issue.targets.length; i++) {
cy.get("div.pf-v5-c-popover__content").within(() => {
validateTextPresence("span.pf-v5-c-label__text", issue.targets[i]);
});
}
}
}

public static applyFilter(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,9 @@ import {
deleteByList,
getRandomAnalysisData,
getRandomApplicationData,
getUniqueElementsFromSecondArray,
login,
validatePagination,
validateSortBy,
validateTextPresence,
} from "../../../../../utils/utils";
import { BusinessServices } from "../../../../models/migration/controls/businessservices";
import * as data from "../../../../../utils/data_utils";
Expand All @@ -25,7 +23,7 @@ import { Issues } from "../../../../models/migration/dynamic-report/issues/issue
import { AppIssue } from "../../../../types/types";
import { AnalysisStatuses, issueFilter, SEC, tdTag, trTag } from "../../../../types/constants";
import { randomWordGenerator } from "../../../../../utils/data_utils";
import { issueColumns, rightSideBar } from "../../../../views/issue.view";
import { rightSideBar } from "../../../../views/issue.view";

describe(["@tier3"], "Filtering, sorting and pagination in Issues", function () {
const applicationsList: Analysis[] = [];
Expand Down Expand Up @@ -103,23 +101,27 @@ describe(["@tier3"], "Filtering, sorting and pagination in Issues", function ()
// Analyzing daytrader app for pagination test to generate issues more than 10.
const bookServerApp = applicationsList[0];
const dayTraderApp = applicationsList[6];
Analysis.analyzeAll(dayTraderApp);
Analysis.verifyAllAnalysisStatuses(AnalysisStatuses.completed);
Issues.openList(10, true);
Issues.applyFilter(issueFilter.appName, bookServerApp.name);
const bookServerIssues = this.analysisData["source_analysis_on_bookserverapp"]["issues"];
const dayTraderIssues = this.analysisData["source+dep_analysis_on_daytrader-app"]["issues"];
bookServerIssues.forEach((issue: AppIssue) => {
Issues.validateFilter(issue);
});

// Getting list of issues unique for daytrader app and making sure they are not present in the list while filtering issues by book server app
getUniqueElementsFromSecondArray(bookServerIssues, dayTraderIssues).forEach(
(issue: AppIssue) => {
validateTextPresence(issueColumns.issue, issue.name, false);
}
Analysis.analyzeAll(dayTraderApp);
Analysis.verifyAllAnalysisStatuses(AnalysisStatuses.completed);

Issues.openList(100, true);
Issues.applyAndValidateFilter(
issueFilter.appName,
[bookServerApp.name],
bookServerIssues,
dayTraderIssues
);
clearAllFilters();

Issues.applyAndValidateFilter(
issueFilter.appName,
[dayTraderApp.name],
dayTraderIssues,
bookServerIssues
);
clearAllFilters();
});

Expand Down
13 changes: 13 additions & 0 deletions cypress/fixtures/analysis.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,19 @@
"appName": "deps",
"storyPoints": 24,
"issues": [
{
"name": "File system - Java IO",
"category": "mandatory",
"source": "None",
"targets": ["cloud-readiness"],
"effort": 1,
"totalEffort": 2,
"incidents": 2,
"affectedFiles": 1,
"ruleSet": "cloud-readiness",
"rule": "local-storage-00001",
"labels": ["konveyor.io/source", "storage"]
},
{
"name": "The package 'javax' has been replaced by 'jakarta'.",
"category": "mandatory",
Expand Down
16 changes: 10 additions & 6 deletions cypress/utils/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ import {
getSpecialMigrationWavesTableSelector,
} from "../e2e/views/migration-wave.view";
import { manageCredentials, mavenCredential, sourceCredential } from "../e2e/views/analysis.view";
import * as ansiRegex from "ansi-regex";

const { _ } = Cypress;

Expand All @@ -134,7 +135,7 @@ export function clearInput(fieldID: string): void {

export function clickByText(
fieldId: string,
buttonText: string,
buttonText: string | ansiRegex,
isForced = true,
log = false
): void {
Expand Down Expand Up @@ -1884,13 +1885,16 @@ export function validateMtaVersionInUI(expectedVersion: string): void {
* @param arrB is an array of any type
* @return result
*/
export function getUniqueElementsFromSecondArray<T>(arrA: T[], arrB: T[]): T[] {
export function getUniqueElementsFromSecondArray<T extends { name: string }>(
arrA: T[],
arrB: T[]
): T[] {
const result: T[] = [];

for (const item of arrB) {
if (!arrA.includes(item)) {
const namesInArrA = arrA.map((item) => item.name);
arrB.forEach((item: T) => {
if (!namesInArrA.includes(item.name)) {
result.push(item);
}
}
});
return result;
}

0 comments on commit 132feb5

Please sign in to comment.