Files
mealie/frontend/app/components/Domain/Recipe/RecipeStepOperationDetails.test.ts
T
jfmcarreira 8dad430650
Release Drafter / auto_label (push) Skipped
Release Drafter / draft_release (push) Canceled after 0s
CodeQL / Analyze (javascript-typescript) (push) Canceled after 0s
CodeQL / Analyze (python) (push) Canceled after 0s
Backend Lint and Test / tests (sqlite) (push) Canceled after 0s
Backend Lint and Test / tests (postgres) (push) Canceled after 0s
Docker Nightly Production / Backend Server Tests (push) Canceled after 0s
Frontend Lint and Test / lint (push) Canceled after 0s
Docker Nightly Production / Frontend Tests (push) Canceled after 0s
Build Package / Build frontend and wheel (push) Canceled after 0s
Docker Nightly Production / Build Package (push) Canceled after 0s
Docker Nightly Production / Build E2E Image Cache (push) Canceled after 0s
Docker Nightly Production / Build Tagged Release (push) Canceled after 0s
Docker Nightly Production / Notify Discord (push) Canceled after 0s
feat(recipe): add step quantities and appliance settings
2026-12-01 13:05:50 +00:00

92 lines
5.2 KiB
TypeScript

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 RecipeStepOperationDetails from "./RecipeStepOperationDetails.vue";
import type { StepCooking } from "~/lib/api/types/recipe";
function editor(modelValue: StepCooking = {}) {
return mount(RecipeStepOperationDetails, {
props: { modelValue },
global: { plugins: [createVuetify({ components, directives })] },
});
}
describe("generic operation editor", () => {
test("edits fractional duration bounds without inventing a fixed setting", async () => {
const wrapper = editor({ speed: 2, durationKind: "range" });
const inputs = wrapper.findAllComponents(components.VNumberInput);
await inputs.find(input => input.props("label") === "Minimum duration (seconds)")!.vm.$emit("update:modelValue", 0.5);
expect(wrapper.emitted("update:modelValue")?.at(-1)).toEqual([{
speed: 2, durationKind: "range", durationRangeSeconds: { minimum: 0.5 },
}]);
});
test("preserves progressive speeds and rejects an invalid progression visibly", async () => {
const wrapper = editor({ speed: 1, speedKind: "progression", speedProgression: [1, 3, 5] });
const input = wrapper.findAllComponents(components.VTextField).find(field => field.props("label") === "Speed progression (comma-separated)")!.find("input");
await input.setValue("1, 2.5, 6");
await input.trigger("change");
expect(wrapper.emitted("update:modelValue")?.at(-1)?.[0]).toMatchObject({ speed: 1, speedProgression: [1, 2.5, 6] });
const count = wrapper.emitted("update:modelValue")!.length;
await input.setValue("1, invalid");
await input.trigger("change");
expect(wrapper.emitted("update:modelValue")).toHaveLength(count);
expect(wrapper.text()).toContain("Enter a comma-separated list of numbers.");
});
test("edits accessory state and typed mode parameters without changing other settings", async () => {
const settings: StepCooking = {
appliance: "mixer",
accessories: [{ name: "basket", state: "unknown" }],
modeParameters: [{ name: "pulses", kind: "number", value: 3 }],
};
const wrapper = editor(settings);
const accessory = wrapper.findAllComponents(components.VSelect).find(field => field.props("label") === "State")!;
await accessory.vm.$emit("update:modelValue", "removed");
expect(wrapper.emitted("update:modelValue")?.at(-1)?.[0]).toMatchObject({
accessories: [{ name: "basket", state: "removed" }], modeParameters: settings.modeParameters,
});
const parameter = wrapper.findAllComponents(components.VNumberInput).find(field => field.props("label") === "Value")!;
await parameter.vm.$emit("update:modelValue", 4);
expect(wrapper.emitted("update:modelValue")?.at(-1)?.[0]).toMatchObject({
modeParameters: [{ name: "pulses", kind: "number", value: 4 }], appliance: "mixer",
});
});
test("edits conditions and repeats independently", async () => {
const wrapper = editor({ optional: true, condition: "If too coarse", requiresConfirmation: true });
const repeats = wrapper.findAllComponents(components.VNumberInput).find(field => field.props("label") === "Repetitions")!;
await repeats.vm.$emit("update:modelValue", 3);
expect(wrapper.emitted("update:modelValue")?.at(-1)?.[0]).toMatchObject({
optional: true, condition: "If too coarse", requiresConfirmation: true, repetitions: 3,
});
});
test("explicit parameter type changes clear incompatible values with a visible hint", async () => {
const wrapper = editor({ modeParameters: [{ name: "pulses", kind: "number", value: 3 }] });
const field = wrapper.findAllComponents(components.VSelect).find(input => input.props("label") === "Parameter type")!;
expect(wrapper.text()).toContain("Changing type clears the previous value and bounds.");
await field.vm.$emit("update:modelValue", "range");
expect(wrapper.emitted("update:modelValue")?.at(-1)?.[0]).toMatchObject({
modeParameters: [{ name: "pulses", kind: "range", value: null, minimum: null, maximum: null }],
});
});
test("exposes review candidates, provenance and an explicit resolution", async () => {
const wrapper = editor({
reviews: [{ id: "review", category: "ingredient", source: "some flour", reason: "Unknown portion", candidateIngredientIds: ["flour"], status: "unresolved" }],
});
await wrapper.setProps({ ingredients: [{ referenceId: "flour", quantity: 100, note: "flour" }] });
const link = wrapper.findAllComponents(components.VSelect).find(field => field.props("label") === "Link a candidate ingredient (unknown amount)")!;
await link.vm.$emit("update:modelValue", "flour");
expect(wrapper.emitted("linkIngredient")).toEqual([["flour"]]);
const resolution = wrapper.findAllComponents(components.VTextField).find(field => field.props("label") === "Resolution")!;
await resolution.vm.$emit("update:modelValue", "Confirmed manual addition");
expect(wrapper.emitted("update:modelValue")?.at(-1)?.[0]).toMatchObject({
reviews: [{ source: "some flour", reason: "Unknown portion", resolution: "Confirmed manual addition", status: "unresolved" }],
});
});
});