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 RecipeStepAllocationEditor from "./RecipeStepAllocationEditor.vue"; describe("allocation intent editor", () => { test("does not change legacy quantities on mount and never infers scale activation", () => { const wrapper = mount(RecipeStepAllocationEditor, { props: { modelValue: { referenceId: "flour", quantity: null } }, global: { plugins: [createVuetify({ components, directives })] }, }); expect(wrapper.findComponent(components.VSelect).props("modelValue")).toBe("full"); expect(wrapper.emitted("update:modelValue")).toBeUndefined(); }); test("selects unknown safely and retains the association identity", async () => { const wrapper = mount(RecipeStepAllocationEditor, { props: { modelValue: { allocationId: "allocation", referenceId: "flour", quantity: 20, weighing: "weigh" } }, global: { plugins: [createVuetify({ components, directives })] }, }); await wrapper.findComponent(components.VSelect).vm.$emit("update:modelValue", "unknown"); expect(wrapper.emitted("update:modelValue")?.at(-1)).toEqual([{ allocationId: "allocation", referenceId: "flour", quantity: 0, quantityKind: "unknown", weighing: "unspecified", }]); }); test("edits partial portions and weighing independently", async () => { const wrapper = mount(RecipeStepAllocationEditor, { props: { modelValue: { allocationId: "allocation", referenceId: "flour", quantityKind: "partial", quantity: 0 } }, global: { plugins: [createVuetify({ components, directives })] }, }); await wrapper.findComponent(components.VNumberInput).vm.$emit("update:modelValue", 0.5); expect(wrapper.emitted("update:modelValue")?.at(-1)?.[0]).toMatchObject({ quantity: 0.5, quantityKind: "partial" }); const weighing = wrapper.findAllComponents(components.VSelect)[1]!; await weighing.vm.$emit("update:modelValue", "manual"); expect(wrapper.emitted("update:modelValue")?.at(-1)?.[0]).toMatchObject({ quantity: 0, weighing: "manual" }); }); test("requires a portion to be entered when an unknown amount is changed to partial", async () => { const wrapper = mount(RecipeStepAllocationEditor, { props: { modelValue: { referenceId: "flour", quantityKind: "unknown", quantity: 0 } }, global: { plugins: [createVuetify({ components, directives })] }, }); await wrapper.findComponent(components.VSelect).vm.$emit("update:modelValue", "partial"); expect(wrapper.emitted("update:modelValue")?.at(-1)?.[0]).toMatchObject({ quantityKind: "partial", quantity: null }); }); });