Skip to content

Commit 237b176

Browse files
committed
Add e2e tests for locale loading
1 parent b6b40e9 commit 237b176

File tree

2 files changed

+63
-4
lines changed

2 files changed

+63
-4
lines changed

client/src/App.jsx

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,15 @@ import {
66
defineMetabaseAuthConfig,
77
defineMetabaseTheme,
88
} from "@metabase/embedding-sdk-react";
9+
import { useMemo } from "react";
910

1011
// Configuration
1112
const config = defineMetabaseAuthConfig({
1213
metabaseInstanceUrl: import.meta.env.VITE_METABASE_INSTANCE_URL,
1314
authProviderUri: import.meta.env.VITE_AUTH_PROVIDER_URI,
1415
});
1516

16-
const questionId = 24;
17+
const defaultQuestionId = 24;
1718

1819
const theme = defineMetabaseTheme({
1920
// Specify a font to use from the set of fonts supported by Metabase.
@@ -63,10 +64,19 @@ const theme = defineMetabaseTheme({
6364
});
6465

6566
function App() {
67+
const { locale, questionId } = useMemo(() => {
68+
const searchParams = new URLSearchParams(window.location.search);
69+
70+
return {
71+
locale: searchParams.get('locale') ?? null,
72+
questionId: parseInt(searchParams.get('questionId') || defaultQuestionId),
73+
};
74+
}, [])
75+
6676
return (
6777
<div className="App" style={{ width: "1200px", height: "800px" }}>
68-
<MetabaseProvider authConfig={config} theme={theme}>
69-
<InteractiveQuestion questionId={questionId} />
78+
<MetabaseProvider authConfig={config} theme={theme} locale={locale}>
79+
<InteractiveQuestion questionId={questionId} withDownloads />
7080
</MetabaseProvider>
7181
</div>
7282
);

e2e/test/compatibility.cy.spec.js

Lines changed: 50 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,53 @@ describe("Embedding SDK: metabase-nodejs-react-sdk-embedding-sample compatibilit
1212

1313
expect(cy.findByTestId("visualization-root").should("exist"));
1414
});
15+
16+
it("should load a metabase locale", () => {
17+
cy.visit({
18+
url: "/?locale=es&questionId=1",
19+
});
20+
21+
expect(cy.findByText('Tabla', {timeout: TIMEOUT_MS}).should("exist"));
22+
});
23+
24+
it("should load a moment locale", () => {
25+
const time = new Date('2025-01-01')
26+
cy.clock(time, ['Date'])
27+
28+
cy.visit({
29+
url: "/?locale=es&questionId=1",
30+
});
31+
32+
cy.findByText('Filtro', {timeout: TIMEOUT_MS}).click();
33+
cy.get('[data-element-id="mantine-popover"]').within(() => {
34+
cy.findByText('Created At').click();
35+
// Different texts for 54 and 55
36+
cy.findByText(/(Fechas relativas|Rango de fechas relativo)/).click();
37+
})
38+
39+
cy.findByTestId('date-filter-picker').within(() => {
40+
41+
cy.findByText('dic. 2–31, 2024').should('exist');
42+
})
43+
});
44+
45+
it("should load a dayjs locale", () => {
46+
const time = new Date('2025-01-01')
47+
cy.clock(time, ['Date'])
48+
49+
cy.visit({
50+
url: "/?locale=es&questionId=1",
51+
});
52+
53+
cy.findByText('Filtro', {timeout: TIMEOUT_MS}).click();
54+
cy.get('[data-element-id="mantine-popover"]').within(() => {
55+
cy.findByText('Created At').click();
56+
// Different texts for 54 and 55
57+
cy.findByText(/(Fechas específicas|Rango de fechas fijo)/).click();
58+
})
59+
60+
cy.findByTestId('date-filter-picker').within(() => {
61+
cy.findByText('enero 2025').should('exist');
62+
})
63+
});
1564
});

0 commit comments

Comments
 (0)