Skip to content

Commit

Permalink
Merge branch 'master' into tsvb_table_server
Browse files Browse the repository at this point in the history
  • Loading branch information
kibanamachine authored Jul 26, 2021
2 parents 3f9c936 + 6a50aff commit 7bce86d
Show file tree
Hide file tree
Showing 145 changed files with 6,630 additions and 130 deletions.
2 changes: 1 addition & 1 deletion docs/developer/advanced/running-elasticsearch.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ See all available options, like how to specify a specific license, with the `--h
yarn es snapshot --help
----

`trial` will give you access to all capabilities.
`--license trial` will give you access to all capabilities.

**Keeping data between snapshots**

Expand Down
264 changes: 264 additions & 0 deletions src/plugins/data/common/search/expressions/kibana_context.test.ts
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);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ export const getKibanaContextFn = (
return {
type: 'kibana_context',
query: queries,
filters: uniqFilters(filters).filter((f: any) => !f.meta?.disabled),
filters: uniqFilters(filters.filter((f: any) => !f.meta?.disabled)),
timeRange,
};
},
Expand Down
2 changes: 2 additions & 0 deletions src/plugins/expression_reveal_image/public/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import { CoreSetup, CoreStart, Plugin } from '../../../core/public';
import { ExpressionsStart, ExpressionsSetup } from '../../expressions/public';
import { revealImageRenderer } from './expression_renderers';
import { revealImageFunction } from '../common/expression_functions';

interface SetupDeps {
expressions: ExpressionsSetup;
Expand All @@ -30,6 +31,7 @@ export class ExpressionRevealImagePlugin
StartDeps
> {
public setup(core: CoreSetup, { expressions }: SetupDeps): ExpressionRevealImagePluginSetup {
expressions.registerFunction(revealImageFunction);
expressions.registerRenderer(revealImageRenderer);
}

Expand Down
2 changes: 2 additions & 0 deletions src/plugins/expression_shape/public/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import { CoreSetup, CoreStart, Plugin } from '../../../core/public';
import { ExpressionsStart, ExpressionsSetup } from '../../expressions/public';
import { shapeRenderer } from './expression_renderers';
import { shapeFunction } from '../common/expression_functions';

interface SetupDeps {
expressions: ExpressionsSetup;
Expand All @@ -24,6 +25,7 @@ export type ExpressionShapePluginStart = void;
export class ExpressionShapePlugin
implements Plugin<ExpressionShapePluginSetup, ExpressionShapePluginStart, SetupDeps, StartDeps> {
public setup(core: CoreSetup, { expressions }: SetupDeps): ExpressionShapePluginSetup {
expressions.registerFunction(shapeFunction);
expressions.registerRenderer(shapeRenderer);
}

Expand Down
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);
});
});
});
Loading

0 comments on commit 7bce86d

Please sign in to comment.