Elffuss BraidHub

kikocis/continue public

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