From 7ffdac9257769bce44f99ef2641c1a37ebf809be Mon Sep 17 00:00:00 2001
From: Raphael Krut-Landau <raphael.kl@gmail.com>
Date: Thu, 7 Nov 2024 10:34:52 -0500
Subject: [PATCH] Remove withFeatures from renderWithProviders (#49137)

---
 .../tests/premium.unit.spec.tsx               |  1 +
 .../CollectionInfoSidebar/tests/setup.tsx     | 29 +++++++++++-------
 .../tests/enterprise.unit.spec.tsx            |  2 +-
 .../tests/premium.unit.spec.tsx               |  2 +-
 .../DashboardEntityIdCard/tests/setup.tsx     | 30 +++++++++++++++----
 frontend/test/__support__/ui.tsx              | 27 -----------------
 6 files changed, 47 insertions(+), 44 deletions(-)

diff --git a/frontend/src/metabase/collections/components/CollectionInfoSidebar/tests/premium.unit.spec.tsx b/frontend/src/metabase/collections/components/CollectionInfoSidebar/tests/premium.unit.spec.tsx
index 69d84c55e84..859118d5733 100644
--- a/frontend/src/metabase/collections/components/CollectionInfoSidebar/tests/premium.unit.spec.tsx
+++ b/frontend/src/metabase/collections/components/CollectionInfoSidebar/tests/premium.unit.spec.tsx
@@ -10,6 +10,7 @@ import {
 const setup = ({ collection }: { collection: Collection }) =>
   baseSetup({
     collection,
+    enableEnterprisePlugins: true,
     enableOfficialCollections: true,
     enableSerialization: true,
   });
diff --git a/frontend/src/metabase/collections/components/CollectionInfoSidebar/tests/setup.tsx b/frontend/src/metabase/collections/components/CollectionInfoSidebar/tests/setup.tsx
index 5dc96426689..4695bca9bff 100644
--- a/frontend/src/metabase/collections/components/CollectionInfoSidebar/tests/setup.tsx
+++ b/frontend/src/metabase/collections/components/CollectionInfoSidebar/tests/setup.tsx
@@ -1,6 +1,12 @@
+import { setupEnterprisePlugins } from "__support__/enterprise";
+import { mockSettings } from "__support__/settings";
 import { renderWithProviders } from "__support__/ui";
-import type { Collection, TokenFeature } from "metabase-types/api";
-import { createMockCollection } from "metabase-types/api/mocks";
+import type { Collection } from "metabase-types/api";
+import {
+  createMockCollection,
+  createMockTokenFeatures,
+} from "metabase-types/api/mocks";
+import { createMockState } from "metabase-types/store/mocks";
 
 import { CollectionInfoSidebar } from "../CollectionInfoSidebar";
 
@@ -15,12 +21,16 @@ export const setup = ({
   enableOfficialCollections: boolean;
   enableSerialization?: boolean;
 }) => {
-  const withFeatures: TokenFeature[] = [];
-  if (enableOfficialCollections) {
-    withFeatures.push("official_collections");
-  }
-  if (enableSerialization) {
-    withFeatures.push("serialization");
+  const state = createMockState({
+    settings: mockSettings({
+      "token-features": createMockTokenFeatures({
+        serialization: enableSerialization,
+        official_collections: enableOfficialCollections,
+      }),
+    }),
+  });
+  if (enableEnterprisePlugins) {
+    setupEnterprisePlugins();
   }
   return renderWithProviders(
     <>
@@ -32,8 +42,7 @@ export const setup = ({
       />
     </>,
     {
-      withFeatures,
-      shouldSetupEnterprisePlugins: enableEnterprisePlugins,
+      storeInitialState: state,
     },
   );
 };
diff --git a/frontend/src/metabase/dashboard/components/DashboardInfoSidebar/DashboardEntityIdCard/tests/enterprise.unit.spec.tsx b/frontend/src/metabase/dashboard/components/DashboardInfoSidebar/DashboardEntityIdCard/tests/enterprise.unit.spec.tsx
index b8217a9840a..3e26843f143 100644
--- a/frontend/src/metabase/dashboard/components/DashboardInfoSidebar/DashboardEntityIdCard/tests/enterprise.unit.spec.tsx
+++ b/frontend/src/metabase/dashboard/components/DashboardInfoSidebar/DashboardEntityIdCard/tests/enterprise.unit.spec.tsx
@@ -2,7 +2,7 @@ import { setup } from "./setup";
 
 describe("DashboardEntityIdCard (EE without token)", () => {
   it("should return null", async () => {
-    const { container } = setup({ shouldSetupEnterprisePlugins: true });
+    const { container } = setup({ hasEnterprisePlugins: true });
     expect(container).toBeEmptyDOMElement();
   });
 });
diff --git a/frontend/src/metabase/dashboard/components/DashboardInfoSidebar/DashboardEntityIdCard/tests/premium.unit.spec.tsx b/frontend/src/metabase/dashboard/components/DashboardInfoSidebar/DashboardEntityIdCard/tests/premium.unit.spec.tsx
index 6b88b06e995..a5a22a86eb1 100644
--- a/frontend/src/metabase/dashboard/components/DashboardInfoSidebar/DashboardEntityIdCard/tests/premium.unit.spec.tsx
+++ b/frontend/src/metabase/dashboard/components/DashboardInfoSidebar/DashboardEntityIdCard/tests/premium.unit.spec.tsx
@@ -18,7 +18,7 @@ const setup = ({
 } & RenderWithProvidersOptions = {}) => {
   return baseSetup({
     dashboard,
-    withFeatures: ["serialization"],
+    enableSerialization: true,
     ...renderOptions,
   });
 };
diff --git a/frontend/src/metabase/dashboard/components/DashboardInfoSidebar/DashboardEntityIdCard/tests/setup.tsx b/frontend/src/metabase/dashboard/components/DashboardInfoSidebar/DashboardEntityIdCard/tests/setup.tsx
index 642b1ab6097..d4617106273 100644
--- a/frontend/src/metabase/dashboard/components/DashboardInfoSidebar/DashboardEntityIdCard/tests/setup.tsx
+++ b/frontend/src/metabase/dashboard/components/DashboardInfoSidebar/DashboardEntityIdCard/tests/setup.tsx
@@ -1,20 +1,40 @@
+import { setupEnterprisePlugins } from "__support__/enterprise";
+import { mockSettings } from "__support__/settings";
 import {
   type RenderWithProvidersOptions,
   renderWithProviders,
 } from "__support__/ui";
 import type { Dashboard } from "metabase-types/api";
-import { createMockDashboard } from "metabase-types/api/mocks";
+import {
+  createMockDashboard,
+  createMockTokenFeatures,
+} from "metabase-types/api/mocks";
+import { createMockState } from "metabase-types/store/mocks";
 
 import { DashboardEntityIdCard } from "../DashboardEntityIdCard";
 
 export const setup = ({
   dashboard = createMockDashboard(),
+  hasEnterprisePlugins,
+  enableSerialization = false,
   ...renderOptions
 }: {
   dashboard?: Dashboard;
+  hasEnterprisePlugins?: boolean;
+  enableSerialization?: boolean;
 } & RenderWithProvidersOptions = {}) => {
-  return renderWithProviders(
-    <DashboardEntityIdCard dashboard={dashboard} />,
-    renderOptions,
-  );
+  if (hasEnterprisePlugins) {
+    setupEnterprisePlugins();
+  }
+  const state = createMockState({
+    settings: mockSettings({
+      "token-features": createMockTokenFeatures({
+        serialization: enableSerialization,
+      }),
+    }),
+  });
+  return renderWithProviders(<DashboardEntityIdCard dashboard={dashboard} />, {
+    ...renderOptions,
+    storeInitialState: state,
+  });
 };
diff --git a/frontend/test/__support__/ui.tsx b/frontend/test/__support__/ui.tsx
index 45065cacaca..7cf52e35b2b 100644
--- a/frontend/test/__support__/ui.tsx
+++ b/frontend/test/__support__/ui.tsx
@@ -15,7 +15,6 @@ import { Router, useRouterHistory } from "react-router";
 import { routerMiddleware, routerReducer } from "react-router-redux";
 import _ from "underscore";
 
-import { mockSettings } from "__support__/settings";
 import {
   MetabaseProviderInternal,
   type MetabaseProviderProps,
@@ -29,12 +28,9 @@ import { baseStyle } from "metabase/css/core/base.styled";
 import { mainReducers } from "metabase/reducers-main";
 import { publicReducers } from "metabase/reducers-public";
 import { ThemeProvider } from "metabase/ui";
-import type { TokenFeature } from "metabase-types/api";
-import { createMockTokenFeatures } from "metabase-types/api/mocks";
 import type { State } from "metabase-types/store";
 import { createMockState } from "metabase-types/store/mocks";
 
-import { setupEnterprisePlugins } from "./enterprise";
 import { getStore } from "./entities-store";
 
 type ReducerValue = ReducerObject | Reducer;
@@ -54,11 +50,6 @@ export interface RenderWithProvidersOptions {
   withKBar?: boolean;
   withDND?: boolean;
   withUndos?: boolean;
-  /** Token features to enable.
-   *
-   * Note: To keep tests isolated from another, don't change token features between tests in the same file. */
-  withFeatures?: TokenFeature[];
-  shouldSetupEnterprisePlugins?: boolean;
   customReducers?: ReducerObject;
   sdkProviderProps?: Partial<MetabaseProviderProps> | null;
   theme?: MantineThemeOverride;
@@ -79,30 +70,12 @@ export function renderWithProviders(
     withKBar = false,
     withDND = false,
     withUndos = false,
-    withFeatures,
-    shouldSetupEnterprisePlugins,
     customReducers,
     sdkProviderProps = null,
     theme,
     ...options
   }: RenderWithProvidersOptions = {},
 ) {
-  if (withFeatures?.length) {
-    const featuresObject = Object.fromEntries(
-      withFeatures.map(feature => [feature, true]),
-    );
-    storeInitialState.settings = {
-      ...storeInitialState.settings,
-      ...mockSettings({
-        "token-features": createMockTokenFeatures(featuresObject),
-      }),
-    };
-  }
-
-  if (shouldSetupEnterprisePlugins || withFeatures?.length) {
-    setupEnterprisePlugins();
-  }
-
   let { routing, ...initialState }: Partial<State> =
     createMockState(storeInitialState);
 
-- 
GitLab