Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[RFR] Minor code quality improvements #839

Merged
merged 1 commit into from
Nov 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 0 additions & 11 deletions cypress/e2e/models/administration/general/generalConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
10 changes: 2 additions & 8 deletions cypress/e2e/models/migration/applicationinventory/analysis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,9 @@ import {
assessAppButton,
createAppButton,
SEC,
analysis,
analyzeButton,
reviewAppButton,
migration,
application,
} from "../../../types/constants";
import { navMenu, navTab } from "../../../views/menu.view";
import {
Expand Down
27 changes: 7 additions & 20 deletions cypress/utils/data_utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};
Expand Down Expand Up @@ -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];
Expand Down
93 changes: 12 additions & 81 deletions cypress/utils/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ import {
credentialType,
artifact,
repositoryType,
analysis,
owner,
JiraType,
migration,
Expand Down Expand Up @@ -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";
Expand Down Expand Up @@ -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<string> {
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<string> {
selectItemsPerPage(100);
let itemList = [];
Expand Down Expand Up @@ -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" }
Expand All @@ -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" }
Expand All @@ -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",
});
Expand All @@ -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();

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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? },
Expand Down Expand Up @@ -1101,16 +1042,6 @@ export function createMultipleApplicationsWithBSandTags(
return applicationList;
}

export function createApplicationObjects(numberOfObjects: number): Array<Assessment> {
let applicationObjectsList: Array<Assessment> = [];
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<T extends Deletable>(array: T[]): void {
Expand Down Expand Up @@ -1418,29 +1349,29 @@ 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) {
xmlDOM
.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);
});
}
Expand Down
Loading