Skip to content

Commit 1f35a23

Browse files
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>
1 parent cf00325 commit 1f35a23

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

frontend/composables/recipes/use-recipe-ingredients.test.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,4 +118,14 @@ describe(parseIngredientText.name, () => {
118118

119119
expect(parseIngredientText(ingredient, false)).toEqual("diced onions");
120120
});
121+
122+
test("plural test : single qty, scaled", () => {
123+
const ingredient = createRecipeIngredient({
124+
quantity: 1,
125+
unit: { id: "1", name: "tablespoon", pluralName: "tablespoons", abbreviation: "tbsp", pluralAbbreviation: "tbsps", useAbbreviation: false },
126+
food: { id: "1", name: "diced onion", pluralName: "diced onions" }
127+
});
128+
129+
expect(parseIngredientText(ingredient, false, 2)).toEqual("2 tablespoons diced onions");
130+
});
121131
});

frontend/composables/recipes/use-recipe-ingredients.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,8 @@ export function useParsedIngredientText(ingredient: RecipeIngredient, disableAmo
4646
}
4747

4848
const { quantity, food, unit, note } = ingredient;
49-
const usePluralUnit = quantity !== undefined && quantity > 1;
50-
const usePluralFood = (!quantity) || quantity > 1
49+
const usePluralUnit = quantity !== undefined && (quantity * scale > 1 || quantity * scale === 0);
50+
const usePluralFood = (!quantity) || quantity * scale > 1
5151

5252
let returnQty = "";
5353

0 commit comments

Comments
 (0)