-
Notifications
You must be signed in to change notification settings - Fork 1.2k
/
RefusedOAuthFactory.spec.ts
257 lines (232 loc) · 12.2 KB
/
RefusedOAuthFactory.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
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
/** *******************************************************************
* copyright (c) 2021 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,
EditorView,
InputBox,
Locators,
NewScmView,
SingleScmProvider,
TextEditor,
ViewControl,
ViewSection
} from 'monaco-page-objects';
import { expect } from 'chai';
import { registerRunningWorkspace } from '../MochaHooks';
import { BrowserTabsUtil } from '../../utils/BrowserTabsUtil';
import { CLASSES, TYPES } from '../../configs/inversify.types';
import { WorkspaceHandlingTests } from '../../tests-library/WorkspaceHandlingTests';
import { CheCodeLocatorLoader } from '../../pageobjects/ide/CheCodeLocatorLoader';
import { ProjectAndFileTests } from '../../tests-library/ProjectAndFileTests';
import { DriverHelper } from '../../utils/DriverHelper';
import { OauthPage } from '../../pageobjects/git-providers/OauthPage';
import { StringUtil } from '../../utils/StringUtil';
import { Logger } from '../../utils/Logger';
import { LoginTests } from '../../tests-library/LoginTests';
import { OAUTH_CONSTANTS } from '../../constants/OAUTH_CONSTANTS';
import { BASE_TEST_CONSTANTS } from '../../constants/BASE_TEST_CONSTANTS';
import { FACTORY_TEST_CONSTANTS, GitProviderType } from '../../constants/FACTORY_TEST_CONSTANTS';
import { ITestWorkspaceUtil } from '../../utils/workspace/ITestWorkspaceUtil';
import { Dashboard } from '../../pageobjects/dashboard/Dashboard';
suite(
`Create a workspace via launching a factory from the ${FACTORY_TEST_CONSTANTS.TS_SELENIUM_FACTORY_GIT_PROVIDER} repository and deny the access ${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 loginTests: LoginTests = e2eContainer.get(CLASSES.LoginTests);
const oauthPage: OauthPage = e2eContainer.get(CLASSES.OauthPage);
const testWorkspaceUtil: ITestWorkspaceUtil = e2eContainer.get(TYPES.WorkspaceUtil);
const dashboard: Dashboard = e2eContainer.get(CLASSES.Dashboard);
let projectSection: ViewSection;
let scmProvider: SingleScmProvider;
let rest: SingleScmProvider[];
let scmContextMenu: ContextMenu;
// test specific data
const timeToRefresh: number = 1500;
const changesToCommit: string = new Date().getTime().toString();
const fileToChange: string = 'Date.txt';
const commitChangesButtonLabel: string = `Commit Changes on "${FACTORY_TEST_CONSTANTS.TS_SELENIUM_FACTORY_GIT_REPO_BRANCH}"`;
const refreshButtonLabel: string = 'Refresh';
const pushItemLabel: string = 'Push';
const label: string = BASE_TEST_CONSTANTS.TS_SELENIUM_PROJECT_ROOT_FILE_NAME;
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();
});
test(`Navigate to the ${isPrivateRepo} repository factory URL`, async function (): Promise<void> {
await browserTabsUtil.navigateTo(FACTORY_TEST_CONSTANTS.TS_SELENIUM_FACTORY_URL());
});
test(`Authorize with a ${FACTORY_TEST_CONSTANTS.TS_SELENIUM_FACTORY_GIT_PROVIDER} OAuth and deny access`, async function (): Promise<void> {
await oauthPage.login();
await oauthPage.waitOauthPage();
await oauthPage.denyAccess();
});
test('Obtain workspace name from workspace loader page', async function (): Promise<void> {
await workspaceHandlingTests.obtainWorkspaceNameFromStartingPage();
});
test('The workspace starts with access deny flag in the url', async function (): Promise<void> {
expect(await driverHelper.getDriver().getCurrentUrl()).contains('&error_code=access_denied');
});
test('Registering the running workspace', function (): void {
registerRunningWorkspace(WorkspaceHandlingTests.getWorkspaceName());
});
test('Wait the workspace readiness', async function (): Promise<void> {
await projectAndFileTests.waitWorkspaceReadinessForCheCodeEditor();
});
if (FACTORY_TEST_CONSTANTS.TS_SELENIUM_IS_PRIVATE_FACTORY_GIT_REPO) {
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.ScmView.multiProviderItem);
await projectAndFileTests.performTrustAuthorDialog();
const isProjectFolderUnable: string = await driverHelper.waitAndGetElementAttribute(
(webCheCodeLocators.TreeItem as any).projectFolderItem,
'aria-label'
);
expect(isProjectFolderUnable).to.contain(
'/projects/' + testRepoProjectName + ' • Unable to resolve workspace folder (Unable to resolve nonexistent file'
);
});
} else {
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, label), '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);
const editor: TextEditor = (await new EditorView().openEditor(fileToChange)) as TextEditor;
await driverHelper.waitVisibility(webCheCodeLocators.Editor.inputArea);
Logger.debug('editor.clearText');
await editor.clearText();
Logger.debug(`editor.typeTextAt: "${changesToCommit}"`);
await editor.typeTextAt(1, 1, changesToCommit);
});
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);
[scmProvider, ...rest] = await scmView.getProviders();
if (scmProvider === undefined) {
await projectAndFileTests.performManageWorkspaceTrustBox();
[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);
Logger.debug('scmProvider.openMoreActions');
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.debug(`scmProvider.commitChanges: commit name "Commit ${changesToCommit}"`);
await scmProvider.commitChanges('Commit ' + 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.ScmView.actionConstructor(
`Push 1 commits to origin/${FACTORY_TEST_CONSTANTS.TS_SELENIUM_FACTORY_GIT_REPO_BRANCH}`
)
);
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);
});
test('Insert git credentials which were asked after push', async function (): Promise<void> {
try {
await driverHelper.waitVisibility(webCheCodeLocators.InputBox.message);
} catch (e) {
Logger.info(`Workspace did not ask credentials before push - ${e};
Known issue for github.com - https://issues.redhat.com/browse/CRW-4066, please check if not other git provider. `);
expect(FACTORY_TEST_CONSTANTS.TS_SELENIUM_FACTORY_GIT_PROVIDER).eqls(GitProviderType.GITHUB);
}
const input: InputBox = new InputBox();
await input.setText(OAUTH_CONSTANTS.TS_SELENIUM_GIT_PROVIDER_USERNAME);
await input.confirm();
await driverHelper.wait(timeToRefresh);
await input.setText(OAUTH_CONSTANTS.TS_SELENIUM_GIT_PROVIDER_PASSWORD);
await input.confirm();
await driverHelper.wait(timeToRefresh);
});
test('Check if the changes were pushed', async function (): Promise<void> {
try {
Logger.debug(`scmProvider.takeAction: "${refreshButtonLabel}"`);
await scmProvider.takeAction(refreshButtonLabel);
} catch (e) {
Logger.info(
'Check you use correct credentials.' +
'For bitbucket.org ensure you use an app password: https://support.atlassian.com/bitbucket-cloud/docs/using-app-passwords/;' +
'For github.com - personal access token instead of password.'
);
}
const isCommitButtonDisabled: string = await driverHelper.waitAndGetElementAttribute(
webCheCodeLocators.ScmView.actionConstructor(commitChangesButtonLabel),
'aria-disabled'
);
expect(isCommitButtonDisabled).to.be.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> {
await testWorkspaceUtil.stopAndDeleteWorkspaceByName(WorkspaceHandlingTests.getWorkspaceName());
});
suiteTeardown('Unregister running workspace', function (): void {
registerRunningWorkspace('');
});
}
);