Add portion controls and improve recipe display

This commit is contained in:
2026-08-03 15:45:34 -05:00
parent 139eb9bca2
commit f94b08a4e6
10 changed files with 276 additions and 28 deletions
+28
View File
@@ -0,0 +1,28 @@
const test = require("node:test");
const assert = require("node:assert/strict");
const { parseYield, scaleIngredient, scaleRecipe } = require("../lib/recipe-scaler");
test("extracts the number of portions from a recipe yield", () => {
assert.equal(parseYield("6 servings"), 6);
assert.equal(parseYield(4), 4);
assert.equal(parseYield("as needed"), null);
});
test("scales leading whole, fractional, and mixed quantities", () => {
assert.equal(scaleIngredient("2 cups oats", 2), "4 cups oats");
assert.equal(scaleIngredient("½ cup milk", 2), "1 cup milk");
assert.equal(scaleIngredient("1 1/2 tsp salt", 2), "3 tsp salt");
assert.equal(scaleIngredient("Salt to taste", 2), "Salt to taste");
});
test("returns a scaled copy of a recipe", () => {
const original = {
name: "Oatmeal Cups",
recipeYield: "6 servings",
recipeIngredient: ["2 cups oats", "Salt to taste"]
};
const scaled = scaleRecipe(original, 9);
assert.equal(scaled.recipeYield, "9 servings");
assert.deepEqual(scaled.recipeIngredient, ["3 cups oats", "Salt to taste"]);
assert.equal(original.recipeYield, "6 servings");
});