From e8ef2358ee29a8f7e79a981d7ac6ca7ffd2962fe Mon Sep 17 00:00:00 2001 From: CJ Cenizal Date: Thu, 12 Aug 2021 20:26:13 -0700 Subject: [PATCH] Fix broken mocks in Jest tests. --- .../component_template_create.test.tsx | 23 +++++++++++ .../helpers/setup_environment.tsx | 33 +++++++++++----- .../load_mappings_provider.test.tsx | 39 +++++++++++-------- .../__jest__/test_pipeline.helpers.tsx | 8 +++- .../load_from_json/modal_provider.test.tsx | 35 ++++++++++------- 5 files changed, 94 insertions(+), 44 deletions(-) diff --git a/x-pack/plugins/index_management/public/application/components/component_templates/__jest__/client_integration/component_template_create.test.tsx b/x-pack/plugins/index_management/public/application/components/component_templates/__jest__/client_integration/component_template_create.test.tsx index 2fca273a4c7e2..fa6c4f9913c0d 100644 --- a/x-pack/plugins/index_management/public/application/components/component_templates/__jest__/client_integration/component_template_create.test.tsx +++ b/x-pack/plugins/index_management/public/application/components/component_templates/__jest__/client_integration/component_template_create.test.tsx @@ -38,6 +38,29 @@ jest.mock('@elastic/eui', () => { }; }); +// This mocks JsonEditor's consumption of EuiCodeEditor. +jest.mock( + '../../../../../../../../../src/plugins/es_ui_shared/public/components/code_editor', + () => { + const original = jest.requireActual( + '../../../../../../../../../src/plugins/es_ui_shared/public/components/code_editor' + ); + + return { + ...original, + // Mocking EuiCodeEditor, which uses React Ace under the hood + EuiCodeEditor: (props: any) => ( + { + props.onChange(syntheticEvent.jsonString); + }} + /> + ), + }; + } +); + describe('', () => { let testBed: ComponentTemplateCreateTestBed; diff --git a/x-pack/plugins/index_management/public/application/components/mappings_editor/__jest__/client_integration/helpers/setup_environment.tsx b/x-pack/plugins/index_management/public/application/components/mappings_editor/__jest__/client_integration/helpers/setup_environment.tsx index b2647b175b324..223e58617c04f 100644 --- a/x-pack/plugins/index_management/public/application/components/mappings_editor/__jest__/client_integration/helpers/setup_environment.tsx +++ b/x-pack/plugins/index_management/public/application/components/mappings_editor/__jest__/client_integration/helpers/setup_environment.tsx @@ -30,16 +30,6 @@ jest.mock('@elastic/eui', () => { }} /> ), - // Mocking EuiCodeEditor, which uses React Ace under the hood - EuiCodeEditor: (props: any) => ( - { - props.onChange(e.jsonContent); - }} - /> - ), // Mocking EuiSuperSelect to be able to easily change its value // with a `myWrapper.simulate('change', { target: { value: 'someValue' } })` EuiSuperSelect: (props: any) => ( @@ -54,6 +44,29 @@ jest.mock('@elastic/eui', () => { }; }); +jest.mock( + '../../../../../../../../../../src/plugins/es_ui_shared/public/components/code_editor', + () => { + const original = jest.requireActual( + '../../../../../../../../../../src/plugins/es_ui_shared/public/components/code_editor' + ); + + return { + ...original, + // Mocking EuiCodeEditor, which uses React Ace under the hood + EuiCodeEditor: (props: any) => ( + { + props.onChange(e.jsonContent); + }} + /> + ), + }; + } +); + jest.mock('../../../../../../../../../../src/plugins/kibana_react/public', () => { const original = jest.requireActual( '../../../../../../../../../../src/plugins/kibana_react/public' diff --git a/x-pack/plugins/index_management/public/application/components/mappings_editor/components/load_mappings/load_mappings_provider.test.tsx b/x-pack/plugins/index_management/public/application/components/mappings_editor/components/load_mappings/load_mappings_provider.test.tsx index 8f70406962e4c..69b22150fc3a6 100644 --- a/x-pack/plugins/index_management/public/application/components/mappings_editor/components/load_mappings/load_mappings_provider.test.tsx +++ b/x-pack/plugins/index_management/public/application/components/mappings_editor/components/load_mappings/load_mappings_provider.test.tsx @@ -8,23 +8,6 @@ import React from 'react'; import { act } from 'react-dom/test-utils'; -jest.mock('@elastic/eui', () => { - const original = jest.requireActual('@elastic/eui'); - - return { - ...original, - // Mocking EuiCodeEditor, which uses React Ace under the hood - EuiCodeEditor: (props: any) => ( - { - props.onChange(syntheticEvent.jsonString); - }} - /> - ), - }; -}); - jest.mock('lodash', () => { const original = jest.requireActual('lodash'); @@ -34,6 +17,28 @@ jest.mock('lodash', () => { }; }); +jest.mock( + '../../../../../../../../../src/plugins/es_ui_shared/public/components/code_editor', + () => { + const original = jest.requireActual( + '../../../../../../../../../src/plugins/es_ui_shared/public/components/code_editor' + ); + + return { + ...original, + // Mocking EuiCodeEditor, which uses React Ace under the hood + EuiCodeEditor: (props: any) => ( + { + props.onChange(syntheticEvent.jsonString); + }} + /> + ), + }; + } +); + import { registerTestBed, TestBed } from '@kbn/test/jest'; import { LoadMappingsProvider } from './load_mappings_provider'; diff --git a/x-pack/plugins/ingest_pipelines/public/application/components/pipeline_editor/__jest__/test_pipeline.helpers.tsx b/x-pack/plugins/ingest_pipelines/public/application/components/pipeline_editor/__jest__/test_pipeline.helpers.tsx index 88e5c62a5b1d3..365ca7c1d89c1 100644 --- a/x-pack/plugins/ingest_pipelines/public/application/components/pipeline_editor/__jest__/test_pipeline.helpers.tsx +++ b/x-pack/plugins/ingest_pipelines/public/application/components/pipeline_editor/__jest__/test_pipeline.helpers.tsx @@ -24,6 +24,7 @@ stubWebWorker(); jest.mock('../../../../../../../../src/plugins/kibana_react/public', () => { const original = jest.requireActual('../../../../../../../../src/plugins/kibana_react/public'); + return { ...original, // Mocking CodeEditor, which uses React Monaco under the hood @@ -39,8 +40,11 @@ jest.mock('../../../../../../../../src/plugins/kibana_react/public', () => { }; }); -jest.mock('@elastic/eui', () => { - const original = jest.requireActual('@elastic/eui'); +jest.mock('../../../../../../../../src/plugins/es_ui_shared/public/components/code_editor', () => { + const original = jest.requireActual( + '../../../../../../../../src/plugins/es_ui_shared/public/components/code_editor' + ); + return { ...original, // Mocking EuiCodeEditor, which uses React Ace under the hood diff --git a/x-pack/plugins/ingest_pipelines/public/application/components/pipeline_editor/components/load_from_json/modal_provider.test.tsx b/x-pack/plugins/ingest_pipelines/public/application/components/pipeline_editor/components/load_from_json/modal_provider.test.tsx index ccefac896fe7c..620b1d3cae652 100644 --- a/x-pack/plugins/ingest_pipelines/public/application/components/pipeline_editor/components/load_from_json/modal_provider.test.tsx +++ b/x-pack/plugins/ingest_pipelines/public/application/components/pipeline_editor/components/load_from_json/modal_provider.test.tsx @@ -8,22 +8,27 @@ import React from 'react'; import { ModalProvider, OnDoneLoadJsonHandler } from './modal_provider'; -jest.mock('@elastic/eui', () => { - const original = jest.requireActual('@elastic/eui'); +jest.mock( + '../../../../../../../../../src/plugins/es_ui_shared/public/components/code_editor', + () => { + const original = jest.requireActual( + '../../../../../../../../../src/plugins/es_ui_shared/public/components/code_editor' + ); - return { - ...original, - // Mocking EuiCodeEditor, which uses React Ace under the hood - EuiCodeEditor: (props: any) => ( - { - props.onChange(syntheticEvent.jsonString); - }} - /> - ), - }; -}); + return { + ...original, + // Mocking EuiCodeEditor, which uses React Ace under the hood + EuiCodeEditor: (props: any) => ( + { + props.onChange(syntheticEvent.jsonString); + }} + /> + ), + }; + } +); jest.mock('lodash', () => { const original = jest.requireActual('lodash');