import { afterEach, describe, expect, it } from "vitest"; import { mount } from "@vue/test-utils"; import { defineComponent, h, nextTick } from "vue"; import Foundation from "../packages/vue/tests/fixtures/NumberFieldFoundation.vue"; // Capability probes for installed Reka, not acceptance tests for a public NumberField. const wrappers: ReturnType[] = []; afterEach(() => { wrappers.splice(0).forEach((wrapper) => wrapper.unmount()); document.body.innerHTML = ""; }); describe("NumberField foundation: installed Reka capabilities and adapter gaps", () => { it("steps decimal values and clamps to bounds", async () => { const wrapper = mount(Foundation, { props: { defaultValue: 0.2, step: 0.1, min: 0, max: 0.3 }, attachTo: document.body, }); wrappers.push(wrapper); await wrapper .get('[role="spinbutton"]') .trigger("keydown", { key: "ArrowUp" }); expect(wrapper.get('[role="spinbutton"]').attributes("aria-valuenow")).toBe( "0.3", ); expect( ( wrapper.get('button[aria-label="Increase"]') .element as HTMLButtonElement ).disabled, ).toBe(true); }); it("formats locale text while submitting one canonical numeric value", async () => { const wrapper = mount( defineComponent({ render: () => h("form", {}, [ h(Foundation, { defaultValue: 1234.5, locale: "de-DE", name: "quantity", }), ]), }), { attachTo: document.body }, ); wrappers.push(wrapper); await nextTick(); expect( (wrapper.get('[role="spinbutton"]').element as HTMLInputElement).value, ).toBe("1.234,5"); expect( new FormData(wrapper.get("form").element).getAll("quantity"), ).toEqual(["1234.5"]); }); it("omits a disabled value from native FormData", async () => { const wrapper = mount( defineComponent({ render: () => h("form", {}, [ h(Foundation, { defaultValue: 4, disabled: true, name: "quantity", }), ]), }), { attachTo: document.body }, ); wrappers.push(wrapper); await nextTick(); expect(new FormData(wrapper.get("form").element).has("quantity")).toBe( false, ); }); it("allows an initially empty controlled parent to reject a step", async () => { const wrapper = mount(Foundation, { props: { modelValue: null }, attachTo: document.body, }); wrappers.push(wrapper); await wrapper .get('[role="spinbutton"]') .trigger("keydown", { key: "ArrowUp" }); expect(wrapper.emitted("update:modelValue")?.[0]).toEqual([0]); expect( wrapper.get('[role="spinbutton"]').attributes("aria-valuenow"), ).toBeUndefined(); expect( (wrapper.get('[role="spinbutton"]').element as HTMLInputElement).value, ).toBe(""); }); it("records the raw Home/End readonly gap for the library adapter", async () => { const wrapper = mount(Foundation, { props: { defaultValue: 2, readonly: true, min: 0, max: 5 }, attachTo: document.body, }); wrappers.push(wrapper); await wrapper.get('[role="spinbutton"]').trigger("keydown", { key: "End" }); // This is an upstream capability audit: the future public component must block this. expect(wrapper.emitted("update:modelValue")?.[0]).toEqual([5]); }); it("records that raw Reka does not reset its numeric state with the native form", async () => { const wrapper = mount( defineComponent({ render: () => h("form", {}, [h(Foundation, { defaultValue: 2, name: "quantity" })]), }), { attachTo: document.body }, ); wrappers.push(wrapper); await wrapper .get('[role="spinbutton"]') .trigger("keydown", { key: "ArrowUp" }); expect(wrapper.get('[role="spinbutton"]').attributes("aria-valuenow")).toBe( "3", ); wrapper.get("form").element.reset(); await nextTick(); // The library will own reset coordination; this asserts the installed baseline only. expect(wrapper.get('[role="spinbutton"]').attributes("aria-valuenow")).toBe( "3", ); }); });