Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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 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('defers to hierarchical aggResponse converter', function () {
var football = {};
var renderbot = {
vis: {
isHierarchical: _.constant(true)
}
};
var stub = sinon.stub(aggResponse, 'hierarchical').returns(football);
expect(buildChartData.call(renderbot, football)).to.be(football);
expect(stub).to.have.property('callCount', 1);
expect(stub.firstCall.args[0]).to.be(renderbot.vis);
expect(stub.firstCall.args[1]).to.be(football);
});
});
it('defers to hierarchical aggResponse converter', function () {
var football = {};
var renderbot = {
vis: {
isHierarchical: _.constant(true)
}
};
var stub = sinon.stub(aggResponse, 'hierarchical').returns(football);
expect(buildChartData.call(renderbot, football)).to.be(football);
expect(stub).to.have.property('callCount', 1);
expect(stub.firstCall.args[0]).to.be(renderbot.vis);
expect(stub.firstCall.args[1]).to.be(football);
});
});
it('returns a single chart if the tabify response contains only a single table', function () {
var chart = { hits: 1, rows: [], columns: [] };
var renderbot = {
vis: {
isHierarchical: _.constant(false),
type: {
responseConverter: _.constant(chart)
}
}
};
var esResp = { hits: { total: 1 } };
var tabbed = { tables: [ new Table() ] };
sinon.stub(aggResponse, 'tabify').returns(tabbed);
expect(buildChartData.call(renderbot, esResp)).to.eql(chart);
});
it('should trigger the watcher on initialization', function () {
var stub = sinon.stub();
firstValue = 'first';
secondValue = 'second';
$scope.$watchMulti(stateWatchers, stub);
$rootScope.$apply();
expect(stub.callCount).to.be(1);
expect(stub.firstCall.args[0]).to.eql([firstValue, secondValue]);
expect(stub.firstCall.args[1]).to.eql([firstValue, secondValue]);
});
});
it('should use the tooltip formatter', function () {
var content;
var sample = _.sample(mapData.features);
var stub = sinon.stub(markerLayer, '_tooltipFormatter', function (val) {
return;
});
markerLayer._showTooltip(sample);
expect(stub.callCount).to.equal(1);
expect(stub.firstCall.calledWith(sample)).to.be(true);
});
});
it('should clear a specific handler when off is called for an event', function () {
var obj = new Events();
var handler1 = sinon.stub();
var handler2 = sinon.stub();
obj.on('test', handler1);
obj.on('test', handler2);
expect(obj._listeners).to.have.property('test');
obj.off('test', handler1);
return obj.emit('test', 'Hello World')
.then(function () {
sinon.assert.calledOnce(handler2);
sinon.assert.notCalled(handler1);
});
});