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>
This commit is contained in:
Michael Genson 2023-11-27 10:58:18 -06:00 committed by GitHub
parent cf00325c2b
commit 1f35a23bfa
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 2 deletions

View File

@ -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");
});
});

View File

@ -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 = "";