minor filter select enhancements (#3933)

* `values_for_column` configurable row limit

* `FilterControl` cancels active ajax request if any
This commit is contained in:
kkalyan
2017-11-27 21:05:53 -08:00
committed by Maxime Beauchemin
parent 17635e1a2b
commit f9202ba179
4 changed files with 54 additions and 12 deletions

View File

@@ -109,12 +109,15 @@ describe('FilterControl', () => {
]);
});
before(() => {
sinon.stub($, 'ajax');
});
after(() => {
$.ajax.restore();
});
it('makes a GET request to retrieve value choices', () => {
sinon.stub($, 'ajax');
wrapper.instance().fetchFilterValues(0, 'col1');
expect($.ajax.getCall(0).args[0].type).to.deep.equal('GET');
expect($.ajax.getCall(0).args[0].url).to.deep.equal('/superset/filter/qtable/1/col1/');
@@ -214,4 +217,31 @@ describe('FilterControl', () => {
},
]);
});
it('tracks an active filter select ajax request', () => {
const spyReq = sinon.spy();
$.ajax.reset();
$.ajax.onFirstCall().returns(spyReq);
wrapper.instance().fetchFilterValues(0, 'col1');
expect(wrapper.state().activeRequest).to.equal(spyReq);
// Sets active to null after success
$.ajax.getCall(0).args[0].success('choices');
expect(wrapper.state().filters[0].valuesLoading).to.equal(false);
expect(wrapper.state().filters[0].valueChoices).to.equal('choices');
expect(wrapper.state().activeRequest).to.equal(null);
});
it('cancels active request if another is submitted', () => {
const spyReq = sinon.spy();
spyReq.abort = sinon.spy();
$.ajax.reset();
$.ajax.onFirstCall().returns(spyReq);
wrapper.instance().fetchFilterValues(0, 'col1');
expect(wrapper.state().activeRequest).to.equal(spyReq);
const spyReq1 = sinon.spy();
$.ajax.onSecondCall().returns(spyReq1);
wrapper.instance().fetchFilterValues(1, 'col2');
expect(spyReq.abort.called).to.equal(true);
expect(wrapper.state().activeRequest).to.equal(spyReq1);
});
});