-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Expand file tree
/
Copy pathNoSetupRepoFactory.spec.ts
More file actions
269 lines (242 loc) · 13.5 KB
/
NoSetupRepoFactory.spec.ts
File metadata and controls
269 lines (242 loc) · 13.5 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
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
/** *******************************************************************
* copyright (c) 2021-2025 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 'reflect-metadata';
import { e2eContainer } from '../../configs/inversify.config';
import {
ActivityBar,
ContextMenu,
InputBox,
Key,
Locators,
NewScmView,
SingleScmProvider,
ViewControl,
ViewSection
} from 'monaco-page-objects';
import { expect } from 'chai';
import { StringUtil } from '../../utils/StringUtil';
import { CheCodeLocatorLoader } from '../../pageobjects/ide/CheCodeLocatorLoader';
import { registerRunningWorkspace } from '../MochaHooks';
import { BrowserTabsUtil } from '../../utils/BrowserTabsUtil';
import { CLASSES, TYPES } from '../../configs/inversify.types';
import { WorkspaceHandlingTests } from '../../tests-library/WorkspaceHandlingTests';
import { ProjectAndFileTests } from '../../tests-library/ProjectAndFileTests';
import { DriverHelper } from '../../utils/DriverHelper';
import { Dashboard } from '../../pageobjects/dashboard/Dashboard';
import { Logger } from '../../utils/Logger';
import { LoginTests } from '../../tests-library/LoginTests';
import { FACTORY_TEST_CONSTANTS, GitProviderType } from '../../constants/FACTORY_TEST_CONSTANTS';
import { BASE_TEST_CONSTANTS } from '../../constants/BASE_TEST_CONSTANTS';
import { UserPreferences } from '../../pageobjects/dashboard/UserPreferences';
import { ITestWorkspaceUtil } from '../../utils/workspace/ITestWorkspaceUtil';
import { CreateWorkspace } from '../../pageobjects/dashboard/CreateWorkspace';
import { ViewsMoreActionsButton } from '../../pageobjects/ide/ViewsMoreActionsButton';
import { OAUTH_CONSTANTS } from '../../constants/OAUTH_CONSTANTS';
import { TIMEOUT_CONSTANTS } from '../../constants/TIMEOUT_CONSTANTS';
import { SourceControlView } from '../../pageobjects/ide/SourceControlView';
import { GitHubExtensionDialog } from '../../pageobjects/ide/GitHubExtensionDialog';
suite(
`Create a workspace via launching a factory from the ${FACTORY_TEST_CONSTANTS.TS_SELENIUM_FACTORY_GIT_PROVIDER} repository without PAT/OAuth setup ${BASE_TEST_CONSTANTS.TEST_ENVIRONMENT}`,
function (): void {
const browserTabsUtil: BrowserTabsUtil = e2eContainer.get(CLASSES.BrowserTabsUtil);
const workspaceHandlingTests: WorkspaceHandlingTests = e2eContainer.get(CLASSES.WorkspaceHandlingTests);
const projectAndFileTests: ProjectAndFileTests = e2eContainer.get(CLASSES.ProjectAndFileTests);
const cheCodeLocatorLoader: CheCodeLocatorLoader = e2eContainer.get(CLASSES.CheCodeLocatorLoader);
const webCheCodeLocators: Locators = cheCodeLocatorLoader.webCheCodeLocators;
const driverHelper: DriverHelper = e2eContainer.get(CLASSES.DriverHelper);
const dashboard: Dashboard = e2eContainer.get(CLASSES.Dashboard);
const loginTests: LoginTests = e2eContainer.get(CLASSES.LoginTests);
const testWorkspaceUtil: ITestWorkspaceUtil = e2eContainer.get(TYPES.WorkspaceUtil);
const createWorkspace: CreateWorkspace = e2eContainer.get(CLASSES.CreateWorkspace);
const viewsMoreActionsButton: ViewsMoreActionsButton = e2eContainer.get(CLASSES.ViewsMoreActionsButton);
const userPreferences: UserPreferences = e2eContainer.get(CLASSES.UserPreferences);
const sourceControlView: SourceControlView = e2eContainer.get(CLASSES.SourceControlView);
const gitHubExtensionDialog: GitHubExtensionDialog = e2eContainer.get(CLASSES.GitHubExtensionDialog);
let projectSection: ViewSection;
let scmProvider: SingleScmProvider;
let scmContextMenu: ContextMenu;
let viewsActionsButton: boolean;
// test specific data
const timeToRefresh: number = 1500;
const changesToCommit: string = new Date().getTime().toString();
const fileToChange: string = 'Date.txt';
const refreshButtonLabel: string = 'Refresh';
const pushItemLabel: string = 'Push';
let testRepoProjectName: string;
const isPrivateRepo: string = FACTORY_TEST_CONSTANTS.TS_SELENIUM_IS_PRIVATE_FACTORY_GIT_REPO ? 'private' : 'public';
suiteSetup('Login', async function (): Promise<void> {
await loginTests.loginIntoChe();
await userPreferences.setupGitConfig(
FACTORY_TEST_CONSTANTS.TS_GIT_COMMIT_AUTHOR_NAME,
FACTORY_TEST_CONSTANTS.TS_GIT_COMMIT_AUTHOR_EMAIL
);
});
test(`Navigate to the ${isPrivateRepo} repository factory URL`, async function (): Promise<void> {
await browserTabsUtil.navigateTo(FACTORY_TEST_CONSTANTS.TS_SELENIUM_FACTORY_URL());
await createWorkspace.performTrustAuthorPopup();
});
if (FACTORY_TEST_CONSTANTS.TS_SELENIUM_IS_PRIVATE_FACTORY_GIT_REPO) {
test('Check creating workspace using default devfile', async function (): Promise<void> {
await workspaceHandlingTests.obtainWorkspaceNameFromStartingPage();
registerRunningWorkspace(WorkspaceHandlingTests.getWorkspaceName());
await projectAndFileTests.waitWorkspaceReadinessForCheCodeEditor();
});
test('Check that a project folder has not been cloned', async function (): Promise<void> {
testRepoProjectName = StringUtil.getProjectNameFromGitUrl(FACTORY_TEST_CONSTANTS.TS_SELENIUM_FACTORY_GIT_REPO_URL);
await driverHelper.waitVisibility(webCheCodeLocators.TitleBar.itemElement);
await projectAndFileTests.performTrustAuthorDialog();
const isProjectFolderUnable: string = await driverHelper.waitAndGetElementAttribute(
(webCheCodeLocators.TreeItem as any).projectFolderItem,
'aria-label'
);
expect(isProjectFolderUnable).to.contain('No Folder Opened Section');
});
} else {
test('Obtain workspace name from workspace loader page', async function (): Promise<void> {
await workspaceHandlingTests.obtainWorkspaceNameFromStartingPage();
});
test('Registering the running workspace', function (): void {
registerRunningWorkspace(WorkspaceHandlingTests.getWorkspaceName());
});
test('Wait the workspace readiness', async function (): Promise<void> {
await projectAndFileTests.waitWorkspaceReadinessForCheCodeEditor();
});
test('Check if a project folder has been created', async function (): Promise<void> {
testRepoProjectName = StringUtil.getProjectNameFromGitUrl(FACTORY_TEST_CONSTANTS.TS_SELENIUM_FACTORY_GIT_REPO_URL);
projectSection = await projectAndFileTests.getProjectViewSession();
expect(await projectAndFileTests.getProjectTreeItem(projectSection, testRepoProjectName), 'Project folder was not imported')
.not.undefined;
});
test('Accept the project as a trusted one', async function (): Promise<void> {
await projectAndFileTests.performTrustAuthorDialog();
});
test('Check if the project files were imported', async function (): Promise<void> {
expect(
await projectAndFileTests.getProjectTreeItem(projectSection, BASE_TEST_CONSTANTS.TS_SELENIUM_PROJECT_ROOT_FILE_NAME),
'Project files were not imported'
).not.undefined;
});
test('Make changes to the file', async function (): Promise<void> {
Logger.debug(`projectSection.openItem: "${fileToChange}"`);
await projectSection.openItem(testRepoProjectName, fileToChange);
await driverHelper.waitVisibility(webCheCodeLocators.Editor.inputArea);
await driverHelper.getDriver().findElement(webCheCodeLocators.Editor.inputArea).click();
Logger.debug('Clearing the editor with Ctrl+A');
await driverHelper.getDriver().actions().keyDown(Key.CONTROL).sendKeys('a').keyUp(Key.CONTROL).perform();
await driverHelper.wait(500);
Logger.debug('Deleting selected text');
await driverHelper.getDriver().actions().sendKeys(Key.DELETE).perform();
await driverHelper.wait(500);
Logger.debug(`Entering text: "${changesToCommit}"`);
await driverHelper.getDriver().actions().sendKeys(changesToCommit).perform();
});
test('Open a source control manager', async function (): Promise<void> {
const viewSourceControl: string = 'Source Control';
const sourceControl: ViewControl = (await new ActivityBar().getViewControl(viewSourceControl)) as ViewControl;
Logger.debug(`sourceControl.openView: "${viewSourceControl}"`);
await sourceControl.openView();
const scmView: NewScmView = new NewScmView();
await driverHelper.waitVisibility(webCheCodeLocators.ScmView.inputField);
let rest: SingleScmProvider[];
[scmProvider, ...rest] = await scmView.getProviders();
Logger.debug(`scmView.getProviders: "${JSON.stringify(scmProvider)}, ${rest}"`);
});
test('Check if the changes are displayed in the source control manager', async function (): Promise<void> {
await driverHelper.waitVisibility(webCheCodeLocators.ScmView.more);
await driverHelper.wait(timeToRefresh);
Logger.debug(`wait and click on: "${refreshButtonLabel}"`);
await driverHelper.waitAndClick(webCheCodeLocators.ScmView.actionConstructor(refreshButtonLabel));
// wait while changes counter will be refreshed
await driverHelper.wait(timeToRefresh);
const changes: number = await scmProvider.getChangeCount();
Logger.debug(`scmProvider.getChangeCount: number of changes is "${changes}"`);
expect(changes).eql(1);
});
test('Stage the changes', async function (): Promise<void> {
await driverHelper.waitVisibility(webCheCodeLocators.ScmView.more);
viewsActionsButton = await viewsMoreActionsButton.viewsAndMoreActionsButtonIsVisible();
if (viewsActionsButton) {
await viewsMoreActionsButton.closeSourceControlGraph();
}
scmContextMenu = await scmProvider.openMoreActions();
await driverHelper.waitVisibility(webCheCodeLocators.ContextMenu.contextView);
Logger.debug('scmContextMenu.select: "Changes" -> "Stage All Changes"');
await scmContextMenu.select('Changes', 'Stage All Changes');
});
test('Commit the changes', async function (): Promise<void> {
Logger.info(`ScmView inputField locator: "${(webCheCodeLocators.ScmView as any).scmEditor}"`);
Logger.debug('Click on the Scm Editor');
await driverHelper
.getDriver()
.findElement((webCheCodeLocators.ScmView as any).scmEditor)
.click();
await sourceControlView.typeCommitMessage(changesToCommit);
await driverHelper.waitVisibility(webCheCodeLocators.ScmView.more);
await driverHelper.wait(timeToRefresh);
Logger.debug(`wait and click on: "${refreshButtonLabel}"`);
await driverHelper.waitAndClick(webCheCodeLocators.ScmView.actionConstructor(refreshButtonLabel));
// wait while changes counter will be refreshed
await driverHelper.wait(timeToRefresh);
const changes: number = await scmProvider.getChangeCount();
Logger.debug(`scmProvider.getChangeCount: number of changes is "${changes}"`);
expect(changes).eql(0);
});
test('Push the changes', async function (): Promise<void> {
await driverHelper.waitVisibility(webCheCodeLocators.Notification.action);
await driverHelper.waitVisibility(webCheCodeLocators.ScmView.more);
Logger.debug('scmProvider.openMoreActions');
scmContextMenu = await scmProvider.openMoreActions();
await driverHelper.waitVisibility(webCheCodeLocators.ContextMenu.itemConstructor(pushItemLabel));
Logger.debug(`scmContextMenu.select: "${pushItemLabel}"`);
await scmContextMenu.select(pushItemLabel);
if (await gitHubExtensionDialog.isDialogVisible()) {
await gitHubExtensionDialog.closeDialog();
}
if (FACTORY_TEST_CONSTANTS.TS_SELENIUM_FACTORY_GIT_PROVIDER !== GitProviderType.BITBUCKET_CLOUD_OAUTH2) {
// wait for the user name input to appear and create an InputBox to enter the user name
Logger.debug('Waiting for username input to appear');
const inputUsername: InputBox = await InputBox.create(TIMEOUT_CONSTANTS.TS_DIALOG_WINDOW_DEFAULT_TIMEOUT);
Logger.debug(`Setting username: "${OAUTH_CONSTANTS.TS_SELENIUM_GIT_PROVIDER_USERNAME}"`);
await inputUsername.setText(OAUTH_CONSTANTS.TS_SELENIUM_GIT_PROVIDER_USERNAME);
await inputUsername.confirm();
}
// wait for password input to appear after username confirmation
Logger.debug('Waiting for password input to appear');
const inputPassword: InputBox = await InputBox.create(TIMEOUT_CONSTANTS.TS_DIALOG_WINDOW_DEFAULT_TIMEOUT);
Logger.debug('Setting password');
await inputPassword.setText(FACTORY_TEST_CONSTANTS.TS_GIT_PERSONAL_ACCESS_TOKEN);
await inputPassword.confirm();
});
test('Check if the changes were pushed', async function (): Promise<void> {
await driverHelper.waitVisibility(webCheCodeLocators.ScmView.more);
await driverHelper.wait(timeToRefresh);
Logger.debug(`wait and click on: "${refreshButtonLabel}"`);
await driverHelper.waitAndClick(webCheCodeLocators.ScmView.actionConstructor(refreshButtonLabel));
const isCommitButtonDisabled: string = await driverHelper.waitAndGetElementAttribute(
webCheCodeLocators.Notification.action,
'aria-disabled'
);
expect(isCommitButtonDisabled).to.equal('true');
});
}
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> {
// to avoid a possible creating workspace which is not appeared on Dashboard yet. TODO: implement a better solution.
await driverHelper.wait(30000);
await testWorkspaceUtil.stopAndDeleteWorkspaceByName(WorkspaceHandlingTests.getWorkspaceName());
});
suiteTeardown('Unregister running workspace', function (): void {
registerRunningWorkspace('');
});
}
);