55
66import { BASE_PATH , TIMEOUT } from '../../../utils/constants' ;
77
8+ const REPORT_DEFINITION_API = '**/api/reporting/reportDefinitions/**' ;
9+
10+ const setupEditIntercepts = ( ) => {
11+ cy . intercept ( 'GET' , REPORT_DEFINITION_API ) . as ( 'getReportDefinition' ) ;
12+
13+ cy . intercept ( 'PUT' , REPORT_DEFINITION_API , ( req ) => {
14+ req . headers [ 'origin' ] = BASE_PATH ;
15+ if (
16+ req . body &&
17+ req . body . report_params &&
18+ req . body . report_params . core_params
19+ ) {
20+ req . body . report_params . core_params . origin = BASE_PATH ;
21+ }
22+ } ) . as ( 'updateReportDefinition' ) ;
23+ } ;
24+
25+ const openEditPage = ( ) => {
26+ cy . get ( '#reportDefinitionDetailsLink' ) . first ( ) . click ( { force : true } ) ;
27+
28+ cy . get ( '#editReportDefinitionButton' , { timeout : TIMEOUT } ) . should ( 'exist' ) ;
29+ cy . get ( '#editReportDefinitionButton' ) . click ( ) ;
30+
31+ cy . url ( ) . should ( 'include' , 'edit' ) ;
32+
33+ cy . wait ( '@getReportDefinition' , { timeout : TIMEOUT } ) ;
34+
35+ cy . get ( '#reportSettingsName' , { timeout : TIMEOUT } )
36+ . should ( 'exist' )
37+ . and ( ( $el ) => {
38+ expect ( $el . val ( ) ) . to . not . equal ( '' ) ;
39+ } ) ;
40+ } ;
41+
42+ const clickSaveChanges = ( ) => {
43+ cy . get ( '#editReportDefinitionButton' )
44+ . contains ( 'Save Changes' )
45+ . trigger ( 'mouseover' )
46+ . click ( { force : true } ) ;
47+
48+ cy . wait ( '@updateReportDefinition' , { timeout : TIMEOUT } )
49+ . its ( 'response.statusCode' )
50+ . should ( 'eq' , 200 ) ;
51+
52+ // check that re-direct to home page
53+ cy . get ( '#reportDefinitionDetailsLink' , { timeout : TIMEOUT } ) . should ( 'exist' ) ;
54+ } ;
55+
856describe ( 'Cypress' , ( ) => {
957 beforeEach ( ( ) => {
58+ setupEditIntercepts ( ) ;
59+
1060 // Wait before visiting to allow index refresh after previous test's save
1161 cy . wait ( 5000 ) ;
1262 cy . visit ( `${ BASE_PATH } /app/reports-dashboards#/` , {
@@ -29,12 +79,7 @@ describe('Cypress', () => {
2979 } ) ;
3080
3181 it ( 'Visit edit page, update name and description' , ( ) => {
32- cy . get ( '#reportDefinitionDetailsLink' ) . first ( ) . click ( { force : true } ) ;
33-
34- cy . get ( '#editReportDefinitionButton' ) . should ( 'exist' ) ;
35- cy . get ( '#editReportDefinitionButton' ) . click ( ) ;
36-
37- cy . url ( ) . should ( 'include' , 'edit' ) ;
82+ openEditPage ( ) ;
3883
3984 // update the report name
4085 cy . get ( '#reportSettingsName' ) . type ( '{selectall}{backspace} update name' ) ;
@@ -44,61 +89,30 @@ describe('Cypress', () => {
4489 '{selectall}{backspace} update description'
4590 ) ;
4691
47- cy . get ( '#editReportDefinitionButton' )
48- . contains ( 'Save Changes' )
49- . trigger ( 'mouseover' )
50- . click ( { force : true } ) ;
51-
52- // check that re-direct to home page
53- cy . get ( '#reportDefinitionDetailsLink' , { timeout : TIMEOUT } ) . should (
54- 'exist'
55- ) ;
92+ clickSaveChanges ( ) ;
5693 } ) ;
5794
5895 it ( 'Visit edit page, change report trigger' , ( ) => {
59- cy . get ( '#reportDefinitionDetailsLink' ) . first ( ) . click ( ) ;
60-
61- cy . get ( '#editReportDefinitionButton' ) . should ( 'exist' ) ;
62- cy . get ( '#editReportDefinitionButton' ) . click ( ) ;
63-
64- cy . url ( ) . should ( 'include' , 'edit' ) ;
96+ openEditPage ( ) ;
6597
6698 cy . get ( '#reportDefinitionTriggerTypes > div:nth-child(2)' ) . click ( {
6799 force : true ,
68100 } ) ;
69101
70- cy . get ( '#Schedule' ) . check ( { force : true } ) ;
71- cy . get ( '#editReportDefinitionButton' )
72- . contains ( 'Save Changes' )
73- . trigger ( 'mouseover' )
74- . click ( { force : true } ) ;
102+ cy . get ( '#Schedule' ) . check ( { force : true } ) . should ( 'be.checked' ) ;
75103
76- // check that re-direct to home page
77- cy . get ( '#reportDefinitionDetailsLink' , { timeout : TIMEOUT } ) . should (
78- 'exist'
79- ) ;
104+ clickSaveChanges ( ) ;
80105 } ) ;
81106
82107 it ( 'Visit edit page, change report trigger back' , ( ) => {
83- cy . get ( '#reportDefinitionDetailsLink' ) . first ( ) . click ( ) ;
84-
85- cy . get ( '#editReportDefinitionButton' ) . should ( 'exist' ) ;
86- cy . get ( '#editReportDefinitionButton' ) . click ( ) ;
87-
88- cy . url ( ) . should ( 'include' , 'edit' ) ;
108+ openEditPage ( ) ;
89109
90110 cy . get ( '#reportDefinitionTriggerTypes > div:nth-child(1)' ) . click ( {
91111 force : true ,
92112 } ) ;
93113
94- cy . get ( '#editReportDefinitionButton' )
95- . contains ( 'Save Changes' )
96- . trigger ( 'mouseover' )
97- . click ( { force : true } ) ;
114+ cy . get ( '#On\\ demand' ) . check ( { force : true } ) . should ( 'be.checked' ) ;
98115
99- // check that re-direct to home page
100- cy . get ( '#reportDefinitionDetailsLink' , { timeout : TIMEOUT } ) . should (
101- 'exist'
102- ) ;
116+ clickSaveChanges ( ) ;
103117 } ) ;
104118} ) ;
0 commit comments