The easy-to-use open source Business Intelligence and Embedded Analytics tool that lets everyone work with data :bar_chart:
TypeScript analyticsbibusiness-intelligencebusinessintelligenceclojuredashboarddatadata-analysisdata-visualizationdatabasemetabasemysqlpostgrespostgresqlreportingslacksql-editorvisualization
test: get rid of warnings in tests (#74577)
Uladzimir Havenchyk281414957670
diff --git a/frontend/src/metabase/admin/performance/hooks/useInvalidateTarget.unit.spec.tsx b/frontend/src/metabase/admin/performance/hooks/useInvalidateTarget.unit.spec.tsxindex 86908df345d..47730fc4a5b 100644--- a/frontend/src/metabase/admin/performance/hooks/useInvalidateTarget.unit.spec.tsx+++ b/frontend/src/metabase/admin/performance/hooks/useInvalidateTarget.unit.spec.tsx@@ -1,6 +1,6 @@import fetchMock from "fetch-mock";-import { renderWithProviders } from "__support__/ui";+import { act, renderWithProviders } from "__support__/ui";import type { CacheableModel } from "metabase-types/api";import { useInvalidateTarget } from "./useInvalidateTarget";@@ -22,8 +22,7 @@ function setup(targetId: number, targetModel: CacheableModel) {return { getInvalidateTarget: () => invalidateTarget! };}-async function getInvalidateRequestUrl(): Promise<URL> {- await fetchMock.callHistory.flush();+function getInvalidateRequestUrl(): URL {const calls = fetchMock.callHistory.calls();const invalidateCall = calls.find((call) =>call.url?.includes("/api/cache/invalidate"),@@ -35,9 +34,13 @@ describe("useInvalidateTarget", () => {it('should send "question" as the query param when model is "question"', async () => {const { getInvalidateTarget } = setup(1, "question");- await getInvalidateTarget()();+ // Invoking the callback triggers an RTK Query mutation whose state+ // updates must stay wrapped in act.+ await act(async () => {+ await getInvalidateTarget()();+ });- const url = await getInvalidateRequestUrl();+ const url = getInvalidateRequestUrl();expect(url.searchParams.get("question")).toBe("1");expect(url.searchParams.has("metric")).toBe(false);});@@ -45,9 +48,13 @@ describe("useInvalidateTarget", () => {it('should map "metric" to "question" in the query param', async () => {const { getInvalidateTarget } = setup(1, "metric");- await getInvalidateTarget()();+ // Invoking the callback triggers an RTK Query mutation whose state+ // updates must stay wrapped in act.+ await act(async () => {+ await getInvalidateTarget()();+ });- const url = await getInvalidateRequestUrl();+ const url = getInvalidateRequestUrl();expect(url.searchParams.get("question")).toBe("1");expect(url.searchParams.has("metric")).toBe(false);});diff --git a/frontend/src/metabase/admin/performance/hooks/useSaveStrategy.unit.spec.tsx b/frontend/src/metabase/admin/performance/hooks/useSaveStrategy.unit.spec.tsxindex 98fd1e2a340..9d2b775c8e4 100644--- a/frontend/src/metabase/admin/performance/hooks/useSaveStrategy.unit.spec.tsx+++ b/frontend/src/metabase/admin/performance/hooks/useSaveStrategy.unit.spec.tsx@@ -1,6 +1,6 @@import { setupPerformanceEndpoints } from "__support__/server-mocks/performance";import { findRequests } from "__support__/server-mocks/util";-import { renderWithProviders } from "__support__/ui";+import { act, renderWithProviders } from "__support__/ui";import type { CacheConfig, CacheStrategy } from "metabase-types/api";import { createMockCacheConfig } from "metabase-types/api/mocks";@@ -28,7 +28,9 @@ describe("useSaveStrategy", () => {const { getSaveStrategy } = setup(1, "question");- await getSaveStrategy()({ type: "inherit" });+ await act(async () => {+ await getSaveStrategy()({ type: "inherit" });+ });const deleteRequests = await findRequests("DELETE");expect(deleteRequests).toHaveLength(1);@@ -43,7 +45,9 @@ describe("useSaveStrategy", () => {const { getSaveStrategy } = setup(1, "metric");- await getSaveStrategy()({ type: "inherit" });+ await act(async () => {+ await getSaveStrategy()({ type: "inherit" });+ });const deleteRequests = await findRequests("DELETE");expect(deleteRequests).toHaveLength(1);@@ -55,8 +59,10 @@ describe("useSaveStrategy", () => {const { getSaveStrategy } = setup(1, "metric");- await getSaveStrategy()({- type: "nocache",+ await act(async () => {+ await getSaveStrategy()({+ type: "nocache",+ });});const putRequests = await findRequests("PUT");diff --git a/frontend/src/metabase/common/components/ActionButton/ActionButton.unit.spec.tsx b/frontend/src/metabase/common/components/ActionButton/ActionButton.unit.spec.tsxindex 171edf6ae1b..f939b74c8b7 100644--- a/frontend/src/metabase/common/components/ActionButton/ActionButton.unit.spec.tsx+++ b/frontend/src/metabase/common/components/ActionButton/ActionButton.unit.spec.tsx@@ -188,7 +188,9 @@ describe("ActionButton", () => {);const button = screen.getByRole("button");- button.click();+ act(() => {+ button.click();+ });unmount();diff --git a/frontend/src/metabase/common/hooks/entity-framework/use-entity-list-query/use-entity-list-query.unit.spec.tsx b/frontend/src/metabase/common/hooks/entity-framework/use-entity-list-query/use-entity-list-query.unit.spec.tsxindex b419a9576f3..ef3b4c5b0de 100644--- a/frontend/src/metabase/common/hooks/entity-framework/use-entity-list-query/use-entity-list-query.unit.spec.tsx+++ b/frontend/src/metabase/common/hooks/entity-framework/use-entity-list-query/use-entity-list-query.unit.spec.tsx@@ -72,10 +72,14 @@ const setup = ({ reload }: { reload?: boolean } = {}) => {};describe("useEntityListQuery", () => {- it("should be initially loading", () => {+ it("should be initially loading", async () => {setup();expect(screen.getByTestId("loading-indicator")).toBeInTheDocument();++ // Let the pending list requests settle so their state updates stay+ // wrapped in act instead of leaking into the next test.+ await waitForLoaderToBeRemoved();});it("should load data only once", async () => {@@ -159,9 +163,9 @@ describe("useEntityListQuery", () => {within(screen.getByTestId("test2")).getByTestId("loading-indicator"),).toBeInTheDocument();- await delay(100); // trigger fetch request to be resolved-- await delay(0); // trigger extra event loop to make sure React state has been updated+ // Wait for the delayed (cached) request to resolve. Using waitFor keeps the+ // resulting state updates wrapped in act, unlike a bare delay.+ await waitForLoaderToBeRemoved();expect(fetchMock.callHistory.calls("path:/api/card")).toHaveLength(1);expect(screen.queryByTestId("loading-indicator")).not.toBeInTheDocument();diff --git a/frontend/src/metabase/dashboard/containers/DashboardApp/DashboardApp.unit.spec.tsx b/frontend/src/metabase/dashboard/containers/DashboardApp/DashboardApp.unit.spec.tsxindex b4bda250a4b..e1bdb7bac21 100644--- a/frontend/src/metabase/dashboard/containers/DashboardApp/DashboardApp.unit.spec.tsx+++ b/frontend/src/metabase/dashboard/containers/DashboardApp/DashboardApp.unit.spec.tsx@@ -162,14 +162,18 @@ describe("DashboardApp", () => {it("does not show custom warning modal when leaving with no changes via SPA navigation", async () => {const { dashboardId, history } = await setup();- history.push("/");- history.push(`/dashboard/${dashboardId}`);+ act(() => {+ history.push("/");+ history.push(`/dashboard/${dashboardId}`);+ });await waitForLoaderToBeRemoved();await userEvent.click(await screen.findByLabelText("Edit dashboard"));- history.goBack();+ act(() => {+ history.goBack();+ });expect(screen.queryByTestId("leave-confirmation"),diff --git a/frontend/src/metabase/data-studio/segments/pages/SegmentDetailPage/tests/common.unit.spec.tsx b/frontend/src/metabase/data-studio/segments/pages/SegmentDetailPage/tests/common.unit.spec.tsxindex 7815351f6f8..fa98de5c8cd 100644--- a/frontend/src/metabase/data-studio/segments/pages/SegmentDetailPage/tests/common.unit.spec.tsx+++ b/frontend/src/metabase/data-studio/segments/pages/SegmentDetailPage/tests/common.unit.spec.tsx@@ -8,7 +8,7 @@ import { TEST_SEGMENT, setup } from "./setup";describe("SegmentDetailPage", () => {it("renders page with segment data, tabs, and actions menu", async () => {- setup();+ await setup();expect(screen.getByDisplayValue("High Value Orders")).toBeInTheDocument();expect(screen.getByLabelText("Give it a description")).toHaveValue(@@ -20,7 +20,7 @@ describe("SegmentDetailPage", () => {});it("does not show Save/Cancel buttons when form is pristine", async () => {- setup();+ await setup();expect(screen.queryByRole("button", { name: "Save" }),@@ -31,7 +31,7 @@ describe("SegmentDetailPage", () => {});it("shows Save/Cancel buttons when description is modified", async () => {- setup();+ await setup();const descriptionInput = screen.getByLabelText("Give it a description");await userEvent.clear(descriptionInput);@@ -42,7 +42,7 @@ describe("SegmentDetailPage", () => {});it("resets form when Cancel is clicked after modifying description", async () => {- setup();+ await setup();const descriptionInput = screen.getByLabelText("Give it a description");await userEvent.clear(descriptionInput);@@ -65,7 +65,7 @@ describe("SegmentDetailPage", () => {fetchMock.put(`path:/api/segment/${TEST_SEGMENT.id}`, updatedSegment);- setup();+ await setup();const descriptionInput = screen.getByLabelText("Give it a description");await userEvent.clear(descriptionInput);@@ -90,7 +90,7 @@ describe("SegmentDetailPage", () => {});it("displays existing filter from segment definition", async () => {- setup();+ await setup();await waitFor(() => {expect(screen.getByText(/Total is greater than/)).toBeInTheDocument();@@ -98,7 +98,7 @@ describe("SegmentDetailPage", () => {});it("opens actions menu with Preview and Remove options when clicking menu button", async () => {- setup();+ await setup();await userEvent.click(screen.getByLabelText("Segment actions"));@@ -107,7 +107,7 @@ describe("SegmentDetailPage", () => {});it("shows confirmation modal when Remove segment is clicked", async () => {- setup();+ await setup();await userEvent.click(screen.getByLabelText("Segment actions"));await userEvent.click(screen.getByText("Remove segment"));@@ -121,14 +121,14 @@ describe("SegmentDetailPage", () => {describe("readonly state for non-admin users", () => {it("has readonly segment name input", async () => {- setup({ isAdmin: false });+ await setup({ isAdmin: false });const nameInput = screen.getByDisplayValue("High Value Orders");expect(nameInput).toBeDisabled();});it("shows description as plain text", async () => {- setup({ isAdmin: false });+ await setup({ isAdmin: false });expect(screen.getByText("Description")).toBeInTheDocument();expect(screen.getByText("Orders with total > 100")).toBeInTheDocument();@@ -138,7 +138,7 @@ describe("SegmentDetailPage", () => {});it("hides description section when there is no description", async () => {- setup({+ await setup({isAdmin: false,segment: createMockSegment({ ...TEST_SEGMENT, description: "" }),});@@ -147,7 +147,7 @@ describe("SegmentDetailPage", () => {});it("does not show Remove segment option in actions menu", async () => {- setup({ isAdmin: false });+ await setup({ isAdmin: false });await userEvent.click(screen.getByLabelText("Segment actions"));@@ -156,7 +156,7 @@ describe("SegmentDetailPage", () => {});it("does not show Save/Cancel buttons", async () => {- setup({ isAdmin: false });+ await setup({ isAdmin: false });expect(screen.queryByRole("button", { name: "Save" }),diff --git a/frontend/src/metabase/metadata/components/NameDescriptionInput/NameDescriptionInput.unit.spec.tsx b/frontend/src/metabase/metadata/components/NameDescriptionInput/NameDescriptionInput.unit.spec.tsxindex d09b686b8c9..614f94595ba 100644--- a/frontend/src/metabase/metadata/components/NameDescriptionInput/NameDescriptionInput.unit.spec.tsx+++ b/frontend/src/metabase/metadata/components/NameDescriptionInput/NameDescriptionInput.unit.spec.tsx@@ -1,6 +1,6 @@import userEvent from "@testing-library/user-event";-import { render, screen } from "__support__/ui";+import { act, render, screen } from "__support__/ui";import { NameDescriptionInput } from "./NameDescriptionInput";@@ -43,7 +43,9 @@ describe("NameDescriptionInput", () => {const nameInput = screen.getByPlaceholderText("Enter name");await userEvent.type(nameInput, "{backspace}".repeat(3));- nameInput.blur();+ act(() => {+ nameInput.blur();+ });expect(onNameChange).toHaveBeenCalledTimes(0);});@@ -53,7 +55,9 @@ describe("NameDescriptionInput", () => {const descriptionInput = screen.getByPlaceholderText("Enter description");await userEvent.type(descriptionInput, "{backspace}".repeat(3));- descriptionInput.blur();+ act(() => {+ descriptionInput.blur();+ });expect(onDescriptionChange.mock.calls).toEqual([[""]]);expect(descriptionInput).toHaveValue("");@@ -64,7 +68,9 @@ describe("NameDescriptionInput", () => {const nameInput = screen.getByPlaceholderText("Enter name");await userEvent.type(nameInput, "{backspace}z ");- nameInput.blur();+ act(() => {+ nameInput.blur();+ });expect(onNameChange).toHaveBeenCalledTimes(0);});@@ -74,7 +80,9 @@ describe("NameDescriptionInput", () => {const nameInput = screen.getByPlaceholderText("Enter description");await userEvent.type(nameInput, "{backspace}z ");- nameInput.blur();+ act(() => {+ nameInput.blur();+ });expect(onNameChange).toHaveBeenCalledTimes(0);});diff --git a/frontend/src/metabase/nav/containers/Navbar.unit.spec.tsx b/frontend/src/metabase/nav/containers/Navbar.unit.spec.tsxindex 59bcc4d3846..f42031df96d 100644--- a/frontend/src/metabase/nav/containers/Navbar.unit.spec.tsx+++ b/frontend/src/metabase/nav/containers/Navbar.unit.spec.tsx@@ -11,6 +11,7 @@ import {setupSettingEndpoint,} from "__support__/server-mocks";import {+ act,renderWithProviders,screen,waitForLoaderToBeRemoved,@@ -153,12 +154,15 @@ describe("nav > containers > Navbar > Core App", () => {it("should not close navbar when preserveNavbarState is set", async () => {const store = await setup({ isOpen: true });await expectNavbarOpen();- store.dispatch({- type: "@@router/LOCATION_CHANGE",- payload: {- pathname: "/question/1",- state: { preserveNavbarState: true },- },+ // act(...) flushes the connected Navbar re-render caused by the dispatch+ act(() => {+ store.dispatch({+ type: "@@router/LOCATION_CHANGE",+ payload: {+ pathname: "/question/1",+ state: { preserveNavbarState: true },+ },+ });});await expectNavbarOpen();});@@ -174,11 +178,16 @@ describe("nav > containers > Navbar > Core App", () => {await expectNavbarClosed();dispatchLocationChange({ store, pathname: "/collection/4" });await expectNavbarClosed();- store.dispatch({ type: OPEN_NAVBAR });+ // act(...) flushes the connected Navbar re-render caused by the dispatch+ act(() => {+ store.dispatch({ type: OPEN_NAVBAR });+ });await expectNavbarOpen();dispatchLocationChange({ store, pathname: "/collection/5" });await expectNavbarOpen();- store.dispatch({ type: CLOSE_NAVBAR });+ act(() => {+ store.dispatch({ type: CLOSE_NAVBAR });+ });dispatchLocationChange({ store, pathname: "/collection/6" });await expectNavbarClosed();});@@ -281,11 +290,16 @@ function dispatchLocationChange({initialRoute = false,pathname,}: DispatchLocationChangeParams) {- store.dispatch({- type: "@@router/LOCATION_CHANGE",- payload: {- pathname,- action: initialRoute ? "POP" : "PUSH",- },+ // The dispatch synchronously re-renders the connected Navbar; wrap it in+ // act(...) so React's state updates are flushed within the test instead+ // of leaking past it.+ act(() => {+ store.dispatch({+ type: "@@router/LOCATION_CHANGE",+ payload: {+ pathname,+ action: initialRoute ? "POP" : "PUSH",+ },+ });});}diff --git a/frontend/src/metabase/query_builder/components/QueryVisualization.unit.spec.tsx b/frontend/src/metabase/query_builder/components/QueryVisualization.unit.spec.tsxindex fd5bd575e43..c38ab81f2cc 100644--- a/frontend/src/metabase/query_builder/components/QueryVisualization.unit.spec.tsx+++ b/frontend/src/metabase/query_builder/components/QueryVisualization.unit.spec.tsx@@ -1,4 +1,4 @@-import { renderWithProviders, screen } from "__support__/ui";+import { act, renderWithProviders, screen } from "__support__/ui";import { PLUGIN_SELECTORS } from "metabase/plugins";import { VisualizationRunningState } from "metabase/querying/components/QueryVisualization";@@ -23,7 +23,9 @@ describe("VisualizationRunningState", () => {setup();expect(await screen.findByText("Doing science...")).toBeInTheDocument();- jest.advanceTimersByTime(5000);+ act(() => {+ jest.advanceTimersByTime(5000);+ });expect(await screen.findByText("Waiting for results..."),).toBeInTheDocument();@@ -36,7 +38,9 @@ describe("VisualizationRunningState", () => {setup({ customMessage });expect(await screen.findByText("Custom message...")).toBeInTheDocument();- jest.advanceTimersByTime(5000);+ act(() => {+ jest.advanceTimersByTime(5000);+ });expect(await screen.findByText("Custom message (slow)..."),).toBeInTheDocument();diff --git a/frontend/src/metabase/query_builder/components/SavedQuestionHeaderButton/SavedQuestionHeaderButton.unit.spec.js b/frontend/src/metabase/query_builder/components/SavedQuestionHeaderButton/SavedQuestionHeaderButton.unit.spec.jsindex ff1d068d042..382db3c8282 100644--- a/frontend/src/metabase/query_builder/components/SavedQuestionHeaderButton/SavedQuestionHeaderButton.unit.spec.js+++ b/frontend/src/metabase/query_builder/components/SavedQuestionHeaderButton/SavedQuestionHeaderButton.unit.spec.js@@ -3,7 +3,7 @@ import userEvent from "@testing-library/user-event";import { setupEnterpriseOnlyPlugin } from "__support__/enterprise";import { createMockMetadata } from "__support__/metadata";import { mockSettings } from "__support__/settings";-import { getIcon, renderWithProviders, screen } from "__support__/ui";+import { act, getIcon, renderWithProviders, screen } from "__support__/ui";import { createMockState } from "metabase/redux/store/mocks";import Question from "metabase-lib/v1/Question";import {@@ -62,7 +62,9 @@ describe("SavedQuestionHeaderButton", () => {const titleInput = screen.getByTestId("saved-question-header-title");await userEvent.type(titleInput, "1");- titleInput.blur();+ act(() => {+ titleInput.blur();+ });expect(onSave).toHaveBeenCalled();});@@ -73,7 +75,9 @@ describe("SavedQuestionHeaderButton", () => {const titleInput = screen.getByTestId("saved-question-header-title");await userEvent.clear(titleInput);await userEvent.paste("A".repeat(300));- titleInput.blur();+ act(() => {+ titleInput.blur();+ });expect(onSave).toHaveBeenCalledWith("A".repeat(254));});diff --git a/frontend/src/metabase/querying/editor/hooks/use-query-results/use-query-results.unit.spec.ts b/frontend/src/metabase/querying/editor/hooks/use-query-results/use-query-results.unit.spec.tsindex 3c03feed146..0bc186048f5 100644--- a/frontend/src/metabase/querying/editor/hooks/use-query-results/use-query-results.unit.spec.ts+++ b/frontend/src/metabase/querying/editor/hooks/use-query-results/use-query-results.unit.spec.ts@@ -1,5 +1,5 @@import { setupCardDataset } from "__support__/server-mocks";-import { renderHookWithProviders, waitFor } from "__support__/ui";+import { act, renderHookWithProviders, waitFor } from "__support__/ui";import Question from "metabase-lib/v1/Question";import type { Dataset } from "metabase-types/api";import { createMockDataset } from "metabase-types/api/mocks";@@ -62,7 +62,9 @@ describe("useQueryResults", () => {onChangeUiState,});- await result.current.runQuery();+ await act(async () => {+ await result.current.runQuery();+ });await waitFor(() => {expect(onChangeUiState).toHaveBeenCalled();@@ -80,7 +82,9 @@ describe("useQueryResults", () => {mockResponse: { status: 400, dataset: ERROR_DATASET },});- await result.current.runQuery();+ await act(async () => {+ await result.current.runQuery();+ });await waitFor(() => {expect(onChangeUiState).toHaveBeenCalled();diff --git a/frontend/src/metabase/querying/filters/components/FilterPicker/FilterColumnPicker/FilterColumnPicker.unit.spec.tsx b/frontend/src/metabase/querying/filters/components/FilterPicker/FilterColumnPicker/FilterColumnPicker.unit.spec.tsxindex 6f8c1bb1387..545a19597e4 100644--- a/frontend/src/metabase/querying/filters/components/FilterPicker/FilterColumnPicker/FilterColumnPicker.unit.spec.tsx+++ b/frontend/src/metabase/querying/filters/components/FilterPicker/FilterColumnPicker/FilterColumnPicker.unit.spec.tsx@@ -1,5 +1,7 @@+import userEvent from "@testing-library/user-event";+import { setupFieldsValuesEndpoints } from "__support__/server-mocks";-import { fireEvent, renderWithProviders, screen } from "__support__/ui";+import { renderWithProviders, screen } from "__support__/ui";import * as Lib from "metabase-lib";import { DEFAULT_TEST_QUERY, SAMPLE_PROVIDER } from "metabase-lib/test-helpers";import { SAMPLE_DB_FIELD_VALUES } from "metabase-types/api/mocks/presets";@@ -35,18 +37,16 @@ describe("FilterColumnPicker", () => {);});- test("Searching by displayName should works (#39622)", () => {+ it("Searching by displayName should work (#39622)", async () => {const query = Lib.createTestQuery(SAMPLE_PROVIDER, DEFAULT_TEST_QUERY);const stageIndexes = [0];setup({ query, stageIndexes });- screen.getByText("User").click();- fireEvent.change(screen.getByTestId("list-search-field"), {- target: { value: "Birth Date" },- });+ await userEvent.click(screen.getByText("User"));+ await userEvent.type(screen.getByTestId("list-search-field"), "Birth Date");expect(- screen.getByRole("option", { name: "Birth Date" }),+ await screen.findByRole("option", { name: "Birth Date" }),).toBeInTheDocument();});});diff --git a/frontend/src/metabase/querying/filters/components/FilterPicker/FilterValuePicker/FilterValuePicker.unit.spec.tsx b/frontend/src/metabase/querying/filters/components/FilterPicker/FilterValuePicker/FilterValuePicker.unit.spec.tsxindex 5b7a0d07eb8..e2b987f807f 100644--- a/frontend/src/metabase/querying/filters/components/FilterPicker/FilterValuePicker/FilterValuePicker.unit.spec.tsx+++ b/frontend/src/metabase/querying/filters/components/FilterPicker/FilterValuePicker/FilterValuePicker.unit.spec.tsx@@ -7,6 +7,7 @@ import {setupRemappedFieldValueEndpoint,} from "__support__/server-mocks";import {+ act,createMockClipboardData,renderWithProviders,screen,@@ -773,7 +774,11 @@ describe("StringFilterValuePicker", () => {const input = screen.getByRole("combobox", { name: "Filter value" });await userEvent.type(input, "[email protected]");- input.blur();+ // blurring commits the typed value; wrap it so the resulting state+ // updates in MultiAutocomplete are flushed inside act()+ act(() => {+ input.blur();+ });expect(onChange).toHaveBeenLastCalledWith(["[email protected]"]);});diff --git a/frontend/src/metabase/querying/notebook/components/DataStep/tests/common.unit.spec.tsx b/frontend/src/metabase/querying/notebook/components/DataStep/tests/common.unit.spec.tsxindex fc35c7c1509..0614141dbf1 100644--- a/frontend/src/metabase/querying/notebook/components/DataStep/tests/common.unit.spec.tsx+++ b/frontend/src/metabase/querying/notebook/components/DataStep/tests/common.unit.spec.tsx@@ -89,9 +89,18 @@ describe("DataStep", () => {beforeAll(() => {HTMLElement.prototype.scrollBy = jest.fn();// needed for @tanstack/react-virtual, see https://github.com/TanStack/virtual/issues/29#issuecomment-657519522- HTMLElement.prototype.getBoundingClientRect = jest- .fn()- .mockReturnValue({ height: 1, width: 1 });+ // position fields are zeroed so floating-ui (Mantine popovers) does not+ // compute a `NaN` offset from the otherwise-undefined `top`/`left`.+ HTMLElement.prototype.getBoundingClientRect = jest.fn().mockReturnValue({+ height: 1,+ width: 1,+ top: 0,+ left: 0,+ right: 0,+ bottom: 0,+ x: 0,+ y: 0,+ });});afterAll(() => {diff --git a/frontend/src/metabase/querying/notebook/components/DataStep/tests/enterprise.unit.spec.tsx b/frontend/src/metabase/querying/notebook/components/DataStep/tests/enterprise.unit.spec.tsxindex 433e9aafeab..b20ae70c1eb 100644--- a/frontend/src/metabase/querying/notebook/components/DataStep/tests/enterprise.unit.spec.tsx+++ b/frontend/src/metabase/querying/notebook/components/DataStep/tests/enterprise.unit.spec.tsx@@ -19,9 +19,18 @@ describe("DataStep", () => {beforeAll(() => {HTMLElement.prototype.scrollBy = jest.fn();// needed for @tanstack/react-virtual, see https://github.com/TanStack/virtual/issues/29#issuecomment-657519522- HTMLElement.prototype.getBoundingClientRect = jest- .fn()- .mockReturnValue({ height: 1, width: 1 });+ // position fields are zeroed so floating-ui (Mantine popovers) does not+ // compute a `NaN` offset from the otherwise-undefined `top`/`left`.+ HTMLElement.prototype.getBoundingClientRect = jest.fn().mockReturnValue({+ height: 1,+ width: 1,+ top: 0,+ left: 0,+ right: 0,+ bottom: 0,+ x: 0,+ y: 0,+ });});afterAll(() => {diff --git a/frontend/src/metabase/timelines/questions/components/TimelineList/TimelineList.unit.spec.tsx b/frontend/src/metabase/timelines/questions/components/TimelineList/TimelineList.unit.spec.tsxindex 293b9ee80c2..4eb9e929eed 100644--- a/frontend/src/metabase/timelines/questions/components/TimelineList/TimelineList.unit.spec.tsx+++ b/frontend/src/metabase/timelines/questions/components/TimelineList/TimelineList.unit.spec.tsx@@ -8,8 +8,8 @@ describe("TimelineList", () => {it("should render a list of timelines", () => {const props = getProps({timelines: [- createMockTimeline({ name: "Releases" }),- createMockTimeline({ name: "Holidays" }),+ createMockTimeline({ id: 1, name: "Releases" }),+ createMockTimeline({ id: 2, name: "Holidays" }),],});diff --git a/frontend/src/metabase/transforms/pages/TransformSettingsPage/TransformSettingsSection/TargetSection.unit.spec.tsx b/frontend/src/metabase/transforms/pages/TransformSettingsPage/TransformSettingsSection/TargetSection.unit.spec.tsxindex 7be2f9bbe80..46cabce6c83 100644--- a/frontend/src/metabase/transforms/pages/TransformSettingsPage/TransformSettingsSection/TargetSection.unit.spec.tsx+++ b/frontend/src/metabase/transforms/pages/TransformSettingsPage/TransformSettingsSection/TargetSection.unit.spec.tsx@@ -101,23 +101,23 @@ function setup({}describe("TransformSettingsSection", () => {- it("should disable the change target button when the transform is running", () => {+ it("should disable the change target button when the transform is running", async () => {setup({transform: createMockTransform({last_run: createMockTransformRun({ status: "started" }),}),});- const button = screen.getByRole("button", { name: "Change target" });+ const button = await screen.findByRole("button", { name: "Change target" });expect(button).toBeDisabled();});- it("should not disable the change target button when the transform is not running", () => {+ it("should not disable the change target button when the transform is not running", async () => {setup({transform: createMockTransform({last_run: createMockTransformRun({ status: "failed" }),}),});- const button = screen.getByRole("button", { name: "Change target" });+ const button = await screen.findByRole("button", { name: "Change target" });expect(button).toBeEnabled();});@@ -126,15 +126,18 @@ describe("TransformSettingsSection", () => {setup({ remoteSyncType: "read-only" });});- it("does not show the change target button", () => {+ it("does not show the change target button", async () => {+ await screen.findByRole("switch", {+ name: /Only process new and changed data/,+ });expect(screen.queryByRole("button", { name: "Change target" }),).not.toBeInTheDocument();});- it("makes Incremental transformation switch disabled", () => {+ it("makes Incremental transformation switch disabled", async () => {expect(- screen.getByRole("switch", {+ await screen.findByRole("switch", {name: /Only process new and changed data/,}),).toBeDisabled();@@ -143,17 +146,17 @@ describe("TransformSettingsSection", () => {});describe("OwnerSection", () => {- it("should render the ownership section with title and description", () => {+ it("should render the ownership section with title and description", async () => {setup({transform: createMockTransform(),});- expect(screen.getByText("Ownership")).toBeInTheDocument();+ expect(await screen.findByText("Ownership")).toBeInTheDocument();expect(screen.getByText("Specify who is responsible for this transform."),).toBeInTheDocument();});- it("should render the owner label", () => {+ it("should render the owner label", async () => {setup({transform: createMockTransform({owner_user_id: 1,@@ -164,17 +167,17 @@ describe("OwnerSection", () => {}),}),});- expect(screen.getByText("Owner")).toBeInTheDocument();+ expect(await screen.findByText("Owner")).toBeInTheDocument();});- it("should display external email when owner_email is set", () => {+ it("should display external email when owner_email is set", async () => {setup({transform: createMockTransform({owner_email: "[email protected]",owner: createMockTransformOwner({ email: "[email protected]" }),}),});- expect(screen.getByText("Ownership")).toBeInTheDocument();+ expect(await screen.findByText("Ownership")).toBeInTheDocument();});});diff --git a/frontend/src/metabase/ui/components/inputs/TextInputBlurChange/TextInputBlurChange.unit.spec.tsx b/frontend/src/metabase/ui/components/inputs/TextInputBlurChange/TextInputBlurChange.unit.spec.tsxindex b4af0d7f190..be5bcf19a81 100644--- a/frontend/src/metabase/ui/components/inputs/TextInputBlurChange/TextInputBlurChange.unit.spec.tsx+++ b/frontend/src/metabase/ui/components/inputs/TextInputBlurChange/TextInputBlurChange.unit.spec.tsx@@ -38,7 +38,7 @@ describe("TextInputBlurChange", () => {expect(onBlurChange).toHaveBeenCalledTimes(0);await userEvent.type(inputEl, "test");- inputEl.blur();+ await userEvent.tab();expect(onBlurChange).toHaveBeenCalledTimes(1);expect(onBlurChange.mock.results[0].value).toBe("test");diff --git a/frontend/src/metabase/ui/components/inputs/TextareaBlurChange/TextareaBlurChange.unit.spec.tsx b/frontend/src/metabase/ui/components/inputs/TextareaBlurChange/TextareaBlurChange.unit.spec.tsxindex f8d1f4a17d3..b520bd5675e 100644--- a/frontend/src/metabase/ui/components/inputs/TextareaBlurChange/TextareaBlurChange.unit.spec.tsx+++ b/frontend/src/metabase/ui/components/inputs/TextareaBlurChange/TextareaBlurChange.unit.spec.tsx@@ -1,6 +1,6 @@import userEvent from "@testing-library/user-event";-import { cleanup, render, screen } from "__support__/ui";+import { act, cleanup, render, screen } from "__support__/ui";import type { TextareaBlurChangeProps } from "./TextareaBlurChange";import { TextareaBlurChange } from "./TextareaBlurChange";@@ -38,7 +38,11 @@ describe("TextareaBlurChange", () => {expect(onBlurChange).toHaveBeenCalledTimes(0);await userEvent.type(inputEl, "test");- inputEl.blur();+ // `blur()` synchronously updates the component's internal value, so it+ // must be wrapped in `act` to keep the state update flushed.+ act(() => {+ inputEl.blur();+ });expect(onBlurChange).toHaveBeenCalledTimes(1);expect(onBlurChange.mock.results[0].value).toBe("test");