Elffuss BraidHub

kikocis/continue public

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