mirror of
https://github.com/elastic/kibana.git
synced 2025-04-23 01:13:23 -04:00
add event emitter tests
added to emit checks for adding, removing and pinning filters
This commit is contained in:
parent
01a6c25040
commit
bb4c518e0c
3 changed files with 51 additions and 4 deletions
|
@ -1,6 +1,7 @@
|
|||
define(function (require) {
|
||||
return ['add filters', function () {
|
||||
var _ = require('lodash');
|
||||
var sinon = require('test_utils/auto_release_sinon');
|
||||
var MockState = require('fixtures/mock_state');
|
||||
var storeNames = {
|
||||
app: 'appState',
|
||||
|
@ -60,16 +61,30 @@ define(function (require) {
|
|||
expect(globalState.filters.length).to.be(0);
|
||||
});
|
||||
|
||||
it('should add filters to globalState', function () {
|
||||
queryFilter.addFilters(filters, true);
|
||||
expect(appState.filters.length).to.be(0);
|
||||
expect(globalState.filters.length).to.be(3);
|
||||
});
|
||||
|
||||
it('should accept a single filter', function () {
|
||||
queryFilter.addFilters(filters[0]);
|
||||
expect(appState.filters.length).to.be(1);
|
||||
expect(globalState.filters.length).to.be(0);
|
||||
});
|
||||
|
||||
it('should add filters to globalState', function () {
|
||||
queryFilter.addFilters(filters, true);
|
||||
expect(appState.filters.length).to.be(0);
|
||||
expect(globalState.filters.length).to.be(3);
|
||||
it('should fire the update and fetch events', function () {
|
||||
var emitSpy = sinon.spy(queryFilter, 'emit');
|
||||
|
||||
// set up the watchers
|
||||
$rootScope.$digest();
|
||||
queryFilter.addFilters(filters);
|
||||
// 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');
|
||||
});
|
||||
});
|
||||
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
define(function (require) {
|
||||
return ['pin filters', function () {
|
||||
var _ = require('lodash');
|
||||
var sinon = require('test_utils/auto_release_sinon');
|
||||
var MockState = require('fixtures/mock_state');
|
||||
var storeNames = {
|
||||
app: 'appState',
|
||||
|
@ -102,6 +103,21 @@ define(function (require) {
|
|||
expect(globalState.filters).to.have.length(1);
|
||||
expect(appState.filters).to.have.length(7);
|
||||
});
|
||||
|
||||
|
||||
it('should only fire the update event', function () {
|
||||
var filter = appState.filters[1];
|
||||
var emitSpy = sinon.spy(queryFilter, 'emit');
|
||||
|
||||
// set up the watchers
|
||||
$rootScope.$digest();
|
||||
queryFilter.pinFilter(filter);
|
||||
// trigger the digest loop to fire the watchers
|
||||
$rootScope.$digest();
|
||||
|
||||
expect(emitSpy.callCount).to.be(1);
|
||||
expect(emitSpy.firstCall.args[0]).to.be('update');
|
||||
});
|
||||
});
|
||||
|
||||
describe('bulk pinning', function () {
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
define(function (require) {
|
||||
return ['remove filters', function () {
|
||||
var _ = require('lodash');
|
||||
var sinon = require('test_utils/auto_release_sinon');
|
||||
var MockState = require('fixtures/mock_state');
|
||||
var storeNames = {
|
||||
app: 'appState',
|
||||
|
@ -68,6 +69,21 @@ define(function (require) {
|
|||
expect(globalState.filters).to.have.length(2);
|
||||
});
|
||||
|
||||
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.removeFilter(filters[0]);
|
||||
// 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');
|
||||
});
|
||||
|
||||
it('should only remove matching instances', function () {
|
||||
globalState.filters.push(filters[0]);
|
||||
globalState.filters.push(filters[1]);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue