87 lines
3.0 KiB
TypeScript
87 lines
3.0 KiB
TypeScript
import { describe, it, expect } from "vitest";
|
|
import { Operation } from "../../src/component/operation.js";
|
|
import type { OperationProps } from "../../src/component/operation.js";
|
|
import type { UElement, UNode } from "@alkdev/ujsx";
|
|
|
|
describe("Operation", () => {
|
|
it("produces UElement with type operation", () => {
|
|
const el = Operation({ name: "classify" } as OperationProps & { children?: UNode[] });
|
|
expect(el.type).toBe("operation");
|
|
});
|
|
|
|
it("requires name prop", () => {
|
|
const el = Operation({ name: "architect" } as OperationProps & { children?: UNode[] });
|
|
expect((el as UElement).props.name).toBe("architect");
|
|
});
|
|
|
|
it("has no children (leaf node)", () => {
|
|
const el = Operation({ name: "classify" } as OperationProps & { children?: UNode[] });
|
|
expect(el.children).toEqual([]);
|
|
});
|
|
|
|
it("ignores children even if provided (leaf node)", () => {
|
|
const el = Operation({
|
|
name: "classify",
|
|
children: ["child1"],
|
|
} as OperationProps & { children?: UNode[] });
|
|
expect(el.children).toEqual([]);
|
|
});
|
|
|
|
it("preserves optional input prop", () => {
|
|
const el = Operation({
|
|
name: "process",
|
|
input: { key: "value" },
|
|
} as OperationProps & { children?: UNode[] });
|
|
expect((el as UElement).props.input).toEqual({ key: "value" });
|
|
});
|
|
|
|
it("preserves optional retries prop", () => {
|
|
const el = Operation({
|
|
name: "fetch",
|
|
retries: 3,
|
|
} as OperationProps & { children?: UNode[] });
|
|
expect((el as UElement).props.retries).toBe(3);
|
|
});
|
|
|
|
it("preserves optional timeout prop", () => {
|
|
const el = Operation({
|
|
name: "fetch",
|
|
timeout: 5000,
|
|
} as OperationProps & { children?: UNode[] });
|
|
expect((el as UElement).props.timeout).toBe(5000);
|
|
});
|
|
|
|
it("omits optional props when not provided", () => {
|
|
const el = Operation({ name: "classify" } as OperationProps & { children?: UNode[] });
|
|
expect((el as UElement).props.input).toBeUndefined();
|
|
expect((el as UElement).props.retries).toBeUndefined();
|
|
expect((el as UElement).props.timeout).toBeUndefined();
|
|
});
|
|
|
|
it("preserves all props together", () => {
|
|
const el = Operation({
|
|
name: "fetch",
|
|
input: "data",
|
|
retries: 2,
|
|
timeout: 10000,
|
|
} as OperationProps & { children?: UNode[] });
|
|
expect((el as UElement).props.name).toBe("fetch");
|
|
expect((el as UElement).props.input).toBe("data");
|
|
expect((el as UElement).props.retries).toBe(2);
|
|
expect((el as UElement).props.timeout).toBe(10000);
|
|
});
|
|
|
|
it("is a valid UElement (has type, props, children)", () => {
|
|
const el = Operation({ name: "test" } as OperationProps & { children?: UNode[] });
|
|
expect(el).toHaveProperty("type");
|
|
expect(el).toHaveProperty("props");
|
|
expect(el).toHaveProperty("children");
|
|
expect(typeof el.type).toBe("string");
|
|
expect(typeof el.props).toBe("object");
|
|
expect(Array.isArray(el.children)).toBe(true);
|
|
});
|
|
|
|
it("displayName is Operation", () => {
|
|
expect(Operation.displayName).toBe("Operation");
|
|
});
|
|
}); |