import { cleanup, render, screen } from "@testing-library/react"; import type { ReactNode } from "react"; import { afterEach, beforeEach, describe, expect, it, vi } from "vitest"; let pathname = "/settings/integrations/github"; const COPY_CONFIG_TEST_ID = "mock-copy-config"; const state = { workspaces: { activeId: "ws-1", items: [ { id: "ws-1", name: "Default" }, { id: "ws-2", name: "Archive" }, ], }, setActiveWorkspace: vi.fn(), }; vi.mock("@/lib/routing/client-router", () => ({ usePathname: () => pathname, useRouter: () => ({ replace: vi.fn() }), useSearchParams: () => new URLSearchParams(), })); vi.mock("@/components/state-provider", () => ({ useAppStore: (selector: (s: typeof state) => unknown) => selector(state), })); vi.mock("@/components/page-topbar", () => ({ PageTopbar: ({ actions }: { actions?: ReactNode }) => (
{actions}
), })); vi.mock("@kandev/ui/tooltip", () => ({ TooltipProvider: ({ children }: { children: ReactNode }) => <>{children}, })); vi.mock("@/components/integrations/integration-copy-config-menu", () => ({ IntegrationCopyConfigMenu: ({ sourceWorkspaceId }: { sourceWorkspaceId: string }) => (
), })); import { SettingsLayoutClient } from "./settings-layout-client"; describe("SettingsLayoutClient integrations actions", () => { beforeEach(() => { pathname = "/settings/integrations/github"; state.workspaces.activeId = "ws-1"; state.setActiveWorkspace.mockClear(); }); afterEach(() => cleanup()); it("keeps copy config available without rendering the workspace switcher", () => { render(
Settings page
, ); expect(screen.queryByTestId("integration-workspace-switcher")).toBeNull(); expect(screen.getByTestId(COPY_CONFIG_TEST_ID).dataset.sourceWorkspaceId).toBe("ws-1"); }); it("shows copy config on workspace-scoped integration pages", () => { pathname = "/settings/workspace/ws-1/integrations/github"; render(
Settings page
, ); expect(screen.getByTestId(COPY_CONFIG_TEST_ID).dataset.sourceWorkspaceId).toBe("ws-1"); }); it("uses the workspace from scoped integration routes before store hydration catches up", () => { pathname = "/settings/workspace/ws-2/integrations/github"; state.workspaces.activeId = "ws-1"; render(
Settings page
, ); expect(screen.getByTestId(COPY_CONFIG_TEST_ID).dataset.sourceWorkspaceId).toBe("ws-2"); }); it("falls back to the active workspace when a scoped route has invalid encoding", () => { pathname = "/settings/workspace/%E0%A4%A/integrations/github"; state.workspaces.activeId = "ws-1"; render(
Settings page
, ); expect(screen.getByTestId(COPY_CONFIG_TEST_ID).dataset.sourceWorkspaceId).toBe("ws-1"); }); });