Fix tests

This commit is contained in:
Matt Rubens
2025-02-01 12:15:03 -05:00
parent 14683cc3c5
commit 70ad037016
4 changed files with 45 additions and 0 deletions

View File

@@ -5,9 +5,25 @@ const vscode = {
createTextEditorDecorationType: jest.fn().mockReturnValue({ createTextEditorDecorationType: jest.fn().mockReturnValue({
dispose: jest.fn(), dispose: jest.fn(),
}), }),
tabGroups: {
onDidChangeTabs: jest.fn(() => {
return {
dispose: jest.fn(),
}
}),
all: [],
},
}, },
workspace: { workspace: {
onDidSaveTextDocument: jest.fn(), 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 { Disposable: class {
dispose() {} dispose() {}
@@ -57,6 +73,17 @@ const vscode = {
Development: 2, Development: 2,
Test: 3, Test: 3,
}, },
FileType: {
Unknown: 0,
File: 1,
Directory: 2,
SymbolicLink: 64,
},
TabInputText: class {
constructor(uri) {
this.uri = uri
}
},
} }
module.exports = vscode module.exports = vscode

View File

@@ -128,6 +128,7 @@ jest.mock("vscode", () => {
visibleTextEditors: [mockTextEditor], visibleTextEditors: [mockTextEditor],
tabGroups: { tabGroups: {
all: [mockTabGroup], all: [mockTabGroup],
onDidChangeTabs: jest.fn(() => ({ dispose: jest.fn() })),
}, },
}, },
workspace: { workspace: {

View File

@@ -16,6 +16,12 @@ const mockWatcher = {
} }
jest.mock("vscode", () => ({ jest.mock("vscode", () => ({
window: {
tabGroups: {
onDidChangeTabs: jest.fn(() => ({ dispose: jest.fn() })),
all: [],
},
},
workspace: { workspace: {
workspaceFolders: [ workspaceFolders: [
{ {
@@ -61,6 +67,7 @@ describe("WorkspaceTracker", () => {
expect(mockProvider.postMessageToWebview).toHaveBeenCalledWith({ expect(mockProvider.postMessageToWebview).toHaveBeenCalledWith({
type: "workspaceUpdated", type: "workspaceUpdated",
filePaths: expect.arrayContaining(["file1.ts", "file2.ts"]), filePaths: expect.arrayContaining(["file1.ts", "file2.ts"]),
openedTabs: [],
}) })
expect((mockProvider.postMessageToWebview as jest.Mock).mock.calls[0][0].filePaths).toHaveLength(2) expect((mockProvider.postMessageToWebview as jest.Mock).mock.calls[0][0].filePaths).toHaveLength(2)
}) })
@@ -74,6 +81,7 @@ describe("WorkspaceTracker", () => {
expect(mockProvider.postMessageToWebview).toHaveBeenCalledWith({ expect(mockProvider.postMessageToWebview).toHaveBeenCalledWith({
type: "workspaceUpdated", type: "workspaceUpdated",
filePaths: ["newfile.ts"], filePaths: ["newfile.ts"],
openedTabs: [],
}) })
}) })
@@ -92,6 +100,7 @@ describe("WorkspaceTracker", () => {
expect(mockProvider.postMessageToWebview).toHaveBeenLastCalledWith({ expect(mockProvider.postMessageToWebview).toHaveBeenLastCalledWith({
type: "workspaceUpdated", type: "workspaceUpdated",
filePaths: [], filePaths: [],
openedTabs: [],
}) })
}) })
@@ -106,6 +115,7 @@ describe("WorkspaceTracker", () => {
expect(mockProvider.postMessageToWebview).toHaveBeenCalledWith({ expect(mockProvider.postMessageToWebview).toHaveBeenCalledWith({
type: "workspaceUpdated", type: "workspaceUpdated",
filePaths: expect.arrayContaining(["newdir"]), filePaths: expect.arrayContaining(["newdir"]),
openedTabs: [],
}) })
const lastCall = (mockProvider.postMessageToWebview as jest.Mock).mock.calls.slice(-1)[0] const lastCall = (mockProvider.postMessageToWebview as jest.Mock).mock.calls.slice(-1)[0]
expect(lastCall[0].filePaths).toHaveLength(1) expect(lastCall[0].filePaths).toHaveLength(1)
@@ -126,6 +136,7 @@ describe("WorkspaceTracker", () => {
expect(mockProvider.postMessageToWebview).toHaveBeenCalledWith({ expect(mockProvider.postMessageToWebview).toHaveBeenCalledWith({
type: "workspaceUpdated", type: "workspaceUpdated",
filePaths: expect.arrayContaining(expectedFiles), filePaths: expect.arrayContaining(expectedFiles),
openedTabs: [],
}) })
expect(calls[0][0].filePaths).toHaveLength(1000) expect(calls[0][0].filePaths).toHaveLength(1000)

View File

@@ -41,6 +41,7 @@ describe("ChatTextArea", () => {
// Default mock implementation for useExtensionState // Default mock implementation for useExtensionState
;(useExtensionState as jest.Mock).mockReturnValue({ ;(useExtensionState as jest.Mock).mockReturnValue({
filePaths: [], filePaths: [],
openedTabs: [],
apiConfiguration: { apiConfiguration: {
apiProvider: "anthropic", apiProvider: "anthropic",
}, },
@@ -51,6 +52,7 @@ describe("ChatTextArea", () => {
it("should be disabled when textAreaDisabled is true", () => { it("should be disabled when textAreaDisabled is true", () => {
;(useExtensionState as jest.Mock).mockReturnValue({ ;(useExtensionState as jest.Mock).mockReturnValue({
filePaths: [], filePaths: [],
openedTabs: [],
}) })
render(<ChatTextArea {...defaultProps} textAreaDisabled={true} />) render(<ChatTextArea {...defaultProps} textAreaDisabled={true} />)
@@ -68,6 +70,7 @@ describe("ChatTextArea", () => {
;(useExtensionState as jest.Mock).mockReturnValue({ ;(useExtensionState as jest.Mock).mockReturnValue({
filePaths: [], filePaths: [],
openedTabs: [],
apiConfiguration, apiConfiguration,
}) })
@@ -85,6 +88,7 @@ describe("ChatTextArea", () => {
it("should not send message when input is empty", () => { it("should not send message when input is empty", () => {
;(useExtensionState as jest.Mock).mockReturnValue({ ;(useExtensionState as jest.Mock).mockReturnValue({
filePaths: [], filePaths: [],
openedTabs: [],
apiConfiguration: { apiConfiguration: {
apiProvider: "openrouter", apiProvider: "openrouter",
}, },
@@ -101,6 +105,7 @@ describe("ChatTextArea", () => {
it("should show loading state while enhancing", () => { it("should show loading state while enhancing", () => {
;(useExtensionState as jest.Mock).mockReturnValue({ ;(useExtensionState as jest.Mock).mockReturnValue({
filePaths: [], filePaths: [],
openedTabs: [],
apiConfiguration: { apiConfiguration: {
apiProvider: "openrouter", apiProvider: "openrouter",
}, },
@@ -123,6 +128,7 @@ describe("ChatTextArea", () => {
// Update apiConfiguration // Update apiConfiguration
;(useExtensionState as jest.Mock).mockReturnValue({ ;(useExtensionState as jest.Mock).mockReturnValue({
filePaths: [], filePaths: [],
openedTabs: [],
apiConfiguration: { apiConfiguration: {
apiProvider: "openrouter", apiProvider: "openrouter",
newSetting: "test", newSetting: "test",