all filter tests require mocking courier

This commit is contained in:
Joe Fleming 2015-05-18 13:45:44 -07:00
parent a5bf6036db
commit 51ac6f8cf3
3 changed files with 36 additions and 13 deletions

View file

@ -9,7 +9,7 @@ define(function (require) {
};
var filters;
var queryFilter;
var $rootScope, appState, globalState;
var $rootScope, getIndexPatternStub, appState, globalState;
beforeEach(module('kibana'));
@ -35,6 +35,11 @@ define(function (require) {
beforeEach(function () {
module('kibana/global_state', function ($provide) {
$provide.service('courier', function () {
var courier = { indexPatterns: { get: getIndexPatternStub } };
return courier;
});
$provide.service('getAppState', function () {
return function () {
return appState;
@ -48,7 +53,11 @@ define(function (require) {
});
beforeEach(function () {
inject(function (_$rootScope_, Private) {
getIndexPatternStub = sinon.stub();
inject(function (_$rootScope_, Private, Promise) {
var indexPattern = Private(require('fixtures/stubbed_logstash_index_pattern'));
getIndexPatternStub.returns(Promise.resolve(indexPattern));
$rootScope = _$rootScope_;
queryFilter = Private(require('components/filter_bar/query_filter'));
});

View file

@ -9,7 +9,7 @@ define(function (require) {
};
var filters;
var queryFilter;
var $rootScope, appState, globalState;
var $rootScope, getIndexPatternStub, appState, globalState;
beforeEach(module('kibana'));
@ -55,6 +55,11 @@ define(function (require) {
beforeEach(function () {
module('kibana/global_state', function ($provide) {
$provide.service('courier', function () {
var courier = { indexPatterns: { get: getIndexPatternStub } };
return courier;
});
$provide.service('getAppState', function () {
return function () {
return appState;
@ -68,7 +73,11 @@ define(function (require) {
});
beforeEach(function () {
inject(function (_$rootScope_, Private) {
getIndexPatternStub = sinon.stub();
inject(function (_$rootScope_, Private, Promise) {
var indexPattern = Private(require('fixtures/stubbed_logstash_index_pattern'));
getIndexPatternStub.returns(Promise.resolve(indexPattern));
$rootScope = _$rootScope_;
queryFilter = Private(require('components/filter_bar/query_filter'));
});
@ -106,13 +115,11 @@ define(function (require) {
it('should only fire the update event', function () {
var filter = appState.filters[1];
var emitSpy = sinon.spy(queryFilter, 'emit');
// set up the watchers
var filter = appState.filters[1];
$rootScope.$digest();
queryFilter.pinFilter(filter);
// trigger the digest loop to fire the watchers
$rootScope.$digest();
expect(emitSpy.callCount).to.be(1);

View file

@ -9,7 +9,7 @@ define(function (require) {
};
var filters;
var queryFilter;
var $rootScope, appState, globalState;
var $rootScope, getIndexPatternStub, appState, globalState;
beforeEach(module('kibana'));
@ -35,6 +35,11 @@ define(function (require) {
beforeEach(function () {
module('kibana/global_state', function ($provide) {
$provide.service('courier', function () {
var courier = { indexPatterns: { get: getIndexPatternStub } };
return courier;
});
$provide.service('getAppState', function () {
return function () {
return appState;
@ -48,7 +53,11 @@ define(function (require) {
});
beforeEach(function () {
inject(function (_$rootScope_, Private) {
getIndexPatternStub = sinon.stub();
inject(function (_$rootScope_, Private, Promise) {
var indexPattern = Private(require('fixtures/stubbed_logstash_index_pattern'));
getIndexPatternStub.returns(Promise.resolve(indexPattern));
$rootScope = _$rootScope_;
queryFilter = Private(require('components/filter_bar/query_filter'));
});
@ -78,11 +87,9 @@ define(function (require) {
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.toggleFilter(filters[1]);
// trigger the digest loop to fire the watchers
$rootScope.$digest();
expect(emitSpy.callCount).to.be(2);