Skip to content

Commit b396471

Browse files
Added automated tests with cypress for C & U Gap Collection form
1 parent 893118b commit b396471

File tree

1 file changed

+121
-0
lines changed

1 file changed

+121
-0
lines changed
Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
/* eslint-disable no-undef */
2+
import { flashClassMap } from '../../../../support/assertions/assertion_constants';
3+
4+
// Menu options
5+
const SETTINGS_MENU_OPTION = 'Settings';
6+
const APP_SETTINGS_MENU_OPTION = 'Application Settings';
7+
8+
// List items
9+
const DIAGNOSTICS_ACCORDION_ITEM = 'Diagnostics';
10+
const MANAGEIQ_REGION_ACCORD_ITEM = /^ManageIQ Region:/;
11+
const ZONE_ACCORD_ITEM = /^Zone:/;
12+
13+
// Field values
14+
const FORM_HEADER = 'Diagnostics Zone';
15+
const FORM_SUBHEADER_SNIPPET = 'Collection Options';
16+
const TIMEZONE_TYPE_HAWAII = '(GMT-10:00) Hawaii';
17+
const START_DATE = '06/25/2026';
18+
const END_DATE = '06/28/2026';
19+
20+
// Buttons
21+
const SAVE_BUTTON_TEXT = 'Save';
22+
23+
// Flash message text snippets
24+
const FLASH_MESSAGE_GAP_COLLECTION_INITIATED = 'initiated';
25+
const FLASH_MESSAGE_DATE_RANGE_INVALID = 'cannot';
26+
27+
function assertFormInputFieldWithLabel(id) {
28+
// Assert timezone field label is visible
29+
cy.getFormLabelByInputId(id).should('be.visible');
30+
// Assert input field is visible and enabled
31+
cy.getFormInputFieldById(id).should('be.visible').and('be.enabled');
32+
}
33+
34+
function fillGapCollectionForm(startDateValue, endDateValue) {
35+
// Select "Hawaii" from timezone dropdown
36+
cy.getFormLabelByInputId('timezone').click();
37+
cy.contains('[role="option"]', TIMEZONE_TYPE_HAWAII)
38+
.should('be.visible')
39+
.click();
40+
// Add start date
41+
cy.getFormInputFieldById('startDate').type(startDateValue);
42+
// Add end date
43+
cy.getFormInputFieldById('endDate').type(endDateValue, {
44+
force: true,
45+
});
46+
}
47+
48+
function saveFormAndAssertFlashMessage(flashMessageType, flashMessage) {
49+
cy.interceptApi({
50+
alias: 'saveGapCollectionApi',
51+
urlPattern: '/ops/cu_repair?button=submit',
52+
triggerFn: () =>
53+
cy
54+
.getFormFooterButtonByType(SAVE_BUTTON_TEXT, 'submit')
55+
.click({ force: true }),
56+
onApiResponse: () => cy.expect_flash(flashMessageType, flashMessage),
57+
});
58+
}
59+
60+
describe('Automate C & U Gap Collection form operations: Settings > Application Settings > Diagnostics > ManageIQ Region > Zone Default Zone > C & U Gap Collection', () => {
61+
beforeEach(() => {
62+
cy.login();
63+
// Navigate to Application settings and expand Diagnostics accordion
64+
cy.menu(SETTINGS_MENU_OPTION, APP_SETTINGS_MENU_OPTION);
65+
cy.interceptApi({
66+
alias: 'accordionSelectApi',
67+
urlPattern: /\/ops\/accordion_select\?id=.*/,
68+
triggerFn: () => cy.accordion(DIAGNOSTICS_ACCORDION_ITEM),
69+
});
70+
// Select "Zone:" accordion item
71+
cy.interceptApi({
72+
alias: 'treeSelectApi',
73+
urlPattern: /\/ops\/tree_select\?id=.*&text=.*/,
74+
triggerFn: () =>
75+
cy.selectAccordionItem([MANAGEIQ_REGION_ACCORD_ITEM, ZONE_ACCORD_ITEM]),
76+
});
77+
// Select "C & U Gap Collection" tab
78+
cy.get(
79+
'#tab_all_tabs_div #ops_tabs .nav-tabs li#diagnostics_cu_repair_tab'
80+
).click();
81+
});
82+
83+
it('Validate form elements', () => {
84+
// Assert form header is visible
85+
cy.expect_explorer_title(FORM_HEADER).should('be.visible');
86+
// Assert form sub-header is visible
87+
cy.contains('#main-content .bx--form h3', FORM_SUBHEADER_SNIPPET).should(
88+
'be.visible'
89+
);
90+
// Assert timezone label & field is visible and enabled
91+
assertFormInputFieldWithLabel('timezone');
92+
// Assert start date label & field is visible and enabled
93+
assertFormInputFieldWithLabel('startDate');
94+
// Assert end date label & field is visible and enabled
95+
assertFormInputFieldWithLabel('endDate');
96+
// Assert save button is visible and disabled
97+
cy.getFormFooterButtonByType(SAVE_BUTTON_TEXT, 'submit')
98+
.should('be.visible')
99+
.and('be.disabled');
100+
});
101+
102+
it('Should fail if start date is greater than end date', () => {
103+
// Fill the form with end date less than start date
104+
fillGapCollectionForm(END_DATE, START_DATE);
105+
// Save form and assert flash error message
106+
saveFormAndAssertFlashMessage(
107+
flashClassMap.error,
108+
FLASH_MESSAGE_DATE_RANGE_INVALID
109+
);
110+
});
111+
112+
it('Validate gap collection initiation', () => {
113+
// Fill the form
114+
fillGapCollectionForm(START_DATE, END_DATE);
115+
// Save form and assert flash success message
116+
saveFormAndAssertFlashMessage(
117+
flashClassMap.success,
118+
FLASH_MESSAGE_GAP_COLLECTION_INITIATED
119+
);
120+
});
121+
});

0 commit comments

Comments
 (0)