Skip to content

Commit 5d4ec73

Browse files
Replaced repeated form selectors with custom getter commands
1 parent c382d24 commit 5d4ec73

File tree

1 file changed

+12
-20
lines changed

1 file changed

+12
-20
lines changed

cypress/e2e/ui/Settings/Application-Settings/tenant.cy.js

Lines changed: 12 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,8 @@ const textConstants = {
2323
initialChildTenantName: 'Child-Tenant',
2424
initialChildTenantDescription: 'Child Tenant description',
2525

26-
// Common selectors
27-
inputFieldSelector: (inputId) =>
28-
`#main-content .bx--form-item input#${inputId}`,
29-
buttonSelector: (type) => `#main-content .bx--btn-set button[type="${type}"]`,
30-
3126
// Button types
3227
submitButtonType: 'submit',
33-
normalButtonType: 'button',
3428
resetButtonType: 'reset',
3529

3630
// Element ids
@@ -154,8 +148,8 @@ function addOrEditOperation(
154148
// Check if button is disabled initially
155149
cy.getFormFooterButtonByType(button, 'submit').should('be.disabled');
156150
// Add or edit name and description
157-
const nameField = cy.get(inputFieldSelector(nameInputFieldId));
158-
const descriptionField = cy.get(inputFieldSelector(descriptionInputFieldId));
151+
const nameField = cy.getFormInputFieldById(nameInputFieldId);
152+
const descriptionField = cy.getFormInputFieldById(descriptionInputFieldId);
159153
if (isEditOperation) {
160154
nameField.clear().type(name);
161155
descriptionField.clear().type(description);
@@ -293,7 +287,7 @@ function rollbackQuotas() {
293287

294288
function cancelOperation(flashMessageSnippet = flashMessageOperationCanceled) {
295289
// Cancel the form
296-
cy.contains(buttonSelector(normalButtonType), cancelButton).click();
290+
cy.getFormFooterButtonByType(cancelButton).click();
297291
cy.expect_flash(flashTypeWarning, flashMessageSnippet);
298292
}
299293

@@ -302,20 +296,18 @@ function resetOperation(
302296
oldDescription = initialParentTenantDescription
303297
) {
304298
// Check if Reset button is disabled initially
305-
cy.contains(buttonSelector(normalButtonType), resetButton).should(
306-
'be.disabled'
307-
);
299+
cy.getFormFooterButtonByType(resetButton).should('be.disabled');
308300
// Editing name and description fields
309-
cy.get(inputFieldSelector(nameInputFieldId)).type(editedTenantNameValue);
310-
cy.get(inputFieldSelector(descriptionInputFieldId)).type(editedDescriptionValue);
301+
cy.getFormInputFieldById(nameInputFieldId).type(editedTenantNameValue);
302+
cy.getFormInputFieldById(descriptionInputFieldId).type(
303+
editedDescriptionValue
304+
);
311305
// Confirm Reset button is enabled once dropdown value is changed and then click on Reset
312-
cy.contains(buttonSelector(normalButtonType), resetButton)
313-
.should('be.enabled')
314-
.click();
306+
cy.getFormFooterButtonByType(resetButton).should('be.enabled').click();
315307
cy.expect_flash(flashTypeWarning, flashMessageOperationReset);
316308
// Confirm name and description has old values
317-
cy.get(inputFieldSelector(nameInputFieldId)).should('have.value', oldName);
318-
cy.get(inputFieldSelector(descriptionInputFieldId)).should(
309+
cy.getFormInputFieldById(nameInputFieldId).should('have.value', oldName);
310+
cy.getFormInputFieldById(descriptionInputFieldId).should(
319311
'have.value',
320312
oldDescription
321313
);
@@ -458,7 +450,7 @@ describe('Automate Tenant form operations: Settings > Application Settings > Acc
458450
// Open the Add child tenant form again
459451
cy.toolbar(configToolbarButton, addChildTenantConfigOption);
460452
// Trying to add a child tenant with the same name
461-
cy.get(inputFieldSelector(nameInputFieldId)).type(initialChildTenantName);
453+
cy.getFormInputFieldById(nameInputFieldId).type(initialChildTenantName);
462454
cy.get('#rbac_details #name-error-msg').contains(nameAlreadyTakenError);
463455
// Cancel the add form
464456
cancelOperation();

0 commit comments

Comments
 (0)