mirror of
https://github.com/hay-kot/mealie.git
synced 2025-08-22 14:33:33 -07:00
updated ingredient display tests
This commit is contained in:
parent
3b82acb390
commit
b8a8128ecc
1 changed files with 20 additions and 26 deletions
|
@ -145,6 +145,11 @@ from mealie.schema.recipe.recipe_ingredient import (
|
|||
@pytest.mark.parametrize(
|
||||
["food", "expected_food_singular_string", "expected_food_plural_string"],
|
||||
[
|
||||
[
|
||||
None,
|
||||
"",
|
||||
"",
|
||||
],
|
||||
[
|
||||
IngredientFood(id=uuid4(), name="chopped onion", plural_name=None),
|
||||
"chopped onion",
|
||||
|
@ -157,16 +162,14 @@ from mealie.schema.recipe.recipe_ingredient import (
|
|||
],
|
||||
],
|
||||
)
|
||||
@pytest.mark.parametrize("note", ["very thin", ""])
|
||||
@pytest.mark.parametrize("use_food", [True, False])
|
||||
@pytest.mark.parametrize("note", ["very thin", "", None])
|
||||
def test_ingredient_display(
|
||||
quantity: float | None,
|
||||
quantity_display_decimal: str,
|
||||
quantity_display_fraction: str,
|
||||
unit: IngredientUnit | None,
|
||||
food: IngredientFood,
|
||||
note: str,
|
||||
use_food: bool,
|
||||
food: IngredientFood | None,
|
||||
note: str | None,
|
||||
expect_display_fraction: bool,
|
||||
expect_plural_unit: bool,
|
||||
expect_plural_food: bool,
|
||||
|
@ -176,34 +179,25 @@ def test_ingredient_display(
|
|||
expected_food_plural_string: str,
|
||||
):
|
||||
expected_components = []
|
||||
if use_food:
|
||||
if expect_display_fraction:
|
||||
expected_components.append(quantity_display_fraction)
|
||||
if expect_display_fraction:
|
||||
expected_components.append(quantity_display_fraction)
|
||||
else:
|
||||
expected_components.append(quantity_display_decimal)
|
||||
|
||||
if quantity:
|
||||
if expect_plural_unit:
|
||||
expected_components.append(expected_unit_plural_string)
|
||||
else:
|
||||
expected_components.append(quantity_display_decimal)
|
||||
|
||||
if quantity:
|
||||
if expect_plural_unit:
|
||||
expected_components.append(expected_unit_plural_string)
|
||||
else:
|
||||
expected_components.append(expected_unit_singular_string)
|
||||
expected_components.append(expected_unit_singular_string)
|
||||
|
||||
if food:
|
||||
if expect_plural_food:
|
||||
expected_components.append(expected_food_plural_string)
|
||||
else:
|
||||
expected_components.append(expected_food_singular_string)
|
||||
|
||||
expected_components.append(note)
|
||||
|
||||
else:
|
||||
if quantity != 0 and quantity != 1:
|
||||
if expect_display_fraction:
|
||||
expected_components.append(quantity_display_fraction)
|
||||
else:
|
||||
expected_components.append(quantity_display_decimal)
|
||||
|
||||
expected_components.append(note)
|
||||
expected_components.append(note or "")
|
||||
|
||||
expected_display_value = " ".join(c for c in expected_components if c)
|
||||
ingredient = RecipeIngredient(quantity=quantity, unit=unit, food=food, note=note, use_food=use_food)
|
||||
ingredient = RecipeIngredient(quantity=quantity, unit=unit, food=food, note=note)
|
||||
assert ingredient.display == expected_display_value
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue