Skip to content

Commit 8576556

Browse files
Added automated tests with cypress for Zone form
1 parent 244aea3 commit 8576556

File tree

1 file changed

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

1 file changed

+264
-0
lines changed
Lines changed: 264 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,264 @@
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_LABEL = '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 NAME_FIELD_LABEL = 'Name';
23+
const DESCRIPTION_FIELD_LABEL = 'Description';
24+
const SERVER_IP_FIELD_LABEL = 'Server IP';
25+
const MAX_SCAN_FIELD_LABEL = 'VM Scans';
26+
const FORM_HEADER_FRAGMENT = 'Zone';
27+
const INFO_SUB_HEADER = 'Info';
28+
const SETTINGS_SUB_HEADER = 'Settings';
29+
const ZONE_NAME = 'Test-Zone-Name';
30+
const INITIAL_ZONE_DESCRIPTION = 'Test-Zone-Description';
31+
const UPDATED_ZONE_DESCRIPTION = 'Test-Zone-Description-Updated';
32+
const INITIAL_SERVER_IP = '0.0.0.0';
33+
const UPDATED_SERVER_IP = '1.1.1.1';
34+
const INITIAL_MAX_SCAN_LIMIT = 5;
35+
const UPDATED_MAX_SCAN_LIMIT = 10;
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+
cy.toolbar(CONFIG_TOOLBAR_BUTTON, ADD_ZONE_CONFIG_OPTION);
51+
cy.getFormInputFieldByIdAndType({ inputId: 'name' }).type(ZONE_NAME);
52+
cy.getFormInputFieldByIdAndType({ inputId: 'description' }).type(
53+
INITIAL_ZONE_DESCRIPTION
54+
);
55+
cy.getFormInputFieldByIdAndType({ inputId: 'settings.proxy_server_ip' }).type(
56+
INITIAL_SERVER_IP
57+
);
58+
cy.getFormSelectFieldById({
59+
selectId: 'settings.concurrent_vm_scans',
60+
}).select(INITIAL_MAX_SCAN_LIMIT);
61+
cy.interceptApi({
62+
alias: 'createZoneApi',
63+
urlPattern: '/api/zones',
64+
triggerFn: () =>
65+
cy
66+
.getFormFooterButtonByTypeWithText({
67+
buttonText: ADD_BUTTON_TEXT,
68+
buttonType: 'submit',
69+
})
70+
.should('be.enabled')
71+
.click(),
72+
});
73+
return cy.then(() => {
74+
return `Zone: ${INITIAL_ZONE_DESCRIPTION}`;
75+
});
76+
}
77+
78+
function validateFormElements(isEditForm = false) {
79+
cy.expect_explorer_title(FORM_HEADER_FRAGMENT);
80+
cy.get('#main-content .bx--form h3').contains(INFO_SUB_HEADER);
81+
cy.getFormLabelByForAttribute({ forValue: 'name' })
82+
.should('be.visible')
83+
.and('contain.text', NAME_FIELD_LABEL);
84+
cy.getFormInputFieldByIdAndType({ inputId: 'name' })
85+
.should('be.visible')
86+
.then((nameField) => {
87+
if (isEditForm) {
88+
expect(nameField).to.be.disabled;
89+
} else {
90+
expect(nameField).to.not.be.disabled;
91+
}
92+
});
93+
cy.getFormLabelByForAttribute({ forValue: 'description' })
94+
.should('be.visible')
95+
.and('contain.text', DESCRIPTION_FIELD_LABEL);
96+
cy.getFormInputFieldByIdAndType({ inputId: 'description' })
97+
.should('be.visible')
98+
.and('be.enabled');
99+
cy.getFormLabelByForAttribute({ forValue: 'settings.proxy_server_ip' })
100+
.should('be.visible')
101+
.and('contain.text', SERVER_IP_FIELD_LABEL);
102+
cy.getFormInputFieldByIdAndType({ inputId: 'settings.proxy_server_ip' })
103+
.should('be.visible')
104+
.and('be.enabled');
105+
cy.get('#main-content .bx--form h3').contains(SETTINGS_SUB_HEADER);
106+
cy.getFormLabelByForAttribute({ forValue: 'settings.concurrent_vm_scans' })
107+
.should('be.visible')
108+
.and('contain.text', MAX_SCAN_FIELD_LABEL);
109+
cy.getFormSelectFieldById({ selectId: 'settings.concurrent_vm_scans' })
110+
.should('be.visible')
111+
.and('be.enabled');
112+
cy.getFormFooterButtonByTypeWithText({ buttonText: CANCEL_BUTTON_TEXT })
113+
.should('be.visible')
114+
.and('be.enabled');
115+
if (isEditForm) {
116+
cy.getFormFooterButtonByTypeWithText({ buttonText: RESET_BUTTON_TEXT })
117+
.should('be.visible')
118+
.and('be.disabled');
119+
}
120+
cy.getFormFooterButtonByTypeWithText({
121+
buttonText: isEditForm ? SAVE_BUTTON_TEXT : ADD_BUTTON_TEXT,
122+
buttonType: 'submit',
123+
})
124+
.should('be.visible')
125+
.and('be.disabled');
126+
}
127+
128+
function cleanUp() {
129+
cy.get('li.list-group-item').each((item) => {
130+
const text = item.text().trim();
131+
if (text.includes(INITIAL_ZONE_DESCRIPTION)) {
132+
if (!item.hasClass('node-selected')) {
133+
cy.wrap(item).click();
134+
}
135+
cy.expect_browser_confirm_with_text({
136+
confirmTriggerFn: () =>
137+
cy.toolbar(CONFIG_TOOLBAR_BUTTON, DELETE_ZONE_CONFIG_OPTION),
138+
});
139+
return false; // exit the iteration
140+
}
141+
return null; // has no impact - just to get rid of eslint warning
142+
});
143+
}
144+
145+
function selectZoneAccordionItem(childZoneNode) {
146+
cy.selectAccordionItem([
147+
MANAGEIQ_REGION_ACCORDION_ITEM,
148+
ZONES_ACCORDION_ITEM,
149+
...(childZoneNode ? [childZoneNode] : []),
150+
]);
151+
}
152+
153+
describe('Automate Zone form operations: Settings > Application Settings > Settings > Zones > Configuration > Add a new Zone', () => {
154+
beforeEach(() => {
155+
cy.login();
156+
cy.menu(SETTINGS_LABEL, APP_SETTINGS_OPTION);
157+
cy.accordion(SETTINGS_LABEL);
158+
selectZoneAccordionItem();
159+
});
160+
161+
it('Validate the visibility and state of add form elements', () => {
162+
cy.toolbar(CONFIG_TOOLBAR_BUTTON, ADD_ZONE_CONFIG_OPTION);
163+
validateFormElements();
164+
});
165+
166+
it('Checking whether cancel button works on the add form', () => {
167+
cy.toolbar(CONFIG_TOOLBAR_BUTTON, ADD_ZONE_CONFIG_OPTION);
168+
cy.getFormFooterButtonByTypeWithText({
169+
buttonText: CANCEL_BUTTON_TEXT,
170+
}).click();
171+
cy.expect_flash(flashClassMap.warning, FLASH_MESSAGE_OPERATION_CANCELED);
172+
});
173+
174+
it('Checking whether add, edit & delete zone works', () => {
175+
/* ===== Add ===== */
176+
addZone().then((createdZone) => {
177+
// Here the createdZone will have value "Zone: Test-Zone-Description",
178+
// which is the accordion item to be selected
179+
cy.expect_flash(flashClassMap.success, FLASH_MESSAGE_ZONE_UPDATED);
180+
selectZoneAccordionItem(createdZone);
181+
});
182+
/* ===== Edit ===== */
183+
cy.toolbar(CONFIG_TOOLBAR_BUTTON, EDIT_ZONE_CONFIG_OPTION);
184+
cy.getFormInputFieldByIdAndType({ inputId: 'description' })
185+
.clear()
186+
.type(UPDATED_SERVER_IP);
187+
cy.getFormSelectFieldById({
188+
selectId: 'settings.concurrent_vm_scans',
189+
}).select(UPDATED_MAX_SCAN_LIMIT);
190+
cy.getFormFooterButtonByTypeWithText({
191+
buttonText: SAVE_BUTTON_TEXT,
192+
buttonType: 'submit',
193+
})
194+
.should('be.enabled')
195+
.click();
196+
cy.expect_flash(flashClassMap.success, FLASH_MESSAGE_ZONE_UPDATED);
197+
/* ===== Delete ===== */
198+
cy.expect_browser_confirm_with_text({
199+
confirmTriggerFn: () =>
200+
cy.toolbar(CONFIG_TOOLBAR_BUTTON, DELETE_ZONE_CONFIG_OPTION),
201+
containsText: DELETE_CONFIRM_TEXT,
202+
});
203+
cy.expect_flash(flashClassMap.success, DELETE_CONFIRM_TEXT);
204+
});
205+
206+
it('Validate the visibility and state of edit form elements', () => {
207+
addZone().then((createdZone) => {
208+
// Here the createdZone will have value "Zone: Test-Zone-Description",
209+
// which is the accordion item to be selected
210+
selectZoneAccordionItem(createdZone);
211+
});
212+
cy.toolbar(CONFIG_TOOLBAR_BUTTON, EDIT_ZONE_CONFIG_OPTION);
213+
validateFormElements(true);
214+
cy.getFormFooterButtonByTypeWithText({
215+
buttonText: CANCEL_BUTTON_TEXT,
216+
}).click();
217+
});
218+
219+
it('Checking whether cancel & reset buttons work on the edit form', () => {
220+
addZone().then((createdZone) => {
221+
// Here the createdZone will have value "Zone: Test-Zone-Description",
222+
// which is the accordion item to be selected
223+
selectZoneAccordionItem(createdZone);
224+
});
225+
cy.toolbar(CONFIG_TOOLBAR_BUTTON, EDIT_ZONE_CONFIG_OPTION);
226+
/* ===== Reset ===== */
227+
cy.getFormInputFieldByIdAndType({ inputId: 'description' })
228+
.clear()
229+
.type(UPDATED_ZONE_DESCRIPTION);
230+
cy.getFormInputFieldByIdAndType({ inputId: 'settings.proxy_server_ip' })
231+
.clear()
232+
.type(UPDATED_SERVER_IP);
233+
cy.getFormFooterButtonByTypeWithText({ buttonText: RESET_BUTTON_TEXT })
234+
.should('be.enabled')
235+
.click();
236+
cy.expect_flash(flashClassMap.warning, FLASH_MESSAGE_OPERATION_RESET);
237+
cy.getFormInputFieldByIdAndType({ inputId: 'description' }).should(
238+
'have.value',
239+
INITIAL_ZONE_DESCRIPTION
240+
);
241+
cy.getFormInputFieldByIdAndType({
242+
inputId: 'settings.proxy_server_ip',
243+
}).should('have.value', INITIAL_SERVER_IP);
244+
/* ===== Cancel ===== */
245+
cy.getFormFooterButtonByTypeWithText({
246+
buttonText: CANCEL_BUTTON_TEXT,
247+
}).click();
248+
cy.expect_flash(flashClassMap.warning, FLASH_MESSAGE_OPERATION_CANCELED);
249+
});
250+
251+
afterEach(() => {
252+
cy.url()
253+
.then((url) => {
254+
// Ensures navigation to Settings -> Application-Settings in the UI
255+
if (!url.endsWith(COMPONENT_ROUTE_URL)) {
256+
cy.visit(COMPONENT_ROUTE_URL);
257+
}
258+
cy.accordion(SETTINGS_LABEL);
259+
})
260+
.then(() => {
261+
cleanUp();
262+
});
263+
});
264+
});

0 commit comments

Comments
 (0)