|
| 1 | +/** ******************************************************************* |
| 2 | + * copyright (c) 2020-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 | +import { e2eContainer } from '../../configs/inversify.config'; |
| 11 | +import { ViewSection } from 'monaco-page-objects'; |
| 12 | +import { CLASSES } from '../../configs/inversify.types'; |
| 13 | +import { expect } from 'chai'; |
| 14 | +import { WorkspaceHandlingTests } from '../../tests-library/WorkspaceHandlingTests'; |
| 15 | +import { ProjectAndFileTests } from '../../tests-library/ProjectAndFileTests'; |
| 16 | +import { LoginTests } from '../../tests-library/LoginTests'; |
| 17 | +import { registerRunningWorkspace } from '../MochaHooks'; |
| 18 | +import { BrowserTabsUtil } from '../../utils/BrowserTabsUtil'; |
| 19 | +import { BASE_TEST_CONSTANTS } from '../../constants/BASE_TEST_CONSTANTS'; |
| 20 | +import { Dashboard } from '../../pageobjects/dashboard/Dashboard'; |
| 21 | +import { FACTORY_TEST_CONSTANTS } from '../../constants/FACTORY_TEST_CONSTANTS'; |
| 22 | +import { CreateWorkspace } from '../../pageobjects/dashboard/CreateWorkspace'; |
| 23 | +import { TIMEOUT_CONSTANTS } from '../../constants/TIMEOUT_CONSTANTS'; |
| 24 | + |
| 25 | +const projectName: string = FACTORY_TEST_CONSTANTS.TS_SELENIUM_PROJECT_NAME || 'python-hello-world'; |
| 26 | + |
| 27 | +suite(`"Start workspace with existed workspace name" test ${BASE_TEST_CONSTANTS.TEST_ENVIRONMENT}`, function (): void { |
| 28 | + const workspaceHandlingTests: WorkspaceHandlingTests = e2eContainer.get(CLASSES.WorkspaceHandlingTests); |
| 29 | + const projectAndFileTests: ProjectAndFileTests = e2eContainer.get(CLASSES.ProjectAndFileTests); |
| 30 | + const loginTests: LoginTests = e2eContainer.get(CLASSES.LoginTests); |
| 31 | + const browserTabsUtil: BrowserTabsUtil = e2eContainer.get(CLASSES.BrowserTabsUtil); |
| 32 | + const dashboard: Dashboard = e2eContainer.get(CLASSES.Dashboard); |
| 33 | + const createWorkspace: CreateWorkspace = e2eContainer.get(CLASSES.CreateWorkspace); |
| 34 | + |
| 35 | + let projectSection: ViewSection; |
| 36 | + let firstWorkspaceName: string; |
| 37 | + let secondWorkspaceName: string; |
| 38 | + const factoryUrl: string = BASE_TEST_CONSTANTS.IS_CLUSTER_DISCONNECTED() |
| 39 | + ? FACTORY_TEST_CONSTANTS.TS_SELENIUM_AIRGAP_FACTORY_GIT_REPO_URL || 'https://gh.crw-qe.com/test-automation-only/python-hello-world' |
| 40 | + : FACTORY_TEST_CONSTANTS.TS_SELENIUM_FACTORY_GIT_REPO_URL || 'https://github.com/crw-qe/python-hello-world'; |
| 41 | + |
| 42 | + suiteSetup('Login', async function (): Promise<void> { |
| 43 | + await loginTests.loginIntoChe(); |
| 44 | + }); |
| 45 | + |
| 46 | + async function waitDashboardPage(): Promise<void> { |
| 47 | + await dashboard.openDashboard(); |
| 48 | + await dashboard.waitPage(); |
| 49 | + await browserTabsUtil.closeAllTabsExceptCurrent(); |
| 50 | + |
| 51 | + await dashboard.clickCreateWorkspaceButton(); |
| 52 | + await createWorkspace.waitPage(); |
| 53 | + expect(await createWorkspace.isCreateNewWorkspaceCheckboxChecked()).to.be.true; |
| 54 | + } |
| 55 | + |
| 56 | + async function waitWorkspaceReadiness(): Promise<void> { |
| 57 | + const originalWindowHandle: string = await browserTabsUtil.getCurrentWindowHandle(); |
| 58 | + await browserTabsUtil.waitAndSwitchToAnotherWindow(originalWindowHandle, TIMEOUT_CONSTANTS.TS_IDE_LOAD_TIMEOUT); |
| 59 | + |
| 60 | + await workspaceHandlingTests.obtainWorkspaceNameFromStartingPage(); |
| 61 | + |
| 62 | + registerRunningWorkspace(WorkspaceHandlingTests.getWorkspaceName()); |
| 63 | + |
| 64 | + await projectAndFileTests.waitWorkspaceReadinessForCheCodeEditor(); |
| 65 | + projectSection = await projectAndFileTests.getProjectViewSession(); |
| 66 | + expect(await projectAndFileTests.getProjectTreeItem(projectSection, projectName), 'Project folder was not imported').not.undefined; |
| 67 | + expect( |
| 68 | + await projectAndFileTests.getProjectTreeItem(projectSection, BASE_TEST_CONSTANTS.TS_SELENIUM_PROJECT_ROOT_FILE_NAME), |
| 69 | + 'Project files were not imported' |
| 70 | + ).not.undefined; |
| 71 | + } |
| 72 | + |
| 73 | + test('Verify "Create New" is off and a new workspace is created', async function (): Promise<void> { |
| 74 | + await waitDashboardPage(); |
| 75 | + |
| 76 | + await createWorkspace.setGitRepositoryUrl(factoryUrl); |
| 77 | + expect(await createWorkspace.isCreateNewWorkspaceCheckboxChecked()).to.be.false; |
| 78 | + expect(await createWorkspace.getGitRepositoryUrl()).to.be.equal(factoryUrl); |
| 79 | + await createWorkspace.clickOnCreateAndOpenButton(); |
| 80 | + await createWorkspace.performTrustAuthorPopup(); |
| 81 | + |
| 82 | + await waitWorkspaceReadiness(); |
| 83 | + |
| 84 | + firstWorkspaceName = WorkspaceHandlingTests.getWorkspaceName(); |
| 85 | + }); |
| 86 | + |
| 87 | + test('Verify existing workspace opens instead of creating a duplicate', async function (): Promise<void> { |
| 88 | + await waitDashboardPage(); |
| 89 | + |
| 90 | + await createWorkspace.setGitRepositoryUrl(factoryUrl); |
| 91 | + expect(await createWorkspace.getGitRepositoryUrl()).to.be.equal(factoryUrl); |
| 92 | + await createWorkspace.clickOnCreateAndOpenButton(); |
| 93 | + await createWorkspace.performTrustAuthorPopup(); |
| 94 | + |
| 95 | + await waitWorkspaceReadiness(); |
| 96 | + |
| 97 | + expect(WorkspaceHandlingTests.getWorkspaceName()).to.be.equal(firstWorkspaceName); |
| 98 | + }); |
| 99 | + |
| 100 | + test('Ensure `new` is appended and a new workspace is created without warnings', async function (): Promise<void> { |
| 101 | + await waitDashboardPage(); |
| 102 | + |
| 103 | + await createWorkspace.setGitRepositoryUrl(factoryUrl); |
| 104 | + await createWorkspace.setCreateNewWorkspaceCheckbox(true); |
| 105 | + |
| 106 | + expect(await createWorkspace.getGitRepositoryUrl()).to.be.equal(factoryUrl + '?new'); |
| 107 | + |
| 108 | + await createWorkspace.clickOnCreateAndOpenButton(); |
| 109 | + await createWorkspace.performTrustAuthorPopup(); |
| 110 | + |
| 111 | + await waitWorkspaceReadiness(); |
| 112 | + |
| 113 | + secondWorkspaceName = WorkspaceHandlingTests.getWorkspaceName(); |
| 114 | + // validate workspace name follows pattern: firstWorkspaceName + "-xxxx" (4 alphanumeric chars) |
| 115 | + expect(secondWorkspaceName).to.match(new RegExp(`^${firstWorkspaceName}-[a-z0-9]{4}$`)); |
| 116 | + }); |
| 117 | + |
| 118 | + test('Verify warning appears with list of existing workspaces and open the first created workspace', async function (): Promise<void> { |
| 119 | + await waitDashboardPage(); |
| 120 | + |
| 121 | + await createWorkspace.setGitRepositoryUrl(factoryUrl); |
| 122 | + await createWorkspace.clickOnCreateAndOpenButton(); |
| 123 | + await createWorkspace.performTrustAuthorPopup(); |
| 124 | + const originalWindowHandle: string = await browserTabsUtil.getCurrentWindowHandle(); |
| 125 | + await browserTabsUtil.waitAndSwitchToAnotherWindow(originalWindowHandle, TIMEOUT_CONSTANTS.TS_IDE_LOAD_TIMEOUT); |
| 126 | + |
| 127 | + await dashboard.waitExistingWorkspaceFoundAlert(); |
| 128 | + await dashboard.startExistedWorkspace(firstWorkspaceName); |
| 129 | + |
| 130 | + await workspaceHandlingTests.obtainWorkspaceNameFromStartingPage(); |
| 131 | + registerRunningWorkspace(WorkspaceHandlingTests.getWorkspaceName()); |
| 132 | + |
| 133 | + await projectAndFileTests.waitWorkspaceReadinessForCheCodeEditor(); |
| 134 | + projectSection = await projectAndFileTests.getProjectViewSession(); |
| 135 | + expect(await projectAndFileTests.getProjectTreeItem(projectSection, projectName), 'Project folder was not imported').not.undefined; |
| 136 | + expect( |
| 137 | + await projectAndFileTests.getProjectTreeItem(projectSection, BASE_TEST_CONSTANTS.TS_SELENIUM_PROJECT_ROOT_FILE_NAME), |
| 138 | + 'Project files were not imported' |
| 139 | + ).not.undefined; |
| 140 | + }); |
| 141 | + |
| 142 | + suiteTeardown('Stop and delete all created workspaces', async function (): Promise<void> { |
| 143 | + await workspaceHandlingTests.stopAndRemoveWorkspace(firstWorkspaceName); |
| 144 | + await workspaceHandlingTests.stopAndRemoveWorkspace(secondWorkspaceName); |
| 145 | + }); |
| 146 | + |
| 147 | + suiteTeardown('Unregister running workspace', function (): void { |
| 148 | + registerRunningWorkspace(''); |
| 149 | + }); |
| 150 | +}); |
0 commit comments