kimi-code / apps /vscode /test /webview /mention-insert.test.ts
SaylorTwift's picture
SaylorTwift HF Staff
Add files using upload-large-folder tool
5710dd0 verified
Raw History Blame Contribute Delete
1.57 kB
import { describe, expect, it } from 'vitest';
import { computeMentionInsert } from '@/components/inputarea/utils';
describe('computeMentionInsert', () => {
it('replaces the active token with the mention and moves the cursor past it', () => {
const result = computeMentionInsert({
text: 'check @ap',
cursorPos: 9,
filePath: 'src/app.ts',
activeToken: { start: 6 },
isAppend: false,
});
expect(result.newText).toBe('check @src/app.ts ');
expect(result.newCursorPos).toBe(result.newText.length);
});
it('appends the mention when there is no active token', () => {
const result = computeMentionInsert({
text: 'hi ',
cursorPos: 3,
filePath: 'a.ts',
activeToken: null,
isAppend: true,
});
expect(result.newText).toBe('hi @a.ts ');
expect(result.newCursorPos).toBe(result.newText.length);
});
it('quotes a path containing spaces so whitespace cannot split the mention', () => {
const result = computeMentionInsert({
text: '@my',
cursorPos: 3,
filePath: 'My Folder/app.ts',
activeToken: { start: 0 },
isAppend: false,
});
expect(result.newText).toBe('@"My Folder/app.ts" ');
expect(result.newCursorPos).toBe(result.newText.length);
});
it('quotes a path containing spaces in append mode', () => {
const result = computeMentionInsert({
text: '',
cursorPos: 0,
filePath: 'My Folder',
activeToken: null,
isAppend: true,
});
expect(result.newText).toBe('@"My Folder" ');
});
});