Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug] Resize should trigger chart re-render #4322

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions superset/assets/javascripts/chart/Chart.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ class Chart extends React.PureComponent {
componentDidUpdate(prevProps) {
if (
this.props.queryResponse &&
this.props.chartStatus === 'success' &&
['success', 'rendered'].indexOf(this.props.chartStatus) > -1 &&
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do you think we should make these CONSTANTS to make this less error-prone and ensure consistency between components?

!this.props.queryResponse.error && (
prevProps.annotationData !== this.props.annotationData ||
prevProps.queryResponse !== this.props.queryResponse ||
Expand Down Expand Up @@ -210,7 +210,7 @@ class Chart extends React.PureComponent {
{!this.props.chartAlert &&
<ChartBody
containerId={this.containerId}
vizType={this.props.formData.viz_type}
vizType={this.props.vizType}
height={this.height}
width={this.width}
ref={(inner) => {
Expand Down
71 changes: 71 additions & 0 deletions superset/assets/spec/javascripts/chart/Chart_spec.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
import React from 'react';
import { shallow } from 'enzyme';
import { describe, it } from 'mocha';
import { expect } from 'chai';
import sinon from 'sinon';

import { chart as initChart } from '../../../javascripts/chart/chartReducer';
import Chart from '../../../javascripts/chart/Chart';

describe('Chart', () => {
const chart = {
...initChart,
queryResponse: {
form_data: {},
error: null,
status: 'success',
},
};
const mockedProps = {
...chart,
chartKey: 'slice_223',
containerId: 'slice-container-223',
datasource: {},
formData: {},
vizType: 'pie',
height: 300,
width: 400,
actions: {
runQuery: () => {},
},
};

describe('renderViz', () => {
let wrapper;
let stub;
beforeEach(() => {
wrapper = shallow(
<Chart {...mockedProps} />,
);
stub = sinon.stub(wrapper.instance(), 'renderViz');
});

it('should not call when loading', () => {
const prevProp = wrapper.props();
wrapper.setProps({
height: 100,
});
wrapper.instance().componentDidUpdate(prevProp);
expect(stub.callCount).to.equals(0);
});

it('should call after chart stop loading', () => {
const prevProp = wrapper.props();
wrapper.setProps({
chartStatus: 'success',
});
wrapper.instance().componentDidUpdate(prevProp);
expect(stub.callCount).to.equals(1);
});

it('should call after resize', () => {
const prevProp = wrapper.props();
wrapper.setProps({
chartStatus: 'rendered',
height: 100,
});
wrapper.instance().componentDidUpdate(prevProp);
expect(stub.callCount).to.equals(1);
});
});
});