Skip to content

Commit be75b2c

Browse files
Replaced repeated form selectors with custom getter commands
1 parent 4d1cd48 commit be75b2c

File tree

1 file changed

+18
-29
lines changed

1 file changed

+18
-29
lines changed

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

Lines changed: 18 additions & 29 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
@@ -108,10 +102,7 @@ const {
108102
allocatedStorageQuota,
109103
allocatedVmQuota,
110104
nameAlreadyTakenError,
111-
buttonSelector,
112-
inputFieldSelector,
113105
submitButtonType,
114-
normalButtonType,
115106
resetButtonType,
116107
nameInputFieldId,
117108
descriptionInputFieldId,
@@ -139,10 +130,10 @@ function addOrEditOperation(
139130
isEditOperation = false
140131
) {
141132
// Check if button is disabled initially
142-
cy.contains(buttonSelector(submitButtonType), button).should('be.disabled');
133+
cy.getFormFooterButtonByType(button, submitButtonType).should('be.disabled');
143134
// Add or edit name and description
144-
const nameField = cy.get(inputFieldSelector(nameInputFieldId));
145-
const descriptionField = cy.get(inputFieldSelector(descriptionInputFieldId));
135+
const nameField = cy.getFormInputFieldById(nameInputFieldId);
136+
const descriptionField = cy.getFormInputFieldById(descriptionInputFieldId);
146137
if (isEditOperation) {
147138
nameField.clear().type(name);
148139
descriptionField.clear().type(description);
@@ -151,7 +142,7 @@ function addOrEditOperation(
151142
descriptionField.type(description);
152143
}
153144
// Save the form
154-
cy.contains(buttonSelector(submitButtonType), button)
145+
cy.getFormFooterButtonByType(button, submitButtonType)
155146
.should('be.enabled')
156147
.click();
157148
cy.expect_flash(flashTypeSuccess, flashMessageSnippet);
@@ -254,13 +245,13 @@ function editQuotasTable(quotaName = allocatedStorageQuota) {
254245

255246
function quotasResetOperation(quotaName = allocatedStorageQuota) {
256247
// Check if Reset button is disabled initially
257-
cy.contains(buttonSelector(resetButtonType), resetButton).should(
248+
cy.getFormFooterButtonByType(resetButton, resetButtonType).should(
258249
'be.disabled'
259250
);
260251
// Editing the quota table
261252
editQuotasTable(quotaName);
262253
// Confirm Reset button is enabled once table values are updated and then click on Reset
263-
cy.contains(buttonSelector(resetButtonType), resetButton)
254+
cy.getFormFooterButtonByType(resetButton, resetButtonType)
264255
.should('be.enabled')
265256
.click();
266257
cy.expect_flash(flashTypeWarning, flashMessageOperationReset);
@@ -270,7 +261,7 @@ function updateQuotas(quotaName = allocatedStorageQuota) {
270261
// Opting for the desired quota in the table
271262
editQuotasTable(quotaName);
272263
// Saving the form
273-
cy.contains(buttonSelector(submitButtonType), saveButton).click();
264+
cy.getFormFooterButtonByType(saveButton, submitButtonType).click();
274265
cy.expect_flash(flashTypeSuccess, flashMessageSaved);
275266
}
276267

@@ -288,12 +279,12 @@ function rollbackQuotas() {
288279
}
289280
});
290281
// Saving the form
291-
cy.contains(buttonSelector(submitButtonType), saveButton).click();
282+
cy.getFormFooterButtonByType(saveButton, submitButtonType).click();
292283
}
293284

294285
function cancelOperation(flashMessageSnippet = flashMessageOperationCanceled) {
295286
// Cancel the form
296-
cy.contains(buttonSelector(normalButtonType), cancelButton).click();
287+
cy.getFormFooterButtonByType(cancelButton).click();
297288
cy.expect_flash(flashTypeWarning, flashMessageSnippet);
298289
}
299290

@@ -302,20 +293,18 @@ function resetOperation(
302293
oldDescription = initialParentTenantDescription
303294
) {
304295
// Check if Reset button is disabled initially
305-
cy.contains(buttonSelector(normalButtonType), resetButton).should(
306-
'be.disabled'
307-
);
296+
cy.getFormFooterButtonByType(resetButton).should('be.disabled');
308297
// Editing name and description fields
309-
cy.get(inputFieldSelector(nameInputFieldId)).type(editedTenantNameValue);
310-
cy.get(inputFieldSelector(descriptionInputFieldId)).type(editedDescriptionValue);
298+
cy.getFormInputFieldById(nameInputFieldId).type(editedTenantNameValue);
299+
cy.getFormInputFieldById(descriptionInputFieldId).type(
300+
editedDescriptionValue
301+
);
311302
// 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();
303+
cy.getFormFooterButtonByType(resetButton).should('be.enabled').click();
315304
cy.expect_flash(flashTypeWarning, flashMessageOperationReset);
316305
// Confirm name and description has old values
317-
cy.get(inputFieldSelector(nameInputFieldId)).should('have.value', oldName);
318-
cy.get(inputFieldSelector(descriptionInputFieldId)).should(
306+
cy.getFormInputFieldById(nameInputFieldId).should('have.value', oldName);
307+
cy.getFormInputFieldById(descriptionInputFieldId).should(
319308
'have.value',
320309
oldDescription
321310
);
@@ -446,7 +435,7 @@ describe('Automate Tenant form operations: Settings > Application Settings > Acc
446435
// Open the Add child tenant form again
447436
cy.toolbar(configToolbarButton, addChildTenantConfigOption);
448437
// Trying to add a child tenant with the same name
449-
cy.get(inputFieldSelector(nameInputFieldId)).type(initialChildTenantName);
438+
cy.getFormInputFieldById(nameInputFieldId).type(initialChildTenantName);
450439
cy.get('#rbac_details #name-error-msg').contains(nameAlreadyTakenError);
451440
// Cancel the add form
452441
cancelOperation();

0 commit comments

Comments
 (0)