Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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';
Copy link
Member

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.

Copy link
Contributor Author

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?

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.

Copy link
Member

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.

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

Copy link
Contributor Author

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.

  └── cypress/support/assertions/assertion_constants.js
  └── cypress/e2e/ui/Settings/Application-Settings/test1.js
  └── cypress/e2e/ui/Automate/Embeded/Explorer/test2.js

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....

Copy link
Contributor Author

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

Copy link
Member

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

  └── @cypress-dir/support/assertions/assertion_constants.js
  └── @cypress-dir/e2e/ui/Settings/Application-Settings/test1.js
  └── @cypress-dir/e2e/ui/Automate/Embeded/Explorer/test2.js


// 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
);
});
});