xonecas.io
70160
Ce

cel-tui / files

cel-tui / packages / core / src / index.test.ts

1.9 KB
1import { describe, expect, test } from "bun:test";
2import {
3  type CursorStyle,
4  type cel,
5  type EmitOptions,
6  type KeyEvent,
7  type KeyPressHandler,
8  type ScrollHandler,
9  Text,
10  type TextInputBaseProps,
11  type TextInputProps,
12} from "@cel-tui/core";
13
14type AssertNever<T extends never> = T;
15type ContainerOnlyTextInputKey = Extract<
16  keyof TextInputProps,
17  | "gap"
18  | "justifyContent"
19  | "alignItems"
20  | "flexWrap"
21  | "overflow"
22  | "scrollbar"
23  | "scrollbarStyle"
24  | "scrollOffset"
25  | "onScroll"
26  | "onClick"
27>;
28type _TextInputExcludesContainerOnlyProps =
29  AssertNever<ContainerOnlyTextInputKey>;
30type _CelExcludesTestHooks = AssertNever<
31  Extract<keyof typeof cel, "_getBuffer" | "_flush">
32>;
33
34describe("@cel-tui/core public barrel", () => {
35  test("re-exports public callback contracts", () => {
36    const keyHandler: KeyPressHandler = () => false;
37    const scrollHandler: ScrollHandler = () => false;
38    const cursorStyle: CursorStyle = "bar";
39    const textInputBaseProps: TextInputBaseProps = {
40      width: "100%",
41      scrollStep: 4,
42      focusable: true,
43    };
44    const emitOptions: EmitOptions = {
45      cursor: { visible: true, x: 0, y: 0, style: "bar" },
46      previousCursor: { visible: false },
47    };
48    const keyEvent: KeyEvent = {
49      key: "a",
50      text: "a",
51      eventType: "press",
52      codePoint: 97,
53      modifiers: {
54        shift: false,
55        alt: false,
56        ctrl: false,
57        super: false,
58        hyper: false,
59        meta: false,
60        capsLock: false,
61        numLock: false,
62      },
63    };
64
65    expect(keyHandler("escape", keyEvent)).toBe(false);
66    expect(scrollHandler(1, 10)).toBe(false);
67    expect(cursorStyle).toBe("bar");
68    expect(textInputBaseProps.scrollStep).toBe(4);
69    expect(emitOptions.cursor?.visible).toBe(true);
70    expect(keyEvent.eventType).toBe("press");
71    expect(Text("public entrypoint").content).toBe("public entrypoint");
72  });
73});