Skip to content

Commit d99dc5b

Browse files
Added automated tests with cypress for Namespace form
1 parent 7f79b24 commit d99dc5b

File tree

1 file changed

+349
-0
lines changed

1 file changed

+349
-0
lines changed
Lines changed: 349 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,349 @@
1+
/* eslint-disable no-undef */
2+
3+
const textConstants = {
4+
// Menu options
5+
automationMenuOption: 'Automation',
6+
embeddedAutomationMenuOption: 'Embedded Automate',
7+
explorerMenuOption: 'Explorer',
8+
9+
// Toolbar options
10+
toolbarConfiguration: 'Configuration',
11+
toolbarAddNewDomain: 'Add a New Domain',
12+
toolbarRemoveDomain: 'Remove this Domain',
13+
toolbarAddNewNamespace: 'Add a New Namespace',
14+
toolbarEditNamespace: 'Edit this Namespace',
15+
toolbarRemoveNamespace: 'Remove this Namespace',
16+
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+
33+
// Field values
34+
domainName: 'Test_Domain',
35+
description: 'Test description',
36+
namespaceName: 'Test_Namespace',
37+
editedNamespaceName: 'Test_Namespace_Edited',
38+
editedDescription: 'Test description edited',
39+
invalidNamespaceName: 'Test Namespace',
40+
addNamespaceFormHeader: 'Adding a new Automate Namespace',
41+
editNamespaceFormHeader: 'Editing Automate Namespace',
42+
namespaceFormSubHeader: 'Info',
43+
44+
// List items
45+
dataStoreAccordionItem: 'Datastore',
46+
47+
// Buttons
48+
addButton: 'Add',
49+
cancelButton: 'Cancel',
50+
saveButton: 'Save',
51+
resetButton: 'Reset',
52+
53+
// Flash message types
54+
flashTypeSuccess: 'success',
55+
flashTypeWarning: 'warning',
56+
flashTypeError: 'error',
57+
58+
// Flash message text snippets
59+
flashMessageAddSuccess: 'added',
60+
flashMessageSaveSuccess: 'saved',
61+
flashMessageCancelled: 'cancel',
62+
flashMessageInvalidNamespace: 'contain only alphanumeric',
63+
flashMessageNamespaceRemoved: 'delete successful',
64+
flashMessageNameAlreadyExists: 'taken',
65+
flashMessageResetNamespace: 'reset',
66+
browserConfirmRemoveMessage: 'remove',
67+
};
68+
69+
const {
70+
automationMenuOption,
71+
embeddedAutomationMenuOption,
72+
explorerMenuOption,
73+
inputFieldSelector,
74+
buttonSelector,
75+
normalButtonSelector,
76+
inputFieldLabelSelector,
77+
addButton,
78+
cancelButton,
79+
resetButton,
80+
saveButton,
81+
domainName,
82+
description,
83+
toolbarConfiguration,
84+
toolbarAddNewDomain,
85+
toolbarAddNewNamespace,
86+
toolbarEditNamespace,
87+
toolbarRemoveNamespace,
88+
toolbarRemoveDomain,
89+
addNamespaceFormHeader,
90+
editNamespaceFormHeader,
91+
namespaceFormSubHeader,
92+
namespaceName,
93+
editedNamespaceName,
94+
editedDescription,
95+
invalidNamespaceName,
96+
flashTypeError,
97+
flashTypeSuccess,
98+
flashTypeWarning,
99+
flashMessageAddSuccess,
100+
flashMessageSaveSuccess,
101+
flashMessageCancelled,
102+
flashMessageNamespaceRemoved,
103+
flashMessageInvalidNamespace,
104+
flashMessageNameAlreadyExists,
105+
flashMessageResetNamespace,
106+
browserConfirmRemoveMessage,
107+
dataStoreAccordionItem,
108+
nameInputFieldId,
109+
descriptionInputFieldId,
110+
namespacePathInputFieldId,
111+
submitButtonType,
112+
normalButtonType,
113+
} = textConstants;
114+
115+
function addNamespace(nameFieldValue = namespaceName) {
116+
// Navigating to the Add Namespace form
117+
cy.toolbar(toolbarConfiguration, toolbarAddNewNamespace);
118+
// Creating a new namespace
119+
cy.get(inputFieldSelector(nameInputFieldId)).type(nameFieldValue);
120+
cy.get(inputFieldSelector(descriptionInputFieldId)).type(description);
121+
cy.contains(buttonSelector(submitButtonType), addButton).click();
122+
cy.wait('@addNamespaceApi');
123+
}
124+
125+
function selectAccordionTree(textValue) {
126+
const aliasObject = {
127+
[domainName]: 'getCreatedDomainInfo',
128+
[namespaceName]: 'getCreatedNamespaceInfo',
129+
[dataStoreAccordionItem]: 'getDataStoreAccordionItemInfo',
130+
};
131+
cy.intercept(
132+
'POST',
133+
new RegExp(`/miq_ae_class/tree_select\\?id=.*&text=${textValue}`)
134+
).as(aliasObject[textValue]);
135+
cy.accordionItem(textValue);
136+
cy.wait(`@${aliasObject[textValue]}`);
137+
}
138+
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+
196+
describe('Automate operations on Namespaces: Automation -> Embedded Automate -> Explorer -> {Any-created-domain} -> Namespace form', () => {
197+
beforeEach(() => {
198+
cy.login();
199+
cy.menu(
200+
automationMenuOption,
201+
embeddedAutomationMenuOption,
202+
explorerMenuOption
203+
);
204+
// Creating a domain to test namespace operations
205+
cy.toolbar(toolbarConfiguration, toolbarAddNewDomain);
206+
cy.get(inputFieldSelector(nameInputFieldId)).type(domainName);
207+
cy.get(inputFieldSelector(descriptionInputFieldId)).type(description);
208+
cy.intercept('POST', '/miq_ae_class/create_namespace/new?button=add').as(
209+
'addNamespaceApi'
210+
);
211+
cy.contains(buttonSelector(submitButtonType), addButton).click();
212+
cy.wait('@addNamespaceApi');
213+
cy.expect_flash(flashTypeSuccess, flashMessageAddSuccess);
214+
// Selecting the created domain from the accordion list items
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();
227+
});
228+
229+
it('Validate Cancel button', () => {
230+
// Navigating to the Add Namespace form
231+
cy.toolbar(toolbarConfiguration, toolbarAddNewNamespace);
232+
233+
// Cancelling the form
234+
cy.contains(buttonSelector(normalButtonType), cancelButton)
235+
.should('be.enabled')
236+
.click();
237+
cy.expect_flash(flashTypeWarning, flashMessageCancelled);
238+
});
239+
240+
it('Validate Name field allows only alphanumeric and _ . - $ characters', () => {
241+
// Trying to add a namespace with invalid characters
242+
addNamespace(invalidNamespaceName);
243+
cy.expect_flash(flashTypeError, flashMessageInvalidNamespace);
244+
245+
// Cancelling the form
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();
258+
});
259+
260+
it('Checking whether add, edit & delete namespace works', () => {
261+
// Adding a new namespace
262+
addNamespace();
263+
cy.expect_flash(flashTypeSuccess, flashMessageAddSuccess);
264+
265+
// Selecting the created namespace from the accordion list items
266+
selectAccordionTree(namespaceName);
267+
// Editing the namespace
268+
cy.toolbar(toolbarConfiguration, toolbarEditNamespace);
269+
// Checking if the Save button is disabled initially
270+
cy.contains(buttonSelector(submitButtonType), saveButton).should(
271+
'be.disabled'
272+
);
273+
cy.get(inputFieldSelector(descriptionInputFieldId))
274+
.clear()
275+
.type(editedDescription);
276+
cy.contains(buttonSelector(submitButtonType), saveButton)
277+
.should('be.enabled')
278+
.click();
279+
cy.expect_flash(flashTypeSuccess, flashMessageSaveSuccess);
280+
281+
// Deleting the namespace
282+
cy.expect_browser_confirm_with_text({
283+
confirmTriggerFn: () =>
284+
cy.toolbar(toolbarConfiguration, toolbarRemoveNamespace),
285+
containsText: browserConfirmRemoveMessage,
286+
});
287+
cy.expect_flash(flashTypeSuccess, flashMessageNamespaceRemoved);
288+
});
289+
290+
it('Checking whether creating a duplicate namespace is restricted', () => {
291+
// Adding a new namespace
292+
addNamespace();
293+
// Trying to add duplicate namespace
294+
addNamespace();
295+
cy.expect_flash(flashTypeError, flashMessageNameAlreadyExists);
296+
297+
// Cancelling the form
298+
cy.contains(buttonSelector(normalButtonType), cancelButton).click();
299+
});
300+
301+
it('Checking whether Cancel & Reset buttons work fine in the Edit form', () => {
302+
// Create a namespace and open the edit form
303+
createNamespaceAndOpenEditForm();
304+
305+
/* Validating Reset button */
306+
// Checking if the Reset button is disabled initially
307+
cy.contains(buttonSelector(normalButtonType), resetButton).should(
308+
'be.disabled'
309+
);
310+
// Editing name and description fields
311+
cy.get(inputFieldSelector(nameInputFieldId))
312+
.clear()
313+
.type(editedNamespaceName);
314+
cy.get(inputFieldSelector(descriptionInputFieldId))
315+
.clear()
316+
.type(editedDescription);
317+
// Resetting
318+
cy.contains(buttonSelector(normalButtonType), resetButton)
319+
.should('be.enabled')
320+
.click();
321+
cy.expect_flash(flashTypeWarning, flashMessageResetNamespace);
322+
// Confirming the edited fields contain the old values after resetting
323+
cy.get(inputFieldSelector(nameInputFieldId)).should(
324+
'have.value',
325+
namespaceName
326+
);
327+
cy.get(inputFieldSelector(descriptionInputFieldId)).should(
328+
'have.value',
329+
description
330+
);
331+
332+
/* Validating Cancel button */
333+
cy.contains(buttonSelector(normalButtonType), cancelButton).click();
334+
cy.expect_flash(flashTypeWarning, flashMessageCancelled);
335+
});
336+
337+
afterEach(() => {
338+
// Selecting the created domain(Test_Domain) from the accordion list items
339+
selectAccordionTree(dataStoreAccordionItem);
340+
cy.accordionItem(domainName);
341+
cy.wait('@getCreatedDomainInfo');
342+
// Removing the domain
343+
cy.expect_browser_confirm_with_text({
344+
confirmTriggerFn: () =>
345+
cy.toolbar(toolbarConfiguration, toolbarRemoveDomain),
346+
containsText: browserConfirmRemoveMessage,
347+
});
348+
});
349+
});

0 commit comments

Comments
 (0)