Skip to content
Source
Sign inSign up
Open History to see the last commit

guestAttachments.test.ts

43 lines2.1 KB

1import { describe, expect, it } from "vite-plus/test";
2​
3import { guestHostImageType, repliesShowImage } from "./guestAttachments.ts";
4​
5describe("guest host images", () => {
6 it.each([
7 ["![a](/w/a.png)", "/w/a.png", "image/png"],
8 ["![a](</w/my shot.jpg>)", "/w/my shot.jpg", "image/jpeg"],
9 ["![a](/w/shot(1).png)", "/w/shot(1).png", "image/png"],
10 ["![a](/w/shot\\_1.png) ![b](/w/a&amp;b.png)", "/w/shot_1.png", "image/png"],
11 ["![a](/w/shot\\_1.png) ![b](/w/a&amp;b.png)", "/w/a&b.png", "image/png"],
12 ["![a](file:///w/caf%c3%a9.png)", "/w/café.png", "image/png"],
13 ["![a](file:///w/%73hot.png) ![b](/w/sh&#111;t2.png)", "/w/shot.png", "image/png"],
14 ["![a](file:///w/%73hot.png) ![b](/w/sh&#111;t2.png)", "/w/shot2.png", "image/png"],
15 ["![a][r]\n\n[r]: /w/ref.png", "/w/ref.png", "image/png"],
16 ["![a](file:///w/url%20form.png)", "/w/url form.png", "image/png"],
17 ["![a](C:\\w\\win.png)", "C:\\w\\win.png", "image/png"],
18 ["![a][r]\n\n[r]: C:\\w\\ref.png", "C:/w/ref.png", "image/png"],
19 [
20 '<picture><source media="(prefers-color-scheme: dark)" srcset="/w/dark.png"><img src="/w/light.png"></picture>',
21 "/w/dark.png",
22 "image/png",
23 ],
24 [
25 '<picture><source media="(prefers-color-scheme: dark)" srcset="C:\\w\\dark.png"><img src="C:\\w\\light.png"></picture>',
26 "C:/w/dark.png",
27 "image/png",
28 ],
29 // Shown as a link, in code, or not at all: the guest sees no image, so none loads.
30 ["[a](/w/link.png)", "/w/link.png", null],
31 ["```\n![a](/w/code.png)\n```", "/w/code.png", null],
32 ["`![a](/w/span.png)`", "/w/span.png", null],
33 ["<!-- ![a](/w/comment.png) -->", "/w/comment.png", null],
34 ["![a](/w/a.png)", "/a.png", null],
35 ["![a](//host/s/x.png)", "//host/s/x.png", null],
36 ["![a](\\\\host\\s\\x.png)", "\\\\host\\s\\x.png", null],
37 ["![a](/w/a.svg)", "/w/a.svg", null],
38 ["![a](/w/a.constructor)", "/w/a.constructor", null],
39 ])("%j serves %j as %j", (text, path, type) => {
40 const served = guestHostImageType(path) !== null && repliesShowImage(path, [{ text }]);
41 expect(served ? guestHostImageType(path) : null).toBe(type);
42 });
43});