import { mount } from "@vue/test-utils"; import { describe, expect, test, vi } from "vitest"; import RecipePrintView from "./RecipePrintView.vue"; import { makeRecipe } from "~/tests/factories"; vi.mock("~/composables/api", () => ({ useStaticRoutes: () => ({ recipeImage: () => "" }), })); vi.mock("~/composables/use-locales", () => ({ useLocales: () => ({ locales: [{ value: "en-US" }], locale: { value: "en-US" } }), })); describe("RecipePrintView", () => { test.each([true, false])("renders settings with their step and only labels reverse rotation: %s", (reverse) => { const recipe = makeRecipe({ recipeIngredient: [{ referenceId: "ingredient", quantity: 100, food: { name: "flour" } }], recipeInstructions: [ { text: "Mix", durationSeconds: 180, cooking: { temperatureCelsius: 120, speed: "spoon", reverse } }, { text: "Rest" }, ], }); const wrapper = mount(RecipePrintView, { props: { recipe }, global: { mocks: { $globals: { icons: { primary: "", potSteam: "" } } }, stubs: { SafeMarkdown: { props: ["source"], template: "
{{ source }}
" }, SafeInlineHtml: { props: ["html"], template: "{{ html }}" }, RecipeTimeCard: true, }, }, }); expect(wrapper.find(".ingredient-cell").text()).toContain("flour"); expect(wrapper.find(".ingredient-cell").text()).not.toContain("120"); const steps = wrapper.findAll(".recipe-step-body"); expect(steps).toHaveLength(2); expect(steps[0].element.parentElement?.textContent).toContain("120 °C"); expect(steps[0].element.parentElement?.textContent?.includes("Reverse rotation")).toBe(reverse); expect(wrapper.text()).not.toContain("Forward rotation"); expect(steps[0].element.parentElement?.textContent).toContain("3m"); expect(steps[1].element.parentElement?.textContent).not.toContain("120 °C"); expect(steps[1].element.parentElement?.textContent).not.toContain("Reverse rotation"); }); test("prints fractional pulses, ranges, accessories and allocation intent without scaling operation settings", () => { const recipe = makeRecipe({ recipeIngredient: [{ referenceId: "flour", quantity: 100, food: { name: "flour" } }], recipeInstructions: [{ text: "Check consistency", durationSeconds: 0.5, ingredientReferences: [{ referenceId: "flour", quantityKind: "unknown", quantity: 0, weighing: "manual", destination: "bowl" }], cooking: { durationRangeSeconds: { minimum: 0.5, maximum: 2 }, speedProgression: [1, 3, 5], accessories: [{ name: "lid", state: "open" }], optional: true, condition: "If too coarse", repetitions: 3, modeParameters: [{ name: "thickness", kind: "text", value: "coarse" }], }, }], }); const wrapper = mount(RecipePrintView, { props: { recipe, scale: 2 }, global: { mocks: { $globals: { icons: { primary: "", potSteam: "" } } }, stubs: { SafeMarkdown: true, SafeInlineHtml: true, RecipeTimeCard: true }, }, }); expect(wrapper.text()).toContain("0.5s"); expect(wrapper.text()).toContain("0.5–2 s"); expect(wrapper.text()).toContain("1 → 3 → 5"); expect(wrapper.text()).toContain("lid: Open"); expect(wrapper.text()).toContain("Unknown amount"); expect(wrapper.text()).toContain("If too coarse"); expect(recipe.recipeIngredient[0]!.quantity).toBe(100); expect(recipe.recipeInstructions[0]!.ingredientReferences![0]!.quantity).toBe(0); }); });