Skip to content

Commit

Permalink
add/update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
michael-genson committed May 11, 2024
1 parent d9d7a48 commit 741c221
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 5 deletions.
10 changes: 8 additions & 2 deletions frontend/composables/recipes/use-recipe-ingredients.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { describe, test, expect } from "vitest";
import { parseIngredientText } from "./use-recipe-ingredients";
import { describe, expect, test } from "vitest";
import { RecipeIngredient } from "~/lib/api/types/recipe";
import { parseIngredientText } from "./use-recipe-ingredients";

Check failure on line 3 in frontend/composables/recipes/use-recipe-ingredients.test.ts

View workflow job for this annotation

GitHub Actions / Frontend and End-to-End Tests / lint

`./use-recipe-ingredients` import should occur before import of `~/lib/api/types/recipe`

describe(parseIngredientText.name, () => {
const createRecipeIngredient = (overrides: Partial<RecipeIngredient>): RecipeIngredient => ({
Expand Down Expand Up @@ -34,6 +34,12 @@ describe(parseIngredientText.name, () => {
expect(parseIngredientText(ingredient, false, 1, true)).contain("1 <sup>1</sup>").and.to.contain("<sub>2</sub>");
});

test("ingredient text with fraction when unit is null", () => {
const ingredient = createRecipeIngredient({ quantity: 1.5, unit: undefined });

expect(parseIngredientText(ingredient, false, 1, true)).contain("1 <sup>1</sup>").and.to.contain("<sub>2</sub>");
});

test("ingredient text with fraction no formatting", () => {
const ingredient = createRecipeIngredient({ quantity: 1.5, unit: { fraction: true, id: "1", name: "cup" } });
const result = parseIngredientText(ingredient, false, 1, false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@

import pytest

from mealie.schema.recipe.recipe_ingredient import IngredientFood, IngredientUnit, RecipeIngredient
from tests.utils.factories import random_string
from mealie.schema.recipe.recipe_ingredient import (
IngredientFood,
IngredientUnit,
RecipeIngredient,
)


@pytest.mark.parametrize(
Expand All @@ -19,6 +22,12 @@
@pytest.mark.parametrize(
["unit", "expect_display_fraction", "expected_unit_singular_string", "expected_unit_plural_string"],
[
[
None,
True,
"",
"",
],
[
IngredientUnit(
id=uuid4(),
Expand Down Expand Up @@ -154,7 +163,7 @@ def test_ingredient_display(
quantity: float | None,
quantity_display_decimal: str,
quantity_display_fraction: str,
unit: IngredientUnit,
unit: IngredientUnit | None,
food: IngredientFood,
note: str,
use_food: bool,
Expand Down

0 comments on commit 741c221

Please sign in to comment.