import EditDashboardPage from "./EditDashboard" ; class AddMetricsPage { constructor ( ) { cy . contains ( "Add metrics" ) ; } selectCreateFromScratch ( ) { cy . findByLabelText ( "Create new" ) . check ( { force : true } ) ; cy . get ( "button" ) . contains ( "Continue" ) . click ( ) ; } fillTitle ( title ) { cy . findByLabelText ( "Metrics title*" ) . type ( title ) ; } addNewMetric ( title , value ) { cy . intercept ( { method : "GET" , url : new RegExp ( /\/prod\/dashboard\/.+/ ) , } ) . as ( "viewDashboardRequest" ) ; cy . intercept ( { method : "GET" , url : "/prod/dataset" , } ) . as ( "datasetRequest" ) ; 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" , "@datasetRequest" ] ) ; } 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 ( "addMetricRequest" ) ; cy . intercept ( { method : "POST" , url : new RegExp ( /\/prod\/dashboard\/.+\/widget/ ) , } ) . as ( "createWidgetRequest" ) ; 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 ( "Add metrics" ) . click ( ) ; cy . wait ( [ "@addMetricRequest" , "@createWidgetRequest" , "@viewDashboardRequest" , "@viewDashboardVersionsRequest" , ] ) ; return new EditDashboardPage ( ) ; } } export default AddMetricsPage ;