Skip to content
Snippets Groups Projects
Unverified Commit d419e9ac authored by Nicolò Pretto's avatar Nicolò Pretto Committed by GitHub
Browse files

add missing tests from meet embedders testing plan (#38772)


* test: adds tests for localStorage flag

* Apply suggestions from code review

Co-authored-by: default avatarMahatthana (Kelvin) Nomsawadi <me@bboykelvin.dev>

---------

Co-authored-by: default avatarMahatthana (Kelvin) Nomsawadi <me@bboykelvin.dev>
parent 521a3cb4
Branches
Tags
No related merge requests found
......@@ -33,6 +33,7 @@ interface SetupOpts {
recentItems?: RecentItem[];
popularItems?: PopularItem[];
isXrayEnabled?: boolean;
hasEmbeddingHomepageFlag?: boolean;
}
const setup = async ({
......@@ -41,6 +42,7 @@ const setup = async ({
recentItems = [],
popularItems = [],
isXrayEnabled = true,
hasEmbeddingHomepageFlag = false,
}: SetupOpts) => {
const state = createMockState({
currentUser: user,
......@@ -49,6 +51,10 @@ const setup = async ({
}),
});
if (hasEmbeddingHomepageFlag) {
localStorage.setItem("showEmbedHomepage", "true");
}
setupDatabasesEndpoints(databases);
setupRecentViewsEndpoints(recentItems);
setupPopularItemsEndpoints(popularItems);
......@@ -63,6 +69,7 @@ describe("HomeContent", () => {
beforeEach(() => {
jest.useFakeTimers({ advanceTimers: true });
jest.setSystemTime(new Date(2020, 0, 10));
localStorage.clear();
});
afterEach(() => {
......@@ -173,4 +180,64 @@ describe("HomeContent", () => {
screen.queryByText(/Here are some explorations/),
).not.toBeInTheDocument();
});
describe("embed-focused homepage", () => {
it("should show it for admins if the localStorage flag is set", async () => {
await setup({
user: createMockUser({ is_superuser: true }),
hasEmbeddingHomepageFlag: true,
});
expect(
screen.getByText("Get started with Embedding Metabase in your app"),
).toBeInTheDocument();
});
it("should not show it for non-admins even if the flag is set", async () => {
await setup({
user: createMockUser({ is_superuser: false }),
hasEmbeddingHomepageFlag: true,
});
expect(
screen.queryByText("Get started with Embedding Metabase in your app"),
).not.toBeInTheDocument();
});
it("should be possible to dismiss it", async () => {
await setup({
user: createMockUser({ is_superuser: true }),
hasEmbeddingHomepageFlag: true,
});
screen.getByRole("button", { name: "close icon" }).click();
expect(
screen.queryByText("Get started with Embedding Metabase in your app"),
).not.toBeInTheDocument();
expect(localStorage.getItem("showEmbedHomepage")).toBeNull();
});
it("should not show it if the user is not admin", async () => {
await setup({
user: createMockUser({ is_superuser: false }),
hasEmbeddingHomepageFlag: true,
});
expect(
screen.queryByText("Get started with Embedding Metabase in your app"),
).not.toBeInTheDocument();
});
it("should not show it if the localStorage flag is not set", async () => {
await setup({
user: createMockUser({ is_superuser: true }),
});
expect(
screen.queryByText("Get started with Embedding Metabase in your app"),
).not.toBeInTheDocument();
});
});
});
......@@ -14,6 +14,9 @@ import { Setup } from "./components/Setup";
import type { SetupStep } from "./types";
async function setup({ step = "welcome" }: { step?: SetupStep } = {}) {
localStorage.clear();
jest.clearAllMocks();
const state = createMockState({
setup: createMockSetupState({
step,
......@@ -24,6 +27,7 @@ async function setup({ step = "welcome" }: { step?: SetupStep } = {}) {
});
fetchMock.post("path:/api/util/password_check", { valid: true });
fetchMock.post("path:/api/setup", {});
renderWithProviders(<Setup />, { storeInitialState: state });
......@@ -88,6 +92,20 @@ describe("setup", () => {
expectSectionToHaveLabel("Add your data", "4");
expectSectionToHaveLabel("Usage data preferences", "5");
});
it("should not set the flag for the embedding homepage", async () => {
await setupForUsageQuestion();
selectUsageReason("self-service-analytics");
clickNextStep();
screen.getByText("I'll add my data later").click();
screen.getByRole("button", { name: "Finish" }).click();
await screen.findByRole("link", { name: "Take me to Metabase" });
expect(localStorage.getItem("showEmbedHomepage")).toBeNull();
});
});
describe("when selecting 'Embedding'", () => {
......@@ -105,6 +123,18 @@ describe("setup", () => {
expectSectionToHaveLabel("Usage data preferences", "4");
});
it("should set the flag for the embed homepage in the local storage", async () => {
await setupForUsageQuestion();
selectUsageReason("embedding");
clickNextStep();
screen.getByRole("button", { name: "Finish" }).click();
await screen.findByRole("link", { name: "Take me to Metabase" });
expect(localStorage.getItem("showEmbedHomepage")).toBe("true");
});
});
describe("when selecting 'A bit of both'", () => {
......@@ -123,6 +153,20 @@ describe("setup", () => {
expectSectionToHaveLabel("Add your data", "4");
expectSectionToHaveLabel("Usage data preferences", "5");
});
it("should set the flag for the embed homepage in the local storage", async () => {
await setupForUsageQuestion();
selectUsageReason("both");
clickNextStep();
screen.getByText("I'll add my data later").click();
screen.getByRole("button", { name: "Finish" }).click();
await screen.findByRole("link", { name: "Take me to Metabase" });
expect(localStorage.getItem("showEmbedHomepage")).toBe("true");
});
});
describe("when selecting 'Not sure yet'", () => {
......@@ -141,6 +185,20 @@ describe("setup", () => {
expectSectionToHaveLabel("Add your data", "4");
expectSectionToHaveLabel("Usage data preferences", "5");
});
it("should not set the flag for the embedding homepage", async () => {
await setupForUsageQuestion();
selectUsageReason("self-service-analytics");
clickNextStep();
screen.getByText("I'll add my data later").click();
screen.getByRole("button", { name: "Finish" }).click();
await screen.findByRole("link", { name: "Take me to Metabase" });
expect(localStorage.getItem("showEmbedHomepage")).toBeNull();
});
});
});
});
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment