Skip to content

Commit 66aae77

Browse files
Added automated tests with cypress for Namespace form
1 parent ef8fb4c commit 66aae77

File tree

1 file changed

+348
-0
lines changed

1 file changed

+348
-0
lines changed
Lines changed: 348 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,348 @@
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+
inputFieldLabelSelector,
76+
addButton,
77+
cancelButton,
78+
resetButton,
79+
saveButton,
80+
domainName,
81+
description,
82+
toolbarConfiguration,
83+
toolbarAddNewDomain,
84+
toolbarAddNewNamespace,
85+
toolbarEditNamespace,
86+
toolbarRemoveNamespace,
87+
toolbarRemoveDomain,
88+
addNamespaceFormHeader,
89+
editNamespaceFormHeader,
90+
namespaceFormSubHeader,
91+
namespaceName,
92+
editedNamespaceName,
93+
editedDescription,
94+
invalidNamespaceName,
95+
flashTypeError,
96+
flashTypeSuccess,
97+
flashTypeWarning,
98+
flashMessageAddSuccess,
99+
flashMessageSaveSuccess,
100+
flashMessageCancelled,
101+
flashMessageNamespaceRemoved,
102+
flashMessageInvalidNamespace,
103+
flashMessageNameAlreadyExists,
104+
flashMessageResetNamespace,
105+
browserConfirmRemoveMessage,
106+
dataStoreAccordionItem,
107+
nameInputFieldId,
108+
descriptionInputFieldId,
109+
namespacePathInputFieldId,
110+
submitButtonType,
111+
normalButtonType,
112+
} = textConstants;
113+
114+
function addNamespace(nameFieldValue = namespaceName) {
115+
// Navigating to the Add Namespace form
116+
cy.toolbar(toolbarConfiguration, toolbarAddNewNamespace);
117+
// Creating a new namespace
118+
cy.get(inputFieldSelector(nameInputFieldId)).type(nameFieldValue);
119+
cy.get(inputFieldSelector(descriptionInputFieldId)).type(description);
120+
cy.contains(buttonSelector(submitButtonType), addButton).click();
121+
cy.wait('@addNamespaceApi');
122+
}
123+
124+
function selectAccordionTree(textValue) {
125+
const aliasObject = {
126+
[domainName]: 'getCreatedDomainInfo',
127+
[namespaceName]: 'getCreatedNamespaceInfo',
128+
[dataStoreAccordionItem]: 'getDataStoreAccordionItemInfo',
129+
};
130+
cy.intercept(
131+
'POST',
132+
new RegExp(`/miq_ae_class/tree_select\\?id=.*&text=${textValue}`)
133+
).as(aliasObject[textValue]);
134+
cy.accordionItem(textValue);
135+
cy.wait(`@${aliasObject[textValue]}`);
136+
}
137+
138+
function validateNamespaceFormFields(isEditForm = false) {
139+
// Validate form header visibility
140+
cy.expect_explorer_title(
141+
isEditForm
142+
? `${editNamespaceFormHeader} "${namespaceName}"`
143+
: addNamespaceFormHeader
144+
);
145+
// Validate sub header visibility
146+
cy.get('#main-content #datastore-form-wrapper h3').contains(
147+
namespaceFormSubHeader
148+
);
149+
// Validate name-space path field visibility
150+
cy.get(inputFieldLabelSelector(namespacePathInputFieldId)).should(
151+
'be.visible'
152+
);
153+
cy.get(inputFieldSelector(namespacePathInputFieldId))
154+
.should('be.visible')
155+
.and('be.disabled')
156+
.and(
157+
'have.value',
158+
isEditForm ? `/${domainName}/${namespaceName}` : `/${domainName}`
159+
);
160+
// Validate name field visibility
161+
cy.get(inputFieldLabelSelector(nameInputFieldId)).should('be.visible');
162+
cy.get(inputFieldSelector(nameInputFieldId))
163+
.should('be.visible')
164+
.and('be.enabled');
165+
// Validate description field visibility
166+
cy.get(inputFieldLabelSelector(descriptionInputFieldId)).should('be.visible');
167+
cy.get(inputFieldSelector(descriptionInputFieldId))
168+
.should('be.visible')
169+
.and('be.enabled');
170+
// Validate cancel button visibility
171+
cy.get(buttonSelector(normalButtonType))
172+
.contains(cancelButton)
173+
.should('be.visible');
174+
// Validate add/save button visibility
175+
cy.get(buttonSelector(submitButtonType))
176+
.contains(isEditForm ? saveButton : addButton)
177+
.should('be.visible');
178+
if (isEditForm) {
179+
// Validate reset button visibility
180+
cy.get(buttonSelector(normalButtonType))
181+
.contains(resetButton)
182+
.should('be.visible');
183+
}
184+
}
185+
186+
function createNamespaceAndOpenEditForm() {
187+
// Adding a new namespace
188+
addNamespace();
189+
// Selecting the created namespace from the accordion list items
190+
selectAccordionTree(namespaceName);
191+
// Opening the edit form
192+
cy.toolbar(toolbarConfiguration, toolbarEditNamespace);
193+
}
194+
195+
describe('Automate operations on Namespaces: Automation -> Embedded Automate -> Explorer -> {Any-created-domain} -> Namespace form', () => {
196+
beforeEach(() => {
197+
cy.login();
198+
cy.menu(
199+
automationMenuOption,
200+
embeddedAutomationMenuOption,
201+
explorerMenuOption
202+
);
203+
// Creating a domain to test namespace operations
204+
cy.toolbar(toolbarConfiguration, toolbarAddNewDomain);
205+
cy.get(inputFieldSelector(nameInputFieldId)).type(domainName);
206+
cy.get(inputFieldSelector(descriptionInputFieldId)).type(description);
207+
cy.intercept('POST', '/miq_ae_class/create_namespace/new?button=add').as(
208+
'addNamespaceApi'
209+
);
210+
cy.contains(buttonSelector(submitButtonType), addButton).click();
211+
cy.wait('@addNamespaceApi');
212+
cy.expect_flash(flashTypeSuccess, flashMessageAddSuccess);
213+
// Selecting the created domain from the accordion list items
214+
selectAccordionTree(domainName);
215+
});
216+
217+
it('Validate Add Namespace form fields', () => {
218+
// Navigating to the Add Namespace form
219+
cy.toolbar(toolbarConfiguration, toolbarAddNewNamespace);
220+
221+
// Validating the form fields
222+
validateNamespaceFormFields();
223+
224+
// Cancelling the form
225+
cy.contains(buttonSelector(normalButtonType), cancelButton).click();
226+
});
227+
228+
it('Validate Cancel button', () => {
229+
// Navigating to the Add Namespace form
230+
cy.toolbar(toolbarConfiguration, toolbarAddNewNamespace);
231+
232+
// Cancelling the form
233+
cy.contains(buttonSelector(normalButtonType), cancelButton)
234+
.should('be.enabled')
235+
.click();
236+
cy.expect_flash(flashTypeWarning, flashMessageCancelled);
237+
});
238+
239+
it('Validate Name field allows only alphanumeric and _ . - $ characters', () => {
240+
// Trying to add a namespace with invalid characters
241+
addNamespace(invalidNamespaceName);
242+
cy.expect_flash(flashTypeError, flashMessageInvalidNamespace);
243+
244+
// Cancelling the form
245+
cy.contains(buttonSelector(normalButtonType), cancelButton).click();
246+
});
247+
248+
it('Validate Edit Namespace form fields', () => {
249+
// Create a namespace and open the edit form
250+
createNamespaceAndOpenEditForm();
251+
252+
// Validating the form fields
253+
validateNamespaceFormFields(true);
254+
255+
// Cancelling the form
256+
cy.contains(buttonSelector(normalButtonType), cancelButton).click();
257+
});
258+
259+
it('Checking whether add, edit & delete namespace works', () => {
260+
// Adding a new namespace
261+
addNamespace();
262+
cy.expect_flash(flashTypeSuccess, flashMessageAddSuccess);
263+
264+
// Selecting the created namespace from the accordion list items
265+
selectAccordionTree(namespaceName);
266+
// Editing the namespace
267+
cy.toolbar(toolbarConfiguration, toolbarEditNamespace);
268+
// Checking if the Save button is disabled initially
269+
cy.contains(buttonSelector(submitButtonType), saveButton).should(
270+
'be.disabled'
271+
);
272+
cy.get(inputFieldSelector(descriptionInputFieldId))
273+
.clear()
274+
.type(editedDescription);
275+
cy.contains(buttonSelector(submitButtonType), saveButton)
276+
.should('be.enabled')
277+
.click();
278+
cy.expect_flash(flashTypeSuccess, flashMessageSaveSuccess);
279+
280+
// Deleting the namespace
281+
cy.expect_browser_confirm_with_text({
282+
confirmTriggerFn: () =>
283+
cy.toolbar(toolbarConfiguration, toolbarRemoveNamespace),
284+
containsText: browserConfirmRemoveMessage,
285+
});
286+
cy.expect_flash(flashTypeSuccess, flashMessageNamespaceRemoved);
287+
});
288+
289+
it('Checking whether creating a duplicate namespace is restricted', () => {
290+
// Adding a new namespace
291+
addNamespace();
292+
// Trying to add duplicate namespace
293+
addNamespace();
294+
cy.expect_flash(flashTypeError, flashMessageNameAlreadyExists);
295+
296+
// Cancelling the form
297+
cy.contains(buttonSelector(normalButtonType), cancelButton).click();
298+
});
299+
300+
it('Checking whether Cancel & Reset buttons work fine in the Edit form', () => {
301+
// Create a namespace and open the edit form
302+
createNamespaceAndOpenEditForm();
303+
304+
/* Validating Reset button */
305+
// Checking if the Reset button is disabled initially
306+
cy.contains(buttonSelector(normalButtonType), resetButton).should(
307+
'be.disabled'
308+
);
309+
// Editing name and description fields
310+
cy.get(inputFieldSelector(nameInputFieldId))
311+
.clear()
312+
.type(editedNamespaceName);
313+
cy.get(inputFieldSelector(descriptionInputFieldId))
314+
.clear()
315+
.type(editedDescription);
316+
// Resetting
317+
cy.contains(buttonSelector(normalButtonType), resetButton)
318+
.should('be.enabled')
319+
.click();
320+
cy.expect_flash(flashTypeWarning, flashMessageResetNamespace);
321+
// Confirming the edited fields contain the old values after resetting
322+
cy.get(inputFieldSelector(nameInputFieldId)).should(
323+
'have.value',
324+
namespaceName
325+
);
326+
cy.get(inputFieldSelector(descriptionInputFieldId)).should(
327+
'have.value',
328+
description
329+
);
330+
331+
/* Validating Cancel button */
332+
cy.contains(buttonSelector(normalButtonType), cancelButton).click();
333+
cy.expect_flash(flashTypeWarning, flashMessageCancelled);
334+
});
335+
336+
afterEach(() => {
337+
// Selecting the created domain(Test_Domain) from the accordion list items
338+
selectAccordionTree(dataStoreAccordionItem);
339+
cy.accordionItem(domainName);
340+
cy.wait('@getCreatedDomainInfo');
341+
// Removing the domain
342+
cy.expect_browser_confirm_with_text({
343+
confirmTriggerFn: () =>
344+
cy.toolbar(toolbarConfiguration, toolbarRemoveDomain),
345+
containsText: browserConfirmRemoveMessage,
346+
});
347+
});
348+
});

0 commit comments

Comments
 (0)