import { describe, expect, it } from "vite-plus/test";
import { guestHostImageType, repliesShowImage } from "./guestAttachments.ts";
describe("guest host images", () => {
it.each([
["", "/w/a.png", "image/png"],
["", "/w/my shot.jpg", "image/jpeg"],
[".png)", "/w/shot(1).png", "image/png"],
[" ", "/w/shot_1.png", "image/png"],
[" ", "/w/a&b.png", "image/png"],
["", "/w/café.png", "image/png"],
[" ", "/w/shot.png", "image/png"],
[" ", "/w/shot2.png", "image/png"],
["![a][r]\n\n[r]: /w/ref.png", "/w/ref.png", "image/png"],
["", "/w/url form.png", "image/png"],
["", "C:\\w\\win.png", "image/png"],
["![a][r]\n\n[r]: C:\\w\\ref.png", "C:/w/ref.png", "image/png"],
[
'<picture><source media="(prefers-color-scheme: dark)" srcset="/w/dark.png"><img src="/w/light.png"></picture>',
"/w/dark.png",
"image/png",
],
[
'<picture><source media="(prefers-color-scheme: dark)" srcset="C:\\w\\dark.png"><img src="C:\\w\\light.png"></picture>',
"C:/w/dark.png",
"image/png",
],
// Shown as a link, in code, or not at all: the guest sees no image, so none loads.
["[a](/w/link.png)", "/w/link.png", null],
["```\n\n```", "/w/code.png", null],
["``", "/w/span.png", null],
["<!--  -->", "/w/comment.png", null],
["", "/a.png", null],
["", "//host/s/x.png", null],
["", "\\\\host\\s\\x.png", null],
["", "/w/a.svg", null],
["", "/w/a.constructor", null],
])("%j serves %j as %j", (text, path, type) => {
const served = guestHostImageType(path) !== null && repliesShowImage(path, [{ text }]);
expect(served ? guestHostImageType(path) : null).toBe(type);
});
});