Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Tim Roes committed Apr 16, 2018
1 parent ead1d1e commit fd86ca1
Showing 1 changed file with 48 additions and 0 deletions.
48 changes: 48 additions & 0 deletions src/ui/public/courier/data_source/__tests__/search_source.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@ import { requestQueue } from '../../_request_queue';
import { SearchSourceProvider } from '../search_source';
import StubIndexPatternProv from 'test_utils/stub_index_pattern';

function timeout() {
return new Promise(resolve => {
setTimeout(resolve);
});
}

describe('SearchSource', function () {
require('test_utils/no_digest_promises').activateForSuite();

Expand Down Expand Up @@ -154,6 +160,48 @@ describe('SearchSource', function () {
});
});

describe('#onRequestStart()', () => {
it('should be called when starting a request', async () => {
const source = new SearchSource();
const fn = sinon.spy();
source.onRequestStart(fn);
const request = {};
source.requestIsStarting(request);
await timeout();
expect(fn.calledWith(source, request)).to.be(true);
});

it('should not be called on parent searchSource', async () => {
const parent = new SearchSource();
const source = new SearchSource().inherits(parent);

const fn = sinon.spy();
source.onRequestStart(fn);
const parentFn = sinon.spy();
parent.onRequestStart(parentFn);
const request = {};
source.requestIsStarting(request);
await timeout();
expect(fn.calledWith(source, request)).to.be(true);
expect(parentFn.notCalled).to.be(true);
});

it('should be called on parent searchSource if callParentStartHandlers is true', async () => {
const parent = new SearchSource();
const source = new SearchSource().inherits(parent, { callParentStartHandlers: true });

const fn = sinon.spy();
source.onRequestStart(fn);
const parentFn = sinon.spy();
parent.onRequestStart(parentFn);
const request = {};
source.requestIsStarting(request);
await timeout();
expect(fn.calledWith(source, request)).to.be(true);
expect(parentFn.calledWith(source, request)).to.be(true);
});
});

describe('#_mergeProp', function () {
describe('filter', function () {
let source;
Expand Down

0 comments on commit fd86ca1

Please sign in to comment.