diff --git a/frontend/dpdm.config.ts b/frontend/dpdm.config.ts index 667843569..c8bb3a6c4 100644 --- a/frontend/dpdm.config.ts +++ b/frontend/dpdm.config.ts @@ -1,8 +1,8 @@ import { defineConfig } from "dpdm"; export default defineConfig({ - // dpdm cannot parse SFCs, so a `.vue` import is a dead end: every `.ts` - // module is an entry so the graph does not stop at the first component. + // dpdm cannot parse SFCs, so a `.vue` import is a dead end. Every `.ts` + // file is an entry, or the graph would stop at the first component. files: ["src/**/*.ts", ".storybook/*.ts"], // `src/console` is frozen v1 and still holds cycles we are not refactoring. exclude: "node_modules|/src/console/", diff --git a/frontend/src/utils/downloadPath.test.ts b/frontend/src/utils/downloadPath.test.ts index 6f28250a3..52cf8c015 100644 --- a/frontend/src/utils/downloadPath.test.ts +++ b/frontend/src/utils/downloadPath.test.ts @@ -1,81 +1,83 @@ import { describe, expect, it } from "vitest"; import type { SimpleRom } from "@/stores/roms"; import { getDownloadPath } from "./downloadPath"; +import { makeRom } from "./rom.fixtures"; describe("getDownloadPath", () => { it("uses fs_name for a flat single-file rom", () => { - const rom = { + const rom = makeRom({ id: 14, fs_name: "Maniac Mansion (1989).adf", has_nested_single_file: false, - files: [{ id: 19, file_name: "Maniac Mansion (1989).adf" }], - } as SimpleRom; + files: [ + { id: 19, file_name: "Maniac Mansion (1989).adf" }, + ] as SimpleRom["files"], + }); expect(getDownloadPath({ rom })).toBe( "/api/roms/14/content/Maniac Mansion (1989).adf", ); }); it("uses the file name for a nested single-file rom", () => { - const rom = { + const rom = makeRom({ id: 21, fs_name: "Art Of Fighting", has_nested_single_file: true, - files: [{ id: 26, file_name: "aof.zip" }], - } as SimpleRom; + files: [{ id: 26, file_name: "aof.zip" }] as SimpleRom["files"], + }); expect(getDownloadPath({ rom })).toBe("/api/roms/21/content/aof.zip"); }); it("uses fs_name for an unselected multi-file rom", () => { - const rom = { + const rom = makeRom({ id: 24, fs_name: "B.A.T.", has_nested_single_file: false, files: [ { id: 29, file_name: "B.A.T. Disk1.adf" }, { id: 30, file_name: "B.A.T. Disk2.adf" }, - ], - } as SimpleRom; + ] as SimpleRom["files"], + }); expect(getDownloadPath({ rom })).toBe("/api/roms/24/content/B.A.T."); }); 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 = { + // fs_name is the extensionless folder name here, so the path segment has + // to carry the file's real name for the emulator to get the 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; + ] as SimpleRom["files"], + }); expect(getDownloadPath({ rom, fileIDs: [29] })).toBe( "/api/roms/24/content/B.A.T.%20Disk1.adf?file_ids=29", ); }); it("falls back to fs_name when multiple files are selected (zip)", () => { - const rom = { + 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; + ] 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 = { + const rom = makeRom({ id: 24, fs_name: "B.A.T.", has_nested_single_file: false, - files: [] as SimpleRom["files"], - } as SimpleRom; + files: [], + }); expect(getDownloadPath({ rom, fileIDs: [999] })).toBe( "/api/roms/24/content/B.A.T.?file_ids=999", ); diff --git a/frontend/src/utils/index.test.ts b/frontend/src/utils/index.test.ts index 32344fbc4..b91debfc7 100644 --- a/frontend/src/utils/index.test.ts +++ b/frontend/src/utils/index.test.ts @@ -1,22 +1,13 @@ import { describe, expect, it } from "vitest"; import type { Config } from "@/stores/config"; import type { Heartbeat } from "@/stores/heartbeat"; -import type { SimpleRom } from "@/stores/roms"; import { isJsDosBundle, isJsDosEmulationSupported, isPico8EmulationSupported, isPico8Rom, } from "./index"; - -function makeRom(overrides: Partial): SimpleRom { - return { - id: 1, - fs_name: "Game", - files: [], - ...overrides, - } as SimpleRom; -} +import { makeRom } from "./rom.fixtures"; function makeHeartbeat( emulation: Partial = {}, diff --git a/frontend/src/utils/rom.fixtures.ts b/frontend/src/utils/rom.fixtures.ts new file mode 100644 index 000000000..ae1cfe965 --- /dev/null +++ b/frontend/src/utils/rom.fixtures.ts @@ -0,0 +1,10 @@ +import type { SimpleRom } from "@/stores/roms"; + +export function makeRom(overrides: Partial): SimpleRom { + return { + id: 1, + fs_name: "Game", + files: [], + ...overrides, + } as SimpleRom; +}