|
| 1 | +import { describe, expect, it } from "vitest"; |
| 2 | +import { AUDIO_EXT, IMAGE_EXT, isMediaFile, MEDIA_EXT, VIDEO_EXT } from "./mediaTypes"; |
| 3 | +import { getTimelineAssetKind } from "./timelineAssetDrop"; |
| 4 | + |
| 5 | +describe("media types", () => { |
| 6 | + it.each([ |
| 7 | + ["clip.m4v", "video"], |
| 8 | + ["assets/Take 2.M4V", "video"], |
| 9 | + ["song.flac", "audio"], |
| 10 | + ["voice.FLAC", "audio"], |
| 11 | + ["clip.mp4", "video"], |
| 12 | + ["music.mp3", "audio"], |
| 13 | + ["still.png", "image"], |
| 14 | + ] as const)("the timeline takes %s as %s", (path, kind) => { |
| 15 | + expect(getTimelineAssetKind(path)).toBe(kind); |
| 16 | + expect(isMediaFile(path)).toBe(true); |
| 17 | + }); |
| 18 | + |
| 19 | + it("still refuses files that are not media", () => { |
| 20 | + for (const path of ["notes.pdf", "font.woff2", "grade.cube", "clip.m4v.txt", "flac"]) { |
| 21 | + expect(getTimelineAssetKind(path)).toBeNull(); |
| 22 | + expect(isMediaFile(path)).toBe(false); |
| 23 | + } |
| 24 | + }); |
| 25 | + |
| 26 | + it("counts a file as media exactly when it is an image, video or audio file", () => { |
| 27 | + const paths = ["a.mp4", "a.m4v", "a.flac", "a.png", "a.ico", "a.woff", "a.pdf", "a.cube"]; |
| 28 | + for (const path of paths) { |
| 29 | + const kinds = [IMAGE_EXT, VIDEO_EXT, AUDIO_EXT].filter((re) => re.test(path)).length; |
| 30 | + expect(MEDIA_EXT.test(path)).toBe(kinds > 0); |
| 31 | + } |
| 32 | + }); |
| 33 | +}); |
0 commit comments