From 70ad037016e60af76a798108187ed44d42f3684f Mon Sep 17 00:00:00 2001 From: Matt Rubens Date: Sat, 1 Feb 2025 12:15:03 -0500 Subject: [PATCH] Fix tests --- src/__mocks__/vscode.js | 27 +++++++++++++++++++ src/core/__tests__/Cline.test.ts | 1 + .../__tests__/WorkspaceTracker.test.ts | 11 ++++++++ .../chat/__tests__/ChatTextArea.test.tsx | 6 +++++ 4 files changed, 45 insertions(+) diff --git a/src/__mocks__/vscode.js b/src/__mocks__/vscode.js index 6c25b10..ba44f8d 100644 --- a/src/__mocks__/vscode.js +++ b/src/__mocks__/vscode.js @@ -5,9 +5,25 @@ const vscode = { createTextEditorDecorationType: jest.fn().mockReturnValue({ dispose: jest.fn(), }), + tabGroups: { + onDidChangeTabs: jest.fn(() => { + return { + dispose: jest.fn(), + } + }), + all: [], + }, }, workspace: { onDidSaveTextDocument: jest.fn(), + createFileSystemWatcher: jest.fn().mockReturnValue({ + onDidCreate: jest.fn().mockReturnValue({ dispose: jest.fn() }), + onDidDelete: jest.fn().mockReturnValue({ dispose: jest.fn() }), + dispose: jest.fn(), + }), + fs: { + stat: jest.fn(), + }, }, Disposable: class { dispose() {} @@ -57,6 +73,17 @@ const vscode = { Development: 2, Test: 3, }, + FileType: { + Unknown: 0, + File: 1, + Directory: 2, + SymbolicLink: 64, + }, + TabInputText: class { + constructor(uri) { + this.uri = uri + } + }, } module.exports = vscode diff --git a/src/core/__tests__/Cline.test.ts b/src/core/__tests__/Cline.test.ts index e49b660..4c1f697 100644 --- a/src/core/__tests__/Cline.test.ts +++ b/src/core/__tests__/Cline.test.ts @@ -128,6 +128,7 @@ jest.mock("vscode", () => { visibleTextEditors: [mockTextEditor], tabGroups: { all: [mockTabGroup], + onDidChangeTabs: jest.fn(() => ({ dispose: jest.fn() })), }, }, workspace: { diff --git a/src/integrations/workspace/__tests__/WorkspaceTracker.test.ts b/src/integrations/workspace/__tests__/WorkspaceTracker.test.ts index 44b5648..47b678a 100644 --- a/src/integrations/workspace/__tests__/WorkspaceTracker.test.ts +++ b/src/integrations/workspace/__tests__/WorkspaceTracker.test.ts @@ -16,6 +16,12 @@ const mockWatcher = { } jest.mock("vscode", () => ({ + window: { + tabGroups: { + onDidChangeTabs: jest.fn(() => ({ dispose: jest.fn() })), + all: [], + }, + }, workspace: { workspaceFolders: [ { @@ -61,6 +67,7 @@ describe("WorkspaceTracker", () => { expect(mockProvider.postMessageToWebview).toHaveBeenCalledWith({ type: "workspaceUpdated", filePaths: expect.arrayContaining(["file1.ts", "file2.ts"]), + openedTabs: [], }) expect((mockProvider.postMessageToWebview as jest.Mock).mock.calls[0][0].filePaths).toHaveLength(2) }) @@ -74,6 +81,7 @@ describe("WorkspaceTracker", () => { expect(mockProvider.postMessageToWebview).toHaveBeenCalledWith({ type: "workspaceUpdated", filePaths: ["newfile.ts"], + openedTabs: [], }) }) @@ -92,6 +100,7 @@ describe("WorkspaceTracker", () => { expect(mockProvider.postMessageToWebview).toHaveBeenLastCalledWith({ type: "workspaceUpdated", filePaths: [], + openedTabs: [], }) }) @@ -106,6 +115,7 @@ describe("WorkspaceTracker", () => { expect(mockProvider.postMessageToWebview).toHaveBeenCalledWith({ type: "workspaceUpdated", filePaths: expect.arrayContaining(["newdir"]), + openedTabs: [], }) const lastCall = (mockProvider.postMessageToWebview as jest.Mock).mock.calls.slice(-1)[0] expect(lastCall[0].filePaths).toHaveLength(1) @@ -126,6 +136,7 @@ describe("WorkspaceTracker", () => { expect(mockProvider.postMessageToWebview).toHaveBeenCalledWith({ type: "workspaceUpdated", filePaths: expect.arrayContaining(expectedFiles), + openedTabs: [], }) expect(calls[0][0].filePaths).toHaveLength(1000) diff --git a/webview-ui/src/components/chat/__tests__/ChatTextArea.test.tsx b/webview-ui/src/components/chat/__tests__/ChatTextArea.test.tsx index 5467c29..599e8d3 100644 --- a/webview-ui/src/components/chat/__tests__/ChatTextArea.test.tsx +++ b/webview-ui/src/components/chat/__tests__/ChatTextArea.test.tsx @@ -41,6 +41,7 @@ describe("ChatTextArea", () => { // Default mock implementation for useExtensionState ;(useExtensionState as jest.Mock).mockReturnValue({ filePaths: [], + openedTabs: [], apiConfiguration: { apiProvider: "anthropic", }, @@ -51,6 +52,7 @@ describe("ChatTextArea", () => { it("should be disabled when textAreaDisabled is true", () => { ;(useExtensionState as jest.Mock).mockReturnValue({ filePaths: [], + openedTabs: [], }) render() @@ -68,6 +70,7 @@ describe("ChatTextArea", () => { ;(useExtensionState as jest.Mock).mockReturnValue({ filePaths: [], + openedTabs: [], apiConfiguration, }) @@ -85,6 +88,7 @@ describe("ChatTextArea", () => { it("should not send message when input is empty", () => { ;(useExtensionState as jest.Mock).mockReturnValue({ filePaths: [], + openedTabs: [], apiConfiguration: { apiProvider: "openrouter", }, @@ -101,6 +105,7 @@ describe("ChatTextArea", () => { it("should show loading state while enhancing", () => { ;(useExtensionState as jest.Mock).mockReturnValue({ filePaths: [], + openedTabs: [], apiConfiguration: { apiProvider: "openrouter", }, @@ -123,6 +128,7 @@ describe("ChatTextArea", () => { // Update apiConfiguration ;(useExtensionState as jest.Mock).mockReturnValue({ filePaths: [], + openedTabs: [], apiConfiguration: { apiProvider: "openrouter", newSetting: "test",