|
| 1 | +/** ******************************************************************* |
| 2 | + * copyright (c) 2025 Red Hat, Inc. |
| 3 | + * |
| 4 | + * This program and the accompanying materials are made |
| 5 | + * available under the terms of the Eclipse Public License 2.0 |
| 6 | + * which is available at https://www.eclipse.org/legal/epl-2.0/ |
| 7 | + * |
| 8 | + * SPDX-License-Identifier: EPL-2.0 |
| 9 | + **********************************************************************/ |
| 10 | + |
| 11 | +import { ViewSection } from 'monaco-page-objects'; |
| 12 | +import { ProjectAndFileTests } from '../../tests-library/ProjectAndFileTests'; |
| 13 | +import { CLASSES, TYPES } from '../../configs/inversify.types'; |
| 14 | +import { e2eContainer } from '../../configs/inversify.config'; |
| 15 | +import { WorkspaceHandlingTests } from '../../tests-library/WorkspaceHandlingTests'; |
| 16 | +import { registerRunningWorkspace } from '../MochaHooks'; |
| 17 | +import { LoginTests } from '../../tests-library/LoginTests'; |
| 18 | +import { StringUtil } from '../../utils/StringUtil'; |
| 19 | +import { FACTORY_TEST_CONSTANTS } from '../../constants/FACTORY_TEST_CONSTANTS'; |
| 20 | +import { BrowserTabsUtil } from '../../utils/BrowserTabsUtil'; |
| 21 | +import { expect } from 'chai'; |
| 22 | +import { BASE_TEST_CONSTANTS } from '../../constants/BASE_TEST_CONSTANTS'; |
| 23 | +import { UserPreferences } from '../../pageobjects/dashboard/UserPreferences'; |
| 24 | +import { Dashboard } from '../../pageobjects/dashboard/Dashboard'; |
| 25 | +import { ITestWorkspaceUtil } from '../../utils/workspace/ITestWorkspaceUtil'; |
| 26 | +import { Logger } from '../../utils/Logger'; |
| 27 | + |
| 28 | +suite(`The SshUrlNoOauthPatFactory userstory ${BASE_TEST_CONSTANTS.TEST_ENVIRONMENT}`, function (): void { |
| 29 | + const projectAndFileTests: ProjectAndFileTests = e2eContainer.get(CLASSES.ProjectAndFileTests); |
| 30 | + const workspaceHandlingTests: WorkspaceHandlingTests = e2eContainer.get(CLASSES.WorkspaceHandlingTests); |
| 31 | + const loginTests: LoginTests = e2eContainer.get(CLASSES.LoginTests); |
| 32 | + const browserTabsUtil: BrowserTabsUtil = e2eContainer.get(CLASSES.BrowserTabsUtil); |
| 33 | + const userPreferences: UserPreferences = e2eContainer.get(CLASSES.UserPreferences); |
| 34 | + const dashboard: Dashboard = e2eContainer.get(CLASSES.Dashboard); |
| 35 | + const testWorkspaceUtil: ITestWorkspaceUtil = e2eContainer.get(TYPES.WorkspaceUtil); |
| 36 | + const factoryUrl: string = |
| 37 | + FACTORY_TEST_CONSTANTS.TS_SELENIUM_FACTORY_GIT_REPO_URL || |
| 38 | + 'ssh://[email protected]/~admin/private-bb-repo.git'; |
| 39 | + const privateSshKeyPath: string = 'resources/factory/pr-k.txt'; |
| 40 | + const publicSshKeyPath: string = 'resources/factory/pub-k.txt'; |
| 41 | + let projectSection: ViewSection; |
| 42 | + |
| 43 | + async function deleteSshKeys(): Promise<void> { |
| 44 | + Logger.debug('Deleting SSH keys if they are present'); |
| 45 | + await userPreferences.openUserPreferencesPage(); |
| 46 | + await userPreferences.openSshKeyTab(); |
| 47 | + if (await userPreferences.isSshKeyPresent()) { |
| 48 | + await userPreferences.deleteSshKeys(); |
| 49 | + } |
| 50 | + } |
| 51 | + |
| 52 | + suite(`Create workspace from factory:${factoryUrl}`, function (): void { |
| 53 | + suiteSetup('Login', async function (): Promise<void> { |
| 54 | + await loginTests.loginIntoChe(); |
| 55 | + await deleteSshKeys(); |
| 56 | + }); |
| 57 | + test('Add SSH keys', async function (): Promise<void> { |
| 58 | + await userPreferences.openUserPreferencesPage(); |
| 59 | + await userPreferences.openSshKeyTab(); |
| 60 | + await userPreferences.addSshKeys(privateSshKeyPath, publicSshKeyPath); |
| 61 | + }); |
| 62 | + test(`Create and open new workspace from factory:${factoryUrl}`, async function (): Promise<void> { |
| 63 | + await workspaceHandlingTests.createAndOpenWorkspaceFromGitRepository(factoryUrl); |
| 64 | + }); |
| 65 | + test('Obtain workspace name from workspace loader page', async function (): Promise<void> { |
| 66 | + await workspaceHandlingTests.obtainWorkspaceNameFromStartingPage(); |
| 67 | + }); |
| 68 | + test('Register running workspace', function (): void { |
| 69 | + registerRunningWorkspace(WorkspaceHandlingTests.getWorkspaceName()); |
| 70 | + }); |
| 71 | + test('Wait workspace readiness', async function (): Promise<void> { |
| 72 | + await projectAndFileTests.waitWorkspaceReadinessForCheCodeEditor(); |
| 73 | + }); |
| 74 | + test('Check a project folder has been created', async function (): Promise<void> { |
| 75 | + const projectName: string = FACTORY_TEST_CONSTANTS.TS_SELENIUM_PROJECT_NAME || StringUtil.getProjectNameFromGitUrl(factoryUrl); |
| 76 | + projectSection = await projectAndFileTests.getProjectViewSession(); |
| 77 | + expect(await projectAndFileTests.getProjectTreeItem(projectSection, projectName), 'Project folder was not imported').not |
| 78 | + .undefined; |
| 79 | + }); |
| 80 | + test('Accept the project as a trusted one', async function (): Promise<void> { |
| 81 | + await projectAndFileTests.performTrustAuthorDialog(); |
| 82 | + }); |
| 83 | + test('Check the project files was imported', async function (): Promise<void> { |
| 84 | + expect( |
| 85 | + await projectAndFileTests.getProjectTreeItem(projectSection, BASE_TEST_CONSTANTS.TS_SELENIUM_PROJECT_ROOT_FILE_NAME), |
| 86 | + 'Project files were not imported' |
| 87 | + ).not.undefined; |
| 88 | + }); |
| 89 | + suiteTeardown('Delete SSH keys', async function (): Promise<void> { |
| 90 | + await dashboard.openDashboard(); |
| 91 | + await deleteSshKeys(); |
| 92 | + }); |
| 93 | + suiteTeardown('Stop and delete the workspace by APII', async function (): Promise<void> { |
| 94 | + await browserTabsUtil.closeAllTabsExceptCurrent(); |
| 95 | + await testWorkspaceUtil.stopAndDeleteWorkspaceByName(WorkspaceHandlingTests.getWorkspaceName()); |
| 96 | + }); |
| 97 | + suiteTeardown('Unregister running workspace', function (): void { |
| 98 | + registerRunningWorkspace(''); |
| 99 | + }); |
| 100 | + }); |
| 101 | +}); |
0 commit comments