Skip to content

Commit 1338c30

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

File tree

1 file changed

+253
-0
lines changed

1 file changed

+253
-0
lines changed
Lines changed: 253 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,253 @@
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+
// Field values
18+
domainName: 'Test_Domain',
19+
description: 'Test description',
20+
namespaceName: 'Test_Namespace',
21+
editedNamespaceName: 'Test_Namespace_Edited',
22+
editedDescription: 'Test description edited',
23+
invalidNamespaceName: 'Test Namespace',
24+
25+
// List items
26+
dataStoreAccordionItem: 'Datastore',
27+
28+
// Buttons
29+
addButton: 'Add',
30+
cancelButton: 'Cancel',
31+
saveButton: 'Save',
32+
resetButton: 'Reset',
33+
34+
// Flash message types
35+
flashTypeSuccess: 'success',
36+
flashTypeWarning: 'warning',
37+
flashTypeError: 'error',
38+
39+
// Flash message text snippets
40+
flashMessageAddSuccess: 'added',
41+
flashMessageSaveSuccess: 'saved',
42+
flashMessageCancelled: 'cancelled',
43+
flashMessageInvalidNamespace: 'contain only alphanumeric',
44+
flashMessageNamespaceRemoved: 'delete successful',
45+
flashMessageNameAlreadyExists: 'taken',
46+
flashMessageResetNamespace: 'reset',
47+
browserConfirmRemoveMessage: 'remove',
48+
};
49+
50+
const {
51+
automationMenuOption,
52+
embeddedAutomationMenuOption,
53+
explorerMenuOption,
54+
addButton,
55+
cancelButton,
56+
resetButton,
57+
saveButton,
58+
domainName,
59+
description,
60+
toolbarConfiguration,
61+
toolbarAddNewDomain,
62+
toolbarAddNewNamespace,
63+
toolbarEditNamespace,
64+
toolbarRemoveNamespace,
65+
toolbarRemoveDomain,
66+
namespaceName,
67+
editedNamespaceName,
68+
editedDescription,
69+
invalidNamespaceName,
70+
flashTypeError,
71+
flashTypeSuccess,
72+
flashTypeWarning,
73+
flashMessageAddSuccess,
74+
flashMessageSaveSuccess,
75+
flashMessageCancelled,
76+
flashMessageNamespaceRemoved,
77+
flashMessageInvalidNamespace,
78+
flashMessageNameAlreadyExists,
79+
flashMessageResetNamespace,
80+
browserConfirmRemoveMessage,
81+
dataStoreAccordionItem,
82+
} = textConstants;
83+
84+
function addNamespace(nameFieldValue = namespaceName) {
85+
// Navigating to the Add Namespace form
86+
cy.toolbar(toolbarConfiguration, toolbarAddNewNamespace);
87+
// 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();
93+
cy.wait('@addNamespaceApi');
94+
}
95+
96+
function interceptAccordionApi(textValue = namespaceName) {
97+
const aliasObject = {
98+
[domainName]: 'getCreatedDomainInfo',
99+
[namespaceName]: 'getCreatedNamespaceInfo',
100+
[dataStoreAccordionItem]: 'getDataStoreAccordionItemInfo',
101+
};
102+
cy.intercept(
103+
'POST',
104+
new RegExp(`/miq_ae_class/tree_select\\?id=.*&text=${textValue}`)
105+
).as(aliasObject[textValue]);
106+
cy.accordionItem(textValue);
107+
cy.wait(`@${aliasObject[textValue]}`);
108+
}
109+
110+
describe('Automate operations on Namespaces: Automation -> Embedded Automate -> Explorer -> {Any-created-domain} -> Namespace form', () => {
111+
beforeEach(() => {
112+
cy.login();
113+
cy.menu(
114+
automationMenuOption,
115+
embeddedAutomationMenuOption,
116+
explorerMenuOption
117+
);
118+
// Creating a domain to test namespace operations
119+
cy.toolbar(toolbarConfiguration, toolbarAddNewDomain);
120+
cy.get('#datastore-form-wrapper input#name').type(domainName);
121+
cy.get('#datastore-form-wrapper input#description').type(description);
122+
cy.intercept('POST', '/miq_ae_class/create_namespace/new?button=add').as(
123+
'addNamespaceApi'
124+
);
125+
cy.get('#main-content .bx--btn-set button[type="submit"]')
126+
.contains(addButton)
127+
.click();
128+
cy.wait('@addNamespaceApi');
129+
cy.expect_flash(flashTypeSuccess, flashMessageAddSuccess);
130+
// Selecting the created domain from the accordion list items
131+
interceptAccordionApi(domainName);
132+
});
133+
134+
it('Validate Cancel button', () => {
135+
cy.toolbar(toolbarConfiguration, toolbarAddNewNamespace);
136+
// Cancelling the form
137+
cy.get('#main-content .bx--btn-set button[type="button"]')
138+
.contains(cancelButton)
139+
.should('be.enabled')
140+
.click();
141+
cy.expect_flash(flashTypeWarning, flashMessageCancelled);
142+
});
143+
144+
it('Validate Name field allows only alphanumeric and _ . - $ characters', () => {
145+
// Trying to add a namespace with invalid characters
146+
addNamespace(invalidNamespaceName);
147+
cy.expect_flash(flashTypeError, flashMessageInvalidNamespace);
148+
// Cancelling the form
149+
cy.get('#main-content .bx--btn-set button[type="button"]')
150+
.contains(cancelButton)
151+
.click();
152+
});
153+
154+
it('Checking whether add, edit & delete namespace works', () => {
155+
// Adding a new namespace
156+
addNamespace();
157+
cy.expect_flash(flashTypeSuccess, flashMessageAddSuccess);
158+
159+
// Selecting the created namespace from the accordion list items
160+
interceptAccordionApi();
161+
// Editing the namespace
162+
cy.toolbar(toolbarConfiguration, toolbarEditNamespace);
163+
// 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')
168+
.clear()
169+
.type(editedDescription);
170+
cy.get('#main-content .bx--btn-set button[type="submit"]')
171+
.contains(saveButton)
172+
.should('be.enabled')
173+
.click();
174+
cy.expect_flash(flashTypeSuccess, flashMessageSaveSuccess);
175+
176+
// Deleting the namespace
177+
cy.expect_browser_confirm_with_text({
178+
confirmTriggerFn: () =>
179+
cy.toolbar(toolbarConfiguration, toolbarRemoveNamespace),
180+
containsText: browserConfirmRemoveMessage,
181+
});
182+
cy.expect_flash(flashTypeSuccess, flashMessageNamespaceRemoved);
183+
});
184+
185+
it('Checking whether creating a duplicate namespace is restricted', () => {
186+
// Adding a new namespace
187+
addNamespace();
188+
// Trying to add duplicate namespace
189+
addNamespace();
190+
cy.expect_flash(flashTypeError, flashMessageNameAlreadyExists);
191+
192+
// Cancelling the form
193+
cy.get('#main-content .bx--btn-set button[type="button"]')
194+
.contains(cancelButton)
195+
.click();
196+
});
197+
198+
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);
205+
206+
/* Validating Reset button */
207+
// 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');
211+
// Editing name and description fields
212+
cy.get('#datastore-form-wrapper input#name')
213+
.clear()
214+
.type(editedNamespaceName);
215+
cy.get('#datastore-form-wrapper input#description')
216+
.clear()
217+
.type(editedDescription);
218+
// Resetting
219+
cy.get('#main-content .bx--btn-set button[type="button"]')
220+
.contains(resetButton)
221+
.should('be.enabled')
222+
.click();
223+
cy.expect_flash(flashTypeWarning, flashMessageResetNamespace);
224+
// Confirming the edited fields contain the old values after resetting
225+
cy.get('#datastore-form-wrapper input#name').should(
226+
'have.value',
227+
namespaceName
228+
);
229+
cy.get('#datastore-form-wrapper input#description').should(
230+
'have.value',
231+
description
232+
);
233+
234+
/* Validating Cancel button */
235+
cy.get('#main-content .bx--btn-set button[type="button"]')
236+
.contains(cancelButton)
237+
.click();
238+
cy.expect_flash(flashTypeWarning, flashMessageCancelled);
239+
});
240+
241+
afterEach(() => {
242+
// Selecting the created domain(Test_Domain) from the accordion list items
243+
interceptAccordionApi(dataStoreAccordionItem);
244+
cy.accordionItem(domainName);
245+
cy.wait('@getCreatedDomainInfo');
246+
// Removing the domain
247+
cy.expect_browser_confirm_with_text({
248+
confirmTriggerFn: () =>
249+
cy.toolbar(toolbarConfiguration, toolbarRemoveDomain),
250+
containsText: browserConfirmRemoveMessage,
251+
});
252+
});
253+
});

0 commit comments

Comments
 (0)