Implement Parallel ujsx component with id and maxConcurrency props
This commit is contained in:
@@ -1 +1,2 @@
|
||||
export {};
|
||||
export { Parallel } from "./parallel.js";
|
||||
export type { ParallelProps } from "./parallel.js";
|
||||
@@ -1 +1,26 @@
|
||||
export {};
|
||||
import type { UComponent, UElement, UNode, UniversalProps } from "@alkdev/ujsx";
|
||||
|
||||
export interface ParallelProps extends UniversalProps {
|
||||
id?: string;
|
||||
maxConcurrency?: number;
|
||||
}
|
||||
|
||||
export const Parallel: UComponent<ParallelProps> = (
|
||||
props: ParallelProps & { children?: UNode[] },
|
||||
): UElement => {
|
||||
const { id, maxConcurrency, children, ...rest } = props;
|
||||
const elementProps: UniversalProps = { ...rest };
|
||||
if (id !== undefined) {
|
||||
elementProps.id = id;
|
||||
}
|
||||
if (maxConcurrency !== undefined) {
|
||||
elementProps.maxConcurrency = maxConcurrency;
|
||||
}
|
||||
return {
|
||||
type: "parallel",
|
||||
props: elementProps,
|
||||
children: children ?? [],
|
||||
};
|
||||
};
|
||||
|
||||
Parallel.displayName = "Parallel";
|
||||
@@ -1,7 +1,33 @@
|
||||
import { describe, it, expect } from 'vitest';
|
||||
import { describe, it, expect } from "vitest";
|
||||
import { Parallel } from "../../src/component/parallel.js";
|
||||
import type { ParallelProps } from "../../src/component/parallel.js";
|
||||
import type { UElement, UNode } from "@alkdev/ujsx";
|
||||
|
||||
describe('components', () => {
|
||||
it('placeholder', () => {
|
||||
expect(true).toBe(true);
|
||||
describe("Parallel", () => {
|
||||
it("produces UElement with type parallel", () => {
|
||||
const el = Parallel({} as ParallelProps & { children?: UNode[] });
|
||||
expect(el.type).toBe("parallel");
|
||||
expect(el.children).toEqual([]);
|
||||
});
|
||||
|
||||
it("preserves id prop", () => {
|
||||
const el = Parallel({ id: "group-1" } as ParallelProps & { children?: UNode[] });
|
||||
expect((el as UElement).props.id).toBe("group-1");
|
||||
});
|
||||
|
||||
it("preserves maxConcurrency prop", () => {
|
||||
const el = Parallel({ maxConcurrency: 3 } as ParallelProps & { children?: UNode[] });
|
||||
expect((el as UElement).props.maxConcurrency).toBe(3);
|
||||
});
|
||||
|
||||
it("includes children", () => {
|
||||
const el = Parallel({ children: ["child1", "child2"] } as ParallelProps & { children?: UNode[] });
|
||||
expect(el.children).toEqual(["child1", "child2"]);
|
||||
});
|
||||
|
||||
it("omits id and maxConcurrency when not provided", () => {
|
||||
const el = Parallel({} as ParallelProps & { children?: UNode[] });
|
||||
expect((el as UElement).props.id).toBeUndefined();
|
||||
expect((el as UElement).props.maxConcurrency).toBeUndefined();
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user