From 15cad32156677b23a3006bd81be2245fe950f9a3 Mon Sep 17 00:00:00 2001 From: Ignacio Rivas Date: Wed, 13 Apr 2022 10:00:20 +0200 Subject: [PATCH 1/4] Remove last axios dep from ingest pipelines --- .../__jest__/processors/append.test.tsx | 6 ++++-- .../__jest__/processors/bytes.test.tsx | 5 +++-- .../__jest__/processors/circle.test.tsx | 5 +++-- .../processors/common_processor_fields.test.tsx | 5 +++-- .../__jest__/processors/community_id.test.tsx | 5 +++-- .../__jest__/processors/convert.test.tsx | 5 +++-- .../__jest__/processors/csv.test.tsx | 5 +++-- .../__jest__/processors/date.test.tsx | 5 +++-- .../__jest__/processors/date_index.test.tsx | 5 +++-- .../__jest__/processors/dot_expander.test.tsx | 5 +++-- .../__jest__/processors/fail.test.tsx | 5 +++-- .../__jest__/processors/fingerprint.test.tsx | 5 +++-- .../processors/network_direction.test.tsx | 5 +++-- .../__jest__/processors/processor.helpers.tsx | 17 +++++------------ .../__jest__/processors/processor_form.test.tsx | 5 +++-- .../processors/registered_domain.test.tsx | 5 +++-- .../__jest__/processors/set.test.tsx | 5 +++-- .../__jest__/processors/uri_parts.test.tsx | 5 +++-- .../__jest__/processors/user_agent.test.tsx | 5 +++-- 19 files changed, 60 insertions(+), 48 deletions(-) diff --git a/x-pack/plugins/ingest_pipelines/public/application/components/pipeline_editor/__jest__/processors/append.test.tsx b/x-pack/plugins/ingest_pipelines/public/application/components/pipeline_editor/__jest__/processors/append.test.tsx index af3651525d6a3..f35e05b800f14 100644 --- a/x-pack/plugins/ingest_pipelines/public/application/components/pipeline_editor/__jest__/processors/append.test.tsx +++ b/x-pack/plugins/ingest_pipelines/public/application/components/pipeline_editor/__jest__/processors/append.test.tsx @@ -6,7 +6,7 @@ */ import { act } from 'react-dom/test-utils'; -import { setup, SetupResult, getProcessorValue } from './processor.helpers'; +import { setup, SetupResult, getProcessorValue, setupEnvironment } from './processor.helpers'; const APPEND_TYPE = 'append'; @@ -14,6 +14,8 @@ describe('Processor: Append', () => { let onUpdate: jest.Mock; let testBed: SetupResult; + const { httpSetup } = setupEnvironment(); + beforeAll(() => { jest.useFakeTimers(); }); @@ -26,7 +28,7 @@ describe('Processor: Append', () => { onUpdate = jest.fn(); await act(async () => { - testBed = await setup({ + testBed = await setup(httpSetup, { value: { processors: [], }, diff --git a/x-pack/plugins/ingest_pipelines/public/application/components/pipeline_editor/__jest__/processors/bytes.test.tsx b/x-pack/plugins/ingest_pipelines/public/application/components/pipeline_editor/__jest__/processors/bytes.test.tsx index 51117c3b517f9..d4ac176d6aaf5 100644 --- a/x-pack/plugins/ingest_pipelines/public/application/components/pipeline_editor/__jest__/processors/bytes.test.tsx +++ b/x-pack/plugins/ingest_pipelines/public/application/components/pipeline_editor/__jest__/processors/bytes.test.tsx @@ -6,13 +6,14 @@ */ import { act } from 'react-dom/test-utils'; -import { setup, SetupResult, getProcessorValue } from './processor.helpers'; +import { setup, SetupResult, getProcessorValue, setupEnvironment } from './processor.helpers'; const BYTES_TYPE = 'bytes'; describe('Processor: Bytes', () => { let onUpdate: jest.Mock; let testBed: SetupResult; + const { httpSetup } = setupEnvironment(); beforeAll(() => { jest.useFakeTimers(); @@ -26,7 +27,7 @@ describe('Processor: Bytes', () => { onUpdate = jest.fn(); await act(async () => { - testBed = await setup({ + testBed = await setup(httpSetup, { value: { processors: [], }, diff --git a/x-pack/plugins/ingest_pipelines/public/application/components/pipeline_editor/__jest__/processors/circle.test.tsx b/x-pack/plugins/ingest_pipelines/public/application/components/pipeline_editor/__jest__/processors/circle.test.tsx index b8c8f6c58f711..00153471ea65e 100644 --- a/x-pack/plugins/ingest_pipelines/public/application/components/pipeline_editor/__jest__/processors/circle.test.tsx +++ b/x-pack/plugins/ingest_pipelines/public/application/components/pipeline_editor/__jest__/processors/circle.test.tsx @@ -6,13 +6,14 @@ */ import { act } from 'react-dom/test-utils'; -import { setup, SetupResult, getProcessorValue } from './processor.helpers'; +import { setup, SetupResult, getProcessorValue, setupEnvironment } from './processor.helpers'; const CIRCLE_TYPE = 'circle'; describe('Processor: Circle', () => { let onUpdate: jest.Mock; let testBed: SetupResult; + const { httpSetup } = setupEnvironment(); beforeAll(() => { jest.useFakeTimers(); @@ -26,7 +27,7 @@ describe('Processor: Circle', () => { onUpdate = jest.fn(); await act(async () => { - testBed = await setup({ + testBed = await setup(httpSetup, { value: { processors: [], }, diff --git a/x-pack/plugins/ingest_pipelines/public/application/components/pipeline_editor/__jest__/processors/common_processor_fields.test.tsx b/x-pack/plugins/ingest_pipelines/public/application/components/pipeline_editor/__jest__/processors/common_processor_fields.test.tsx index af5c8c50abf7b..ebffd5adf78c1 100644 --- a/x-pack/plugins/ingest_pipelines/public/application/components/pipeline_editor/__jest__/processors/common_processor_fields.test.tsx +++ b/x-pack/plugins/ingest_pipelines/public/application/components/pipeline_editor/__jest__/processors/common_processor_fields.test.tsx @@ -6,13 +6,14 @@ */ import { act } from 'react-dom/test-utils'; -import { setup, SetupResult, getProcessorValue } from './processor.helpers'; +import { setup, SetupResult, getProcessorValue, setupEnvironment } from './processor.helpers'; const BYTES_TYPE = 'bytes'; describe('Processor: Common Fields For All Processors', () => { let onUpdate: jest.Mock; let testBed: SetupResult; + const { httpSetup } = setupEnvironment(); beforeAll(() => { jest.useFakeTimers(); @@ -26,7 +27,7 @@ describe('Processor: Common Fields For All Processors', () => { onUpdate = jest.fn(); await act(async () => { - testBed = await setup({ + testBed = await setup(httpSetup, { value: { processors: [], }, diff --git a/x-pack/plugins/ingest_pipelines/public/application/components/pipeline_editor/__jest__/processors/community_id.test.tsx b/x-pack/plugins/ingest_pipelines/public/application/components/pipeline_editor/__jest__/processors/community_id.test.tsx index 0338cb8e04348..e571474576ff2 100644 --- a/x-pack/plugins/ingest_pipelines/public/application/components/pipeline_editor/__jest__/processors/community_id.test.tsx +++ b/x-pack/plugins/ingest_pipelines/public/application/components/pipeline_editor/__jest__/processors/community_id.test.tsx @@ -6,13 +6,14 @@ */ import { act } from 'react-dom/test-utils'; -import { setup, SetupResult, getProcessorValue } from './processor.helpers'; +import { setup, SetupResult, getProcessorValue, setupEnvironment } from './processor.helpers'; const COMMUNITY_ID_TYPE = 'community_id'; describe('Processor: Community id', () => { let onUpdate: jest.Mock; let testBed: SetupResult; + const { httpSetup } = setupEnvironment(); beforeAll(() => { jest.useFakeTimers(); @@ -26,7 +27,7 @@ describe('Processor: Community id', () => { onUpdate = jest.fn(); await act(async () => { - testBed = await setup({ + testBed = await setup(httpSetup, { value: { processors: [], }, diff --git a/x-pack/plugins/ingest_pipelines/public/application/components/pipeline_editor/__jest__/processors/convert.test.tsx b/x-pack/plugins/ingest_pipelines/public/application/components/pipeline_editor/__jest__/processors/convert.test.tsx index 5a58a7b595c90..3090e59b32e0b 100644 --- a/x-pack/plugins/ingest_pipelines/public/application/components/pipeline_editor/__jest__/processors/convert.test.tsx +++ b/x-pack/plugins/ingest_pipelines/public/application/components/pipeline_editor/__jest__/processors/convert.test.tsx @@ -6,7 +6,7 @@ */ import { act } from 'react-dom/test-utils'; -import { setup, SetupResult, getProcessorValue } from './processor.helpers'; +import { setup, SetupResult, getProcessorValue, setupEnvironment } from './processor.helpers'; // Default parameter values automatically added to the `convert processor` when saved const defaultConvertParameters = { @@ -23,6 +23,7 @@ const CONVERT_TYPE = 'convert'; describe('Processor: Convert', () => { let onUpdate: jest.Mock; let testBed: SetupResult; + const { httpSetup } = setupEnvironment(); beforeAll(() => { jest.useFakeTimers(); @@ -36,7 +37,7 @@ describe('Processor: Convert', () => { onUpdate = jest.fn(); await act(async () => { - testBed = await setup({ + testBed = await setup(httpSetup, { value: { processors: [], }, diff --git a/x-pack/plugins/ingest_pipelines/public/application/components/pipeline_editor/__jest__/processors/csv.test.tsx b/x-pack/plugins/ingest_pipelines/public/application/components/pipeline_editor/__jest__/processors/csv.test.tsx index b40b46967dae5..6414976b56f9a 100644 --- a/x-pack/plugins/ingest_pipelines/public/application/components/pipeline_editor/__jest__/processors/csv.test.tsx +++ b/x-pack/plugins/ingest_pipelines/public/application/components/pipeline_editor/__jest__/processors/csv.test.tsx @@ -6,7 +6,7 @@ */ import { act } from 'react-dom/test-utils'; -import { setup, SetupResult, getProcessorValue } from './processor.helpers'; +import { setup, SetupResult, getProcessorValue, setupEnvironment } from './processor.helpers'; // Default parameter values automatically added to the CSV processor when saved const defaultCSVParameters = { @@ -26,6 +26,7 @@ const CSV_TYPE = 'csv'; describe('Processor: CSV', () => { let onUpdate: jest.Mock; let testBed: SetupResult; + const { httpSetup } = setupEnvironment(); beforeAll(() => { jest.useFakeTimers(); @@ -39,7 +40,7 @@ describe('Processor: CSV', () => { onUpdate = jest.fn(); await act(async () => { - testBed = await setup({ + testBed = await setup(httpSetup, { value: { processors: [], }, diff --git a/x-pack/plugins/ingest_pipelines/public/application/components/pipeline_editor/__jest__/processors/date.test.tsx b/x-pack/plugins/ingest_pipelines/public/application/components/pipeline_editor/__jest__/processors/date.test.tsx index 390f8e0191ce9..22666ebbe2a98 100644 --- a/x-pack/plugins/ingest_pipelines/public/application/components/pipeline_editor/__jest__/processors/date.test.tsx +++ b/x-pack/plugins/ingest_pipelines/public/application/components/pipeline_editor/__jest__/processors/date.test.tsx @@ -6,13 +6,14 @@ */ import { act } from 'react-dom/test-utils'; -import { setup, SetupResult, getProcessorValue } from './processor.helpers'; +import { setup, SetupResult, getProcessorValue, setupEnvironment } from './processor.helpers'; const DATE_TYPE = 'date'; describe('Processor: Date', () => { let onUpdate: jest.Mock; let testBed: SetupResult; + const { httpSetup } = setupEnvironment(); beforeAll(() => { jest.useFakeTimers(); @@ -26,7 +27,7 @@ describe('Processor: Date', () => { onUpdate = jest.fn(); await act(async () => { - testBed = await setup({ + testBed = await setup(httpSetup, { value: { processors: [], }, diff --git a/x-pack/plugins/ingest_pipelines/public/application/components/pipeline_editor/__jest__/processors/date_index.test.tsx b/x-pack/plugins/ingest_pipelines/public/application/components/pipeline_editor/__jest__/processors/date_index.test.tsx index 264db2c5b65c0..b9e990f36c15b 100644 --- a/x-pack/plugins/ingest_pipelines/public/application/components/pipeline_editor/__jest__/processors/date_index.test.tsx +++ b/x-pack/plugins/ingest_pipelines/public/application/components/pipeline_editor/__jest__/processors/date_index.test.tsx @@ -6,13 +6,14 @@ */ import { act } from 'react-dom/test-utils'; -import { setup, SetupResult, getProcessorValue } from './processor.helpers'; +import { setup, SetupResult, getProcessorValue, setupEnvironment } from './processor.helpers'; const DATE_INDEX_TYPE = 'date_index_name'; describe('Processor: Date Index Name', () => { let onUpdate: jest.Mock; let testBed: SetupResult; + const { httpSetup } = setupEnvironment(); beforeAll(() => { jest.useFakeTimers(); @@ -26,7 +27,7 @@ describe('Processor: Date Index Name', () => { onUpdate = jest.fn(); await act(async () => { - testBed = await setup({ + testBed = await setup(httpSetup, { value: { processors: [], }, diff --git a/x-pack/plugins/ingest_pipelines/public/application/components/pipeline_editor/__jest__/processors/dot_expander.test.tsx b/x-pack/plugins/ingest_pipelines/public/application/components/pipeline_editor/__jest__/processors/dot_expander.test.tsx index eb93f4ea86449..7ebad2de01a92 100644 --- a/x-pack/plugins/ingest_pipelines/public/application/components/pipeline_editor/__jest__/processors/dot_expander.test.tsx +++ b/x-pack/plugins/ingest_pipelines/public/application/components/pipeline_editor/__jest__/processors/dot_expander.test.tsx @@ -6,13 +6,14 @@ */ import { act } from 'react-dom/test-utils'; -import { setup, SetupResult, getProcessorValue } from './processor.helpers'; +import { setup, SetupResult, getProcessorValue, setupEnvironment } from './processor.helpers'; const DOT_EXPANDER_TYPE = 'dot_expander'; describe('Processor: Dot Expander', () => { let onUpdate: jest.Mock; let testBed: SetupResult; + const { httpSetup } = setupEnvironment(); beforeAll(() => { jest.useFakeTimers(); @@ -26,7 +27,7 @@ describe('Processor: Dot Expander', () => { onUpdate = jest.fn(); await act(async () => { - testBed = await setup({ + testBed = await setup(httpSetup, { value: { processors: [], }, diff --git a/x-pack/plugins/ingest_pipelines/public/application/components/pipeline_editor/__jest__/processors/fail.test.tsx b/x-pack/plugins/ingest_pipelines/public/application/components/pipeline_editor/__jest__/processors/fail.test.tsx index db5840379536a..9b8148bd0dffd 100644 --- a/x-pack/plugins/ingest_pipelines/public/application/components/pipeline_editor/__jest__/processors/fail.test.tsx +++ b/x-pack/plugins/ingest_pipelines/public/application/components/pipeline_editor/__jest__/processors/fail.test.tsx @@ -6,12 +6,13 @@ */ import { act } from 'react-dom/test-utils'; -import { setup, SetupResult, getProcessorValue } from './processor.helpers'; +import { setup, SetupResult, getProcessorValue, setupEnvironment } from './processor.helpers'; const FAIL_TYPE = 'fail'; describe('Processor: Fail', () => { let onUpdate: jest.Mock; let testBed: SetupResult; + const { httpSetup } = setupEnvironment(); beforeAll(() => { jest.useFakeTimers(); @@ -25,7 +26,7 @@ describe('Processor: Fail', () => { onUpdate = jest.fn(); await act(async () => { - testBed = await setup({ + testBed = await setup(httpSetup, { value: { processors: [], }, diff --git a/x-pack/plugins/ingest_pipelines/public/application/components/pipeline_editor/__jest__/processors/fingerprint.test.tsx b/x-pack/plugins/ingest_pipelines/public/application/components/pipeline_editor/__jest__/processors/fingerprint.test.tsx index 7c2ca012a0460..49d7937fab002 100644 --- a/x-pack/plugins/ingest_pipelines/public/application/components/pipeline_editor/__jest__/processors/fingerprint.test.tsx +++ b/x-pack/plugins/ingest_pipelines/public/application/components/pipeline_editor/__jest__/processors/fingerprint.test.tsx @@ -6,7 +6,7 @@ */ import { act } from 'react-dom/test-utils'; -import { setup, SetupResult, getProcessorValue } from './processor.helpers'; +import { setup, SetupResult, getProcessorValue, setupEnvironment } from './processor.helpers'; // Default parameter values automatically added to the registered domain processor when saved const defaultFingerprintParameters = { @@ -25,6 +25,7 @@ const FINGERPRINT_TYPE = 'fingerprint'; describe('Processor: Fingerprint', () => { let onUpdate: jest.Mock; let testBed: SetupResult; + const { httpSetup } = setupEnvironment(); beforeAll(() => { jest.useFakeTimers(); @@ -38,7 +39,7 @@ describe('Processor: Fingerprint', () => { onUpdate = jest.fn(); await act(async () => { - testBed = await setup({ + testBed = await setup(httpSetup, { value: { processors: [], }, diff --git a/x-pack/plugins/ingest_pipelines/public/application/components/pipeline_editor/__jest__/processors/network_direction.test.tsx b/x-pack/plugins/ingest_pipelines/public/application/components/pipeline_editor/__jest__/processors/network_direction.test.tsx index 7a4c55d6f5e02..4f92aec06efd3 100644 --- a/x-pack/plugins/ingest_pipelines/public/application/components/pipeline_editor/__jest__/processors/network_direction.test.tsx +++ b/x-pack/plugins/ingest_pipelines/public/application/components/pipeline_editor/__jest__/processors/network_direction.test.tsx @@ -6,7 +6,7 @@ */ import { act } from 'react-dom/test-utils'; -import { setup, SetupResult, getProcessorValue } from './processor.helpers'; +import { setup, SetupResult, getProcessorValue, setupEnvironment } from './processor.helpers'; // Default parameter values automatically added to the network direction processor when saved const defaultNetworkDirectionParameters = { @@ -27,6 +27,7 @@ const NETWORK_DIRECTION_TYPE = 'network_direction'; describe('Processor: Network Direction', () => { let onUpdate: jest.Mock; let testBed: SetupResult; + const { httpSetup } = setupEnvironment(); beforeAll(() => { jest.useFakeTimers(); @@ -40,7 +41,7 @@ describe('Processor: Network Direction', () => { onUpdate = jest.fn(); await act(async () => { - testBed = await setup({ + testBed = await setup(httpSetup, { value: { processors: [], }, diff --git a/x-pack/plugins/ingest_pipelines/public/application/components/pipeline_editor/__jest__/processors/processor.helpers.tsx b/x-pack/plugins/ingest_pipelines/public/application/components/pipeline_editor/__jest__/processors/processor.helpers.tsx index ec68c3b3bfdf6..0e7431964c84b 100644 --- a/x-pack/plugins/ingest_pipelines/public/application/components/pipeline_editor/__jest__/processors/processor.helpers.tsx +++ b/x-pack/plugins/ingest_pipelines/public/application/components/pipeline_editor/__jest__/processors/processor.helpers.tsx @@ -7,10 +7,9 @@ import { act } from 'react-dom/test-utils'; import React from 'react'; -import axios from 'axios'; -import axiosXhrAdapter from 'axios/lib/adapters/xhr'; import { usageCollectionPluginMock } from 'src/plugins/usage_collection/public/mocks'; +import { HttpSetup } from 'kibana/public'; import { registerTestBed, TestBed } from '@kbn/test-jest-helpers'; import { stubWebWorker } from '@kbn/test-jest-helpers'; @@ -102,7 +101,9 @@ const createActions = (testBed: TestBed) => { }; }; -export const setup = async (props: Props): Promise => { +export const setup = async (httpSetup: HttpSetup, props: Props): Promise => { + apiService.setup(httpSetup, uiMetricService); + const testBed = testBedSetup(props); return { ...testBed, @@ -110,19 +111,11 @@ export const setup = async (props: Props): Promise => { }; }; -const mockHttpClient = axios.create({ adapter: axiosXhrAdapter }); - export const setupEnvironment = () => { // Initialize mock services uiMetricService.setup(usageCollectionPluginMock.createSetupContract()); - // @ts-ignore - apiService.setup(mockHttpClient, uiMetricService); - - const { httpRequestsMockHelpers } = initHttpRequests(); - return { - httpRequestsMockHelpers, - }; + return initHttpRequests(); }; export const getProcessorValue = (onUpdate: jest.Mock, type: string) => { diff --git a/x-pack/plugins/ingest_pipelines/public/application/components/pipeline_editor/__jest__/processors/processor_form.test.tsx b/x-pack/plugins/ingest_pipelines/public/application/components/pipeline_editor/__jest__/processors/processor_form.test.tsx index de0061dcb0407..b2e2fb81f2c86 100644 --- a/x-pack/plugins/ingest_pipelines/public/application/components/pipeline_editor/__jest__/processors/processor_form.test.tsx +++ b/x-pack/plugins/ingest_pipelines/public/application/components/pipeline_editor/__jest__/processors/processor_form.test.tsx @@ -6,11 +6,12 @@ */ import { act } from 'react-dom/test-utils'; -import { setup, SetupResult } from './processor.helpers'; +import { setup, SetupResult, setupEnvironment } from './processor.helpers'; describe('Processor: Bytes', () => { let onUpdate: jest.Mock; let testBed: SetupResult; + const { httpSetup } = setupEnvironment(); beforeAll(() => { jest.useFakeTimers(); @@ -24,7 +25,7 @@ describe('Processor: Bytes', () => { onUpdate = jest.fn(); await act(async () => { - testBed = await setup({ + testBed = await setup(httpSetup, { value: { processors: [], }, diff --git a/x-pack/plugins/ingest_pipelines/public/application/components/pipeline_editor/__jest__/processors/registered_domain.test.tsx b/x-pack/plugins/ingest_pipelines/public/application/components/pipeline_editor/__jest__/processors/registered_domain.test.tsx index 962e099f5b667..dcf332912a94b 100644 --- a/x-pack/plugins/ingest_pipelines/public/application/components/pipeline_editor/__jest__/processors/registered_domain.test.tsx +++ b/x-pack/plugins/ingest_pipelines/public/application/components/pipeline_editor/__jest__/processors/registered_domain.test.tsx @@ -6,7 +6,7 @@ */ import { act } from 'react-dom/test-utils'; -import { setup, SetupResult, getProcessorValue } from './processor.helpers'; +import { setup, SetupResult, getProcessorValue, setupEnvironment } from './processor.helpers'; // Default parameter values automatically added to the registered domain processor when saved const defaultRegisteredDomainParameters = { @@ -21,6 +21,7 @@ const REGISTERED_DOMAIN_TYPE = 'registered_domain'; describe('Processor: Registered Domain', () => { let onUpdate: jest.Mock; let testBed: SetupResult; + const { httpSetup } = setupEnvironment(); beforeAll(() => { jest.useFakeTimers(); @@ -34,7 +35,7 @@ describe('Processor: Registered Domain', () => { onUpdate = jest.fn(); await act(async () => { - testBed = await setup({ + testBed = await setup(httpSetup, { value: { processors: [], }, diff --git a/x-pack/plugins/ingest_pipelines/public/application/components/pipeline_editor/__jest__/processors/set.test.tsx b/x-pack/plugins/ingest_pipelines/public/application/components/pipeline_editor/__jest__/processors/set.test.tsx index 544b8aeb51c05..ebfa678648904 100644 --- a/x-pack/plugins/ingest_pipelines/public/application/components/pipeline_editor/__jest__/processors/set.test.tsx +++ b/x-pack/plugins/ingest_pipelines/public/application/components/pipeline_editor/__jest__/processors/set.test.tsx @@ -6,13 +6,14 @@ */ import { act } from 'react-dom/test-utils'; -import { setup, SetupResult, getProcessorValue } from './processor.helpers'; +import { setup, SetupResult, getProcessorValue, setupEnvironment } from './processor.helpers'; const SET_TYPE = 'set'; describe('Processor: Set', () => { let onUpdate: jest.Mock; let testBed: SetupResult; + const { httpSetup } = setupEnvironment(); beforeAll(() => { jest.useFakeTimers(); @@ -26,7 +27,7 @@ describe('Processor: Set', () => { onUpdate = jest.fn(); await act(async () => { - testBed = await setup({ + testBed = await setup(httpSetup, { value: { processors: [], }, diff --git a/x-pack/plugins/ingest_pipelines/public/application/components/pipeline_editor/__jest__/processors/uri_parts.test.tsx b/x-pack/plugins/ingest_pipelines/public/application/components/pipeline_editor/__jest__/processors/uri_parts.test.tsx index 442788a7f75aa..9062fcc02f7f8 100644 --- a/x-pack/plugins/ingest_pipelines/public/application/components/pipeline_editor/__jest__/processors/uri_parts.test.tsx +++ b/x-pack/plugins/ingest_pipelines/public/application/components/pipeline_editor/__jest__/processors/uri_parts.test.tsx @@ -6,7 +6,7 @@ */ import { act } from 'react-dom/test-utils'; -import { setup, SetupResult, getProcessorValue } from './processor.helpers'; +import { setup, SetupResult, getProcessorValue, setupEnvironment } from './processor.helpers'; // Default parameter values automatically added to the URI parts processor when saved const defaultUriPartsParameters = { @@ -19,6 +19,7 @@ const URI_PARTS_TYPE = 'uri_parts'; describe('Processor: URI parts', () => { let onUpdate: jest.Mock; let testBed: SetupResult; + const { httpSetup } = setupEnvironment(); beforeAll(() => { jest.useFakeTimers(); @@ -32,7 +33,7 @@ describe('Processor: URI parts', () => { onUpdate = jest.fn(); await act(async () => { - testBed = await setup({ + testBed = await setup(httpSetup, { value: { processors: [], }, diff --git a/x-pack/plugins/ingest_pipelines/public/application/components/pipeline_editor/__jest__/processors/user_agent.test.tsx b/x-pack/plugins/ingest_pipelines/public/application/components/pipeline_editor/__jest__/processors/user_agent.test.tsx index fa1c24c9dfb39..ed778aa1cc1f3 100644 --- a/x-pack/plugins/ingest_pipelines/public/application/components/pipeline_editor/__jest__/processors/user_agent.test.tsx +++ b/x-pack/plugins/ingest_pipelines/public/application/components/pipeline_editor/__jest__/processors/user_agent.test.tsx @@ -6,7 +6,7 @@ */ import { act } from 'react-dom/test-utils'; -import { setup, SetupResult, getProcessorValue } from './processor.helpers'; +import { setup, SetupResult, getProcessorValue, setupEnvironment } from './processor.helpers'; // Default parameter values automatically added to the user agent processor when saved const defaultUserAgentParameters = { @@ -24,6 +24,7 @@ const USER_AGENT_TYPE = 'user_agent'; describe('Processor: User Agent', () => { let onUpdate: jest.Mock; let testBed: SetupResult; + const { httpSetup } = setupEnvironment(); beforeAll(() => { jest.useFakeTimers(); @@ -37,7 +38,7 @@ describe('Processor: User Agent', () => { onUpdate = jest.fn(); await act(async () => { - testBed = await setup({ + testBed = await setup(httpSetup, { value: { processors: [], }, From 6f33057db80fc798ce4787475f03eae14b1fda3f Mon Sep 17 00:00:00 2001 From: Ignacio Rivas Date: Wed, 13 Apr 2022 11:16:38 +0200 Subject: [PATCH 2/4] Remove last axios dep from index management --- .../__jest__/components/index_table.test.js | 64 ++++--------------- 1 file changed, 14 insertions(+), 50 deletions(-) diff --git a/x-pack/plugins/index_management/__jest__/components/index_table.test.js b/x-pack/plugins/index_management/__jest__/components/index_table.test.js index bf5ab6541bad8..267fbdb19a975 100644 --- a/x-pack/plugins/index_management/__jest__/components/index_table.test.js +++ b/x-pack/plugins/index_management/__jest__/components/index_table.test.js @@ -8,10 +8,7 @@ import React from 'react'; import { Provider } from 'react-redux'; import { MemoryRouter } from 'react-router-dom'; -import axios from 'axios'; -import sinon from 'sinon'; import { findTestSubject } from '@elastic/eui/lib/test'; -import axiosXhrAdapter from 'axios/lib/adapters/xhr'; /** * The below import is required to avoid a console error warn from brace package @@ -20,6 +17,7 @@ import axiosXhrAdapter from 'axios/lib/adapters/xhr'; at createWorker (//node_modules/brace/index.js:17992:5) */ import { mountWithIntl, stubWebWorker } from '@kbn/test-jest-helpers'; // eslint-disable-line no-unused-vars +import { init as initHttpRequests } from '../client_integration/helpers/http_requests'; import { BASE_PATH, API_BASE_PATH } from '../../common/constants'; import { AppWithoutRouter } from '../../public/application/app'; @@ -40,9 +38,6 @@ import { executionContextServiceMock, } from '../../../../../src/core/public/mocks'; -const mockHttpClient = axios.create({ adapter: axiosXhrAdapter }); - -let server = null; let store = null; const indices = []; @@ -149,6 +144,8 @@ const getActionMenuButtons = (rendered) => { .map((span) => span.text()); }; describe('index table', () => { + const { httpSetup, httpRequestsMockHelpers } = initHttpRequests(); + beforeEach(() => { // Mock initialization of services const services = { @@ -159,8 +156,7 @@ describe('index table', () => { setExtensionsService(services.extensionsService); setUiMetricService(services.uiMetricService); - // @ts-ignore - httpService.setup(mockHttpClient); + httpService.setup(httpSetup); breadcrumbService.setup(() => undefined); notificationService.setup(notificationServiceMock.createStartContract()); @@ -186,35 +182,12 @@ describe('index table', () => { ); store.dispatch(loadIndicesSuccess({ indices })); - server = sinon.fakeServer.create(); - - server.respondWith(`${API_BASE_PATH}/indices`, [ - 200, - { 'Content-Type': 'application/json' }, - JSON.stringify(indices), - ]); - - server.respondWith([ - 200, - { 'Content-Type': 'application/json' }, - JSON.stringify({ acknowledged: true }), - ]); - - server.respondWith(`${API_BASE_PATH}/indices/reload`, [ - 200, - { 'Content-Type': 'application/json' }, - JSON.stringify(indices), - ]); - - server.respondImmediately = true; - }); - afterEach(() => { - if (!server) { - return; - } - server.restore(); + + httpRequestsMockHelpers.setLoadIndicesResponse(indices); + httpRequestsMockHelpers.setReloadIndicesResponse(indices); }); + test('should change pages when a pagination link is clicked on', async () => { const rendered = mountWithIntl(component); await runAllPromises(); @@ -476,22 +449,17 @@ describe('index table', () => { }); test('close index button works from context menu', async () => { - const rendered = mountWithIntl(component); - await runAllPromises(); - rendered.update(); - const modifiedIndices = indices.map((index) => { return { ...index, status: index.name === 'testy0' ? 'close' : index.status, }; }); + httpRequestsMockHelpers.setReloadIndicesResponse(modifiedIndices); - server.respondWith(`${API_BASE_PATH}/indices/reload`, [ - 200, - { 'Content-Type': 'application/json' }, - JSON.stringify(modifiedIndices), - ]); + const rendered = mountWithIntl(component); + await runAllPromises(); + rendered.update(); testAction(rendered, 'closeIndexMenuButton'); }); @@ -503,16 +471,12 @@ describe('index table', () => { status: index.name === 'testy1' ? 'closed' : index.status, }; }); - - server.respondWith(`${API_BASE_PATH}/indices`, [ - 200, - { 'Content-Type': 'application/json' }, - JSON.stringify(modifiedIndices), - ]); + httpRequestsMockHelpers.setLoadIndicesResponse(modifiedIndices); const rendered = mountWithIntl(component); await runAllPromises(); rendered.update(); + testAction(rendered, 'openIndexMenuButton', 'testy1'); }); From 06a9d798df83fe5eabaf407e1cd582304d19f6f1 Mon Sep 17 00:00:00 2001 From: Ignacio Rivas Date: Wed, 13 Apr 2022 11:18:24 +0200 Subject: [PATCH 3/4] commit using @elastic.co From 753884e99a3623f25d7b59cbd15a8bdb5cee255d Mon Sep 17 00:00:00 2001 From: Ignacio Rivas Date: Wed, 13 Apr 2022 11:18:36 +0200 Subject: [PATCH 4/4] Fix linter errors --- .../index_management/__jest__/components/index_table.test.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/x-pack/plugins/index_management/__jest__/components/index_table.test.js b/x-pack/plugins/index_management/__jest__/components/index_table.test.js index 267fbdb19a975..d6d2b1da9670f 100644 --- a/x-pack/plugins/index_management/__jest__/components/index_table.test.js +++ b/x-pack/plugins/index_management/__jest__/components/index_table.test.js @@ -19,7 +19,7 @@ import { findTestSubject } from '@elastic/eui/lib/test'; import { mountWithIntl, stubWebWorker } from '@kbn/test-jest-helpers'; // eslint-disable-line no-unused-vars import { init as initHttpRequests } from '../client_integration/helpers/http_requests'; -import { BASE_PATH, API_BASE_PATH } from '../../common/constants'; +import { BASE_PATH } from '../../common/constants'; import { AppWithoutRouter } from '../../public/application/app'; import { AppContextProvider } from '../../public/application/app_context'; import { loadIndicesSuccess } from '../../public/application/store/actions'; @@ -187,7 +187,6 @@ describe('index table', () => { httpRequestsMockHelpers.setReloadIndicesResponse(indices); }); - test('should change pages when a pagination link is clicked on', async () => { const rendered = mountWithIntl(component); await runAllPromises();