-
Notifications
You must be signed in to change notification settings - Fork 365
[WIP] - Added automated tests with cypress for Tenants form #9532
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
base: master
Are you sure you want to change the base?
[WIP] - Added automated tests with cypress for Tenants form #9532
Conversation
fe71238
to
3cdea0a
Compare
Sporadic server-related failures were noticed here as well: A couple of API requests are made right after logging in, prior to dashboard rendering: So I just tried adding a fixed wait using |
Need a second opinion here -This test currently bundles add project and manage quotas with both parent and child tenants, which makes it quite large. Would it be better to break out add project and manage quotas into standalone tests? |
TODOs:
|
RE: the sporadic test failure... see #9515 (comment) (if we can bypass saving session in the API and some of the /dashboard GETs, most of the contention causing stale session writes should be removed. 🤞 |
3cdea0a
to
f3ec47a
Compare
Related issue on tenant deletion: #9512 |
339c7eb
to
42fcdcf
Compare
|
||
it('Validate Cancel & Reset buttons in Manage Quotas form', () => { | ||
// Edit the quotas table and reset the quotas | ||
quotasResetOperation(); |
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.
This quotasResetOperation function combines the navigate to the form, editing it, clicking a button and validating the flash/result. I think these would read better if the tests read like this:
cy.getFormFooterButtonByType(resetButton, resetButtonType).should(
'be.disabled'
);
// Editing the quota table
editQuotasTable(quotaName);
cy.getFormFooterButtonByType(resetButton, resetButtonType)
.should('be.enabled')
.click();
cy.expect_flash(flashTypeWarning, flashMessageOperationReset);
cancelOperation();
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.
|
||
it('Validate Manage Quotas function', () => { | ||
// Enabling the quota: "Allocated Storage in GB" with value 10 | ||
updateQuotas(); |
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.
Same as above, I need to scroll to the function to understand what's being done and then asserted.
I don't mind repeating the same code if it better describes the test:
editQuotasTable(quotaName);
// Saving the form
cy.getFormFooterButtonByType(saveButton, submitButtonType).click();
cy.expect_flash(flashTypeSuccess, flashMessageSaved);
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.
|
||
it('Validate cancel button on Add child tenant form', () => { | ||
// Cancel the add operation | ||
cancelOperation(); |
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.
not sure if this is worthy of a separate test. It's also called on line 441.
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.
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.
Thanks for the clarification. Basically, if we have a single step test, we should verify if it's really within a larger workflow. It's ok to unit test in cypress but I think something like cancel would be better suited towards filling out the minimum needed for a form but then hitting cancel. Or mix it with "click add child tenant", "cancel", click it again, fill out the form and save/add.
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.
Makes sense, mixed it with "add & delete child tenant" test - see
|
||
it('Validate Cancel & Reset buttons on Edit tenant form', () => { | ||
// Reset operation | ||
resetOperation(); |
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.
Similar to above, this function is doing more than one thing. I think it would read better as a test:
verify reset disabled
edit form
verify reset enabled / any other validations
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.
}); | ||
|
||
after(() => { | ||
confirmUiNavigation(() => deleteAccordionItem(projectNameValue)); |
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.
Similar here... single after call... wondering if we could have a problem if the test were run out of order in a specific order.
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.
oh wait, is after an alias for afterEach?
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.
Since the suite 'Validate Add Project function' has only one test, using after or afterEach effectively results in the same behaviour.
oh wait, is after an alias for afterEach?
not really after
and afterEach
are different hooks
after
: Runs once after all tests in a describe block have completed
afterEach
: Runs after each individual test in a describe block
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.
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.
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.
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.
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.
Thanks, switched to afterEach
be75b2c
to
5d4ec73
Compare
f59a514
to
1fe2474
Compare
|
||
it('Validate cancel button on Add child tenant form', () => { | ||
// Cancel the add operation | ||
cancelForm(); |
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.
we call cancelForm(); in several other places... I'm not sure it's worth testing on it's own here. Maybe it can be tested in the test above: validateFormElements
. In other words, when validating the add child tenant form elements, I'm thinking the cancel button is part of a way to test the form.
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.
Moving that into the test above 'Validate Add child tenant form elements' (see)
I avoided placing that inside validateFormElements
because it's used in other tests where cancel validation isn’t needed & adding a flag to control it would make it less clean
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.
This is now moved along with "Add & delete child tenant" test, as discussed above
dd4684f
to
6f9f4bb
Compare
// Assert form header is visible | ||
cy.expect_explorer_title(formHeaderFragment); | ||
// Assert name field label is visible | ||
cy.getFormLabelByInputId(nameInputFieldId).should('be.visible'); |
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.
Do we care about the getFormLabelByInputId
? We only check that the element is in the dom and has that id. We don't check the value elsewhere. If we care, we should check the id has a value or remove it entirely. Thoughts?
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.
Updated to check the label text: see
but I am also thinking to use .contains
in getFormLabelByInputId as we did with getFormFooterButtonByType
It might make sense to use .contains
when a specific text is passed, and .get
otherwise, as the label is already targeted using the linked element’s ID (for attribute), which should uniquely identify it.
Cypress.Commands.add(
'getFormLabelByForAttributeAndText',
({ forValue, labelText }) => {
if (forValue) {
return labelText
? cy.contains(
`#main-content .bx--form label[for="${forValue}"]`,
labelText
)
: cy.get(`#main-content .bx--form label[for="${forValue}"]`);
}
cy.logAndThrowError('forValue is required');
}
);
Can be done as part of #9598
.should('be.visible') | ||
.and('be.enabled'); | ||
// Assert description field label is visible | ||
cy.getFormLabelByInputId(descriptionInputFieldId).should('be.visible'); |
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.
Same as above
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.
Updated to check the label text: see
67570c4
to
4e9c401
Compare
4e9c401
to
9fc6bb4
Compare
CP4AIOPS-16943
Pr that adds cypress tests for Tenants form(Settings -> Application Settings ->Access Control -> Tenants)
@miq-bot assign @elsamaryv
@miq-bot add-label cypress
@miq-bot add-label test