Files
healer-man/src/ui/ContentManagerScreen.test.ts
T
2026-09-20 19:27:37 -04:00

116 lines
3.9 KiB
TypeScript

import { createElement, Fragment, type ReactNode } from "react";
import { renderToStaticMarkup } from "react-dom/server";
import { beforeEach, describe, expect, it, vi } from "vitest";
const content = vi.hoisted(() => ({
installed: true,
update: true,
bundled: false,
packs: [{
id: "characters:test",
label: "Test Characters",
bytes: 1024,
fileCount: 1,
bundledOnAndroid: false,
dependencies: [],
}],
install: vi.fn(async () => undefined),
remove: vi.fn(async () => undefined),
}));
vi.mock("@capacitor/core", () => ({
Capacitor: { isNativePlatform: () => false },
}));
vi.mock("../content/contentManager", () => ({
checkForContentUpdates: vi.fn(async () => null),
contentPackHasUpdate: () => content.update,
contentPackIsBundled: () => content.bundled,
contentPackIsInstalled: () => content.installed,
installContentPack: content.install,
removeContentPack: content.remove,
}));
vi.mock("../content/useContentManager", () => ({
useContentManagerSnapshot: () => ({
revision: 1,
checking: false,
manifest: {
version: "content-test",
packs: content.packs,
},
bundledManifest: null,
installingPackId: null,
downloadedBytes: 0,
totalBytes: 0,
error: "",
}),
}));
vi.mock("../components/DualDisplayFrame", () => ({
DualDisplayFrame: ({ top }: { readonly top: ReactNode }) => createElement(Fragment, null, top),
}));
vi.mock("./LazyLocalCompanionPanel", () => ({
LazyLocalCompanionPanel: () => null,
}));
import { ContentManagerScreen } from "./ContentManagerScreen";
describe("browser Downloads actions", () => {
beforeEach(() => {
content.installed = true;
content.update = true;
content.bundled = false;
content.packs = [{
id: "characters:test", label: "Test Characters", bytes: 1024,
fileCount: 1, bundledOnAndroid: false, dependencies: [],
}];
});
it("offers an update action when an installed browser pack has changed", () => {
const markup = renderToStaticMarkup(createElement(ContentManagerScreen, { onClose: () => undefined }));
expect(markup).toContain("Update available");
expect(markup).toContain(">Update</button>");
expect(markup).toContain(">Remove</button>");
});
it("offers download and remove actions for optional browser packs", () => {
content.installed = false;
content.update = false;
let markup = renderToStaticMarkup(createElement(ContentManagerScreen, { onClose: () => undefined }));
expect(markup).toContain("Not installed");
expect(markup).toContain(">Download</button>");
content.installed = true;
markup = renderToStaticMarkup(createElement(ContentManagerScreen, { onClose: () => undefined }));
expect(markup).toContain("Installed — offline ready");
expect(markup).toContain(">Remove</button>");
});
it("does not offer removal for bundled browser basics", () => {
content.update = false;
content.bundled = true;
const markup = renderToStaticMarkup(createElement(ContentManagerScreen, { onClose: () => undefined }));
expect(markup).toContain("Included — always available");
expect(markup).not.toContain(">Remove</button>");
});
it("hides shelved and internal dependency packs from Downloads", () => {
content.packs = [
...content.packs,
{ id: "core:arenas", label: "Rated Arenas", bytes: 1, fileCount: 1, bundledOnAndroid: false, dependencies: [] },
{ id: "manastorm:deadmines", label: "Deadmines Manastorm", bytes: 1, fileCount: 1, bundledOnAndroid: false, dependencies: [] },
{ id: "creatures:deadmines", label: "Deadmines Creatures", bytes: 1, fileCount: 1, bundledOnAndroid: false, dependencies: [] },
];
const markup = renderToStaticMarkup(createElement(ContentManagerScreen, { onClose: () => undefined }));
expect(markup).toContain("Test Characters");
expect(markup).not.toContain("Rated Arenas");
expect(markup).not.toContain("Deadmines Manastorm");
expect(markup).not.toContain("Deadmines Creatures");
});
});