@@ -3,6 +3,30 @@ import CheckmkSelectors from '../support/checkmk_selectors';
33import '../support/commands' ;
44import { LabelVariableNames } from '../types' ;
55
6+ enum FilterTypes {
7+ HOSTNAME = 'Hostname' ,
8+ HOSTNAME_REGEX = 'Hostname regex' ,
9+ HOST_LABELS = 'Host labels' ,
10+ SERVICE = 'Service' ,
11+ SERVICE_REGEX = 'Service regex' ,
12+ }
13+
14+ enum Services {
15+ CHECK_MK = 'Check_MK' ,
16+ CPU_REGEX = 'CPU' ,
17+ MEMORY_REGEX = 'Memory' ,
18+ }
19+
20+ enum GraphTypes {
21+ TIME_BY_PHASE = 'Time usage by phase' ,
22+ RAM_USED = 'RAM used' ,
23+ UPTIME = 'Uptime' ,
24+ }
25+
26+ enum Sites {
27+ ALL_SITES = 'All Sites' ,
28+ }
29+
630describe ( 'e2e tests' , ( ) => {
731 const cmkUser = 'cmkuser' ;
832 const cmkPassword = 'somepassword123457' ;
@@ -13,20 +37,11 @@ describe('e2e tests', () => {
1337 const CmkCEE = 'Commercial editions' ;
1438 const CmkCRE = 'Raw Edition' ;
1539
16- const inputDatasourceId = 'data-source-picker' ;
17- const inputFilterId = CheckmkSelectors . AddDashboard . filterFieldId ;
1840 const inputGraphId = 'input_Predefined_graph' ;
1941 const inputGraphTypeId = 'input_Graph_type' ;
20- const inputHostId = 'input_Hostname' ;
2142 const inputMetricId = 'input_Single_metric' ;
22- const inputServiceId = 'input_Service' ;
23- const inputSiteId = 'input_Site' ;
2443 const inputHostLabelId = CheckmkSelectors . AddDashboard . hostLabelFieldId ;
2544 const inputCustomLabelSelector = 'input[data-test-id="custom-label-field"]' ;
26- const refreshQueryButtonSelector = 'button[data-test-id="data-testid RefreshPicker run button"]' ;
27-
28- const inputHostRegexDataTestId = 'host_name_regex-filter-input' ;
29- const inputServiceRegexDataTestId = 'service_regex-filter-input' ;
3045
3146 const queryEditorSelector = '[class="query-editor-row"]' ;
3247
@@ -93,19 +108,13 @@ describe('e2e tests', () => {
93108 it ( 'time-usage panel by service (single host)' , { } , ( ) => {
94109 cy . selectDataSource ( CmkCEE ) ;
95110
96- cy . contains ( 'Checkmk ' + CmkCEE ) . should ( 'be.visible' ) ; // Assert Cmk CEE datasource is used
97-
98- cy . inputLocatorById ( inputFilterId ) . type ( 'Hostname{enter}' ) ; // Filter -> 'Host name'
99- cy . inputLocatorById ( inputFilterId ) . type ( 'Service{enter}' ) ; // Filter -> 'Service'
111+ cy . addFilter ( FilterTypes . HOSTNAME ) ;
112+ cy . filterByHostname ( hostName0 ) ;
100113
101- cy . inputLocatorById ( inputHostId ) . type ( '{enter}' ) ; // Hostname -> hostName0 (first entry)
102- cy . contains ( hostName0 ) . should ( 'exist' ) ;
114+ cy . addFilter ( FilterTypes . SERVICE ) ;
115+ cy . filterByService ( Services . CHECK_MK ) ;
103116
104- cy . inputLocatorById ( inputServiceId ) . type ( '{enter}' ) ; // Service -> 'Check_MK' (first entry)
105- cy . contains ( 'Check_MK' ) . should ( 'exist' ) ;
106-
107- cy . inputLocatorById ( inputGraphId ) . type ( '{enter}' ) ; // Predefined graph -> 'Time usage by phase' (one entry)
108- cy . contains ( 'Time usage by phase' ) . should ( 'exist' ) ;
117+ cy . selectPredefinedGraphType ( GraphTypes . TIME_BY_PHASE ) ;
109118
110119 cy . assertLegendElement ( 'CPU time in user space' ) ;
111120 cy . assertLegendElement ( 'CPU time in operating system' ) ;
@@ -119,7 +128,7 @@ describe('e2e tests', () => {
119128 cy . get ( queryEditorSelector ) . contains ( 'Type to trigger search' ) . should ( 'not.exist' ) ;
120129 cy . get ( queryEditorSelector ) . find ( 'button' ) . eq ( 0 ) . click ( ) ; // Remove filter by hostname
121130 cy . get ( queryEditorSelector ) . find ( 'button' ) . eq ( 0 ) . click ( ) ; // Remove filter by service
122- cy . inputLocatorById ( inputFilterId ) . type ( 'Service{enter}' ) ; // Filter -> 'Service'
131+ cy . addFilter ( FilterTypes . SERVICE ) ;
123132
124133 // Assert the filter is not set
125134 cy . get ( queryEditorSelector ) . contains ( 'Type to trigger search' ) . should ( 'exist' ) ;
@@ -128,22 +137,18 @@ describe('e2e tests', () => {
128137 it ( 'time-usage panel by service (multiple hosts)' , { } , ( ) => {
129138 cy . selectDataSource ( CmkCEE ) ;
130139
131- cy . contains ( 'Checkmk ' + CmkCEE ) . should ( 'be.visible' ) ; // Assert Cmk CEE datasource is used
132- cy . inputLocatorById ( inputFilterId ) . type ( 'Service{enter}' ) ; // Filter -> 'Service'
133-
134- cy . inputLocatorById ( inputServiceId ) . type ( '{enter}' ) ; // Service -> 'Check_MK' (first entry)
135- cy . contains ( 'Check_MK' ) . should ( 'exist' ) ;
140+ cy . addFilter ( FilterTypes . SERVICE ) ;
141+ cy . filterByService ( Services . CHECK_MK ) ;
136142
137- cy . inputLocatorById ( inputFilterId ) . type ( 'regex{enter}' ) ; // Filter -> 'Hostname regex'
138- cy . get ( 'input[data-test-id="host_name_regex-filter-input"]' ) . type ( ' localhost_grafana[0-9]+{enter}' ) ;
143+ cy . addFilter ( FilterTypes . HOSTNAME_REGEX ) ;
144+ cy . filterByHostnameRegex ( ' localhost_grafana[0-9]+' ) . wait ( 1000 ) ;
139145
140- cy . inputLocatorById ( inputGraphId ) . click ( ) ;
146+ cy . inputLocatorById ( CheckmkSelectors . AddDashboard . predefinedGraphFieldId ) . click ( ) ;
141147 cy . get ( '[class="scrollbar-view"]' )
142148 . children ( )
143149 . its ( 'length' )
144150 . then ( ( $dropdownLength ) => {
145- cy . inputLocatorById ( inputGraphId ) . type ( '{enter}' ) ; // Predefined graph -> 'Time usage by phase' (one entry)
146- cy . contains ( 'Time usage by phase' ) . should ( 'exist' ) ;
151+ cy . selectPredefinedGraphType ( GraphTypes . TIME_BY_PHASE ) ;
147152
148153 // assert legend elements (not all plots have a legend)
149154 cy . assertLegendElement ( 'CPU time in user space, ' + hostName0 ) ;
@@ -154,29 +159,24 @@ describe('e2e tests', () => {
154159 cy . assertHoverSelectorsOff ( 8 ) ;
155160 cy . assertHoverSelectorsOn ( 8 ) ;
156161
157- cy . get ( '[data-test-id="cmk-oac-minus-button-Service"]' ) . click ( ) ; // Remove filter by service
162+ cy . removeFilterByService ( ) ;
158163
159- cy . inputLocatorById ( inputFilterId ) . type ( 'Service regex{enter}' ) ; // Filter -> 'Service regex'
160- cy . contains ( 'Service regex' ) . should ( 'exist' ) ;
164+ cy . addFilter ( FilterTypes . SERVICE_REGEX ) ;
165+ cy . filterByServiceRegex ( Services . CPU_REGEX ) ;
161166
162- cy . inputLocatorByDataTestId ( inputServiceRegexDataTestId ) . type ( 'CPU{enter}' ) ; // Service regex -> 'CPU utilization (one entry only)'
163- cy . contains ( 'CPU' ) . should ( 'exist' ) ;
164167 cy . get ( '[class="scrollbar-view"]' ) . children ( ) . its ( 'length' ) . should ( 'be.gte' , $dropdownLength ) ;
165168 } ) ;
166169 } ) ;
167170
168171 it ( 'RAM-used panel by service regex (multiple hosts)' , { } , ( ) => {
169172 cy . selectDataSource ( CmkCEE ) ;
170- cy . contains ( 'Checkmk ' + CmkCEE ) . should ( 'be.visible' ) ; // Assert Cmk CEE datasource is used
171- cy . inputLocatorById ( inputFilterId ) . type ( 'Service regex{enter}' ) ; // Filter -> 'Service'
172- cy . contains ( 'Service regex' ) . should ( 'exist' ) ;
173173
174- cy . inputLocatorByDataTestId ( inputServiceRegexDataTestId ) . type ( 'Memory{enter}' ) ; // Service regex -> 'Memory'
175- cy . get ( 'input[value="Memory"]' ) . should ( 'exist' ) ;
174+ cy . addFilter ( FilterTypes . SERVICE_REGEX ) ;
175+ cy . filterByServiceRegex ( Services . MEMORY_REGEX ) ;
176176 cy . expectSpinners ( ) ;
177177
178- cy . inputLocatorById ( inputGraphId ) . click ( ) ; // Predefined graph -> 'RAM used'
179- cy . get ( '[aria-label="Select options menu"]' ) . contains ( 'RAM used' ) . click ( ) ;
178+ cy . selectPredefinedGraphType ( GraphTypes . RAM_USED ) ;
179+
180180 cy . contains ( / ^ R A M u s e d $ / ) . should ( 'exist' ) ;
181181
182182 cy . assertLegendElement ( hostName0 ) ;
@@ -188,9 +188,8 @@ describe('e2e tests', () => {
188188
189189 it ( 'RAM-used panel by host labels (multiple hosts, single metric)' , { } , ( ) => {
190190 cy . selectDataSource ( CmkCEE ) ;
191- cy . contains ( 'Checkmk ' + CmkCEE ) . should ( 'be.visible' ) ; // Assert Cmk CEE datasource is used
192- cy . inputLocatorById ( inputFilterId ) . type ( 'Host labels{enter}' ) ; // Filter -> 'Host labels'
193- cy . contains ( 'Host labels' ) . should ( 'exist' ) ;
191+
192+ cy . addFilter ( FilterTypes . HOST_LABELS ) ;
194193
195194 cy . inputLocatorById ( inputHostLabelId ) . type ( 'cmk/site:cm' ) ; // Host labels -> 'cmk/site:cm' (one entry)
196195 // TODO: should only contain a single lable, but shows all?
@@ -216,16 +215,12 @@ describe('e2e tests', () => {
216215
217216 it ( 'RAM-used panel by service regex and hostname regex' , { } , ( ) => {
218217 cy . selectDataSource ( CmkCEE ) ;
219- cy . contains ( 'Checkmk ' + CmkCEE ) . should ( 'be.visible' ) ; // Assert Cmk CEE datasource is used
220- cy . inputLocatorById ( inputFilterId ) . type ( 'Service regex{enter}' ) ; // Filter -> 'Service'
221- cy . contains ( 'Service regex' ) . should ( 'exist' ) ;
222218
223- cy . inputLocatorByDataTestId ( inputServiceRegexDataTestId ) . type ( 'Memory{enter}' ) ; // Service regex -> 'Memory'
224- cy . get ( 'input[value="Memory"]' ) . should ( 'exist' ) ;
219+ cy . addFilter ( FilterTypes . SERVICE_REGEX ) ;
220+ cy . filterByServiceRegex ( Services . MEMORY_REGEX ) ;
225221 cy . expectSpinners ( ) ;
226222
227- cy . inputLocatorById ( inputGraphId ) . click ( ) ; // Predefined graph -> 'RAM used'
228- cy . get ( '[aria-label="Select options menu"]' ) . contains ( 'RAM used' ) . click ( ) ;
223+ cy . selectPredefinedGraphType ( GraphTypes . RAM_USED ) ;
229224 cy . contains ( / ^ R A M u s e d $ / ) . should ( 'exist' ) ;
230225
231226 cy . assertLegendElement ( hostName0 ) ;
@@ -234,20 +229,16 @@ describe('e2e tests', () => {
234229 cy . assertHoverSelectorsOff ( 2 ) ;
235230 cy . assertHoverSelectorsOn ( 2 ) ;
236231
237- cy . inputLocatorById ( inputFilterId ) . type ( 'Hostname regex{enter}' ) ; // Filter -> 'Hostname regex'
238- cy . contains ( 'Hostname regex' ) . should ( 'exist' ) ;
239-
240- cy . inputLocatorByDataTestId ( inputHostRegexDataTestId ) . type ( hostName0 + '{enter}' ) ; // Hostname regex -> {hostname0}
241- cy . get ( 'input[value="' + hostName0 + '"]' ) . should ( 'exist' ) ;
232+ cy . addFilter ( FilterTypes . HOSTNAME_REGEX ) ;
233+ cy . filterByHostnameRegex ( hostName0 ) ;
242234
243235 // assert legend elements (expecting a change in the panel)
244236 cy . assertLegendElement ( 'RAM used' ) ;
245237
246238 cy . assertHoverSelectorsOff ( 1 ) ;
247239 cy . assertHoverSelectorsOn ( 1 ) ;
248240
249- cy . inputLocatorByDataTestId ( inputHostRegexDataTestId ) . type ( '|' + hostName1 + '{enter}' ) ; // Hostname regex -> '{hostname0}|{hostname1}'
250- cy . get ( 'input[value="' + hostName0 + '|' + hostName1 + '"]' ) . should ( 'exist' ) ;
241+ cy . filterByHostnameRegex ( hostName0 + '|' + hostName1 ) ;
251242
252243 // assert legend elements (expecting a change in the panel)
253244 cy . assertLegendElement ( hostName0 ) ;
@@ -259,14 +250,12 @@ describe('e2e tests', () => {
259250
260251 it ( 'Uptime panel by hostname' , { } , ( ) => {
261252 cy . selectDataSource ( CmkCEE ) ;
262- cy . contains ( 'Checkmk ' + CmkCEE ) . should ( 'be.visible' ) ; // Assert Cmk CEE datasource is used
263- cy . inputLocatorById ( inputFilterId ) . type ( 'Hostname{enter}' ) ; // Filter -> 'Host name'
264253
265- cy . inputLocatorById ( inputHostId ) . type ( '{enter}' ) ; // Hostname -> hostName0 (first entry)
266- cy . contains ( hostName0 ) . should ( 'exist' ) ;
254+ cy . addFilter ( FilterTypes . HOSTNAME ) ;
255+ cy . filterByHostname ( hostName0 ) ;
267256
268- cy . inputLocatorById ( inputGraphId ) . type ( 'Uptime{enter}' ) ; // Predefined graph -> 'Uptime' (no entry expected)
269- cy . contains ( 'No options found' ) . should ( 'exist' ) ;
257+ // Predefined graph -> 'Uptime' (no entry expected)
258+ cy . selectNonExistentPredefinedGraphType ( GraphTypes . UPTIME ) ;
270259 cy . get ( 'body' ) . click ( ) ;
271260
272261 cy . inputLocatorById ( inputGraphTypeId ) . click ( ) ;
@@ -285,16 +274,12 @@ describe('e2e tests', () => {
285274 it ( 'Custom labels' , { } , ( ) => {
286275 cy . selectDataSource ( CmkCEE ) ;
287276
288- cy . contains ( 'Checkmk ' + CmkCEE ) . should ( 'be.visible' ) ; // Assert Cmk CEE datasource is used
277+ cy . addFilter ( FilterTypes . HOSTNAME ) ;
278+ cy . filterByHostname ( hostName0 ) ;
289279
290- cy . inputLocatorById ( inputFilterId ) . type ( 'Hostname' ) . type ( '{enter}' ) ; // Filter -> 'Host name'
291- cy . inputLocatorById ( inputHostId ) . type ( hostName0 ) . type ( '{enter}' ) ; // Hostname -> hostName0
292- cy . contains ( hostName0 ) . should ( 'exist' ) ;
293280 cy . contains ( 'Predefined graph' ) . should ( 'exist' ) ;
294281
295- cy . get ( `#${ inputGraphId } ` ) . type ( 'time usage by phase' ) . wait ( 2000 ) . type ( '{enter}' ) ; // Predefined graph -> 'Time usage by phase' (one entry)
296- cy . contains ( 'Time usage by phase' ) . should ( 'exist' ) ;
297- cy . wait ( 2000 ) ;
282+ cy . selectPredefinedGraphType ( GraphTypes . TIME_BY_PHASE ) ;
298283 cy . assertLegendElement ( `CPU time in user space` ) ;
299284
300285 //Label $label
@@ -318,22 +303,14 @@ describe('e2e tests', () => {
318303 } ) ;
319304 describe ( 'CRE tests' , ( ) => {
320305 it ( 'time-usage panel by service (single host)' , { } , ( ) => {
321- cy . selectDataSource ( CmkCRE ) ;
322-
323306 cy . passOnException ( 'ResizeObserver loop limit exceeded' ) ;
324- cy . inputLocatorById ( inputDatasourceId ) . type ( 'Checkmk ' + CmkCRE + '{enter}' ) ;
325- cy . contains ( 'Checkmk ' + CmkCRE ) . should ( 'be.visible' ) ;
326-
327- cy . inputLocatorById ( inputSiteId ) . type ( '{enter}' ) ; // Site -> All Sites (first entry)
328-
329- cy . inputLocatorById ( inputHostId ) . type ( '{enter}' ) ; // Hostname -> hostName0 (first entry)
330- cy . contains ( hostName0 ) . should ( 'exist' ) ;
307+ cy . selectDataSource ( CmkCRE ) ;
331308
332- cy . inputLocatorById ( inputServiceId ) . type ( '{enter}' ) ; // Service -> 'Check_MK' (first entry)
333- cy . contains ( 'Check_MK' ) . should ( 'exist' ) ;
309+ cy . filterBySite ( Sites . ALL_SITES ) ;
310+ cy . filterByHostname ( hostName0 ) ;
311+ cy . filterByService ( Services . CHECK_MK ) ;
334312
335- cy . inputLocatorById ( inputGraphId ) . type ( '{enter}' ) ; // Predefined graph -> 'Time usage by phase' (one entry)
336- cy . contains ( 'Time usage by phase' ) . should ( 'exist' ) ;
313+ cy . selectPredefinedGraphType ( GraphTypes . TIME_BY_PHASE ) ;
337314
338315 cy . assertLegendElement ( 'CPU time in user space' ) ;
339316 cy . assertLegendElement ( 'CPU time in operating system' ) ;
@@ -345,31 +322,18 @@ describe('e2e tests', () => {
345322
346323 cy . contains ( "Could not find 'cmk_cpu_time_by_phase'" ) . should ( 'not.exist' ) ;
347324
348- cy . inputLocatorById ( inputServiceId ) . click ( ) ; // Service -> 'Memory'
349- cy . contains ( 'Memory' ) . click ( ) ;
350- cy . contains ( 'Memory' ) . should ( 'exist' ) ;
325+ cy . filterByService ( Services . MEMORY_REGEX ) ;
351326
352327 cy . contains ( "Could not find 'cmk_cpu_time_by_phase'" ) . should ( 'be.visible' ) ; // Assert previous graph input not visible
353328 } ) ;
354329 it ( 'Used-RAM panel by service (single host)' , { } , ( ) => {
355- cy . selectDataSource ( CmkCRE ) ;
356-
357330 cy . passOnException ( 'ResizeObserver loop limit exceeded' ) ;
358- cy . inputLocatorById ( inputDatasourceId ) . type ( 'Checkmk ' + CmkCRE + '{enter}' ) ;
359- cy . contains ( 'Checkmk ' + CmkCRE ) . should ( 'be.visible' ) ;
360-
361- cy . inputLocatorById ( inputSiteId ) . type ( '{enter}' ) ; // Site -> All Sites (first entry)
362-
363- cy . inputLocatorById ( inputHostId ) . type ( '{enter}' ) ; // Hostname -> hostName0 (first entry)
364- cy . contains ( hostName0 ) . should ( 'exist' ) ;
365-
366- cy . inputLocatorById ( inputServiceId ) . click ( ) ; // Service -> 'Memory'
367- cy . contains ( 'Memory' ) . click ( ) ;
368- cy . contains ( 'Memory' ) . should ( 'exist' ) ;
331+ cy . selectDataSource ( CmkCRE ) ;
332+ cy . filterBySite ( Sites . ALL_SITES ) ;
333+ cy . filterByHostname ( hostName0 ) ;
334+ cy . filterByService ( Services . MEMORY_REGEX ) ;
369335
370- cy . inputLocatorById ( inputGraphId ) . click ( ) ; // Predefined graph -> 'Used RAM'
371- cy . contains ( 'Used RAM' ) . click ( ) ;
372- cy . contains ( 'Used RAM' ) . should ( 'exist' ) ;
336+ cy . selectPredefinedGraphType ( GraphTypes . RAM_USED ) ;
373337
374338 cy . assertLegendElement ( 'RAM used %' ) ; // TODO: Getting 'RAM used %'. Should the graph name match the metric?
375339
0 commit comments