import * as Chance from "chance" ; import EditDashboardPage from "../pages/EditDashboard" ; import CreateDashboardPage from "../pages/CreateDashboard" ; import AddMetricsPage from "../pages/AddMetrics" ; import AddTextPage from "../pages/AddText" ; import AddChartPage from "../pages/AddChart" ; import AddTablePage from "../pages/AddTable" ; import LoginPage from "../pages/Login" ; import EditTextPage from "../pages/EditText" ; import EditMetricsPage from "../pages/EditMetrics" ; import EditChartPage from "../pages/EditChart" ; import EditTablePage from "../pages/EditTable" ; const random = new Chance ( ) ; let dashboardName ; let editDashboardPage ; describe ( "Admin user" , ( ) => { beforeEach ( ( ) => { const loginPage = new LoginPage ( ) ; loginPage . visit ( ) ; loginPage . loginAsAdmin ( ) ; const createDashboardPage = new CreateDashboardPage ( ) ; createDashboardPage . visit ( ) ; dashboardName = random . company ( ) ; createDashboardPage . fillName ( dashboardName ) ; createDashboardPage . fillDescription ( random . sentence ( ) ) ; editDashboardPage = createDashboardPage . submit ( ) ; cy . contains ( `"${ dashboardName }" draft dashboard successfully created.` ) ; } ) ; it ( "can add a Text content item to a dashboard" , ( ) => { const addContentItemPage = editDashboardPage . goToAddContentItem ( ) ; addContentItemPage . selectTextContentItem ( ) ; const addTextPage = addContentItemPage . clickContinue ( ) as AddTextPage ; cy . get ( "button" ) . contains ( "Add text" ) . click ( ) ; cy . contains ( "Resolve error(s) to add the text" ) ; cy . contains ( "Please specify a text title" ) ; cy . contains ( "Please specify text content" ) ; const textTitle = random . word ( ) ; addTextPage . fillTitle ( textTitle ) ; const textContent = random . paragraph ( ) ; addTextPage . fillTextContent ( textContent ) ; addTextPage . verifyPreview ( textTitle , textContent ) ; editDashboardPage = addTextPage . submit ( ) ; cy . contains ( `'${ textTitle }' text has been successfully added.` ) ; cy . get ( "div.grid-row" ) . contains ( textTitle ) ; const editTextPage = editDashboardPage . goToEditContentItem ( "Text" ) as EditTextPage ; const newTextTitle = random . word ( ) ; editTextPage . fillTitle ( newTextTitle ) ; const newTextContent = random . paragraph ( ) ; editTextPage . fillTextContent ( newTextContent ) ; editTextPage . verifyPreview ( newTextTitle , newTextContent ) ; editDashboardPage = editTextPage . submit ( ) ; cy . contains ( `'${ newTextTitle }' text has been successfully edited.` ) ; cy . get ( "div.grid-row" ) . contains ( newTextTitle ) ; editDashboardPage . copyContentItem ( ) ; cy . contains ( `Text '${ newTextTitle }' was successfully copied.` ) ; cy . get ( "div.grid-row" ) . contains ( "(Copy) " . concat ( newTextTitle ) ) ; editDashboardPage . deleteContentItem ( ) ; cy . contains ( `Text '${ newTextTitle }' was successfully deleted.` ) ; editDashboardPage . deleteContentItem ( ) ; cy . get ( "div.grid-row" ) . should ( "not.exist" ) ; const dashboardListingPage = editDashboardPage . goToDashboardListing ( ) ; dashboardListingPage . deleteDashboard ( dashboardName ) ; } ) ; it ( "can add a Metrics content item to a dashboard" , ( ) => { const addContentItemPage = editDashboardPage . goToAddContentItem ( ) ; addContentItemPage . selectMetricsContentItem ( ) ; const addMetricsPage = addContentItemPage . clickContinue ( ) as AddMetricsPage ; addMetricsPage . selectCreateFromScratch ( ) ; cy . get ( "button" ) . contains ( "Add metrics" ) . click ( ) ; cy . contains ( "Resolve error(s) to add the metrics" ) ; cy . contains ( "Please specify a content title" ) ; const metricsTitle = random . word ( ) ; addMetricsPage . fillTitle ( metricsTitle ) ; cy . get ( "button" ) . contains ( "Add metrics" ) . click ( ) ; cy . contains ( "Enter at least one metric to continue" ) ; const metricTitle = random . word ( ) ; const metricValue = random . integer ( { min : 100 , max : 500 } ) ; addMetricsPage . addNewMetric ( metricTitle , metricValue ) ; addMetricsPage . verifyPreview ( metricTitle , metricValue ) ; editDashboardPage = addMetricsPage . submit ( ) ; cy . contains ( `Metrics '${ metricsTitle }' have been successfully added` ) ; cy . get ( "div.grid-row" ) . contains ( metricsTitle ) ; const editMetricsPage = editDashboardPage . goToEditContentItem ( "Metrics" ) as EditMetricsPage ; const newMetricsTitle = random . word ( ) ; editMetricsPage . fillTitle ( newMetricsTitle ) ; const updatedMetricValue = random . integer ( { min : 100 , max : 500 } ) ; editMetricsPage . editMetric ( metricTitle , updatedMetricValue ) ; cy . contains ( "Metric successfully edited." ) ; editMetricsPage . deleteMetric ( ) ; const newMetricTitle = random . word ( ) ; const newMetricValue = random . integer ( { min : 100 , max : 500 } ) ; editMetricsPage . addNewMetric ( newMetricTitle , newMetricValue ) ; editMetricsPage . verifyPreview ( newMetricTitle , newMetricValue ) ; editDashboardPage = editMetricsPage . submit ( ) ; cy . contains ( `Metrics '${ newMetricsTitle }' have been successfully edited` ) ; cy . get ( "div.grid-row" ) . contains ( newMetricsTitle ) ; editDashboardPage . copyContentItem ( ) ; cy . contains ( `Metrics '${ newMetricsTitle }' was successfully copied.` ) ; cy . get ( "div.grid-row" ) . contains ( "(Copy) " . concat ( newMetricsTitle ) ) ; editDashboardPage . deleteContentItem ( ) ; cy . contains ( `Metrics '${ newMetricsTitle }' was successfully deleted.` ) ; editDashboardPage . deleteContentItem ( ) ; cy . get ( "div.grid-row" ) . should ( "not.exist" ) ; const dashboardListingPage = editDashboardPage . goToDashboardListing ( ) ; dashboardListingPage . deleteDashboard ( dashboardName ) ; } ) ; it ( "can add a Line Chart content item to a dashboard" , ( ) => { const addContentItemPage = editDashboardPage . goToAddContentItem ( ) ; addContentItemPage . selectChartContentItem ( ) ; const addChartPage = addContentItemPage . clickContinue ( ) as AddChartPage ; addChartPage . selectStaticDataset ( ) ; cy . findByLabelText ( "Static datasets" ) . attachFile ( "chart_missing_header.csv" ) ; cy . contains ( "Failed to upload file. Please make sure there are values for all column headers." ) ; addChartPage . uploadDataset ( "chart.csv" ) ; addChartPage . selectColumns ( ) ; const chartTitle = random . word ( ) ; addChartPage . fillTitle ( chartTitle ) ; const chartSummary = random . sentence ( ) ; addChartPage . fillSummary ( chartSummary ) ; addChartPage . verifyPreview ( chartTitle , chartSummary ) ; editDashboardPage = addChartPage . submit ( ) ; cy . contains ( `'${ chartTitle }' chart has been successfully added.` ) ; cy . get ( "div.grid-row" ) . contains ( chartTitle ) ; const editChartPage = editDashboardPage . goToEditContentItem ( "Chart" ) as EditChartPage ; editChartPage . uploadDataset ( "chart.csv" , "table.csv" ) ; editChartPage . selectColumns ( ) ; const newChartTitle = random . word ( ) ; const newChartSummary = random . sentence ( ) ; editChartPage . fillTitle ( newChartTitle ) ; editChartPage . fillSummary ( newChartSummary ) ; editChartPage . verifyPreview ( newChartTitle , newChartSummary ) ; editDashboardPage = editChartPage . submit ( false ) ; cy . contains ( `'${ newChartTitle }' chart has been successfully edited.` ) ; cy . get ( "div.grid-row" ) . contains ( newChartTitle ) ; editDashboardPage . copyContentItem ( ) ; cy . contains ( `Line chart '${ newChartTitle }' was successfully copied.` ) ; cy . get ( "div.grid-row" ) . contains ( "(Copy) " . concat ( newChartTitle ) ) ; editDashboardPage . deleteContentItem ( ) ; cy . contains ( `Line chart '${ newChartTitle }' was successfully deleted.` ) ; editDashboardPage . deleteContentItem ( ) ; cy . get ( "div.grid-row" ) . should ( "not.exist" ) ; const dashboardListingPage = editDashboardPage . goToDashboardListing ( ) ; dashboardListingPage . deleteDashboard ( dashboardName ) ; } ) ; it ( "can add a Table content item to a dashboard" , ( ) => { const addContentItemPage = editDashboardPage . goToAddContentItem ( ) ; addContentItemPage . selectTableContentItem ( ) ; const addTablePage = addContentItemPage . clickContinue ( ) as AddTablePage ; addTablePage . selectStaticDataset ( ) ; addTablePage . uploadDataset ( "table.csv" ) ; addTablePage . selectColumns ( ) ; const tableTitle = random . word ( ) ; addTablePage . fillTitle ( tableTitle ) ; const tableSummary = random . sentence ( ) ; addTablePage . fillSummary ( tableSummary ) ; addTablePage . verifyPreview ( tableTitle , tableSummary ) ; editDashboardPage = addTablePage . submit ( ) ; cy . contains ( `'${ tableTitle }' table has been successfully added.` ) ; cy . contains ( tableTitle ) ; const editTablePage = editDashboardPage . goToEditContentItem ( "Table" ) as EditTablePage ; editTablePage . uploadDataset ( "table.csv" , "chart.csv" ) ; editTablePage . selectColumns ( ) ; const newTableTitle = random . word ( ) ; const newTableSummary = random . sentence ( ) ; editTablePage . fillTitle ( newTableTitle ) ; editTablePage . fillSummary ( newTableSummary ) ; editTablePage . verifyPreview ( newTableTitle , newTableSummary ) ; editDashboardPage = editTablePage . submit ( ) ; cy . contains ( `'${ newTableTitle }' table has been successfully edited.` ) ; cy . get ( "div.grid-row" ) . contains ( newTableTitle ) ; editDashboardPage . copyContentItem ( ) ; cy . contains ( `Table '${ newTableTitle }' was successfully copied.` ) ; cy . get ( "div.grid-row" ) . contains ( "(Copy) " . concat ( newTableTitle ) ) ; editDashboardPage . deleteContentItem ( ) ; cy . contains ( `Table '${ newTableTitle }' was successfully deleted.` ) ; editDashboardPage . deleteContentItem ( ) ; cy . get ( "div.grid-row" ) . should ( "not.exist" ) ; const dashboardListingPage = editDashboardPage . goToDashboardListing ( ) ; dashboardListingPage . deleteDashboard ( dashboardName ) ; } ) ; } ) ;