2025-03-24 09:50:27 +08:00
|
|
|
import { AiLocateElement, AiLocateSection } from '@/ai-model';
|
2025-03-07 17:20:18 +08:00
|
|
|
import { getContextFromFixture } from 'tests/evaluation';
|
2025-04-30 16:07:31 +08:00
|
|
|
import { expect, test, vi } from 'vitest';
|
|
|
|
|
|
|
|
vi.setConfig({
|
|
|
|
testTimeout: 60 * 1000,
|
|
|
|
});
|
2025-02-10 16:36:12 +08:00
|
|
|
|
|
|
|
test(
|
|
|
|
'basic inspect',
|
|
|
|
async () => {
|
|
|
|
const { context } = await getContextFromFixture('todo');
|
|
|
|
|
|
|
|
const startTime = Date.now();
|
2025-03-17 19:19:54 +08:00
|
|
|
const { parseResult } = await AiLocateElement({
|
2025-02-10 16:36:12 +08:00
|
|
|
context,
|
|
|
|
targetElementDescription: 'input 输入框',
|
|
|
|
});
|
|
|
|
console.log('parseResult', JSON.stringify(parseResult, null, 2));
|
|
|
|
const endTime = Date.now();
|
|
|
|
const cost = endTime - startTime;
|
|
|
|
expect(parseResult.elements.length).toBe(1);
|
|
|
|
},
|
|
|
|
{
|
|
|
|
timeout: 1000000,
|
|
|
|
},
|
|
|
|
);
|
|
|
|
|
2025-03-24 09:50:27 +08:00
|
|
|
test('locate section', async () => {
|
|
|
|
const { context } = await getContextFromFixture('todo');
|
|
|
|
const { rect } = await AiLocateSection({
|
|
|
|
context,
|
|
|
|
sectionDescription: '搜索框',
|
|
|
|
});
|
|
|
|
expect(rect).toBeDefined();
|
|
|
|
});
|
|
|
|
|
2025-02-10 16:36:12 +08:00
|
|
|
test('use quick answer', async () => {
|
|
|
|
const { context } = await getContextFromFixture('todo');
|
|
|
|
|
|
|
|
const startTime = Date.now();
|
2025-03-17 19:19:54 +08:00
|
|
|
const { parseResult } = await AiLocateElement({
|
2025-02-10 16:36:12 +08:00
|
|
|
context,
|
|
|
|
targetElementDescription: 'never mind',
|
|
|
|
});
|
|
|
|
console.log('parseResult', parseResult);
|
|
|
|
const endTime = Date.now();
|
|
|
|
const cost = endTime - startTime;
|
|
|
|
expect(parseResult.elements.length).toBe(1);
|
|
|
|
expect(cost).toBeLessThan(100);
|
|
|
|
});
|