Skip to content

Commit

Permalink
fix: Scaled Ingredients Not Changing to Plural (mealie-recipes#2726)
Browse files Browse the repository at this point in the history
* 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>
  • Loading branch information
michael-genson and boc-the-git authored Nov 27, 2023
1 parent cf00325 commit 1f35a23
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
10 changes: 10 additions & 0 deletions frontend/composables/recipes/use-recipe-ingredients.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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");
});
});
4 changes: 2 additions & 2 deletions frontend/composables/recipes/use-recipe-ingredients.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = "";

Expand Down

0 comments on commit 1f35a23

Please sign in to comment.