Skip to content

Commit 2fc0b47

Browse files
Added automated tests with cypress for Zone form
1 parent 4f7604d commit 2fc0b47

File tree

1 file changed

+287
-0
lines changed
  • cypress/e2e/ui/Settings/Application-Settings

1 file changed

+287
-0
lines changed
Lines changed: 287 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,287 @@
1+
/* eslint-disable no-undef */
2+
import { flashClassMap } from '../../../../support/assertions/assertion_constants';
3+
4+
// Component route url
5+
const COMPONENT_ROUTE_URL = '/ops/explorer';
6+
7+
// Menu options
8+
const SETTINGS_OPTION = 'Settings';
9+
const APP_SETTINGS_OPTION = 'Application Settings';
10+
11+
// Accordion items
12+
const MANAGEIQ_REGION_ACCORDION_ITEM = /^ManageIQ Region:/;
13+
const ZONES_ACCORDION_ITEM = 'Zones';
14+
15+
// Config options
16+
const CONFIG_TOOLBAR_BUTTON = 'Configuration';
17+
const ADD_ZONE_CONFIG_OPTION = 'Add a new Zone';
18+
const EDIT_ZONE_CONFIG_OPTION = 'Edit this Zone';
19+
const DELETE_ZONE_CONFIG_OPTION = 'Delete this Zone';
20+
21+
// Field values
22+
const FORM_HEADER_FRAGMENT = 'Zone';
23+
const INFO_SUB_HEADER = 'Info';
24+
const SETTINGS_SUB_HEADER = 'Settings';
25+
const ZONE_NAME = 'Test-Zone-Name';
26+
const INITIAL_ZONE_DESCRIPTION = 'Test-Zone-Description';
27+
const UPDATED_ZONE_DESCRIPTION = 'Test-Zone-Description-Updated';
28+
const INITIAL_SERVER_IP = '0.0.0.0';
29+
const UPDATED_SERVER_IP = '1.1.1.1';
30+
const INITIAL_MAX_SCAN_LIMIT = 5;
31+
const UPDATED_MAX_SCAN_LIMIT = 10;
32+
33+
// Element ids
34+
const IP_INPUT_FIELD_ID = 'settings\\.proxy_server_ip';
35+
const MAX_SCAN_SELECT_FIELD_ID = 'settings\\.concurrent_vm_scans';
36+
37+
// Buttons
38+
const SAVE_BUTTON_TEXT = 'Save';
39+
const CANCEL_BUTTON_TEXT = 'Cancel';
40+
const ADD_BUTTON_TEXT = 'Add';
41+
const RESET_BUTTON_TEXT = 'Reset';
42+
43+
// Flash message text snippets
44+
const FLASH_MESSAGE_OPERATION_CANCELED = 'cancel';
45+
const FLASH_MESSAGE_ZONE_UPDATED = 'queued';
46+
const FLASH_MESSAGE_OPERATION_RESET = 'reset';
47+
const DELETE_CONFIRM_TEXT = 'delete';
48+
49+
function addZone() {
50+
// Open add form
51+
cy.toolbar(CONFIG_TOOLBAR_BUTTON, ADD_ZONE_CONFIG_OPTION);
52+
// Adding name, description, ip and scan limit
53+
cy.getFormInputFieldById('name').type(ZONE_NAME);
54+
cy.getFormInputFieldById('description').type(INITIAL_ZONE_DESCRIPTION);
55+
cy.getFormInputFieldById(IP_INPUT_FIELD_ID).type(INITIAL_SERVER_IP);
56+
cy.getFormSelectFieldById(MAX_SCAN_SELECT_FIELD_ID).select(
57+
INITIAL_MAX_SCAN_LIMIT
58+
);
59+
cy.interceptApi({
60+
alias: 'createZoneApi',
61+
urlPattern: '/api/zones',
62+
triggerFn: () =>
63+
cy
64+
.getFormFooterButtonByType(ADD_BUTTON_TEXT, 'submit')
65+
.should('be.enabled')
66+
.click(),
67+
});
68+
return cy.then(() => {
69+
return `Zone: ${INITIAL_ZONE_DESCRIPTION}`;
70+
});
71+
}
72+
73+
function validateFormElements(isEditForm = false) {
74+
// Assert form header is visible
75+
cy.expect_explorer_title(FORM_HEADER_FRAGMENT);
76+
// Assert Info sub header is visible
77+
cy.get('#main-content .bx--form h3').contains(INFO_SUB_HEADER);
78+
// Assert name field label is visible
79+
cy.getFormLabelByInputId('name').should('be.visible');
80+
// Assert name field is visible and enabled
81+
cy.getFormInputFieldById('name')
82+
.should('be.visible')
83+
.then((nameField) => {
84+
if (isEditForm) {
85+
expect(nameField).to.be.disabled;
86+
} else {
87+
expect(nameField).to.not.be.disabled;
88+
}
89+
});
90+
// Assert description field label is visible
91+
cy.getFormLabelByInputId('description').should('be.visible');
92+
// Assert description field is visible and enabled
93+
cy.getFormInputFieldById('description')
94+
.should('be.visible')
95+
.and('be.enabled');
96+
// Assert IP field label is visible
97+
cy.getFormLabelByInputId(IP_INPUT_FIELD_ID).should('be.visible');
98+
// Assert IP field is visible and enabled
99+
cy.getFormInputFieldById(IP_INPUT_FIELD_ID)
100+
.should('be.visible')
101+
.and('be.enabled');
102+
// Assert Settings sub header is visible
103+
cy.get('#main-content .bx--form h3').contains(SETTINGS_SUB_HEADER);
104+
// Assert max scan field label is visible
105+
cy.getFormLabelByInputId(MAX_SCAN_SELECT_FIELD_ID).should('be.visible');
106+
// Assert max scan field is visible and enabled
107+
cy.getFormSelectFieldById(MAX_SCAN_SELECT_FIELD_ID)
108+
.should('be.visible')
109+
.and('be.enabled');
110+
// Assert cancel button is visible and enabled
111+
cy.getFormFooterButtonByType(CANCEL_BUTTON_TEXT)
112+
.should('be.visible')
113+
.and('be.enabled');
114+
if (isEditForm) {
115+
// Assert reset button is visible and disabled
116+
cy.getFormFooterButtonByType(RESET_BUTTON_TEXT)
117+
.should('be.visible')
118+
.and('be.disabled');
119+
}
120+
// Assert add/save button is visible and disabled
121+
cy.getFormFooterButtonByType(
122+
isEditForm ? SAVE_BUTTON_TEXT : ADD_BUTTON_TEXT,
123+
'submit'
124+
)
125+
.should('be.visible')
126+
.and('be.disabled');
127+
}
128+
129+
function cleanUp() {
130+
cy.get('li.list-group-item').each((item) => {
131+
const text = item?.text()?.trim();
132+
if (text.includes(INITIAL_ZONE_DESCRIPTION)) {
133+
// Select the zone node if it hasn't been selected yet
134+
if (!item.hasClass('node-selected')) {
135+
cy.wrap(item).click();
136+
cy.wait('@treeSelectApi');
137+
}
138+
// Deleting the zone
139+
cy.expect_browser_confirm_with_text({
140+
confirmTriggerFn: () =>
141+
cy.toolbar(CONFIG_TOOLBAR_BUTTON, DELETE_ZONE_CONFIG_OPTION),
142+
});
143+
return false; // exit the iteration
144+
}
145+
return null; // has no impact - just to get rid of eslint warning
146+
});
147+
}
148+
149+
function selectZoneAccordionItem(childZoneNode) {
150+
cy.interceptApi({
151+
alias: 'treeSelectApi',
152+
urlPattern: /\/ops\/tree_select\?id=.*&text=.*/,
153+
triggerFn: () =>
154+
cy.selectAccordionItem([
155+
MANAGEIQ_REGION_ACCORDION_ITEM,
156+
ZONES_ACCORDION_ITEM,
157+
...(childZoneNode ? [childZoneNode] : []),
158+
]),
159+
});
160+
}
161+
162+
describe('Automate Schedule form operations: Settings > Application Settings > Settings > Zones > Configuration > Add a new Zone', () => {
163+
beforeEach(() => {
164+
cy.login();
165+
// Navigate to Application-Settings
166+
cy.menu(SETTINGS_OPTION, APP_SETTINGS_OPTION);
167+
// Expand Settings accordion panel if not already expanded
168+
cy.accordion(SETTINGS_OPTION);
169+
// Select "Zones" accordion item
170+
selectZoneAccordionItem();
171+
});
172+
173+
it('Validate the visibility and state of add form elements', () => {
174+
// Open add form
175+
cy.toolbar(CONFIG_TOOLBAR_BUTTON, ADD_ZONE_CONFIG_OPTION);
176+
// Validate fields
177+
validateFormElements();
178+
});
179+
180+
it('Checking whether cancel button works on the add form', () => {
181+
// Open add form
182+
cy.toolbar(CONFIG_TOOLBAR_BUTTON, ADD_ZONE_CONFIG_OPTION);
183+
// Cancelling the form
184+
cy.getFormFooterButtonByType(CANCEL_BUTTON_TEXT).click();
185+
cy.expect_flash(flashClassMap.warning, FLASH_MESSAGE_OPERATION_CANCELED);
186+
});
187+
188+
it('Checking whether add, edit & delete zone works', () => {
189+
/* ===== Add ===== */
190+
// Adding zone
191+
addZone().then((createdZone) => {
192+
// Here the createdZone will have value "Zone: Test-Zone-Description",
193+
// which is the accordion item to be selected
194+
// Assert flash message
195+
cy.expect_flash(flashClassMap.success, FLASH_MESSAGE_ZONE_UPDATED);
196+
// Select the created zone
197+
selectZoneAccordionItem(createdZone);
198+
});
199+
/* ===== Edit ===== */
200+
// Open edit form
201+
cy.toolbar(CONFIG_TOOLBAR_BUTTON, EDIT_ZONE_CONFIG_OPTION);
202+
// Update IP & scan limit
203+
cy.getFormInputFieldById('description').clear().type(UPDATED_SERVER_IP);
204+
cy.getFormSelectFieldById(MAX_SCAN_SELECT_FIELD_ID).select(
205+
UPDATED_MAX_SCAN_LIMIT
206+
);
207+
// Save the form
208+
cy.getFormFooterButtonByType(SAVE_BUTTON_TEXT, 'submit')
209+
.should('be.enabled')
210+
.click();
211+
cy.expect_flash(flashClassMap.success, FLASH_MESSAGE_ZONE_UPDATED);
212+
/* ===== Delete ===== */
213+
// Deleting the zone
214+
cy.expect_browser_confirm_with_text({
215+
confirmTriggerFn: () =>
216+
cy.toolbar(CONFIG_TOOLBAR_BUTTON, DELETE_ZONE_CONFIG_OPTION),
217+
containsText: DELETE_CONFIRM_TEXT,
218+
});
219+
cy.expect_flash(flashClassMap.success, DELETE_CONFIRM_TEXT);
220+
});
221+
222+
it('Validate the visibility and state of edit form elements', () => {
223+
// Adding zone
224+
addZone().then((createdZone) => {
225+
// Here the createdZone will have value "Zone: Test-Zone-Description",
226+
// which is the accordion item to be selected
227+
// Select the created zone
228+
selectZoneAccordionItem(createdZone);
229+
});
230+
// Open edit form
231+
cy.toolbar(CONFIG_TOOLBAR_BUTTON, EDIT_ZONE_CONFIG_OPTION);
232+
// Validate fields
233+
validateFormElements(true);
234+
// Cancelling the form
235+
cy.getFormFooterButtonByType(CANCEL_BUTTON_TEXT).click();
236+
});
237+
238+
it('Checking whether cancel & reset buttons work on the edit form', () => {
239+
// Adding zone
240+
addZone().then((createdZone) => {
241+
// Here the createdZone will have value "Zone: Test-Zone-Description",
242+
// which is the accordion item to be selected
243+
// Select the created zone
244+
selectZoneAccordionItem(createdZone);
245+
});
246+
// Open edit form
247+
cy.toolbar(CONFIG_TOOLBAR_BUTTON, EDIT_ZONE_CONFIG_OPTION);
248+
/* ===== Reset ===== */
249+
// Update description & IP
250+
cy.getFormInputFieldById('description')
251+
.clear()
252+
.type(UPDATED_ZONE_DESCRIPTION);
253+
cy.getFormInputFieldById(IP_INPUT_FIELD_ID).clear().type(UPDATED_SERVER_IP);
254+
// Resetting the form
255+
cy.getFormFooterButtonByType(RESET_BUTTON_TEXT)
256+
.should('be.enabled')
257+
.click();
258+
cy.expect_flash(flashClassMap.warning, FLASH_MESSAGE_OPERATION_RESET);
259+
// Confirming the edited fields contain the old values after resetting
260+
cy.getFormInputFieldById('description').should(
261+
'have.value',
262+
INITIAL_ZONE_DESCRIPTION
263+
);
264+
cy.getFormInputFieldById(IP_INPUT_FIELD_ID).should(
265+
'have.value',
266+
INITIAL_SERVER_IP
267+
);
268+
/* ===== Cancel ===== */
269+
// Cancelling the form
270+
cy.getFormFooterButtonByType(CANCEL_BUTTON_TEXT).click();
271+
cy.expect_flash(flashClassMap.warning, FLASH_MESSAGE_OPERATION_CANCELED);
272+
});
273+
274+
afterEach(() => {
275+
cy.url()
276+
?.then((url) => {
277+
// Ensures navigation to Settings -> Application-Settings in the UI
278+
if (!url?.includes(COMPONENT_ROUTE_URL)) {
279+
// Navigate to Settings -> Application-Settings before cleanup
280+
cy.menu(SETTINGS_OPTION, APP_SETTINGS_OPTION);
281+
}
282+
})
283+
.then(() => {
284+
cleanUp();
285+
});
286+
});
287+
});

0 commit comments

Comments
 (0)