42 lines
2.3 KiB
TypeScript
42 lines
2.3 KiB
TypeScript
import { describe, expect, it } from "vitest";
|
|
import { TextFieldRootPropsSchema, TextFieldMeta } from "../../src/components/text-field/text-field.props";
|
|
import { CheckboxRootPropsSchema, CheckboxMeta } from "../../src/components/checkbox/checkbox.props";
|
|
import { SwitchRootPropsSchema, SwitchMeta } from "../../src/components/switch/switch.props";
|
|
import { RadioGroupRootPropsSchema, RadioGroupMeta } from "../../src/components/radio-group/radio-group.props";
|
|
import { SliderRootPropsSchema, SliderMeta } from "../../src/components/slider/slider.props";
|
|
import { NumberFieldRootPropsSchema, NumberFieldMeta } from "../../src/components/number-field/number-field.props";
|
|
import { ToggleGroupRootPropsSchema, ToggleGroupMeta } from "../../src/components/toggle-group/toggle-group.props";
|
|
describe("Form component schemas", () => {
|
|
it("TextField validates", () => {
|
|
expect(TextFieldRootPropsSchema.safeParse({ value: "hello", disabled: false }).success).toBe(true);
|
|
});
|
|
it("Checkbox validates", () => {
|
|
expect(CheckboxRootPropsSchema.safeParse({ checked: true, name: "agree" }).success).toBe(true);
|
|
});
|
|
it("Switch validates", () => {
|
|
expect(SwitchRootPropsSchema.safeParse({ checked: false }).success).toBe(true);
|
|
});
|
|
it("RadioGroup validates", () => {
|
|
expect(RadioGroupRootPropsSchema.safeParse({ value: "opt1", orientation: "horizontal" }).success).toBe(true);
|
|
expect(RadioGroupRootPropsSchema.safeParse({ orientation: "invalid" }).success).toBe(false);
|
|
});
|
|
it("Slider validates", () => {
|
|
expect(SliderRootPropsSchema.safeParse({ value: [25, 75], min: 0, max: 100, step: 5 }).success).toBe(true);
|
|
});
|
|
it("NumberField validates", () => {
|
|
expect(NumberFieldRootPropsSchema.safeParse({ value: 42, min: 0, max: 100 }).success).toBe(true);
|
|
});
|
|
it("ToggleGroup validates", () => {
|
|
expect(ToggleGroupRootPropsSchema.safeParse({ value: "a" }).success).toBe(true);
|
|
expect(ToggleGroupRootPropsSchema.safeParse({ value: ["a", "b"], multiple: true }).success).toBe(true);
|
|
});
|
|
it("all Meta objects valid", () => {
|
|
const metas = [TextFieldMeta, CheckboxMeta, SwitchMeta, RadioGroupMeta, SliderMeta, NumberFieldMeta, ToggleGroupMeta];
|
|
for (const meta of metas) {
|
|
expect(meta.name).toBeTruthy();
|
|
expect(meta.description).toBeTruthy();
|
|
expect(meta.parts.length).toBeGreaterThan(0);
|
|
}
|
|
});
|
|
});
|