Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
it('should fire the update and fetch events', function () {
var emitSpy = sinon.spy(queryFilter, 'emit');
appState.filters = filters;
// set up the watchers
$rootScope.$digest();
queryFilter.invertFilter(filters[1]);
// trigger the digest loop to fire the watchers
$rootScope.$digest();
expect(emitSpy.callCount).to.be(2);
expect(emitSpy.firstCall.args[0]).to.be('update');
expect(emitSpy.secondCall.args[0]).to.be('fetch');
});
});
beforeEach(ngMock.inject(function (Private) {
// mock parts of leaflet
leafletMocks.tileLayer = { on: sinon.stub() };
leafletMocks.map = { on: sinon.stub() };
leafletStubs.tileLayer = sinon.stub(L, 'tileLayer', _.constant(leafletMocks.tileLayer));
leafletStubs.map = sinon.stub(L, 'map', _.constant(leafletMocks.map));
Map = Private(require('ui/vislib/visualizations/_map'));
}));
beforeEach(ngMock.inject(function (Private) {
// mock parts of leaflet
leafletMocks.tileLayer = { on: sinon.stub() };
leafletMocks.map = { on: sinon.stub() };
leafletStubs.tileLayer = sinon.stub(L, 'tileLayer', _.constant(leafletMocks.tileLayer));
leafletStubs.map = sinon.stub(L, 'map', _.constant(leafletMocks.map));
Map = Private(require('ui/vislib/visualizations/_map'));
}));
ngMock.inject(function ($injector, _$rootScope_, _$compile_, _$timeout_, _Promise_, _Private_, _config_) {
$timeout = _$timeout_;
$compile = _$compile_;
Promise = _Promise_;
Private = _Private_;
config = _config_;
// Give us a scope
$rootScope = _$rootScope_;
var es = $injector.get('es');
mockValidateQuery = sinon.stub(es.indices, 'validateQuery');
});
};
it('should fire the update and fetch events', function () {
var emitSpy = sinon.spy(queryFilter, 'emit');
appState.filters = filters;
$rootScope.$digest();
queryFilter.toggleFilter(filters[1]);
$rootScope.$digest();
expect(emitSpy.callCount).to.be(2);
expect(emitSpy.firstCall.args[0]).to.be('update');
expect(emitSpy.secondCall.args[0]).to.be('fetch');
});
it('should fire the update and fetch events', function () {
var emitSpy = sinon.spy(queryFilter, 'emit');
appState.filters = filters;
$rootScope.$digest();
queryFilter.removeFilter(filters[0]);
$rootScope.$digest();
expect(emitSpy.callCount).to.be(2);
expect(emitSpy.firstCall.args[0]).to.be('update');
expect(emitSpy.secondCall.args[0]).to.be('fetch');
});
it('should only fire the update event', function () {
var emitSpy = sinon.spy(queryFilter, 'emit');
var filter = appState.filters[1];
$rootScope.$digest();
queryFilter.pinFilter(filter);
$rootScope.$digest();
expect(emitSpy.callCount).to.be(1);
expect(emitSpy.firstCall.args[0]).to.be('update');
});
});
it('should increment the poplarity count by default', function () {
var saveSpy = sinon.stub(indexPattern, 'save');
indexPattern.fields.forEach(function (field, i) {
var oldCount = field.count;
indexPattern.popularizeField(field.name);
expect(saveSpy.callCount).to.equal(i + 1);
expect(field.count).to.equal(oldCount + 1);
});
});
it('always emits the handlers that were initially registered', function () {
var destructive = sinon.spy(function () {
emitter.removeAllListeners();
expect(emitter.listenerCount()).to.be(0);
});
var stub = sinon.stub();
emitter.on('run', destructive).on('run', stub).emit('run');
expect(destructive).to.have.property('callCount', 1);
expect(stub).to.have.property('callCount', 1);
});
it('clears the timeout', function () {
var spy = sinon.spy(window, 'clearTimeout');
checker.destroy();
expect(spy).to.have.property('callCount', 1);
});
});