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/);
});
});
+12
View File
@@ -81,6 +81,16 @@ describe('návrhy jídel z historie', () => {
expect(history.map(item => item.name)).toEqual(['Častější', 'Novější', 'Starší']);
});
it('stejnojmenná jídla z různých zdrojů nabídne zvlášť', async () => {
await addMeal(LOGIN, { ...gyros, source: 'Everest', price: 15900 });
await addMeal(LOGIN, { ...gyros, source: 'Namaste', price: 16900 });
const history = await getMealHistory(LOGIN);
expect(history.map(item => `${item.source}: ${item.price}`).sort())
.toEqual(['Everest: 15900', 'Namaste: 16900']);
});
it('historie je oddělená mezi uživateli', async () => {
await addMeal(LOGIN, gyros);
@@ -181,6 +191,7 @@ describe('doplnění do jídel stejného názvu', () => {
await addMeal(LOGIN, { ...salat, date: '2025-03-01' });
await addMeal(LOGIN, { ...salat, date: '2025-03-02', name: 'těstovinový SALÁT' });
await addMeal(LOGIN, { ...salat, date: '2025-03-02', name: 'Jiné jídlo' });
await addMeal(LOGIN, { ...salat, date: '2025-03-05', source: 'Everest' });
await addMeal(LOGIN, { ...salat, date: '2025-03-04', calories: 300, caloriesPer100g: 120 });
const day = await addMeal(LOGIN, {
...salat, date: DATE, weight: 350, caloriesPer100g: 160, nutrientsPer100g: { protein: 6 },
@@ -207,6 +218,7 @@ describe('doplnění do jídel stejného názvu', () => {
const second = (await getDay(LOGIN, '2025-03-02')).entries;
expect(second.find(entry => entry.name === 'těstovinový SALÁT')?.calories).toBe(560);
expect(second.find(entry => entry.name === 'Jiné jídlo')?.calories).toBeUndefined();
expect((await getDay(LOGIN, '2025-03-05')).entries[0].calories).toBeUndefined();
expect((await getDay(LOGIN, '2025-03-04')).entries[0].calories).toBe(300);
});