fix: graf cena per zdroj nahrazen koláčem

feat: stránka doplnit údaje předělána na samostatnou stránku jídel + přidáno přejmenování
This commit is contained in:
Ondřej Anděl committed 2026-10-12 09:49:41 +02:00
1 parent b880b36edd
commit efed5e6e86
30 files changed
+514 -153

No files matched your search

+54 -1
View File
@@ -1,6 +1,7 @@
process.env.CALORIE_PROVIDER = 'none';
import { addMeal, fillMealGroup, getDay, getMealGroups } from "../meals";
import { addMeal, fillMealGroup, getDay, getMealGroups, renameMealGroup } from "../meals";
import { searchCalories } from "../calories";
import { resetMemoryStorage } from "../storage/memory";
import { MealType } from "../../../types/gen/types.gen";
@@ -118,3 +119,55 @@ describe('hromadné doplnění údajů do skupiny', () => {
expect((await getDay(LOGIN, '2025-03-02')).entries[0].calories).toBeUndefined();
});
});
describe('přejmenování skupiny jídel', () => {
it('přejmenuje a přesune do jiného zdroje všechna jídla skupiny', async () => {
await addMeal(LOGIN, { ...cina, date: '2025-03-01', price: 13900 });
await addMeal(LOGIN, { ...cina, date: '2025-03-02', name: 'cina' });
await addMeal(LOGIN, { ...cina, date: '2025-03-02', source: 'doma' });
const result = await renameMealGroup(LOGIN, 'Čína', 'Chefie', 'Kuře kung-pao', 'Everest');
expect(result).toEqual({ count: 2, dates: ['2025-03-01', '2025-03-02'] });
expect((await getDay(LOGIN, '2025-03-01')).entries[0])
.toMatchObject({ name: 'Kuře kung-pao', source: 'Everest', price: 13900 });
const second = (await getDay(LOGIN, '2025-03-02')).entries;
expect(second.map(entry => `${entry.name}|${entry.source}`).sort())
.toEqual(['Kuře kung-pao|Everest', 'Čína|doma']);
});
it('prázdný zdroj zdroj odebere a jídla se sloučí se skupinou bez zdroje', async () => {
await addMeal(LOGIN, { ...cina, date: '2025-03-01' });
await addMeal(LOGIN, { ...cina, date: '2025-03-02', source: undefined });
await renameMealGroup(LOGIN, 'Čína', 'Chefie', 'Čína', undefined);
const groups = await getMealGroups(LOGIN);
expect(groups).toHaveLength(1);
expect(groups[0].count).toBe(2);
expect((await getDay(LOGIN, '2025-03-01')).entries[0]).not.toHaveProperty('source');
});
it('jídla se shodným zápisem nepočítá', async () => {
await addMeal(LOGIN, { ...cina, date: '2025-03-01' });
await addMeal(LOGIN, { ...cina, date: '2025-03-02', name: 'čína' });
const result = await renameMealGroup(LOGIN, 'Čína', 'Chefie', 'Čína', 'Chefie');
expect(result).toEqual({ count: 1, dates: ['2025-03-02'] });
});
it('energii na 100 g si knihovna zapamatuje i pod novým názvem', async () => {
await addMeal(LOGIN, { ...cina, date: '2025-03-01', weight: 400, caloriesPer100g: 150 });
await renameMealGroup(LOGIN, 'Čína', 'Chefie', 'Kuře kung-pao', 'Chefie');
const { suggestions } = await searchCalories(LOGIN, 'Kuře kung-pao');
expect(suggestions[0]).toMatchObject({ name: 'Kuře kung-pao', caloriesPer100g: 150 });
});
it('odmítne prázdný nový název', async () => {
await expect(renameMealGroup(LOGIN, 'Čína', 'Chefie', ' ', 'Chefie')).rejects.toThrow(/nový název/);
});
});