-
Notifications
You must be signed in to change notification settings - Fork 334
Expand file tree
/
Copy pathpods.spec.ts
More file actions
517 lines (410 loc) · 19.7 KB
/
pods.spec.ts
File metadata and controls
517 lines (410 loc) · 19.7 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
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
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
import { WorkloadsPodsListPagePo, WorkLoadsPodDetailsPagePo, WorkLoadsPodEditPagePo } from '@/cypress/e2e/po/pages/explorer/workloads-pods.po';
// import { WorkloadsPodsListPagePo, WorkLoadsPodDetailsPagePo, WorkloadsPodsCreatePagePo } from '@/cypress/e2e/po/pages/explorer/workloads-pods.po';
import { createPodBlueprint, clonePodBlueprint } from '@/cypress/e2e/blueprints/explorer/workload-pods';
import PodPo from '@/cypress/e2e/po/components/workloads/pod.po';
// import PromptRemove from '@/cypress/e2e/po/prompts/promptRemove.po';
import HomePagePo from '@/cypress/e2e/po/pages/home.po';
import { generatePodsDataSmall } from '@/cypress/e2e/blueprints/explorer/workloads/pods/pods-get';
import SortableTablePo from '@/cypress/e2e/po/components/sortable-table.po';
import ClusterDashboardPagePo from '@/cypress/e2e/po/pages/explorer/cluster-dashboard.po';
import { SMALL_CONTAINER } from '@/cypress/e2e/tests/pages/explorer2/workloads/workload.utils';
const localCluster = 'local';
describe('Pods', { testIsolation: false, tags: ['@explorer2', '@adminUser'] }, () => {
const workloadsPodPage = new WorkloadsPodsListPagePo(localCluster);
before(() => {
cy.login();
});
describe('List', { tags: ['@noVai', '@adminUser'] }, () => {
let uniquePod = SortableTablePo.firstByDefaultName('pod');
let podNamesList = [];
let nsName1: string;
let nsName2: string;
let rootResourceName: string;
before('set up', () => {
cy.getRootE2EResourceName().then((root) => {
rootResourceName = root;
});
const createPod = (podName?: string) => {
return ({ ns, i }: {ns: string, i: number}) => {
const name = podName || Cypress._.uniqueId(`${ Date.now().toString() }-${ i }`);
return cy.createPod(ns, name, SMALL_CONTAINER.image, false, { createNameOptions: { prefixContext: true } });
};
};
cy.createManyNamespacedResources({
context: 'pods1',
createResource: createPod(),
})
.then(({ ns, workloadNames }) => {
podNamesList = workloadNames;
nsName1 = ns;
})
.then(() => cy.createManyNamespacedResources({
context: 'pods2',
createResource: createPod(uniquePod),
count: 1
}))
.then(({ ns, workloadNames }) => {
uniquePod = workloadNames[0];
nsName2 = ns;
cy.tableRowsPerPageAndNamespaceFilter(10, localCluster, 'none', `{\"local\":[\"ns://${ nsName1 }\",\"ns://${ nsName2 }\"]}`);
});
});
it('pagination is visible and user is able to navigate through pods data', () => {
ClusterDashboardPagePo.goToAndConfirmNsValues(localCluster, { nsProject: { values: [nsName1, nsName2] } });
WorkloadsPodsListPagePo.navTo();
workloadsPodPage.waitForPage();
// check pods count
const count = podNamesList.length + 1;
cy.waitForRancherResources('v1', 'pods', count - 1, true).then((resp: Cypress.Response<any>) => {
// pagination is visible
workloadsPodPage.list().resourceTable().sortableTable().pagination()
.checkVisible();
// basic checks on navigation buttons
workloadsPodPage.list().resourceTable().sortableTable().pagination()
.beginningButton()
.isDisabled();
workloadsPodPage.list().resourceTable().sortableTable().pagination()
.leftButton()
.isDisabled();
workloadsPodPage.list().resourceTable().sortableTable().pagination()
.rightButton()
.isEnabled();
workloadsPodPage.list().resourceTable().sortableTable().pagination()
.endButton()
.isEnabled();
// check text before navigation
workloadsPodPage.list().resourceTable().sortableTable().pagination()
.paginationText()
.then((el) => {
expect(el.trim()).to.eq(`1 - 10 of ${ count } Pods`);
});
// navigate to next page - right button
workloadsPodPage.list().resourceTable().sortableTable().pagination()
.rightButton()
.click();
// check text and buttons after navigation
workloadsPodPage.list().resourceTable().sortableTable().pagination()
.paginationText()
.then((el) => {
expect(el.trim()).to.eq(`11 - 20 of ${ count } Pods`);
});
workloadsPodPage.list().resourceTable().sortableTable().pagination()
.beginningButton()
.isEnabled();
workloadsPodPage.list().resourceTable().sortableTable().pagination()
.leftButton()
.isEnabled();
// navigate to first page - left button
workloadsPodPage.list().resourceTable().sortableTable().pagination()
.leftButton()
.click();
// check text and buttons after navigation
workloadsPodPage.list().resourceTable().sortableTable().pagination()
.paginationText()
.then((el) => {
expect(el.trim()).to.eq(`1 - 10 of ${ count } Pods`);
});
workloadsPodPage.list().resourceTable().sortableTable().pagination()
.beginningButton()
.isDisabled();
workloadsPodPage.list().resourceTable().sortableTable().pagination()
.leftButton()
.isDisabled();
// navigate to last page - end button
workloadsPodPage.list().resourceTable().sortableTable().pagination()
.endButton()
.scrollIntoView()
.click();
// row count on last page
let lastPageCount = count % 10;
if (lastPageCount === 0) {
lastPageCount = 10;
}
// check text after navigation
workloadsPodPage.list().resourceTable().sortableTable().pagination()
.paginationText()
.then((el) => {
expect(el.trim()).to.eq(`${ count - (lastPageCount) + 1 } - ${ count } of ${ count } Pods`);
});
// navigate to first page - beginning button
workloadsPodPage.list().resourceTable().sortableTable().pagination()
.beginningButton()
.click();
// check text and buttons after navigation
workloadsPodPage.list().resourceTable().sortableTable().pagination()
.paginationText()
.then((el) => {
expect(el.trim()).to.eq(`1 - 10 of ${ count } Pods`);
});
workloadsPodPage.list().resourceTable().sortableTable().pagination()
.beginningButton()
.isDisabled();
workloadsPodPage.list().resourceTable().sortableTable().pagination()
.leftButton()
.isDisabled();
});
});
it('sorting changes the order of paginated pods data', () => {
WorkloadsPodsListPagePo.navTo();
workloadsPodPage.waitForPage();
// use filter to only show test data
workloadsPodPage.list().resourceTable().sortableTable().filter(rootResourceName);
// check table is sorted by name in ASC order by default
workloadsPodPage.list().resourceTable().sortableTable().tableHeaderRow()
.checkSortOrder(2, 'down');
// pod name should be visible on first page (sorted in ASC order)
workloadsPodPage.list().resourceTable().sortableTable().tableHeaderRow()
.self()
.scrollIntoView();
workloadsPodPage.list().resourceTable().sortableTable().rowElementWithName(podNamesList[0])
.scrollIntoView()
.should('be.visible');
// sort by name in DESC order
workloadsPodPage.list().resourceTable().sortableTable().sort(2)
.click({ force: true });
workloadsPodPage.list().resourceTable().sortableTable().tableHeaderRow()
.checkSortOrder(2, 'up');
// pod name should be NOT visible on first page (sorted in DESC order)
workloadsPodPage.list().resourceTable().sortableTable().rowElementWithName(podNamesList[0])
.should('not.exist');
// navigate to last page
workloadsPodPage.list().resourceTable().sortableTable().pagination()
.endButton()
.scrollIntoView()
.click();
// pod name should be visible on last page (sorted in DESC order)
workloadsPodPage.list().resourceTable().sortableTable().rowElementWithName(podNamesList[0])
.scrollIntoView()
.should('be.visible');
});
it('filter pods', () => {
WorkloadsPodsListPagePo.navTo();
workloadsPodPage.waitForPage();
workloadsPodPage.list().resourceTable().sortableTable().checkVisible();
workloadsPodPage.list().resourceTable().sortableTable().checkLoadingIndicatorNotVisible();
workloadsPodPage.list().resourceTable().sortableTable().checkRowCount(false, 10);
// filter by name
workloadsPodPage.list().resourceTable().sortableTable().filter(podNamesList[0]);
workloadsPodPage.list().resourceTable().sortableTable().checkRowCount(false, 1);
workloadsPodPage.list().resourceTable().sortableTable().rowElementWithName(podNamesList[0])
.should('be.visible');
// filter by namespace
workloadsPodPage.list().resourceTable().sortableTable().filter(nsName2);
workloadsPodPage.list().resourceTable().sortableTable().checkRowCount(false, 1);
workloadsPodPage.list().resourceTable().sortableTable().rowElementWithName(uniquePod)
.should('be.visible');
});
it('pagination is hidden', () => {
cy.tableRowsPerPageAndNamespaceFilter(10, localCluster, 'none', '{"local":[]}');
// generate small set of pods data
generatePodsDataSmall();
HomePagePo.goTo(); // this is needed here for the intercept to work
WorkloadsPodsListPagePo.navTo();
cy.wait('@podsDataSmall');
workloadsPodPage.waitForPage();
workloadsPodPage.list().resourceTable().sortableTable().checkVisible();
workloadsPodPage.list().resourceTable().sortableTable().checkLoadingIndicatorNotVisible();
workloadsPodPage.list().resourceTable().sortableTable().checkRowCount(false, 3);
workloadsPodPage.list().resourceTable().sortableTable().pagination()
.checkNotExists();
});
after('clean up', () => {
// Ensure the default rows per page value is set after running the tests
cy.tableRowsPerPageAndNamespaceFilter(100, localCluster, 'none', '{"local":["all://user"]}');
// delete namespace (this will also delete all pods in it)
cy.deleteNamespace([nsName1, nsName2]);
});
});
describe('Should open a terminal', () => {
beforeEach(() => {
workloadsPodPage.goTo();
});
it('should open a pod shell', () => {
const shellPodPo = new PodPo();
shellPodPo.openPodShell();
});
});
describe('When cloning a pod', () => {
const { name: origPodName, namespace } = createPodBlueprint.metadata;
const { name: clonePodName } = clonePodBlueprint.metadata;
beforeEach(() => {
cy.intercept('GET', `/v1/pods/${ namespace }/${ origPodName }?*`).as('origPod');
cy.intercept('GET', `/v1/pods/${ namespace }/${ clonePodName }?*`).as('clonedPod');
workloadsPodPage.goTo();
const createPodPo = new PodPo();
createPodPo.createPodViaKubectl(createPodBlueprint);
});
it(`Should have same spec as the original pod`, () => {
const cloneCreatePodPage = new WorkLoadsPodDetailsPagePo(origPodName, { mode: 'clone' });
cloneCreatePodPage.goTo();
let origPodSpec: any;
cy.wait('@origPod', { timeout: 20000 })
.then(({ response }) => {
expect(response?.statusCode).to.eq(200);
origPodSpec = response?.body.spec;
expect(origPodSpec.containers[0].resources).to.deep.eq(createPodBlueprint.spec.containers[0].resources);
});
const createClonePo = new PodPo();
// Each pod need a unique name
createClonePo.nameNsDescription().name().set(clonePodName);
createClonePo.save();
workloadsPodPage.waitForPage();
workloadsPodPage.list().checkVisible();
workloadsPodPage.list().resourceTable().sortableTable().filter(clonePodName);
workloadsPodPage.list().resourceTable().sortableTable().rowWithName(clonePodName)
.checkExists();
// Simple test to assert we haven't broken Pods detail page
// https://github.com/rancher/dashboard/issues/10490
const clonedPodPage = new WorkLoadsPodDetailsPagePo(clonePodName);
clonedPodPage.goTo();// Needs to be goTo to ensure http request is fired
clonedPodPage.waitForPage();
cy.wait('@clonedPod', { timeout: 20000 })
.then(({ response }) => {
expect(response?.statusCode).to.eq(200);
const clonedSpec = response?.body?.spec;
// In Dashboard adds empty affinity object by default
// Remove this to compare
if (!Object.keys(clonedSpec.affinity).length) {
delete clonedSpec.affinity;
}
expect(clonedSpec).to.deep.eq(origPodSpec);
expect(clonedSpec.containers[0].resources).to.deep.eq(createPodBlueprint.spec.containers[0].resources);
});
});
});
describe('When creating a pod using the web Form', () => {
const singlePodName = Cypress._.uniqueId(Date.now().toString());
it(`should have the default input units displayed`, () => {
workloadsPodPage.goTo();
workloadsPodPage.createPod();
const podDetails = new PodPo();
podDetails.nameNsDescription().name().set(singlePodName);
const podDetailsGeneral = podDetails.containerButton().general();
podDetailsGeneral.inputImageName().set(SMALL_CONTAINER.image);
const podDetailsResources = podDetails.containerButton().resources();
podDetailsResources.clickResources();
podDetailsResources.inputCpuLimit().getAttributeValue('placeholder').should('contain', 'e.g. 1000');
podDetailsResources.inputCpuReservation().getAttributeValue('placeholder').should('contain', 'e.g. 1000');
podDetailsResources.inputMemoryReservation().getAttributeValue('placeholder').should('contain', 'e.g. 128');
podDetailsResources.inputMemoryLimit().getAttributeValue('placeholder').should('contain', 'e.g. 128');
podDetailsResources.inputGpuLimit().getAttributeValue('placeholder').should('contain', 'e.g. 1');
podDetailsResources.inputCpuLimit().set('100');
podDetailsResources.inputCpuReservation().set('100');
podDetailsResources.inputMemoryLimit().set('128');
podDetailsResources.inputMemoryLimit().set('128');
podDetailsResources.inputGpuLimit().set('0');
podDetails.saveCreateForm().cruResource().saveOrCreate().click();
workloadsPodPage.waitForPage();
workloadsPodPage.list().resourceTable().sortableTable().rowElementWithName(singlePodName)
.scrollIntoView()
.should('be.visible');
});
it('Footer controls should stick to bottom in YAML Editor', () => {
// testing https://github.com/rancher/dashboard/issues/10880
const workloadsPodEditPage = new WorkLoadsPodEditPagePo(singlePodName);
cy.intercept('GET', `/api/v1/namespaces/default/pods/${ singlePodName }`).as('getPod');
workloadsPodPage.goTo();
workloadsPodPage.waitForPage();
workloadsPodPage.list().resourceTable().sortableTable().rowElementWithName(singlePodName)
.scrollIntoView()
.should('be.visible');
workloadsPodPage.list().actionMenu(singlePodName).getMenuItem('Edit YAML').click();
workloadsPodEditPage.waitForPage('mode=edit&as=yaml');
cy.wait('@getPod');
// clear the form
workloadsPodEditPage.resourceDetail().resourceYaml().codeMirror().set('');
// footer should maintain its position on the page
workloadsPodEditPage.resourceDetail().resourceYaml().footer().then(($el) => {
const elementRect = $el[0].getBoundingClientRect();
const viewportHeight = Cypress.config('viewportHeight');
const pageHeight = Cypress.$(cy.state('window')).height();
expect(elementRect.bottom).to.be.closeTo(pageHeight, 0.1);
expect(elementRect.bottom).to.be.closeTo(viewportHeight, 0.1);
});
});
it(`should properly add container tabs to the tablist`, () => {
workloadsPodPage.goTo();
workloadsPodPage.createPod();
const podDetails = new PodPo();
podDetails.nameNsDescription().name().set(singlePodName);
podDetails.addButton().click();
podDetails.tabsPrimary().within(() => {
cy.get('[data-testid="btn-pod"]').should('contain.text', 'Pod');
cy.get('[data-testid="btn-container-0"]').should('contain.text', 'container-0');
cy.get('[data-testid="btn-container-1"]').should('contain.text', 'container-1');
cy.get('[data-testid="workload-button-add-container"]').should('contain.text', 'Add Container');
});
});
// testing https://github.com/rancher/dashboard/issues/14071
it('should remove the correct environment variable from the workload form', () => {
cy.viewport(1280, 720);
const podDetails = new PodPo();
workloadsPodPage.goTo();
workloadsPodPage.createPod();
podDetails.nameNsDescription().name().set(singlePodName);
// add multiple environment variables
const envVars = [
{ key: 'FIRST_VAR', value: 'one' },
{ key: 'SECOND_VAR', value: 'two' },
{ key: 'THIRD_VAR', value: 'three' },
];
envVars.forEach(({ key, value }, index) => {
podDetails.environmentVariables().setKeyValueEnvVarAtIndex(key, value, index);
});
// confirm all env vars are present
envVars.forEach(({ key }, index) => {
podDetails.environmentVariables().getVariableAtIndex(index).find('.name input')
.should('have.value', key)
.and('exist');
});
// remove SECOND_VAR
podDetails.environmentVariables().removeButtonAtIndex(1).click();
// confirm only FIRST_VAR and THIRD_VAR remain
const newEnvVars = [
{ key: 'FIRST_VAR', value: 'one' },
{ key: 'THIRD_VAR', value: 'three' },
];
newEnvVars.forEach(({ key }, index) => {
podDetails.environmentVariables().getVariableAtIndex(index).find('.name input').should('have.value', key);
});
podDetails.environmentVariables().getVariableByName('SECOND_VAR').should('not.exist');
});
});
// describe.skip('[Vue3 Skip]: should delete pod', () => {
// const podName = `pod-${ Date.now() }`;
// beforeEach(() => {
// workloadsPodPage.goTo();
// });
// it('dialog should open/close as expected', () => {
// const podCreatePage = new WorkloadsPodsCreatePagePo(cluster);
// podCreatePage.goTo();
// podCreatePage.createWithUI(podName, 'nginx', 'default');
// // Should be on the list view
// const podsListPage = new WorkloadsPodsListPagePo(cluster);
// // Filter the list to just show the newly created pod
// podsListPage.list().resourceTable().sortableTable().filter(podName);
// podsListPage.list().resourceTable().sortableTable().checkRowCount(false, 1);
// // Open action menu and delete for the first item
// podsListPage.list().resourceTable().sortableTable().rowActionMenuOpen(podName)
// .getMenuItem('Delete')
// .click();
// let dialog = new PromptRemove();
// dialog.checkExists();
// dialog.checkVisible();
// dialog.cancel();
// dialog.checkNotExists();
// podsListPage.list().resourceTable().sortableTable().checkRowCount(false, 1);
// // Open action menu and delete for the first item
// podsListPage.list().resourceTable().sortableTable().rowActionMenuOpen(podName)
// .getMenuItem('Delete')
// .click();
// dialog = new PromptRemove();
// dialog.checkExists();
// dialog.checkVisible();
// dialog.remove();
// dialog.checkNotExists();
// podsListPage.list().resourceTable().sortableTable().checkRowCount(true, 1, true);
// podsListPage.list().resourceTable().sortableTable().resetFilter();
// });
// });
});