Open History to see the last commit
1import { describe, expect, it } from "vite-plus/test";
2
3import {
4 isWorkspaceBrowserPreviewPath,
5 isWorkspaceImagePreviewPath,
6 isWorkspacePreviewEntryPath,
7 isWorkspaceVideoPreviewPath,
8 mediaKindFromPath,
9} from "./filePreview.ts";
10
11describe("workspace file previews", () => {
12 it.each(["report.html", "report.HTM", "document.pdf?download=1"])(
13 "recognizes browser preview path %s",
14 (path) => {
15 expect(isWorkspaceBrowserPreviewPath(path)).toBe(true);
16 expect(isWorkspacePreviewEntryPath(path)).toBe(true);
17 },
18 );
19
20 it.each([
21 "icon.png",
22 "photo.JPEG",
23 "animation.gif",
24 "vector.svg#mark",
25 "texture.webp",
26 "image.avif",
27 ])("recognizes image preview path %s", (path) => {
28 expect(isWorkspaceImagePreviewPath(path)).toBe(true);
29 expect(isWorkspacePreviewEntryPath(path)).toBe(true);
30 });
31
32 it.each(["README.md", "src/index.ts", "image.png.ts", "png"])(
33 "rejects non-preview path %s",
34 (path) => {
35 expect(isWorkspacePreviewEntryPath(path)).toBe(false);
36 },
37 );
38});
39
40describe("media path parsing", () => {
41 it.each([
42 ["https://cdn.example/clip.webm?download=1#t=2", "video"],
43 ["https://example.com/download?name=recording.mp4", null],
44 ["https://example.png", null],
45 ["images%2Fresult%2Epng", "image"],
46 ["images/result%23v2.png", "image"],
47 ["images/result.png%23secret.txt", null],
48 ["images/result.png%3Fsecret.txt", null],
49 ["/tmp/100%.png", "image"],
50 ])("classifies the decoded pathname of %s", (source, kind) => {
51 expect(mediaKindFromPath(source)).toBe(kind);
52 });
53
54 it.each([
55 ["recording.mp4#t=2", "video", false],
56 ["recording%2Emp4", "video", false],
57 ["recording#take2.mp4", null, true],
58 ["recording?take2.mp4", null, true],
59 ])("distinguishes authored URLs from literal filenames in %s", (source, kind, literalVideo) => {
60 expect(mediaKindFromPath(source)).toBe(kind);
61 expect(isWorkspaceVideoPreviewPath(source)).toBe(literalVideo);
62 });
63});