From 6cf6c36fbe7f5930b4a671a3e2f35189f6e3878a Mon Sep 17 00:00:00 2001 From: Maayan Hadasi Date: Tue, 26 Nov 2024 15:30:48 +0200 Subject: [PATCH] Task manager: cancel analysis test cases Signed-off-by: Maayan Hadasi --- .../migration/task-manager/task-manager.ts | 28 ++++++- .../task-manager/cancel_task_negative.test.ts | 75 +++++++++++++++++++ cypress/e2e/types/constants.ts | 2 + cypress/e2e/views/common.view.ts | 1 + 4 files changed, 105 insertions(+), 1 deletion(-) create mode 100644 cypress/e2e/tests/migration/task-manager/cancel_task_negative.test.ts diff --git a/cypress/e2e/models/migration/task-manager/task-manager.ts b/cypress/e2e/models/migration/task-manager/task-manager.ts index aac517ad1..da05cc364 100644 --- a/cypress/e2e/models/migration/task-manager/task-manager.ts +++ b/cypress/e2e/models/migration/task-manager/task-manager.ts @@ -33,7 +33,12 @@ import { trTag, } from "../../../types/constants"; import { sideKebabMenu } from "../../../views/applicationinventory.view"; -import { actionMenuItem, searchButton, searchInput } from "../../../views/common.view"; +import { + actionMenuItem, + kebabActionButton, + searchButton, + searchInput, +} from "../../../views/common.view"; import { navMenu } from "../../../views/menu.view"; import { tasksStatusColumn } from "../../../views/taskmanager.view"; @@ -107,4 +112,25 @@ export class TaskManager { cy.get(actionMenuItem).contains("Cancel").should("not.be.enabled"); } } + + public static cancelAnalysiskByStatus( + appName: string, + status: TaskStatus, + enabled = true + ): void { + TaskManager.open(); + selectItemsPerPage(itemsPerPage); + cy.get(trTag) + .filter(':contains("' + TaskKind.analyzer + '")') + .filter(':contains("' + appName + '")') + .filter(':contains("' + status + '")') + .within(() => { + click(sideKebabMenu); + }); + if (enabled) { + cy.get(kebabActionButton).contains("Cancel").click(); + } else { + cy.get(kebabActionButton).contains("Cancel").should("not.be.enabled"); + } + } } diff --git a/cypress/e2e/tests/migration/task-manager/cancel_task_negative.test.ts b/cypress/e2e/tests/migration/task-manager/cancel_task_negative.test.ts new file mode 100644 index 000000000..72c91e2bf --- /dev/null +++ b/cypress/e2e/tests/migration/task-manager/cancel_task_negative.test.ts @@ -0,0 +1,75 @@ +/* +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 { getRandomUserData } from "../../../../utils/data_utils"; +import { + deleteApplicationTableRows, + getRandomAnalysisData, + getRandomApplicationData, + login, + logout, +} from "../../../../utils/utils"; +import { User } from "../../../models/keycloak/users/user"; +import { UserArchitect } from "../../../models/keycloak/users/userArchitect"; +import { UserMigrator } from "../../../models/keycloak/users/userMigrator"; +import { Analysis } from "../../../models/migration/applicationinventory/analysis"; +import { Application } from "../../../models/migration/applicationinventory/application"; +import { TaskManager } from "../../../models/migration/task-manager/task-manager"; +import { TaskKind, TaskStatus } from "../../../types/constants"; + +describe(["@tier2"], "Negative: cancel task created by another user", function () { + let userMigrator = new UserMigrator(getRandomUserData()); + let userArchitect = new UserArchitect(getRandomUserData()); + let applicationsList: Array = []; + + before("Login", function () { + // Creating RBAC users + User.loginKeycloakAdmin(); + userMigrator.create(); + userArchitect.create(); + + login(); + deleteApplicationTableRows(); + }); + + beforeEach("Load data", function () { + cy.fixture("application").then(function (appData) { + this.appData = appData; + }); + cy.fixture("analysis").then(function (analysisData) { + this.analysisData = analysisData; + }); + }); + + it("Bug MTA-3819: Run analysis by admin and cancel by migrator user - should not be allowed", function () { + let application = new Analysis( + getRandomApplicationData("bookserverApp", { + sourceData: this.appData["bookserver-app"], + }), + getRandomAnalysisData(this.analysisData["source_analysis_on_bookserverapp"]) + ); + application.create(); + application.analyze(); + + userMigrator.login(); + TaskManager.cancelAnalysiskByStatus(application.name, TaskStatus.running, false); + + logout(); + userArchitect.login(); + TaskManager.cancelAnalysiskByStatus(application.name, TaskStatus.running, false); + }); +}); diff --git a/cypress/e2e/types/constants.ts b/cypress/e2e/types/constants.ts index 30672fed6..2adcf8324 100644 --- a/cypress/e2e/types/constants.ts +++ b/cypress/e2e/types/constants.ts @@ -219,6 +219,8 @@ export enum TaskStatus { succeeded = "Succeeded", pending = "Pending", running = "Running", + ready = "Ready", + postponed = "Postponed", } export enum TaskKind { diff --git a/cypress/e2e/views/common.view.ts b/cypress/e2e/views/common.view.ts index fb5af97fb..bf431ab4f 100644 --- a/cypress/e2e/views/common.view.ts +++ b/cypress/e2e/views/common.view.ts @@ -57,6 +57,7 @@ export const helperBusiness = 'span[class*="helper-text__item"]'; export const stakeHolderGroupHelper = "div.pf-v5-c-helper-text"; export const actionMenuItem = "span.pf-v5-c-menu__item-text"; export const kebabMenuItem = "a.pf-c-dropdown__menu-item"; +export const kebabActionButton = "li.pf-v5-c-menu__list-item"; export const commonTable = "table.pf-v5-c-table.pf-m-grid-md"; export const tableRowActions = ".pf-v5-c-table__tr.actions-row"; export const plainButton = "button.pf-v5-c-button.pf-m-plain";