Skip to content

Commit

Permalink
add unit tests for #41440 (#41465) (#41495)
Browse files Browse the repository at this point in the history
Co-authored-by: Nicolò Pretto <info@npretto.com>
  • Loading branch information
metabase-bot[bot] and npretto committed Apr 17, 2024
1 parent 649600e commit 8a72ca3
Showing 1 changed file with 33 additions and 2 deletions.
Expand Up @@ -42,12 +42,41 @@ describe("PublicDashboard", () => {
expect(screen.getByTestId("embed-frame-header")).toBeInTheDocument();
expect(screen.queryByText("Tab 1")).not.toBeInTheDocument();
});

it("should select the tab from the url", async () => {
await setup({ queryString: "?tab=2", numberOfTabs: 3 });

const secondTab = screen.getByRole("tab", { name: "Tab 2" });

expect(secondTab).toHaveAttribute("aria-selected", "true");
});

it("should work with ?tab={tabid}-${tab-name}", async () => {
// note: as all slugs this is ignored and we only use the id
await setup({
queryString: "?tab=2-this-is-the-tab-name",
numberOfTabs: 3,
});

const secondTab = screen.getByRole("tab", { name: "Tab 2" });

expect(secondTab).toHaveAttribute("aria-selected", "true");
});

it("should default to the first tab if the one passed on the url doesn't exist", async () => {
await setup({ queryString: "?tab=1111", numberOfTabs: 3 });

const firstTab = screen.getByRole("tab", { name: "Tab 1" });

expect(firstTab).toHaveAttribute("aria-selected", "true");
});
});

async function setup({
hash,
queryString,
numberOfTabs = 1,
}: { hash?: string; numberOfTabs?: number } = {}) {
}: { hash?: string; queryString?: string; numberOfTabs?: number } = {}) {
const dashboard = createMockDashboard({
id: 1,
name: DASHBOARD_TITLE,
Expand All @@ -65,7 +94,9 @@ async function setup({
{
storeInitialState: createMockState(),
withRouter: true,
initialRoute: `embed/dashboard/${MOCK_TOKEN}${hash ? "#" + hash : ""}`,
initialRoute: `embed/dashboard/${MOCK_TOKEN}${
queryString ? `?` + queryString : ""
}${hash ? "#" + hash : ""}`,
},
);

Expand Down

0 comments on commit 8a72ca3

Please sign in to comment.