Skip to content

Commit ee0165b

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

File tree

1 file changed

+119
-0
lines changed

1 file changed

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

0 commit comments

Comments
 (0)