From 95d93cdfa5e6c066c0be53b2f58158330ff6cb86 Mon Sep 17 00:00:00 2001 From: zhichao-aws Date: Wed, 31 May 2023 10:28:21 +0800 Subject: [PATCH] Fix flush flaky test (#779) * fix tests Signed-off-by: zhichao-aws * modify release notes Signed-off-by: zhichao-aws --------- Signed-off-by: zhichao-aws (cherry picked from commit 78964cd009f533498f7d333d429abd172c4330d6) --- .../AliasActions/AliasActions.test.tsx | 12 +- .../__snapshots__/AliasActions.test.tsx.snap | 172 ------------------ .../DataStreamsActions.test.tsx | 11 +- .../DataStreamsActions.test.tsx.snap | 153 ---------------- .../IndicesActions/IndicesActions.test.tsx | 4 +- ...dashboards-plugin.release-notes-2.8.0.0.md | 2 +- 6 files changed, 14 insertions(+), 340 deletions(-) diff --git a/public/pages/Aliases/containers/AliasActions/AliasActions.test.tsx b/public/pages/Aliases/containers/AliasActions/AliasActions.test.tsx index 984bdf7ba..4ae8cc4ae 100644 --- a/public/pages/Aliases/containers/AliasActions/AliasActions.test.tsx +++ b/public/pages/Aliases/containers/AliasActions/AliasActions.test.tsx @@ -6,7 +6,6 @@ import React from "react"; import "@testing-library/jest-dom/extend-expect"; import { render, waitFor } from "@testing-library/react"; -// @ts-ignore import userEvent from "@testing-library/user-event"; import { browserServicesMock, coreServicesMock } from "../../../../../test/mocks"; import AliasesActions, { AliasesActionsProps } from "./index"; @@ -14,7 +13,6 @@ import { ModalProvider } from "../../../../components/Modal"; import { ServicesContext } from "../../../../services"; import { CoreServicesContext } from "../../../../components/core_services"; import { buildMockApiCallerForFlush, selectedAliases } from "../../../../containers/FlushIndexModal/FlushIndexModalTestHelper"; -import { act } from "react-dom/test-utils"; import { IAlias } from "../../interface"; function renderWithRouter(props: Omit) { @@ -359,7 +357,7 @@ describe(" spec", () => { it("renders flush component", async () => { browserServicesMock.commonService.apiCaller = buildMockApiCallerForFlush(); - const { getByTestId, getByText } = render( + const { getByTestId, getByText, queryByTestId } = render( @@ -370,9 +368,11 @@ describe(" spec", () => { ); userEvent.click(document.querySelector('[data-test-subj="moreAction"] button') as Element); userEvent.click(getByTestId("Flush Action")); - await act(async () => {}); - expect(getByText("The following aliases will be flushed:")).toBeInTheDocument(); - expect(document.body.children).toMatchSnapshot(); + await waitFor(() => { + expect(queryByTestId("Flush Action")).toBeNull(); + expect(getByText("The following aliases will be flushed:")).toBeInTheDocument(); + expect(document.body.children).toMatchSnapshot(); + }); }); it("flush all aliases disabled", async () => { diff --git a/public/pages/Aliases/containers/AliasActions/__snapshots__/AliasActions.test.tsx.snap b/public/pages/Aliases/containers/AliasActions/__snapshots__/AliasActions.test.tsx.snap index 2874e21ba..0db264c08 100644 --- a/public/pages/Aliases/containers/AliasActions/__snapshots__/AliasActions.test.tsx.snap +++ b/public/pages/Aliases/containers/AliasActions/__snapshots__/AliasActions.test.tsx.snap @@ -466,178 +466,6 @@ HTMLCollection [ , -