Skip to content

Commit

Permalink
Fixed ingredients units and quantities being presented as "null".
Browse files Browse the repository at this point in the history
  • Loading branch information
Hugo1307 committed Dec 3, 2023
1 parent 0784b45 commit c75cbfe
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
11 changes: 10 additions & 1 deletion src/components/Recipes/Ingredients/RecipeIngredient.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,16 @@ export default function RecipeIngredient({ ingredient }) {
{ingredient.food}
</h3>
<p className="text-blue-500 font-bold">
<span className="text-blue-500">{`${ingredient.quantity} ${ingredient.measure}`}</span>
<span className="text-blue-500">
{ingredient.quantity > 0
? parseFloat(ingredient.quantity).toFixed(1) + " "
: null}
</span>
<span className="text-blue-500">
{ingredient.measure !== "null" && ingredient.measure !== "<unit>"
? ingredient.measure
: null}
</span>
<span className="text-gray-500 ms-1">{`(${Math.round(
ingredient.weight,
)} g)`}</span>
Expand Down
4 changes: 3 additions & 1 deletion src/components/Recipes/Ingredients/RecipeIngredient.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,10 @@ describe("RecipeIngredient component", () => {
text: "A fresh apple",
};
render(<RecipeIngredient ingredient={ingredient} />);
const quantityMeasureElement = screen.getByText(/1 piece/i);
const quantityMeasureElement = screen.getAllByText(/1.0/i)[0];
const unitMeasureElement = screen.getByText(/piece/i);
expect(quantityMeasureElement).toBeInTheDocument();
expect(unitMeasureElement).toBeInTheDocument();
});

it("renders the ingredient weight correctly", () => {
Expand Down

0 comments on commit c75cbfe

Please sign in to comment.