Skip to content

Commit b8fc5d5

Browse files
Enhanced test with additional mock data
1 parent 5e78f1e commit b8fc5d5

File tree

1 file changed

+110
-21
lines changed

1 file changed

+110
-21
lines changed

cypress/e2e/ui/Services/Requests/service_requests.cy.js

Lines changed: 110 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ const REASON_LABEL = 'Reason';
2222
const SELECT_OPTION_ALL = 'all';
2323
const TYPE_VM_RECONFIGURE = 'vm_reconfigure';
2424
const REQUEST_DATE_LAST_7_DAYS = '7';
25+
const REQUEST_DATE_LAST_30_DAYS = '30';
2526

2627
// Checkbox labels
2728
const PENDING_APPROVAL_LABEL = 'Pending Approval';
@@ -51,17 +52,26 @@ function getDateStringInDbFormat(dateObject = new Date()) {
5152
return `${year}-${month}-${day} ${hours}:${minutes}:${seconds}.${micros}`;
5253
}
5354

55+
/**
56+
* Function to do assertions on table data
57+
*/
58+
function assertGtlData({ columnIndex, expectedRowCount, rowContainsText }) {
59+
cy.gtlGetRows([columnIndex]).then((data) => {
60+
expect(data.length).to.equal(expectedRowCount);
61+
if (rowContainsText) {
62+
expect(data[0][0]).to.include(rowContainsText);
63+
}
64+
});
65+
}
66+
5467
describe('Automate Service Requests form operations: Services > Requests', () => {
5568
beforeEach(() => {
5669
cy.login();
5770
});
5871

5972
describe('Verify form fields', () => {
60-
beforeEach(() => {
61-
cy.menu(SERVICES_MENU_OPTION, REQUESTS_MENU_OPTION);
62-
});
63-
6473
it('Verify form’s initial UI state', () => {
74+
cy.menu(SERVICES_MENU_OPTION, REQUESTS_MENU_OPTION);
6575
cy.contains('#main-content h1', FORM_HEADER);
6676
cy.getFormLegendByText({ legendText: APPROVAL_STATE_HEADER });
6777
cy.validateFormLabels([
@@ -208,13 +218,21 @@ describe('Automate Service Requests form operations: Services > Requests', () =>
208218
status: 'Ok',
209219
},
210220
],
211-
]);
221+
]).then((createdRequestsData) => {
222+
expect(createdRequestsData.length).to.equal(4);
223+
cy.menu(SERVICES_MENU_OPTION, REQUESTS_MENU_OPTION);
224+
});
212225
});
213226

214227
it('Validate reset & apply buttons', () => {
215228
/* Reset */
216-
cy.getFormSelectFieldById({ selectId: 'selectedUser' }).select(
217-
'Administrator'
229+
cy.getFormSelectFieldById({ selectId: 'selectedUser' }).then(
230+
(selectElement) => {
231+
const value = [...selectElement[0].options].find(
232+
(option) => option.value !== SELECT_OPTION_ALL
233+
).value;
234+
cy.wrap(selectElement).select(value);
235+
}
218236
);
219237
cy.getFormLabelByForAttribute({
220238
forValue: 'approvalStates-pending_approval',
@@ -238,7 +256,7 @@ describe('Automate Service Requests form operations: Services > Requests', () =>
238256
inputType: 'checkbox',
239257
}).should('not.be.checked');
240258
cy.getFormSelectFieldById({ selectId: 'types' }).select(
241-
TYPE_VM_PROVISION
259+
TYPE_VM_RECONFIGURE
242260
);
243261
cy.getFormSelectFieldById({ selectId: 'selectedPeriod' }).select(
244262
'Last 30 Days'
@@ -278,7 +296,7 @@ describe('Automate Service Requests form operations: Services > Requests', () =>
278296
''
279297
);
280298
/* Apply */
281-
// Filter data with approval state
299+
// Filter data with approval state: Denied
282300
cy.getFormLabelByForAttribute({
283301
forValue: 'approvalStates-pending_approval',
284302
}).click();
@@ -297,29 +315,102 @@ describe('Automate Service Requests form operations: Services > Requests', () =>
297315
buttonText: APPLY_BUTTON_TEXT,
298316
buttonType: 'submit',
299317
}).click();
300-
cy.expect_gtl_no_records_with_text();
318+
assertGtlData({
319+
columnIndex: 7,
320+
expectedRowCount: 1,
321+
rowContainsText: DENIED_LABEL,
322+
});
323+
cy.getFormButtonByTypeWithText({
324+
buttonText: RESET_BUTTON_TEXT,
325+
}).click();
326+
assertGtlData({ columnIndex: 0, expectedRowCount: 3 });
327+
// Filter data with approval state: Approved
328+
cy.getFormLabelByForAttribute({
329+
forValue: 'approvalStates-pending_approval',
330+
}).click();
331+
cy.getFormInputFieldByIdAndType({
332+
inputId: 'approvalStates-pending_approval',
333+
inputType: 'checkbox',
334+
}).should('not.be.checked');
335+
cy.getFormLabelByForAttribute({
336+
forValue: 'approvalStates-denied',
337+
}).click();
338+
cy.getFormInputFieldByIdAndType({
339+
inputId: 'approvalStates-denied',
340+
inputType: 'checkbox',
341+
}).should('not.be.checked');
342+
cy.getFormButtonByTypeWithText({
343+
buttonText: APPLY_BUTTON_TEXT,
344+
buttonType: 'submit',
345+
}).click();
346+
assertGtlData({
347+
columnIndex: 7,
348+
expectedRowCount: 1,
349+
rowContainsText: APPROVED_LABEL,
350+
});
301351
cy.getFormButtonByTypeWithText({
302352
buttonText: RESET_BUTTON_TEXT,
303353
}).click();
304-
cy.gtlGetRows([0]).then((data) => {
305-
expect(data.length).to.equal(1);
354+
assertGtlData({ columnIndex: 0, expectedRowCount: 3 });
355+
// Filter data with approval state: Pending approval
356+
cy.getFormLabelByForAttribute({
357+
forValue: 'approvalStates-approved',
358+
}).click();
359+
cy.getFormInputFieldByIdAndType({
360+
inputId: 'approvalStates-approved',
361+
inputType: 'checkbox',
362+
}).should('not.be.checked');
363+
cy.getFormLabelByForAttribute({
364+
forValue: 'approvalStates-denied',
365+
}).click();
366+
cy.getFormInputFieldByIdAndType({
367+
inputId: 'approvalStates-denied',
368+
inputType: 'checkbox',
369+
}).should('not.be.checked');
370+
cy.getFormButtonByTypeWithText({
371+
buttonText: APPLY_BUTTON_TEXT,
372+
buttonType: 'submit',
373+
}).click();
374+
assertGtlData({
375+
columnIndex: 7,
376+
expectedRowCount: 1,
377+
rowContainsText: PENDING_APPROVAL_LABEL,
306378
});
307-
// Filter data with type
379+
cy.getFormButtonByTypeWithText({
380+
buttonText: RESET_BUTTON_TEXT,
381+
}).click();
382+
assertGtlData({ columnIndex: 0, expectedRowCount: 3 });
383+
// Filter data with type: VM Reconfigure
308384
cy.getFormSelectFieldById({ selectId: 'types' }).select(
309-
TYPE_VM_PROVISION
385+
TYPE_VM_RECONFIGURE
310386
);
311387
cy.getFormButtonByTypeWithText({
312388
buttonText: APPLY_BUTTON_TEXT,
313389
buttonType: 'submit',
314390
}).click();
315-
cy.expect_gtl_no_records_with_text();
391+
assertGtlData({
392+
columnIndex: 4,
393+
expectedRowCount: 1,
394+
rowContainsText: 'VM Reconfigure',
395+
});
316396
cy.getFormButtonByTypeWithText({
317397
buttonText: RESET_BUTTON_TEXT,
318398
}).click();
319-
cy.gtlGetRows([0]).then((data) => {
320-
expect(data.length).to.equal(1);
399+
assertGtlData({ columnIndex: 0, expectedRowCount: 3 });
400+
// Filter data with request date: last 30 days
401+
cy.getFormSelectFieldById({ selectId: 'selectedPeriod' }).select(
402+
REQUEST_DATE_LAST_30_DAYS
403+
);
404+
cy.getFormButtonByTypeWithText({
405+
buttonText: APPLY_BUTTON_TEXT,
406+
buttonType: 'submit',
407+
}).click();
408+
assertGtlData({
409+
columnIndex: 6,
410+
expectedRowCount: 4,
411+
rowContainsText: 'request made in the last 30 days',
321412
});
322-
// Filter data with
413+
// Filter data with reason text
323414
cy.getFormInputFieldByIdAndType({ inputId: 'reasonText' }).type('r@ndOm');
324415
cy.getFormButtonByTypeWithText({
325416
buttonText: APPLY_BUTTON_TEXT,
@@ -329,9 +420,7 @@ describe('Automate Service Requests form operations: Services > Requests', () =>
329420
cy.getFormButtonByTypeWithText({
330421
buttonText: RESET_BUTTON_TEXT,
331422
}).click();
332-
cy.gtlGetRows([0]).then((data) => {
333-
expect(data.length).to.equal(1);
334-
});
423+
assertGtlData({ columnIndex: 0, expectedRowCount: 3 });
335424
});
336425

337426
afterEach(() => {

0 commit comments

Comments
 (0)