mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Elasticsearch: Added modifyQuery method to add filters in Explore (#52313)
This commit is contained in:
@@ -1021,6 +1021,54 @@ describe('enhanceDataFrame', () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe('modifyQuery', () => {
|
||||
let ds: ElasticDatasource;
|
||||
beforeEach(() => {
|
||||
ds = getTestContext().ds;
|
||||
});
|
||||
describe('with empty query', () => {
|
||||
let query: ElasticsearchQuery;
|
||||
beforeEach(() => {
|
||||
query = { query: '', refId: 'A' };
|
||||
});
|
||||
|
||||
it('should add the filter', () => {
|
||||
expect(ds.modifyQuery(query, { type: 'ADD_FILTER', key: 'foo', value: 'bar' }).query).toBe('foo:"bar"');
|
||||
});
|
||||
|
||||
it('should add the negative filter', () => {
|
||||
expect(ds.modifyQuery(query, { type: 'ADD_FILTER_OUT', key: 'foo', value: 'bar' }).query).toBe('-foo:"bar"');
|
||||
});
|
||||
|
||||
it('should do nothing on unknown type', () => {
|
||||
expect(ds.modifyQuery(query, { type: 'unknown', key: 'foo', value: 'bar' }).query).toBe(query.query);
|
||||
});
|
||||
});
|
||||
|
||||
describe('with non-empty query', () => {
|
||||
let query: ElasticsearchQuery;
|
||||
beforeEach(() => {
|
||||
query = { query: 'test:"value"', refId: 'A' };
|
||||
});
|
||||
|
||||
it('should add the filter', () => {
|
||||
expect(ds.modifyQuery(query, { type: 'ADD_FILTER', key: 'foo', value: 'bar' }).query).toBe(
|
||||
'test:"value" AND foo:"bar"'
|
||||
);
|
||||
});
|
||||
|
||||
it('should add the negative filter', () => {
|
||||
expect(ds.modifyQuery(query, { type: 'ADD_FILTER_OUT', key: 'foo', value: 'bar' }).query).toBe(
|
||||
'test:"value" AND -foo:"bar"'
|
||||
);
|
||||
});
|
||||
|
||||
it('should do nothing on unknown type', () => {
|
||||
expect(ds.modifyQuery(query, { type: 'unknown', key: 'foo', value: 'bar' }).query).toBe(query.query);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
const createElasticQuery = (): DataQueryRequest<ElasticsearchQuery> => {
|
||||
return {
|
||||
requestId: '',
|
||||
|
||||
Reference in New Issue
Block a user