mirror of
https://github.com/elastic/kibana.git
synced 2025-04-23 09:19:04 -04:00
add tests for removing filters
This commit is contained in:
parent
158fd830a8
commit
67daea5493
2 changed files with 101 additions and 0 deletions
100
test/unit/specs/components/filter_bar/_removeFilters.js
Normal file
100
test/unit/specs/components/filter_bar/_removeFilters.js
Normal file
|
@ -0,0 +1,100 @@
|
|||
define(function (require) {
|
||||
return ['remove filters', function () {
|
||||
var _ = require('lodash');
|
||||
var MockState = require('fixtures/mock_state');
|
||||
var storeNames = {
|
||||
app: 'appState',
|
||||
global: 'globalState'
|
||||
};
|
||||
var filters;
|
||||
var queryFilter;
|
||||
var $rootScope, appState, globalState;
|
||||
|
||||
beforeEach(module('kibana'));
|
||||
|
||||
beforeEach(function () {
|
||||
appState = new MockState({ filters: [] });
|
||||
globalState = new MockState({ filters: [] });
|
||||
|
||||
filters = [
|
||||
{
|
||||
query: { match: { extension: { query: 'jpg', type: 'phrase' } } },
|
||||
meta: { negate: false, disabled: false }
|
||||
},
|
||||
{
|
||||
query: { match: { '@tags': { query: 'info', type: 'phrase' } } },
|
||||
meta: { negate: false, disabled: false }
|
||||
},
|
||||
{
|
||||
query: { match: { '_type': { query: 'nginx', type: 'phrase' } } },
|
||||
meta: { negate: false, disabled: false }
|
||||
}
|
||||
];
|
||||
});
|
||||
|
||||
beforeEach(function () {
|
||||
module('kibana/global_state', function ($provide) {
|
||||
$provide.service('getAppState', function () {
|
||||
return function () {
|
||||
return appState;
|
||||
};
|
||||
});
|
||||
|
||||
$provide.service('globalState', function () {
|
||||
return globalState;
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
beforeEach(function () {
|
||||
inject(function (_$rootScope_, Private) {
|
||||
$rootScope = _$rootScope_;
|
||||
queryFilter = Private(require('components/filter_bar/query_filter'));
|
||||
});
|
||||
});
|
||||
|
||||
describe('removing a filter', function () {
|
||||
it('should remove the filter from appState', function () {
|
||||
appState.filters = filters;
|
||||
expect(appState.filters).to.have.length(3);
|
||||
queryFilter.removeFilter(filters[0]);
|
||||
expect(appState.filters).to.have.length(2);
|
||||
});
|
||||
|
||||
it('should remove the filter from globalState', function () {
|
||||
globalState.filters = filters;
|
||||
expect(globalState.filters).to.have.length(3);
|
||||
queryFilter.removeFilter(filters[0]);
|
||||
expect(globalState.filters).to.have.length(2);
|
||||
});
|
||||
|
||||
it('should only remove matching instances', function () {
|
||||
globalState.filters.push(filters[0]);
|
||||
globalState.filters.push(filters[1]);
|
||||
appState.filters.push(filters[2]);
|
||||
|
||||
queryFilter.removeFilter(_.cloneDeep(filters[0]));
|
||||
expect(globalState.filters).to.have.length(2);
|
||||
expect(appState.filters).to.have.length(1);
|
||||
|
||||
queryFilter.removeFilter(_.cloneDeep(filters[2]));
|
||||
expect(globalState.filters).to.have.length(2);
|
||||
expect(appState.filters).to.have.length(1);
|
||||
});
|
||||
});
|
||||
|
||||
describe('bulk removal', function () {
|
||||
it('should remove all the filters from both states', function () {
|
||||
globalState.filters.push(filters[0]);
|
||||
globalState.filters.push(filters[1]);
|
||||
appState.filters.push(filters[2]);
|
||||
expect(globalState.filters).to.have.length(2);
|
||||
expect(appState.filters).to.have.length(1);
|
||||
|
||||
queryFilter.removeAll();
|
||||
expect(globalState.filters).to.have.length(0);
|
||||
expect(appState.filters).to.have.length(0);
|
||||
});
|
||||
});
|
||||
}];
|
||||
});
|
|
@ -47,6 +47,7 @@ define(function (require) {
|
|||
var childSuites = [
|
||||
require('specs/components/filter_bar/_getFilters'),
|
||||
require('specs/components/filter_bar/_addFilters'),
|
||||
require('specs/components/filter_bar/_removeFilters'),
|
||||
].forEach(function (s) {
|
||||
describe(s[0], s[1]);
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue