From 357bc37e033889caee288949c3e6f2ef3beff769 Mon Sep 17 00:00:00 2001 From: Alejandro Brugarolas <117646518+abrugaro@users.noreply.github.com> Date: Tue, 28 Nov 2023 20:55:16 +0100 Subject: [PATCH] Minor code quality improvements (#839) Signed-off-by: Alejandro Brugarolas --- .../administration/general/generalConfig.ts | 11 --- .../applicationinventory/analysis.ts | 10 +- .../applicationinventory/application.ts | 2 - cypress/utils/data_utils.ts | 27 ++---- cypress/utils/utils.ts | 93 +++---------------- 5 files changed, 21 insertions(+), 122 deletions(-) diff --git a/cypress/e2e/models/administration/general/generalConfig.ts b/cypress/e2e/models/administration/general/generalConfig.ts index 2c37254b4..3be7391fe 100644 --- a/cypress/e2e/models/administration/general/generalConfig.ts +++ b/cypress/e2e/models/administration/general/generalConfig.ts @@ -4,19 +4,8 @@ import { navMenu } from "../../../views/menu.view"; import { switchToggle } from "../../../views/reports.view"; export class GeneralConfig { - private static instance: GeneralConfig; - static downloadReport: boolean; static fullUrl = Cypress.env("tackleUrl") + "/general"; - // GeneralConfig class is singleton, which means that only one object of this class can be created - // This function is required to get GeneralConfig instance in any part of the code - public static getInstance(): GeneralConfig { - if (!GeneralConfig.instance) { - GeneralConfig.instance = new GeneralConfig(); - } - return GeneralConfig.instance; - } - static open(): void { cy.url().then(($url) => { if ($url != GeneralConfig.fullUrl) { diff --git a/cypress/e2e/models/migration/applicationinventory/analysis.ts b/cypress/e2e/models/migration/applicationinventory/analysis.ts index dbc0d9dfc..e6412c1c1 100644 --- a/cypress/e2e/models/migration/applicationinventory/analysis.ts +++ b/cypress/e2e/models/migration/applicationinventory/analysis.ts @@ -230,11 +230,13 @@ export class Analysis extends Application { inputText(enterPackageName, this.manuallyAnalyzePackages); clickByText(addButton, "Add"); } + if (this.excludePackages) { click(excludePackagesSwitch); inputText(enterPackageNameToExclude, this.excludePackages); clickByText(addButton, "Add"); } + if (this.openSourceLibraries) { click("#oss"); } @@ -397,14 +399,6 @@ export class Analysis extends Application { }); } - validateTransactionReport(): void { - cy.get(fileName + " > a") - .should("contain", this.appName) - .click(); - cy.get(tabsPanel).contains("Transactions").click(); - cy.get("div[class='main']").should("contain", "Transactions Report"); - } - validateExcludedPackages(text?: string): void { // Click on App name // then Application Details tab diff --git a/cypress/e2e/models/migration/applicationinventory/application.ts b/cypress/e2e/models/migration/applicationinventory/application.ts index 6c3ccd2eb..d22f745b3 100644 --- a/cypress/e2e/models/migration/applicationinventory/application.ts +++ b/cypress/e2e/models/migration/applicationinventory/application.ts @@ -22,11 +22,9 @@ import { assessAppButton, createAppButton, SEC, - analysis, analyzeButton, reviewAppButton, migration, - application, } from "../../../types/constants"; import { navMenu, navTab } from "../../../views/menu.view"; import { diff --git a/cypress/utils/data_utils.ts b/cypress/utils/data_utils.ts index bb3ba064d..3ca16cd42 100644 --- a/cypress/utils/data_utils.ts +++ b/cypress/utils/data_utils.ts @@ -236,22 +236,20 @@ export function getJiraConnectionData( isInsecure?: boolean, useTestingAccount = false ): JiraConnectionData { - let name: string; - let url: string; + let url = getRandomUrl(6); let type = jiraType; - if (type === JiraType.cloud) { - url = useTestingAccount ? Cypress.env("jira_atlassian_cloud_url") : getRandomUrl(6); - } else { - url = useTestingAccount ? Cypress.env("jira_stage_datacenter_url") : getRandomUrl(6); + if (useTestingAccount) { + url = + type === JiraType.cloud + ? Cypress.env("jira_atlassian_cloud_url") + : Cypress.env("jira_stage_datacenter_url"); } - name = "Jira_" + getRandomWord(5); - return { credential: jiraCredential, isInsecure: isInsecure, - name: name, + name: "Jira_" + getRandomWord(5), type: type, url: url, }; @@ -310,17 +308,6 @@ export function getRandomProxyData(credentials?: CredentialsData): ProxyData { }; } -export function getRealProxyData(credentials?: CredentialsData): ProxyData { - return { - excludeList: ["127.0.0.1", "cnn.com"], - credentials: credentials, - httpEnabled: false, - hostname: "rhev-node-12.rdu2.scalelab.redhat.com", - port: (3128).toString(), - httpsEnabled: true, - }; -} - export function getRandomUserData(): UserData { let fullName = getFullName(); let firstName = fullName.split(" ")[0]; diff --git a/cypress/utils/utils.ts b/cypress/utils/utils.ts index 09e85836d..0395db8af 100644 --- a/cypress/utils/utils.ts +++ b/cypress/utils/utils.ts @@ -45,7 +45,6 @@ import { credentialType, artifact, repositoryType, - analysis, owner, JiraType, migration, @@ -89,7 +88,6 @@ import { CredentialsMaven } from "../e2e/models/administration/credentials/crede import { CredentialsSourceControlUsername } from "../e2e/models/administration/credentials/credentialsSourceControlUsername"; import { CredentialsSourceControlKey } from "../e2e/models/administration/credentials/credentialsSourceControlKey"; import { switchToggle } from "../e2e/views/reports.view"; -import { MigrationWaveView } from "../e2e/views/migration-wave.view"; import Chainable = Cypress.Chainable; import { MigrationWave } from "../e2e/models/migration/migration-waves/migration-wave"; import { Jira } from "../e2e/models/administration/jira-connection/jira"; @@ -446,41 +444,6 @@ export function generateRandomDateRange( }; } -export function sortAscCopyAssessmentTable(sortCriteria: string): void { - cy.get(`.pf-m-compact > thead > tr > th[data-label="${sortCriteria}"]`).then(($tableHeader) => { - if ( - $tableHeader.attr("aria-sort") === "descending" || - $tableHeader.attr("aria-sort") === "none" - ) { - $tableHeader.find("button").trigger("click"); - } - }); -} - -export function sortDescCopyAssessmentTable(sortCriteria: string): void { - cy.get(`.pf-m-compact > thead > tr > th[data-label="${sortCriteria}"]`).then(($tableHeader) => { - if ( - $tableHeader.attr("aria-sort") === "ascending" || - $tableHeader.attr("aria-sort") === "none" - ) { - $tableHeader.find("button").trigger("click"); - } - }); -} - -export function getColumnDataforCopyAssessmentTable(columnName: string): Array { - selectItemsPerPage(100); - cy.wait(4000); - let itemList = []; - cy.get(".pf-m-compact > tbody > tr") - .not(".pf-c-table__expandable-row") - .find(`td[data-label="${columnName}"]`) - .each(($ele) => { - if ($ele.text() !== "") itemList.push($ele.text().toString().toLowerCase()); - }); - return itemList; -} - export function getTableColumnData(columnName: string): Array { selectItemsPerPage(100); let itemList = []; @@ -651,12 +614,7 @@ export function importApplication(fileName: string, disableAutoCreation?: boolea checkSuccessAlert(commonView.successAlertMessage, `Success! file saved to be processed.`); } -export function uploadXml(fileName: string, customSelector?: string): void { - let selector = 'input[type="file"]'; - if (customSelector) { - selector = customSelector; - } - // Uplaod any file +export function uploadXml(fileName: string, selector = 'input[type="file"]'): void { cy.get(selector, { timeout: 5 * SEC }).attachFile( { filePath: fileName, mimeType: "text/xml", encoding: "utf-8" }, { subjectType: "drag-n-drop" } @@ -665,7 +623,6 @@ export function uploadXml(fileName: string, customSelector?: string): void { } export function uploadApplications(fileName: string): void { - // Uplaod any file cy.get('input[type="file"]', { timeout: 5 * SEC }).attachFile( { filePath: fileName, encoding: "binary" }, { subjectType: "drag-n-drop" } @@ -674,7 +631,6 @@ export function uploadApplications(fileName: string): void { } export function uploadFile(fileName: string): void { - // Uplaod any file cy.get('input[type="file"]', { timeout: 5 * SEC }).attachFile(fileName, { subjectType: "drag-n-drop", }); @@ -686,7 +642,7 @@ export function navigate_to_application_inventory(): void { clickByText(navMenu, applicationInventory); } -export function application_inventory_kebab_menu(menu): void { +export function application_inventory_kebab_menu(menu: string): void { // The value for menu could be one of {Import, Manage imports, Delete, Manage credentials} navigate_to_application_inventory(); @@ -748,12 +704,6 @@ export function verifyImportErrorMsg(errorMsg: any): void { } } -export function migration_wave_kebab_menu(menu): void { - // The value for menu could be one of {Export to Issue Manager, Delete} - cy.get(actionButton).eq(1).click({ force: true }); - cy.get(commonView.kebabMenuItem).contains(menu).click({ force: true }); -} - // Perform edit/delete action on the specified row selector by clicking a text button export function performRowAction(itemName: string, action: string): void { // itemName is text to be searched on the screen (like credentials name, stakeholder name, etc) @@ -991,15 +941,6 @@ export function generateMultipleCredentials(amount: number): Credentials[] { return createdCredentialsList; } -export function getRowsAmount(): number { - let amount: number; - cy.get(commonView.appTable).get("tbody").find(trTag).as("rowsIdentifier"); - cy.get("@rowsIdentifier").then(($tableRows) => { - amount = $tableRows.length; - }); - return amount; -} - export function getRandomApplicationData( appName?, options?: { sourceData?; binaryData? }, @@ -1101,16 +1042,6 @@ export function createMultipleApplicationsWithBSandTags( return applicationList; } -export function createApplicationObjects(numberOfObjects: number): Array { - let applicationObjectsList: Array = []; - for (let i = 0; i < numberOfObjects; i++) { - // Create an object of application - const application = new Assessment(getRandomApplicationData()); - applicationObjectsList.push(application); - } - return applicationObjectsList; -} - type Deletable = { delete: () => void }; export function deleteByList(array: T[]): void { @@ -1418,9 +1349,10 @@ export function writeMavenSettingsFile(username: string, password: string, url?: cy.writeFile("cypress/fixtures/xml/settings.xml", ""); return; } - var xml = data.toString(); const parser = new DOMParser(); - const xmlDOM = parser.parseFromString(xml, "text/xml"); + const xmlDOM = parser.parseFromString(data.toString(), "text/xml"); + const serializer = new XMLSerializer(); + xmlDOM.getElementsByTagName("username")[0].childNodes[0].nodeValue = username; xmlDOM.getElementsByTagName("password")[0].childNodes[0].nodeValue = password; if (url) { @@ -1428,19 +1360,18 @@ export function writeMavenSettingsFile(username: string, password: string, url?: .getElementsByTagName("repository")[1] .getElementsByTagName("url")[0].childNodes[0].nodeValue = url; } - var serializer = new XMLSerializer(); - var writetofile = serializer.serializeToString(xmlDOM); - cy.writeFile("cypress/fixtures/xml/settings.xml", writetofile); + + cy.writeFile("cypress/fixtures/xml/settings.xml", serializer.serializeToString(xmlDOM)); }); } export function writeGpgKey(git_key): void { cy.readFile("cypress/fixtures/gpgkey").then((data) => { - var key = git_key; - var beginningKey: string = "-----BEGIN RSA PRIVATE KEY-----"; - var endingKey: string = "-----END RSA PRIVATE KEY-----"; - var keystring = key.toString().split(" ").join("\n"); - var gpgkey = beginningKey + "\n" + keystring + "\n" + endingKey; + const key = git_key; + const beginningKey = "-----BEGIN RSA PRIVATE KEY-----"; + const endingKey = "-----END RSA PRIVATE KEY-----"; + const keystring = key.toString().split(" ").join("\n"); + const gpgkey = beginningKey + "\n" + keystring + "\n" + endingKey; cy.writeFile("cypress/fixtures/gpgkey", gpgkey); }); }