The best way to control Claude Code, Codex and more from any computer or phone
Mirrored from https://github.com/Camo67/t3code.git
Synced Nov 21, 03:37 UTC
| 1 | import { expect, it } from "vite-plus/test"; |
| 2 | |
| 3 | import { appendGeneratedImageEmbeds } from "./generatedImageMarkdown.ts"; |
| 4 | |
| 5 | it.each([ |
| 6 | { |
| 7 | name: "appends each new image once", |
| 8 | text: "Done.", |
| 9 | saved: ["/tmp/a.png", "/tmp/b.png", "/tmp/a.png"], |
| 10 | expected: "Done.\n\n\n\n", |
| 11 | }, |
| 12 | { |
| 13 | name: "skips images the reply already shows", |
| 14 | text: String.raw`  ![C][a\*b] ![D][unc] |
| 15 | |
| 16 | [a\*b]: c:\Users\me\.codex\c.png |
| 17 | [unc]: <\\HOST\Share\d.png> |
| 18 | |
| 19 | `, |
| 20 | saved: [ |
| 21 | "/tmp/a b.png", |
| 22 | String.raw`C:\Users\Me\.codex\b.png`, |
| 23 | String.raw`C:\Users\Me\.codex\c.png`, |
| 24 | String.raw`\\host\share\d.png`, |
| 25 | String.raw`\\HOST\SHARE\e.png`, |
| 26 | "/tmp/C.png", |
| 27 | ], |
| 28 | expected: String.raw`  ![C][a\*b] ![D][unc] |
| 29 | |
| 30 | [a\*b]: c:\Users\me\.codex\c.png |
| 31 | [unc]: <\\HOST\Share\d.png> |
| 32 | |
| 33 |  |
| 34 | |
| 35 | `, |
| 36 | }, |
| 37 | { |
| 38 | name: "links, code and escaped embeds still need a preview", |
| 39 | text: "[open](/tmp/a.png) ``\n\n```md\n\n```\n\\", |
| 40 | saved: ["/tmp/a.png"], |
| 41 | expected: |
| 42 | "[open](/tmp/a.png) ``\n\n```md\n\n```\n\\\n\n", |
| 43 | }, |
| 44 | { |
| 45 | name: "an unclosed trailing fence is closed first", |
| 46 | text: 'Created.\n\n~~~js\nconsole.log("done");', |
| 47 | saved: ["/tmp/a.png"], |
| 48 | expected: 'Created.\n\n~~~js\nconsole.log("done");\n~~~\n\n', |
| 49 | }, |
| 50 | { |
| 51 | name: "an unclosed trailing HTML comment is closed first", |
| 52 | text: "<!--\n", |
| 53 | saved: ["/tmp/a.png"], |
| 54 | expected: "<!--\n\n-->\n\n", |
| 55 | }, |
| 56 | { |
| 57 | name: "an unclosed trailing raw HTML block is closed first", |
| 58 | text: "<pre>\nlog", |
| 59 | saved: ["/tmp/a.png"], |
| 60 | expected: "<pre>\nlog\n</pre>\n\n", |
| 61 | }, |
| 62 | { |
| 63 | name: "Windows, UNC and reserved characters keep their path", |
| 64 | text: "", |
| 65 | saved: [ |
| 66 | String.raw`C:\Users\me\a b#1.png`, |
| 67 | String.raw`\\host\share\a.png`, |
| 68 | "/tmp/a#b?100%25©\\!\n<x>.png", |
| 69 | ], |
| 70 | expected: |
| 71 | "\n\n\n\n", |
| 72 | }, |
| 73 | ])("generated image embeds: $name", ({ text, saved, expected }) => { |
| 74 | const result = appendGeneratedImageEmbeds(text, saved); |
| 75 | expect(result).toBe(expected); |
| 76 | // Clients read every appended embed back as its saved file. |
| 77 | expect(appendGeneratedImageEmbeds(result, saved)).toBe(result); |
| 78 | }); |