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.

3.3 KB
Raw Blame
import assert from "node:assert/strict";
import { test } from "node:test";
import {
  findTranscriptMatches,
  findTranscriptTextMatches,
} from "../src/lib/transcriptLines.ts";

test("matches case-insensitively and returns exact original slices", () => {
  const text = "Open Settings, then open settings again.";
  const ranges = findTranscriptTextMatches(text, "SETTINGS");
  assert.equal(ranges.length, 2);
  assert.deepEqual(
    ranges.map((r) => text.slice(r.start, r.end)),
    ["Settings", "settings"]
  );
});

test("matches across precomposed and decomposed accents in either direction", () => {
  const precomposed = "We reviewed the Café résumé in São Paulo.";
  const fromAscii = findTranscriptTextMatches(precomposed, "cafe");
  assert.deepEqual(
    fromAscii.map((r) => precomposed.slice(r.start, r.end)),
    ["Café"]
  );

  const fromAccented = findTranscriptTextMatches("plain cafe and resume", "café");
  assert.deepEqual(
    fromAccented.map((r) => "plain cafe and resume".slice(r.start, r.end)),
    ["cafe"]
  );

  // Decomposed e + combining acute accent (\u0301): highlight must include the mark.
  const decomposed = "Meet at the Cafe\u0301 today.";
  const decomposedRanges = findTranscriptTextMatches(decomposed, "cafe");
  assert.equal(decomposedRanges.length, 1);
  assert.equal(
    decomposed.slice(decomposedRanges[0].start, decomposedRanges[0].end),
    "Cafe\u0301"
  );
});

test("handles punctuation and regex metacharacters literally", () => {
  const text = "Check v1.2 (beta)? It's $100 + [tax] — don't skip!";
  for (const query of ["v1.2 (beta)?", "$100 + [tax]", "don't"]) {
    const ranges = findTranscriptTextMatches(text, query);
    assert.equal(ranges.length, 1, `expected 1 match for ${query}`);
    assert.equal(text.slice(ranges[0].start, ranges[0].end), query);
  }
});

test("keeps accurate UTF-16 offsets after surrogate-pair emoji", () => {
  const text = "🎉 Café launched 🚀 at Café!";
  const ranges = findTranscriptTextMatches(text, "cafe");
  assert.deepEqual(
    ranges.map((r) => text.slice(r.start, r.end)),
    ["Café", "Café"]
  );
});

test("returns empty for blank queries, combining-only queries, and no matches", () => {
  assert.deepEqual(findTranscriptTextMatches("Hello world", ""), []);
  assert.deepEqual(findTranscriptTextMatches("Hello world", "   "), []);
  assert.deepEqual(findTranscriptTextMatches("Hello world", "\u0301"), []);
  assert.deepEqual(findTranscriptTextMatches("Hello world", "missing"), []);
  assert.deepEqual(findTranscriptTextMatches("", "hello"), []);
});

test("finds non-overlapping matches across multiple transcript lines in order", () => {
  const lines = [
    { startMs: 1000, endMs: 4000, text: "First click the résumé button." },
    { startMs: 5000, endMs: 8000, text: "Nothing related here." },
    { startMs: 9000, endMs: 13000, text: "Resume the upload, then resume playback." },
  ];

  const matches = findTranscriptMatches(lines, "resume");
  assert.deepEqual(
    matches.map((m) => ({
      lineIndex: m.lineIndex,
      startMs: m.startMs,
      slice: lines[m.lineIndex].text.slice(m.start, m.end),
    })),
    [
      { lineIndex: 0, startMs: 1000, slice: "résumé" },
      { lineIndex: 2, startMs: 9000, slice: "Resume" },
      { lineIndex: 2, startMs: 9000, slice: "resume" },
    ]
  );
});