Skip to content

armgit / clipy

Public Imported from GitHub
0

The AI-native screen recorder. Record your screen and talk; the people you share it with and your AI agents both get it.

2.6 KB
Raw Blame
import { describe, expect, it } from "vitest";
import { groupTranscriptLines } from "../src/lib/transcriptLines";

function segment(startMs: number, endMs: number, text: string) {
  return { startMs, endMs, text };
}

describe("groupTranscriptLines", () => {
  it("attaches punctuation to the previous word and breaks after a quoted sentence", () => {
    const words = [
      segment(0, 100, " “Wait "), segment(100, 110, ","), segment(110, 220, "please"),
      segment(220, 230, "!”"), segment(230, 300, "Next"),
    ];
    expect(groupTranscriptLines(words)).toEqual([segment(0, 230, "“Wait, please!”"), segment(230, 300, "Next")]);
    expect(words[0]).toEqual(segment(0, 100, " “Wait "));
  });

  it("measures pauses from the latest word end and ignores blank tokens", () => {
    const words = [
      segment(0, 300, "one"), segment(100, 150, "more"),
      segment(999, 1099, "word"), // 699 ms of silence.
      segment(1300, 1500, "   "),
      segment(1799, 1900, "next"), // 700 ms since the last word.
    ];
    expect(groupTranscriptLines(words)).toEqual([segment(0, 1099, "one more word"), segment(1799, 1900, "next")]);
  });

  it("starts a new line when the next token would reach 14 seconds", () => {
    const words = [
      segment(0, 13_900, "first"), segment(13_900, 13_999, "line"), segment(13_999, 14_000, "next"),
    ];
    expect(groupTranscriptLines(words)).toEqual([segment(0, 13_999, "first line"), segment(13_999, 14_000, "next")]);
  });

  it.each([
    ["Latin", "a".repeat(88), "b", " b"],
    ["CJK", "漢".repeat(44), "字", "字"],
    ["Korean", "안".repeat(43), "안", " 안"],
    ["Thai", "ก".repeat(89), "ก", "ก"],
  ])(
    "wraps %s text only when the joined width exceeds 90",
    (_script, prefix, word, suffix) => {
      const next = segment(200, 300, word);
      expect(
        groupTranscriptLines([
          segment(0, 100, prefix),
          segment(100, 200, word),
          next,
        ]),
      ).toEqual([segment(0, 200, prefix + suffix), next]);
    },
  );

  it("joins mixed-script seams and retains spaces between Korean words", () => {
    const words = ["Open", "設定", "panel", "메뉴", "열기"].map((text, i) => segment(i * 100, (i + 1) * 100, text));
    expect(groupTranscriptLines(words)).toEqual([segment(0, 500, "Open設定panel 메뉴 열기")]);
  });

  it("omits empty lines and keeps a token with a reversed end at its start", () => {
    expect(groupTranscriptLines([segment(10, 20, " ")])).toEqual([]);
    expect(groupTranscriptLines([segment(500, 490, " Hi ")])).toEqual([segment(500, 500, "Hi")]);
  });
});