-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Expand file tree
/
Copy pathWorkspaceDetails.ts
More file actions
219 lines (174 loc) · 9.09 KB
/
Copy pathWorkspaceDetails.ts
File metadata and controls
219 lines (174 loc) · 9.09 KB
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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
/** *******************************************************************
* copyright (c) 2019-2026 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 { DriverHelper } from '../../../utils/DriverHelper';
import { inject, injectable } from 'inversify';
import { CLASSES, TYPES } from '../../../configs/inversify.types';
import 'reflect-metadata';
import { By } from 'selenium-webdriver';
import { WorkspaceStatus } from '../../../utils/workspace/WorkspaceStatus';
import { Logger } from '../../../utils/Logger';
import { TIMEOUT_CONSTANTS } from '../../../constants/TIMEOUT_CONSTANTS';
import { ITestWorkspaceUtil } from '../../../utils/workspace/ITestWorkspaceUtil';
import { ProjectAndFileTests } from '../../../tests-library/ProjectAndFileTests';
@injectable()
export class WorkspaceDetails {
private static readonly RUN_BUTTON: By = By.css('#run-workspace-button[che-button-title="Run"]');
private static readonly OPEN_BUTTON: By = By.css('#open-in-ide-button[che-button-title="Open"]');
private static readonly SAVE_BUTTON: By = By.css('button[name="save-button"]');
private static readonly ENABLED_SAVE_BUTTON: By = By.css('button[name="save-button"][aria-disabled="false"]');
private static readonly WORKSPACE_DETAILS_LOADER: By = By.css('workspace-details-overview md-progress-linear');
private static readonly STORAGE_TYPE_INFO_BUTTON: By = By.css('span[aria-label="More info for storage type"]');
private static readonly CLOSE_STORAGE_TYPE_INFO_BUTTON: By = By.xpath('//button[@aria-label="Close"]');
private static readonly STORAGE_TYPE_DOC_LINK: By = By.xpath('//div/p/a');
private static readonly DEVFILE_DOC_LINK: By = By.xpath('//a[text()="Devfile Documentation"]');
private static readonly RENAME_WORKSPACE_BUTTON: By = By.xpath('//button[@title="Edit Workspace Name"]');
private static readonly RENAME_WORKSPACE_INPUT: By = By.id('edit-workspace-name');
private static readonly RENAME_SAVE_BUTTON: By = By.xpath('//button[@data-testid="edit-workspace-name-save"]');
private static readonly RENAME_CANCEL_BUTTON: By = By.xpath('//button[@data-testid="edit-workspace-name-cancel"]');
constructor(
@inject(CLASSES.DriverHelper)
private readonly driverHelper: DriverHelper,
@inject(TYPES.WorkspaceUtil)
private readonly testWorkspaceUtil: ITestWorkspaceUtil,
@inject(CLASSES.ProjectAndFileTests)
private readonly testProjectAndFileCheCode: ProjectAndFileTests
) {}
async waitLoaderDisappearance(
attempts: number = TIMEOUT_CONSTANTS.TS_SELENIUM_DEFAULT_ATTEMPTS,
polling: number = TIMEOUT_CONSTANTS.TS_SELENIUM_DEFAULT_POLLING
): Promise<void> {
Logger.debug();
await this.driverHelper.waitDisappearance(WorkspaceDetails.WORKSPACE_DETAILS_LOADER, attempts, polling);
}
async saveChanges(): Promise<void> {
Logger.debug();
await this.waitSaveButton();
await this.clickOnSaveButton();
await this.waitSaveButtonDisappearance();
}
async waitPage(workspaceName: string, timeout: number = TIMEOUT_CONSTANTS.TS_SELENIUM_LOAD_PAGE_TIMEOUT): Promise<void> {
Logger.debug(`workspace: "${workspaceName}"`);
await this.waitWorkspaceTitle(workspaceName, timeout);
await this.waitOpenButton(timeout);
await this.waitRunButton(timeout);
await this.waitTabsPresence(timeout);
await this.waitLoaderDisappearance(timeout);
}
async waitWorkspaceTitle(workspaceName: string, timeout: number = TIMEOUT_CONSTANTS.TS_COMMON_DASHBOARD_WAIT_TIMEOUT): Promise<void> {
Logger.debug(`title: "${workspaceName}"`);
const workspaceTitleLocator: By = this.getWorkspaceTitleLocator(workspaceName);
await this.driverHelper.waitVisibility(workspaceTitleLocator, timeout);
}
async waitRunButton(timeout: number = TIMEOUT_CONSTANTS.TS_COMMON_DASHBOARD_WAIT_TIMEOUT): Promise<void> {
Logger.debug();
await this.driverHelper.waitVisibility(WorkspaceDetails.RUN_BUTTON, timeout);
}
async clickOnRunButton(timeout: number = TIMEOUT_CONSTANTS.TS_CLICK_DASHBOARD_ITEM_TIMEOUT): Promise<void> {
Logger.debug();
await this.driverHelper.waitAndClick(WorkspaceDetails.RUN_BUTTON, timeout);
}
async waitOpenButton(timeout: number = TIMEOUT_CONSTANTS.TS_COMMON_DASHBOARD_WAIT_TIMEOUT): Promise<void> {
Logger.debug();
await this.driverHelper.waitVisibility(WorkspaceDetails.OPEN_BUTTON, timeout);
}
async openWorkspace(
namespace: string,
workspaceName: string,
timeout: number = TIMEOUT_CONSTANTS.TS_SELENIUM_LOAD_PAGE_TIMEOUT
): Promise<void> {
Logger.debug(`"${namespace}/${workspaceName}"`);
await this.clickOnOpenButton(timeout);
await this.testProjectAndFileCheCode.waitWorkspaceReadinessForCheCodeEditor();
await this.testWorkspaceUtil.waitWorkspaceStatus(workspaceName, WorkspaceStatus.STARTING);
}
async waitTabsPresence(timeout: number = TIMEOUT_CONSTANTS.TS_COMMON_DASHBOARD_WAIT_TIMEOUT): Promise<void> {
Logger.debug();
const workspaceDetailsTabs: Array<string> = ['Overview', 'Devfile', 'DevWorkspace', 'Logs', 'Events'];
for (const tabTitle of workspaceDetailsTabs) {
const workspaceDetailsTabLocator: By = this.getTabLocator(tabTitle);
await this.driverHelper.waitVisibility(workspaceDetailsTabLocator, timeout);
}
}
async selectTab(tabTitle: string, timeout: number = TIMEOUT_CONSTANTS.TS_COMMON_DASHBOARD_WAIT_TIMEOUT): Promise<void> {
Logger.debug(`${tabTitle}`);
await this.clickOnTab(tabTitle, timeout);
}
async clickStorageTypeInfo(): Promise<void> {
Logger.debug();
await this.driverHelper.waitAndClick(WorkspaceDetails.STORAGE_TYPE_INFO_BUTTON);
}
async getOpenStorageTypeDocumentationLink(): Promise<string> {
Logger.debug();
return await this.driverHelper.waitAndGetElementAttribute(WorkspaceDetails.STORAGE_TYPE_DOC_LINK, 'href');
}
async closeStorageTypeInfo(): Promise<void> {
Logger.debug();
await this.driverHelper.waitAndClick(WorkspaceDetails.CLOSE_STORAGE_TYPE_INFO_BUTTON);
}
async getDevfileDocumentationLink(): Promise<string> {
return await this.driverHelper.waitAndGetElementAttribute(WorkspaceDetails.DEVFILE_DOC_LINK, 'href');
}
/**
* devSpaces Dashboard does not allow editing the workspace display name while the workspace is running.
*/
async waitRenameWorkspaceNotPossibleWhileWorkspaceRunning(): Promise<void> {
Logger.debug();
await this.driverHelper.waitDisappearance(WorkspaceDetails.RENAME_WORKSPACE_BUTTON);
}
/**
* rename a stopped workspace from the Overview tab (fill name + save).
*/
async renameStoppedWorkspaceTo(newDisplayName: string): Promise<void> {
Logger.debug(`newDisplayName: "${newDisplayName}"`);
await this.driverHelper.waitAndClick(WorkspaceDetails.RENAME_WORKSPACE_BUTTON, TIMEOUT_CONSTANTS.TS_SELENIUM_LOAD_PAGE_TIMEOUT);
await this.driverHelper.type(WorkspaceDetails.RENAME_WORKSPACE_INPUT, newDisplayName);
await this.driverHelper.waitAndClick(WorkspaceDetails.RENAME_SAVE_BUTTON);
await this.waitWorkspaceTitle(newDisplayName);
}
async attemptRenameWorkspaceName(desiredName: string): Promise<void> {
Logger.debug(`desiredName: "${desiredName}"`);
await this.driverHelper.waitAndClick(WorkspaceDetails.RENAME_WORKSPACE_BUTTON, TIMEOUT_CONSTANTS.TS_SELENIUM_LOAD_PAGE_TIMEOUT);
await this.driverHelper.type(WorkspaceDetails.RENAME_WORKSPACE_INPUT, desiredName);
await this.driverHelper.waitAttributePresent(
WorkspaceDetails.RENAME_SAVE_BUTTON,
'disabled',
TIMEOUT_CONSTANTS.TS_COMMON_DASHBOARD_WAIT_TIMEOUT
);
await this.closeRenameWorkspaceForm();
}
async closeRenameWorkspaceForm(): Promise<void> {
await this.driverHelper.waitAndClick(WorkspaceDetails.RENAME_CANCEL_BUTTON, TIMEOUT_CONSTANTS.TS_SELENIUM_LOAD_PAGE_TIMEOUT);
}
private getWorkspaceTitleLocator(workspaceName: string): By {
return By.xpath(`//h1[text()='${workspaceName}']`);
}
private getTabLocator(tabTitle: string): By {
return By.xpath(`//button[contains(@id,'${tabTitle}')]`);
}
private async waitSaveButton(timeout: number = TIMEOUT_CONSTANTS.TS_COMMON_DASHBOARD_WAIT_TIMEOUT): Promise<void> {
await this.driverHelper.waitVisibility(WorkspaceDetails.ENABLED_SAVE_BUTTON, timeout);
}
private async waitSaveButtonDisappearance(
attempts: number = TIMEOUT_CONSTANTS.TS_SELENIUM_DEFAULT_ATTEMPTS,
polling: number = TIMEOUT_CONSTANTS.TS_SELENIUM_DEFAULT_POLLING
): Promise<void> {
await this.driverHelper.waitDisappearance(WorkspaceDetails.SAVE_BUTTON, attempts, polling);
}
private async clickOnSaveButton(timeout: number = TIMEOUT_CONSTANTS.TS_CLICK_DASHBOARD_ITEM_TIMEOUT): Promise<void> {
await this.driverHelper.waitAndClick(WorkspaceDetails.ENABLED_SAVE_BUTTON, timeout);
}
private async clickOnOpenButton(timeout: number = TIMEOUT_CONSTANTS.TS_CLICK_DASHBOARD_ITEM_TIMEOUT): Promise<void> {
await this.driverHelper.waitAndClick(WorkspaceDetails.OPEN_BUTTON, timeout);
}
private async clickOnTab(tabTitle: string, timeout: number = TIMEOUT_CONSTANTS.TS_CLICK_DASHBOARD_ITEM_TIMEOUT): Promise<void> {
const workspaceDetailsTabLocator: By = this.getTabLocator(tabTitle);
await this.driverHelper.waitAndClick(workspaceDetailsTabLocator, timeout);
}
}