Skip to content

Commit

Permalink
[explore] fix missing CacheLabel (apache#4326)
Browse files Browse the repository at this point in the history
Also adding a basic unit test.
  • Loading branch information
mistercrunch authored and Grace Guo committed Feb 2, 2018
1 parent 75a2b4f commit 1f8fccc
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ class ExploreChartHeader extends React.PureComponent {
json_endpoint: getExploreUrl(formData, 'json'),
standalone_endpoint: getExploreUrl(formData, 'standalone'),
};

const chartSucceeded = ['success', 'rendered'].indexOf(this.props.chart.chartStatus) > 0;
return (
<div
id="slice-header"
Expand Down Expand Up @@ -115,21 +115,16 @@ class ExploreChartHeader extends React.PureComponent {
/>
}
<div className="pull-right">
{this.props.chart.chartStatus === 'success' && queryResponse &&
{chartSucceeded && queryResponse &&
<RowCountLabel
rowcount={queryResponse.rowcount}
limit={formData.row_limit}
/>
}
{this.props.chart.chartStatus === 'success' &&
queryResponse &&
queryResponse.is_cached &&

<CachedLabel
onClick={this.runQuery.bind(this)}
cachedTimestamp={queryResponse.cached_dttm}
/>
}
/>}
{chartSucceeded && queryResponse && queryResponse.is_cached &&
<CachedLabel
onClick={this.runQuery.bind(this)}
cachedTimestamp={queryResponse.cached_dttm}
/>}
<Timer
startTime={this.props.chart.chartUpdateStartTime}
endTime={this.props.chart.chartUpdateEndTime}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import React from 'react';
import { expect } from 'chai';
import { describe, it } from 'mocha';
import { shallow } from 'enzyme';

import ExploreChartHeader from '../../../../javascripts/explore/components/ExploreChartHeader';
import ExploreActionButtons from '../../../../javascripts/explore/components/ExploreActionButtons';
import EditableTitle from '../../../../javascripts/components/EditableTitle';

const mockProps = {
actions: {},
can_overwrite: true,
can_download: true,
isStarred: true,
slice: {},
table_name: 'foo',
form_data: {},
timeout: 1000,
chart: {
queryResponse: {},
},
};

describe('ExploreChartHeader', () => {
let wrapper;
beforeEach(() => {
wrapper = shallow(<ExploreChartHeader {...mockProps} />);
});

it('is valid', () => {
expect(
React.isValidElement(<ExploreChartHeader {...mockProps} />),
).to.equal(true);
});

it('renders', () => {
expect(wrapper.find(EditableTitle)).to.have.lengthOf(1);
expect(wrapper.find(ExploreActionButtons)).to.have.lengthOf(1);
});
});

0 comments on commit 1f8fccc

Please sign in to comment.