diff --git a/src/ui/public/filter_bar/__tests__/_updateFilters.js b/src/ui/public/filter_bar/__tests__/_updateFilters.js index 91b93c3cf287..d7bec6538963 100644 --- a/src/ui/public/filter_bar/__tests__/_updateFilters.js +++ b/src/ui/public/filter_bar/__tests__/_updateFilters.js @@ -39,26 +39,51 @@ describe('update filters', function () { describe('updating', function () { var currentFilter; + var newFilter; beforeEach(function () { - currentFilter = {query: { match: { extension: { query: 'jpg', type: 'phrase' } } } }; + newFilter = _.cloneDeep({ + query: { + match: { + extension: { + query: 'jpg', + type: 'phrase' + } + } + } + }); + currentFilter = _.assign(_.cloneDeep(newFilter), { + meta: {} + }); }); it('should be able to update a filter', function () { - var newFilter = _.cloneDeep(currentFilter); newFilter.query.match.extension.query = 'png'; expect(currentFilter.query.match.extension.query).to.be('jpg'); queryFilter.updateFilter({ source: currentFilter, - model: newFilter + model: newFilter, + type: 'query' }); $rootScope.$digest(); expect(currentFilter.query.match.extension.query).to.be('png'); }); + it('should set an alias in the meta object', function () { + + queryFilter.updateFilter({ + source: currentFilter, + model: newFilter, + type: 'query', + alias: 'foo' + }); + $rootScope.$digest(); + expect(currentFilter.meta.alias).to.be('foo'); + }); + it('should replace the filter type if it is changed', function () { - var newFilter = { + newFilter = { 'range': { 'bytes': { 'gte': 0, diff --git a/src/ui/public/filter_bar/__tests__/filter_bar.js b/src/ui/public/filter_bar/__tests__/filter_bar.js index 33f68558e646..5b102de7043f 100644 --- a/src/ui/public/filter_bar/__tests__/filter_bar.js +++ b/src/ui/public/filter_bar/__tests__/filter_bar.js @@ -55,6 +55,7 @@ describe('Filter Bar Directive', function () { { meta: { index: 'logstash-*' }, query: { match: { '_type': { query: 'nginx' } } } }, { meta: { index: 'logstash-*' }, exists: { field: '@timestamp' } }, { meta: { index: 'logstash-*' }, missing: { field: 'host' }, disabled: true }, + { meta: { index: 'logstash-*', alias: 'foo' }, query: { match: { '_type': { query: 'nginx' } } } }, ]; Promise.map(filters, mapFilter).then(function (filters) { @@ -75,7 +76,7 @@ describe('Filter Bar Directive', function () { it('should render all the filters in state', function () { var filters = $el.find('.filter'); - expect(filters).to.have.length(4); + expect(filters).to.have.length(5); 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:'); @@ -86,6 +87,11 @@ describe('Filter Bar Directive', function () { expect($(filters[3]).find('span')[1].innerHTML).to.equal('"host"'); }); + it('should be able to set an alias', function () { + var filter = $el.find('.filter')[4]; + expect($(filter).find('span')[0].innerHTML).to.equal('foo'); + }); + describe('editing filters', function () { beforeEach(function () { $scope.startEditingFilter(appState.filters[3]); diff --git a/src/ui/public/filter_bar/filter_bar.html b/src/ui/public/filter_bar/filter_bar.html index 50ed3083971b..9ca33e22b9b2 100644 --- a/src/ui/public/filter_bar/filter_bar.html +++ b/src/ui/public/filter_bar/filter_bar.html @@ -13,8 +13,9 @@