Skip to content

Commit 7a75c3d

Browse files
Fix flush flaky test (#779) (#783)
* fix tests Signed-off-by: zhichao-aws <[email protected]> * modify release notes Signed-off-by: zhichao-aws <[email protected]> --------- Signed-off-by: zhichao-aws <[email protected]> (cherry picked from commit 78964cd) Co-authored-by: zhichao-aws <[email protected]>
1 parent 0e5dcdd commit 7a75c3d

File tree

6 files changed

+14
-340
lines changed

6 files changed

+14
-340
lines changed

public/pages/Aliases/containers/AliasActions/AliasActions.test.tsx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,13 @@
66
import React from "react";
77
import "@testing-library/jest-dom/extend-expect";
88
import { render, waitFor } from "@testing-library/react";
9-
// @ts-ignore
109
import userEvent from "@testing-library/user-event";
1110
import { browserServicesMock, coreServicesMock } from "../../../../../test/mocks";
1211
import AliasesActions, { AliasesActionsProps } from "./index";
1312
import { ModalProvider } from "../../../../components/Modal";
1413
import { ServicesContext } from "../../../../services";
1514
import { CoreServicesContext } from "../../../../components/core_services";
1615
import { buildMockApiCallerForFlush, selectedAliases } from "../../../../containers/FlushIndexModal/FlushIndexModalTestHelper";
17-
import { act } from "react-dom/test-utils";
1816
import { IAlias } from "../../interface";
1917

2018
function renderWithRouter(props: Omit<AliasesActionsProps, "history">) {
@@ -359,7 +357,7 @@ describe("<AliasesActions /> spec", () => {
359357

360358
it("renders flush component", async () => {
361359
browserServicesMock.commonService.apiCaller = buildMockApiCallerForFlush();
362-
const { getByTestId, getByText } = render(
360+
const { getByTestId, getByText, queryByTestId } = render(
363361
<CoreServicesContext.Provider value={coreServicesMock}>
364362
<ServicesContext.Provider value={browserServicesMock}>
365363
<ModalProvider>
@@ -370,9 +368,11 @@ describe("<AliasesActions /> spec", () => {
370368
);
371369
userEvent.click(document.querySelector('[data-test-subj="moreAction"] button') as Element);
372370
userEvent.click(getByTestId("Flush Action"));
373-
await act(async () => {});
374-
expect(getByText("The following aliases will be flushed:")).toBeInTheDocument();
375-
expect(document.body.children).toMatchSnapshot();
371+
await waitFor(() => {
372+
expect(queryByTestId("Flush Action")).toBeNull();
373+
expect(getByText("The following aliases will be flushed:")).toBeInTheDocument();
374+
expect(document.body.children).toMatchSnapshot();
375+
});
376376
});
377377

378378
it("flush all aliases disabled", async () => {

public/pages/Aliases/containers/AliasActions/__snapshots__/AliasActions.test.tsx.snap

Lines changed: 0 additions & 172 deletions
Original file line numberDiff line numberDiff line change
@@ -466,178 +466,6 @@ HTMLCollection [
466466
</div>
467467
</div>
468468
</div>,
469-
<div
470-
aria-hidden="true"
471-
data-aria-hidden="true"
472-
>
473-
<div
474-
data-focus-guard="true"
475-
style="width: 1px; height: 0px; padding: 0px; overflow: hidden; position: fixed; top: 1px; left: 1px;"
476-
tabindex="-1"
477-
/>
478-
<div
479-
data-focus-lock-disabled="disabled"
480-
>
481-
<div
482-
aria-describedby="some_html_id"
483-
aria-live="off"
484-
aria-modal="true"
485-
class="euiPanel euiPanel--borderRadiusMedium euiPanel--plain euiPanel--noShadow euiPopover__panel euiPopover__panel--bottom euiPopover__panel-isOpen"
486-
data-autofocus="true"
487-
role="dialog"
488-
style="top: 16px; left: -22px; z-index: 2000;"
489-
tabindex="0"
490-
>
491-
<div
492-
class="euiPopover__panelArrow euiPopover__panelArrow--bottom"
493-
style="left: 10px; top: 0px;"
494-
/>
495-
<p
496-
class="euiScreenReaderOnly"
497-
id="some_html_id"
498-
>
499-
You are in a dialog. To close this dialog, hit escape.
500-
</p>
501-
<div>
502-
<div
503-
class="euiContextMenu"
504-
style="height: 0px;"
505-
>
506-
<div
507-
class="euiContextMenuPanel euiContextMenu__panel"
508-
tabindex="-1"
509-
>
510-
<div>
511-
<div>
512-
<button
513-
class="euiContextMenuItem euiContextMenuItem-isDisabled"
514-
data-test-subj="editAction"
515-
disabled=""
516-
type="button"
517-
>
518-
<span
519-
class="euiContextMenu__itemLayout"
520-
>
521-
<span
522-
class="euiContextMenuItem__text"
523-
>
524-
Edit
525-
</span>
526-
</span>
527-
</button>
528-
<hr
529-
class="euiHorizontalRule euiHorizontalRule--full"
530-
/>
531-
<button
532-
class="euiContextMenuItem"
533-
data-test-subj="ForceMergeAction"
534-
type="button"
535-
>
536-
<span
537-
class="euiContextMenu__itemLayout"
538-
>
539-
<span
540-
class="euiContextMenuItem__text"
541-
>
542-
Force merge
543-
</span>
544-
</span>
545-
</button>
546-
<button
547-
class="euiContextMenuItem euiContextMenuItem-isDisabled"
548-
data-test-subj="rolloverAction"
549-
disabled=""
550-
type="button"
551-
>
552-
<span
553-
class="euiContextMenu__itemLayout"
554-
>
555-
<span
556-
class="euiContextMenuItem__text"
557-
>
558-
Roll over
559-
</span>
560-
</span>
561-
</button>
562-
<hr
563-
class="euiHorizontalRule euiHorizontalRule--full"
564-
/>
565-
<button
566-
class="euiContextMenuItem"
567-
data-test-subj="ClearCacheAction"
568-
type="button"
569-
>
570-
<span
571-
class="euiContextMenu__itemLayout"
572-
>
573-
<span
574-
class="euiContextMenuItem__text"
575-
>
576-
Clear cache
577-
</span>
578-
</span>
579-
</button>
580-
<button
581-
class="euiContextMenuItem"
582-
data-test-subj="Flush Action"
583-
type="button"
584-
>
585-
<span
586-
class="euiContextMenu__itemLayout"
587-
>
588-
<span
589-
class="euiContextMenuItem__text"
590-
>
591-
Flush
592-
</span>
593-
</span>
594-
</button>
595-
<button
596-
class="euiContextMenuItem"
597-
data-test-subj="refreshAction"
598-
type="button"
599-
>
600-
<span
601-
class="euiContextMenu__itemLayout"
602-
>
603-
<span
604-
class="euiContextMenuItem__text"
605-
>
606-
Refresh
607-
</span>
608-
</span>
609-
</button>
610-
<hr
611-
class="euiHorizontalRule euiHorizontalRule--full"
612-
/>
613-
<button
614-
class="euiContextMenuItem"
615-
data-test-subj="deleteAction"
616-
type="button"
617-
>
618-
<span
619-
class="euiContextMenu__itemLayout"
620-
>
621-
<span
622-
class="euiContextMenuItem__text"
623-
>
624-
Delete
625-
</span>
626-
</span>
627-
</button>
628-
</div>
629-
</div>
630-
</div>
631-
</div>
632-
</div>
633-
</div>
634-
</div>
635-
<div
636-
data-focus-guard="true"
637-
style="width: 1px; height: 0px; padding: 0px; overflow: hidden; position: fixed; top: 1px; left: 1px;"
638-
tabindex="-1"
639-
/>
640-
</div>,
641469
<div
642470
class="euiOverlayMask euiOverlayMask--aboveHeader"
643471
>

public/pages/DataStreams/containers/DataStreamsActions/DataStreamsActions.test.tsx

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ import { CoreServicesContext } from "../../../../components/core_services";
1414
import { Route, HashRouter as Router, Switch, Redirect } from "react-router-dom";
1515
import { ROUTES } from "../../../../utils/constants";
1616
import { buildMockApiCallerForFlush, selectedDataStreams } from "../../../../containers/FlushIndexModal/FlushIndexModalTestHelper";
17-
import { act } from "react-dom/test-utils";
1817
const historyPushMock = jest.fn();
1918

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

336335
it("renders flush component", async () => {
337336
browserServicesMock.commonService.apiCaller = buildMockApiCallerForFlush();
338-
const { getByTestId, getByText } = render(
337+
const { getByTestId, getByText, queryByTestId } = render(
339338
<CoreServicesContext.Provider value={coreServicesMock}>
340339
<ServicesContext.Provider value={browserServicesMock}>
341340
<Router>
@@ -367,9 +366,11 @@ describe("<DataStreamsActions /> spec", () => {
367366
);
368367
userEvent.click(document.querySelector('[data-test-subj="moreAction"] button') as Element);
369368
userEvent.click(getByTestId("Flush Action"));
370-
await act(async () => {});
371-
expect(getByText("The following data streams will be flushed:")).toBeInTheDocument();
372-
expect(document.body.children).toMatchSnapshot();
369+
await waitFor(() => {
370+
expect(queryByTestId("Flush Action")).toBeNull();
371+
expect(getByText("The following data streams will be flushed:")).toBeInTheDocument();
372+
expect(document.body.children).toMatchSnapshot();
373+
});
373374
});
374375

375376
it("flush all data streams disabled", async () => {

0 commit comments

Comments
 (0)