From c65b935fae9c52f8535a5c621ca2e63374bf9d29 Mon Sep 17 00:00:00 2001 From: Walter Rafelsberger Date: Thu, 5 Dec 2024 16:59:00 +0100 Subject: [PATCH] [ML] Transform: Fix jest test. (#195998) ## Summary Fixes #195992 (failing test). Updates the mock for the preview endpoint to make the test pass again. ### Checklist - [x] [Unit or functional tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html) were updated or added to match the most common scenarios - [x] This was checked for breaking API changes and was [labeled appropriately](https://www.elastic.co/guide/en/kibana/master/contributing.html#_add_your_labels) (cherry picked from commit c4d64039b3c23433eb643f3a772357407695d024) --- .../transform/public/app/__mocks__/app_dependencies.tsx | 9 ++++++++- .../components/step_define/step_define_summary.test.tsx | 4 +--- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/x-pack/plugins/transform/public/app/__mocks__/app_dependencies.tsx b/x-pack/plugins/transform/public/app/__mocks__/app_dependencies.tsx index cdb159c158d10..49bd43232c9f5 100644 --- a/x-pack/plugins/transform/public/app/__mocks__/app_dependencies.tsx +++ b/x-pack/plugins/transform/public/app/__mocks__/app_dependencies.tsx @@ -67,7 +67,14 @@ dataStart.search.search = jest.fn(({ params }: IKibanaSearchRequest) => { }) as ISearchGeneric; // Replace mock to support tests for `use_index_data`. -coreSetup.http.post = jest.fn().mockResolvedValue([]); +coreSetup.http.post = jest.fn().mockImplementation((endpoint) => { + if (endpoint === '/internal/transform/transforms/_preview') { + return Promise.resolve({ + generated_dest_index: { mappings: { properties: {} } }, + preview: [], + }); + } +}); const appDependencies: AppDependencies = { analytics: coreStart.analytics, 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 5b6e314e951aa..7c08a2462f65a 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,9 +20,7 @@ import { StepDefineSummary } from './step_define_summary'; jest.mock('../../../../app_dependencies'); -// Failing: https://github.com/elastic/kibana/issues/195992 -describe.skip('Transform: ', () => { - // Using the async/await wait()/done() pattern to avoid act() errors. +describe('Transform: ', () => { test('Minimal initialization', async () => { // Arrange const queryClient = new QueryClient();