|
@@ -194,8 +194,16 @@ describe("getContextMenuOptions", () => {
|
|
|
{ path: "/Users/test/project/assets/", type: "folder", label: "assets/" },
|
|
{ path: "/Users/test/project/assets/", type: "folder", label: "assets/" },
|
|
|
]
|
|
]
|
|
|
|
|
|
|
|
|
|
+ // Mock translation function
|
|
|
|
|
+ const mockT = (key: string, options?: { name?: string }) => {
|
|
|
|
|
+ if (key === "chat:command.triggerDescription" && options?.name) {
|
|
|
|
|
+ return `Trigger command: ${options.name}`
|
|
|
|
|
+ }
|
|
|
|
|
+ return key
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
it("should return all option types for empty query", () => {
|
|
it("should return all option types for empty query", () => {
|
|
|
- const result = getContextMenuOptions("", "", null, [])
|
|
|
|
|
|
|
+ const result = getContextMenuOptions("", "", mockT, null, [])
|
|
|
expect(result).toHaveLength(6)
|
|
expect(result).toHaveLength(6)
|
|
|
expect(result.map((item) => item.type)).toEqual([
|
|
expect(result.map((item) => item.type)).toEqual([
|
|
|
ContextMenuOptionType.Problems,
|
|
ContextMenuOptionType.Problems,
|
|
@@ -208,7 +216,7 @@ describe("getContextMenuOptions", () => {
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
it("should filter by selected type when query is empty", () => {
|
|
it("should filter by selected type when query is empty", () => {
|
|
|
- const result = getContextMenuOptions("", "", ContextMenuOptionType.File, mockQueryItems)
|
|
|
|
|
|
|
+ const result = getContextMenuOptions("", "", mockT, ContextMenuOptionType.File, mockQueryItems)
|
|
|
expect(result).toHaveLength(2)
|
|
expect(result).toHaveLength(2)
|
|
|
expect(result.map((item) => item.type)).toContain(ContextMenuOptionType.File)
|
|
expect(result.map((item) => item.type)).toContain(ContextMenuOptionType.File)
|
|
|
expect(result.map((item) => item.type)).toContain(ContextMenuOptionType.OpenedFile)
|
|
expect(result.map((item) => item.type)).toContain(ContextMenuOptionType.OpenedFile)
|
|
@@ -217,19 +225,19 @@ describe("getContextMenuOptions", () => {
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
it("should match git commands", () => {
|
|
it("should match git commands", () => {
|
|
|
- const result = getContextMenuOptions("git", "git", null, mockQueryItems)
|
|
|
|
|
|
|
+ const result = getContextMenuOptions("git", "git", mockT, null, mockQueryItems)
|
|
|
expect(result[0].type).toBe(ContextMenuOptionType.Git)
|
|
expect(result[0].type).toBe(ContextMenuOptionType.Git)
|
|
|
expect(result[0].label).toBe("Git Commits")
|
|
expect(result[0].label).toBe("Git Commits")
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
it("should match git commit hashes", () => {
|
|
it("should match git commit hashes", () => {
|
|
|
- const result = getContextMenuOptions("abc1234", "abc1234", null, mockQueryItems)
|
|
|
|
|
|
|
+ const result = getContextMenuOptions("abc1234", "abc1234", mockT, null, mockQueryItems)
|
|
|
expect(result[0].type).toBe(ContextMenuOptionType.Git)
|
|
expect(result[0].type).toBe(ContextMenuOptionType.Git)
|
|
|
expect(result[0].value).toBe("abc1234")
|
|
expect(result[0].value).toBe("abc1234")
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
it("should return NoResults when no matches found", () => {
|
|
it("should return NoResults when no matches found", () => {
|
|
|
- const result = getContextMenuOptions("nonexistent", "nonexistent", null, mockQueryItems)
|
|
|
|
|
|
|
+ const result = getContextMenuOptions("nonexistent", "nonexistent", mockT, null, mockQueryItems)
|
|
|
expect(result).toHaveLength(1)
|
|
expect(result).toHaveLength(1)
|
|
|
expect(result[0].type).toBe(ContextMenuOptionType.NoResults)
|
|
expect(result[0].type).toBe(ContextMenuOptionType.NoResults)
|
|
|
})
|
|
})
|
|
@@ -250,7 +258,7 @@ describe("getContextMenuOptions", () => {
|
|
|
},
|
|
},
|
|
|
]
|
|
]
|
|
|
|
|
|
|
|
- const result = getContextMenuOptions("test", "test", null, testItems, mockDynamicSearchResults)
|
|
|
|
|
|
|
+ const result = getContextMenuOptions("test", "test", mockT, null, testItems, mockDynamicSearchResults)
|
|
|
|
|
|
|
|
// Check if opened files and dynamic search results are included
|
|
// Check if opened files and dynamic search results are included
|
|
|
expect(result.some((item) => item.type === ContextMenuOptionType.OpenedFile)).toBe(true)
|
|
expect(result.some((item) => item.type === ContextMenuOptionType.OpenedFile)).toBe(true)
|
|
@@ -259,7 +267,7 @@ describe("getContextMenuOptions", () => {
|
|
|
|
|
|
|
|
it("should maintain correct result ordering according to implementation", () => {
|
|
it("should maintain correct result ordering according to implementation", () => {
|
|
|
// Add multiple item types to test ordering
|
|
// Add multiple item types to test ordering
|
|
|
- const result = getContextMenuOptions("t", "t", null, mockQueryItems, mockDynamicSearchResults)
|
|
|
|
|
|
|
+ const result = getContextMenuOptions("t", "t", mockT, null, mockQueryItems, mockDynamicSearchResults)
|
|
|
|
|
|
|
|
// Find the different result types
|
|
// Find the different result types
|
|
|
const fileResults = result.filter(
|
|
const fileResults = result.filter(
|
|
@@ -290,7 +298,7 @@ describe("getContextMenuOptions", () => {
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
it("should include opened files when dynamic search results exist", () => {
|
|
it("should include opened files when dynamic search results exist", () => {
|
|
|
- const result = getContextMenuOptions("open", "open", null, mockQueryItems, mockDynamicSearchResults)
|
|
|
|
|
|
|
+ const result = getContextMenuOptions("open", "open", mockT, null, mockQueryItems, mockDynamicSearchResults)
|
|
|
|
|
|
|
|
// Verify opened files are included
|
|
// Verify opened files are included
|
|
|
expect(result.some((item) => item.type === ContextMenuOptionType.OpenedFile)).toBe(true)
|
|
expect(result.some((item) => item.type === ContextMenuOptionType.OpenedFile)).toBe(true)
|
|
@@ -299,7 +307,7 @@ describe("getContextMenuOptions", () => {
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
it("should include git results when dynamic search results exist", () => {
|
|
it("should include git results when dynamic search results exist", () => {
|
|
|
- const result = getContextMenuOptions("commit", "commit", null, mockQueryItems, mockDynamicSearchResults)
|
|
|
|
|
|
|
+ const result = getContextMenuOptions("commit", "commit", mockT, null, mockQueryItems, mockDynamicSearchResults)
|
|
|
|
|
|
|
|
// Verify git results are included
|
|
// Verify git results are included
|
|
|
expect(result.some((item) => item.type === ContextMenuOptionType.Git)).toBe(true)
|
|
expect(result.some((item) => item.type === ContextMenuOptionType.Git)).toBe(true)
|
|
@@ -320,7 +328,7 @@ describe("getContextMenuOptions", () => {
|
|
|
},
|
|
},
|
|
|
]
|
|
]
|
|
|
|
|
|
|
|
- const result = getContextMenuOptions("test", "test", null, mockQueryItems, duplicateSearchResults)
|
|
|
|
|
|
|
+ const result = getContextMenuOptions("test", "test", mockT, null, mockQueryItems, duplicateSearchResults)
|
|
|
|
|
|
|
|
// Count occurrences of src/test.ts in results
|
|
// Count occurrences of src/test.ts in results
|
|
|
const duplicateCount = result.filter(
|
|
const duplicateCount = result.filter(
|
|
@@ -340,6 +348,7 @@ describe("getContextMenuOptions", () => {
|
|
|
const result = getContextMenuOptions(
|
|
const result = getContextMenuOptions(
|
|
|
"nonexistentquery123456",
|
|
"nonexistentquery123456",
|
|
|
"nonexistentquery123456",
|
|
"nonexistentquery123456",
|
|
|
|
|
+ mockT,
|
|
|
null,
|
|
null,
|
|
|
mockQueryItems,
|
|
mockQueryItems,
|
|
|
[], // Empty dynamic search results
|
|
[], // Empty dynamic search results
|
|
@@ -387,7 +396,7 @@ describe("getContextMenuOptions", () => {
|
|
|
]
|
|
]
|
|
|
|
|
|
|
|
// Get results for "test" query
|
|
// Get results for "test" query
|
|
|
- const result = getContextMenuOptions(testQuery, testQuery, null, testItems, testSearchResults)
|
|
|
|
|
|
|
+ const result = getContextMenuOptions(testQuery, testQuery, mockT, null, testItems, testSearchResults)
|
|
|
|
|
|
|
|
// Verify we have results
|
|
// Verify we have results
|
|
|
expect(result.length).toBeGreaterThan(0)
|
|
expect(result.length).toBeGreaterThan(0)
|
|
@@ -433,7 +442,7 @@ describe("getContextMenuOptions", () => {
|
|
|
},
|
|
},
|
|
|
]
|
|
]
|
|
|
|
|
|
|
|
- const result = getContextMenuOptions("/co", "/co", null, [], [], mockModes)
|
|
|
|
|
|
|
+ const result = getContextMenuOptions("/co", "/co", mockT, null, [], [], mockModes)
|
|
|
|
|
|
|
|
// Verify mode results are returned
|
|
// Verify mode results are returned
|
|
|
expect(result[0].type).toBe(ContextMenuOptionType.Mode)
|
|
expect(result[0].type).toBe(ContextMenuOptionType.Mode)
|
|
@@ -443,7 +452,7 @@ describe("getContextMenuOptions", () => {
|
|
|
it("should not process slash commands when query starts with slash but inputValue doesn't", () => {
|
|
it("should not process slash commands when query starts with slash but inputValue doesn't", () => {
|
|
|
// Use a completely non-matching query to ensure we get NoResults
|
|
// Use a completely non-matching query to ensure we get NoResults
|
|
|
// and provide empty query items to avoid any matches
|
|
// and provide empty query items to avoid any matches
|
|
|
- const result = getContextMenuOptions("/nonexistentquery", "Hello /code", null, [], [])
|
|
|
|
|
|
|
+ const result = getContextMenuOptions("/nonexistentquery", "Hello /code", mockT, null, [], [])
|
|
|
|
|
|
|
|
// Should not process as a mode command
|
|
// Should not process as a mode command
|
|
|
expect(result[0].type).not.toBe(ContextMenuOptionType.Mode)
|
|
expect(result[0].type).not.toBe(ContextMenuOptionType.Mode)
|
|
@@ -453,7 +462,7 @@ describe("getContextMenuOptions", () => {
|
|
|
|
|
|
|
|
// --- Tests for Escaped Spaces (Focus on how paths are presented) ---
|
|
// --- Tests for Escaped Spaces (Focus on how paths are presented) ---
|
|
|
it("should return search results with correct labels/descriptions (no escaping needed here)", () => {
|
|
it("should return search results with correct labels/descriptions (no escaping needed here)", () => {
|
|
|
- const options = getContextMenuOptions("@search", "search", null, mockQueryItems, mockSearchResults)
|
|
|
|
|
|
|
+ const options = getContextMenuOptions("@search", "search", mockT, null, mockQueryItems, mockSearchResults)
|
|
|
const fileResult = options.find((o) => o.label === "search result spaces.ts")
|
|
const fileResult = options.find((o) => o.label === "search result spaces.ts")
|
|
|
expect(fileResult).toBeDefined()
|
|
expect(fileResult).toBeDefined()
|
|
|
// Value should be the normalized path, description might be the same or label
|
|
// Value should be the normalized path, description might be the same or label
|
|
@@ -466,7 +475,7 @@ describe("getContextMenuOptions", () => {
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
it("should return query items (like opened files) with correct labels/descriptions", () => {
|
|
it("should return query items (like opened files) with correct labels/descriptions", () => {
|
|
|
- const options = getContextMenuOptions("open", "@open", null, mockQueryItems, [])
|
|
|
|
|
|
|
+ const options = getContextMenuOptions("open", "@open", mockT, null, mockQueryItems, [])
|
|
|
const openedFile = options.find((o) => o.label === "open file.ts")
|
|
const openedFile = options.find((o) => o.label === "open file.ts")
|
|
|
expect(openedFile).toBeDefined()
|
|
expect(openedFile).toBeDefined()
|
|
|
expect(openedFile?.value).toBe("src/open file.ts")
|
|
expect(openedFile?.value).toBe("src/open file.ts")
|
|
@@ -483,7 +492,7 @@ describe("getContextMenuOptions", () => {
|
|
|
]
|
|
]
|
|
|
|
|
|
|
|
// The formatting happens in getContextMenuOptions when converting search results to menu items
|
|
// The formatting happens in getContextMenuOptions when converting search results to menu items
|
|
|
- const formattedItems = getContextMenuOptions("spaces", "@spaces", null, [], searchResults)
|
|
|
|
|
|
|
+ const formattedItems = getContextMenuOptions("spaces", "@spaces", mockT, null, [], searchResults)
|
|
|
|
|
|
|
|
// Verify we get some results back that aren't "No Results"
|
|
// Verify we get some results back that aren't "No Results"
|
|
|
expect(formattedItems.length).toBeGreaterThan(0)
|
|
expect(formattedItems.length).toBeGreaterThan(0)
|