File size: 1,568 Bytes
5710dd0 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 | 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" ');
});
});
|