[explore] Split large reducer logic in ExploreViewContainer (#3088)

* split reducer logic for ExploreViewContainer

* fix saveModal component and unit tests

* revert changes in SaveModal_spec.
will make another commit just to improve test coverage for SaveModal component.

* remove comment-out code

* fix merge confilicts
This commit is contained in:
Grace Guo
2017-08-10 14:21:45 -07:00
committed by Maxime Beauchemin
parent 08b7e891a7
commit b3107bb603
14 changed files with 365 additions and 330 deletions

View File

@@ -0,0 +1,36 @@
import { it, describe } from 'mocha';
import { expect } from 'chai';
import sinon from 'sinon';
import $ from 'jquery';
import * as exploreUtils from '../../../javascripts/explore/exploreUtils';
import * as actions from '../../../javascripts/explore/actions/chartActions';
describe('chart actions', () => {
let dispatch;
let urlStub;
let ajaxStub;
let request;
beforeEach(() => {
dispatch = sinon.spy();
urlStub = sinon.stub(exploreUtils, 'getExploreUrl').callsFake(() => ('mockURL'));
ajaxStub = sinon.stub($, 'ajax');
});
afterEach(() => {
urlStub.restore();
ajaxStub.restore();
});
it('should handle query timeout', () => {
ajaxStub.yieldsTo('error', { statusText: 'timeout' });
request = actions.runQuery({});
request(dispatch, sinon.stub().returns({
explore: {
controls: [],
},
}));
expect(dispatch.callCount).to.equal(3);
expect(dispatch.args[0][0].type).to.equal(actions.CHART_UPDATE_TIMEOUT);
});
});

View File

@@ -4,9 +4,8 @@ import { expect } from 'chai';
import sinon from 'sinon';
import $ from 'jquery';
import * as actions from '../../../javascripts/explore/actions/exploreActions';
import * as exploreUtils from '../../../javascripts/explore/exploreUtils';
import { defaultState } from '../../../javascripts/explore/stores/store';
import { exploreReducer } from '../../../javascripts/explore/reducers/exploreReducer';
import exploreReducer from '../../../javascripts/explore/reducers/exploreReducer';
describe('reducers', () => {
it('sets correct control value given a key and value', () => {
@@ -81,69 +80,4 @@ describe('fetching actions', () => {
expect(dispatch.getCall(4).args[0].type).to.equal(actions.TRIGGER_QUERY);
});
});
describe('fetchDashboards', () => {
const userID = 1;
const mockDashboardData = {
pks: ['value'],
result: [
{ dashboard_title: 'dashboard title' },
],
};
const makeRequest = () => {
request = actions.fetchDashboards(userID);
request(dispatch);
};
it('makes the ajax request', () => {
makeRequest();
expect(ajaxStub.calledOnce).to.be.true;
});
it('calls correct url', () => {
const url = '/dashboardmodelviewasync/api/read?_flt_0_owners=' + userID;
makeRequest();
expect(ajaxStub.getCall(0).args[0].url).to.equal(url);
});
it('calls correct actions on error', () => {
ajaxStub.yieldsTo('error', { responseJSON: { error: 'error text' } });
makeRequest();
expect(dispatch.callCount).to.equal(1);
expect(dispatch.getCall(0).args[0].type).to.equal(actions.FETCH_DASHBOARDS_FAILED);
});
it('calls correct actions on success', () => {
ajaxStub.yieldsTo('success', mockDashboardData);
makeRequest();
expect(dispatch.callCount).to.equal(1);
expect(dispatch.getCall(0).args[0].type).to.equal(actions.FETCH_DASHBOARDS_SUCCEEDED);
});
});
});
describe('runQuery', () => {
let dispatch;
let urlStub;
let ajaxStub;
let request;
beforeEach(() => {
dispatch = sinon.spy();
urlStub = sinon.stub(exploreUtils, 'getExploreUrl').callsFake(() => ('mockURL'));
ajaxStub = sinon.stub($, 'ajax');
});
afterEach(() => {
urlStub.restore();
ajaxStub.restore();
});
it('should handle query timeout', () => {
ajaxStub.yieldsTo('error', { statusText: 'timeout' });
request = actions.runQuery({});
request(dispatch);
expect(dispatch.callCount).to.equal(2);
expect(dispatch.args[0][0].type).to.equal(actions.CHART_UPDATE_TIMEOUT);
});
});