Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Backport 2.8] Fix flush flaky test #783

Merged
merged 1 commit into from
May 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,13 @@
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";
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<AliasesActionsProps, "history">) {
Expand Down Expand Up @@ -359,7 +357,7 @@ describe("<AliasesActions /> spec", () => {

it("renders flush component", async () => {
browserServicesMock.commonService.apiCaller = buildMockApiCallerForFlush();
const { getByTestId, getByText } = render(
const { getByTestId, getByText, queryByTestId } = render(
<CoreServicesContext.Provider value={coreServicesMock}>
<ServicesContext.Provider value={browserServicesMock}>
<ModalProvider>
Expand All @@ -370,9 +368,11 @@ describe("<AliasesActions /> 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 () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -466,178 +466,6 @@ HTMLCollection [
</div>
</div>
</div>,
<div
aria-hidden="true"
data-aria-hidden="true"
>
<div
data-focus-guard="true"
style="width: 1px; height: 0px; padding: 0px; overflow: hidden; position: fixed; top: 1px; left: 1px;"
tabindex="-1"
/>
<div
data-focus-lock-disabled="disabled"
>
<div
aria-describedby="some_html_id"
aria-live="off"
aria-modal="true"
class="euiPanel euiPanel--borderRadiusMedium euiPanel--plain euiPanel--noShadow euiPopover__panel euiPopover__panel--bottom euiPopover__panel-isOpen"
data-autofocus="true"
role="dialog"
style="top: 16px; left: -22px; z-index: 2000;"
tabindex="0"
>
<div
class="euiPopover__panelArrow euiPopover__panelArrow--bottom"
style="left: 10px; top: 0px;"
/>
<p
class="euiScreenReaderOnly"
id="some_html_id"
>
You are in a dialog. To close this dialog, hit escape.
</p>
<div>
<div
class="euiContextMenu"
style="height: 0px;"
>
<div
class="euiContextMenuPanel euiContextMenu__panel"
tabindex="-1"
>
<div>
<div>
<button
class="euiContextMenuItem euiContextMenuItem-isDisabled"
data-test-subj="editAction"
disabled=""
type="button"
>
<span
class="euiContextMenu__itemLayout"
>
<span
class="euiContextMenuItem__text"
>
Edit
</span>
</span>
</button>
<hr
class="euiHorizontalRule euiHorizontalRule--full"
/>
<button
class="euiContextMenuItem"
data-test-subj="ForceMergeAction"
type="button"
>
<span
class="euiContextMenu__itemLayout"
>
<span
class="euiContextMenuItem__text"
>
Force merge
</span>
</span>
</button>
<button
class="euiContextMenuItem euiContextMenuItem-isDisabled"
data-test-subj="rolloverAction"
disabled=""
type="button"
>
<span
class="euiContextMenu__itemLayout"
>
<span
class="euiContextMenuItem__text"
>
Roll over
</span>
</span>
</button>
<hr
class="euiHorizontalRule euiHorizontalRule--full"
/>
<button
class="euiContextMenuItem"
data-test-subj="ClearCacheAction"
type="button"
>
<span
class="euiContextMenu__itemLayout"
>
<span
class="euiContextMenuItem__text"
>
Clear cache
</span>
</span>
</button>
<button
class="euiContextMenuItem"
data-test-subj="Flush Action"
type="button"
>
<span
class="euiContextMenu__itemLayout"
>
<span
class="euiContextMenuItem__text"
>
Flush
</span>
</span>
</button>
<button
class="euiContextMenuItem"
data-test-subj="refreshAction"
type="button"
>
<span
class="euiContextMenu__itemLayout"
>
<span
class="euiContextMenuItem__text"
>
Refresh
</span>
</span>
</button>
<hr
class="euiHorizontalRule euiHorizontalRule--full"
/>
<button
class="euiContextMenuItem"
data-test-subj="deleteAction"
type="button"
>
<span
class="euiContextMenu__itemLayout"
>
<span
class="euiContextMenuItem__text"
>
Delete
</span>
</span>
</button>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<div
data-focus-guard="true"
style="width: 1px; height: 0px; padding: 0px; overflow: hidden; position: fixed; top: 1px; left: 1px;"
tabindex="-1"
/>
</div>,
<div
class="euiOverlayMask euiOverlayMask--aboveHeader"
>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import { CoreServicesContext } from "../../../../components/core_services";
import { Route, HashRouter as Router, Switch, Redirect } from "react-router-dom";
import { ROUTES } from "../../../../utils/constants";
import { buildMockApiCallerForFlush, selectedDataStreams } from "../../../../containers/FlushIndexModal/FlushIndexModalTestHelper";
import { act } from "react-dom/test-utils";
const historyPushMock = jest.fn();

function renderWithRouter(props: Omit<DataStreamsActionsProps, "history">) {
Expand Down Expand Up @@ -335,7 +334,7 @@ describe("<DataStreamsActions /> spec", () => {

it("renders flush component", async () => {
browserServicesMock.commonService.apiCaller = buildMockApiCallerForFlush();
const { getByTestId, getByText } = render(
const { getByTestId, getByText, queryByTestId } = render(
<CoreServicesContext.Provider value={coreServicesMock}>
<ServicesContext.Provider value={browserServicesMock}>
<Router>
Expand Down Expand Up @@ -367,9 +366,11 @@ describe("<DataStreamsActions /> spec", () => {
);
userEvent.click(document.querySelector('[data-test-subj="moreAction"] button') as Element);
userEvent.click(getByTestId("Flush Action"));
await act(async () => {});
expect(getByText("The following data streams will be flushed:")).toBeInTheDocument();
expect(document.body.children).toMatchSnapshot();
await waitFor(() => {
expect(queryByTestId("Flush Action")).toBeNull();
expect(getByText("The following data streams will be flushed:")).toBeInTheDocument();
expect(document.body.children).toMatchSnapshot();
});
});

it("flush all data streams disabled", async () => {
Expand Down
Loading