Skip to content

Commit

Permalink
Fixed failing tests
Browse files Browse the repository at this point in the history
  • Loading branch information
pkirilin committed Dec 2, 2023
1 parent e439c17 commit 9314b58
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 27 deletions.
4 changes: 2 additions & 2 deletions src/frontend/src/features/notes/components/MealsList.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import React from 'react';
import { Meals } from '../models';
import { getMealTypes } from '../models';
import MealsListItem from './MealsListItem';

const MealsList: React.FC = () => {
return (
<React.Fragment>
{Meals.get().map((mealType, index) => (
{getMealTypes().map((mealType, index) => (
<MealsListItem key={index} mealType={mealType} />
))}
</React.Fragment>
Expand Down
4 changes: 2 additions & 2 deletions src/frontend/src/features/notes/components/MealsListItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import ExpandMoreIcon from '@mui/icons-material/ExpandMore';
import { Accordion, AccordionDetails, AccordionSummary, Typography } from '@mui/material';
import type React from 'react';
import { useMemo, useState } from 'react';
import { Meals, type MealType } from '../models';
import { getMealName, type MealType } from '../models';
import NotesTable from './NotesTable';

interface MealsListItemProps {
Expand All @@ -11,7 +11,7 @@ interface MealsListItemProps {

const MealsListItem: React.FC<MealsListItemProps> = ({ mealType }: MealsListItemProps) => {
const [expanded, setExpanded] = useState(true);
const mealName = useMemo(() => Meals.getName(mealType), [mealType]);
const mealName = useMemo(() => getMealName(mealType), [mealType]);

const handleAccordionChange = (): void => {
setExpanded(!expanded);
Expand Down
21 changes: 0 additions & 21 deletions src/frontend/src/features/notes/meals.ts

This file was deleted.

22 changes: 20 additions & 2 deletions src/frontend/src/features/notes/models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,26 @@ export enum MealType {
Dinner = 5,
}

const AVAILABLE_MEALS: Map<MealType, string> = new Map<MealType, string>([
[MealType.Breakfast, 'Breakfast'],
[MealType.SecondBreakfast, 'Second breakfast'],
[MealType.Lunch, 'Lunch'],
[MealType.AfternoonSnack, 'Afternoon snack'],
[MealType.Dinner, 'Dinner'],
]);

export const getMealTypes = (): MealType[] => Array.from(AVAILABLE_MEALS.keys());

export const getMealName = (mealType: MealType): string => {
const mealName = AVAILABLE_MEALS.get(mealType);

if (!mealName) {
throw new Error(`Meal type = '${mealType}' doesn't exist`);
}

return mealName;
};

export interface NoteItem {
id: number;
mealType: MealType;
Expand All @@ -23,5 +43,3 @@ export interface NoteCreateEdit {
productQuantity: number;
displayOrder: number;
}

export * as Meals from './meals';

0 comments on commit 9314b58

Please sign in to comment.