feat: synchronize recipe completion controls

Fixes #5\nRefs #1, #2
This commit is contained in:
2026-08-14 13:28:57 -05:00
parent b61ca70bed
commit 6f28f83f4a
10 changed files with 334 additions and 29 deletions
+25
View File
@@ -0,0 +1,25 @@
const test = require("node:test");
const assert = require("node:assert/strict");
const { flattenInstructions, updateProgress } = require("../lib/recipe-progress");
const recipe = {
recipeIngredient: ["1 cup flour", "1 egg"],
recipeInstructions: ["Mix", { itemListElement: [{ text: "Bake" }] }]
};
test("flattens nested recipe instructions", () => {
assert.deepEqual(flattenInstructions(recipe.recipeInstructions), ["Mix", "Bake"]);
});
test("updates and validates cooking progress", () => {
const ingredientProgress = updateProgress(recipe, {}, {
kind: "ingredient", index: 1, completed: true
});
assert.deepEqual(ingredientProgress, { completedIngredients: [1], completedSteps: [] });
assert.deepEqual(updateProgress(recipe, ingredientProgress, {
kind: "ingredient", index: 1, completed: false
}), { completedIngredients: [], completedSteps: [] });
assert.throws(() => updateProgress(recipe, {}, {
kind: "step", index: 2, completed: true
}), /does not exist/);
});