midscene/packages/core/tests/ai/extract/extract.test.ts

44 lines
1.5 KiB
TypeScript
Raw Normal View History

import { AiExtractElementInfo } from '@/ai-model';
import { getContextFromFixture } from 'tests/evaluation';
import { describe, expect, it, vi } from 'vitest';
vi.setConfig({
testTimeout: 180 * 1000,
hookTimeout: 30 * 1000,
});
2025-01-03 21:50:25 +08:00
describe('extract', () => {
it('todo', async () => {
const { context } = await getContextFromFixture('todo-input-with-value');
2025-01-03 21:50:25 +08:00
const { parseResult } = await AiExtractElementInfo({
dataQuery: 'Array<string>, task list, task name as string',
2025-01-03 21:50:25 +08:00
context,
});
expect(parseResult).toBeDefined();
expect((parseResult.data as string[]).length).toBeGreaterThanOrEqual(3);
// expect(parseResult).toMatchSnapshot();
2025-01-03 21:50:25 +08:00
});
2025-01-03 21:50:25 +08:00
it('online order', async () => {
const { context } = await getContextFromFixture('online_order');
2025-01-03 21:50:25 +08:00
const { parseResult } = await AiExtractElementInfo({
dataQuery: '{name: string, price: string}[], 饮品名称和价格',
context,
});
2025-01-03 21:50:25 +08:00
expect(parseResult).toMatchSnapshot();
});
2025-01-03 21:50:25 +08:00
it('todo obj', async () => {
const { context } = await getContextFromFixture('todo-input-with-value');
2025-01-03 21:50:25 +08:00
const { parseResult } = await AiExtractElementInfo({
dataQuery:
'{checked: boolean; text: string;}[], Task list with checkbox ahead of the task name (checkbox is a round box), task name as string and `checked` is true if the task is completed. Exclude the fist row if there is no round checkbox ahead of the task name.',
2025-01-03 21:50:25 +08:00
context,
});
2025-01-03 21:50:25 +08:00
expect(parseResult).toMatchSnapshot();
});
});