Skip to content

Commit bdbf274

Browse files
committed
Add e2e tests for pdf downloading and locale loading
1 parent b6b40e9 commit bdbf274

File tree

4 files changed

+118
-7
lines changed

4 files changed

+118
-7
lines changed

client/package-lock.json

Lines changed: 31 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

client/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@
1313
"dependencies": {
1414
"@metabase/embedding-sdk-react": "^0.54.11",
1515
"react": "^18.3.1",
16-
"react-dom": "^18.3.1"
16+
"react-dom": "^18.3.1",
17+
"wouter": "^3.7.0"
1718
},
1819
"devDependencies": {
1920
"@eslint/js": "^9.13.0",

client/src/App.jsx

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,19 @@ import {
44
MetabaseProvider,
55
InteractiveQuestion,
66
defineMetabaseAuthConfig,
7-
defineMetabaseTheme,
7+
defineMetabaseTheme, InteractiveDashboard,
88
} from "@metabase/embedding-sdk-react";
9+
import { useMemo } from "react";
10+
import { Redirect, Route, Switch, useSearchParams } from "wouter"
911

1012
// Configuration
1113
const config = defineMetabaseAuthConfig({
1214
metabaseInstanceUrl: import.meta.env.VITE_METABASE_INSTANCE_URL,
1315
authProviderUri: import.meta.env.VITE_AUTH_PROVIDER_URI,
1416
});
1517

16-
const questionId = 24;
18+
const defaultQuestionId = 24;
19+
const defaultDashboardId = 1;
1720

1821
const theme = defineMetabaseTheme({
1922
// Specify a font to use from the set of fonts supported by Metabase.
@@ -63,10 +66,22 @@ const theme = defineMetabaseTheme({
6366
});
6467

6568
function App() {
69+
const [searchParams] = useSearchParams()
70+
71+
const { locale, questionId, dashboardId } = useMemo(() => ({
72+
locale: searchParams.get('locale') ?? null,
73+
questionId: parseInt(searchParams.get('questionId') || defaultQuestionId),
74+
dashboardId: parseInt(searchParams.get('dashboardId') || defaultDashboardId),
75+
}), [searchParams])
76+
6677
return (
6778
<div className="App" style={{ width: "1200px", height: "800px" }}>
68-
<MetabaseProvider authConfig={config} theme={theme}>
69-
<InteractiveQuestion questionId={questionId} />
79+
<MetabaseProvider authConfig={config} theme={theme} locale={locale}>
80+
<Switch>
81+
<Route path="/" component={() => <Redirect to="/interactive-question" />} />
82+
<Route path="/interactive-question" component={() => <InteractiveQuestion questionId={questionId} />} />
83+
<Route path="/interactive-dashboard" component={() => <InteractiveDashboard dashboardId={dashboardId} withDownloads />} />
84+
</Switch>
7085
</MetabaseProvider>
7186
</div>
7287
);

e2e/test/compatibility.cy.spec.js

Lines changed: 66 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const TIMEOUT_MS = 20000;
1+
const TIMEOUT_MS = 40000;
22

33
describe("Embedding SDK: metabase-nodejs-react-sdk-embedding-sample compatibility", () => {
44
it("should open an Interactive Question", () => {
@@ -12,4 +12,69 @@ describe("Embedding SDK: metabase-nodejs-react-sdk-embedding-sample compatibilit
1212

1313
expect(cy.findByTestId("visualization-root").should("exist"));
1414
});
15+
16+
it("should download an Interactive Dashboard", () => {
17+
cy.visit({
18+
url: "/interactive-dashboard",
19+
});
20+
21+
expect(cy.findByTestId("embed-frame", {timeout: TIMEOUT_MS}).should("exist"));
22+
cy.findByTestId("embed-frame", {timeout: TIMEOUT_MS}).within(() => {
23+
cy.findByTestId("fixed-width-dashboard-header", {timeout: TIMEOUT_MS}).within(() => {
24+
// Different icons for 54 and 55
25+
cy.get('button svg.Icon-download, button svg.Icon-document').first().click({force: true});
26+
});
27+
28+
cy.readFile('cypress/downloads/E-commerce Insights.pdf', {timeout: TIMEOUT_MS}).should('exist');
29+
});
30+
});
31+
32+
it("should load a metabase locale", () => {
33+
cy.visit({
34+
url: "/interactive-question?locale=es&questionId=1",
35+
});
36+
37+
expect(cy.findByText('Tabla', {timeout: TIMEOUT_MS}).should("exist"));
38+
});
39+
40+
it("should load a moment locale", () => {
41+
const time = new Date('2025-01-01')
42+
cy.clock(time, ['Date'])
43+
44+
cy.visit({
45+
url: "/interactive-question?locale=es&questionId=1",
46+
});
47+
48+
cy.findByText('Filtro', {timeout: TIMEOUT_MS}).click();
49+
cy.get('[data-element-id="mantine-popover"]').within(() => {
50+
cy.findByText('Created At').click();
51+
// Different texts for 54 and 55
52+
cy.findByText(/(Fechas relativas|Rango de fechas relativo)/).click();
53+
})
54+
55+
cy.findByTestId('date-filter-picker').within(() => {
56+
57+
cy.findByText('dic. 2–31, 2024').should('exist');
58+
})
59+
});
60+
61+
it("should load a dayjs locale", () => {
62+
const time = new Date('2025-01-01')
63+
cy.clock(time, ['Date'])
64+
65+
cy.visit({
66+
url: "/interactive-question?locale=es&questionId=1",
67+
});
68+
69+
cy.findByText('Filtro', {timeout: TIMEOUT_MS}).click();
70+
cy.get('[data-element-id="mantine-popover"]').within(() => {
71+
cy.findByText('Created At').click();
72+
// Different texts for 54 and 55
73+
cy.findByText(/(Fechas específicas|Rango de fechas fijo)/).click();
74+
})
75+
76+
cy.findByTestId('date-filter-picker').within(() => {
77+
cy.findByText('enero 2025').should('exist');
78+
})
79+
});
1580
});

0 commit comments

Comments
 (0)