From 227657dd0285883bbe82fe3607aa78b58631eee7 Mon Sep 17 00:00:00 2001 From: Skoryk Serhii Date: Thu, 11 Jan 2024 15:45:49 +0200 Subject: [PATCH] add RevokeOauth test --- tests/e2e/configs/inversify.config.ts | 2 +- tests/e2e/configs/inversify.types.ts | 3 +- .../pageobjects/dashboard/UserPreferences.ts | 28 +++++++++++++++++ .../specs/miscellaneous/RevokeOauth.spec.ts | 31 +++++++++++++++++++ .../miscellaneous/UserPreferencesTest.spec.ts | 2 +- 5 files changed, 63 insertions(+), 3 deletions(-) create mode 100644 tests/e2e/specs/miscellaneous/RevokeOauth.spec.ts diff --git a/tests/e2e/configs/inversify.config.ts b/tests/e2e/configs/inversify.config.ts index 0ef3b06aafa0..9f647c6de54c 100644 --- a/tests/e2e/configs/inversify.config.ts +++ b/tests/e2e/configs/inversify.config.ts @@ -52,7 +52,7 @@ import { Main as Generator } from '@eclipse-che/che-devworkspace-generator/lib/m import { ContainerTerminal, KubernetesCommandLineToolsExecutor } from '../utils/KubernetesCommandLineToolsExecutor'; import { ShellExecutor } from '../utils/ShellExecutor'; import { UserPreferences } from '../pageobjects/dashboard/UserPreferences'; -import { WebTerminalPage } from "../pageobjects/webterminal/WebTerminalPage"; +import { WebTerminalPage } from '../pageobjects/webterminal/WebTerminalPage'; const e2eContainer: Container = new Container({ defaultScope: 'Transient', skipBaseClassChecks: true }); diff --git a/tests/e2e/configs/inversify.types.ts b/tests/e2e/configs/inversify.types.ts index 6308302ce820..dd44525a41ec 100644 --- a/tests/e2e/configs/inversify.types.ts +++ b/tests/e2e/configs/inversify.types.ts @@ -49,7 +49,8 @@ const CLASSES: any = { ShellExecutor: 'ShellExecutor', ContainerTerminal: 'ContainerTerminal', UserPreferences: 'UserPreferences', - WebTerminalPage: 'WebTerminalPage' + WebTerminalPage: 'WebTerminalPage', + RevokeOauthPage: 'RevokeOauthPage' }; const EXTERNAL_CLASSES: any = { diff --git a/tests/e2e/pageobjects/dashboard/UserPreferences.ts b/tests/e2e/pageobjects/dashboard/UserPreferences.ts index d607508ef5f5..f87929eddd59 100644 --- a/tests/e2e/pageobjects/dashboard/UserPreferences.ts +++ b/tests/e2e/pageobjects/dashboard/UserPreferences.ts @@ -21,7 +21,9 @@ export class UserPreferences { private static readonly USER_PREFERENCES_PAGE: By = By.xpath('//h1[text()="User Preferences"]'); private static readonly CONTAINER_REGISTRIES_TAB: By = By.xpath('//button[text()="Container Registries"]'); + private static readonly GIT_SERVICES_TAB: By = By.xpath('//button[text()="Git Services"]'); + private static readonly GIT_SERVICES_REVOKE_BUTTON: By = By.xpath('//button[text()="Revoke"]'); private static readonly PAT_TAB: By = By.xpath('//button[text()="Personal Access Tokens"]'); private static readonly ADD_NEW_PAT_BUTTON: By = By.xpath('//button[text()="Add Personal Access Token"]'); @@ -31,6 +33,10 @@ export class UserPreferences { private static readonly SSH_KEY_TAB: By = By.xpath('//button[text()="SSH Keys"]'); private static readonly ADD_NEW_SSH_KEY_BUTTON: By = By.xpath('//button[text()="Add SSH Key"]'); + private static readonly CONFIRMATION_WINDOW: By = By.xpath('//span[text()="Revoke Git Services"]'); + private static readonly DELETE_CONFIRMATION_CHECKBOX: By = By.xpath('//input[@data-testid="warning-info-checkbox"]'); + private static readonly DELETE_ITEM_BUTTON_ENABLED: By = By.xpath('//button[@data-testid="revoke-button" and not(@disabled)]'); + constructor( @inject(CLASSES.DriverHelper) readonly driverHelper: DriverHelper @@ -67,6 +73,24 @@ export class UserPreferences { await this.driverHelper.waitAndClick(UserPreferences.GIT_SERVICES_TAB); } + async revokeGitService(servicesName: string): Promise { + Logger.debug(); + + await this.selectListItem(servicesName); + await this.driverHelper.waitAndClick(UserPreferences.GIT_SERVICES_REVOKE_BUTTON); + + await this.driverHelper.waitVisibility(UserPreferences.CONFIRMATION_WINDOW); + await this.driverHelper.waitAndClick(UserPreferences.DELETE_CONFIRMATION_CHECKBOX); + await this.driverHelper.waitAndClick(UserPreferences.DELETE_ITEM_BUTTON_ENABLED); + await this.driverHelper.waitDisappearance(this.getServicesListItemLocator(servicesName)); + } + + async selectListItem(servicesName: string): Promise { + Logger.debug(`of the '${servicesName}' list item`); + + await this.driverHelper.waitAndClick(this.getServicesListItemLocator(servicesName)); + } + async openPatTab(): Promise { Logger.debug(); @@ -86,4 +110,8 @@ export class UserPreferences { await this.driverHelper.waitAndClick(UserPreferences.SSH_KEY_TAB); await this.driverHelper.waitVisibility(UserPreferences.ADD_NEW_SSH_KEY_BUTTON); } + + private getServicesListItemLocator(servicesName: string): By { + return By.xpath(`//tr[td[text()='${servicesName}']]//input`); + } } diff --git a/tests/e2e/specs/miscellaneous/RevokeOauth.spec.ts b/tests/e2e/specs/miscellaneous/RevokeOauth.spec.ts new file mode 100644 index 000000000000..37a90cc9e1c7 --- /dev/null +++ b/tests/e2e/specs/miscellaneous/RevokeOauth.spec.ts @@ -0,0 +1,31 @@ +/** ******************************************************************* + * copyright (c) 2020-2024 Red Hat, Inc. + * + * This program and the accompanying materials are made + * available under the terms of the Eclipse Public License 2.0 + * which is available at https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + **********************************************************************/ +import { e2eContainer } from '../../configs/inversify.config'; +import { CLASSES } from '../../configs/inversify.types'; +import { LoginTests } from '../../tests-library/LoginTests'; +import { BASE_TEST_CONSTANTS } from '../../constants/BASE_TEST_CONSTANTS'; +import { UserPreferences } from '../../pageobjects/dashboard/UserPreferences'; + +suite(`"Check User Preferences page" test ${BASE_TEST_CONSTANTS.TEST_ENVIRONMENT}`, function (): void { + const loginTests: LoginTests = e2eContainer.get(CLASSES.LoginTests); + const userPreferences: UserPreferences = e2eContainer.get(CLASSES.UserPreferences); + + suiteSetup('Login', async function (): Promise { + await loginTests.loginIntoChe(); + }); + + test('Check user preferences page', async function (): Promise { + await userPreferences.openUserPreferencesPage(); + await userPreferences.checkTabsAvailability(); + + await userPreferences.openGitServicesTab(); + await userPreferences.revokeGitService('GitHub'); + }); +}); diff --git a/tests/e2e/specs/miscellaneous/UserPreferencesTest.spec.ts b/tests/e2e/specs/miscellaneous/UserPreferencesTest.spec.ts index c4f283537609..cd22c46eeb51 100644 --- a/tests/e2e/specs/miscellaneous/UserPreferencesTest.spec.ts +++ b/tests/e2e/specs/miscellaneous/UserPreferencesTest.spec.ts @@ -21,7 +21,7 @@ suite(`"Check User Preferences page" test ${BASE_TEST_CONSTANTS.TEST_ENVIRONMENT await loginTests.loginIntoChe(); }); - test(`Check user preferences page`, async function (): Promise { + test('Check user preferences page', async function (): Promise { await userPreferences.openUserPreferencesPage(); await userPreferences.checkTabsAvailability(); });