57 lines
2.2 KiB
TypeScript
57 lines
2.2 KiB
TypeScript
import { VOICE_SPLIT_EXAMPLES } from '@superlist/shared'
|
|
import { describe, expect, it } from 'vitest'
|
|
|
|
import { parseItemInput } from './parse-item'
|
|
import { parseQuantity } from './quantity'
|
|
|
|
/**
|
|
* The dictation examples the API shows the model (`@superlist/shared` → voice.ts) must be
|
|
* written exactly the way this parser reads them: each string is one item with the
|
|
* expected quantity, unit and note.
|
|
*/
|
|
const EXPECTED: Record<
|
|
string,
|
|
{ name: string; amount: number | null; unit: string | null; notes: string | null }
|
|
> = {
|
|
'2 pascualinas': { name: 'Pascualinas', amount: 2, unit: null, notes: null },
|
|
'1,5 kg de papas': { name: 'Papas', amount: 1.5, unit: 'kg', notes: null },
|
|
'400 de jamon. Feteado fino': { name: 'Jamón', amount: 400, unit: null, notes: 'Feteado fino' },
|
|
'1 lata de atun': { name: 'Atún', amount: 1, unit: 'lata', notes: null },
|
|
'Queso crema. Solo si hay marca Tregar': {
|
|
name: 'Queso crema',
|
|
amount: null,
|
|
unit: null,
|
|
notes: 'Solo si hay marca Tregar',
|
|
},
|
|
'6 unidades de yogur': { name: 'Yogur', amount: 6, unit: null, notes: null },
|
|
'400g de queso': { name: 'Queso', amount: 400, unit: 'g', notes: null },
|
|
'Leche (descremada)': { name: 'Leche', amount: null, unit: null, notes: 'Descremada' },
|
|
Azúcar: { name: 'Azúcar', amount: null, unit: null, notes: null },
|
|
Leche: { name: 'Leche', amount: null, unit: null, notes: null },
|
|
Café: { name: 'Café', amount: null, unit: null, notes: null },
|
|
}
|
|
|
|
describe('dictation few-shot examples', () => {
|
|
const items = VOICE_SPLIT_EXAMPLES.flatMap((example) => example.items)
|
|
|
|
it('has an expectation for every example item', () => {
|
|
expect([...items].sort()).toEqual(Object.keys(EXPECTED).sort())
|
|
})
|
|
|
|
it.each(items)('parses "%s" as one item with the expected quantity and note', (text) => {
|
|
const parsed = parseItemInput(text)
|
|
expect(parsed).toHaveLength(1)
|
|
|
|
const [item] = parsed
|
|
const quantity = item.quantity ? parseQuantity(item.quantity) : null
|
|
const expected = EXPECTED[text]
|
|
|
|
expect({
|
|
name: item.name,
|
|
amount: quantity?.amount ?? null,
|
|
unit: quantity?.unit ?? null,
|
|
notes: item.notes,
|
|
}).toEqual(expected)
|
|
})
|
|
})
|