Skip to content

Commit a2d5be5

Browse files
Added automated tests with cypress for Collect-logs edit form
1 parent 5f028d4 commit a2d5be5

File tree

1 file changed

+288
-0
lines changed

1 file changed

+288
-0
lines changed
Lines changed: 288 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,288 @@
1+
/* eslint-disable no-undef */
2+
3+
function disableNotificationsIfVisible() {
4+
// Look for notification popups and disable them if present
5+
cy.get('body').then(($body) => {
6+
const $link = $body.find(
7+
'.miq-toast-wrapper .row .alert a:contains("Disable notifications")'
8+
);
9+
if ($link.length && $link.is(':visible')) {
10+
cy.wrap($link).click({ force: true });
11+
}
12+
});
13+
}
14+
15+
function resetProtocolForServer() {
16+
// Select Diagnostics
17+
cy.get('.panel #control_diagnostics_accord .panel-title a')
18+
.contains('Diagnostics')
19+
.click();
20+
// Open ManageIQ Region: - list view if not already open
21+
cy.get(
22+
'#diagnostics_accord .treeview li.list-group-item[title^="ManageIQ Region:"]'
23+
).then(($li) => {
24+
const span = $li.find('span.fa-angle-right');
25+
if (span.length) {
26+
cy.wrap(span).click();
27+
}
28+
});
29+
// Open Zone: - list view if not already open
30+
cy.get(
31+
'#diagnostics_accord .treeview li.list-group-item[title^="Zone:"]'
32+
).then(($li) => {
33+
const span = $li.find('span.fa-angle-right');
34+
if (span.length) {
35+
cy.wrap(span).click();
36+
}
37+
});
38+
// Selecting Server: list view
39+
cy.get(
40+
'#diagnostics_accord .treeview li.list-group-item[title^="Server:"]'
41+
).click();
42+
// Selecting Collect Logs nav bar
43+
cy.get(
44+
'#tab_all_tabs_div #ops_tabs .nav-tabs li#diagnostics_collect_logs_tab'
45+
).click();
46+
// Clicking Edit button
47+
cy.get(
48+
'.miq-toolbar-actions .miq-toolbar-group button#log_depot_edit'
49+
).click();
50+
cy.wait('@editEventForServer');
51+
// Resetting Protocol dropdown value
52+
cy.get('#log-depot-settings .bx--select select#log_protocol').then(
53+
($select) => {
54+
const currentValue = $select.val();
55+
// If the value is not default one(BLANK_VALUE), then setting it to blank
56+
if (currentValue !== 'BLANK_VALUE') {
57+
cy.wrap($select).select('BLANK_VALUE');
58+
cy.get('#diagnostics_collect_logs .bx--btn-set button[type="Submit"]')
59+
.contains('Save')
60+
.click();
61+
cy.get('#main_div #flash_msg_div .alert-success').contains(
62+
'Log Depot Settings were saved'
63+
);
64+
}
65+
}
66+
);
67+
}
68+
69+
function resetProtocolForZone() {
70+
cy.get('.panel #control_diagnostics_accord .panel-title a')
71+
.contains('Diagnostics')
72+
.click();
73+
// Open ManageIQ Region: - list view if not already open
74+
cy.get(
75+
'#diagnostics_accord .treeview li.list-group-item[title^="ManageIQ Region:"]'
76+
).then(($li) => {
77+
const span = $li.find('span.fa-angle-right');
78+
if (span.length) {
79+
cy.wrap(span).click();
80+
}
81+
});
82+
// Open Zone: - list view if not already open
83+
cy.get(
84+
'#diagnostics_accord .treeview li.list-group-item[title^="Zone:"]'
85+
).click();
86+
// Selecting Collect Logs navbar
87+
cy.get(
88+
'#tab_all_tabs_div #ops_tabs .nav-tabs li#diagnostics_collect_logs_tab'
89+
).click();
90+
// Clicking Edit button
91+
cy.get(
92+
'.miq-toolbar-actions .miq-toolbar-group button#zone_log_depot_edit'
93+
).click();
94+
cy.wait('@editEventForZone');
95+
// Resetting Protocol dropdown value
96+
cy.get('#log-depot-settings .bx--select select#log_protocol').then(
97+
($select) => {
98+
const currentValue = $select.val();
99+
// If the value is not default one(BLANK_VALUE), then setting it to blank and then saving
100+
if (currentValue !== 'BLANK_VALUE') {
101+
cy.wrap($select).select('BLANK_VALUE');
102+
cy.get('#diagnostics_collect_logs .bx--btn-set button[type="Submit"]')
103+
.contains('Save')
104+
.click();
105+
cy.get('#main_div #flash_msg_div .alert-success').contains(
106+
'Log Depot Settings were saved'
107+
);
108+
}
109+
}
110+
);
111+
}
112+
113+
function cancelButtonValidation() {
114+
// Click cancel button in the form
115+
cy.get('#diagnostics_collect_logs .bx--btn-set button[type="button"]')
116+
.contains('Cancel')
117+
.should('be.enabled')
118+
.click();
119+
// Validating confirmation alert text displayed
120+
cy.get('#main_div #flash_msg_div .alert-success').contains(
121+
'Edit Log Depot settings was cancelled by the user'
122+
);
123+
}
124+
125+
function resetButtonValidation() {
126+
// Confirm Reset button is disabled initially
127+
cy.get('#diagnostics_collect_logs .bx--btn-set button[type="button"]')
128+
.contains('Reset')
129+
.should('be.disabled');
130+
// Selecting Samba option from dropdown
131+
cy.get('#log-depot-settings .bx--select select#log_protocol').select('Samba');
132+
// Confirm Reset button is enabled once dropdown value is changed and then click on Reset
133+
cy.get('#diagnostics_collect_logs .bx--btn-set button[type="button"]')
134+
.contains('Reset')
135+
.should('be.enabled')
136+
.click();
137+
// Confirm dropdown has the old value
138+
cy.get('#log-depot-settings .bx--select select#log_protocol').should(
139+
'have.value',
140+
'BLANK_VALUE'
141+
);
142+
}
143+
144+
function saveButtonValidation() {
145+
// Confirm Save button is disabled initially
146+
cy.get('#diagnostics_collect_logs .bx--btn-set button[type="Submit"]')
147+
.contains('Save')
148+
.should('be.disabled');
149+
// Selecting Samba option from dropdown
150+
cy.get('#log-depot-settings .bx--select select#log_protocol').select('Samba');
151+
// Confirm Save button is enabled once dropdown value is changed and then click on Save
152+
cy.get('#diagnostics_collect_logs .bx--btn-set button[type="Submit"]')
153+
.contains('Save')
154+
.should('be.enabled')
155+
.click();
156+
// Validating confirmation alert text displayed
157+
cy.get('#main_div #flash_msg_div .alert-success').contains(
158+
'Log Depot Settings were saved'
159+
);
160+
}
161+
162+
describe('Automate Collect logs Edit form operations', () => {
163+
beforeEach(() => {
164+
cy.intercept('GET', '/api/notifications').as('getNotifications');
165+
cy.login();
166+
// After logging in, ensure the notification banner is disabled to avoid blocking other elements
167+
cy.wait('@getNotifications').then(() => {
168+
disableNotificationsIfVisible();
169+
});
170+
// Navigate to Application settings and Select Diagnostics
171+
cy.menu('Settings', 'Application Settings');
172+
cy.get('.panel #control_diagnostics_accord .panel-title a')
173+
.contains('Diagnostics')
174+
.click();
175+
// Open ManageIQ Region: - list view if not already open
176+
cy.get(
177+
'#diagnostics_accord .treeview li.list-group-item[title^="ManageIQ Region:"]'
178+
).then(($li) => {
179+
const span = $li.find('span.fa-angle-right');
180+
if (span.length) {
181+
cy.wrap(span).click();
182+
}
183+
});
184+
});
185+
186+
describe('Settings > Application Settings > Diagnostics > Manage IQ Region > Zone > Server > Collect logs > Edit', () => {
187+
beforeEach(() => {
188+
// Open Zone: - list view if not already open
189+
cy.get(
190+
'#diagnostics_accord .treeview li.list-group-item[title^="Zone:"]'
191+
).then(($li) => {
192+
const span = $li.find('span.fa-angle-right');
193+
if (span.length) {
194+
cy.wrap(span).click();
195+
}
196+
});
197+
// Selecting Server: list view
198+
cy.get(
199+
'#diagnostics_accord .treeview li.list-group-item[title^="Server:"]'
200+
).click();
201+
// Selecting Collect Logs nav bar
202+
cy.get(
203+
'#tab_all_tabs_div #ops_tabs .nav-tabs li#diagnostics_collect_logs_tab'
204+
).click();
205+
// Clicking Edit button
206+
cy.intercept('POST', '/ops/x_button/1?pressed=log_depot_edit').as(
207+
'editEventForServer'
208+
);
209+
cy.get(
210+
'.miq-toolbar-actions .miq-toolbar-group button#log_depot_edit'
211+
).click();
212+
cy.wait('@editEventForServer');
213+
});
214+
215+
it('Validate Cancel button', () => {
216+
cancelButtonValidation();
217+
});
218+
219+
it('Validate Reset button', () => {
220+
resetButtonValidation();
221+
});
222+
223+
it('Validate Save button', () => {
224+
saveButtonValidation();
225+
});
226+
227+
after(() => {
228+
cy?.url()?.then((url) => {
229+
// Ensures navigation to Settings -> Application-Settings in the UI
230+
if (url?.includes('/ops/explorer')) {
231+
resetProtocolForServer();
232+
} else {
233+
// Navigate to Settings -> Application-Settings before selecting Diagnostics
234+
cy.menu('Settings', 'Application Settings');
235+
resetProtocolForServer();
236+
}
237+
});
238+
});
239+
});
240+
241+
describe('Settings > Application Settings > Diagnostics > Manage IQ Region > Zone > Collect logs > Edit', () => {
242+
beforeEach(() => {
243+
// Selecting Zone: - list view
244+
cy.intercept('POST', '/ops/tree_select?id=z-2*').as('treeSelectApi');
245+
cy.get(
246+
'#diagnostics_accord .treeview li.list-group-item[title^="Zone:"]'
247+
).click();
248+
cy.wait('@treeSelectApi');
249+
// Selecting Collect Logs navbar
250+
cy.get(
251+
'#tab_all_tabs_div #ops_tabs .nav-tabs li#diagnostics_collect_logs_tab'
252+
).click();
253+
// Clicking Edit button
254+
cy.intercept('POST', '/ops/x_button/2?pressed=zone_log_depot_edit').as(
255+
'editEventForZone'
256+
);
257+
cy.get(
258+
'.miq-toolbar-actions .miq-toolbar-group button#zone_log_depot_edit'
259+
).click();
260+
cy.wait('@editEventForZone');
261+
});
262+
263+
it('Validate Cancel button', () => {
264+
cancelButtonValidation();
265+
});
266+
267+
it('Validate Reset button', () => {
268+
resetButtonValidation();
269+
});
270+
271+
it('Validate Save button', () => {
272+
saveButtonValidation();
273+
});
274+
275+
after(() => {
276+
cy?.url()?.then((url) => {
277+
// Ensures navigation to Settings -> Application-Settings in the UI
278+
if (url?.includes('/ops/explorer')) {
279+
resetProtocolForZone();
280+
} else {
281+
// Navigate to Settings -> Application-Settings before selecting Diagnostics
282+
cy.menu('Settings', 'Application Settings');
283+
resetProtocolForZone();
284+
}
285+
});
286+
});
287+
});
288+
});

0 commit comments

Comments
 (0)