From d46d1a5daab8537ab06b93cfb6b70da0eaaf681f Mon Sep 17 00:00:00 2001 From: chezsmithy Date: Thu, 28 Aug 2025 00:40:51 -0700 Subject: [PATCH 1/2] chore: :white_check_mark: Add ui tests for the new Unified Terminal --- .../UnifiedTerminal/UnifiedTerminal.test.tsx | 330 ++++++++++++++++++ .../UnifiedTerminal/UnifiedTerminal.tsx | 2 +- 2 files changed, 331 insertions(+), 1 deletion(-) create mode 100644 gui/src/components/UnifiedTerminal/UnifiedTerminal.test.tsx diff --git a/gui/src/components/UnifiedTerminal/UnifiedTerminal.test.tsx b/gui/src/components/UnifiedTerminal/UnifiedTerminal.test.tsx new file mode 100644 index 000000000..1fa229ad6 --- /dev/null +++ b/gui/src/components/UnifiedTerminal/UnifiedTerminal.test.tsx @@ -0,0 +1,330 @@ +import { screen, waitFor } from "@testing-library/react"; +import { ToolCallState } from "core"; +import { renderWithProviders } from "../../util/test/render"; +import { UnifiedTerminalCommand } from "./UnifiedTerminal"; + +const MOCK_COMMAND = "npm test"; +const MOCK_OUTPUT = `Running tests... +✓ Test 1 passed +✓ Test 2 passed +✗ Test 3 failed + Error: Expected true but got false + +Test Results: + 2 passed, 1 failed + Total: 3 tests`; + +const LONG_OUTPUT = Array.from({ length: 25 }, (_, i) => `Line ${i + 1}`).join("\n"); +const MOCK_TOOL_CALL_ID = "terminal-call-123"; + +const MOCK_ANSI_OUTPUT = `\u001b[32m✓\u001b[0m Test passed +\u001b[31m✗\u001b[0m Test failed +\u001b[1mBold text\u001b[0m +\u001b[4mUnderlined text\u001b[0m`; + +const MOCK_OUTPUT_WITH_LINKS = `Build successful! +Visit https://example.com for more info +Check www.github.com/user/repo +Error logs at file:///tmp/error.log`; + +// Mock the redux hooks +const mockDispatch = vi.fn(); +const mockSelector = vi.fn(); +vi.mock("../../redux/hooks", () => ({ + useAppDispatch: () => mockDispatch, + useAppSelector: () => mockSelector, +})); + +beforeEach(() => { + vi.clearAllMocks(); +}); + +describe("UnifiedTerminalCommand", () => { + test("renders basic terminal command without output", async () => { + const { user } = await renderWithProviders( + + ); + + // Should show the command + expect(screen.getByText(`$ ${MOCK_COMMAND}`)).toBeInTheDocument(); + + // Should show terminal header + expect(screen.getByText("Terminal")).toBeInTheDocument(); + + // Should show completed status icon (green dot) + const terminalContainer = screen.getByTestId("terminal-container"); + expect(terminalContainer).toBeInTheDocument(); + }); + + test("renders terminal command with output", async () => { + const { container } = await renderWithProviders( + + ); + + // Should show the command and output + expect(screen.getByText(`$ ${MOCK_COMMAND}`)).toBeInTheDocument(); + + // Check that the output content exists in the container + expect(container.textContent).toMatch(/Test 1 passed/); + expect(container.textContent).toMatch(/Test 3 failed/); + }); + + test("shows running state with blinking cursor", async () => { + const mockToolCallState: ToolCallState = { + status: "calling", + }; + + const { user } = await renderWithProviders( + + ); + + // Should show running status + expect(screen.getByText("Running")).toBeInTheDocument(); + + // Should show move to background link + expect(screen.getByText("Move to background")).toBeInTheDocument(); + }); + + test("can expand and collapse terminal", async () => { + const { user, container } = await renderWithProviders( + + ); + + // Should initially be expanded and show output + expect(container.textContent).toMatch(/Test 1 passed/); + + // Find and click the collapse chevron (SVG icon) + const chevron = container.querySelector('svg[class*="cursor-pointer"], .cursor-pointer svg'); + expect(chevron).toBeInTheDocument(); + + if (chevron) { + await user.click(chevron); + + // After collapsing, output should not be visible + await waitFor(() => { + expect(container.textContent).not.toMatch(/Test 1 passed/); + }); + } + }); + + test("shows collapsible output for long content", async () => { + const { user, container } = await renderWithProviders( + + ); + + // Should show the "+X more lines" indicator + expect(screen.getByText(/\+\d+ more lines/)).toBeInTheDocument(); + + // Should initially show only some of the last lines + expect(container.textContent).toMatch(/Line 25/); + + // Click to expand using the "+X more lines" button + const expandButton = screen.getByText(/\+\d+ more lines/); + await user.click(expandButton); + + // Should now show all lines + await waitFor(() => { + expect(container.textContent).toMatch(/Line 1/); + }); + + // Should show collapse option + expect(screen.getByText(/Collapse/)).toBeInTheDocument(); + }); + + test("renders ANSI colors and formatting", async () => { + const { container } = await renderWithProviders( + + ); + + // Should render ANSI content (check the container text since ANSI splits across elements) + expect(container.textContent).toMatch(/Test passed/); + expect(container.textContent).toMatch(/Test failed/); + expect(container.textContent).toMatch(/Bold text/); + expect(container.textContent).toMatch(/Underlined text/); + + // Verify ANSI processing created styled spans + const styledSpans = container.querySelectorAll('span[class*="sc-esYiGF"]'); + expect(styledSpans.length).toBeGreaterThan(0); + }); + + test("handles links in output", async () => { + const { container } = await renderWithProviders( + + ); + + // Should contain the link text in the output + expect(container.textContent).toMatch(/https:\/\/example\.com/); + expect(container.textContent).toMatch(/www\.github\.com/); + + // Note: Link detection might create actual tags or just display the URLs + // The important thing is the URLs are visible in the output + }); + + test("shows copy and run in terminal buttons when not running", async () => { + const { container } = await renderWithProviders( + + ); + + // Look for toolbar elements - they may be hidden by responsive classes but exist in DOM + const toolbarArea = container.querySelector('[class*="gap-2.5"]'); + expect(toolbarArea).toBeInTheDocument(); + + // Should contain SVG icons for copy/run operations + const svgIcons = container.querySelectorAll('svg'); + expect(svgIcons.length).toBeGreaterThan(0); + + // Should show "Run" text (may be hidden on small screens) + expect(container.textContent).toMatch(/Run/); + }); + + test("handles move to background action", async () => { + const mockToolCallState: ToolCallState = { + status: "calling", + }; + + const { user } = await renderWithProviders( + + ); + + // Find and click move to background link + const moveToBackgroundLink = screen.getByText("Move to background"); + await user.click(moveToBackgroundLink); + + // Should dispatch the move to background action + expect(mockDispatch).toHaveBeenCalled(); + }); + + test("shows different status types correctly", async () => { + // Test completed status + const { rerender, container } = await renderWithProviders( + + ); + + expect(container.textContent).toMatch(/Command completed successfully/); + + // Test failed status + rerender( + + ); + + expect(container.textContent).toMatch(/Command failed with exit code 1/); + + // Test background status + rerender( + + ); + + expect(container.textContent).toMatch(/Command moved to background/); + }); + + test("handles empty output gracefully", async () => { + const { container } = await renderWithProviders( + + ); + + // Should show command but no output section + expect(screen.getByText(`$ ${MOCK_COMMAND}`)).toBeInTheDocument(); + + // Should not show any output content + const outputElements = container.querySelectorAll('pre code > div:not(:first-child)'); + expect(outputElements.length).toBe(0); + }); + + test("processes terminal content correctly for line limiting", async () => { + const { container } = await renderWithProviders( + + ); + + // Should show correct number of hidden lines + expect(screen.getByText(/\+15 more lines/)).toBeInTheDocument(); + + // Should show the last lines + expect(container.textContent).toMatch(/Line 25/); + + // Should not initially show the first lines (Line 1-15 should be hidden) + // The component shows last 10 lines (16-25) with a +15 more lines indicator + expect(container.textContent).toMatch(/Line 16/); + }); + + test("clicking on collapsible output toggles expansion", async () => { + const { user, container } = await renderWithProviders( + + ); + + // Click on the "+15 more lines" button to expand + const expandButton = screen.getByText(/\+15 more lines/); + await user.click(expandButton); + + // Should expand and show all content + await waitFor(() => { + expect(container.textContent).toMatch(/Line 1/); + }); + + // Should show collapse option after expansion + expect(screen.getByText(/Collapse/)).toBeInTheDocument(); + }); +}); \ No newline at end of file diff --git a/gui/src/components/UnifiedTerminal/UnifiedTerminal.tsx b/gui/src/components/UnifiedTerminal/UnifiedTerminal.tsx index 33bc71275..ce2650348 100644 --- a/gui/src/components/UnifiedTerminal/UnifiedTerminal.tsx +++ b/gui/src/components/UnifiedTerminal/UnifiedTerminal.tsx @@ -418,7 +418,7 @@ export function UnifiedTerminalCommand({ }, [command, output, hasOutput]); return ( - +
{/* Toolbar */}
Date: Thu, 28 Aug 2025 08:57:02 -0700 Subject: [PATCH 2/2] fix: :art: Prettier and Typescript fixes --- .../UnifiedTerminal/UnifiedTerminal.test.tsx | 135 ++++++++++-------- .../UnifiedTerminal/UnifiedTerminal.tsx | 6 +- 2 files changed, 84 insertions(+), 57 deletions(-) diff --git a/gui/src/components/UnifiedTerminal/UnifiedTerminal.test.tsx b/gui/src/components/UnifiedTerminal/UnifiedTerminal.test.tsx index 1fa229ad6..36e5169ef 100644 --- a/gui/src/components/UnifiedTerminal/UnifiedTerminal.test.tsx +++ b/gui/src/components/UnifiedTerminal/UnifiedTerminal.test.tsx @@ -14,7 +14,9 @@ Test Results: 2 passed, 1 failed Total: 3 tests`; -const LONG_OUTPUT = Array.from({ length: 25 }, (_, i) => `Line ${i + 1}`).join("\n"); +const LONG_OUTPUT = Array.from({ length: 25 }, (_, i) => `Line ${i + 1}`).join( + "\n", +); const MOCK_TOOL_CALL_ID = "terminal-call-123"; const MOCK_ANSI_OUTPUT = `\u001b[32m✓\u001b[0m Test passed @@ -42,18 +44,15 @@ beforeEach(() => { describe("UnifiedTerminalCommand", () => { test("renders basic terminal command without output", async () => { const { user } = await renderWithProviders( - + , ); // Should show the command expect(screen.getByText(`$ ${MOCK_COMMAND}`)).toBeInTheDocument(); - + // Should show terminal header expect(screen.getByText("Terminal")).toBeInTheDocument(); - + // Should show completed status icon (green dot) const terminalContainer = screen.getByTestId("terminal-container"); expect(terminalContainer).toBeInTheDocument(); @@ -61,16 +60,16 @@ describe("UnifiedTerminalCommand", () => { test("renders terminal command with output", async () => { const { container } = await renderWithProviders( - + />, ); // Should show the command and output expect(screen.getByText(`$ ${MOCK_COMMAND}`)).toBeInTheDocument(); - + // Check that the output content exists in the container expect(container.textContent).toMatch(/Test 1 passed/); expect(container.textContent).toMatch(/Test 3 failed/); @@ -79,43 +78,55 @@ describe("UnifiedTerminalCommand", () => { test("shows running state with blinking cursor", async () => { const mockToolCallState: ToolCallState = { status: "calling", + toolCallId: MOCK_TOOL_CALL_ID, + toolCall: { + id: MOCK_TOOL_CALL_ID, + type: "function", + function: { + name: "terminal", + arguments: "{}", + }, + }, + parsedArgs: {}, }; const { user } = await renderWithProviders( - + />, ); // Should show running status expect(screen.getByText("Running")).toBeInTheDocument(); - + // Should show move to background link expect(screen.getByText("Move to background")).toBeInTheDocument(); }); test("can expand and collapse terminal", async () => { const { user, container } = await renderWithProviders( - + />, ); // Should initially be expanded and show output expect(container.textContent).toMatch(/Test 1 passed/); // Find and click the collapse chevron (SVG icon) - const chevron = container.querySelector('svg[class*="cursor-pointer"], .cursor-pointer svg'); + const chevron = container.querySelector( + 'svg[class*="cursor-pointer"], .cursor-pointer svg', + ); expect(chevron).toBeInTheDocument(); - + if (chevron) { await user.click(chevron); - + // After collapsing, output should not be visible await waitFor(() => { expect(container.textContent).not.toMatch(/Test 1 passed/); @@ -125,40 +136,40 @@ describe("UnifiedTerminalCommand", () => { test("shows collapsible output for long content", async () => { const { user, container } = await renderWithProviders( - + />, ); // Should show the "+X more lines" indicator expect(screen.getByText(/\+\d+ more lines/)).toBeInTheDocument(); - + // Should initially show only some of the last lines expect(container.textContent).toMatch(/Line 25/); - + // Click to expand using the "+X more lines" button const expandButton = screen.getByText(/\+\d+ more lines/); await user.click(expandButton); - + // Should now show all lines await waitFor(() => { expect(container.textContent).toMatch(/Line 1/); }); - + // Should show collapse option expect(screen.getByText(/Collapse/)).toBeInTheDocument(); }); test("renders ANSI colors and formatting", async () => { const { container } = await renderWithProviders( - + />, ); // Should render ANSI content (check the container text since ANSI splits across elements) @@ -166,7 +177,7 @@ describe("UnifiedTerminalCommand", () => { expect(container.textContent).toMatch(/Test failed/); expect(container.textContent).toMatch(/Bold text/); expect(container.textContent).toMatch(/Underlined text/); - + // Verify ANSI processing created styled spans const styledSpans = container.querySelectorAll('span[class*="sc-esYiGF"]'); expect(styledSpans.length).toBeGreaterThan(0); @@ -174,38 +185,38 @@ describe("UnifiedTerminalCommand", () => { test("handles links in output", async () => { const { container } = await renderWithProviders( - + />, ); // Should contain the link text in the output expect(container.textContent).toMatch(/https:\/\/example\.com/); expect(container.textContent).toMatch(/www\.github\.com/); - + // Note: Link detection might create actual tags or just display the URLs // The important thing is the URLs are visible in the output }); test("shows copy and run in terminal buttons when not running", async () => { const { container } = await renderWithProviders( - + />, ); // Look for toolbar elements - they may be hidden by responsive classes but exist in DOM const toolbarArea = container.querySelector('[class*="gap-2.5"]'); expect(toolbarArea).toBeInTheDocument(); - + // Should contain SVG icons for copy/run operations - const svgIcons = container.querySelectorAll('svg'); + const svgIcons = container.querySelectorAll("svg"); expect(svgIcons.length).toBeGreaterThan(0); - + // Should show "Run" text (may be hidden on small screens) expect(container.textContent).toMatch(/Run/); }); @@ -213,15 +224,25 @@ describe("UnifiedTerminalCommand", () => { test("handles move to background action", async () => { const mockToolCallState: ToolCallState = { status: "calling", + toolCallId: MOCK_TOOL_CALL_ID, + toolCall: { + id: MOCK_TOOL_CALL_ID, + type: "function", + function: { + name: "terminal", + arguments: "{}", + }, + }, + parsedArgs: {}, }; const { user } = await renderWithProviders( - + />, ); // Find and click move to background link @@ -235,33 +256,33 @@ describe("UnifiedTerminalCommand", () => { test("shows different status types correctly", async () => { // Test completed status const { rerender, container } = await renderWithProviders( - + />, ); expect(container.textContent).toMatch(/Command completed successfully/); // Test failed status rerender( - + />, ); expect(container.textContent).toMatch(/Command failed with exit code 1/); // Test background status rerender( - + />, ); expect(container.textContent).toMatch(/Command moved to background/); @@ -269,37 +290,39 @@ describe("UnifiedTerminalCommand", () => { test("handles empty output gracefully", async () => { const { container } = await renderWithProviders( - + />, ); // Should show command but no output section expect(screen.getByText(`$ ${MOCK_COMMAND}`)).toBeInTheDocument(); - + // Should not show any output content - const outputElements = container.querySelectorAll('pre code > div:not(:first-child)'); + const outputElements = container.querySelectorAll( + "pre code > div:not(:first-child)", + ); expect(outputElements.length).toBe(0); }); test("processes terminal content correctly for line limiting", async () => { const { container } = await renderWithProviders( - + />, ); // Should show correct number of hidden lines expect(screen.getByText(/\+15 more lines/)).toBeInTheDocument(); - + // Should show the last lines expect(container.textContent).toMatch(/Line 25/); - + // Should not initially show the first lines (Line 1-15 should be hidden) // The component shows last 10 lines (16-25) with a +15 more lines indicator expect(container.textContent).toMatch(/Line 16/); @@ -307,24 +330,24 @@ describe("UnifiedTerminalCommand", () => { test("clicking on collapsible output toggles expansion", async () => { const { user, container } = await renderWithProviders( - + />, ); // Click on the "+15 more lines" button to expand const expandButton = screen.getByText(/\+15 more lines/); await user.click(expandButton); - + // Should expand and show all content await waitFor(() => { expect(container.textContent).toMatch(/Line 1/); }); - + // Should show collapse option after expansion expect(screen.getByText(/Collapse/)).toBeInTheDocument(); }); -}); \ No newline at end of file +}); diff --git a/gui/src/components/UnifiedTerminal/UnifiedTerminal.tsx b/gui/src/components/UnifiedTerminal/UnifiedTerminal.tsx index ce2650348..bb0cdd25c 100644 --- a/gui/src/components/UnifiedTerminal/UnifiedTerminal.tsx +++ b/gui/src/components/UnifiedTerminal/UnifiedTerminal.tsx @@ -418,7 +418,11 @@ export function UnifiedTerminalCommand({ }, [command, output, hasOutput]); return ( - +
{/* Toolbar */}