-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Checks to Dashboard Context (#13182)
* Fixes #13181 - Check values before adding them to filter * Adding tests * Adding check to make sure query is never undefined
- Loading branch information
1 parent
1e50dff
commit 9ee0ca8
Showing
3 changed files
with
138 additions
and
4 deletions.
There are no files selected for viewing
131 changes: 131 additions & 0 deletions
131
src/core_plugins/kibana/public/dashboard/__tests__/dashboard_context.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,131 @@ | ||
import sinon from 'sinon'; | ||
import { expect } from 'chai'; | ||
import { dashboardContextProvider } from '../dashboard_context'; | ||
|
||
describe('Dashboard Context', () => { | ||
|
||
describe('with query bar', () => { | ||
let Private; | ||
let getAppState; | ||
let getDashboardContext; | ||
beforeEach(() => { | ||
Private = sinon.stub().returns({ | ||
getFilters() { | ||
return []; | ||
} | ||
}); | ||
}); | ||
|
||
it('should return an empty must and must not when there are no filters or queries', () => { | ||
getAppState = sinon.stub().returns({ | ||
query: { | ||
language: 'lucene', | ||
query: null | ||
} | ||
}); | ||
getDashboardContext = dashboardContextProvider(Private, getAppState); | ||
const context = getDashboardContext(); | ||
expect(context).to.eql({ | ||
bool: { | ||
must: [], | ||
must_not: [] | ||
} | ||
}); | ||
}); | ||
|
||
it('should add a valid query to must', () => { | ||
getAppState = sinon.stub().returns({ | ||
query: { | ||
language: 'lucene', | ||
query: '*' | ||
} | ||
}); | ||
getDashboardContext = dashboardContextProvider(Private, getAppState); | ||
const context = getDashboardContext(); | ||
expect(context).to.eql({ | ||
bool: { | ||
must: [ | ||
{ | ||
query_string: { | ||
query: '*' | ||
} | ||
} | ||
], | ||
must_not: [] | ||
} | ||
}); | ||
}); | ||
|
||
}); | ||
|
||
describe('with filter bar', () => { | ||
let Private; | ||
let getAppState; | ||
let getDashboardContext; | ||
beforeEach(() => { | ||
getAppState = sinon.stub().returns({ query: { language: 'something-else' } }); | ||
}); | ||
|
||
afterEach(() => { | ||
getAppState.reset(); | ||
}); | ||
|
||
it('should add a valid filter to must', () => { | ||
Private = sinon.stub().returns({ | ||
getFilters() { | ||
return [ | ||
{ meta: { negate: false }, term: { foo: 'bar' } } | ||
]; | ||
} | ||
}); | ||
getDashboardContext = dashboardContextProvider(Private, getAppState); | ||
const context = getDashboardContext(); | ||
expect(context).to.eql({ | ||
bool: { | ||
must: [{ term: { foo: 'bar' } }], | ||
must_not: [] | ||
} | ||
}); | ||
}); | ||
|
||
it('should add a valid filter to must_not', () => { | ||
Private = sinon.stub().returns({ | ||
getFilters() { | ||
return [ | ||
{ meta: { negate: true }, term: { foo: 'bar' } } | ||
]; | ||
} | ||
}); | ||
getDashboardContext = dashboardContextProvider(Private, getAppState); | ||
const context = getDashboardContext(); | ||
expect(context).to.eql({ | ||
bool: { | ||
must: [], | ||
must_not: [{ term: { foo: 'bar' } }] | ||
} | ||
}); | ||
}); | ||
|
||
it('should not add a disabled filter', () => { | ||
Private = sinon.stub().returns({ | ||
getFilters() { | ||
return [ | ||
{ meta: { negate: true, disabled: true }, term: { foo: 'bar' } } | ||
]; | ||
} | ||
}); | ||
getDashboardContext = dashboardContextProvider(Private, getAppState); | ||
const context = getDashboardContext(); | ||
expect(context).to.eql({ | ||
bool: { | ||
must: [], | ||
must_not: [] | ||
} | ||
}); | ||
}); | ||
|
||
}); | ||
|
||
}); | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters