diff --git a/tests/e2e/configs/inversify.types.ts b/tests/e2e/configs/inversify.types.ts index 6308302ce82..dd44525a41e 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 d607508ef5f..1d0f6d4ad6d 100644 --- a/tests/e2e/pageobjects/dashboard/UserPreferences.ts +++ b/tests/e2e/pageobjects/dashboard/UserPreferences.ts @@ -13,6 +13,7 @@ import { CLASSES } from '../../configs/inversify.types'; import { By } from 'selenium-webdriver'; import { DriverHelper } from '../../utils/DriverHelper'; import { Logger } from '../../utils/Logger'; +import { GitProviderType } from '../../constants/FACTORY_TEST_CONSTANTS'; @injectable() export class UserPreferences { @@ -21,7 +22,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 +34,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 +74,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 +111,21 @@ export class UserPreferences { await this.driverHelper.waitAndClick(UserPreferences.SSH_KEY_TAB); await this.driverHelper.waitVisibility(UserPreferences.ADD_NEW_SSH_KEY_BUTTON); } + + getServiceConfig(service: string): string { + const gitService: { [key: string]: string } = { + [GitProviderType.GITHUB]: 'GitHub', + [GitProviderType.GITLAB]: 'GitLab', + [GitProviderType.AZURE_DEVOPS]: 'Microsoft Azure DevOps', + [GitProviderType.BITBUCKET_CLOUD_OAUTH2]: 'Bitbucket Cloud', + [GitProviderType.BITBUCKET_SERVER_OAUTH1]: 'Bitbucket Server', + [GitProviderType.BITBUCKET_SERVER_OAUTH2]: 'Bitbucket Server' + }; + + return gitService[service]; + } + + 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 00000000000..364e49f69ce --- /dev/null +++ b/tests/e2e/specs/miscellaneous/RevokeOauth.spec.ts @@ -0,0 +1,32 @@ +/** ******************************************************************* + * 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 { UserPreferences } from '../../pageobjects/dashboard/UserPreferences'; +import { FACTORY_TEST_CONSTANTS } from '../../constants/FACTORY_TEST_CONSTANTS'; + +suite('"Revoke OAuth" test', function (): void { + const loginTests: LoginTests = e2eContainer.get(CLASSES.LoginTests); + const userPreferences: UserPreferences = e2eContainer.get(CLASSES.UserPreferences); + const gitService: string = FACTORY_TEST_CONSTANTS.TS_SELENIUM_FACTORY_GIT_PROVIDER || 'github'; + + suiteSetup('Login', async function (): Promise { + await loginTests.loginIntoChe(); + }); + + test('Revoke OAuth test', async function (): Promise { + await userPreferences.openUserPreferencesPage(); + await userPreferences.openGitServicesTab(); + + const selectedService: string = userPreferences.getServiceConfig(gitService); + await userPreferences.revokeGitService(selectedService); + }); +}); diff --git a/tests/e2e/specs/miscellaneous/UserPreferencesTest.spec.ts b/tests/e2e/specs/miscellaneous/UserPreferencesTest.spec.ts index c4f28353760..cd22c46eeb5 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(); });