|
| 1 | +import { fireEvent, render, screen } from "@testing-library/react"; |
| 2 | +import { createStore, Provider } from "jotai"; |
| 3 | +import { beforeEach, describe, expect, it, vi } from "vitest"; |
| 4 | +import { localeAtom } from "../../../../atoms/app-ui"; |
| 5 | +import { wsClientAtom } from "../../../../atoms/connection"; |
| 6 | +import { DraftLauncher } from "./draft-launcher"; |
| 7 | + |
| 8 | +const mockUseProviderLauncher = vi.fn(); |
| 9 | + |
| 10 | +vi.mock("../../actions/use-provider-launcher", () => ({ |
| 11 | + useProviderLauncher: (...args: unknown[]) => mockUseProviderLauncher(...args), |
| 12 | +})); |
| 13 | + |
| 14 | +function createRuntimeState(providerId: "claude" | "codex") { |
| 15 | + return { |
| 16 | + runtime: { |
| 17 | + providerId, |
| 18 | + available: true, |
| 19 | + missingCommands: [], |
| 20 | + missingPrerequisites: [], |
| 21 | + autoInstallSupported: false, |
| 22 | + installReadiness: "ready" as const, |
| 23 | + manualGuideKeys: [], |
| 24 | + docUrls: { |
| 25 | + provider: "", |
| 26 | + prerequisites: {}, |
| 27 | + }, |
| 28 | + }, |
| 29 | + loading: false, |
| 30 | + }; |
| 31 | +} |
| 32 | + |
| 33 | +describe("DraftLauncher", () => { |
| 34 | + beforeEach(() => { |
| 35 | + vi.clearAllMocks(); |
| 36 | + mockUseProviderLauncher.mockReturnValue({ |
| 37 | + states: { |
| 38 | + claude: createRuntimeState("claude"), |
| 39 | + codex: createRuntimeState("codex"), |
| 40 | + }, |
| 41 | + launch: vi.fn(), |
| 42 | + }); |
| 43 | + }); |
| 44 | + |
| 45 | + it("uses shared IconButton compatibility classes for header actions", () => { |
| 46 | + const store = createStore(); |
| 47 | + const onClosePane = vi.fn(); |
| 48 | + const onSplitPane = vi.fn(); |
| 49 | + |
| 50 | + store.set(localeAtom, "en"); |
| 51 | + store.set(wsClientAtom, { |
| 52 | + sendCommand: vi.fn(), |
| 53 | + subscribe: vi.fn(() => () => {}), |
| 54 | + } as never); |
| 55 | + |
| 56 | + render( |
| 57 | + <Provider store={store}> |
| 58 | + <DraftLauncher |
| 59 | + workspaceId="ws-123" |
| 60 | + paneId="pane-1" |
| 61 | + onClosePane={onClosePane} |
| 62 | + onSplitPane={onSplitPane} |
| 63 | + /> |
| 64 | + </Provider> |
| 65 | + ); |
| 66 | + |
| 67 | + const splitHorizontal = screen.getByRole("button", { name: "Split horizontal" }); |
| 68 | + const splitVertical = screen.getByRole("button", { name: "Split vertical" }); |
| 69 | + const close = screen.getByRole("button", { name: "Close" }); |
| 70 | + |
| 71 | + expect(splitHorizontal).toHaveClass("btn", "btn-ghost", "btn-sm", "session-action-btn"); |
| 72 | + expect(splitVertical).toHaveClass("btn", "btn-ghost", "btn-sm", "session-action-btn"); |
| 73 | + expect(close).toHaveClass( |
| 74 | + "btn", |
| 75 | + "btn-ghost", |
| 76 | + "btn-sm", |
| 77 | + "session-action-btn", |
| 78 | + "session-action-btn-close" |
| 79 | + ); |
| 80 | + |
| 81 | + fireEvent.click(splitHorizontal); |
| 82 | + fireEvent.click(splitVertical); |
| 83 | + fireEvent.click(close); |
| 84 | + |
| 85 | + expect(onSplitPane).toHaveBeenNthCalledWith(1, "pane-1", "horizontal"); |
| 86 | + expect(onSplitPane).toHaveBeenNthCalledWith(2, "pane-1", "vertical"); |
| 87 | + expect(onClosePane).toHaveBeenCalledWith("pane-1"); |
| 88 | + }); |
| 89 | +}); |
0 commit comments