-
Notifications
You must be signed in to change notification settings - Fork 334
Expand file tree
/
Copy pathcronjobs.spec.ts
More file actions
399 lines (339 loc) · 15.7 KB
/
cronjobs.spec.ts
File metadata and controls
399 lines (339 loc) · 15.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
import { WorkloadsCronJobsListPagePo, WorkloadsCronJobDetailPagePo } from '@/cypress/e2e/po/pages/explorer/workloads-cronjobs.po';
import { WorkLoadsJobDetailsPagePo } from '@/cypress/e2e/po/pages/explorer/workloads-jobs.po';
import HomePagePo from '@/cypress/e2e/po/pages/home.po';
import SortableTablePo from '@/cypress/e2e/po/components/sortable-table.po';
import ClusterDashboardPagePo from '@/cypress/e2e/po/pages/explorer/cluster-dashboard.po';
import { generateCronJobsDataSmall } from '@/cypress/e2e/blueprints/explorer/workloads/cronjobs/cronjobs-get';
import { SMALL_CONTAINER } from '@/cypress/e2e/tests/pages/explorer2/workloads/workload.utils';
import { MEDIUM_TIMEOUT_OPT } from '@/cypress/support/utils/timeouts';
describe('CronJobs', { testIsolation: false, tags: ['@explorer2', '@adminUser'] }, () => {
const localCluster = 'local';
const cronJobListPage = new WorkloadsCronJobsListPagePo(localCluster);
before(() => {
cy.login();
});
describe('Details', () => {
let cronJobName: string;
let jobName: string;
let podName: string;
const defaultNamespace = 'default';
beforeEach('set up', () => {
// Create a cronjob for the test
cy.getRootE2EResourceName().then((root) => {
cronJobName = root;
return cy.createRancherResource('v1', 'batch.cronjob', JSON.stringify({
apiVersion: 'batch/v1',
kind: 'CronJob',
metadata: {
name: cronJobName,
namespace: defaultNamespace
},
spec: {
schedule: '1 1 1 1 1', // basically never
concurrencyPolicy: 'Allow',
failedJobsHistoryLimit: 1,
successfulJobsHistoryLimit: 3,
suspend: false,
jobTemplate: {
spec: {
template: {
spec: {
containers: [SMALL_CONTAINER],
restartPolicy: 'Never'
}
}
}
}
}
}));
});
});
it('Jobs list updates automatically in CronJob details page', () => {
// Set namespace filter to include the test cronjob namespace
cy.tableRowsPerPageAndNamespaceFilter(10, localCluster, 'none', `{\"local\":[\"ns://${ defaultNamespace }\"]}`);
WorkloadsCronJobsListPagePo.navTo();
cronJobListPage.waitForPage();
// Trigger "Run Now" action which will create a new job and pod from the CronJob
cy.intercept('POST', `v1/batch.jobs/${ defaultNamespace }`).as('runNow');
cronJobListPage.runNow(cronJobName);
cy.wait('@runNow').its('response.statusCode').should('eq', 201);
// Retrieve the job and pod names created by the CronJob
cy.getRancherResource('v1', 'batch.job', `${ defaultNamespace }`).then((resp) => {
const job = resp.body.data.find((job: any) => job.metadata.name.startsWith(cronJobName));
jobName = job.metadata.name;
cy.getRancherResource('v1', 'pods', `${ defaultNamespace }`).then((resp) => {
const pod = resp.body.data.find((pod: any) => pod.metadata.name.startsWith(cronJobName));
podName = pod.metadata.name;
// User is redirected to the job's details page after "Run Now"
const jobDetailsPage = new WorkLoadsJobDetailsPagePo(jobName, undefined, 'local', defaultNamespace);
jobDetailsPage.waitForPage(undefined, 'pods');
// Verify job details page displays correct status
// Job status should be Active
jobDetailsPage.resourceDetail().masthead().resourceStatus(MEDIUM_TIMEOUT_OPT)
.should('contain', 'Active');
// Pod status should be Running
jobDetailsPage.resourceDetail().resourceGauges().should('contain', 'Running');
jobDetailsPage.resourceDetail().tabbedList('pods').resourceTableDetails(podName, 1).contains('Running', MEDIUM_TIMEOUT_OPT);
});
// Navigate back to CronJobs list page
WorkloadsCronJobsListPagePo.navTo();
cronJobListPage.waitForPage();
// Verify CronJob status is Active in the list
cronJobListPage.resourceTableDetails(cronJobName, 1).contains('Active');
// Navigate to CronJob details page
cronJobListPage.goToDetailsPage(cronJobName);
const cronJobDetailsPage = new WorkloadsCronJobDetailPagePo(cronJobName, 'local', defaultNamespace);
cronJobDetailsPage.waitForPage(undefined, 'jobs');
// Verify CronJob status is Active in details page
cronJobDetailsPage.resourceDetail().masthead().resourceStatus()
.should('contain', 'Active');
// Verify the job in the jobs tab shows correct status without manual page refresh
// Testing https://github.com/rancher/dashboard/issues/14981:
// The job list should update automatically and not show stale "In Progress" status
cronJobDetailsPage.resourceDetail().tabbedList('jobs').resourceTableDetails(jobName, 1).contains('Active');
});
});
afterEach('clean up', () => {
// Ensure the default rows per page value is set after running the tests
cy.tableRowsPerPageAndNamespaceFilter(100, localCluster, 'none', '{"local":["all://user"]}');
// Delete the cronjob
cy.deleteRancherResource('v1', 'batch.cronjob', `${ defaultNamespace }/${ cronJobName }`);
});
});
describe('List', { tags: ['@noVai', '@adminUser'] }, () => {
let uniqueCronJob = SortableTablePo.firstByDefaultName('cronjob');
let detailsPageCronJob = SortableTablePo.firstByDefaultName('detailscron');
let cronJobNamesList = [];
let nsName1: string;
let nsName2: string;
let nsName3: string;
let rootResourceName: string;
before('set up', () => {
cy.getRootE2EResourceName().then((root) => {
rootResourceName = root;
});
const createCronJob = (cronJobName?: string) => {
return ({ ns, i }: {ns: string, i: number}) => {
const name = cronJobName || Cypress._.uniqueId(`${ Date.now().toString() }-${ i }`);
return cy.createRancherResource('v1', 'batch.cronjob', JSON.stringify({
apiVersion: 'batch/v1',
kind: 'CronJob',
metadata: {
name,
namespace: ns
},
spec: {
schedule: '1 1 1 1 1', // basically never
concurrencyPolicy: 'Allow',
failedJobsHistoryLimit: 1,
successfulJobsHistoryLimit: 3,
suspend: false,
jobTemplate: {
spec: {
template: {
spec: {
containers: [SMALL_CONTAINER],
restartPolicy: 'Never'
}
}
}
}
}
}));
};
};
cy.createManyNamespacedResources({
context: 'cronjobs1',
createResource: createCronJob(),
})
.then(({ ns, workloadNames }) => {
cronJobNamesList = workloadNames;
nsName1 = ns;
})
.then(() => cy.createManyNamespacedResources({
context: 'cronjobs2',
createResource: createCronJob(uniqueCronJob),
count: 1
}))
.then(({ ns, workloadNames }) => {
uniqueCronJob = workloadNames[0];
nsName2 = ns;
cy.tableRowsPerPageAndNamespaceFilter(10, localCluster, 'none', `{\"local\":[\"ns://${ nsName1 }\",\"ns://${ nsName2 }\"]}`);
})
.then(() => cy.createManyNamespacedResources({
context: 'cronjobs3',
createResource: createCronJob(detailsPageCronJob),
count: 1
}))
.then(({ ns, workloadNames }) => {
detailsPageCronJob = workloadNames[0];
nsName3 = ns;
});
});
it('pagination is visible and user is able to navigate through cronjobs data', () => {
ClusterDashboardPagePo.goToAndConfirmNsValues(localCluster, { nsProject: { values: [nsName1, nsName2] } });
WorkloadsCronJobsListPagePo.navTo();
cronJobListPage.waitForPage();
// check cronjobs count
const count = cronJobNamesList.length + 1;
cy.waitForRancherResources('v1', 'batch.cronjob', count, true).then((resp: Cypress.Response<any>) => {
// pagination is visible
cronJobListPage.list().resourceTable().sortableTable().pagination()
.checkVisible();
// basic checks on navigation buttons
cronJobListPage.list().resourceTable().sortableTable().pagination()
.beginningButton()
.isDisabled();
cronJobListPage.list().resourceTable().sortableTable().pagination()
.leftButton()
.isDisabled();
cronJobListPage.list().resourceTable().sortableTable().pagination()
.rightButton()
.isEnabled();
cronJobListPage.list().resourceTable().sortableTable().pagination()
.endButton()
.isEnabled();
// check text before navigation
cronJobListPage.list().resourceTable().sortableTable().pagination()
.paginationText()
.then((el) => {
expect(el.trim()).to.eq(`1 - 10 of ${ count } CronJobs`);
});
// navigate to next page - right button
cronJobListPage.list().resourceTable().sortableTable().pagination()
.rightButton()
.click();
// check text and buttons after navigation
cronJobListPage.list().resourceTable().sortableTable().pagination()
.paginationText()
.then((el) => {
expect(el.trim()).to.eq(`11 - 20 of ${ count } CronJobs`);
});
cronJobListPage.list().resourceTable().sortableTable().pagination()
.beginningButton()
.isEnabled();
cronJobListPage.list().resourceTable().sortableTable().pagination()
.leftButton()
.isEnabled();
// navigate to first page - left button
cronJobListPage.list().resourceTable().sortableTable().pagination()
.leftButton()
.click();
// check text and buttons after navigation
cronJobListPage.list().resourceTable().sortableTable().pagination()
.paginationText()
.then((el) => {
expect(el.trim()).to.eq(`1 - 10 of ${ count } CronJobs`);
});
cronJobListPage.list().resourceTable().sortableTable().pagination()
.beginningButton()
.isDisabled();
cronJobListPage.list().resourceTable().sortableTable().pagination()
.leftButton()
.isDisabled();
// navigate to last page - end button
cronJobListPage.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
cronJobListPage.list().resourceTable().sortableTable().pagination()
.paginationText()
.then((el) => {
expect(el.trim()).to.eq(`${ count - (lastPageCount) + 1 } - ${ count } of ${ count } CronJobs`);
});
// navigate to first page - beginning button
cronJobListPage.list().resourceTable().sortableTable().pagination()
.beginningButton()
.click();
// check text and buttons after navigation
cronJobListPage.list().resourceTable().sortableTable().pagination()
.paginationText()
.then((el) => {
expect(el.trim()).to.eq(`1 - 10 of ${ count } CronJobs`);
});
cronJobListPage.list().resourceTable().sortableTable().pagination()
.beginningButton()
.isDisabled();
cronJobListPage.list().resourceTable().sortableTable().pagination()
.leftButton()
.isDisabled();
});
});
it('sorting changes the order of paginated cronjobs data', () => {
WorkloadsCronJobsListPagePo.navTo();
cronJobListPage.waitForPage();
// use filter to only show test data
cronJobListPage.list().resourceTable().sortableTable().filter(rootResourceName);
// check table is sorted by name in ASC order by default
cronJobListPage.list().resourceTable().sortableTable().tableHeaderRow()
.checkSortOrder(2, 'down');
// cronjob name should be visible on first page (sorted in ASC order)
cronJobListPage.list().resourceTable().sortableTable().tableHeaderRow()
.self()
.scrollIntoView();
cronJobListPage.list().resourceTable().sortableTable().rowElementWithName(cronJobNamesList[0])
.scrollIntoView()
.should('be.visible');
// sort by name in DESC order
cronJobListPage.list().resourceTable().sortableTable().sort(2)
.click({ force: true });
cronJobListPage.list().resourceTable().sortableTable().tableHeaderRow()
.checkSortOrder(2, 'up');
// cronjob name should be NOT visible on first page (sorted in DESC order)
cronJobListPage.list().resourceTable().sortableTable().rowElementWithName(cronJobNamesList[0])
.should('not.exist');
// navigate to last page
cronJobListPage.list().resourceTable().sortableTable().pagination()
.endButton()
.scrollIntoView()
.click();
// cronjob name should be visible on last page (sorted in DESC order)
cronJobListPage.list().resourceTable().sortableTable().rowElementWithName(cronJobNamesList[0])
.scrollIntoView()
.should('be.visible');
});
it('filter cronjobs', () => {
WorkloadsCronJobsListPagePo.navTo();
cronJobListPage.waitForPage();
cronJobListPage.list().resourceTable().sortableTable().checkVisible();
cronJobListPage.list().resourceTable().sortableTable().checkLoadingIndicatorNotVisible();
cronJobListPage.list().resourceTable().sortableTable().checkRowCount(false, 10);
// filter by name
cronJobListPage.list().resourceTable().sortableTable().filter(cronJobNamesList[0]);
cronJobListPage.list().resourceTable().sortableTable().checkRowCount(false, 1);
cronJobListPage.list().resourceTable().sortableTable().rowElementWithName(cronJobNamesList[0])
.should('be.visible');
// filter by namespace
cronJobListPage.list().resourceTable().sortableTable().filter(nsName2);
cronJobListPage.list().resourceTable().sortableTable().checkRowCount(false, 1);
cronJobListPage.list().resourceTable().sortableTable().rowElementWithName(uniqueCronJob)
.should('be.visible');
});
it('pagination is hidden', () => {
cy.tableRowsPerPageAndNamespaceFilter(10, localCluster, 'none', '{"local":[]}');
// generate small set of cronjobs data
generateCronJobsDataSmall();
HomePagePo.goTo(); // this is needed here for the intercept to work
WorkloadsCronJobsListPagePo.navTo();
cy.wait('@cronJobsDataSmall');
cronJobListPage.waitForPage();
cronJobListPage.list().resourceTable().sortableTable().checkVisible();
cronJobListPage.list().resourceTable().sortableTable().checkLoadingIndicatorNotVisible();
cronJobListPage.list().resourceTable().sortableTable().checkRowCount(false, 1);
cronJobListPage.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 namespaces (this will also delete all cronjobs including detailsPageCronJob)
cy.deleteNamespace([nsName1, nsName2, nsName3]);
});
});
});