The easy-to-use open source Business Intelligence and Embedded Analytics tool that lets everyone work with data :bar_chart:
TypeScript analyticsbibusiness-intelligencebusinessintelligenceclojuredashboarddatadata-analysisdata-visualizationdatabasemetabasemysqlpostgrespostgresqlreportingslacksql-editorvisualization
Replace flaky embed code e2e test with jest tests (#79818)
Phoomparin Mano633781cc4e10
diff --git a/e2e/test/scenarios/embedding/sdk-iframe-embedding-setup/get-code.cy.spec.ts b/e2e/test/scenarios/embedding/sdk-iframe-embedding-setup/get-code.cy.spec.tsindex e85081c9daa..c262abc599b 100644--- a/e2e/test/scenarios/embedding/sdk-iframe-embedding-setup/get-code.cy.spec.ts+++ b/e2e/test/scenarios/embedding/sdk-iframe-embedding-setup/get-code.cy.spec.ts@@ -169,28 +169,6 @@ describe("scenarios > embedding > sdk iframe embed setup > get code step", () =>});});- it("should not include useExistingUserSession when SSO is selected", () => {- enableJwtAuth();-- navigateToGetCodeStep({- experience: "dashboard",- resourceName: DASHBOARD_NAME,- preselectSso: true,- });-- getEmbedSidebar().within(() => {- codeBlock().should("not.contain", "useExistingUserSession");-- cy.findByText(/Copy code/).click();-- H.expectUnstructuredSnowplowEvent({- event: "embed_wizard_code_copied",- event_detail:- "experience=dashboard,snippetType=frontend,authSubType=sso",- });- });- });-it("should set dashboard-id for regular dashboard experience", () => {navigateToGetCodeStep({experience: "dashboard",diff --git a/frontend/src/metabase/embedding/embedding-iframe-sdk-setup/components/tests/SdkIframeEmbedSetup.unit.spec.tsx b/frontend/src/metabase/embedding/embedding-iframe-sdk-setup/components/tests/SdkIframeEmbedSetup.unit.spec.tsxindex ea98addc222..edf5c03406c 100644--- a/frontend/src/metabase/embedding/embedding-iframe-sdk-setup/components/tests/SdkIframeEmbedSetup.unit.spec.tsx+++ b/frontend/src/metabase/embedding/embedding-iframe-sdk-setup/components/tests/SdkIframeEmbedSetup.unit.spec.tsx@@ -165,6 +165,42 @@ describe("Embed flow > custom visualizations", () => {});});+describe("Embed flow > Get Code Snippet", () => {+ beforeEach(() => {+ PLUGIN_EMBEDDING_IFRAME_SDK_SETUP.isEnabled = jest.fn(() => true);+ });++ afterEach(() => {+ PLUGIN_EMBEDDING_IFRAME_SDK_SETUP.isEnabled = () => false;+ });++ it("copies the SSO code snippet with only instanceUrl in the config", async () => {+ jest.mocked(navigator.clipboard.writeText).mockClear();++ setup({+ simpleEmbeddingEnabled: true,+ jwtReady: true,+ initialState: { useExistingUserSession: false },+ });++ await userEvent.click(screen.getByRole("button", { name: "Next" }));+ await userEvent.click(screen.getByRole("button", { name: "Get code" }));+ await userEvent.click(screen.getByRole("button", { name: /Copy code/ }));++ const [copiedSnippet] = jest.mocked(navigator.clipboard.writeText).mock+ .calls[0];++ // defineMetabaseConfig accepts a config object+ const metabaseConfigObjectRegex = /defineMetabaseConfig\((\{.*?\})\);/s;+ const [, config] = copiedSnippet.match(metabaseConfigObjectRegex) ?? [];++ // fields like `useExistingUserSession` should not exist+ expect(JSON.parse(config)).toStrictEqual({+ instanceUrl: window.location.origin,+ });+ });+});+describe("Embed flow > forward and backward navigation", () => {beforeEach(() => {PLUGIN_EMBEDDING_IFRAME_SDK_SETUP.isEnabled = jest.fn(() => true);