mirror of
https://github.com/rommapp/romm.git
synced 2026-12-02 18:18:47 +01:00
test(frontend): give the rom fixture one home
review-polish pass. Both `src/utils` test files built the same rom literal, so move the typed factory into `rom.fixtures.ts` and import it from each. Tighten two comments that had grown past the two-line limit. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -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/",
|
||||
|
||||
@@ -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",
|
||||
);
|
||||
|
||||
@@ -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>): SimpleRom {
|
||||
return {
|
||||
id: 1,
|
||||
fs_name: "Game",
|
||||
files: [],
|
||||
...overrides,
|
||||
} as SimpleRom;
|
||||
}
|
||||
import { makeRom } from "./rom.fixtures";
|
||||
|
||||
function makeHeartbeat(
|
||||
emulation: Partial<Heartbeat["EMULATION"]> = {},
|
||||
|
||||
10
frontend/src/utils/rom.fixtures.ts
Normal file
10
frontend/src/utils/rom.fixtures.ts
Normal file
@@ -0,0 +1,10 @@
|
||||
import type { SimpleRom } from "@/stores/roms";
|
||||
|
||||
export function makeRom(overrides: Partial<SimpleRom>): SimpleRom {
|
||||
return {
|
||||
id: 1,
|
||||
fs_name: "Game",
|
||||
files: [],
|
||||
...overrides,
|
||||
} as SimpleRom;
|
||||
}
|
||||
Reference in New Issue
Block a user