forked from talamer/console
-
Notifications
You must be signed in to change notification settings - Fork 0
/
git-page.ts
345 lines (335 loc) · 14.8 KB
/
git-page.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
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
import { getResponseMocks, gitImportRepos } from '../../../testData/git-import/repos';
import { gitAdvancedOptions, buildConfigOptions, builderImages, messages } from '../../constants';
import { gitPO } from '../../pageObjects';
import { app } from '../app';
export const gitPage = {
unselectRoute: () => cy.get(gitPO.advancedOptions.createRoute).uncheck(),
verifyNoWorkLoadsText: (text: string) =>
cy.get(gitPO.noWorkLoadsText).should('contain.text', text),
verifyPipelinesSection: () => {
cy.get('.odc-namespaced-page__content').scrollTo('bottom', { ensureScrollable: false });
cy.get(gitPO.sectionTitle).contains('Pipelines').should('be.visible');
},
verifyPipelineInfoMessage: (message: string) => {
cy.get(gitPO.pipeline.infoMessage).should('contain.text', `Info alert:${message}`);
},
enterGitUrl: (gitUrl: string) => {
const shortUrl = gitUrl.endsWith('.git') ? gitUrl.substring(0, gitUrl.length - 4) : gitUrl;
const repository = gitImportRepos.find((repo) => repo.url === shortUrl);
// mock the github requests for the frequently used repositories to avoid rate limits
if (repository) {
const urlSegments = repository.url.split('/');
const organization = urlSegments[urlSegments.length - 2];
const name = urlSegments[urlSegments.length - 1];
const apiBaseUrl = `https://api.github.com/repos/${organization}/${name}`;
const responses = getResponseMocks(repository);
cy.intercept('GET', apiBaseUrl, {
statusCode: 200,
body: responses.repoResponse,
}).as('getRepo');
cy.intercept('GET', `${apiBaseUrl}/contents/`, {
statusCode: 200,
body: responses.contentsResponse,
}).as('getContents');
cy.intercept('GET', `${apiBaseUrl}/contents//package.json`, {
statusCode: responses.packageResponse ? 200 : 404,
body: responses.packageResponse,
}).as('getPackage');
cy.intercept('POST', '/api/devfile/', {
statusCode: responses.devFileResources ? 200 : 404,
body: responses.devFileResources,
}).as('getDevfileResources');
cy.intercept('GET', `${apiBaseUrl}/contents//func.yaml`, {
statusCode: responses.funcJson ? 200 : 404,
body: responses.funcJson,
}).as('getFuncJson');
}
cy.get(gitPO.gitRepoUrl).clear().type(gitUrl);
if (repository) {
const responses = getResponseMocks(repository);
cy.wait(
responses.packageResponse
? ['@getRepo', '@getContents', '@getPackage']
: ['@getRepo', '@getContents'],
);
}
app.waitForDocumentLoad();
},
verifyPipelineCheckBox: () => {
cy.get(gitPO.pipeline.addPipeline).scrollIntoView().should('be.visible');
},
verifyPipelineCheckBoxChecked: () => {
cy.get(gitPO.pipeline.addPipeline).scrollIntoView().should('be.checked');
},
selectPipeline: (pipelineName: string) => {
cy.get(gitPO.pipeline.pipelineDropdown).scrollIntoView().click();
cy.get(`#${pipelineName}-link`).should('be.visible').click();
},
enterAppName: (appName: string) => {
cy.get('body').then(($body) => {
if ($body.find('#form-input-application-name-field').length !== 0) {
cy.get('#form-input-application-name-field')
.scrollIntoView()
.clear()
.should('not.have.value');
cy.get('#form-input-application-name-field').type(appName).should('have.value', appName);
cy.log(`Application Name "${appName}" is created`);
} else if ($body.find('#form-dropdown-application-name-field').length !== 0) {
cy.get(gitPO.appName).click();
cy.get('[data-test-id="dropdown-text-filter"]').type(appName);
cy.get('[role="listbox"]').then(($el) => {
if ($el.find('li[role="option"]').length === 0) {
cy.get('[data-test-dropdown-menu="#CREATE_APPLICATION_KEY#"]').click();
cy.get('#form-input-application-name-field')
.clear()
.type(appName)
.should('have.value', appName);
} else {
cy.get(`li #${appName}-link`).click();
cy.log(`Application Name "${appName}" is selected`);
}
});
}
});
},
verifyAppName: (appName: string) => {
cy.get(gitPO.appName).then(($el) => {
if ($el.prop('tagName').includes('button')) {
cy.get(gitPO.appName).find('span').should('contain.text', appName);
} else if ($el.prop('tagName').includes('input')) {
cy.get(gitPO.appName).should('have.value', appName);
} else {
cy.log(`App name doesn't contain button or input tags`);
}
});
// cy.get(gitPO.appName).should('have.value', nodeName)
},
editAppName: (newAppName: string) => {
cy.get(gitPO.appName).click();
cy.get(gitPO.createNewApp).first().click();
cy.get(gitPO.newAppName).clear().type(newAppName);
},
enterComponentName: (name: string) => {
app.waitForLoad();
cy.get(gitPO.nodeName).scrollIntoView().invoke('val').should('not.be.empty');
cy.wait(2000);
cy.get(gitPO.nodeName).clear();
cy.get(gitPO.nodeName).type(name).should('have.value', name);
},
enterWorkloadName: (name: string) => {
cy.get(gitPO.nodeName).clear();
cy.get(gitPO.nodeName).type(name).should('have.value', name);
},
verifyNodeName: (componentName: string) =>
cy.get(gitPO.nodeName).should('have.value', componentName),
selectResource: (resource: string = 'deployment') => {
cy.get(gitPO.resourcesDropdown).scrollIntoView().click();
switch (resource) {
case 'deployment':
case 'Deployment':
cy.get(gitPO.resources.deployment).scrollIntoView().click();
break;
case 'deployment config':
case 'Deployment Config':
case 'DeploymentConfig':
cy.get(gitPO.resources.deploymentConfig).scrollIntoView().click();
break;
case 'Knative':
case 'Knative Service':
case 'Serverless Deployment':
cy.get(gitPO.resources.knative).scrollIntoView().click();
break;
default:
throw new Error('Resource option is not available');
break;
}
cy.log(`Resource type "${resource}" is selected`);
},
enterSecret: (secret: string) => {
cy.get('#form-input-pac-repository-webhook-token-field').clear().type(secret);
},
clickGenerateWebhookSecret: () => {
cy.byButtonText('Generate').click();
},
selectAdvancedOptions: (opt: gitAdvancedOptions) => {
switch (opt) {
case gitAdvancedOptions.Routing:
cy.byButtonText('Routing').click();
break;
case gitAdvancedOptions.BuildConfig:
cy.byButtonText('Build Configuration').click();
break;
case gitAdvancedOptions.Deployment:
cy.byButtonText('Deployment').click();
break;
case gitAdvancedOptions.Scaling:
cy.byButtonText('Scaling').click();
break;
case gitAdvancedOptions.ResourceLimits:
cy.byButtonText('Resource Limits').click();
break;
case gitAdvancedOptions.Labels:
cy.byButtonText('Labels').click();
break;
case gitAdvancedOptions.HealthChecks:
cy.byButtonText('Health Checks').click();
break;
case gitAdvancedOptions.Resources:
cy.byButtonText('Resource type').click();
break;
default:
throw new Error('Advanced option is not available');
break;
}
},
selectAddPipeline: () => cy.get(gitPO.pipeline.addPipeline).scrollIntoView().check(),
clickCreate: () => cy.get(gitPO.create).scrollIntoView().should('be.enabled').click(),
clickCancel: () => cy.get(gitPO.cancel).should('be.enabled').click(),
selectBuilderImageForGitUrl: (gitUrl: string) => {
switch (gitUrl) {
case 'https://github.com/sclorg/dancer-ex.git':
cy.get(`[data-test="card ${builderImages.Perl}"]`).click();
cy.log(`Selecting builder image "${builderImages.Perl}" to avoid the git rate limit issue`);
break;
case 'https://github.com/sclorg/cakephp-ex.git':
cy.get(`[data-test="card ${builderImages.PHP}"]`).click();
cy.log(`Selecting builder image "${builderImages.PHP}" to avoid the git rate limit issue`);
break;
case 'https://github.com/sclorg/nginx-ex.git':
cy.get(`[data-test="card ${builderImages.Nginx}"]`).click();
cy.log(
`Selecting builder image "${builderImages.Nginx}" to avoid the git rate limit issue`,
);
break;
case 'https://github.com/sclorg/httpd-ex.git':
cy.get(`[data-test="card ${builderImages.Httpd}"]`).click();
cy.log(
`Selecting builder image "${builderImages.Httpd}" to avoid the git rate limit issue`,
);
break;
case 'https://github.com/redhat-developer/s2i-dotnetcore-ex.git':
cy.get(`[data-test="card ${builderImages.NETCore}"]`).click();
cy.log(
`Selecting builder image "${builderImages.NETCore}" to avoid the git rate limit issue`,
);
break;
case 'https://github.com/sclorg/golang-ex.git':
cy.get(`[data-test="card ${builderImages.Go}"]`).click();
cy.log(`Selecting builder image "${builderImages.Go}" to avoid the git rate limit issue`);
break;
case 'https://github.com/sclorg/ruby-ex.git':
cy.get(`[data-test="card ${builderImages.Ruby}"]`).click();
cy.log(`Selecting builder image "${builderImages.Ruby}" to avoid the git rate limit issue`);
break;
case 'https://github.com/sclorg/django-ex.git':
cy.get(`[data-test="card ${builderImages.Python}"]`).click();
cy.log(
`Selecting builder image "${builderImages.Python}" to avoid the git rate limit issue`,
);
break;
case 'https://github.com/jboss-openshift/openshift-quickstarts':
cy.get(`[data-test="card ${builderImages.Java}"]`).click();
cy.log(`Selecting builder image "${builderImages.Java}" to avoid the git rate limit issue`);
break;
case 'https://github.com/sclorg/nodejs-ex.git':
cy.get(`[data-test="card ${builderImages.NodeJs}"]`).click();
cy.log(
`Selecting builder image "${builderImages.NodeJs}" to avoid the git rate limit issue`,
);
break;
default:
cy.log(
`Unable to find the builder image for git url: ${gitUrl}, so selecting node.js builder by default `,
);
}
},
verifyValidatedMessage: (gitUrl: string) => {
cy.get(gitPO.gitSection.validatedMessage)
.should('not.include.text', 'Validating...')
.and('not.include.text', messages.addFlow.buildDeployMessage);
cy.get('body').then(($body) => {
if ($body.text().includes(messages.addFlow.rateLimitExceeded)) {
// Remove .git suffix and remove all parts before the last path
const componentName = gitUrl.replace(/\.git$/, '').replace(/^.*[\\\\/]/, '');
cy.log(
`Git Rate limit exceeded for url ${gitUrl}, select builder image and fill component name "${componentName}" based on the URL to continue tests.`,
);
gitPage.selectBuilderImageForGitUrl(gitUrl);
cy.get(gitPO.nodeName).clear();
cy.get(gitPO.nodeName).type(componentName);
} else if (
$body.find('[aria-label="Warning Alert"]').length ||
$body.text().includes(messages.addFlow.privateGitRepoMessage)
) {
cy.log(`Issue with git url ${gitUrl}, maybe a private repo url. Please check it`);
gitPage.selectBuilderImageForGitUrl(gitUrl);
}
});
},
verifyBuilderImageDetectedMessage: () =>
cy.get(gitPO.builderSection.builderImageDetected).should('be.visible'),
verifyBuilderImageVersion: () =>
cy.get(gitPO.builderSection.builderImageVersion).should('be.visible'),
selectTargetPortForRouting: () => {
cy.get(gitPO.advancedOptions.routing.targetPort).scrollIntoView().clear().type('8080');
},
enterRoutingHostName: (hostName: string) =>
cy.get(gitPO.advancedOptions.routing.hostname).type(hostName),
enterRoutingPath: (path: string) => cy.get(gitPO.advancedOptions.routing.path).type(path),
uncheckBuildConfigOption: (checkBoxName: string | buildConfigOptions) => {
switch (checkBoxName) {
case buildConfigOptions.webhookBuildTrigger:
cy.get(gitPO.advancedOptions.buildConfig.webHookBuildTrigger)
.should('be.visible')
.uncheck();
break;
case buildConfigOptions.automaticBuildImage:
cy.get(gitPO.advancedOptions.buildConfig.buildTriggerImage).should('be.visible').uncheck();
break;
case buildConfigOptions.launchBuildOnCreatingBuildConfig:
cy.get(gitPO.advancedOptions.buildConfig.buildTriggerConfigField)
.should('be.visible')
.uncheck();
break;
default:
throw new Error(
`Unable to find the "${checkBoxName}" checkbox in Build Configuration Section`,
);
}
},
enterBuildConfigEnvName: (envName: string) =>
cy.get(gitPO.advancedOptions.buildConfig.envName).type(envName),
enterBuildConfigEnvValue: (envValue: string) =>
cy.get(gitPO.advancedOptions.buildConfig.envValue).type(envValue),
verifyDeploymentOptionIsChecked: () => {
cy.get(gitPO.advancedOptions.deployment.deploymentTriggerImage).should('be.checked');
},
enterDeploymentEnvName: (envName: string) =>
cy.get(gitPO.advancedOptions.deployment.envName).type(envName),
enterDeploymentEnvValue: (envValue: string) =>
cy.get(gitPO.advancedOptions.deployment.envValue).type(envValue),
enterResourceLimitCPURequest: (cpuRequestValue: string) =>
cy.get(gitPO.advancedOptions.resourceLimit.cpuRequest).type(cpuRequestValue),
enterResourceLimitCPULimit: (cpuLimitValue: string) =>
cy.get(gitPO.advancedOptions.resourceLimit.cpuLimit).type(cpuLimitValue),
enterResourceLimitMemoryRequest: (memoryRequestValue: string) =>
cy.get(gitPO.advancedOptions.resourceLimit.memoryRequest).type(memoryRequestValue),
enterResourceLimitMemoryLimit: (memoryLimitValue: string) =>
cy.get(gitPO.advancedOptions.resourceLimit.memoryLimit).type(memoryLimitValue),
enterScalingReplicaCount: (replicaCount: string) =>
cy.get(gitPO.advancedOptions.scaling.replicaCount).type(replicaCount),
enterLabels: (labelName: string) => cy.get(gitPO.advancedOptions.labels).type(labelName),
enterRouteLabels: (labelRouteName: string) =>
cy.get(gitPO.advancedOptions.routing.labels).type(labelRouteName),
notificationVerify: (message: string) =>
cy.get(gitPO.pipeline.infoMessage).should('contain.text', message),
checkIfDevfileImportStrategyDisabled: () =>
cy.get(gitPO.importStrategy.devFileStrategy).should('have.attr', 'aria-disabled', 'true'),
clickEditImportStrategy: () => cy.get(gitPO.importStrategy.editImportStrategyBtn).click(),
enterDevfilePath: (devfilePath: string) => {
cy.get(gitPO.importStrategy.devFilePathInput).clear().type(devfilePath);
},
checkDevFileHelpText: (message: string) => {
cy.get(gitPO.importStrategy.devFileHelperText).contains(message).should('exist');
},
};