Skip to content

Commit c5982f0

Browse files
authored
Merge pull request #7 from chadgauth:fix/test-fails
fix the test
2 parents 8b61fcc + 2be8751 commit c5982f0

File tree

3 files changed

+13
-27
lines changed

3 files changed

+13
-27
lines changed

webview-ui/src/components/chat/ChatTextArea/ChatTextAreaInput.tsx

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -432,6 +432,7 @@ const ChatTextAreaInput = React.forwardRef<HTMLTextAreaElement, ChatTextAreaInpu
432432

433433
return (
434434
<div
435+
className="chat-text-area"
435436
style={{
436437
position: "relative",
437438
display: "flex",
@@ -461,22 +462,17 @@ const ChatTextAreaInput = React.forwardRef<HTMLTextAreaElement, ChatTextAreaInpu
461462
let newValue = inputValue.slice(0, cursorPosition)
462463
let totalLength = 0
463464

464-
lines.forEach((line, index) => {
465+
for (const line of lines) {
465466
// Convert each path to a mention-friendly format
466-
const mentionText = convertToMentionPath(line, cwd)
467-
newValue += mentionText
468-
totalLength += mentionText.length
469-
470-
// Add space after each mention except the last one
471-
if (index < lines.length - 1) {
472-
newValue += " "
473-
totalLength += 1
474-
}
475-
})
467+
const mentionPath = convertToMentionPath(line, cwd)
468+
// If the path is unchanged (outside cwd), use it as is
469+
const formattedPath = mentionPath === line ? line : mentionPath
470+
newValue += formattedPath + " "
471+
totalLength += formattedPath.length + 1
472+
}
476473

477-
// Add space after the last mention and append the rest of the input
478-
newValue += " " + inputValue.slice(cursorPosition)
479-
totalLength += 1
474+
// Append the rest of the input without extra space
475+
newValue = newValue.trimEnd() + " " + inputValue.slice(cursorPosition).trimStart()
480476

481477
setInputValue(newValue)
482478
const newCursorPosition = cursorPosition + totalLength

webview-ui/src/components/chat/ChatTextArea/ChatTextAreaLayout.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ interface ChatTextAreaLayoutProps {
1212
const ChatTextAreaLayout: React.FC<ChatTextAreaLayoutProps> = ({ children: { input, selections, actions } }) => {
1313
return (
1414
<div
15-
className="chat-text-area"
1615
style={{
1716
position: "relative",
1817
display: "flex",

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

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,20 +13,11 @@ jest.mock("../../../utils/vscode", () => ({
1313
}))
1414
jest.mock("../../../components/common/CodeBlock")
1515
jest.mock("../../../components/common/MarkdownBlock")
16-
jest.mock("../../../utils/path-mentions", () => ({
17-
convertToMentionPath: jest.fn((path, cwd) => {
18-
// Simple mock implementation that mimics the real function's behavior
19-
if (cwd && path.toLowerCase().startsWith(cwd.toLowerCase())) {
20-
const relativePath = path.substring(cwd.length)
21-
return "@" + (relativePath.startsWith("/") ? relativePath : "/" + relativePath)
22-
}
23-
return path
24-
}),
25-
}))
26-
2716
// Get the mocked postMessage function
2817
const mockPostMessage = vscode.postMessage as jest.Mock
29-
const mockConvertToMentionPath = pathMentions.convertToMentionPath as jest.Mock
18+
19+
// Spy on convertToMentionPath instead of mocking it
20+
const mockConvertToMentionPath = jest.spyOn(pathMentions, "convertToMentionPath")
3021

3122
// Mock ExtensionStateContext
3223
jest.mock("../../../context/ExtensionStateContext")

0 commit comments

Comments
 (0)