Open History to see the last commit
1import {
2 formatComposerContextReference,
3 toComposerContextId,
4} from "@t3tools/shared/composerContextReferences";
5import { describe, expect, it } from "vite-plus/test";
6
7import { stashEntrySnippet } from "./ComposerStashMenu";
8
9const entry = (prompt: string) => ({
10 id: "stash-1",
11 createdAt: "2026-10-01T00:00:00.000Z",
12 prompt,
13 attachments: [],
14 droppedImageNames: [],
15});
16
17describe("stashEntrySnippet", () => {
18 it("cuts a long prompt on a whole character with no space before the ellipsis", () => {
19 expect(stashEntrySnippet(entry(`${"a".repeat(89)}😀 and more`))).toBe(`${"a".repeat(89)}…`);
20 expect(stashEntrySnippet(entry(`${"a".repeat(88)}😀 and more`))).toBe(`${"a".repeat(88)}😀…`);
21 expect(stashEntrySnippet(entry(`${"a".repeat(89)} word`))).toBe(`${"a".repeat(89)}…`);
22 });
23
24 it("does not cut a combining mark off its letter", () => {
25 expect(stashEntrySnippet(entry(`${"a".repeat(89)}कि and more`))).toBe(`${"a".repeat(89)}…`);
26 expect(stashEntrySnippet(entry(`${"a".repeat(89)}e\u0301 and more`))).toBe(
27 `${"a".repeat(89)}…`,
28 );
29 });
30
31 it.each([87, 88])("keeps a Brahmi vowel sign with its letter after %i characters", (length) => {
32 const prefix = "a".repeat(length);
33 expect(stashEntrySnippet(entry(`${prefix}\u{11013}\u{11038} and more`))).toBe(`${prefix}…`);
34 });
35
36 it("shows context chips by their label", () => {
37 const file = formatComposerContextReference({
38 kind: "file",
39 contextId: toComposerContextId("readme"),
40 label: "README.md",
41 });
42 expect(stashEntrySnippet(entry(`Summarize ${file} please`))).toBe("Summarize README.md please");
43 });
44
45 it("counts unreadable and still-saving images in an image-only prompt", () => {
46 expect(stashEntrySnippet({ ...entry(""), unreadableImageNames: ["shot.png"] })).toBe(
47 "(1 image)",
48 );
49 expect(
50 stashEntrySnippet({
51 ...entry(""),
52 droppedImageNames: ["big.png"],
53 unreadableImageNames: ["shot.png"],
54 }),
55 ).toBe("(2 images)");
56 expect(stashEntrySnippet({ ...entry(""), pendingImageCount: 1 })).toBe("(1 image)");
57 });
58});