From 933cbc0d2aa7115833dacdb0f0fa9a6a127debfd Mon Sep 17 00:00:00 2001 From: Kibana Machine <42973632+kibanamachine@users.noreply.github.com> Date: Mon, 21 Oct 2024 23:40:53 +1100 Subject: [PATCH] [8.x] [Cases][Flaky Test] Memoize test provider (#195088) (#197008) # Backport This will backport the following commits from `main` to `8.x`: - [[Cases][Flaky Test] Memoize test provider (#195088)](https://github.com/elastic/kibana/pull/195088) ### Questions ? Please refer to the [Backport tool documentation](https://github.com/sqren/backport) Co-authored-by: Julian Gernun <17549662+jcger@users.noreply.github.com> --- .../public/common/mock/test_providers.tsx | 46 +++++++++---------- .../components/all_cases/utility_bar.test.tsx | 10 ++++ 2 files changed, 31 insertions(+), 25 deletions(-) diff --git a/x-pack/plugins/cases/public/common/mock/test_providers.tsx b/x-pack/plugins/cases/public/common/mock/test_providers.tsx index aef1024cc8afc..257ac4b1f8293 100644 --- a/x-pack/plugins/cases/public/common/mock/test_providers.tsx +++ b/x-pack/plugins/cases/public/common/mock/test_providers.tsx @@ -89,22 +89,20 @@ const TestProvidersComponent: React.FC = ({ }); const getFilesClient = mockGetFilesClient(); + const casesProviderValue = { + externalReferenceAttachmentTypeRegistry, + persistableStateAttachmentTypeRegistry, + features, + owner, + permissions, + getFilesClient, + }; return ( - + {children} @@ -170,23 +168,20 @@ export const createAppMockRenderer = ({ }); const getFilesClient = mockGetFilesClient(); - + const casesProviderValue = { + externalReferenceAttachmentTypeRegistry, + persistableStateAttachmentTypeRegistry, + features, + owner, + permissions, + releasePhase, + getFilesClient, + }; const AppWrapper: React.FC<{ children: React.ReactNode }> = ({ children }) => ( - + {children} @@ -195,10 +190,11 @@ export const createAppMockRenderer = ({ ); AppWrapper.displayName = 'AppWrapper'; + const memoizedAppWrapper = React.memo(AppWrapper); const render: UiRender = (ui, options) => { return reactRender(ui, { - wrapper: AppWrapper, + wrapper: memoizedAppWrapper, ...options, }); }; diff --git a/x-pack/plugins/cases/public/components/all_cases/utility_bar.test.tsx b/x-pack/plugins/cases/public/components/all_cases/utility_bar.test.tsx index bd72a460c8c71..63d8cd2e5faab 100644 --- a/x-pack/plugins/cases/public/components/all_cases/utility_bar.test.tsx +++ b/x-pack/plugins/cases/public/components/all_cases/utility_bar.test.tsx @@ -41,7 +41,17 @@ describe('Severity form field', () => { showClearFiltersButton: false, }; + beforeAll(() => { + jest.useFakeTimers(); + }); + + afterAll(() => { + jest.useRealTimers(); + sessionStorage.removeItem(localStorageKey); + }); + beforeEach(() => { + jest.useFakeTimers(); // Workaround for timeout via https://github.com/testing-library/user-event/issues/833#issuecomment-1171452841 user = userEvent.setup({ advanceTimers: jest.advanceTimersByTime,