Skip to content

Commit

Permalink
[cypress] Test dashboard save/save_as functions (apache#6361)
Browse files Browse the repository at this point in the history
  • Loading branch information
Grace Guo authored and bipinsoniguavus committed Dec 24, 2018
1 parent 4024593 commit acb38df
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 0 deletions.
2 changes: 2 additions & 0 deletions superset/assets/cypress/integration/dashboard/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@ import DashboardEditModeTest from './edit_mode';
import DashboardFavStarTest from './fav_star';
import DashboardFilterTest from './filter';
import DashboardLoadTest from './load';
import DashboardSaveTest from './save';

describe('Dashboard', () => {
DashboardControlsTest();
DashboardEditModeTest();
DashboardFavStarTest();
DashboardFilterTest();
DashboardLoadTest();
DashboardSaveTest();
});
59 changes: 59 additions & 0 deletions superset/assets/cypress/integration/dashboard/save.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import readResponseBlob from '../../utils/readResponseBlob';
import { WORLD_HEALTH_DASHBOARD } from './dashboard.helper';

export default () => describe('save', () => {
let dashboardId;
let boxplotChartId;

beforeEach(() => {
cy.server();
cy.login();
cy.visit(WORLD_HEALTH_DASHBOARD);

cy.get('#app').then((data) => {
const bootstrapData = JSON.parse(data[0].dataset.bootstrap);
const dashboard = bootstrapData.dashboard_data;
dashboardId = dashboard.id;
boxplotChartId = dashboard.slices.find(slice => (slice.form_data.viz_type === 'box_plot')).slice_id;

cy.route('POST', `/superset/copy_dash/${dashboardId}/`).as('copyRequest');
});

cy.get('#save-dash-split-button').trigger('click', { force: true });
cy.contains('Save as').trigger('click', { force: true });
cy.get('.modal-footer').contains('Save').trigger('click', { force: true });
});

it('should save as new dashboard', () => {
cy.wait('@copyRequest').then((xhr) => {
expect(xhr.status).to.eq(200);

readResponseBlob(xhr.response.body).then((json) => {
expect(json.id).to.be.gt(dashboardId);
});
});
});

it('should save/overwrite dashboard', () => {
cy.wait('@copyRequest');

// should have box_plot chart
const boxplotRequest = `/superset/explore_json/?form_data={"slice_id":${boxplotChartId}}`;
cy.route('POST', boxplotRequest).as('boxplotRequest');
cy.wait('@boxplotRequest');
cy.get('.grid-container .box_plot').should('be.exist');

// remove box_plot chart from dashboard
cy.get('.dashboard-header').contains('Edit dashboard').trigger('click', { force: true });
cy.get('.fa.fa-trash').last().trigger('click', { force: true });
cy.get('.grid-container .box_plot').should('not.exist');

cy.route('POST', '/superset/save_dash/**/').as('saveRequest');
cy.get('.dashboard-header').contains('Save changes').trigger('click', { force: true });

// go back to view mode
cy.wait('@saveRequest');
cy.get('.dashboard-header').contains('Edit dashboard');
cy.get('.grid-container .box_plot').should('not.exist');
});
});

0 comments on commit acb38df

Please sign in to comment.