Skip to content

Commit 1fe1fc4

Browse files
Added automated tests with cypress for C & U Gap Collection form
1 parent 2729d56 commit 1fe1fc4

File tree

1 file changed

+126
-0
lines changed

1 file changed

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

0 commit comments

Comments
 (0)