mirror of
https://github.com/elastic/kibana.git
synced 2025-04-23 01:13:23 -04:00
make the filterbar tests pass
there was a strange race condition that seemingly only adding a next tick would fix le sigh
This commit is contained in:
parent
8d803228f3
commit
3359b76796
1 changed files with 65 additions and 34 deletions
|
@ -5,16 +5,31 @@ define(function (require) {
|
|||
var $ = require('jquery');
|
||||
|
||||
require('components/filter_bar/filter_bar');
|
||||
var MockState = require('fixtures/mock_state');
|
||||
|
||||
describe('Filter Bar Directivez', function () {
|
||||
describe('Filter Bar Directive', function () {
|
||||
var $rootScope, $compile, $timeout, Promise;
|
||||
var appState, queryFilter, mapFilter, getIndexPatternStub, indexPattern, $el;
|
||||
// require('test_utils/no_digest_promises').activateForSuite();
|
||||
|
||||
var $rootScope, $compile, $timeout, Promise, mapFilter, getIndexPatternStub, indexPattern, $el;
|
||||
beforeEach(function () {
|
||||
appState = new MockState({ filters: [] });
|
||||
|
||||
module('kibana/global_state', function ($provide) {
|
||||
$provide.service('getAppState', function () {
|
||||
return function () {
|
||||
return appState;
|
||||
};
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
beforeEach(function () {
|
||||
// load the application
|
||||
module('kibana');
|
||||
|
||||
getIndexPatternStub = sinon.stub();
|
||||
|
||||
module('kibana/courier', function ($provide) {
|
||||
$provide.service('courier', function () {
|
||||
var courier = { indexPatterns: { get: getIndexPatternStub } };
|
||||
|
@ -22,47 +37,63 @@ define(function (require) {
|
|||
});
|
||||
});
|
||||
|
||||
inject(function (_$rootScope_, _$compile_, _$timeout_, _Promise_, Private) {
|
||||
inject(function (Private, $injector, _$rootScope_, _$compile_, _$timeout_) {
|
||||
$rootScope = _$rootScope_;
|
||||
$compile = _$compile_;
|
||||
$timeout = _$timeout_;
|
||||
Promise = _Promise_;
|
||||
Promise = $injector.get('Promise');
|
||||
mapFilter = Private(require('components/filter_bar/lib/mapFilter'));
|
||||
|
||||
indexPattern = Private(require('fixtures/stubbed_logstash_index_pattern'));
|
||||
getIndexPatternStub.returns(Promise.resolve(indexPattern));
|
||||
|
||||
var queryFilter = Private(require('components/filter_bar/query_filter'));
|
||||
queryFilter.getFilters = function () {
|
||||
return appState.filters;
|
||||
};
|
||||
});
|
||||
});
|
||||
|
||||
describe('Element rendering', function () {
|
||||
beforeEach(function (done) {
|
||||
var filters = [
|
||||
{ meta: { index: 'logstash-*' }, query: { match: { '_type': { query: 'apache' } } } },
|
||||
{ meta: { index: 'logstash-*' }, query: { match: { '_type': { query: 'nginx' } } } },
|
||||
{ meta: { index: 'logstash-*' }, exists: { field: '@timestamp' } },
|
||||
{ meta: { index: 'logstash-*' }, missing: { field: 'host' }, disabled: true },
|
||||
];
|
||||
|
||||
Promise.map(filters, mapFilter).then(function (filters) {
|
||||
appState.filters = filters;
|
||||
$el = $compile('<filter-bar></filter-bar>')($rootScope);
|
||||
});
|
||||
|
||||
var off = $rootScope.$on('filterbar:updated', function () {
|
||||
off();
|
||||
|
||||
// force a nextTick so it continues *after* the $digest loop completes
|
||||
setTimeout(function () {
|
||||
$rootScope.$apply(); // ┗( ●-﹏ `。)づ ....angular
|
||||
done();
|
||||
}, 0);
|
||||
});
|
||||
|
||||
// kick off the digest loop
|
||||
$rootScope.$digest();
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
beforeEach(function () {
|
||||
var filters = [
|
||||
{ meta: { index: 'logstash-*' }, query: { match: { '_type': { query: 'apache' } } } },
|
||||
{ meta: { index: 'logstash-*' }, query: { match: { '_type': { query: 'nginx' } } } },
|
||||
{ meta: { index: 'logstash-*' }, exists: { field: '@timestamp' } },
|
||||
{ meta: { index: 'logstash-*' }, missing: { field: 'host' }, disabled: true },
|
||||
];
|
||||
|
||||
Promise.map(filters, mapFilter).then(function (filters) {
|
||||
$rootScope.state = { filters: filters };
|
||||
it('should render all the filters in state', function () {
|
||||
var filters = $el.find('.filter');
|
||||
expect(filters).to.have.length(4);
|
||||
expect($(filters[0]).find('span')[0].innerHTML).to.equal('_type:');
|
||||
expect($(filters[0]).find('span')[1].innerHTML).to.equal('"apache"');
|
||||
expect($(filters[1]).find('span')[0].innerHTML).to.equal('_type:');
|
||||
expect($(filters[1]).find('span')[1].innerHTML).to.equal('"nginx"');
|
||||
expect($(filters[2]).find('span')[0].innerHTML).to.equal('exists:');
|
||||
expect($(filters[2]).find('span')[1].innerHTML).to.equal('"@timestamp"');
|
||||
expect($(filters[3]).find('span')[0].innerHTML).to.equal('missing:');
|
||||
expect($(filters[3]).find('span')[1].innerHTML).to.equal('"host"');
|
||||
});
|
||||
$rootScope.$digest();
|
||||
|
||||
$el = $compile('<filter-bar state=state></filter-bar>')($rootScope);
|
||||
$rootScope.$digest();
|
||||
});
|
||||
|
||||
it('should render all the filters in state', function () {
|
||||
var filters = $el.find('.filter');
|
||||
expect(filters).to.have.length(4);
|
||||
expect($(filters[0]).find('span')[0].innerHTML).to.equal('_type:');
|
||||
expect($(filters[0]).find('span')[1].innerHTML).to.equal('"apache"');
|
||||
expect($(filters[1]).find('span')[0].innerHTML).to.equal('_type:');
|
||||
expect($(filters[1]).find('span')[1].innerHTML).to.equal('"nginx"');
|
||||
expect($(filters[2]).find('span')[0].innerHTML).to.equal('exists:');
|
||||
expect($(filters[2]).find('span')[1].innerHTML).to.equal('"@timestamp"');
|
||||
expect($(filters[3]).find('span')[0].innerHTML).to.equal('missing:');
|
||||
expect($(filters[3]).find('span')[1].innerHTML).to.equal('"host"');
|
||||
});
|
||||
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue