-
Notifications
You must be signed in to change notification settings - Fork 1.2k
/
Copy pathWorkspaceIdleTimeout.spec.ts
112 lines (98 loc) · 5.55 KB
/
WorkspaceIdleTimeout.spec.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
/** *******************************************************************
* copyright (c) 2020-2023 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, TYPES } from '../../configs/inversify.types';
import { WorkspaceHandlingTests } from '../../tests-library/WorkspaceHandlingTests';
import { ProjectAndFileTests } from '../../tests-library/ProjectAndFileTests';
import { LoginTests } from '../../tests-library/LoginTests';
import { registerRunningWorkspace } from '../MochaHooks';
import { Dashboard } from '../../pageobjects/dashboard/Dashboard';
import { Workspaces } from '../../pageobjects/dashboard/Workspaces';
import { TIMEOUT_CONSTANTS } from '../../constants/TIMEOUT_CONSTANTS';
import { DriverHelper } from '../../utils/DriverHelper';
import { CheCodeLocatorLoader } from '../../pageobjects/ide/CheCodeLocatorLoader';
import { Locators, ModalDialog } from 'monaco-page-objects';
import { expect } from 'chai';
import { KubernetesCommandLineToolsExecutor } from '../../utils/KubernetesCommandLineToolsExecutor';
import { ShellExecutor } from '../../utils/ShellExecutor';
import { ITestWorkspaceUtil } from '../../utils/workspace/ITestWorkspaceUtil';
import { BrowserTabsUtil } from '../../utils/BrowserTabsUtil';
import { OAUTH_CONSTANTS } from '../../constants/OAUTH_CONSTANTS';
suite('"Check workspace idle timeout" test', function (): void {
const workspaceHandlingTests: WorkspaceHandlingTests = e2eContainer.get(CLASSES.WorkspaceHandlingTests);
const projectAndFileTests: ProjectAndFileTests = e2eContainer.get(CLASSES.ProjectAndFileTests);
const loginTests: LoginTests = e2eContainer.get(CLASSES.LoginTests);
const dashboard: Dashboard = e2eContainer.get(CLASSES.Dashboard);
const workspaces: Workspaces = e2eContainer.get(CLASSES.Workspaces);
const driverHelper: DriverHelper = e2eContainer.get(CLASSES.DriverHelper);
const cheCodeLocatorLoader: CheCodeLocatorLoader = e2eContainer.get(CLASSES.CheCodeLocatorLoader);
const webCheCodeLocators: Locators = cheCodeLocatorLoader.webCheCodeLocators;
const kubernetesCommandLineToolsExecutor: KubernetesCommandLineToolsExecutor = e2eContainer.get(
CLASSES.KubernetesCommandLineToolsExecutor
);
const shellExecutor: ShellExecutor = e2eContainer.get(CLASSES.ShellExecutor);
const testWorkspaceUtil: ITestWorkspaceUtil = e2eContainer.get(TYPES.WorkspaceUtil);
const browserTabsUtil: BrowserTabsUtil = e2eContainer.get(CLASSES.BrowserTabsUtil);
const stackName: string = 'Empty Workspace';
const cheClusterName: string = 'devspaces';
let stopWorkspaceTimeout: number = 0;
suiteSetup(function (): void {
kubernetesCommandLineToolsExecutor.loginToOcp(OAUTH_CONSTANTS.TS_SELENIUM_OCP_USERNAME, OAUTH_CONSTANTS.TS_SELENIUM_OCP_PASSWORD);
shellExecutor.executeCommand('oc project openshift-devspaces');
// get current value of spec.devEnvironments.secondsOfInactivityBeforeIdling
stopWorkspaceTimeout = Number(
shellExecutor.executeCommand(
`oc get checluster/${cheClusterName} -o "jsonpath={.spec.devEnvironments.secondsOfInactivityBeforeIdling}"`
)
);
// set spec.devEnvironments.secondsOfInactivityBeforeIdling to 60
shellExecutor.executeCommand(
`oc patch checluster ${cheClusterName} --type=merge -p '{"spec":{"devEnvironments":{"secondsOfInactivityBeforeIdling": 60}}}'`
);
});
suiteTeardown(function (): void {
// restore spec.devEnvironments.secondsOfInactivityBeforeIdling to original value
shellExecutor.executeCommand(
`oc patch checluster ${cheClusterName} --type=merge -p '{"spec":{"devEnvironments":{"secondsOfInactivityBeforeIdling": ${stopWorkspaceTimeout}}}}'`
);
});
suiteSetup('Login', async function (): Promise<void> {
await loginTests.loginIntoChe();
});
test(`Create and open new workspace, stack:${stackName}`, async function (): Promise<void> {
await workspaceHandlingTests.createAndOpenWorkspace(stackName);
await workspaceHandlingTests.obtainWorkspaceNameFromStartingPage();
});
test('Wait workspace readiness', async function (): Promise<void> {
registerRunningWorkspace(WorkspaceHandlingTests.getWorkspaceName());
await projectAndFileTests.waitWorkspaceReadinessForCheCodeEditor();
await projectAndFileTests.performTrustAuthorDialog();
});
test('Wait idle timeout dialog and click on "Return to Dashboard" button', async function (): Promise<void> {
await driverHelper.waitVisibility(webCheCodeLocators.Dialog.details, TIMEOUT_CONSTANTS.TS_SELENIUM_START_WORKSPACE_TIMEOUT);
const dialog: ModalDialog = new ModalDialog();
expect(await dialog.getDetails()).includes('Your workspace has stopped due to inactivity.');
await dialog.pushButton('Return to dashboard');
});
test('Check that the workspace has Stopped state', async function (): Promise<void> {
await dashboard.waitPage();
await workspaces.waitWorkspaceWithStoppedStatus(WorkspaceHandlingTests.getWorkspaceName());
});
suiteTeardown('Open dashboard and close all other tabs', async function (): Promise<void> {
await dashboard.openDashboard();
await browserTabsUtil.closeAllTabsExceptCurrent();
});
suiteTeardown('Stop and delete the workspace by API', async function (): Promise<void> {
await testWorkspaceUtil.deleteWorkspaceByName(WorkspaceHandlingTests.getWorkspaceName());
});
suiteTeardown('Unregister running workspace', function (): void {
registerRunningWorkspace('');
});
});