|
|
|
@ -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: '', |
|
|
|
|