| 1 | import { describe, expect, it } from "vite-plus/test"; |
| 2 | |
| 3 | import { mediaFileReference, mediaReferenceFileName } from "./mediaReference.ts"; |
| 4 | |
| 5 | describe("mediaFileReference", () => { |
| 6 | it.each([ |
| 7 | ["/work/project/./media/../clip.mp4", "/work/project/", "clip.mp4"], |
| 8 | ["/work/project/../outside.mp4", "/work/project", undefined], |
| 9 | ["/work/project-other/clip.mp4", "/work/project", undefined], |
| 10 | ["/work/Project/clip.mp4", "/work/project", undefined], |
| 11 | ["/work/project/a\\b.mp4", "/work/project", "a\\b.mp4"], |
| 12 | ["/work/clip.mp4", "/work/other/..", "clip.mp4"], |
| 13 | ["/clip.mp4", "/", "clip.mp4"], |
| 14 | ["C:\\WORK\\project\\media\\..\\Clip.mp4", "c:/work/project/", "Clip.mp4"], |
| 15 | ["D:\\work\\clip.mp4", "C:\\work", undefined], |
| 16 | ["\\\\Server\\Share\\Project\\Clip.mp4", "//server/share/project", "Clip.mp4"], |
| 17 | ["\\\\server\\other\\clip.mp4", "\\\\server\\share", undefined], |
| 18 | ["../clip.mp4", "/work/project", undefined], |
| 19 | ])("preserves %s and only labels paths inside %s as relative", (path, root, relativePath) => { |
| 20 | expect(mediaFileReference(path, root)).toEqual({ |
| 21 | kind: "file", |
| 22 | path, |
| 23 | ...(relativePath === undefined ? {} : { relativePath }), |
| 24 | }); |
| 25 | }); |
| 26 | }); |
| 27 | |
| 28 | describe("mediaReferenceFileName", () => { |
| 29 | it.each([ |
| 30 | [{ kind: "file", path: "/tmp/take\\one%20.mp4" }, "take\\one%20.mp4"], |
| 31 | [{ kind: "file", path: "C:\\clips/take\\one.mp4" }, "one.mp4"], |
| 32 | [{ kind: "file", path: "\\\\server\\share\\one.mp4" }, "one.mp4"], |
| 33 | [{ kind: "url", url: "//cdn.example/clip%20one%2Emp4?sig=a+b#t=2" }, "clip one.mp4"], |
| 34 | [{ kind: "url", url: "https://cdn.example/clip%2520.mp4" }, "clip%20.mp4"], |
| 35 | [{ kind: "url", url: "https://cdn.example/clip%20%oops.mp4" }, "clip%20%oops.mp4"], |
| 36 | ] as const)("preserves filename semantics for %j", (reference, name) => { |
| 37 | expect(mediaReferenceFileName(reference)).toBe(name); |
| 38 | }); |
| 39 | }); |