Open History to see the last commit
1import { describe, expect, it } from "vite-plus/test";
2
3import { formatDroppedFilePaths, quoteDroppedFilePath } from "./droppedFilePaths";
4
5describe("quoteDroppedFilePath", () => {
6 it("leaves a path without whitespace alone", () => {
7 expect(quoteDroppedFilePath("/Users/me/notes.pdf")).toBe("/Users/me/notes.pdf");
8 });
9
10 it("escapes a double quote inside a quoted path", () => {
11 expect(quoteDroppedFilePath('/tmp/a " b.pdf')).toBe('"/tmp/a \\" b.pdf"');
12 });
13
14 it("leaves a double quote alone when there is no whitespace to quote for", () => {
15 expect(quoteDroppedFilePath('/tmp/a"b.pdf')).toBe('/tmp/a"b.pdf');
16 });
17
18 it("quotes a path containing spaces", () => {
19 expect(quoteDroppedFilePath("/Users/me/Voice Memos/note 1.m4a")).toBe(
20 '"/Users/me/Voice Memos/note 1.m4a"',
21 );
22 });
23});
24
25describe("formatDroppedFilePaths", () => {
26 it("joins several paths with a space", () => {
27 expect(formatDroppedFilePaths(["/a/one.opus", "/b/two.pdf"])).toBe("/a/one.opus /b/two.pdf");
28 });
29
30 it("preserves a trailing space in a filename instead of trimming it", () => {
31 expect(formatDroppedFilePaths(["/tmp/report "])).toBe('"/tmp/report "');
32 });
33
34 it("skips empty and whitespace-only entries", () => {
35 expect(formatDroppedFilePaths(["", " ", "/a/one.opus"])).toBe("/a/one.opus");
36 });
37
38 it("returns an empty string when nothing resolved", () => {
39 expect(formatDroppedFilePaths([])).toBe("");
40 });
41});