-
Notifications
You must be signed in to change notification settings - Fork 365
Added automated tests with cypress for C & U Gap Collection form #9562
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
jrafanie
merged 1 commit into
ManageIQ:master
from
asirvadAbrahamVarghese:c-and-u-gap-collection-form-automation-testing
Sep 25, 2025
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
126 changes: 126 additions & 0 deletions
126
cypress/e2e/ui/Settings/Application-Settings/c_and_u_gap_collection.cy.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,126 @@ | ||
/* eslint-disable no-undef */ | ||
import { flashClassMap } from '../../../../support/assertions/assertion_constants'; | ||
|
||
// Menu options | ||
const SETTINGS_MENU_OPTION = 'Settings'; | ||
const APP_SETTINGS_MENU_OPTION = 'Application Settings'; | ||
|
||
// List items | ||
const DIAGNOSTICS_ACCORDION_ITEM = 'Diagnostics'; | ||
const MANAGEIQ_REGION_ACCORD_ITEM = /^ManageIQ Region:/; | ||
const ZONE_ACCORD_ITEM = /^Zone:/; | ||
|
||
// Field values | ||
const TIMEZONE_FIELD_LABEL = 'Timezone'; | ||
const START_DATE_FIELD_LABEL = 'Start Date'; | ||
const END_DATE_FIELD_LABEL = 'End Date'; | ||
const FORM_HEADER = 'Diagnostics Zone'; | ||
const FORM_SUBHEADER_SNIPPET = 'Collection Options'; | ||
const TIMEZONE_TYPE_HAWAII = '(GMT-10:00) Hawaii'; | ||
const START_DATE = '06/25/2026'; | ||
const END_DATE = '06/28/2026'; | ||
|
||
// Flash message text snippets | ||
const FLASH_MESSAGE_GAP_COLLECTION_INITIATED = 'initiated'; | ||
const FLASH_MESSAGE_DATE_RANGE_INVALID = 'cannot'; | ||
|
||
function fillGapCollectionForm(startDateValue, endDateValue) { | ||
// Select "Hawaii" from timezone dropdown | ||
cy.getFormLabelByForAttribute({ forValue: 'timezone' }).click(); | ||
cy.contains('[role="option"]', TIMEZONE_TYPE_HAWAII).click(); | ||
// Add start date | ||
cy.getFormInputFieldByIdAndType({ inputId: 'startDate' }).type( | ||
startDateValue | ||
); | ||
// Click elsewhere to close the start date calendar popup | ||
cy.get('h3').contains(FORM_SUBHEADER_SNIPPET).click(); | ||
// Add end date | ||
cy.getFormInputFieldByIdAndType({ inputId: 'endDate' }).type(endDateValue); | ||
// Click elsewhere to close the end date calendar popup | ||
cy.get('h3').contains(FORM_SUBHEADER_SNIPPET).click(); | ||
} | ||
|
||
function saveFormAndAssertFlashMessage(flashMessageType, flashMessage) { | ||
cy.interceptApi({ | ||
alias: 'saveGapCollectionApi', | ||
urlPattern: '/ops/cu_repair?button=submit', | ||
triggerFn: () => | ||
cy | ||
.getFormFooterButtonByTypeWithText({ | ||
buttonText: 'Save', | ||
buttonType: 'submit', | ||
}) | ||
.click(), | ||
onApiResponse: () => cy.expect_flash(flashMessageType, flashMessage), | ||
}); | ||
} | ||
|
||
describe('Automate C & U Gap Collection form operations: Settings > Application Settings > Diagnostics > ManageIQ Region > Zone Default Zone > C & U Gap Collection', () => { | ||
beforeEach(() => { | ||
cy.login(); | ||
// Navigate to Application settings and expand Diagnostics accordion | ||
cy.menu(SETTINGS_MENU_OPTION, APP_SETTINGS_MENU_OPTION); | ||
cy.accordion(DIAGNOSTICS_ACCORDION_ITEM); | ||
// Select "Zone:" accordion item | ||
cy.selectAccordionItem([MANAGEIQ_REGION_ACCORD_ITEM, ZONE_ACCORD_ITEM]); | ||
// Select "C & U Gap Collection" tab | ||
cy.tabs({ tabLabel: 'C & U Gap Collection' }); | ||
}); | ||
|
||
it('Validate form elements', () => { | ||
// Assert form header is visible | ||
cy.expect_explorer_title(FORM_HEADER).should('be.visible'); | ||
// Assert form sub-header is visible | ||
cy.contains('#main-content .bx--form h3', FORM_SUBHEADER_SNIPPET).should( | ||
'be.visible' | ||
); | ||
// Assert timezone label & field is visible and enabled | ||
cy.getFormLabelByForAttribute({ forValue: 'timezone' }) | ||
.should('be.visible') | ||
.and('contain.text', TIMEZONE_FIELD_LABEL); | ||
cy.getFormInputFieldByIdAndType({ inputId: 'timezone' }) | ||
.should('be.visible') | ||
.and('be.enabled'); | ||
// Assert start date label & field is visible and enabled | ||
cy.getFormLabelByForAttribute({ forValue: 'startDate' }) | ||
.should('be.visible') | ||
.and('contain.text', START_DATE_FIELD_LABEL); | ||
cy.getFormInputFieldByIdAndType({ inputId: 'startDate' }) | ||
.should('be.visible') | ||
.and('be.enabled'); | ||
// Assert end date label & field is visible and enabled | ||
cy.getFormLabelByForAttribute({ forValue: 'endDate' }) | ||
.should('be.visible') | ||
.and('contain.text', END_DATE_FIELD_LABEL); | ||
cy.getFormInputFieldByIdAndType({ inputId: 'endDate' }) | ||
.should('be.visible') | ||
.and('be.enabled'); | ||
// Assert save button is visible and disabled | ||
cy.getFormFooterButtonByTypeWithText({ | ||
buttonText: 'Save', | ||
buttonType: 'submit', | ||
}) | ||
.should('be.visible') | ||
.and('be.disabled'); | ||
}); | ||
|
||
it('Should fail if start date is greater than end date', () => { | ||
// Fill the form with end date less than start date | ||
fillGapCollectionForm(END_DATE, START_DATE); | ||
// Save form and assert flash error message | ||
saveFormAndAssertFlashMessage( | ||
flashClassMap.error, | ||
FLASH_MESSAGE_DATE_RANGE_INVALID | ||
); | ||
}); | ||
|
||
it('Validate gap collection initiation', () => { | ||
// Fill the form | ||
fillGapCollectionForm(START_DATE, END_DATE); | ||
// Save form and assert flash success message | ||
saveFormAndAssertFlashMessage( | ||
flashClassMap.success, | ||
FLASH_MESSAGE_GAP_COLLECTION_INITIATED | ||
); | ||
}); | ||
}); |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does cypress expose a global variable or a function to get the support or cypress directory? If we split other tests out to directories of tests, it would be painful to add or remove "../.." above so it can find the file.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cypress doesn't provide a built-in global variable specifically for resolving paths.
This was already on my cypress enhancement to-do list involving the webpack-preprocessor. I will come up with a follow up PR to allow importing utils in an aliased format instead of relative paths.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great. If there's a single file that defines a constant to a path they can reuse to find file to import, that would be good enough. As you suggest, for follow up... not for here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The way I see your point, that approach would work if all test files were at the same directory depth, since our test directories vary depending on menu navigation depth, the number of "../" in the relative paths also changes, making it unreliable to use a fixed relative path constant.
For Settings/Application-Settings it would be "./../../../" and for Automate/Embeded/Explorer it would be "../../../../../"
I’m not sure if I’ve interpreted your suggestion correctly....
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PR with an alternative solution to resolve modules: #9631
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Your solution is good. I think I would want to use cypress as the directory... so you can do things relative to cypress... so it would be