forked from phenom/healer-man
Release Healer Man 0.1.14
This commit is contained in:
1 parent
67d7a8ebe7
commit
7b41b102fa
147 files changed
+169892
-1342
No files matched your search
@@ -0,0 +1,77 @@
|
||||
import { beforeEach, describe, expect, it, vi } from "vitest";
|
||||
|
||||
const content = vi.hoisted(() => ({
|
||||
usable: false,
|
||||
install: vi.fn(async () => undefined),
|
||||
remove: vi.fn(async () => undefined),
|
||||
listener: null as (() => void) | null,
|
||||
snapshot: {
|
||||
downloadedBytes: 4,
|
||||
totalBytes: 8,
|
||||
manifest: {
|
||||
packs: [{ id: "core:combat-media", fileCount: 12 }],
|
||||
},
|
||||
},
|
||||
}));
|
||||
|
||||
vi.mock("../content/contentManager", () => ({
|
||||
contentPackIsUsable: () => content.usable,
|
||||
getContentManagerSnapshot: () => content.snapshot,
|
||||
installContentPack: content.install,
|
||||
removeContentPack: content.remove,
|
||||
resolveContentUrl: (url: string) => `resolved:${url}`,
|
||||
subscribeContentManager: (listener: () => void) => {
|
||||
content.listener = listener;
|
||||
return () => { content.listener = null; };
|
||||
},
|
||||
}));
|
||||
|
||||
import {
|
||||
combatMediaPackReady,
|
||||
downloadCombatMediaPack,
|
||||
fetchCombatMediaAsset,
|
||||
removeCombatMediaPack,
|
||||
} from "./combatMediaPack";
|
||||
|
||||
beforeEach(() => {
|
||||
content.usable = false;
|
||||
content.install.mockClear();
|
||||
content.remove.mockClear();
|
||||
vi.unstubAllGlobals();
|
||||
});
|
||||
|
||||
describe("optional combat media pack", () => {
|
||||
it("uses the shared verified content-pack installer only after an explicit request", async () => {
|
||||
const progress = vi.fn();
|
||||
await expect(downloadCombatMediaPack(progress)).resolves.toEqual({ fileCount: 12 });
|
||||
expect(content.install).toHaveBeenCalledWith("core:combat-media");
|
||||
expect(progress).toHaveBeenLastCalledWith({ completed: 4, total: 8 });
|
||||
});
|
||||
|
||||
it("does not fetch source media while its pack is offloaded", async () => {
|
||||
const fetch = vi.fn();
|
||||
vi.stubGlobal("fetch", fetch);
|
||||
|
||||
expect(combatMediaPackReady()).toBe(false);
|
||||
await expect(fetchCombatMediaAsset("/assets/game/combat-effects/audio/shield.wav"))
|
||||
.rejects.toThrow("not installed");
|
||||
expect(fetch).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("resolves installed media through the shared content router and removes the same pack", async () => {
|
||||
content.usable = true;
|
||||
const response = new Response(new Uint8Array([1, 2, 3]));
|
||||
const fetch = vi.fn(async () => response);
|
||||
vi.stubGlobal("fetch", fetch);
|
||||
|
||||
await expect(fetchCombatMediaAsset("/assets/game/combat-effects/audio/shield.wav"))
|
||||
.resolves.toBe(response);
|
||||
expect(fetch).toHaveBeenCalledWith(
|
||||
"resolved:/assets/game/combat-effects/audio/shield.wav",
|
||||
{ cache: "no-store" },
|
||||
);
|
||||
|
||||
await removeCombatMediaPack();
|
||||
expect(content.remove).toHaveBeenCalledWith("core:combat-media");
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user