@@ -14,13 +14,32 @@ const textConstants = {
1414 toolbarEditNamespace: 'Edit this Namespace',
1515 toolbarRemoveNamespace: 'Remove this Namespace',
1616
17+ // Common selectors
18+ inputFieldSelector: (inputId) =>
19+ `#main-content #datastore-form-wrapper input#${inputId}`,
20+ buttonSelector: (type) => `#main-content .bx--btn-set button[type="${type}"]`,
21+ inputFieldLabelSelector: (forValue) =>
22+ `#main-content #datastore-form-wrapper label[for="${forValue}"]`,
23+
24+ // Element ids
25+ nameInputFieldId: 'name',
26+ descriptionInputFieldId: 'description',
27+ namespacePathInputFieldId: 'namespacePath',
28+
29+ // Button types
30+ submitButtonType: 'submit',
31+ normalButtonType: 'button',
32+
1733 // Field values
1834 domainName: 'Test_Domain',
1935 description: 'Test description',
2036 namespaceName: 'Test_Namespace',
2137 editedNamespaceName: 'Test_Namespace_Edited',
2238 editedDescription: 'Test description edited',
2339 invalidNamespaceName: 'Test Namespace',
40+ addNamespaceFormHeader: 'Adding a new Automate Namespace',
41+ editNamespaceFormHeader: 'Editing Automate Namespace',
42+ namespaceFormSubHeader: 'Info',
2443
2544 // List items
2645 dataStoreAccordionItem: 'Datastore',
@@ -39,7 +58,7 @@ const textConstants = {
3958 // Flash message text snippets
4059 flashMessageAddSuccess: 'added',
4160 flashMessageSaveSuccess: 'saved',
42- flashMessageCancelled: 'cancelled ',
61+ flashMessageCancelled: 'cancel ',
4362 flashMessageInvalidNamespace: 'contain only alphanumeric',
4463 flashMessageNamespaceRemoved: 'delete successful',
4564 flashMessageNameAlreadyExists: 'taken',
@@ -51,6 +70,10 @@ const {
5170 automationMenuOption,
5271 embeddedAutomationMenuOption,
5372 explorerMenuOption,
73+ inputFieldSelector,
74+ buttonSelector,
75+ normalButtonSelector,
76+ inputFieldLabelSelector,
5477 addButton,
5578 cancelButton,
5679 resetButton,
@@ -63,6 +86,9 @@ const {
6386 toolbarEditNamespace,
6487 toolbarRemoveNamespace,
6588 toolbarRemoveDomain,
89+ addNamespaceFormHeader,
90+ editNamespaceFormHeader,
91+ namespaceFormSubHeader,
6692 namespaceName,
6793 editedNamespaceName,
6894 editedDescription,
@@ -79,21 +105,24 @@ const {
79105 flashMessageResetNamespace,
80106 browserConfirmRemoveMessage,
81107 dataStoreAccordionItem,
108+ nameInputFieldId,
109+ descriptionInputFieldId,
110+ namespacePathInputFieldId,
111+ submitButtonType,
112+ normalButtonType,
82113} = textConstants;
83114
84115function addNamespace(nameFieldValue = namespaceName) {
85116 // Navigating to the Add Namespace form
86117 cy.toolbar(toolbarConfiguration, toolbarAddNewNamespace);
87118 // Creating a new namespace
88- cy.get('#datastore-form-wrapper input#name').type(nameFieldValue);
89- cy.get('#datastore-form-wrapper input#description').type(description);
90- cy.get('#main-content .bx--btn-set button[type="submit"]')
91- .contains(addButton)
92- .click();
119+ cy.get(inputFieldSelector(nameInputFieldId)).type(nameFieldValue);
120+ cy.get(inputFieldSelector(descriptionInputFieldId)).type(description);
121+ cy.contains(buttonSelector(submitButtonType), addButton).click();
93122 cy.wait('@addNamespaceApi');
94123}
95124
96- function interceptAccordionApi (textValue = namespaceName ) {
125+ function selectAccordionTree (textValue) {
97126 const aliasObject = {
98127 [domainName]: 'getCreatedDomainInfo',
99128 [namespaceName]: 'getCreatedNamespaceInfo',
@@ -107,6 +136,63 @@ function interceptAccordionApi(textValue = namespaceName) {
107136 cy.wait(`@${aliasObject[textValue]}`);
108137}
109138
139+ function validateNamespaceFormFields(isEditForm = false) {
140+ // Validate form header visibility
141+ cy.expect_explorer_title(
142+ isEditForm
143+ ? `${editNamespaceFormHeader} "${namespaceName}"`
144+ : addNamespaceFormHeader
145+ );
146+ // Validate sub header visibility
147+ cy.get('#main-content #datastore-form-wrapper h3').contains(
148+ namespaceFormSubHeader
149+ );
150+ // Validate name-space path field visibility
151+ cy.get(inputFieldLabelSelector(namespacePathInputFieldId)).should(
152+ 'be.visible'
153+ );
154+ cy.get(inputFieldSelector(namespacePathInputFieldId))
155+ .should('be.visible')
156+ .and('be.disabled')
157+ .and(
158+ 'have.value',
159+ isEditForm ? `/${domainName}/${namespaceName}` : `/${domainName}`
160+ );
161+ // Validate name field visibility
162+ cy.get(inputFieldLabelSelector(nameInputFieldId)).should('be.visible');
163+ cy.get(inputFieldSelector(nameInputFieldId))
164+ .should('be.visible')
165+ .and('be.enabled');
166+ // Validate description field visibility
167+ cy.get(inputFieldLabelSelector(descriptionInputFieldId)).should('be.visible');
168+ cy.get(inputFieldSelector(descriptionInputFieldId))
169+ .should('be.visible')
170+ .and('be.enabled');
171+ // Validate cancel button visibility
172+ cy.get(buttonSelector(normalButtonType))
173+ .contains(cancelButton)
174+ .should('be.visible');
175+ // Validate add/save button visibility
176+ cy.get(buttonSelector(submitButtonType))
177+ .contains(isEditForm ? saveButton : addButton)
178+ .should('be.visible');
179+ if (isEditForm) {
180+ // Validate reset button visibility
181+ cy.get(buttonSelector(normalButtonType))
182+ .contains(resetButton)
183+ .should('be.visible');
184+ }
185+ }
186+
187+ function createNamespaceAndOpenEditForm() {
188+ // Adding a new namespace
189+ addNamespace();
190+ // Selecting the created namespace from the accordion list items
191+ selectAccordionTree(namespaceName);
192+ // Opening the edit form
193+ cy.toolbar(toolbarConfiguration, toolbarEditNamespace);
194+ }
195+
110196describe('Automate operations on Namespaces: Automation -> Embedded Automate -> Explorer -> {Any-created-domain} -> Namespace form', () => {
111197 beforeEach(() => {
112198 cy.login();
@@ -117,25 +203,35 @@ describe('Automate operations on Namespaces: Automation -> Embedded Automate ->
117203 );
118204 // Creating a domain to test namespace operations
119205 cy.toolbar(toolbarConfiguration, toolbarAddNewDomain);
120- cy.get('#datastore-form-wrapper input#name' ).type(domainName);
121- cy.get('#datastore-form-wrapper input#description' ).type(description);
206+ cy.get(inputFieldSelector(nameInputFieldId) ).type(domainName);
207+ cy.get(inputFieldSelector(descriptionInputFieldId) ).type(description);
122208 cy.intercept('POST', '/miq_ae_class/create_namespace/new?button=add').as(
123209 'addNamespaceApi'
124210 );
125- cy.get('#main-content .bx--btn-set button[type="submit"]')
126- .contains(addButton)
127- .click();
211+ cy.contains(buttonSelector(submitButtonType), addButton).click();
128212 cy.wait('@addNamespaceApi');
129213 cy.expect_flash(flashTypeSuccess, flashMessageAddSuccess);
130214 // Selecting the created domain from the accordion list items
131- interceptAccordionApi(domainName);
215+ selectAccordionTree(domainName);
216+ });
217+
218+ it('Validate Add Namespace form fields', () => {
219+ // Navigating to the Add Namespace form
220+ cy.toolbar(toolbarConfiguration, toolbarAddNewNamespace);
221+
222+ // Validating the form fields
223+ validateNamespaceFormFields();
224+
225+ // Cancelling the form
226+ cy.contains(buttonSelector(normalButtonType), cancelButton).click();
132227 });
133228
134229 it('Validate Cancel button', () => {
230+ // Navigating to the Add Namespace form
135231 cy.toolbar(toolbarConfiguration, toolbarAddNewNamespace);
232+
136233 // Cancelling the form
137- cy.get('#main-content .bx--btn-set button[type="button"]')
138- .contains(cancelButton)
234+ cy.contains(buttonSelector(normalButtonType), cancelButton)
139235 .should('be.enabled')
140236 .click();
141237 cy.expect_flash(flashTypeWarning, flashMessageCancelled);
@@ -145,10 +241,20 @@ describe('Automate operations on Namespaces: Automation -> Embedded Automate ->
145241 // Trying to add a namespace with invalid characters
146242 addNamespace(invalidNamespaceName);
147243 cy.expect_flash(flashTypeError, flashMessageInvalidNamespace);
244+
148245 // Cancelling the form
149- cy.get('#main-content .bx--btn-set button[type="button"]')
150- .contains(cancelButton)
151- .click();
246+ cy.contains(buttonSelector(normalButtonType), cancelButton).click();
247+ });
248+
249+ it('Validate Edit Namespace form fields', () => {
250+ // Create a namespace and open the edit form
251+ createNamespaceAndOpenEditForm();
252+
253+ // Validating the form fields
254+ validateNamespaceFormFields(true);
255+
256+ // Cancelling the form
257+ cy.contains(buttonSelector(normalButtonType), cancelButton).click();
152258 });
153259
154260 it('Checking whether add, edit & delete namespace works', () => {
@@ -157,18 +263,17 @@ describe('Automate operations on Namespaces: Automation -> Embedded Automate ->
157263 cy.expect_flash(flashTypeSuccess, flashMessageAddSuccess);
158264
159265 // Selecting the created namespace from the accordion list items
160- interceptAccordionApi( );
266+ selectAccordionTree(namespaceName );
161267 // Editing the namespace
162268 cy.toolbar(toolbarConfiguration, toolbarEditNamespace);
163269 // Checking if the Save button is disabled initially
164- cy.get('#main-content .bx--btn-set button[type="submit"]')
165- .contains(saveButton)
166- .should('be.disabled' );
167- cy.get('#datastore-form-wrapper input#description' )
270+ cy.contains(buttonSelector(submitButtonType), saveButton).should(
271+ 'be.disabled'
272+ );
273+ cy.get(inputFieldSelector(descriptionInputFieldId) )
168274 .clear()
169275 .type(editedDescription);
170- cy.get('#main-content .bx--btn-set button[type="submit"]')
171- .contains(saveButton)
276+ cy.contains(buttonSelector(submitButtonType), saveButton)
172277 .should('be.enabled')
173278 .click();
174279 cy.expect_flash(flashTypeSuccess, flashMessageSaveSuccess);
@@ -190,57 +295,48 @@ describe('Automate operations on Namespaces: Automation -> Embedded Automate ->
190295 cy.expect_flash(flashTypeError, flashMessageNameAlreadyExists);
191296
192297 // Cancelling the form
193- cy.get('#main-content .bx--btn-set button[type="button"]')
194- .contains(cancelButton)
195- .click();
298+ cy.contains(buttonSelector(normalButtonType), cancelButton).click();
196299 });
197300
198301 it('Checking whether Cancel & Reset buttons work fine in the Edit form', () => {
199- // Adding a new namespace
200- addNamespace();
201- // Selecting the created namespace from the accordion list items
202- interceptAccordionApi();
203- // Opening the edit form
204- cy.toolbar(toolbarConfiguration, toolbarEditNamespace);
302+ // Create a namespace and open the edit form
303+ createNamespaceAndOpenEditForm();
205304
206305 /* Validating Reset button */
207306 // Checking if the Reset button is disabled initially
208- cy.get('#main-content .bx--btn-set button[type="button"]')
209- .contains(resetButton)
210- .should('be.disabled' );
307+ cy.contains(buttonSelector(normalButtonType), resetButton).should(
308+ 'be.disabled'
309+ );
211310 // Editing name and description fields
212- cy.get('#datastore-form-wrapper input#name' )
311+ cy.get(inputFieldSelector(nameInputFieldId) )
213312 .clear()
214313 .type(editedNamespaceName);
215- cy.get('#datastore-form-wrapper input#description' )
314+ cy.get(inputFieldSelector(descriptionInputFieldId) )
216315 .clear()
217316 .type(editedDescription);
218317 // Resetting
219- cy.get('#main-content .bx--btn-set button[type="button"]')
220- .contains(resetButton)
318+ cy.contains(buttonSelector(normalButtonType), resetButton)
221319 .should('be.enabled')
222320 .click();
223321 cy.expect_flash(flashTypeWarning, flashMessageResetNamespace);
224322 // Confirming the edited fields contain the old values after resetting
225- cy.get('#datastore-form-wrapper input#name' ).should(
323+ cy.get(inputFieldSelector(nameInputFieldId) ).should(
226324 'have.value',
227325 namespaceName
228326 );
229- cy.get('#datastore-form-wrapper input#description' ).should(
327+ cy.get(inputFieldSelector(descriptionInputFieldId) ).should(
230328 'have.value',
231329 description
232330 );
233331
234332 /* Validating Cancel button */
235- cy.get('#main-content .bx--btn-set button[type="button"]')
236- .contains(cancelButton)
237- .click();
333+ cy.contains(buttonSelector(normalButtonType), cancelButton).click();
238334 cy.expect_flash(flashTypeWarning, flashMessageCancelled);
239335 });
240336
241337 afterEach(() => {
242338 // Selecting the created domain(Test_Domain) from the accordion list items
243- interceptAccordionApi (dataStoreAccordionItem);
339+ selectAccordionTree (dataStoreAccordionItem);
244340 cy.accordionItem(domainName);
245341 cy.wait('@getCreatedDomainInfo');
246342 // Removing the domain
0 commit comments