1
1
/* eslint-disable no-undef */
2
2
3
+ const textConstants = {
4
+ // Menu options
5
+ settingsMenuOption : 'Settings' ,
6
+ appSettingsMenuOption : 'Application Settings' ,
7
+
8
+ // List items
9
+ diagnosticsAccordionItem : 'Diagnostics' ,
10
+ diagnosticsAccordionItemId : 'diagnostics_accord' ,
11
+ manageIQRegionAccordItem : 'ManageIQ Region:' ,
12
+ zoneAccordItem : 'Zone:' ,
13
+ serverAccordItem : 'Server:' ,
14
+
15
+ // Buttons
16
+ saveButton : 'Save' ,
17
+ cancelButton : 'Cancel' ,
18
+ resetButton : 'Reset' ,
19
+
20
+ // Dropdown values
21
+ dropdownBlankValue : 'BLANK_VALUE' ,
22
+ sambaDropdownValue : 'FileDepotSmb' ,
23
+
24
+ // Component route url
25
+ componentRouteUrl : '/ops/explorer' ,
26
+ } ;
27
+
28
+ const {
29
+ diagnosticsAccordionItem,
30
+ dropdownBlankValue,
31
+ sambaDropdownValue,
32
+ saveButton,
33
+ cancelButton,
34
+ resetButton,
35
+ settingsMenuOption,
36
+ appSettingsMenuOption,
37
+ diagnosticsAccordionItemId,
38
+ manageIQRegionAccordItem,
39
+ zoneAccordItem,
40
+ serverAccordItem,
41
+ componentRouteUrl,
42
+ } = textConstants ;
43
+
3
44
function invokeAndAwaitDiagnosticsInfo ( ) {
4
45
let requestFired = false ;
5
46
cy . intercept (
6
47
'POST' ,
7
- ' /ops/accordion_select?id=diagnostics_accord' ,
48
+ ` /ops/accordion_select?id=${ diagnosticsAccordionItemId } ` ,
8
49
( ) => ( requestFired = true )
9
50
) . as ( 'getDiagnosticsInfo' ) ;
10
- cy . accordion ( 'Diagnostics' ) ;
51
+ cy . accordion ( diagnosticsAccordionItem ) ;
11
52
cy . then ( ( ) => {
12
53
// If the request was fired, wait for the alias
13
54
if ( requestFired ) {
@@ -36,44 +77,42 @@ function interceptAndAwaitApi({
36
77
cy . wait ( `@${ alias } ` ) ;
37
78
}
38
79
39
- function invokeAndAwaitRegionInfo ( {
40
- currentApiIntercepts,
41
- } ) {
80
+ function invokeAndAwaitRegionInfo ( { currentApiIntercepts } ) {
42
81
interceptAndAwaitApi ( {
43
82
alias : 'getRegionInfo' ,
44
83
urlPattern : / o p s \/ t r e e _ s e l e c t \? i d = .* & t e x t = .* M a n a g e I Q .* R e g i o n .* R e g i o n .* / ,
45
84
triggerFn : ( ) =>
46
- cy . accordionItem ( 'ManageIQ Region:' , true , 'diagnostics_accord' ) ,
85
+ cy . accordionItem (
86
+ manageIQRegionAccordItem ,
87
+ true ,
88
+ diagnosticsAccordionItemId
89
+ ) ,
47
90
currentApiIntercepts,
48
91
} ) ;
49
92
}
50
93
51
- function invokeAndAwaitZoneDefaultInfo ( {
52
- currentApiIntercepts,
53
- } ) {
94
+ function invokeAndAwaitZoneDefaultInfo ( { currentApiIntercepts } ) {
54
95
interceptAndAwaitApi ( {
55
96
alias : 'getZoneDefaultInfo' ,
56
97
urlPattern :
57
98
/ o p s \/ t r e e _ s e l e c t \? i d = .* & t e x t = .* Z o n e .* D e f a u l t .* Z o n e .* ( c u r r e n t ) .* / ,
58
- triggerFn : ( ) => cy . accordionItem ( 'Zone:' , true , 'diagnostics_accord' ) ,
99
+ triggerFn : ( ) =>
100
+ cy . accordionItem ( zoneAccordItem , true , diagnosticsAccordionItemId ) ,
59
101
currentApiIntercepts,
60
102
} ) ;
61
103
}
62
104
63
- function invokeAndAwaitServerInfo ( {
64
- currentApiIntercepts,
65
- } ) {
105
+ function invokeAndAwaitServerInfo ( { currentApiIntercepts } ) {
66
106
interceptAndAwaitApi ( {
67
107
alias : 'getServerInfo' ,
68
108
urlPattern : / o p s \/ t r e e _ s e l e c t \? i d = .* & t e x t = .* S e r v e r .* E V M .* ( c u r r e n t ) .* / ,
69
- triggerFn : ( ) => cy . accordionItem ( 'Server:' , true , 'diagnostics_accord' ) ,
109
+ triggerFn : ( ) =>
110
+ cy . accordionItem ( serverAccordItem , true , diagnosticsAccordionItemId ) ,
70
111
currentApiIntercepts,
71
112
} ) ;
72
113
}
73
114
74
- function invokeAndAwaitCollectLogsTabInfo ( {
75
- currentApiIntercepts,
76
- } ) {
115
+ function invokeAndAwaitCollectLogsTabInfo ( { currentApiIntercepts } ) {
77
116
interceptAndAwaitApi ( {
78
117
alias : 'getCollectLogsTabInfo' ,
79
118
urlPattern : '/ops/change_tab?tab_id=diagnostics_collect_logs' ,
@@ -87,9 +126,7 @@ function invokeAndAwaitCollectLogsTabInfo({
87
126
} ) ;
88
127
}
89
128
90
- function invokeAndAwaitEditEventForServer ( {
91
- currentApiIntercepts,
92
- } ) {
129
+ function invokeAndAwaitEditEventForServer ( { currentApiIntercepts } ) {
93
130
interceptAndAwaitApi ( {
94
131
alias : 'editEventForServer' ,
95
132
urlPattern : / \/ o p s \/ x _ b u t t o n \/ [ ^ / ] + \? p r e s s e d = .* l o g _ d e p o t _ e d i t / , // matches both /ops/x_button/1?pressed=log_depot_edit & /ops/x_button/2?pressed=zone_log_depot_edit endpoints
@@ -129,10 +166,10 @@ function resetProtocolDropdown({
129
166
( $select ) => {
130
167
const currentValue = $select . val ( ) ;
131
168
// If the value is not default one(BLANK_VALUE), then setting it to blank
132
- if ( currentValue !== 'BLANK_VALUE' ) {
133
- cy . wrap ( $select ) . select ( 'BLANK_VALUE' ) ;
169
+ if ( currentValue !== dropdownBlankValue ) {
170
+ cy . wrap ( $select ) . select ( dropdownBlankValue ) ;
134
171
cy . get ( '#diagnostics_collect_logs .bx--btn-set button[type="Submit"]' )
135
- . contains ( 'Save' )
172
+ . contains ( saveButton )
136
173
. click ( ) ;
137
174
cy . get ( '#main_div #flash_msg_div .alert-success' ) . contains (
138
175
'Log Depot Settings were saved'
@@ -145,7 +182,7 @@ function resetProtocolDropdown({
145
182
function cancelButtonValidation ( ) {
146
183
// Click cancel button in the form
147
184
cy . get ( '#diagnostics_collect_logs .bx--btn-set button[type="button"]' )
148
- . contains ( 'Cancel' )
185
+ . contains ( cancelButton )
149
186
. should ( 'be.enabled' )
150
187
. click ( ) ;
151
188
// Validating confirmation alert text displayed
@@ -157,36 +194,36 @@ function cancelButtonValidation() {
157
194
function resetButtonValidation ( ) {
158
195
// Confirm Reset button is disabled initially
159
196
cy . get ( '#diagnostics_collect_logs .bx--btn-set button[type="button"]' )
160
- . contains ( 'Reset' )
197
+ . contains ( resetButton )
161
198
. should ( 'be.disabled' ) ;
162
199
// Selecting Samba option from dropdown
163
200
cy . get ( '#log-depot-settings .bx--select select#log_protocol' ) . select (
164
- 'FileDepotSmb'
201
+ sambaDropdownValue
165
202
) ;
166
203
// Confirm Reset button is enabled once dropdown value is changed and then click on Reset
167
204
cy . get ( '#diagnostics_collect_logs .bx--btn-set button[type="button"]' )
168
- . contains ( 'Reset' )
205
+ . contains ( resetButton )
169
206
. should ( 'be.enabled' )
170
207
. click ( ) ;
171
208
// Confirm dropdown has the old value
172
209
cy . get ( '#log-depot-settings .bx--select select#log_protocol' ) . should (
173
210
'have.value' ,
174
- 'BLANK_VALUE'
211
+ dropdownBlankValue
175
212
) ;
176
213
}
177
214
178
215
function saveButtonValidation ( ) {
179
216
// Confirm Save button is disabled initially
180
217
cy . get ( '#diagnostics_collect_logs .bx--btn-set button[type="Submit"]' )
181
- . contains ( 'Save' )
218
+ . contains ( saveButton )
182
219
. should ( 'be.disabled' ) ;
183
220
// Selecting Samba option from dropdown
184
221
cy . get ( '#log-depot-settings .bx--select select#log_protocol' ) . select (
185
- 'FileDepotSmb'
222
+ sambaDropdownValue
186
223
) ;
187
224
// Confirm Save button is enabled once dropdown value is changed and then click on Save
188
225
cy . get ( '#diagnostics_collect_logs .bx--btn-set button[type="Submit"]' )
189
- . contains ( 'Save' )
226
+ . contains ( saveButton )
190
227
. should ( 'be.enabled' )
191
228
. click ( ) ;
192
229
// Validating confirmation alert text displayed
@@ -205,7 +242,7 @@ describe('Automate Collect logs Edit form operations', () => {
205
242
registeredApiIntercepts = { } ;
206
243
cy . login ( ) ;
207
244
// Navigate to Application settings and Select Diagnostics
208
- cy . menu ( 'Settings' , 'Application Settings' ) ;
245
+ cy . menu ( settingsMenuOption , appSettingsMenuOption ) ;
209
246
invokeAndAwaitDiagnosticsInfo ( ) ;
210
247
// Open ManageIQ Region: - list view if not already open
211
248
invokeAndAwaitRegionInfo ( { currentApiIntercepts : registeredApiIntercepts } ) ;
@@ -247,13 +284,13 @@ describe('Automate Collect logs Edit form operations', () => {
247
284
after ( ( ) => {
248
285
cy ?. url ( ) ?. then ( ( url ) => {
249
286
// Ensures navigation to Settings -> Application-Settings in the UI
250
- if ( url ?. includes ( '/ops/explorer' ) ) {
287
+ if ( url ?. includes ( componentRouteUrl ) ) {
251
288
resetProtocolDropdown ( {
252
289
currentApiIntercepts : registeredApiIntercepts ,
253
290
} ) ;
254
291
} else {
255
292
// Navigate to Settings -> Application-Settings before selecting Diagnostics
256
- cy . menu ( 'Settings' , 'Application Settings' ) ;
293
+ cy . menu ( settingsMenuOption , appSettingsMenuOption ) ;
257
294
resetProtocolDropdown ( {
258
295
currentApiIntercepts : registeredApiIntercepts ,
259
296
} ) ;
@@ -293,14 +330,14 @@ describe('Automate Collect logs Edit form operations', () => {
293
330
after ( ( ) => {
294
331
cy ?. url ( ) ?. then ( ( url ) => {
295
332
// Ensures navigation to Settings -> Application-Settings in the UI
296
- if ( url ?. includes ( '/ops/explorer' ) ) {
333
+ if ( url ?. includes ( componentRouteUrl ) ) {
297
334
resetProtocolDropdown ( {
298
335
currentApiIntercepts : registeredApiIntercepts ,
299
336
needsServerInfoFetch : false ,
300
337
} ) ;
301
338
} else {
302
339
// Navigate to Settings -> Application-Settings before selecting Diagnostics
303
- cy . menu ( 'Settings' , 'Application Settings' ) ;
340
+ cy . menu ( settingsMenuOption , appSettingsMenuOption ) ;
304
341
resetProtocolDropdown ( {
305
342
currentApiIntercepts : registeredApiIntercepts ,
306
343
needsServerInfoFetch : false ,
0 commit comments