Skip to content

Commit 8ca7228

Browse files
Added automated tests with cypress for C & U Gap Collection form
1 parent 5008352 commit 8ca7228

File tree

1 file changed

+124
-0
lines changed

1 file changed

+124
-0
lines changed
Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
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+
// 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.getFormLabelByForAttribute({ forValue: 'timezone' }).click();
30+
cy.contains('[role="option"]', TIMEZONE_TYPE_HAWAII).click();
31+
// Add start date
32+
cy.getFormInputFieldByIdAndType({ inputId: 'startDate' }).type(
33+
startDateValue
34+
);
35+
// Add end date
36+
cy.getFormInputFieldByIdAndType({ inputId: '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+
.getFormFooterButtonByTypeWithText({
48+
buttonText: 'Save',
49+
buttonType: 'submit',
50+
})
51+
.click({ force: true }),
52+
onApiResponse: () => cy.expect_flash(flashMessageType, flashMessage),
53+
});
54+
}
55+
56+
describe('Automate C & U Gap Collection form operations: Settings > Application Settings > Diagnostics > ManageIQ Region > Zone Default Zone > C & U Gap Collection', () => {
57+
beforeEach(() => {
58+
cy.login();
59+
// Navigate to Application settings and expand Diagnostics accordion
60+
cy.menu(SETTINGS_MENU_OPTION, APP_SETTINGS_MENU_OPTION);
61+
cy.accordion(DIAGNOSTICS_ACCORDION_ITEM);
62+
// Select "Zone:" accordion item
63+
cy.selectAccordionItem([MANAGEIQ_REGION_ACCORD_ITEM, ZONE_ACCORD_ITEM]);
64+
// Select "C & U Gap Collection" tab
65+
cy.tabs({ tabLabel: 'C & U Gap Collection' });
66+
});
67+
68+
it('Validate form elements', () => {
69+
// Assert form header is visible
70+
cy.expect_explorer_title(FORM_HEADER).should('be.visible');
71+
// Assert form sub-header is visible
72+
cy.contains('#main-content .bx--form h3', FORM_SUBHEADER_SNIPPET).should(
73+
'be.visible'
74+
);
75+
// Assert timezone label & field is visible and enabled
76+
cy.getFormLabelByForAttribute({ forValue: 'timezone' })
77+
.should('be.visible')
78+
.and('contain.text', TIMEZONE_FIELD_LABEL);
79+
cy.getFormInputFieldByIdAndType({ inputId: 'timezone' })
80+
.should('be.visible')
81+
.and('be.enabled');
82+
// Assert start date label & field is visible and enabled
83+
cy.getFormLabelByForAttribute({ forValue: 'startDate' })
84+
.should('be.visible')
85+
.and('contain.text', START_DATE_FIELD_LABEL);
86+
cy.getFormInputFieldByIdAndType({ inputId: 'startDate' })
87+
.should('be.visible')
88+
.and('be.enabled');
89+
// Assert end date label & field is visible and enabled
90+
cy.getFormLabelByForAttribute({ forValue: 'endDate' })
91+
.should('be.visible')
92+
.and('contain.text', END_DATE_FIELD_LABEL);
93+
cy.getFormInputFieldByIdAndType({ inputId: 'endDate' })
94+
.should('be.visible')
95+
.and('be.enabled');
96+
// Assert save button is visible and disabled
97+
cy.getFormFooterButtonByTypeWithText({
98+
buttonText: 'Save',
99+
buttonType: 'submit',
100+
})
101+
.should('be.visible')
102+
.and('be.disabled');
103+
});
104+
105+
it('Should fail if start date is greater than end date', () => {
106+
// Fill the form with end date less than start date
107+
fillGapCollectionForm(END_DATE, START_DATE);
108+
// Save form and assert flash error message
109+
saveFormAndAssertFlashMessage(
110+
flashClassMap.error,
111+
FLASH_MESSAGE_DATE_RANGE_INVALID
112+
);
113+
});
114+
115+
it('Validate gap collection initiation', () => {
116+
// Fill the form
117+
fillGapCollectionForm(START_DATE, END_DATE);
118+
// Save form and assert flash success message
119+
saveFormAndAssertFlashMessage(
120+
flashClassMap.success,
121+
FLASH_MESSAGE_GAP_COLLECTION_INITIATED
122+
);
123+
});
124+
});

0 commit comments

Comments
 (0)