-
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.
Merge branch 'master' into tsvb_table_server
- Loading branch information
Showing
145 changed files
with
6,630 additions
and
130 deletions.
There are no files selected for viewing
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
264 changes: 264 additions & 0 deletions
264
src/plugins/data/common/search/expressions/kibana_context.test.ts
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,264 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
import { FilterStateStore, buildFilter, FILTERS } from '@kbn/es-query'; | ||
import type { DeeplyMockedKeys } from '@kbn/utility-types/jest'; | ||
import type { ExecutionContext } from 'src/plugins/expressions/common'; | ||
import { KibanaContext } from './kibana_context_type'; | ||
|
||
import { | ||
getKibanaContextFn, | ||
ExpressionFunctionKibanaContext, | ||
KibanaContextStartDependencies, | ||
} from './kibana_context'; | ||
|
||
type StartServicesMock = DeeplyMockedKeys<KibanaContextStartDependencies>; | ||
|
||
const createExecutionContextMock = (): DeeplyMockedKeys<ExecutionContext> => ({ | ||
abortSignal: {} as any, | ||
getExecutionContext: jest.fn(), | ||
getSearchContext: jest.fn(), | ||
getSearchSessionId: jest.fn(), | ||
inspectorAdapters: jest.fn(), | ||
types: {}, | ||
variables: {}, | ||
getKibanaRequest: jest.fn(), | ||
}); | ||
|
||
const emptyArgs = { q: null, timeRange: null, savedSearchId: null }; | ||
|
||
describe('kibanaContextFn', () => { | ||
let kibanaContextFn: ExpressionFunctionKibanaContext; | ||
let startServicesMock: StartServicesMock; | ||
|
||
const getStartServicesMock = (): Promise<StartServicesMock> => Promise.resolve(startServicesMock); | ||
|
||
beforeEach(async () => { | ||
kibanaContextFn = getKibanaContextFn(getStartServicesMock); | ||
startServicesMock = { | ||
savedObjectsClient: { | ||
create: jest.fn(), | ||
delete: jest.fn(), | ||
find: jest.fn(), | ||
get: jest.fn(), | ||
update: jest.fn(), | ||
}, | ||
}; | ||
}); | ||
|
||
it('merges and deduplicates queries from different sources', async () => { | ||
const { fn } = kibanaContextFn; | ||
startServicesMock.savedObjectsClient.get.mockResolvedValue({ | ||
attributes: { | ||
kibanaSavedObjectMeta: { | ||
searchSourceJSON: JSON.stringify({ | ||
query: [ | ||
{ | ||
language: 'kuery', | ||
query: { | ||
match_phrase: { | ||
DUPLICATE: 'DUPLICATE', | ||
}, | ||
}, | ||
}, | ||
{ | ||
language: 'kuery', | ||
query: { | ||
match_phrase: { | ||
DUPLICATE: 'DUPLICATE', | ||
}, | ||
}, | ||
}, | ||
{ | ||
language: 'kuery', | ||
query: { | ||
match_phrase: { | ||
test: 'something1', | ||
}, | ||
}, | ||
}, | ||
], | ||
}), | ||
}, | ||
}, | ||
} as any); | ||
const args = { | ||
...emptyArgs, | ||
q: { | ||
type: 'kibana_query' as 'kibana_query', | ||
language: 'test', | ||
query: { | ||
type: 'test', | ||
match_phrase: { | ||
test: 'something2', | ||
}, | ||
}, | ||
}, | ||
savedSearchId: 'test', | ||
}; | ||
const input: KibanaContext = { | ||
type: 'kibana_context', | ||
query: [ | ||
{ | ||
language: 'kuery', | ||
query: [ | ||
// TODO: Is it expected that if we pass in an array that the values in the array are not deduplicated? | ||
{ | ||
language: 'kuery', | ||
query: { | ||
match_phrase: { | ||
DUPLICATE: 'DUPLICATE', | ||
}, | ||
}, | ||
}, | ||
{ | ||
language: 'kuery', | ||
query: { | ||
match_phrase: { | ||
DUPLICATE: 'DUPLICATE', | ||
}, | ||
}, | ||
}, | ||
{ | ||
language: 'kuery', | ||
query: { | ||
match_phrase: { | ||
test: 'something3', | ||
}, | ||
}, | ||
}, | ||
], | ||
}, | ||
], | ||
timeRange: { | ||
from: 'now-24h', | ||
to: 'now', | ||
}, | ||
}; | ||
|
||
const { query } = await fn(input, args, createExecutionContextMock()); | ||
|
||
expect(query).toEqual([ | ||
{ | ||
language: 'kuery', | ||
query: [ | ||
{ | ||
language: 'kuery', | ||
query: { | ||
match_phrase: { | ||
DUPLICATE: 'DUPLICATE', | ||
}, | ||
}, | ||
}, | ||
{ | ||
language: 'kuery', | ||
query: { | ||
match_phrase: { | ||
DUPLICATE: 'DUPLICATE', | ||
}, | ||
}, | ||
}, | ||
{ | ||
language: 'kuery', | ||
query: { | ||
match_phrase: { | ||
test: 'something3', | ||
}, | ||
}, | ||
}, | ||
], | ||
}, | ||
{ | ||
type: 'kibana_query', | ||
language: 'test', | ||
query: { | ||
type: 'test', | ||
match_phrase: { | ||
test: 'something2', | ||
}, | ||
}, | ||
}, | ||
{ | ||
language: 'kuery', | ||
query: { | ||
match_phrase: { | ||
DUPLICATE: 'DUPLICATE', | ||
}, | ||
}, | ||
}, | ||
{ | ||
language: 'kuery', | ||
query: { | ||
match_phrase: { | ||
test: 'something1', | ||
}, | ||
}, | ||
}, | ||
]); | ||
}); | ||
|
||
it('deduplicates duplicated filters and keeps the first enabled filter', async () => { | ||
const { fn } = kibanaContextFn; | ||
const filter1 = buildFilter( | ||
{ fields: [] }, | ||
{ name: 'test', type: 'test' }, | ||
FILTERS.PHRASE, | ||
false, | ||
true, | ||
{ | ||
query: 'JetBeats', | ||
}, | ||
null, | ||
FilterStateStore.APP_STATE | ||
); | ||
const filter2 = buildFilter( | ||
{ fields: [] }, | ||
{ name: 'test', type: 'test' }, | ||
FILTERS.PHRASE, | ||
false, | ||
false, | ||
{ | ||
query: 'JetBeats', | ||
}, | ||
null, | ||
FilterStateStore.APP_STATE | ||
); | ||
|
||
const filter3 = buildFilter( | ||
{ fields: [] }, | ||
{ name: 'test', type: 'test' }, | ||
FILTERS.PHRASE, | ||
false, | ||
false, | ||
{ | ||
query: 'JetBeats', | ||
}, | ||
null, | ||
FilterStateStore.APP_STATE | ||
); | ||
|
||
const input: KibanaContext = { | ||
type: 'kibana_context', | ||
query: [ | ||
{ | ||
language: 'kuery', | ||
query: '', | ||
}, | ||
], | ||
filters: [filter1, filter2, filter3], | ||
timeRange: { | ||
from: 'now-24h', | ||
to: 'now', | ||
}, | ||
}; | ||
|
||
const { filters } = await fn(input, emptyArgs, createExecutionContextMock()); | ||
expect(filters!.length).toBe(1); | ||
expect(filters![0]).toBe(filter2); | ||
}); | ||
}); |
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
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
69 changes: 69 additions & 0 deletions
69
...plications/app_search/components/crawler/components/add_domain/add_domain_flyout.test.tsx
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,69 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
import React from 'react'; | ||
|
||
import { shallow, ShallowWrapper } from 'enzyme'; | ||
|
||
import { EuiButton, EuiButtonEmpty, EuiFlyout, EuiFlyoutBody } from '@elastic/eui'; | ||
|
||
import { AddDomainFlyout } from './add_domain_flyout'; | ||
import { AddDomainForm } from './add_domain_form'; | ||
import { AddDomainFormErrors } from './add_domain_form_errors'; | ||
import { AddDomainFormSubmitButton } from './add_domain_form_submit_button'; | ||
|
||
describe('AddDomainFlyout', () => { | ||
beforeEach(() => { | ||
jest.clearAllMocks(); | ||
}); | ||
|
||
it('is hidden by default', () => { | ||
const wrapper = shallow(<AddDomainFlyout />); | ||
|
||
expect(wrapper.find(EuiFlyout)).toHaveLength(0); | ||
}); | ||
|
||
it('displays the flyout when the button is pressed', () => { | ||
const wrapper = shallow(<AddDomainFlyout />); | ||
|
||
wrapper.find(EuiButton).simulate('click'); | ||
|
||
expect(wrapper.find(EuiFlyout)).toHaveLength(1); | ||
}); | ||
|
||
describe('flyout', () => { | ||
let wrapper: ShallowWrapper; | ||
|
||
beforeEach(() => { | ||
wrapper = shallow(<AddDomainFlyout />); | ||
|
||
wrapper.find(EuiButton).simulate('click'); | ||
}); | ||
|
||
it('displays form errors', () => { | ||
expect(wrapper.find(EuiFlyoutBody).dive().find(AddDomainFormErrors)).toHaveLength(1); | ||
}); | ||
|
||
it('contains a form to add domains', () => { | ||
expect(wrapper.find(AddDomainForm)).toHaveLength(1); | ||
}); | ||
|
||
it('contains a cancel buttonn', () => { | ||
wrapper.find(EuiButtonEmpty).simulate('click'); | ||
expect(wrapper.find(EuiFlyout)).toHaveLength(0); | ||
}); | ||
|
||
it('contains a submit button', () => { | ||
expect(wrapper.find(AddDomainFormSubmitButton)).toHaveLength(1); | ||
}); | ||
|
||
it('hides the flyout on close', () => { | ||
wrapper.find(EuiFlyout).simulate('close'); | ||
|
||
expect(wrapper.find(EuiFlyout)).toHaveLength(0); | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.