From 92d41a65777c5e4f6147036f72906b96590ff9d0 Mon Sep 17 00:00:00 2001 From: Walter Rafelsberger Date: Tue, 10 Mar 2020 09:18:22 +0100 Subject: [PATCH 1/7] [ML] Replace KqlFilterBar with QueryStringInput. --- .../public/__mocks__/shared_imports.ts | 2 - x-pack/plugins/transform/public/app/app.tsx | 24 ++++-- .../transform/public/app/app_dependencies.tsx | 52 +----------- .../step_define/step_define_form.tsx | 83 ++++++++++++++----- .../transform/public/shared_imports.ts | 14 ---- 5 files changed, 84 insertions(+), 91 deletions(-) diff --git a/x-pack/plugins/transform/public/__mocks__/shared_imports.ts b/x-pack/plugins/transform/public/__mocks__/shared_imports.ts index bc8ace2932c0e..494b5824dc250 100644 --- a/x-pack/plugins/transform/public/__mocks__/shared_imports.ts +++ b/x-pack/plugins/transform/public/__mocks__/shared_imports.ts @@ -8,7 +8,6 @@ jest.mock('ui/new_platform'); export const expandLiteralStrings = jest.fn(); export const XJsonMode = jest.fn(); -export const setDependencyCache = jest.fn(); export const useRequest = jest.fn(() => ({ isLoading: false, error: null, @@ -16,4 +15,3 @@ export const useRequest = jest.fn(() => ({ })); export { mlInMemoryTableBasicFactory } from '../../../../legacy/plugins/ml/public/application/components/ml_in_memory_table'; export const SORT_DIRECTION = { ASC: 'asc' }; -export const KqlFilterBar = jest.fn(() => null); diff --git a/x-pack/plugins/transform/public/app/app.tsx b/x-pack/plugins/transform/public/app/app.tsx index 644aedec3eac0..4db0566411440 100644 --- a/x-pack/plugins/transform/public/app/app.tsx +++ b/x-pack/plugins/transform/public/app/app.tsx @@ -10,10 +10,14 @@ import { HashRouter, Redirect, Route, Switch } from 'react-router-dom'; import { FormattedMessage } from '@kbn/i18n/react'; +import { KibanaContextProvider } from '../../../../../src/plugins/kibana_react/public'; +import { Storage } from '../../../../../src/plugins/kibana_utils/public'; + +import { API_BASE_PATH } from '../../common/constants'; + import { SectionError } from './components'; import { CLIENT_BASE_PATH, SECTION_SLUG } from './constants'; -import { getAppProviders } from './app_dependencies'; -import { AuthorizationContext } from './lib/authorization'; +import { AuthorizationContext, AuthorizationProvider } from './lib/authorization'; import { AppDependencies } from './app_dependencies'; import { CloneTransformSection } from './sections/clone_transform'; @@ -60,13 +64,21 @@ export const App: FC = () => { ); }; +const localStorage = new Storage(window.localStorage); + export const renderApp = (element: HTMLElement, appDependencies: AppDependencies) => { - const Providers = getAppProviders(appDependencies); + const I18nContext = appDependencies.i18n.Context; render( - - - , + + + + + + + + + , element ); diff --git a/x-pack/plugins/transform/public/app/app_dependencies.tsx b/x-pack/plugins/transform/public/app/app_dependencies.tsx index 37258dc777d87..241a208d19b6e 100644 --- a/x-pack/plugins/transform/public/app/app_dependencies.tsx +++ b/x-pack/plugins/transform/public/app/app_dependencies.tsx @@ -4,17 +4,11 @@ * you may not use this file except in compliance with the Elastic License. */ -import React, { createContext, useContext, ReactNode } from 'react'; -import { HashRouter } from 'react-router-dom'; - import { CoreSetup, CoreStart } from 'src/core/public'; import { DataPublicPluginStart } from 'src/plugins/data/public'; -import { API_BASE_PATH } from '../../common/constants'; - -import { setDependencyCache } from '../shared_imports'; - -import { AuthorizationProvider } from './lib/authorization'; +import { useKibana } from '../../../../../src/plugins/kibana_react/public'; +import { Storage } from '../../../../../src/plugins/kibana_utils/public'; export interface AppDependencies { chrome: CoreStart['chrome']; @@ -25,33 +19,12 @@ export interface AppDependencies { notifications: CoreStart['notifications']; uiSettings: CoreStart['uiSettings']; savedObjects: CoreStart['savedObjects']; + storage: Storage; overlays: CoreStart['overlays']; } -let DependenciesContext: React.Context; - -const setAppDependencies = (deps: AppDependencies) => { - const legacyBasePath = { - prepend: deps.http.basePath.prepend, - get: deps.http.basePath.get, - remove: () => {}, - }; - - setDependencyCache({ - autocomplete: deps.data.autocomplete, - docLinks: deps.docLinks, - basePath: legacyBasePath as any, - }); - DependenciesContext = createContext(deps); - return DependenciesContext.Provider; -}; - export const useAppDependencies = () => { - if (!DependenciesContext) { - throw new Error(`The app dependencies Context hasn't been set. - Use the "setAppDependencies()" method when bootstrapping the app.`); - } - return useContext(DependenciesContext); + return useKibana().services as AppDependencies; }; export const useToastNotifications = () => { @@ -60,20 +33,3 @@ export const useToastNotifications = () => { } = useAppDependencies(); return toastNotifications; }; - -export const getAppProviders = (deps: AppDependencies) => { - const I18nContext = deps.i18n.Context; - - // Create App dependencies context and get its provider - const AppDependenciesProvider = setAppDependencies(deps); - - return ({ children }: { children: ReactNode }) => ( - - - - {children} - - - - ); -}; diff --git a/x-pack/plugins/transform/public/app/sections/create_transform/components/step_define/step_define_form.tsx b/x-pack/plugins/transform/public/app/sections/create_transform/components/step_define/step_define_form.tsx index 5b6283fc4777d..5ce14a208f8f7 100644 --- a/x-pack/plugins/transform/public/app/sections/create_transform/components/step_define/step_define_form.tsx +++ b/x-pack/plugins/transform/public/app/sections/create_transform/components/step_define/step_define_form.tsx @@ -20,13 +20,18 @@ import { EuiHorizontalRule, EuiLink, EuiPanel, - // @ts-ignore - EuiSearchBar, EuiSpacer, EuiSwitch, } from '@elastic/eui'; +import { + esKuery, + Query, + QueryStringInput, +} from '../../../../../../../../../src/plugins/data/public'; + import { PivotPreview } from '../../../../components/pivot_preview'; + import { useDocumentationLinks } from '../../../../hooks/use_documentation_links'; import { SavedSearchQuery, SearchItems } from '../../../../hooks/use_search_items'; import { useXJsonMode, xJsonMode } from '../../../../hooks/use_x_json_mode'; @@ -37,7 +42,6 @@ import { DropDown } from '../aggregation_dropdown'; import { AggListForm } from '../aggregation_list'; import { GroupByListForm } from '../group_by_list'; import { SourceIndexPreview } from '../source_index_preview'; -import { KqlFilterBar } from '../../../../../shared_imports'; import { SwitchModal } from './switch_modal'; import { @@ -74,6 +78,11 @@ export interface StepDefineExposedState { const defaultSearch = '*'; const emptySearch = ''; +enum QUERY_LANGUAGE { + KUERY = 'kuery', + LUCENE = 'lucene', +} + export function getDefaultStepDefineState(searchItems: SearchItems): StepDefineExposedState { return { aggList: {} as PivotAggsConfigDict, @@ -244,23 +253,41 @@ export const StepDefineForm: FC = React.memo(({ overrides = {}, onChange, const defaults = { ...getDefaultStepDefineState(searchItems), ...overrides }; // The search filter + const [searchInput, setSearchInput] = useState({ + query: '', + language: QUERY_LANGUAGE.KUERY as string, + }); const [searchString, setSearchString] = useState(defaults.searchString); const [searchQuery, setSearchQuery] = useState(defaults.searchQuery); const [useKQL] = useState(true); - const searchHandler = (d: Record) => { - const { filterQuery, queryString } = d; - const newSearch = queryString === emptySearch ? defaultSearch : queryString; + const { indexPattern } = searchItems; + + const searchChangeHandler = (query: Query) => setSearchInput(query); + const searchSubmitHandler = (query: Query) => { + let queryString = ''; + let filterQuery = { match_all: {} } as Dictionary; + + if (query.language === QUERY_LANGUAGE.KUERY && typeof query.query === 'string') { + filterQuery = esKuery.toElasticsearchQuery( + esKuery.fromKueryExpression(query.query as string), + indexPattern + ); + } else if (typeof query.query === 'string') { + queryString = query.query; + } else { + filterQuery = query.query; + } + + const newSearchString = queryString === emptySearch ? defaultSearch : queryString; const newSearchQuery = isMatchAllQuery(filterQuery) ? defaultSearch : filterQuery; - setSearchString(newSearch); + setSearchString(newSearchString); setSearchQuery(newSearchQuery); }; // The list of selected group by fields const [groupByList, setGroupByList] = useState(defaults.groupByList); - const { indexPattern } = searchItems; - const { groupByOptions, groupByOptionsData, @@ -592,18 +619,32 @@ export const StepDefineForm: FC = React.memo(({ overrides = {}, onChange, defaultMessage: 'Use a query to filter the source data (optional).', })} > - )} diff --git a/x-pack/plugins/transform/public/shared_imports.ts b/x-pack/plugins/transform/public/shared_imports.ts index 4def1bc98ef8c..938ec77344d8f 100644 --- a/x-pack/plugins/transform/public/shared_imports.ts +++ b/x-pack/plugins/transform/public/shared_imports.ts @@ -12,20 +12,6 @@ export { } from '../../../../src/plugins/es_ui_shared/console_lang/lib'; export { - SendRequestConfig, - SendRequestResponse, UseRequestConfig, - sendRequest, useRequest, } from '../../../../src/plugins/es_ui_shared/public/request/np_ready_request'; - -export { - CronEditor, - DAY, -} from '../../../../src/plugins/es_ui_shared/public/components/cron_editor'; - -// Needs to be imported because we're reusing KqlFilterBar which depends on it. -export { setDependencyCache } from '../../../legacy/plugins/ml/public/application/util/dependency_cache'; - -// @ts-ignore: could not find declaration file for module -export { KqlFilterBar } from '../../../legacy/plugins/ml/public/application/components/kql_filter_bar'; From c3bb36ba255954d336d5351bad36b67b2ca016a2 Mon Sep 17 00:00:00 2001 From: Walter Rafelsberger Date: Tue, 10 Mar 2020 15:07:23 +0100 Subject: [PATCH 2/7] [ML] Update tests. --- x-pack/plugins/transform/public/app/app.tsx | 9 ++------- ...pendencies.mock.ts => app_dependencies.mock.tsx} | 13 ++++++++++--- .../transform/public/app/app_dependencies.tsx | 2 +- x-pack/plugins/transform/public/plugin.ts | 5 +++++ 4 files changed, 18 insertions(+), 11 deletions(-) rename x-pack/plugins/transform/public/app/{app_dependencies.mock.ts => app_dependencies.mock.tsx} (62%) diff --git a/x-pack/plugins/transform/public/app/app.tsx b/x-pack/plugins/transform/public/app/app.tsx index 4db0566411440..01ff7f5bff27f 100644 --- a/x-pack/plugins/transform/public/app/app.tsx +++ b/x-pack/plugins/transform/public/app/app.tsx @@ -11,7 +11,6 @@ import { HashRouter, Redirect, Route, Switch } from 'react-router-dom'; import { FormattedMessage } from '@kbn/i18n/react'; import { KibanaContextProvider } from '../../../../../src/plugins/kibana_react/public'; -import { Storage } from '../../../../../src/plugins/kibana_utils/public'; import { API_BASE_PATH } from '../../common/constants'; @@ -64,18 +63,14 @@ export const App: FC = () => { ); }; -const localStorage = new Storage(window.localStorage); - export const renderApp = (element: HTMLElement, appDependencies: AppDependencies) => { const I18nContext = appDependencies.i18n.Context; render( - + - - - + , diff --git a/x-pack/plugins/transform/public/app/app_dependencies.mock.ts b/x-pack/plugins/transform/public/app/app_dependencies.mock.tsx similarity index 62% rename from x-pack/plugins/transform/public/app/app_dependencies.mock.ts rename to x-pack/plugins/transform/public/app/app_dependencies.mock.tsx index 4e5af1eca7bd0..2158dc9315fa5 100644 --- a/x-pack/plugins/transform/public/app/app_dependencies.mock.ts +++ b/x-pack/plugins/transform/public/app/app_dependencies.mock.tsx @@ -4,10 +4,14 @@ * you may not use this file except in compliance with the Elastic License. */ +import React, { FC } from 'react'; + import { coreMock } from '../../../../../src/core/public/mocks'; import { dataPluginMock } from '../../../../../src/plugins/data/public/mocks'; +import { KibanaContextProvider } from '../../../../../src/plugins/kibana_react/public'; +import { Storage } from '../../../../../src/plugins/kibana_utils/public'; -import { getAppProviders, AppDependencies } from './app_dependencies'; +import { AppDependencies } from './app_dependencies'; const coreSetup = coreMock.createSetup(); const coreStart = coreMock.createStart(); @@ -18,11 +22,14 @@ const appDependencies: AppDependencies = { data: dataStart, docLinks: coreStart.docLinks, i18n: coreStart.i18n, - notifications: coreStart.notifications, + notifications: coreSetup.notifications, uiSettings: coreStart.uiSettings, savedObjects: coreStart.savedObjects, + storage: ({ get: jest.fn() } as unknown) as Storage, overlays: coreStart.overlays, http: coreSetup.http, }; -export const Providers = getAppProviders(appDependencies); +export const Providers: FC = ({ children }) => { + return {children}; +}; diff --git a/x-pack/plugins/transform/public/app/app_dependencies.tsx b/x-pack/plugins/transform/public/app/app_dependencies.tsx index 241a208d19b6e..87db02988adf0 100644 --- a/x-pack/plugins/transform/public/app/app_dependencies.tsx +++ b/x-pack/plugins/transform/public/app/app_dependencies.tsx @@ -16,7 +16,7 @@ export interface AppDependencies { docLinks: CoreStart['docLinks']; http: CoreSetup['http']; i18n: CoreStart['i18n']; - notifications: CoreStart['notifications']; + notifications: CoreSetup['notifications']; uiSettings: CoreStart['uiSettings']; savedObjects: CoreStart['savedObjects']; storage: Storage; diff --git a/x-pack/plugins/transform/public/plugin.ts b/x-pack/plugins/transform/public/plugin.ts index 1a34e7a641365..9a83f5b0e05f3 100644 --- a/x-pack/plugins/transform/public/plugin.ts +++ b/x-pack/plugins/transform/public/plugin.ts @@ -9,12 +9,16 @@ import { CoreSetup } from 'src/core/public'; import { DataPublicPluginStart } from 'src/plugins/data/public'; import { ManagementSetup } from 'src/plugins/management/public'; +import { Storage } from '../../../../src/plugins/kibana_utils/public'; + import { renderApp } from './app/app'; import { AppDependencies } from './app/app_dependencies'; import { breadcrumbService } from './app/services/navigation'; import { docTitleService } from './app/services/navigation'; import { textService } from './app/services/text'; +const localStorage = new Storage(window.localStorage); + export interface PluginsDependencies { data: DataPublicPluginStart; management: ManagementSetup; @@ -56,6 +60,7 @@ export class TransformUiPlugin { notifications, overlays, savedObjects, + storage: localStorage, uiSettings, }; From 82ad8968e4c9e0fc9919bfebdc232da6c2b7aec0 Mon Sep 17 00:00:00 2001 From: Walter Rafelsberger Date: Wed, 11 Mar 2020 17:32:30 +0100 Subject: [PATCH 3/7] [ML] Improve query bar implementation. --- .../step_define/step_define_form.tsx | 48 +++++++------------ .../components/step_define/switch_modal.tsx | 4 +- 2 files changed, 18 insertions(+), 34 deletions(-) diff --git a/x-pack/plugins/transform/public/app/sections/create_transform/components/step_define/step_define_form.tsx b/x-pack/plugins/transform/public/app/sections/create_transform/components/step_define/step_define_form.tsx index 5ce14a208f8f7..b9a68ea3c155e 100644 --- a/x-pack/plugins/transform/public/app/sections/create_transform/components/step_define/step_define_form.tsx +++ b/x-pack/plugins/transform/public/app/sections/create_transform/components/step_define/step_define_form.tsx @@ -26,6 +26,7 @@ import { import { esKuery, + esQuery, Query, QueryStringInput, } from '../../../../../../../../../src/plugins/data/public'; @@ -47,7 +48,6 @@ import { SwitchModal } from './switch_modal'; import { getPivotQuery, getPreviewRequestBody, - isMatchAllQuery, matchAllQuery, AggName, DropDownLabel, @@ -69,14 +69,12 @@ export interface StepDefineExposedState { groupByList: PivotGroupByConfigDict; isAdvancedPivotEditorEnabled: boolean; isAdvancedSourceEditorEnabled: boolean; - searchString: string | SavedSearchQuery; searchQuery: string | SavedSearchQuery; sourceConfigUpdated: boolean; valid: boolean; } const defaultSearch = '*'; -const emptySearch = ''; enum QUERY_LANGUAGE { KUERY = 'kuery', @@ -89,7 +87,6 @@ export function getDefaultStepDefineState(searchItems: SearchItems): StepDefineE groupByList: {} as PivotGroupByConfigDict, isAdvancedPivotEditorEnabled: false, isAdvancedSourceEditorEnabled: false, - searchString: searchItems.savedSearch !== undefined ? searchItems.combinedQuery : defaultSearch, searchQuery: searchItems.savedSearch !== undefined ? searchItems.combinedQuery : defaultSearch, sourceConfigUpdated: false, valid: false, @@ -135,7 +132,6 @@ export function applyTransformConfigToDefineState( const query = transformConfig.source.query; if (query !== undefined && !isEqual(query, matchAllQuery)) { state.isAdvancedSourceEditorEnabled = true; - state.searchString = ''; state.searchQuery = query; state.sourceConfigUpdated = true; } @@ -257,32 +253,25 @@ export const StepDefineForm: FC = React.memo(({ overrides = {}, onChange, query: '', language: QUERY_LANGUAGE.KUERY as string, }); - const [searchString, setSearchString] = useState(defaults.searchString); const [searchQuery, setSearchQuery] = useState(defaults.searchQuery); - const [useKQL] = useState(true); const { indexPattern } = searchItems; const searchChangeHandler = (query: Query) => setSearchInput(query); const searchSubmitHandler = (query: Query) => { - let queryString = ''; - let filterQuery = { match_all: {} } as Dictionary; - - if (query.language === QUERY_LANGUAGE.KUERY && typeof query.query === 'string') { - filterQuery = esKuery.toElasticsearchQuery( - esKuery.fromKueryExpression(query.query as string), - indexPattern - ); - } else if (typeof query.query === 'string') { - queryString = query.query; - } else { - filterQuery = query.query; + switch (query.language) { + case QUERY_LANGUAGE.KUERY: + setSearchQuery( + esKuery.toElasticsearchQuery( + esKuery.fromKueryExpression(query.query as string), + indexPattern + ) + ); + return; + case QUERY_LANGUAGE.LUCENE: + setSearchQuery(esQuery.luceneStringToDsl(query.query as string)); + return; } - - const newSearchString = queryString === emptySearch ? defaultSearch : queryString; - const newSearchQuery = isMatchAllQuery(filterQuery) ? defaultSearch : filterQuery; - setSearchString(newSearchString); - setSearchQuery(newSearchQuery); }; // The list of selected group by fields @@ -376,7 +365,7 @@ export const StepDefineForm: FC = React.memo(({ overrides = {}, onChange, const pivotAggsArr = dictionaryToArray(aggList); const pivotGroupByArr = dictionaryToArray(groupByList); - const pivotQuery = useKQL ? getPivotQuery(searchQuery) : getPivotQuery(searchString); + const pivotQuery = getPivotQuery(searchQuery); // Advanced editor for pivot config state const [isAdvancedEditorSwitchModalVisible, setAdvancedEditorSwitchModalVisible] = useState(false); @@ -436,8 +425,6 @@ export const StepDefineForm: FC = React.memo(({ overrides = {}, onChange, const applyAdvancedSourceEditorChanges = () => { const sourceConfig = JSON.parse(advancedEditorSourceConfig); const prettySourceConfig = JSON.stringify(sourceConfig, null, 2); - // Switched to editor so we clear out the search string as the bar won't be visible - setSearchString(emptySearch); setSearchQuery(sourceConfig); setSourceConfigUpdated(true); setAdvancedEditorSourceConfig(prettySourceConfig); @@ -498,7 +485,6 @@ export const StepDefineForm: FC = React.memo(({ overrides = {}, onChange, const toggleAdvancedSourceEditor = (reset = false) => { if (reset === true) { setSearchQuery(defaultSearch); - setSearchString(defaultSearch); setSourceConfigUpdated(false); } if (isAdvancedSourceEditorEnabled === false) { @@ -559,7 +545,6 @@ export const StepDefineForm: FC = React.memo(({ overrides = {}, onChange, groupByList, isAdvancedPivotEditorEnabled, isAdvancedSourceEditorEnabled, - searchString, searchQuery, sourceConfigUpdated, valid, @@ -571,7 +556,6 @@ export const StepDefineForm: FC = React.memo(({ overrides = {}, onChange, JSON.stringify(pivotGroupByArr), isAdvancedPivotEditorEnabled, isAdvancedSourceEditorEnabled, - searchString, searchQuery, valid, /* eslint-enable react-hooks/exhaustive-deps */ @@ -587,7 +571,7 @@ export const StepDefineForm: FC = React.memo(({ overrides = {}, onChange,
- {searchItems.savedSearch === undefined && typeof searchString === 'string' && ( + {searchItems.savedSearch === undefined && ( = React.memo(({ overrides = {}, onChange, 'xpack.transform.stepDefineForm.queryPlaceholderLucene', { defaultMessage: 'e.g. {example}', - values: { example: 'sample lucene query' }, + values: { example: 'method:GET OR status:404' }, } ) } diff --git a/x-pack/plugins/transform/public/app/sections/create_transform/components/step_define/switch_modal.tsx b/x-pack/plugins/transform/public/app/sections/create_transform/components/step_define/switch_modal.tsx index 43d024a8e869d..0a4b5b6e58008 100644 --- a/x-pack/plugins/transform/public/app/sections/create_transform/components/step_define/switch_modal.tsx +++ b/x-pack/plugins/transform/public/app/sections/create_transform/components/step_define/switch_modal.tsx @@ -34,7 +34,7 @@ const pivotModalMessage = i18n.translate( const sourceModalMessage = i18n.translate( 'xpack.transform.stepDefineForm.advancedSourceEditorSwitchModalBodyText', { - defaultMessage: `By switching back to KQL query bar you will lose your edits.`, + defaultMessage: `By switching back to the query bar you will lose your edits.`, } ); const pivotModalConfirmButtonText = i18n.translate( @@ -46,7 +46,7 @@ const pivotModalConfirmButtonText = i18n.translate( const sourceModalConfirmButtonText = i18n.translate( 'xpack.transform.stepDefineForm.advancedSourceEditorSwitchModalConfirmButtonText', { - defaultMessage: 'Switch to KQL', + defaultMessage: 'Switch to query bar', } ); const cancelButtonText = i18n.translate( From c6357c3ff86cfee8bedc42210e3b6033af57f728 Mon Sep 17 00:00:00 2001 From: Walter Rafelsberger Date: Wed, 11 Mar 2020 19:00:00 +0100 Subject: [PATCH 4/7] [ML] Fix tests. Improve kuery/lucene input. --- .../public/__mocks__/shared_imports.ts | 2 - .../public/app/common/request.test.ts | 1 + .../pivot_preview/pivot_preview.test.tsx | 1 - .../toast_notification_text.test.tsx | 1 - .../source_index_preview.test.tsx | 1 - .../step_create/step_create_form.test.tsx | 1 - .../step_define/step_define_form.test.tsx | 1 - .../step_define/step_define_form.tsx | 37 +++++--- .../step_define/step_define_summary.test.tsx | 2 +- .../step_define/step_define_summary.tsx | 85 +++++++------------ .../transform_list/action_delete.test.tsx | 1 - .../transform_list/action_start.test.tsx | 1 - .../transform_list/action_stop.test.tsx | 1 - 13 files changed, 62 insertions(+), 73 deletions(-) diff --git a/x-pack/plugins/transform/public/__mocks__/shared_imports.ts b/x-pack/plugins/transform/public/__mocks__/shared_imports.ts index 494b5824dc250..62ddc13566be8 100644 --- a/x-pack/plugins/transform/public/__mocks__/shared_imports.ts +++ b/x-pack/plugins/transform/public/__mocks__/shared_imports.ts @@ -4,8 +4,6 @@ * you may not use this file except in compliance with the Elastic License. */ -jest.mock('ui/new_platform'); - export const expandLiteralStrings = jest.fn(); export const XJsonMode = jest.fn(); export const useRequest = jest.fn(() => ({ diff --git a/x-pack/plugins/transform/public/app/common/request.test.ts b/x-pack/plugins/transform/public/app/common/request.test.ts index 0720c654d5029..4c3fba3bbf8dd 100644 --- a/x-pack/plugins/transform/public/app/common/request.test.ts +++ b/x-pack/plugins/transform/public/app/common/request.test.ts @@ -143,6 +143,7 @@ describe('Transform: Common', () => { isAdvancedPivotEditorEnabled: false, isAdvancedSourceEditorEnabled: false, sourceConfigUpdated: false, + searchLanguage: 'kuery', searchString: 'the-query', searchQuery: 'the-search-query', valid: true, diff --git a/x-pack/plugins/transform/public/app/components/pivot_preview/pivot_preview.test.tsx b/x-pack/plugins/transform/public/app/components/pivot_preview/pivot_preview.test.tsx index b37cdbb132bab..69ac46b8807e3 100644 --- a/x-pack/plugins/transform/public/app/components/pivot_preview/pivot_preview.test.tsx +++ b/x-pack/plugins/transform/public/app/components/pivot_preview/pivot_preview.test.tsx @@ -19,7 +19,6 @@ import { import { PivotPreview } from './pivot_preview'; -jest.mock('ui/new_platform'); jest.mock('../../../shared_imports'); describe('Transform: ', () => { diff --git a/x-pack/plugins/transform/public/app/components/toast_notification_text.test.tsx b/x-pack/plugins/transform/public/app/components/toast_notification_text.test.tsx index 5b8721cb0fe8c..01d7aca05e88f 100644 --- a/x-pack/plugins/transform/public/app/components/toast_notification_text.test.tsx +++ b/x-pack/plugins/transform/public/app/components/toast_notification_text.test.tsx @@ -12,7 +12,6 @@ import { Providers } from '../app_dependencies.mock'; import { ToastNotificationText } from './toast_notification_text'; jest.mock('../../shared_imports'); -jest.mock('ui/new_platform'); describe('ToastNotificationText', () => { test('should render the text as plain text', () => { diff --git a/x-pack/plugins/transform/public/app/sections/create_transform/components/source_index_preview/source_index_preview.test.tsx b/x-pack/plugins/transform/public/app/sections/create_transform/components/source_index_preview/source_index_preview.test.tsx index 7a1532705916f..89d9f22a15954 100644 --- a/x-pack/plugins/transform/public/app/sections/create_transform/components/source_index_preview/source_index_preview.test.tsx +++ b/x-pack/plugins/transform/public/app/sections/create_transform/components/source_index_preview/source_index_preview.test.tsx @@ -14,7 +14,6 @@ import { SearchItems } from '../../../../hooks/use_search_items'; import { SourceIndexPreview } from './source_index_preview'; -jest.mock('ui/new_platform'); jest.mock('../../../../../shared_imports'); describe('Transform: ', () => { diff --git a/x-pack/plugins/transform/public/app/sections/create_transform/components/step_create/step_create_form.test.tsx b/x-pack/plugins/transform/public/app/sections/create_transform/components/step_create/step_create_form.test.tsx index 6223dfc5623b7..4a698dca980ff 100644 --- a/x-pack/plugins/transform/public/app/sections/create_transform/components/step_create/step_create_form.test.tsx +++ b/x-pack/plugins/transform/public/app/sections/create_transform/components/step_create/step_create_form.test.tsx @@ -12,7 +12,6 @@ import { Providers } from '../../../../app_dependencies.mock'; import { StepCreateForm } from './step_create_form'; -jest.mock('ui/new_platform'); jest.mock('../../../../../shared_imports'); describe('Transform: ', () => { diff --git a/x-pack/plugins/transform/public/app/sections/create_transform/components/step_define/step_define_form.test.tsx b/x-pack/plugins/transform/public/app/sections/create_transform/components/step_define/step_define_form.test.tsx index d5cffad166831..dbc8398da4772 100644 --- a/x-pack/plugins/transform/public/app/sections/create_transform/components/step_define/step_define_form.test.tsx +++ b/x-pack/plugins/transform/public/app/sections/create_transform/components/step_define/step_define_form.test.tsx @@ -19,7 +19,6 @@ import { SearchItems } from '../../../../hooks/use_search_items'; import { StepDefineForm, getAggNameConflictToastMessages } from './step_define_form'; -jest.mock('ui/new_platform'); jest.mock('../../../../../shared_imports'); describe('Transform: ', () => { diff --git a/x-pack/plugins/transform/public/app/sections/create_transform/components/step_define/step_define_form.tsx b/x-pack/plugins/transform/public/app/sections/create_transform/components/step_define/step_define_form.tsx index b9a68ea3c155e..1f9a60fa869b7 100644 --- a/x-pack/plugins/transform/public/app/sections/create_transform/components/step_define/step_define_form.tsx +++ b/x-pack/plugins/transform/public/app/sections/create_transform/components/step_define/step_define_form.tsx @@ -69,6 +69,8 @@ export interface StepDefineExposedState { groupByList: PivotGroupByConfigDict; isAdvancedPivotEditorEnabled: boolean; isAdvancedSourceEditorEnabled: boolean; + searchLanguage: QUERY_LANGUAGE; + searchString: string | undefined; searchQuery: string | SavedSearchQuery; sourceConfigUpdated: boolean; valid: boolean; @@ -76,10 +78,9 @@ export interface StepDefineExposedState { const defaultSearch = '*'; -enum QUERY_LANGUAGE { - KUERY = 'kuery', - LUCENE = 'lucene', -} +const QUERY_LANGUAGE_KUERY = 'kuery'; +const QUERY_LANGUAGE_LUCENE = 'lucene'; +type QUERY_LANGUAGE = 'kuery' | 'lucene'; export function getDefaultStepDefineState(searchItems: SearchItems): StepDefineExposedState { return { @@ -87,6 +88,8 @@ export function getDefaultStepDefineState(searchItems: SearchItems): StepDefineE groupByList: {} as PivotGroupByConfigDict, isAdvancedPivotEditorEnabled: false, isAdvancedSourceEditorEnabled: false, + searchLanguage: QUERY_LANGUAGE_KUERY, + searchString: undefined, searchQuery: searchItems.savedSearch !== undefined ? searchItems.combinedQuery : defaultSearch, sourceConfigUpdated: false, valid: false, @@ -248,19 +251,29 @@ export const StepDefineForm: FC = React.memo(({ overrides = {}, onChange, const defaults = { ...getDefaultStepDefineState(searchItems), ...overrides }; - // The search filter + // The internal state of the input query bar updated on every key stroke. const [searchInput, setSearchInput] = useState({ - query: '', - language: QUERY_LANGUAGE.KUERY as string, + query: defaults.searchString || '', + language: defaults.searchLanguage, }); + + // The state of the input query bar updated on every submit and to be exposed. + const [searchLanguage, setSearchLanguage] = useState( + defaults.searchLanguage + ); + const [searchString, setSearchString] = useState( + defaults.searchString + ); const [searchQuery, setSearchQuery] = useState(defaults.searchQuery); const { indexPattern } = searchItems; const searchChangeHandler = (query: Query) => setSearchInput(query); const searchSubmitHandler = (query: Query) => { + setSearchLanguage(query.language as QUERY_LANGUAGE); + setSearchString(query.query !== '' ? (query.query as string) : undefined); switch (query.language) { - case QUERY_LANGUAGE.KUERY: + case QUERY_LANGUAGE_KUERY: setSearchQuery( esKuery.toElasticsearchQuery( esKuery.fromKueryExpression(query.query as string), @@ -268,7 +281,7 @@ export const StepDefineForm: FC = React.memo(({ overrides = {}, onChange, ) ); return; - case QUERY_LANGUAGE.LUCENE: + case QUERY_LANGUAGE_LUCENE: setSearchQuery(esQuery.luceneStringToDsl(query.query as string)); return; } @@ -545,6 +558,8 @@ export const StepDefineForm: FC = React.memo(({ overrides = {}, onChange, groupByList, isAdvancedPivotEditorEnabled, isAdvancedSourceEditorEnabled, + searchLanguage, + searchString, searchQuery, sourceConfigUpdated, valid, @@ -556,6 +571,8 @@ export const StepDefineForm: FC = React.memo(({ overrides = {}, onChange, JSON.stringify(pivotGroupByArr), isAdvancedPivotEditorEnabled, isAdvancedSourceEditorEnabled, + searchLanguage, + searchString, searchQuery, valid, /* eslint-enable react-hooks/exhaustive-deps */ @@ -610,7 +627,7 @@ export const StepDefineForm: FC = React.memo(({ overrides = {}, onChange, onChange={searchChangeHandler} onSubmit={searchSubmitHandler} placeholder={ - searchInput.language === QUERY_LANGUAGE.KUERY + searchInput.language === QUERY_LANGUAGE_KUERY ? i18n.translate( 'xpack.transform.stepDefineForm.queryPlaceholderKql', { diff --git a/x-pack/plugins/transform/public/app/sections/create_transform/components/step_define/step_define_summary.test.tsx b/x-pack/plugins/transform/public/app/sections/create_transform/components/step_define/step_define_summary.test.tsx index 36a662e0cb7e6..11570a6ef53a5 100644 --- a/x-pack/plugins/transform/public/app/sections/create_transform/components/step_define/step_define_summary.test.tsx +++ b/x-pack/plugins/transform/public/app/sections/create_transform/components/step_define/step_define_summary.test.tsx @@ -20,7 +20,6 @@ import { SearchItems } from '../../../../hooks/use_search_items'; import { StepDefineExposedState } from './step_define_form'; import { StepDefineSummary } from './step_define_summary'; -jest.mock('ui/new_platform'); jest.mock('../../../../../shared_imports'); describe('Transform: ', () => { @@ -51,6 +50,7 @@ describe('Transform: ', () => { isAdvancedPivotEditorEnabled: false, isAdvancedSourceEditorEnabled: false, sourceConfigUpdated: false, + searchLanguage: 'kuery', searchString: 'the-query', searchQuery: 'the-search-query', valid: true, diff --git a/x-pack/plugins/transform/public/app/sections/create_transform/components/step_define/step_define_summary.tsx b/x-pack/plugins/transform/public/app/sections/create_transform/components/step_define/step_define_summary.tsx index 00948109c811d..54cc1e8c071fa 100644 --- a/x-pack/plugins/transform/public/app/sections/create_transform/components/step_define/step_define_summary.tsx +++ b/x-pack/plugins/transform/public/app/sections/create_transform/components/step_define/step_define_summary.tsx @@ -26,9 +26,6 @@ import { GroupByListSummary } from '../group_by_list'; import { StepDefineExposedState } from './step_define_form'; -const defaultSearch = '*'; -const emptySearch = ''; - interface Props { formState: StepDefineExposedState; searchItems: SearchItems; @@ -39,66 +36,50 @@ export const StepDefineSummary: FC = ({ searchItems, }) => { const pivotQuery = getPivotQuery(searchQuery); - let useCodeBlock = false; - let displaySearch; - // searchString set to empty once source config editor used - display query instead - if (searchString === emptySearch) { - displaySearch = JSON.stringify(searchQuery, null, 2); - useCodeBlock = true; - } else if (searchString === defaultSearch) { - displaySearch = emptySearch; - } else { - displaySearch = searchString; - } return (
- {searchItems.savedSearch !== undefined && - searchItems.savedSearch.id === undefined && - typeof searchString === 'string' && ( - + {searchItems.savedSearch === undefined && ( + + + {searchItems.indexPattern.title} + + {typeof searchString === 'string' && ( - {searchItems.indexPattern.title} + {searchString} - {useCodeBlock === false && displaySearch !== emptySearch && ( - - {displaySearch} - - )} - {useCodeBlock === true && displaySearch !== emptySearch && ( - + - - {displaySearch} - - - )} - - )} + {JSON.stringify(searchQuery, null, 2)} + + + )} + + )} {searchItems.savedSearch !== undefined && searchItems.savedSearch.id !== undefined && ( ', () => { diff --git a/x-pack/plugins/transform/public/app/sections/transform_management/components/transform_list/action_start.test.tsx b/x-pack/plugins/transform/public/app/sections/transform_management/components/transform_list/action_start.test.tsx index bbdfdbbc3c121..dc45dcccc9495 100644 --- a/x-pack/plugins/transform/public/app/sections/transform_management/components/transform_list/action_start.test.tsx +++ b/x-pack/plugins/transform/public/app/sections/transform_management/components/transform_list/action_start.test.tsx @@ -14,7 +14,6 @@ import { StartAction } from './action_start'; import transformListRow from '../../../../common/__mocks__/transform_list_row.json'; -jest.mock('ui/new_platform'); jest.mock('../../../../../shared_imports'); describe('Transform: Transform List Actions ', () => { diff --git a/x-pack/plugins/transform/public/app/sections/transform_management/components/transform_list/action_stop.test.tsx b/x-pack/plugins/transform/public/app/sections/transform_management/components/transform_list/action_stop.test.tsx index 840fbc4b9034b..dc9ca2fbfff52 100644 --- a/x-pack/plugins/transform/public/app/sections/transform_management/components/transform_list/action_stop.test.tsx +++ b/x-pack/plugins/transform/public/app/sections/transform_management/components/transform_list/action_stop.test.tsx @@ -14,7 +14,6 @@ import { StopAction } from './action_stop'; import transformListRow from '../../../../common/__mocks__/transform_list_row.json'; -jest.mock('ui/new_platform'); jest.mock('../../../../../shared_imports'); describe('Transform: Transform List Actions ', () => { From 9fa3c4b5172338f853f1c765adfffefc27fe1aa6 Mon Sep 17 00:00:00 2001 From: Walter Rafelsberger Date: Thu, 12 Mar 2020 08:32:23 +0100 Subject: [PATCH 5/7] [ML] Fix tests. --- .../app_dependencies.tsx} | 21 +++++---- .../pivot_preview/pivot_preview.test.tsx | 8 +--- .../toast_notification_text.test.tsx | 15 ++----- .../source_index_preview.test.tsx | 8 +--- .../step_create/step_create_form.test.tsx | 9 +--- .../step_define/step_define_form.test.tsx | 44 +++++++++++++++++-- .../step_define/step_define_summary.test.tsx | 6 +-- .../transform_list/action_delete.test.tsx | 12 +---- .../transform_list/action_start.test.tsx | 11 +---- .../transform_list/action_stop.test.tsx | 11 +---- 10 files changed, 67 insertions(+), 78 deletions(-) rename x-pack/plugins/transform/public/app/{app_dependencies.mock.tsx => __mocks__/app_dependencies.tsx} (55%) diff --git a/x-pack/plugins/transform/public/app/app_dependencies.mock.tsx b/x-pack/plugins/transform/public/app/__mocks__/app_dependencies.tsx similarity index 55% rename from x-pack/plugins/transform/public/app/app_dependencies.mock.tsx rename to x-pack/plugins/transform/public/app/__mocks__/app_dependencies.tsx index 2158dc9315fa5..75fefc99b5458 100644 --- a/x-pack/plugins/transform/public/app/app_dependencies.mock.tsx +++ b/x-pack/plugins/transform/public/app/__mocks__/app_dependencies.tsx @@ -4,20 +4,15 @@ * you may not use this file except in compliance with the Elastic License. */ -import React, { FC } from 'react'; - -import { coreMock } from '../../../../../src/core/public/mocks'; -import { dataPluginMock } from '../../../../../src/plugins/data/public/mocks'; -import { KibanaContextProvider } from '../../../../../src/plugins/kibana_react/public'; -import { Storage } from '../../../../../src/plugins/kibana_utils/public'; - -import { AppDependencies } from './app_dependencies'; +import { coreMock } from '../../../../../../src/core/public/mocks'; +import { dataPluginMock } from '../../../../../../src/plugins/data/public/mocks'; +import { Storage } from '../../../../../../src/plugins/kibana_utils/public'; const coreSetup = coreMock.createSetup(); const coreStart = coreMock.createStart(); const dataStart = dataPluginMock.createStartContract(); -const appDependencies: AppDependencies = { +const appDependencies = { chrome: coreStart.chrome, data: dataStart, docLinks: coreStart.docLinks, @@ -30,6 +25,10 @@ const appDependencies: AppDependencies = { http: coreSetup.http, }; -export const Providers: FC = ({ children }) => { - return {children}; +export const useAppDependencies = () => { + return appDependencies; +}; + +export const useToastNotifications = () => { + return coreSetup.notifications; }; diff --git a/x-pack/plugins/transform/public/app/components/pivot_preview/pivot_preview.test.tsx b/x-pack/plugins/transform/public/app/components/pivot_preview/pivot_preview.test.tsx index 69ac46b8807e3..5ed50eaab46ba 100644 --- a/x-pack/plugins/transform/public/app/components/pivot_preview/pivot_preview.test.tsx +++ b/x-pack/plugins/transform/public/app/components/pivot_preview/pivot_preview.test.tsx @@ -8,7 +8,6 @@ import React from 'react'; import { render, wait } from '@testing-library/react'; import '@testing-library/jest-dom/extend-expect'; -import { Providers } from '../../app_dependencies.mock'; import { getPivotQuery, PivotAggsConfig, @@ -20,6 +19,7 @@ import { import { PivotPreview } from './pivot_preview'; jest.mock('../../../shared_imports'); +jest.mock('../../../app/app_dependencies'); describe('Transform: ', () => { // Using the async/await wait()/done() pattern to avoid act() errors. @@ -44,11 +44,7 @@ describe('Transform: ', () => { query: getPivotQuery('the-query'), }; - const { getByText } = render( - - - - ); + const { getByText } = render(); // Act // Assert diff --git a/x-pack/plugins/transform/public/app/components/toast_notification_text.test.tsx b/x-pack/plugins/transform/public/app/components/toast_notification_text.test.tsx index 01d7aca05e88f..e51119d67d567 100644 --- a/x-pack/plugins/transform/public/app/components/toast_notification_text.test.tsx +++ b/x-pack/plugins/transform/public/app/components/toast_notification_text.test.tsx @@ -7,22 +7,17 @@ import React from 'react'; import { render } from '@testing-library/react'; -import { Providers } from '../app_dependencies.mock'; - import { ToastNotificationText } from './toast_notification_text'; jest.mock('../../shared_imports'); +jest.mock('../../app/app_dependencies'); describe('ToastNotificationText', () => { test('should render the text as plain text', () => { const props = { text: 'a short text message', }; - const { container } = render( - - - - ); + const { container } = render(); expect(container.textContent).toBe('a short text message'); }); @@ -31,11 +26,7 @@ describe('ToastNotificationText', () => { text: 'a text message that is longer than 140 characters. a text message that is longer than 140 characters. a text message that is longer than 140 characters. ', }; - const { container } = render( - - - - ); + const { container } = render(); expect(container.textContent).toBe( 'a text message that is longer than 140 characters. a text message that is longer than 140 characters. a text message that is longer than 140 ...View details' ); diff --git a/x-pack/plugins/transform/public/app/sections/create_transform/components/source_index_preview/source_index_preview.test.tsx b/x-pack/plugins/transform/public/app/sections/create_transform/components/source_index_preview/source_index_preview.test.tsx index 89d9f22a15954..32f6ff9490a0f 100644 --- a/x-pack/plugins/transform/public/app/sections/create_transform/components/source_index_preview/source_index_preview.test.tsx +++ b/x-pack/plugins/transform/public/app/sections/create_transform/components/source_index_preview/source_index_preview.test.tsx @@ -8,13 +8,13 @@ import React from 'react'; import { render, wait } from '@testing-library/react'; import '@testing-library/jest-dom/extend-expect'; -import { Providers } from '../../../../app_dependencies.mock'; import { getPivotQuery } from '../../../../common'; import { SearchItems } from '../../../../hooks/use_search_items'; import { SourceIndexPreview } from './source_index_preview'; jest.mock('../../../../../shared_imports'); +jest.mock('../../../../../app/app_dependencies'); describe('Transform: ', () => { // Using the async/await wait()/done() pattern to avoid act() errors. @@ -27,11 +27,7 @@ describe('Transform: ', () => { } as SearchItems['indexPattern'], query: getPivotQuery('the-query'), }; - const { getByText } = render( - - - - ); + const { getByText } = render(); // Act // Assert diff --git a/x-pack/plugins/transform/public/app/sections/create_transform/components/step_create/step_create_form.test.tsx b/x-pack/plugins/transform/public/app/sections/create_transform/components/step_create/step_create_form.test.tsx index 4a698dca980ff..f2837d30402de 100644 --- a/x-pack/plugins/transform/public/app/sections/create_transform/components/step_create/step_create_form.test.tsx +++ b/x-pack/plugins/transform/public/app/sections/create_transform/components/step_create/step_create_form.test.tsx @@ -8,11 +8,10 @@ import React from 'react'; import { render } from '@testing-library/react'; import '@testing-library/jest-dom/extend-expect'; -import { Providers } from '../../../../app_dependencies.mock'; - import { StepCreateForm } from './step_create_form'; jest.mock('../../../../../shared_imports'); +jest.mock('../../../../../app/app_dependencies'); describe('Transform: ', () => { test('Minimal initialization', () => { @@ -25,11 +24,7 @@ describe('Transform: ', () => { onChange() {}, }; - const { getByText } = render( - - - - ); + const { getByText } = render(); // Act // Assert diff --git a/x-pack/plugins/transform/public/app/sections/create_transform/components/step_define/step_define_form.test.tsx b/x-pack/plugins/transform/public/app/sections/create_transform/components/step_define/step_define_form.test.tsx index dbc8398da4772..a15e958c16b73 100644 --- a/x-pack/plugins/transform/public/app/sections/create_transform/components/step_define/step_define_form.test.tsx +++ b/x-pack/plugins/transform/public/app/sections/create_transform/components/step_define/step_define_form.test.tsx @@ -8,7 +8,14 @@ import React from 'react'; import { render, wait } from '@testing-library/react'; import '@testing-library/jest-dom/extend-expect'; -import { Providers } from '../../../../app_dependencies.mock'; +import { I18nProvider } from '@kbn/i18n/react'; + +import { KibanaContextProvider } from '../../../../../../../../../src/plugins/kibana_react/public'; + +import { coreMock } from '../../../../../../../../../src/core/public/mocks'; +import { dataPluginMock } from '../../../../../../../../../src/plugins/data/public/mocks'; +const startMock = coreMock.createStart(); + import { PivotAggsConfigDict, PivotGroupByConfigDict, @@ -20,6 +27,24 @@ import { SearchItems } from '../../../../hooks/use_search_items'; import { StepDefineForm, getAggNameConflictToastMessages } from './step_define_form'; jest.mock('../../../../../shared_imports'); +jest.mock('../../../../../app/app_dependencies'); + +const createMockWebStorage = () => ({ + clear: jest.fn(), + getItem: jest.fn(), + key: jest.fn(), + removeItem: jest.fn(), + setItem: jest.fn(), + length: 0, +}); + +const createMockStorage = () => ({ + storage: createMockWebStorage(), + get: jest.fn(), + set: jest.fn(), + remove: jest.fn(), + clear: jest.fn(), +}); describe('Transform: ', () => { // Using the async/await wait()/done() pattern to avoid act() errors. @@ -31,10 +56,21 @@ describe('Transform: ', () => { fields: [] as any[], } as SearchItems['indexPattern'], }; + + // mock services for QueryStringInput + const services = { + ...startMock, + data: dataPluginMock.createStartContract(), + appName: 'the-test-app', + storage: createMockStorage(), + }; + const { getByLabelText } = render( - - - + + + + + ); // Act diff --git a/x-pack/plugins/transform/public/app/sections/create_transform/components/step_define/step_define_summary.test.tsx b/x-pack/plugins/transform/public/app/sections/create_transform/components/step_define/step_define_summary.test.tsx index 11570a6ef53a5..f2e5d30b0601f 100644 --- a/x-pack/plugins/transform/public/app/sections/create_transform/components/step_define/step_define_summary.test.tsx +++ b/x-pack/plugins/transform/public/app/sections/create_transform/components/step_define/step_define_summary.test.tsx @@ -8,7 +8,6 @@ import React from 'react'; import { render, wait } from '@testing-library/react'; import '@testing-library/jest-dom/extend-expect'; -import { Providers } from '../../../../app_dependencies.mock'; import { PivotAggsConfig, PivotGroupByConfig, @@ -21,6 +20,7 @@ import { StepDefineExposedState } from './step_define_form'; import { StepDefineSummary } from './step_define_summary'; jest.mock('../../../../../shared_imports'); +jest.mock('../../../../../app/app_dependencies'); describe('Transform: ', () => { // Using the async/await wait()/done() pattern to avoid act() errors. @@ -57,9 +57,7 @@ describe('Transform: ', () => { }; const { getByText } = render( - - - + ); // Act diff --git a/x-pack/plugins/transform/public/app/sections/transform_management/components/transform_list/action_delete.test.tsx b/x-pack/plugins/transform/public/app/sections/transform_management/components/transform_list/action_delete.test.tsx index ca83d379bf3db..fdd0b821f54fd 100644 --- a/x-pack/plugins/transform/public/app/sections/transform_management/components/transform_list/action_delete.test.tsx +++ b/x-pack/plugins/transform/public/app/sections/transform_management/components/transform_list/action_delete.test.tsx @@ -7,14 +7,13 @@ import { shallow } from 'enzyme'; import React from 'react'; -import { Providers } from '../../../../app_dependencies.mock'; - import { TransformListRow } from '../../../../common'; import { DeleteAction } from './action_delete'; import transformListRow from '../../../../common/__mocks__/transform_list_row.json'; jest.mock('../../../../../shared_imports'); +jest.mock('../../../../../app/app_dependencies'); describe('Transform: Transform List Actions ', () => { test('Minimal initialization', () => { @@ -25,14 +24,7 @@ describe('Transform: Transform List Actions ', () => { deleteTransform(d: TransformListRow) {}, }; - const wrapper = shallow( - - - - ) - .find(DeleteAction) - .shallow(); - + const wrapper = shallow(); expect(wrapper).toMatchSnapshot(); }); }); diff --git a/x-pack/plugins/transform/public/app/sections/transform_management/components/transform_list/action_start.test.tsx b/x-pack/plugins/transform/public/app/sections/transform_management/components/transform_list/action_start.test.tsx index dc45dcccc9495..2de115236c4dc 100644 --- a/x-pack/plugins/transform/public/app/sections/transform_management/components/transform_list/action_start.test.tsx +++ b/x-pack/plugins/transform/public/app/sections/transform_management/components/transform_list/action_start.test.tsx @@ -7,14 +7,13 @@ import { shallow } from 'enzyme'; import React from 'react'; -import { Providers } from '../../../../app_dependencies.mock'; - import { TransformListRow } from '../../../../common'; import { StartAction } from './action_start'; import transformListRow from '../../../../common/__mocks__/transform_list_row.json'; jest.mock('../../../../../shared_imports'); +jest.mock('../../../../../app/app_dependencies'); describe('Transform: Transform List Actions ', () => { test('Minimal initialization', () => { @@ -25,13 +24,7 @@ describe('Transform: Transform List Actions ', () => { startTransform(d: TransformListRow) {}, }; - const wrapper = shallow( - - - - ) - .find(StartAction) - .shallow(); + const wrapper = shallow(); expect(wrapper).toMatchSnapshot(); }); diff --git a/x-pack/plugins/transform/public/app/sections/transform_management/components/transform_list/action_stop.test.tsx b/x-pack/plugins/transform/public/app/sections/transform_management/components/transform_list/action_stop.test.tsx index dc9ca2fbfff52..a97097d909848 100644 --- a/x-pack/plugins/transform/public/app/sections/transform_management/components/transform_list/action_stop.test.tsx +++ b/x-pack/plugins/transform/public/app/sections/transform_management/components/transform_list/action_stop.test.tsx @@ -7,14 +7,13 @@ import { shallow } from 'enzyme'; import React from 'react'; -import { Providers } from '../../../../app_dependencies.mock'; - import { TransformListRow } from '../../../../common'; import { StopAction } from './action_stop'; import transformListRow from '../../../../common/__mocks__/transform_list_row.json'; jest.mock('../../../../../shared_imports'); +jest.mock('../../../../../app/app_dependencies'); describe('Transform: Transform List Actions ', () => { test('Minimal initialization', () => { @@ -25,13 +24,7 @@ describe('Transform: Transform List Actions ', () => { stopTransform(d: TransformListRow) {}, }; - const wrapper = shallow( - - - - ) - .find(StopAction) - .shallow(); + const wrapper = shallow(); expect(wrapper).toMatchSnapshot(); }); From fe6d51250325e91f337f2790bcde892dc34c6a80 Mon Sep 17 00:00:00 2001 From: Walter Rafelsberger Date: Thu, 12 Mar 2020 12:12:59 +0100 Subject: [PATCH 6/7] [ML] Fix test subject ids. --- x-pack/test/functional/services/transform_ui/wizard.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/x-pack/test/functional/services/transform_ui/wizard.ts b/x-pack/test/functional/services/transform_ui/wizard.ts index 2d20f3617cf06..ba9096a372d9a 100644 --- a/x-pack/test/functional/services/transform_ui/wizard.ts +++ b/x-pack/test/functional/services/transform_ui/wizard.ts @@ -160,15 +160,15 @@ export function TransformWizardProvider({ getService }: FtrProviderContext) { }, async assertQueryInputExists() { - await testSubjects.existOrFail('tarnsformQueryInput'); + await testSubjects.existOrFail('transformQueryInput'); }, async assertQueryInputMissing() { - await testSubjects.missingOrFail('tarnsformQueryInput'); + await testSubjects.missingOrFail('transformQueryInput'); }, async assertQueryValue(expectedQuery: string) { - const actualQuery = await testSubjects.getVisibleText('tarnsformQueryInput'); + const actualQuery = await testSubjects.getVisibleText('transformQueryInput'); expect(actualQuery).to.eql( expectedQuery, `Query input text should be '${expectedQuery}' (got ${actualQuery})` From 789d2ab6f05f9b507eda510776bd18b462d4704c Mon Sep 17 00:00:00 2001 From: Walter Rafelsberger Date: Thu, 12 Mar 2020 14:00:26 +0100 Subject: [PATCH 7/7] [ML] Fix i18n. --- x-pack/plugins/translations/translations/ja-JP.json | 1 - x-pack/plugins/translations/translations/zh-CN.json | 1 - 2 files changed, 2 deletions(-) diff --git a/x-pack/plugins/translations/translations/ja-JP.json b/x-pack/plugins/translations/translations/ja-JP.json index e1627bc273db9..4ea5d6708b8cd 100644 --- a/x-pack/plugins/translations/translations/ja-JP.json +++ b/x-pack/plugins/translations/translations/ja-JP.json @@ -12428,7 +12428,6 @@ "xpack.transform.stepDefineForm.nestedGroupByListConflictErrorMessage": "「{groupByListName}」とネスティングの矛盾があるため、構成「{aggName}」を追加できませんでした。", "xpack.transform.stepDefineForm.queryHelpText": "クエリ文字列でソースデータをフィルタリングしてください (オプション)。", "xpack.transform.stepDefineForm.queryLabel": "クエリ", - "xpack.transform.stepDefineForm.queryPlaceholder": "例: {example}.", "xpack.transform.stepDefineForm.savedSearchLabel": "保存検索", "xpack.transform.stepDefineSummary.aggregationsLabel": "アグリゲーション(集計)", "xpack.transform.stepDefineSummary.groupByLabel": "グループ分けの条件", diff --git a/x-pack/plugins/translations/translations/zh-CN.json b/x-pack/plugins/translations/translations/zh-CN.json index 65f67d5be5e56..7dd4a876d580d 100644 --- a/x-pack/plugins/translations/translations/zh-CN.json +++ b/x-pack/plugins/translations/translations/zh-CN.json @@ -12428,7 +12428,6 @@ "xpack.transform.stepDefineForm.nestedGroupByListConflictErrorMessage": "无法添加配置“{aggName}”,因为与“{groupByListName}”有嵌套冲突。", "xpack.transform.stepDefineForm.queryHelpText": "使用查询字符串筛选源数据(可选)。", "xpack.transform.stepDefineForm.queryLabel": "查询", - "xpack.transform.stepDefineForm.queryPlaceholder": "例如,{example}", "xpack.transform.stepDefineForm.savedSearchLabel": "已保存搜索", "xpack.transform.stepDefineSummary.aggregationsLabel": "聚合", "xpack.transform.stepDefineSummary.groupByLabel": "分组依据",