From 1f35a23bfa16ec32006e81012ada7d914f23552d Mon Sep 17 00:00:00 2001 From: Michael Genson <71845777+michael-genson@users.noreply.github.com> Date: Mon, 27 Nov 2023 10:58:18 -0600 Subject: [PATCH] fix: Scaled Ingredients Not Changing to Plural (#2726) * fixed food/unit not updating to plural when scaled * added test * fixed weird edgecase that appears only after edits --------- Co-authored-by: boc-the-git <3479092+boc-the-git@users.noreply.github.com> --- .../composables/recipes/use-recipe-ingredients.test.ts | 10 ++++++++++ frontend/composables/recipes/use-recipe-ingredients.ts | 4 ++-- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/frontend/composables/recipes/use-recipe-ingredients.test.ts b/frontend/composables/recipes/use-recipe-ingredients.test.ts index 7850dca1d877..73d163e48409 100644 --- a/frontend/composables/recipes/use-recipe-ingredients.test.ts +++ b/frontend/composables/recipes/use-recipe-ingredients.test.ts @@ -118,4 +118,14 @@ describe(parseIngredientText.name, () => { expect(parseIngredientText(ingredient, false)).toEqual("diced onions"); }); + + test("plural test : single qty, scaled", () => { + const ingredient = createRecipeIngredient({ + quantity: 1, + unit: { id: "1", name: "tablespoon", pluralName: "tablespoons", abbreviation: "tbsp", pluralAbbreviation: "tbsps", useAbbreviation: false }, + food: { id: "1", name: "diced onion", pluralName: "diced onions" } + }); + + expect(parseIngredientText(ingredient, false, 2)).toEqual("2 tablespoons diced onions"); + }); }); diff --git a/frontend/composables/recipes/use-recipe-ingredients.ts b/frontend/composables/recipes/use-recipe-ingredients.ts index 6db7f2fe30de..a31872652fa5 100644 --- a/frontend/composables/recipes/use-recipe-ingredients.ts +++ b/frontend/composables/recipes/use-recipe-ingredients.ts @@ -46,8 +46,8 @@ export function useParsedIngredientText(ingredient: RecipeIngredient, disableAmo } const { quantity, food, unit, note } = ingredient; - const usePluralUnit = quantity !== undefined && quantity > 1; - const usePluralFood = (!quantity) || quantity > 1 + const usePluralUnit = quantity !== undefined && (quantity * scale > 1 || quantity * scale === 0); + const usePluralFood = (!quantity) || quantity * scale > 1 let returnQty = "";