first commit

This commit is contained in:
douboer@gmail.com
2026-03-03 13:23:14 +08:00
commit 3b7c1d558a
161 changed files with 28120 additions and 0 deletions

View File

@@ -0,0 +1,100 @@
import { describe, it, expect, beforeEach, afterEach } from "vitest";
import XInputComponent from "../source/input/index";
import type { IOutputInterface } from "../source/output/interface";
describe("XInputComponent", () => {
let input: XInputComponent;
let container: HTMLElement;
beforeEach(() => {
container = document.createElement("div");
document.body.appendChild(container);
input = new XInputComponent(container);
});
afterEach(() => {
input.dispose();
document.body.removeChild(container);
});
describe("constructor", () => {
it("should create input element", () => {
expect(input.el).toBeInstanceOf(HTMLTextAreaElement);
expect(container.contains(input.el)).toBe(true);
});
it("should mark terminal input as non-login field", () => {
expect(input.el.getAttribute("autocomplete")).toBe("off");
expect(input.el.getAttribute("data-form-type")).toBe("other");
expect(input.el.getAttribute("data-lpignore")).toBe("true");
expect(input.el.getAttribute("data-1p-ignore")).toBe("true");
expect(input.el.getAttribute("data-bwignore")).toBe("true");
});
it("should unlock readonly on first focus", () => {
expect(input.el.readOnly).toBe(true);
input.focus();
expect(input.el.readOnly).toBe(false);
});
});
describe("focus and blur", () => {
it("should focus the input", () => {
input.focus();
expect(document.activeElement).toBe(input.el);
});
it("should blur the input", () => {
input.focus();
input.blur();
expect(document.activeElement).not.toBe(input.el);
});
});
describe("pause and resume", () => {
it("should pause and resume", () => {
input.pause();
// @ts-expect-error testing private property
expect(input.isActive.value).toBe(false);
input.resume();
// @ts-expect-error testing private property
expect(input.isActive.value).toBe(true);
});
});
describe("setValue", () => {
it("should set input value", () => {
input.setValue("test");
expect(input.el.value).toBe("test");
// @ts-expect-error testing private property
expect(input.data.value).toBe("test");
});
});
describe("clear", () => {
it("should clear input value", () => {
input.setValue("test");
input.clear();
expect(input.el.value).toBe("");
// @ts-expect-error testing private property
expect(input.data.value).toBe("");
});
});
describe("pipe", () => {
it("should pipe to output", () => {
const output = {
el: document.createElement("div")
} as IOutputInterface;
input.pipe(output);
expect(output.el.children.length).toBe(3); // before, cursor, after
});
});
describe("dispose", () => {
it("should dispose", () => {
input.dispose();
expect(input.isDisposed).toBe(true);
});
});
});