feat: support external and step images with structured cooking instructions
This commit is contained in:
1 parent
361862ad0b
commit
0ec1d45bdb
34 files changed
+898
-92
No files matched your search
@@ -0,0 +1,33 @@
|
||||
import { describe, expect, it } from 'vitest';
|
||||
import { instructionBlocks } from '../../src/lib/instructions';
|
||||
|
||||
describe('Readable plain-text instructions', () => {
|
||||
it('preserves ingredient references, paragraphs and both list forms', () => {
|
||||
expect(
|
||||
instructionBlocks(
|
||||
'Vorbereiten.\r\n\r\n- {{fleisch}} schneiden.\r\n- Salzen.\n\nAnschließend:\n1. Anbraten.\n2) Servieren.',
|
||||
),
|
||||
).toEqual([
|
||||
{ type: 'paragraph', lines: ['Vorbereiten.'] },
|
||||
{ type: 'unordered', lines: ['{{fleisch}} schneiden.', 'Salzen.'] },
|
||||
{ type: 'paragraph', lines: ['Anschließend:'] },
|
||||
{ type: 'ordered', lines: ['Anbraten.', 'Servieren.'] },
|
||||
]);
|
||||
});
|
||||
it('keeps decimal quantities and temperatures intact when splitting legacy text', () => {
|
||||
const text =
|
||||
'Das Fleisch in 1.5 cm große Würfel schneiden und anschließend gründlich trocken tupfen. Die Pfanne auf mittlerer Hitze vorheizen und das Öl darin gleichmäßig verteilen. Das Fleisch vorsichtig hineinlegen und unter gelegentlichem Wenden goldbraun braten. Bei 180 °C im vorgeheizten Ofen fertig garen und anschließend servieren.';
|
||||
const blocks = instructionBlocks(text);
|
||||
expect(blocks.length).toBeGreaterThan(1);
|
||||
expect(blocks.flatMap((b) => b.lines).join(' ')).toBe(text);
|
||||
});
|
||||
it('leaves short prose, explicit line breaks and literal HTML as text', () => {
|
||||
expect(instructionBlocks('Bei 180 °C garen.')).toEqual([
|
||||
{ type: 'paragraph', lines: ['Bei 180 °C garen.'] },
|
||||
]);
|
||||
expect(instructionBlocks('<script>test</script>\nFertig.')).toEqual([
|
||||
{ type: 'paragraph', lines: ['<script>test</script>'] },
|
||||
{ type: 'paragraph', lines: ['Fertig.'] },
|
||||
]);
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user