import { mount } from "@vue/test-utils"; import { describe, expect, test } from "vitest"; import { createVuetify } from "vuetify"; import * as components from "vuetify/components"; import * as directives from "vuetify/directives"; import RecipeStepCooking from "./RecipeStepCooking.vue"; describe("RecipeStepCooking", () => { test("displays numeric and named settings", () => { const wrapper = mount(RecipeStepCooking, { props: { modelValue: { appliance: "thermomix", temperatureCelsius: 120, speed: "spoon", mode: "steaming" } }, }); expect(wrapper.text()).toContain("120 °C"); expect(wrapper.text()).toContain("Speed: spoon"); expect(wrapper.text()).toContain("steaming"); }); test("edits whole degrees without replacing an imported fraction on focus and blur", async () => { const wrapper = mount(RecipeStepCooking, { props: { modelValue: { temperatureCelsius: 37.5 }, edit: true }, global: { plugins: [createVuetify({ components, directives })] }, }); const field = wrapper.findComponent(components.VNumberInput); const input = field.find("input"); expect(field.props("precision")).toBe(0); expect(field.props("step")).toBe(1); expect(input.element.value).toBe("38"); expect(wrapper.text()).toContain("37.5 °C"); await input.trigger("focus"); await input.trigger("blur"); expect(wrapper.emitted("update:modelValue")).toBeUndefined(); await input.setValue("39"); expect(wrapper.emitted("update:modelValue")?.at(-1)).toEqual([{ temperatureCelsius: 39 }]); }); test.each([true, false, null, undefined])("only displays reverse rotation: %s", (reverse) => { const wrapper = mount(RecipeStepCooking, { props: { modelValue: { speed: 2, reverse } } }); expect(wrapper.text().includes("Reverse rotation")).toBe(reverse === true); expect(wrapper.text()).not.toContain("Forward rotation"); expect(wrapper.text()).toContain("Speed: 2"); }); test("does not render a settings row for forward rotation alone", () => { const wrapper = mount(RecipeStepCooking, { props: { modelValue: { reverse: false } } }); expect(wrapper.find(".text-body-2").exists()).toBe(false); }); test("edits and clears direction while preserving other cooking settings", async () => { const wrapper = mount(RecipeStepCooking, { props: { modelValue: { speed: 2, reverse: true }, edit: true }, global: { plugins: [createVuetify({ components, directives })] }, }); const field = wrapper.findComponent(components.VSelect); await field.vm.$emit("update:modelValue", false); expect(wrapper.emitted("update:modelValue")?.at(-1)).toEqual([{ speed: 2, reverse: false }]); await field.vm.$emit("update:modelValue", null); expect(wrapper.emitted("update:modelValue")?.at(-1)).toEqual([{ speed: 2, reverse: null }]); }); });