frontend
This commit is contained in:
@@ -0,0 +1,23 @@
|
||||
import { test } from 'node:test';
|
||||
import assert from 'node:assert/strict';
|
||||
import { shoppingList, quantityLabel } from '../src/shopping.ts';
|
||||
test('weekly totals include repeated recipes and compatible quantities only',()=>{
|
||||
const recipes=[{id:'a',name:'A',ingredients:'150 g de arroz\n1 ovo\n½ abacate\nSal\n1 colher de sopa de azeite'},{id:'b',name:'B',ingredients:'0,5 kg de arroz\n2 ovos\n1/2 abacate\nSal\n20 ml de azeite'}];
|
||||
const entries=[{slot:'week',recipeId:'a'},{slot:'week',recipeId:'a'},{slot:'week',recipeId:'b'},{slot:'other',recipeId:'b'}];
|
||||
const rows=shoppingList(recipes,entries,['week']);
|
||||
assert.equal(rows.find(r=>r.name==='arroz').quantity,800);
|
||||
assert.equal(rows.find(r=>r.name==='ovo').quantity,4);
|
||||
assert.equal(rows.find(r=>r.name==='abacate').quantity,1.5);
|
||||
assert.equal(rows.find(r=>r.name==='Sal').quantity,null);
|
||||
assert.equal(rows.find(r=>r.name==='Sal').occurrences,3);
|
||||
assert.equal(rows.filter(r=>r.name==='azeite').length,2);
|
||||
assert.deepEqual(shoppingList(recipes,entries,['empty']),[]);
|
||||
});
|
||||
test('fractions, unit conversions, ambiguous quantities and line breaks',()=>{
|
||||
const rows=shoppingList([{id:'r',name:'Receita',ingredients:'1½ l de água\r\n250ml de água\n1 1/2 kg de farinha\n500 g de farinha\n1 a 2 ovos\n1/0 ovos\n\n- 2 bananas'}],[{slot:'s',recipeId:'r'}],['s']);
|
||||
assert.equal(rows.find(r=>r.name==='água').quantity,1750);
|
||||
assert.equal(quantityLabel(rows.find(r=>r.name==='farinha')),'2 kg');
|
||||
assert.equal(rows.find(r=>r.name==='1 a 2 ovos').quantity,null);
|
||||
assert.equal(rows.find(r=>r.name==='1/0 ovos').quantity,null);
|
||||
assert.equal(rows.find(r=>r.name==='banana').quantity,2);
|
||||
});
|
||||
Reference in New Issue
Block a user