| 1 | import { render } from "ink-testing-library"; |
| 2 | import React from "react"; |
| 3 | import { afterEach, beforeEach, describe, expect, it, vi } from "vitest"; |
| 4 | |
| 5 | import { |
| 6 | BottomStatusBar, |
| 7 | BottomStatusBarProps, |
| 8 | } from "../components/BottomStatusBar.js"; |
| 9 | |
| 10 | // Mock the index module functions |
| 11 | vi.mock("../../index.js", () => ({ |
| 12 | shouldShowExitMessage: vi.fn(() => false), |
| 13 | setExitMessageCallback: vi.fn(), |
| 14 | })); |
| 15 | |
| 16 | // Mock git utility functions |
| 17 | vi.mock("../../util/git.js", () => ({ |
| 18 | isGitRepo: vi.fn(() => false), |
| 19 | getGitRemoteUrl: vi.fn(() => null), |
| 20 | getGitBranch: vi.fn(() => null), |
| 21 | })); |
| 22 | |
| 23 | describe("BottomStatusBar Ctrl+C message", () => { |
| 24 | const defaultProps: BottomStatusBarProps = { |
| 25 | currentMode: "normal" as const, |
| 26 | remoteUrl: "github.com/user/repo", |
| 27 | isRemoteMode: false, |
| 28 | services: { model: { model: null } }, |
| 29 | navState: { currentScreen: "chat" }, |
| 30 | navigateTo: vi.fn(), |
| 31 | closeCurrentScreen: vi.fn(), |
| 32 | contextPercentage: undefined, |
| 33 | }; |
| 34 | |
| 35 | beforeEach(async () => { |
| 36 | vi.clearAllMocks(); |
| 37 | // Reset mocks to default state |
| 38 | const indexModule = (await vi.importMock("../../index.js")) as any; |
| 39 | indexModule.shouldShowExitMessage.mockReturnValue(false); |
| 40 | }); |
| 41 | |
| 42 | afterEach(() => { |
| 43 | vi.clearAllMocks(); |
| 44 | }); |
| 45 | |
| 46 | it("shows repo URL when not in exit message mode", async () => { |
| 47 | const indexModule = (await vi.importMock("../../index.js")) as any; |
| 48 | indexModule.shouldShowExitMessage.mockReturnValue(false); |
| 49 | |
| 50 | const { lastFrame } = render(<BottomStatusBar {...defaultProps} />); |
| 51 | |
| 52 | expect(lastFrame()).toContain("github.com/user/repo"); |
| 53 | expect(lastFrame()).not.toContain("ctrl+c to exit"); |
| 54 | }); |
| 55 | |
| 56 | it("shows exit message when shouldShowExitMessage returns true", async () => { |
| 57 | const indexModule = (await vi.importMock("../../index.js")) as any; |
| 58 | indexModule.shouldShowExitMessage.mockReturnValue(true); |
| 59 | |
| 60 | const { lastFrame } = render(<BottomStatusBar {...defaultProps} />); |
| 61 | |
| 62 | expect(lastFrame()).toContain("ctrl+c to exit"); |
| 63 | expect(lastFrame()).not.toContain("github.com/user/repo"); |
| 64 | }); |
| 65 | |
| 66 | it("registers exit message callback on mount", async () => { |
| 67 | const indexModule = (await vi.importMock("../../index.js")) as any; |
| 68 | |
| 69 | render(<BottomStatusBar {...defaultProps} />); |
| 70 | |
| 71 | expect(indexModule.setExitMessageCallback).toHaveBeenCalledWith( |
| 72 | expect.any(Function), |
| 73 | ); |
| 74 | }); |
| 75 | }); |