import { describe, it, expect, afterEach, vi } from "vitest"; import { mount } from "@vue/test-utils"; import { defineComponent, h, nextTick, ref } from "vue"; import { readFileSync } from "node:fs"; import { Description, FieldError, Form, Input, InputGroup, InputGroupInput, Label, TextArea, TextField, } from "../packages/vue/src"; afterEach(() => { document.body.innerHTML = ""; }); const settle = async () => { await nextTick(); await nextTick(); }; describe("TextArea", () => { it("renders native textarea with default rows and variant classes", () => { const w = mount(TextArea, { props: { rows: 5, variant: "secondary", fullWidth: true }, }); const el = w.get("[data-slot=textarea]"); expect(el.element.tagName).toBe("TEXTAREA"); expect((el.element as HTMLTextAreaElement).rows).toBe(5); expect(el.classes()).toContain("hv-textarea"); expect(el.classes()).toContain("hv-textarea--secondary"); expect(el.classes()).toContain("hv-textarea--full-width"); }); it("defaults rows to 3", () => { const w = mount(TextArea); expect((w.get("textarea").element as HTMLTextAreaElement).rows).toBe(3); }); it("submits FormData, respects disabled/readonly and resets uncontrolled values", async () => { const w = mount( defineComponent({ render: () => h(Form, {}, () => [ h(TextField, { name: "bio", defaultValue: "start" }, () => [ h(TextArea), ]), h( TextField, { name: "off", defaultValue: "no", isDisabled: true }, () => [h(TextArea)], ), h( TextField, { name: "ro", defaultValue: "yes", isReadOnly: true }, () => [h(TextArea)], ), ]), }), { attachTo: document.body }, ); const areas = w.findAll("textarea"); await areas[0].setValue("changed"); expect( Object.fromEntries( new FormData(w.get("form").element as HTMLFormElement), ), ).toEqual({ bio: "changed", ro: "yes" }); (w.get("form").element as HTMLFormElement).reset(); await settle(); expect((areas[0].element as HTMLTextAreaElement).value).toBe("start"); w.unmount(); }); it("restores DOM value when the parent rejects updates", async () => { const value = ref("fixed"); const w = mount( defineComponent({ components: { TextField, TextArea }, setup: () => ({ value }), template: `