Skip to content

Commit

Permalink
Merge branch 'master' into update-exp-view-formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
shahzad31 committed Jun 8, 2021
2 parents 420d622 + 451f64b commit 3b936d7
Show file tree
Hide file tree
Showing 208 changed files with 2,558 additions and 2,252 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@
"dependencies": {
"@elastic/apm-rum": "^5.6.1",
"@elastic/apm-rum-react": "^1.2.5",
"@elastic/charts": "29.2.0",
"@elastic/charts": "30.0.0",
"@elastic/datemath": "link:bazel-bin/packages/elastic-datemath",
"@elastic/elasticsearch": "npm:@elastic/elasticsearch-canary@^8.0.0-canary.4",
"@elastic/ems-client": "7.13.0",
Expand Down
6 changes: 5 additions & 1 deletion src/plugins/data/common/search/search_source/mocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ export const searchSourceCommonMock: jest.Mocked<ISearchStartSearchSource> = {
export const createSearchSourceMock = (fields?: SearchSourceFields) =>
new SearchSource(fields, {
getConfig: uiSettingsServiceMock.createStartContract().get,
search: jest.fn(),
search: jest
.fn()
.mockReturnValue(
of({ rawResponse: { hits: { hits: [], total: 0 } }, isPartial: false, isRunning: false })
),
onResponse: jest.fn().mockImplementation((req, res) => res),
});
Original file line number Diff line number Diff line change
Expand Up @@ -699,7 +699,7 @@ export class SearchSource {
searchRequest.body = searchRequest.body || {};
const { body, index, query, filters, highlightAll } = searchRequest;
searchRequest.indexType = this.getIndexType(index);
const metaFields = getConfig(UI_SETTINGS.META_FIELDS);
const metaFields = getConfig(UI_SETTINGS.META_FIELDS) ?? [];

// get some special field types from the index pattern
const { docvalueFields, scriptFields, storedFields, runtimeFields } = index
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,13 @@
*/

import { QueryStringContract } from '.';
import { Observable } from 'rxjs';

const createSetupContractMock = () => {
const queryStringManagerMock: jest.Mocked<QueryStringContract> = {
getQuery: jest.fn(),
setQuery: jest.fn(),
getUpdates$: jest.fn(),
getUpdates$: jest.fn(() => new Observable()),
getDefaultQuery: jest.fn(),
formatQuery: jest.fn(),
clearQuery: jest.fn(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const createSetupContractMock = () => {
getTimeUpdate$: jest.fn(),
getRefreshIntervalUpdate$: jest.fn(),
getAutoRefreshFetch$: jest.fn(() => new Observable<() => void>()),
getFetch$: jest.fn(),
getFetch$: jest.fn(() => new Observable<() => void>()),
getTime: jest.fn(),
setTime: jest.fn(),
setRefreshInterval: jest.fn(),
Expand Down
4 changes: 4 additions & 0 deletions src/plugins/discover/public/__mocks__/index_pattern.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,10 @@ fields.getByName = (name: string) => {
return fields.find((field) => field.name === name);
};

fields.getAll = () => {
return fields;
};

const indexPattern = ({
id: 'the-index-pattern-id',
title: 'the-index-pattern-title',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ const fields = [
fields.getByName = (name: string) => {
return fields.find((field) => field.name === name);
};
fields.getAll = () => {
return fields;
};

const indexPattern = ({
id: 'index-pattern-with-timefield-id',
Expand All @@ -72,5 +75,8 @@ const indexPattern = ({

indexPattern.flattenHit = indexPatterns.flattenHitWrapper(indexPattern, indexPattern.metaFields);
indexPattern.isTimeBased = () => !!indexPattern.timeFieldName;
indexPattern.formatField = (hit: Record<string, unknown>, fieldName: string) => {
return fieldName === '_source' ? hit._source : indexPattern.flattenHit(hit)[fieldName];
};

export const indexPatternWithTimefieldMock = indexPattern;
3 changes: 3 additions & 0 deletions src/plugins/discover/public/__mocks__/saved_search.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
*/

import { SavedSearch } from '../saved_searches';
import { createSearchSourceMock } from '../../../data/public/mocks';
import { indexPatternMock } from './index_pattern';

export const savedSearchMock = ({
id: 'the-saved-search-id',
Expand All @@ -27,4 +29,5 @@ export const savedSearchMock = ({
],
migrationVersion: { search: '7.5.0' },
error: undefined,
searchSource: createSearchSourceMock({ index: indexPatternMock }),
} as unknown) as SavedSearch;
27 changes: 27 additions & 0 deletions src/plugins/discover/public/__mocks__/search_session.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
* 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 { createMemoryHistory } from 'history';
import { dataPluginMock } from '../../../data/public/mocks';
import { DataPublicPluginStart } from '../../../data/public';
import { DiscoverSearchSessionManager } from '../application/apps/main/services/discover_search_session';

export function createSearchSessionMock() {
const history = createMemoryHistory();
const session = dataPluginMock.createStartContract().search.session as jest.Mocked<
DataPublicPluginStart['search']['session']
>;
const searchSessionManager = new DiscoverSearchSessionManager({
history,
session,
});
return {
history,
session,
searchSessionManager,
};
}
63 changes: 63 additions & 0 deletions src/plugins/discover/public/__mocks__/services.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/*
* 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 { DiscoverServices } from '../build_services';
import { dataPluginMock } from '../../../data/public/mocks';
import { chromeServiceMock, coreMock, docLinksServiceMock } from '../../../../core/public/mocks';
import { DEFAULT_COLUMNS_SETTING } from '../../common';
import { savedSearchMock } from './saved_search';
import { UI_SETTINGS } from '../../../data/common';
import { TopNavMenu } from '../../../navigation/public';
const dataPlugin = dataPluginMock.createStartContract();

export const discoverServiceMock = ({
core: coreMock.createStart(),
chrome: chromeServiceMock.createStartContract(),
history: () => ({
location: {
search: '',
},
}),
data: dataPlugin,
docLinks: docLinksServiceMock.createStartContract(),
capabilities: {
visualize: {
show: true,
},
discover: {
save: false,
},
advancedSettings: {
save: true,
},
},
filterManager: dataPlugin.query.filterManager,
uiSettings: {
get: (key: string) => {
if (key === 'fields:popularLimit') {
return 5;
} else if (key === DEFAULT_COLUMNS_SETTING) {
return [];
} else if (key === UI_SETTINGS.META_FIELDS) {
return [];
}
},
},
indexPatternFieldEditor: {
openEditor: jest.fn(),
userPermissions: {
editIndexPattern: jest.fn(),
},
},
getSavedSearchById: (id?: string) => Promise.resolve(savedSearchMock),
navigation: {
ui: { TopNavMenu },
},
metadata: {
branch: 'test',
},
} as unknown) as DiscoverServices;
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/*
* 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 { DiscoverMainApp } from '../apps/main';

// eslint-disable-next-line @typescript-eslint/no-explicit-any
export function createDiscoverDirective(reactDirective: any) {
return reactDirective(DiscoverMainApp, [
['indexPattern', { watchDepth: 'reference' }],
['opts', { watchDepth: 'reference' }],
]);
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
*/
import React, { useState } from 'react';
import { I18nProvider } from '@kbn/i18n/react';
import { DiscoverGrid, DiscoverGridProps } from './discover_grid/discover_grid';
import { DiscoverGrid, DiscoverGridProps } from '../components/discover_grid/discover_grid';
import { getServices } from '../../kibana_services';
import { ElasticSearchHit } from '../doc_views/doc_views_types';

Expand Down

This file was deleted.

Loading

0 comments on commit 3b936d7

Please sign in to comment.