import EditDashboardPage from "./EditDashboard" ; class EditMetricsPage { constructor ( ) { cy . contains ( "Edit metrics" ) ; } fillTitle ( title ) { cy . findByLabelText ( "Metrics title" ) . clear ( ) . type ( title ) ; } addNewMetric ( title , value ) { cy . intercept ( { method : "GET" , url : new RegExp ( /\/prod\/dashboard\/.+/ ) , } ) . as ( "viewDashboardRequest" ) ; cy . intercept ( { method : "GET" , url : new RegExp ( /\/prod\/dashboard\/.+\/widget\/.+/ ) , } ) . as ( "viewWidgetRequest" ) ; cy . intercept ( { method : "GET" , url : new RegExp ( /\/public\/(?!.*logo)(?!.*favicon).+/ ) , } ) . as ( "oldMetricRequest" ) ; cy . get ( "button" ) . contains ( "Add metric" ) . click ( ) ; cy . wait ( [ "@viewDashboardRequest" ] ) ; cy . findByLabelText ( "Metric title*" ) . type ( title ) ; cy . findByLabelText ( "Metric value*" ) . type ( value . toString ( ) ) ; cy . get ( "select#percentage" ) . select ( "Currency" ) ; cy . get ( "select#currency" ) . select ( "Dollar $" ) ; cy . findByLabelText ( "Change over time (optional)" ) . type ( "+10%" ) ; cy . get ( "button" ) . contains ( "Add metric" ) . click ( ) ; cy . wait ( [ "@viewDashboardRequest" , "@viewWidgetRequest" , "@oldMetricRequest" , ] ) ; } editMetric ( title , value ) { cy . intercept ( { method : "GET" , url : new RegExp ( /\/prod\/dashboard\/.+/ ) , } ) . as ( "viewDashboardRequest" ) ; cy . intercept ( { method : "GET" , url : new RegExp ( /\/prod\/dashboard\/.+\/widget\/.+/ ) , } ) . as ( "viewWidgetRequest" ) ; cy . intercept ( { method : "GET" , url : new RegExp ( /\/public\/(?!.*logo)(?!.*favicon).+/ ) , } ) . as ( "oldMetricRequest" ) ; cy . get ( "div.height-card" ) . contains ( title ) ; cy . get ( "button" ) . contains ( "Edit" ) . click ( ) ; cy . wait ( [ "@viewDashboardRequest" ] ) ; cy . findByLabelText ( "Metric value" ) . clear ( ) . type ( value . toString ( ) ) ; cy . get ( "button" ) . contains ( "Save" ) . click ( ) ; cy . wait ( [ "@viewDashboardRequest" , "@viewWidgetRequest" , "@oldMetricRequest" , ] ) ; } deleteMetric ( ) { cy . get ( "button" ) . contains ( "Delete" ) . click ( ) ; } verifyPreview ( title , value ) { cy . contains ( "Metric successfully added" ) ; cy . get ( "div.height-card" ) . contains ( title ) ; cy . get ( "div.height-card" ) . contains ( "$" . concat ( value . toString ( ) ) ) ; cy . get ( "div.height-card" ) . contains ( "10%" ) ; } submit ( ) { cy . intercept ( { method : "PUT" , url : new RegExp ( /\/public\/.+/ ) , } ) . as ( "updateMetricRequest" ) ; cy . intercept ( { method : "PUT" , url : new RegExp ( /\/prod\/dashboard\/.+\/widget/ ) , } ) . as ( "updateWidgetRequest" ) ; cy . intercept ( { method : "GET" , url : new RegExp ( /\/prod\/dashboard\/.+/ ) , } ) . as ( "viewDashboardRequest" ) ; cy . intercept ( { method : "GET" , url : new RegExp ( /\/prod\/dashboard\/.+\/versions/ ) , } ) . as ( "viewDashboardVersionsRequest" ) ; cy . get ( "button" ) . contains ( "Save" ) . click ( ) ; cy . wait ( [ "@updateMetricRequest" , "@updateWidgetRequest" , "@viewDashboardRequest" , "@viewDashboardVersionsRequest" , ] ) ; return new EditDashboardPage ( ) ; } } export default EditMetricsPage ;