-
-
Notifications
You must be signed in to change notification settings - Fork 622
Expand file tree
/
Copy pathindex.test.ts
More file actions
59 lines (54 loc) · 1.85 KB
/
Copy pathindex.test.ts
File metadata and controls
59 lines (54 loc) · 1.85 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import { describe, expect, it } from "vitest";
import type { SimpleRom } from "@/stores/roms";
import { getDownloadPath } from "./index";
function makeRom(overrides: Partial<SimpleRom>): SimpleRom {
return {
id: 1,
fs_name: "Game",
files: [],
...overrides,
} as SimpleRom;
}
describe("getDownloadPath", () => {
it("uses fs_name when no file is selected", () => {
const rom = makeRom({ id: 14, fs_name: "Maniac Mansion (1989).adf" });
expect(getDownloadPath({ rom })).toBe(
"/api/roms/14/content/Maniac Mansion (1989).adf",
);
});
it("uses the selected file name (with extension) for a single file", () => {
// Multi-file rom: fs_name is the folder name with no extension. The URL
// path segment must carry the selected file's real name so the emulator
// receives a file with the correct extension.
const rom = makeRom({
id: 24,
fs_name: "B.A.T.",
files: [
{ id: 29, file_name: "B.A.T. Disk1.adf" },
{ id: 30, file_name: "B.A.T. Disk2.adf" },
] as SimpleRom["files"],
});
expect(getDownloadPath({ rom, fileIDs: [29] })).toBe(
"/api/roms/24/content/B.A.T. Disk1.adf?file_ids=29",
);
});
it("falls back to fs_name when multiple files are selected (zip)", () => {
const rom = makeRom({
id: 24,
fs_name: "B.A.T.",
files: [
{ id: 29, file_name: "B.A.T. Disk1.adf" },
{ id: 30, file_name: "B.A.T. Disk2.adf" },
] as SimpleRom["files"],
});
expect(getDownloadPath({ rom, fileIDs: [29, 30] })).toBe(
"/api/roms/24/content/B.A.T.?file_ids=29%2C30",
);
});
it("falls back to fs_name when the selected file id is unknown", () => {
const rom = makeRom({ id: 24, fs_name: "B.A.T." });
expect(getDownloadPath({ rom, fileIDs: [999] })).toBe(
"/api/roms/24/content/B.A.T.?file_ids=999",
);
});
});