import { expect, it, describe } from "vitest"; import { mount } from "@vue/test-utils"; import { descriptionVariants, fieldErrorVariants, labelVariants, switchGroupVariants, textFieldVariants, } from "@heroui-vue/styles"; import Label from "../packages/vue/src/components/label/Label.vue"; import Description from "../packages/vue/src/components/description/Description.vue"; import FieldError from "../packages/vue/src/components/field/FieldError.vue"; import SwitchGroup from "../packages/vue/src/components/switch/SwitchGroup.vue"; import { labelVariants as componentsLabelVariants, descriptionVariants as componentsDescriptionVariants, fieldErrorVariants as componentsFieldErrorVariants, textFieldVariants as componentsTextFieldVariants, switchGroupVariants as componentsSwitchGroupVariants, } from "../packages/vue/src"; describe("shared field style mappings", () => { it("mirror the pinned upstream variant sets and defaults", () => { expect(labelVariants()).toBe("hv-label"); expect(labelVariants({ isRequired: true })).toContain("hv-label--required"); expect(labelVariants({ isDisabled: true })).toContain("hv-label--disabled"); expect(labelVariants({ isInvalid: true })).toContain("hv-label--invalid"); expect(labelVariants({ isRequired: false })).toBe("hv-label"); expect(descriptionVariants()).toBe("hv-description"); expect(fieldErrorVariants()).toBe("hv-field-error"); expect(textFieldVariants()).toContain("hv-textfield"); expect(textFieldVariants()).not.toContain("full-width"); expect(textFieldVariants({ fullWidth: true })).toContain( "hv-textfield--full-width", ); const group = switchGroupVariants(); expect(group.base()).toContain("hv-switch-group--vertical"); expect(group.items()).toBe("hv-switch-group__items"); expect(switchGroupVariants({ orientation: "horizontal" }).base()).toContain( "hv-switch-group--horizontal", ); }); it("are re-exported unchanged from the components entry", () => { expect(componentsLabelVariants).toBe(labelVariants); expect(componentsDescriptionVariants).toBe(descriptionVariants); expect(componentsFieldErrorVariants).toBe(fieldErrorVariants); expect(componentsTextFieldVariants).toBe(textFieldVariants); expect(componentsSwitchGroupVariants).toBe(switchGroupVariants); }); it("components render exactly the shared mapping output for their states", () => { const label = mount(Label, { props: { isRequired: true, isInvalid: true }, slots: { default: "名称" }, attachTo: document.body, }); expect(label.classes().sort()).toEqual( labelVariants({ isRequired: true, isInvalid: true }).split(" ").sort(), ); label.unmount(); const description = mount(Description, { slots: { default: "说明" }, attachTo: document.body, }); expect(description.classes()).toEqual(descriptionVariants().split(" ")); description.unmount(); const error = mount(FieldError, { slots: { default: "错误" }, attachTo: document.body, }); expect(error.classes()).toContain("hv-field-error"); error.unmount(); const group = mount(SwitchGroup, { props: { orientation: "horizontal" }, slots: { default: "选项" }, attachTo: document.body, }); const expected = switchGroupVariants({ orientation: "horizontal" }); expect(group.classes().sort()).toEqual(expected.base().split(" ").sort()); expect(group.find('[data-slot="switch-group-items"]').classes()).toEqual( expected.items().split(" "), ); group.unmount(); }); });