Skip to content

Commit 70ad037

Browse files
committed
Fix tests
1 parent 14683cc commit 70ad037

File tree

4 files changed

+45
-0
lines changed

4 files changed

+45
-0
lines changed

src/__mocks__/vscode.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,25 @@ const vscode = {
55
createTextEditorDecorationType: jest.fn().mockReturnValue({
66
dispose: jest.fn(),
77
}),
8+
tabGroups: {
9+
onDidChangeTabs: jest.fn(() => {
10+
return {
11+
dispose: jest.fn(),
12+
}
13+
}),
14+
all: [],
15+
},
816
},
917
workspace: {
1018
onDidSaveTextDocument: jest.fn(),
19+
createFileSystemWatcher: jest.fn().mockReturnValue({
20+
onDidCreate: jest.fn().mockReturnValue({ dispose: jest.fn() }),
21+
onDidDelete: jest.fn().mockReturnValue({ dispose: jest.fn() }),
22+
dispose: jest.fn(),
23+
}),
24+
fs: {
25+
stat: jest.fn(),
26+
},
1127
},
1228
Disposable: class {
1329
dispose() {}
@@ -57,6 +73,17 @@ const vscode = {
5773
Development: 2,
5874
Test: 3,
5975
},
76+
FileType: {
77+
Unknown: 0,
78+
File: 1,
79+
Directory: 2,
80+
SymbolicLink: 64,
81+
},
82+
TabInputText: class {
83+
constructor(uri) {
84+
this.uri = uri
85+
}
86+
},
6087
}
6188

6289
module.exports = vscode

src/core/__tests__/Cline.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@ jest.mock("vscode", () => {
128128
visibleTextEditors: [mockTextEditor],
129129
tabGroups: {
130130
all: [mockTabGroup],
131+
onDidChangeTabs: jest.fn(() => ({ dispose: jest.fn() })),
131132
},
132133
},
133134
workspace: {

src/integrations/workspace/__tests__/WorkspaceTracker.test.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,12 @@ const mockWatcher = {
1616
}
1717

1818
jest.mock("vscode", () => ({
19+
window: {
20+
tabGroups: {
21+
onDidChangeTabs: jest.fn(() => ({ dispose: jest.fn() })),
22+
all: [],
23+
},
24+
},
1925
workspace: {
2026
workspaceFolders: [
2127
{
@@ -61,6 +67,7 @@ describe("WorkspaceTracker", () => {
6167
expect(mockProvider.postMessageToWebview).toHaveBeenCalledWith({
6268
type: "workspaceUpdated",
6369
filePaths: expect.arrayContaining(["file1.ts", "file2.ts"]),
70+
openedTabs: [],
6471
})
6572
expect((mockProvider.postMessageToWebview as jest.Mock).mock.calls[0][0].filePaths).toHaveLength(2)
6673
})
@@ -74,6 +81,7 @@ describe("WorkspaceTracker", () => {
7481
expect(mockProvider.postMessageToWebview).toHaveBeenCalledWith({
7582
type: "workspaceUpdated",
7683
filePaths: ["newfile.ts"],
84+
openedTabs: [],
7785
})
7886
})
7987

@@ -92,6 +100,7 @@ describe("WorkspaceTracker", () => {
92100
expect(mockProvider.postMessageToWebview).toHaveBeenLastCalledWith({
93101
type: "workspaceUpdated",
94102
filePaths: [],
103+
openedTabs: [],
95104
})
96105
})
97106

@@ -106,6 +115,7 @@ describe("WorkspaceTracker", () => {
106115
expect(mockProvider.postMessageToWebview).toHaveBeenCalledWith({
107116
type: "workspaceUpdated",
108117
filePaths: expect.arrayContaining(["newdir"]),
118+
openedTabs: [],
109119
})
110120
const lastCall = (mockProvider.postMessageToWebview as jest.Mock).mock.calls.slice(-1)[0]
111121
expect(lastCall[0].filePaths).toHaveLength(1)
@@ -126,6 +136,7 @@ describe("WorkspaceTracker", () => {
126136
expect(mockProvider.postMessageToWebview).toHaveBeenCalledWith({
127137
type: "workspaceUpdated",
128138
filePaths: expect.arrayContaining(expectedFiles),
139+
openedTabs: [],
129140
})
130141
expect(calls[0][0].filePaths).toHaveLength(1000)
131142

webview-ui/src/components/chat/__tests__/ChatTextArea.test.tsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ describe("ChatTextArea", () => {
4141
// Default mock implementation for useExtensionState
4242
;(useExtensionState as jest.Mock).mockReturnValue({
4343
filePaths: [],
44+
openedTabs: [],
4445
apiConfiguration: {
4546
apiProvider: "anthropic",
4647
},
@@ -51,6 +52,7 @@ describe("ChatTextArea", () => {
5152
it("should be disabled when textAreaDisabled is true", () => {
5253
;(useExtensionState as jest.Mock).mockReturnValue({
5354
filePaths: [],
55+
openedTabs: [],
5456
})
5557

5658
render(<ChatTextArea {...defaultProps} textAreaDisabled={true} />)
@@ -68,6 +70,7 @@ describe("ChatTextArea", () => {
6870

6971
;(useExtensionState as jest.Mock).mockReturnValue({
7072
filePaths: [],
73+
openedTabs: [],
7174
apiConfiguration,
7275
})
7376

@@ -85,6 +88,7 @@ describe("ChatTextArea", () => {
8588
it("should not send message when input is empty", () => {
8689
;(useExtensionState as jest.Mock).mockReturnValue({
8790
filePaths: [],
91+
openedTabs: [],
8892
apiConfiguration: {
8993
apiProvider: "openrouter",
9094
},
@@ -101,6 +105,7 @@ describe("ChatTextArea", () => {
101105
it("should show loading state while enhancing", () => {
102106
;(useExtensionState as jest.Mock).mockReturnValue({
103107
filePaths: [],
108+
openedTabs: [],
104109
apiConfiguration: {
105110
apiProvider: "openrouter",
106111
},
@@ -123,6 +128,7 @@ describe("ChatTextArea", () => {
123128
// Update apiConfiguration
124129
;(useExtensionState as jest.Mock).mockReturnValue({
125130
filePaths: [],
131+
openedTabs: [],
126132
apiConfiguration: {
127133
apiProvider: "openrouter",
128134
newSetting: "test",

0 commit comments

Comments
 (0)