mirror of
https://github.com/sourcebot-dev/sourcebot.git
synced 2025-12-12 04:15:30 +00:00
40 lines
1.3 KiB
TypeScript
40 lines
1.3 KiB
TypeScript
import { expect, test } from 'vitest'
|
|
import { renderHook } from '@testing-library/react';
|
|
import { useExtractReferences } from './useExtractReferences';
|
|
import { getFileReferenceId } from './utils';
|
|
import { TextUIPart } from 'ai';
|
|
|
|
test('useExtractReferences extracts file references from text content', () => {
|
|
const part: TextUIPart = {
|
|
type: 'text',
|
|
text: 'The auth flow is implemented in @file:{github.com/sourcebot-dev/sourcebot::auth.ts} and uses sessions @file:{github.com/sourcebot-dev/sourcebot::auth.ts:45-60}.'
|
|
}
|
|
|
|
const { result } = renderHook(() => useExtractReferences(part));
|
|
|
|
expect(result.current).toHaveLength(2);
|
|
expect(result.current[0]).toMatchObject({
|
|
repo: 'github.com/sourcebot-dev/sourcebot',
|
|
path: 'auth.ts',
|
|
id: getFileReferenceId({ repo: 'github.com/sourcebot-dev/sourcebot', path: 'auth.ts' }),
|
|
type: 'file',
|
|
});
|
|
|
|
expect(result.current[1]).toMatchObject({
|
|
repo: 'github.com/sourcebot-dev/sourcebot',
|
|
path: 'auth.ts',
|
|
id: getFileReferenceId({
|
|
repo: 'github.com/sourcebot-dev/sourcebot',
|
|
path: 'auth.ts',
|
|
range: {
|
|
startLine: 45,
|
|
endLine: 60,
|
|
}
|
|
}),
|
|
type: 'file',
|
|
range: {
|
|
startLine: 45,
|
|
endLine: 60,
|
|
}
|
|
});
|
|
});
|