Skip to content

Commit 244aea3

Browse files
authored
Merge pull request #9517 from asirvadAbrahamVarghese/namespace-form-automation-testing
Added automated tests with cypress for Namespace form
2 parents 0ca6581 + fb0557e commit 244aea3

File tree

1 file changed

+278
-0
lines changed

1 file changed

+278
-0
lines changed
Lines changed: 278 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,278 @@
1+
/* eslint-disable no-undef */
2+
import { flashClassMap } from '../../../../../support/assertions/assertion_constants';
3+
4+
// Component route url
5+
const COMPONENT_ROUTE_URL = 'miq_ae_class/explorer#/';
6+
7+
// Menu options
8+
const AUTOMATION_MENU_OPTION = 'Automation';
9+
const EMBEDDED_AUTOMATION_MENU_OPTION = 'Embedded Automate';
10+
const EXPLORER_MENU_OPTION = 'Explorer';
11+
12+
// Toolbar options
13+
const TOOLBAR_CONFIGURATION = 'Configuration';
14+
const TOOLBAR_ADD_NEW_DOMAIN = 'Add a New Domain';
15+
const TOOLBAR_REMOVE_DOMAIN = 'Remove this Domain';
16+
const TOOLBAR_ADD_NEW_NAMESPACE = 'Add a New Namespace';
17+
const TOOLBAR_EDIT_NAMESPACE = 'Edit this Namespace';
18+
const TOOLBAR_REMOVE_NAMESPACE = 'Remove this Namespace';
19+
20+
// Field values
21+
const NAME_SAPCE_PATH_FIELD_LABEL = 'Fully Qualified Name';
22+
const NAME_FIELD_LABEL = 'Name';
23+
const DESCRIPTION_FIELD_LABEL = 'Description';
24+
const DOMAIN_NAME = 'Test_Domain';
25+
const DESCRIPTION = 'Test description';
26+
const NAMESPACE_NAME = 'Test_Namespace';
27+
const EDITED_NAMESPACE_NAME = 'Test_Namespace_Edited';
28+
const EDITED_DESCRIPTION = 'Test description edited';
29+
const INVALID_NAMESPACE_NAME = 'Test Namespace';
30+
const NAMESPACE_FORM_HEADER = 'Automate Namespace';
31+
const NAMESPACE_FORM_SUB_HEADER = 'Info';
32+
33+
// List items
34+
const DATA_STORE_ACCORDION_LABEL = 'Datastore';
35+
36+
// Buttons
37+
const ADD_BUTTON_TEXT = 'Add';
38+
const CANCEL_BUTTON_TEXT = 'Cancel';
39+
const SAVE_BUTTON_TEXT = 'Save';
40+
const RESET_BUTTON_TEXT = 'Reset';
41+
42+
// Flash message text snippets
43+
const FLASH_MESSAGE_ADD_SUCCESS = 'added';
44+
const FLASH_MESSAGE_SAVE_SUCCESS = 'saved';
45+
const FLASH_MESSAGE_CANCELLED = 'cancel';
46+
const FLASH_MESSAGE_INVALID_NAMESPACE = 'contain only alphanumeric';
47+
const FLASH_MESSAGE_NAMESPACE_REMOVED = 'delete successful';
48+
const FLASH_MESSAGE_NAME_ALREADY_EXISTS = 'taken';
49+
const FLASH_MESSAGE_RESET_NAMESPACE = 'reset';
50+
const BROWSER_CONFIRM_REMOVE_MESSAGE = 'remove';
51+
52+
function addDomainOrNamespace({ nameFieldValue }) {
53+
// Adding name & description
54+
cy.getFormInputFieldByIdAndType({ inputId: 'name' }).type(nameFieldValue);
55+
cy.getFormInputFieldByIdAndType({ inputId: 'description' }).type(DESCRIPTION);
56+
// Submitting the form
57+
cy.interceptApi({
58+
alias: 'addDomainOrNamespaceApi',
59+
urlPattern: '/miq_ae_class/create_namespace/new?button=add',
60+
triggerFn: () =>
61+
cy
62+
.getFormFooterButtonByTypeWithText({
63+
buttonText: ADD_BUTTON_TEXT,
64+
buttonType: 'submit',
65+
})
66+
.click(),
67+
});
68+
}
69+
70+
function validateNamespaceFormFields(isEditForm = false) {
71+
cy.expect_explorer_title(NAMESPACE_FORM_HEADER);
72+
cy.get('#main-content #datastore-form-wrapper h3').contains(
73+
NAMESPACE_FORM_SUB_HEADER
74+
);
75+
cy.getFormLabelByForAttribute({ forValue: 'namespacePath' })
76+
.should('be.visible')
77+
.and('contain.text', NAME_SAPCE_PATH_FIELD_LABEL);
78+
cy.getFormInputFieldByIdAndType({ inputId: 'namespacePath' })
79+
.should('be.visible')
80+
.and('be.disabled')
81+
.invoke('val')
82+
.should('include', DOMAIN_NAME);
83+
cy.getFormLabelByForAttribute({ forValue: 'name' })
84+
.should('be.visible')
85+
.and('contain.text', NAME_FIELD_LABEL);
86+
cy.getFormInputFieldByIdAndType({ inputId: 'name' })
87+
.should('be.visible')
88+
.and('be.enabled');
89+
cy.getFormLabelByForAttribute({ forValue: 'description' })
90+
.should('be.visible')
91+
.and('contain.text', DESCRIPTION_FIELD_LABEL);
92+
cy.getFormInputFieldByIdAndType({ inputId: 'description' })
93+
.should('be.visible')
94+
.and('be.enabled');
95+
cy.getFormFooterButtonByTypeWithText({ buttonText: CANCEL_BUTTON_TEXT })
96+
.should('be.visible')
97+
.and('be.enabled');
98+
cy.getFormFooterButtonByTypeWithText({
99+
buttonText: isEditForm ? SAVE_BUTTON_TEXT : ADD_BUTTON_TEXT,
100+
buttonType: 'submit',
101+
})
102+
.should('be.visible')
103+
.and('be.disabled');
104+
if (isEditForm) {
105+
cy.getFormFooterButtonByTypeWithText({ buttonText: RESET_BUTTON_TEXT })
106+
.should('be.visible')
107+
.and('be.disabled');
108+
}
109+
}
110+
111+
function createNamespaceAndOpenEditForm() {
112+
/* TODO: DATA_SETUP - Use API for namespace setup, excluding the test meant to validate functionality via UI */
113+
cy.toolbar(TOOLBAR_CONFIGURATION, TOOLBAR_ADD_NEW_NAMESPACE);
114+
addDomainOrNamespace({ nameFieldValue: NAMESPACE_NAME });
115+
cy.selectAccordionItem([
116+
DATA_STORE_ACCORDION_LABEL,
117+
DOMAIN_NAME,
118+
NAMESPACE_NAME,
119+
]);
120+
cy.toolbar(TOOLBAR_CONFIGURATION, TOOLBAR_EDIT_NAMESPACE);
121+
}
122+
123+
describe('Automate operations on Namespaces: Automation -> Embedded Automate -> Explorer -> {Any-created-domain} -> Namespace form', () => {
124+
beforeEach(() => {
125+
cy.login();
126+
cy.menu(
127+
AUTOMATION_MENU_OPTION,
128+
EMBEDDED_AUTOMATION_MENU_OPTION,
129+
EXPLORER_MENU_OPTION
130+
);
131+
cy.accordion(DATA_STORE_ACCORDION_LABEL);
132+
/* TODO: DATA_SETUP - Refactor to use API for domain data setup */
133+
cy.toolbar(TOOLBAR_CONFIGURATION, TOOLBAR_ADD_NEW_DOMAIN);
134+
addDomainOrNamespace({
135+
nameFieldValue: DOMAIN_NAME,
136+
});
137+
cy.expect_flash(flashClassMap.success, FLASH_MESSAGE_ADD_SUCCESS);
138+
cy.selectAccordionItem([DATA_STORE_ACCORDION_LABEL, DOMAIN_NAME]);
139+
});
140+
141+
it('Validate Add Namespace form fields', () => {
142+
cy.toolbar(TOOLBAR_CONFIGURATION, TOOLBAR_ADD_NEW_NAMESPACE);
143+
validateNamespaceFormFields();
144+
cy.getFormFooterButtonByTypeWithText({
145+
buttonText: CANCEL_BUTTON_TEXT,
146+
}).click();
147+
});
148+
149+
it('Validate Cancel button', () => {
150+
cy.toolbar(TOOLBAR_CONFIGURATION, TOOLBAR_ADD_NEW_NAMESPACE);
151+
cy.getFormFooterButtonByTypeWithText({ buttonText: CANCEL_BUTTON_TEXT })
152+
.should('be.enabled')
153+
.click();
154+
cy.expect_flash(flashClassMap.warning, FLASH_MESSAGE_CANCELLED);
155+
});
156+
157+
it('Validate Name field allows only alphanumeric and _ . - $ characters', () => {
158+
cy.toolbar(TOOLBAR_CONFIGURATION, TOOLBAR_ADD_NEW_NAMESPACE);
159+
addDomainOrNamespace({ nameFieldValue: INVALID_NAMESPACE_NAME });
160+
cy.expect_flash(flashClassMap.error, FLASH_MESSAGE_INVALID_NAMESPACE);
161+
cy.getFormFooterButtonByTypeWithText({
162+
buttonText: CANCEL_BUTTON_TEXT,
163+
}).click();
164+
});
165+
166+
it('Validate Edit Namespace form fields', () => {
167+
createNamespaceAndOpenEditForm();
168+
validateNamespaceFormFields(true);
169+
cy.getFormFooterButtonByTypeWithText({
170+
buttonText: CANCEL_BUTTON_TEXT,
171+
}).click();
172+
});
173+
174+
it('Checking whether add, edit & delete namespace works', () => {
175+
cy.toolbar(TOOLBAR_CONFIGURATION, TOOLBAR_ADD_NEW_NAMESPACE);
176+
addDomainOrNamespace({ nameFieldValue: NAMESPACE_NAME });
177+
cy.expect_flash(flashClassMap.success, FLASH_MESSAGE_ADD_SUCCESS);
178+
cy.selectAccordionItem([
179+
DATA_STORE_ACCORDION_LABEL,
180+
DOMAIN_NAME,
181+
NAMESPACE_NAME,
182+
]);
183+
cy.toolbar(TOOLBAR_CONFIGURATION, TOOLBAR_EDIT_NAMESPACE);
184+
cy.getFormFooterButtonByTypeWithText({
185+
buttonText: SAVE_BUTTON_TEXT,
186+
buttonType: 'submit',
187+
}).should('be.disabled');
188+
cy.getFormInputFieldByIdAndType({ inputId: 'description' })
189+
.clear()
190+
.type(EDITED_DESCRIPTION);
191+
cy.getFormFooterButtonByTypeWithText({
192+
buttonText: SAVE_BUTTON_TEXT,
193+
buttonType: 'submit',
194+
})
195+
.should('be.enabled')
196+
.click();
197+
cy.expect_flash(flashClassMap.success, FLASH_MESSAGE_SAVE_SUCCESS);
198+
cy.expect_browser_confirm_with_text({
199+
confirmTriggerFn: () =>
200+
cy.toolbar(TOOLBAR_CONFIGURATION, TOOLBAR_REMOVE_NAMESPACE),
201+
containsText: BROWSER_CONFIRM_REMOVE_MESSAGE,
202+
});
203+
cy.expect_flash(flashClassMap.success, FLASH_MESSAGE_NAMESPACE_REMOVED);
204+
});
205+
206+
it('Checking whether creating a duplicate namespace is restricted', () => {
207+
/* TODO: DATA_SETUP - Use API for namespace setup, excluding the test meant to validate functionality via UI */
208+
cy.toolbar(TOOLBAR_CONFIGURATION, TOOLBAR_ADD_NEW_NAMESPACE);
209+
addDomainOrNamespace({ nameFieldValue: NAMESPACE_NAME });
210+
cy.toolbar(TOOLBAR_CONFIGURATION, TOOLBAR_ADD_NEW_NAMESPACE);
211+
addDomainOrNamespace({ nameFieldValue: NAMESPACE_NAME });
212+
cy.expect_flash(flashClassMap.error, FLASH_MESSAGE_NAME_ALREADY_EXISTS);
213+
cy.getFormFooterButtonByTypeWithText({
214+
buttonText: CANCEL_BUTTON_TEXT,
215+
}).click();
216+
});
217+
218+
it('Checking whether Cancel & Reset buttons work fine in the Edit form', () => {
219+
createNamespaceAndOpenEditForm();
220+
/* Validating Reset button */
221+
cy.getFormFooterButtonByTypeWithText({
222+
buttonText: RESET_BUTTON_TEXT,
223+
}).should('be.disabled');
224+
cy.getFormInputFieldByIdAndType({ inputId: 'name' })
225+
.clear()
226+
.type(EDITED_NAMESPACE_NAME);
227+
cy.getFormInputFieldByIdAndType({ inputId: 'description' })
228+
.clear()
229+
.type(EDITED_DESCRIPTION);
230+
cy.getFormFooterButtonByTypeWithText({ buttonText: RESET_BUTTON_TEXT })
231+
.should('be.enabled')
232+
.click();
233+
cy.expect_flash(flashClassMap.warning, FLASH_MESSAGE_RESET_NAMESPACE);
234+
cy.getFormInputFieldByIdAndType({ inputId: 'name' }).should(
235+
'have.value',
236+
NAMESPACE_NAME
237+
);
238+
cy.getFormInputFieldByIdAndType({ inputId: 'description' }).should(
239+
'have.value',
240+
DESCRIPTION
241+
);
242+
/* Validating Cancel button */
243+
cy.getFormFooterButtonByTypeWithText({
244+
buttonText: CANCEL_BUTTON_TEXT,
245+
}).click();
246+
cy.expect_flash(flashClassMap.warning, FLASH_MESSAGE_CANCELLED);
247+
});
248+
249+
afterEach(() => {
250+
cy.url()
251+
.then((url) => {
252+
// Ensures navigation to Automation -> Embedded Automate -> Explorer in the UI
253+
if (!url.endsWith(COMPONENT_ROUTE_URL)) {
254+
cy.visit(COMPONENT_ROUTE_URL);
255+
}
256+
cy.accordion(DATA_STORE_ACCORDION_LABEL);
257+
})
258+
.then(() => {
259+
cy.get('div.panel-collapse.collapse.in li.list-group-item').each(
260+
(item) => {
261+
const text = item.text().trim();
262+
if (text === DOMAIN_NAME) {
263+
if (!item.hasClass('node-selected')) {
264+
cy.wrap(item).click();
265+
}
266+
cy.expect_browser_confirm_with_text({
267+
confirmTriggerFn: () =>
268+
cy.toolbar(TOOLBAR_CONFIGURATION, TOOLBAR_REMOVE_DOMAIN),
269+
containsText: BROWSER_CONFIRM_REMOVE_MESSAGE,
270+
});
271+
return false; // exit iteration
272+
}
273+
return null; // has no impact, just to get rid of eslint warning
274+
}
275+
);
276+
});
277+
});
278+
});

0 commit comments

Comments
 (0)