Skip to content
Snippets Groups Projects
Unverified Commit 7ffdac92 authored by Raphael Krut-Landau's avatar Raphael Krut-Landau Committed by GitHub
Browse files

Remove withFeatures from renderWithProviders (#49137)

parent 96f9898d
No related branches found
No related tags found
No related merge requests found
......@@ -10,6 +10,7 @@ import {
const setup = ({ collection }: { collection: Collection }) =>
baseSetup({
collection,
enableEnterprisePlugins: true,
enableOfficialCollections: true,
enableSerialization: true,
});
......
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,
},
);
};
......
......@@ -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();
});
});
......@@ -18,7 +18,7 @@ const setup = ({
} & RenderWithProvidersOptions = {}) => {
return baseSetup({
dashboard,
withFeatures: ["serialization"],
enableSerialization: true,
...renderOptions,
});
};
......
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,
});
};
......@@ -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);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment