Skip to content

The easy-to-use open source Business Intelligence and Embedded Analytics tool that lets everyone work with data :bar_chart:

remove noisy logs from sdk component tests (#70416)

Nicolò Pretto6901847ed20c
diff --git a/e2e/support/component-webpack.config.js b/e2e/support/component-webpack.config.js
index b4d7bfdb8ca..81e74d7e175 100644
--- a/e2e/support/component-webpack.config.js
+++ b/e2e/support/component-webpack.config.js
@@ -1,6 +1,7 @@
const fs = require("fs");
const path = require("path");
+const chalk = require("chalk");
const webpack = require("webpack");
const {
@@ -14,7 +15,7 @@ const { isEmbeddingSdkPackageInstalled, embeddingSdkPath } =
resolveEmbeddingSdkPackage();
console.log(
- `Embedding SDK is ${isEmbeddingSdkPackageInstalled ? "installed" : 'NOT installed, using locally built version from "resources/embedding-sdk"'}`,
+ `Embedding SDK is ${isEmbeddingSdkPackageInstalled ? chalk.green("installed") : `${chalk.red("NOT installed")}, ${chalk.bold("using locally built version")} from "resources/embedding-sdk"'}`}`,
);
console.log(`Embedding SDK path alias is resolved to ${embeddingSdkPath}`);
@@ -122,7 +123,7 @@ function resolveEmbeddingSdkPackage() {
};
}
} catch (err) {
- console.log(`Cannot resolve ${SDK_PACKAGE_NAME} via require.resolve:`, err);
+ console.log(`Cannot resolve ${SDK_PACKAGE_NAME} via require.resolve`);
}
const sdkLocalPackagePath = path.resolve(
diff --git a/e2e/support/helpers/embedding-sdk-component-testing/component-embedding-sdk-helpers.tsx b/e2e/support/helpers/embedding-sdk-component-testing/component-embedding-sdk-helpers.tsx
index 8d23c45595a..cc9bb914c54 100644
--- a/e2e/support/helpers/embedding-sdk-component-testing/component-embedding-sdk-helpers.tsx
+++ b/e2e/support/helpers/embedding-sdk-component-testing/component-embedding-sdk-helpers.tsx
@@ -7,7 +7,6 @@ import React from "react";
import { METABASE_INSTANCE_URL } from "e2e/support/helpers";
import type { DeepPartial } from "metabase/embedding-sdk/types/utils";
-import { ThemeProvider } from "metabase/ui";
export const DEFAULT_SDK_AUTH_PROVIDER_CONFIG = {
metabaseInstanceUrl: METABASE_INSTANCE_URL,
@@ -46,17 +45,15 @@ export function mountSdkContent(
}
const reactNode = (
- <ThemeProvider>
- <MetabaseProvider
- {...sdkProviderProps}
- authConfig={{
- ...DEFAULT_SDK_AUTH_PROVIDER_CONFIG,
- ...sdkProviderProps?.authConfig,
- }}
- >
- {children}
- </MetabaseProvider>
- </ThemeProvider>
+ <MetabaseProvider
+ {...sdkProviderProps}
+ authConfig={{
+ ...DEFAULT_SDK_AUTH_PROVIDER_CONFIG,
+ ...sdkProviderProps?.authConfig,
+ }}
+ >
+ {children}
+ </MetabaseProvider>
);
if (strictMode) {
diff --git a/e2e/test-component/scenarios/embedding-sdk/content-translations-rerender-reproduction.cy.spec.tsx b/e2e/test-component/scenarios/embedding-sdk/content-translations-rerender-reproduction.cy.spec.tsx
index ae9f440d3e8..1bcd309e0d9 100644
--- a/e2e/test-component/scenarios/embedding-sdk/content-translations-rerender-reproduction.cy.spec.tsx
+++ b/e2e/test-component/scenarios/embedding-sdk/content-translations-rerender-reproduction.cy.spec.tsx
@@ -1,3 +1,4 @@
+
import { InteractiveQuestion } from "@metabase/embedding-sdk-react";
import { popover } from "e2e/support/helpers";
@@ -8,7 +9,6 @@ import {
mockAuthProviderAndJwtSignIn,
signInAsAdminAndEnableEmbeddingSdk,
} from "e2e/support/helpers/embedding-sdk-testing";
-import { Flex } from "metabase/ui";
describe("scenarios > embedding-sdk > content-translations-rerender-reproduction", () => {
const setupEditor = () => {
@@ -31,9 +31,9 @@ describe("scenarios > embedding-sdk > content-translations-rerender-reproduction
mockAuthProviderAndJwtSignIn();
mountSdkContent(
- <Flex p="xl">
+ <div style={{ display: "flex", padding: "20px" }}>
<InteractiveQuestion questionId="new" />
- </Flex>,
+ </div>,
{
sdkProviderProps: {
locale: "de",
diff --git a/e2e/test-component/scenarios/embedding-sdk/content-translations.cy.spec.tsx b/e2e/test-component/scenarios/embedding-sdk/content-translations.cy.spec.tsx
index fa94659ae25..51c156355ca 100644
--- a/e2e/test-component/scenarios/embedding-sdk/content-translations.cy.spec.tsx
+++ b/e2e/test-component/scenarios/embedding-sdk/content-translations.cy.spec.tsx
@@ -1,3 +1,4 @@
+
import {
CollectionBrowser,
InteractiveQuestion,
@@ -19,7 +20,6 @@ import {
mockAuthProviderAndJwtSignIn,
signInAsAdminAndEnableEmbeddingSdk,
} from "e2e/support/helpers/embedding-sdk-testing";
-import { Flex } from "metabase/ui";
import type { Card } from "metabase-types/api";
const { ORDERS, ORDERS_ID } = SAMPLE_DATABASE;
@@ -120,9 +120,9 @@ describe("scenarios > embedding-sdk > content-translations", () => {
mockAuthProviderAndJwtSignIn();
mountSdkContent(
- <Flex p="xl">
+ <div style={{ display: "flex", padding: "20px" }}>
<InteractiveQuestion questionId="new" />
- </Flex>,
+ </div>,
{
sdkProviderProps: {
locale: "de",
@@ -677,9 +677,9 @@ describe("scenarios > embedding-sdk > content-translations", () => {
mockAuthProviderAndJwtSignIn();
mountSdkContent(
- <Flex p="xl">
+ <div style={{ display: "flex", padding: "20px" }}>
<InteractiveQuestion questionId="new" />
- </Flex>,
+ </div>,
{
sdkProviderProps: {
locale: "ar",
@@ -842,12 +842,12 @@ describe("scenarios > embedding-sdk > content-translations", () => {
cy.get("@collectionId").then((collectionId) => {
mountSdkContent(
- <Flex p="xl">
+ <div style={{ display: "flex", padding: "20px" }}>
<CollectionBrowser
collectionId={collectionId as unknown as number}
visibleColumns={["type", "name", "description"]}
/>
- </Flex>,
+ </div>,
{
sdkProviderProps: {
locale: "de",
diff --git a/e2e/test-component/scenarios/embedding-sdk/create-question.cy.spec.tsx b/e2e/test-component/scenarios/embedding-sdk/create-question.cy.spec.tsx
index afefb4bee1a..bda39453cdc 100644
--- a/e2e/test-component/scenarios/embedding-sdk/create-question.cy.spec.tsx
+++ b/e2e/test-component/scenarios/embedding-sdk/create-question.cy.spec.tsx
@@ -1,3 +1,4 @@
+
import { InteractiveQuestion } from "@metabase/embedding-sdk-react";
import { SAMPLE_DATABASE } from "e2e/support/cypress_sample_database";
@@ -18,7 +19,6 @@ import { getSdkRoot } from "e2e/support/helpers/e2e-embedding-sdk-helpers";
import { mountSdkContent } from "e2e/support/helpers/embedding-sdk-component-testing/component-embedding-sdk-helpers";
import { signInAsAdminAndEnableEmbeddingSdk } from "e2e/support/helpers/embedding-sdk-testing";
import { mockAuthProviderAndJwtSignIn } from "e2e/support/helpers/embedding-sdk-testing/embedding-sdk-helpers";
-import { Flex } from "metabase/ui";
const { H } = cy;
@@ -33,9 +33,9 @@ describe("scenarios > embedding-sdk > interactive-question > creating a question
cy.intercept("POST", "/api/card").as("createCard");
mountSdkContent(
- <Flex p="xl">
+ <div style={{ display: "flex", padding: "20px" }}>
<InteractiveQuestion questionId="new" />
- </Flex>,
+ </div>,
);
assertSdkNotebookEditorUsable();
@@ -76,9 +76,9 @@ describe("scenarios > embedding-sdk > interactive-question > creating a question
mockAuthProviderAndJwtSignIn();
mountSdkContent(
- <Flex p="xl">
+ <div style={{ display: "flex", padding: "20px" }}>
<InteractiveQuestion questionId="new" />
- </Flex>,
+ </div>,
);
getSdkRoot().within(() => {
@@ -118,9 +118,9 @@ describe("scenarios > embedding-sdk > interactive-question > creating a question
cy.intercept("POST", "/api/card").as("createCard");
mountSdkContent(
- <Flex p="xl">
+ <div style={{ display: "flex", padding: "20px" }}>
<InteractiveQuestion questionId="new" />
- </Flex>,
+ </div>,
);
// Wait until the entity picker modal is visible
@@ -186,9 +186,9 @@ describe("scenarios > embedding-sdk > interactive-question > creating a question
cy.log('1. `entityTypes` = ["table"]');
mountSdkContent(
- <Flex p="xl">
+ <div style={{ display: "flex", padding: "20px" }}>
<InteractiveQuestion questionId="new" entityTypes={["table"]} />
- </Flex>,
+ </div>,
);
// Wait until the entity picker modal is visible
@@ -202,9 +202,9 @@ describe("scenarios > embedding-sdk > interactive-question > creating a question
cy.log('2. `entityTypes` = ["model"]');
mountSdkContent(
- <Flex p="xl">
+ <div style={{ display: "flex", padding: "20px" }}>
<InteractiveQuestion questionId="new" entityTypes={["model"]} />
- </Flex>,
+ </div>,
);
// Wait until the entity picker modal is visible
@@ -218,12 +218,12 @@ describe("scenarios > embedding-sdk > interactive-question > creating a question
cy.log('3. `entityTypes` = ["model", "table]');
mountSdkContent(
- <Flex p="xl">
+ <div style={{ display: "flex", padding: "20px" }}>
<InteractiveQuestion
questionId="new"
entityTypes={["model", "table"]}
/>
- </Flex>,
+ </div>,
);
// Wait until the entity picker modal is visible
@@ -252,12 +252,12 @@ describe("scenarios > embedding-sdk > interactive-question > creating a question
cy.intercept("POST", "/api/card").as("createCard");
mountSdkContent(
- <Flex p="xl">
+ <div style={{ display: "flex", padding: "20px" }}>
<InteractiveQuestion
questionId="new"
targetCollection={targetCollectionId}
/>
- </Flex>,
+ </div>,
);
assertSdkNotebookEditorUsable();
@@ -292,9 +292,9 @@ describe("scenarios > embedding-sdk > interactive-question > creating a question
mockAuthProviderAndJwtSignIn();
mountSdkContent(
- <Flex p="xl">
+ <div style={{ display: "flex", padding: "20px" }}>
<InteractiveQuestion questionId="new" />
- </Flex>,
+ </div>,
);
popover().within(() => {
diff --git a/e2e/test-component/scenarios/embedding-sdk/data-picker.cy.spec.tsx b/e2e/test-component/scenarios/embedding-sdk/data-picker.cy.spec.tsx
index e2ea77a8fdd..23f6bde2957 100644
--- a/e2e/test-component/scenarios/embedding-sdk/data-picker.cy.spec.tsx
+++ b/e2e/test-component/scenarios/embedding-sdk/data-picker.cy.spec.tsx
@@ -1,3 +1,4 @@
+
import { InteractiveQuestion } from "@metabase/embedding-sdk-react";
import { popover } from "e2e/support/helpers";
@@ -5,7 +6,6 @@ import { getSdkRoot } from "e2e/support/helpers/e2e-embedding-sdk-helpers";
import { mountSdkContent } from "e2e/support/helpers/embedding-sdk-component-testing/component-embedding-sdk-helpers";
import { signInAsAdminAndEnableEmbeddingSdk } from "e2e/support/helpers/embedding-sdk-testing";
import { mockAuthProviderAndJwtSignIn } from "e2e/support/helpers/embedding-sdk-testing/embedding-sdk-helpers";
-import { Flex } from "metabase/ui";
describe("scenarios > embedding-sdk > interactive-question > creating a question", () => {
beforeEach(() => {
@@ -19,9 +19,9 @@ describe("scenarios > embedding-sdk > interactive-question > creating a question
cy.intercept("POST", "/api/card").as("createCard");
mountSdkContent(
- <Flex p="xl">
+ <div style={{ display: "flex", padding: "20px" }}>
<InteractiveQuestion questionId="new" />
- </Flex>,
+ </div>,
);
// Wait until the entity picker modal is visible
@@ -61,9 +61,9 @@ describe("scenarios > embedding-sdk > interactive-question > creating a question
cy.intercept("POST", "/api/card").as("createCard");
mountSdkContent(
- <Flex p="xl">
+ <div style={{ display: "flex", padding: "20px" }}>
<InteractiveQuestion questionId="new" />
- </Flex>,
+ </div>,
);
// Wait until the entity picker modal is visible
diff --git a/e2e/test-component/scenarios/embedding-sdk/interactive-dashboard.cy.spec.tsx b/e2e/test-component/scenarios/embedding-sdk/interactive-dashboard.cy.spec.tsx
index 081522df864..c2e58a7da9d 100644
--- a/e2e/test-component/scenarios/embedding-sdk/interactive-dashboard.cy.spec.tsx
+++ b/e2e/test-component/scenarios/embedding-sdk/interactive-dashboard.cy.spec.tsx
@@ -1,4 +1,5 @@
const { H } = cy;
+
import {
InteractiveDashboard,
InteractiveQuestion,
@@ -16,7 +17,6 @@ import { mountSdkContent } from "e2e/support/helpers/embedding-sdk-component-tes
import { signInAsAdminAndEnableEmbeddingSdk } from "e2e/support/helpers/embedding-sdk-testing";
import { mockAuthProviderAndJwtSignIn } from "e2e/support/helpers/embedding-sdk-testing/embedding-sdk-helpers";
import { defer } from "metabase/lib/promise";
-import { Stack } from "metabase/ui";
import type {
ConcreteFieldReference,
DashboardCard,
@@ -86,11 +86,11 @@ describe("scenarios > embedding-sdk > interactive-dashboard", () => {
<InteractiveDashboard
dashboardId={dashboardId}
renderDrillThroughQuestion={() => (
- <Stack>
+ <div style={{ display: "flex", flexDirection: "column" }}>
<InteractiveQuestion.Title />
<InteractiveQuestion.QuestionVisualization />
<div>This is a custom question layout.</div>
- </Stack>
+ </div>
)}
/>,
);
diff --git a/e2e/test-component/scenarios/embedding-sdk/sdk-question-native.cy.spec.tsx b/e2e/test-component/scenarios/embedding-sdk/sdk-question-native.cy.spec.tsx
index e75822f8c69..8c5aa7372de 100644
--- a/e2e/test-component/scenarios/embedding-sdk/sdk-question-native.cy.spec.tsx
+++ b/e2e/test-component/scenarios/embedding-sdk/sdk-question-native.cy.spec.tsx
@@ -1,3 +1,4 @@
+
import { InteractiveQuestion } from "@metabase/embedding-sdk-react";
import { useState } from "react";
@@ -14,7 +15,6 @@ import {
} from "e2e/support/helpers/embedding-sdk-component-testing";
import { signInAsAdminAndEnableEmbeddingSdk } from "e2e/support/helpers/embedding-sdk-testing";
import { mockAuthProviderAndJwtSignIn } from "e2e/support/helpers/embedding-sdk-testing/embedding-sdk-helpers";
-import { Box, Button } from "metabase/ui";
import type { DatasetColumn, TemplateTags } from "metabase-types/api";
import { createMockParameter } from "metabase-types/api/mocks";
@@ -86,13 +86,13 @@ describe("scenarios > embedding-sdk > interactive-question > native", () => {
const [questionId, setQuestionId] = useState<string | number>("new");
return (
- <Box>
+ <div>
<InteractiveQuestion questionId={questionId} />
- <Button onClick={() => setQuestionId(nativeQuestionId)}>
+ <button onClick={() => setQuestionId(nativeQuestionId)}>
use native question
- </Button>
- </Box>
+ </button>
+ </div>
);
};
diff --git a/e2e/test-component/scenarios/embedding-sdk/sdk-question-theming.cy.spec.tsx b/e2e/test-component/scenarios/embedding-sdk/sdk-question-theming.cy.spec.tsx
index 406047aecd1..e8fe2b115cd 100644
--- a/e2e/test-component/scenarios/embedding-sdk/sdk-question-theming.cy.spec.tsx
+++ b/e2e/test-component/scenarios/embedding-sdk/sdk-question-theming.cy.spec.tsx
@@ -1,3 +1,4 @@
+
import {
InteractiveQuestion,
type MetabaseTheme,
@@ -10,7 +11,6 @@ import { getSdkRoot } from "e2e/support/helpers/e2e-embedding-sdk-helpers";
import { mountSdkContent } from "e2e/support/helpers/embedding-sdk-component-testing";
import { signInAsAdminAndEnableEmbeddingSdk } from "e2e/support/helpers/embedding-sdk-testing";
import { mockAuthProviderAndJwtSignIn } from "e2e/support/helpers/embedding-sdk-testing/embedding-sdk-helpers";
-import { Box } from "metabase/ui";
const { ORDERS, ORDERS_ID } = SAMPLE_DATABASE;
@@ -236,9 +236,9 @@ function getColorDifferencePercentage(color1: string, color2: string) {
function setupInteractiveQuestionWithTheme(theme: MetabaseTheme) {
cy.get<number>("@questionId").then((questionId) => {
mountSdkContent(
- <Box bg={theme.colors?.background} h="100vh">
+ <div style={{ background: theme.colors?.background, height: "100vh" }}>
<InteractiveQuestion questionId={questionId} />
- </Box>,
+ </div>,
{ sdkProviderProps: { theme } },
);
});
diff --git a/e2e/test-component/scenarios/embedding-sdk/sdk-question.cy.spec.tsx b/e2e/test-component/scenarios/embedding-sdk/sdk-question.cy.spec.tsx
index ad39d9a157a..b9bbca9ee42 100644
--- a/e2e/test-component/scenarios/embedding-sdk/sdk-question.cy.spec.tsx
+++ b/e2e/test-component/scenarios/embedding-sdk/sdk-question.cy.spec.tsx
@@ -1,4 +1,3 @@
-import { useDisclosure } from "@mantine/hooks";
import {
InteractiveQuestion,
type MetabaseQuestion,
@@ -30,7 +29,6 @@ import {
} from "e2e/support/helpers/embedding-sdk-component-testing";
import { signInAsAdminAndEnableEmbeddingSdk } from "e2e/support/helpers/embedding-sdk-testing";
import { mockAuthProviderAndJwtSignIn } from "e2e/support/helpers/embedding-sdk-testing/embedding-sdk-helpers";
-import { Box, Button, Modal } from "metabase/ui";
const { H } = cy;
const { ORDERS, ORDERS_ID } = SAMPLE_DATABASE;
@@ -253,14 +251,14 @@ describe("scenarios > embedding-sdk > interactive-question", () => {
cy.intercept("POST", "/api/card/*/query").as("cardQuery");
const TestSuiteComponent = ({ questionId }: { questionId: string }) => (
- <Box p="lg">
+ <div style={{ padding: "16px" }}>
<InteractiveQuestion questionId={questionId}>
- <Box>
+ <div>
<InteractiveQuestion.FilterDropdown />
<InteractiveQuestion.QuestionVisualization />
- </Box>
+ </div>
</InteractiveQuestion>
- </Box>
+ </div>
);
cy.get<string>("@questionId").then((questionId) => {
@@ -289,7 +287,9 @@ describe("scenarios > embedding-sdk > interactive-question", () => {
onBeforeSave,
onSave,
}: InteractiveQuestionProps) => {
- const [isSaveModalOpen, { toggle, close }] = useDisclosure(false);
+ const [isSaveModalOpen, setIsSaveModalOpen] = useState(false);
+ const toggle = () => setIsSaveModalOpen((v) => !v);
+ const close = () => setIsSaveModalOpen(false);
const handleSave = (
question: MetabaseQuestion | undefined,
@@ -309,14 +309,14 @@ describe("scenarios > embedding-sdk > interactive-question", () => {
onBeforeSave={onBeforeSave}
onSave={handleSave}
>
- <Box p="lg">
- <Button onClick={toggle}>Save</Button>
- </Box>
+ <div style={{ padding: "16px" }}>
+ <button onClick={toggle}>Save</button>
+ </div>
{isSaveModalOpen && (
- <Modal opened={isSaveModalOpen} onClose={close}>
+ <div role="dialog" data-testid="modal">
<InteractiveQuestion.SaveQuestionForm onCancel={close} />
- </Modal>
+ </div>
)}
{!isSaveModalOpen && <InteractiveQuestion.QuestionVisualization />}
@@ -550,10 +550,10 @@ describe("scenarios > embedding-sdk > interactive-question", () => {
);
return (
- <Box>
+ <div>
<InteractiveQuestion questionId={questionId} />
- <Button onClick={() => setQuestionId("new")}>New Question</Button>
- </Box>
+ <button onClick={() => setQuestionId("new")}>New Question</button>
+ </div>
);
};
diff --git a/eslint.config.mjs b/eslint.config.mjs
index a6276a4b6e3..16e42f27500 100644
--- a/eslint.config.mjs
+++ b/eslint.config.mjs
@@ -461,6 +461,25 @@ const configs = [
"no-console": "error",
},
},
+ {
+ files: ["e2e/test-component/**/*.ts", "e2e/test-component/**/*.tsx"],
+ rules: {
+ "@typescript-eslint/no-restricted-imports": [
+ "warn",
+ {
+ patterns: [
+ {
+ // There might be things that we might benefit from importing, like `defer`, in those cases we can change the regex here to allow them
+ regex: "^metabase/(?!lib/promise$|embedding-sdk/test/).*",
+ allowTypeImports: true,
+ message:
+ "We should avoid importing `metabase/` code in the component tests, we might accidentally include CLJS in the dependencies and that can create issues. Component tests should only use the code it needs to test, which is in the package.",
+ },
+ ],
+ },
+ ],
+ },
+ },
{
files: ["frontend/test/**/*"],
languageOptions: {