Files
Rosea/tools/art-prep/test/manifest.test.ts
T

77 lines
5.1 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import { describe, expect, it } from 'vitest';
import { checkManifest, type Asset, type Manifest } from '../src/manifest.js';
import { reviewPoints } from '../src/style.js';
import { clone, readManifest, readStyle } from './fixtures.js';
const POINTS = reviewPoints(readStyle()).length;
/** The real manifest with one asset changed. */
function withAsset(id: string, change: (a: Record<string, unknown>) => void): Manifest {
const m = clone(readManifest());
const a = m.assets.find((x) => x.id === id) as unknown as Record<string, unknown>;
change(a);
return m;
}
describe('art/manifest.json', () => {
it('passes every check', () => {
expect(checkManifest(readManifest(), POINTS)).toEqual([]);
});
it('asks for the Phase 1 pictures: the rose sheet first, then stages, care, moments, props, chair, four garden layers, the icon', () => {
const m = readManifest();
expect(m.assets[0]?.id).toBe('rose-sheet');
const phase1 = m.assets.filter((a) => a.phase === 1);
const pictures = phase1.flatMap((a: Asset) => (a.cells ? a.cells.map((c) => c.id) : [a.id]));
expect(pictures).toHaveLength(25);
expect(pictures).toEqual(expect.arrayContaining(['rose-bud', 'rose-full-bloom', 'rose-waiting', 'petal-folded', 'garden-chair', 'garden-sunset', 'garden-night', 'app-icon']));
});
it('then Phase 2, the fox sheet first, and the decided Phase 3 pictures: 28 more', () => {
const m = readManifest();
const later = m.assets.filter((a) => a.phase > 1);
expect(later[0]?.id).toBe('fox-sheet');
const pictures = later.flatMap((a: Asset) => (a.cells ? a.cells.map((c) => c.id) : [a.id]));
expect(pictures).toHaveLength(28);
expect(pictures).toEqual(expect.arrayContaining(['fox-watching', 'fox-petted', 'fox-asleep', 'rose-hips', 'bush-ripe', 'fox-brush', 'path-road', 'lantern-lit']));
expect(new Set(m.assets.map((a) => a.phase))).toEqual(new Set([1, 2, 3]));
});
});
describe('checkManifest refuses', () => {
const cases: [string, Manifest, RegExp][] = [
['an id used twice', withAsset('garden-day', (a) => { a.id = 'garden-night'; }), /used twice/],
['a cell id that repeats an asset id', withAsset('care-props-sheet', (a) => { (a.cells as { id: string }[])[0]!.id = 'garden-chair'; }), /garden-chair.*used twice/],
['an id that is not lower-case words', withAsset('garden-day', (a) => { a.id = 'Garden_Day'; }), /lower-case/],
['a size no generator offers', withAsset('garden-chair', (a) => { a.width = 2048; }), /not a size image generators offer/],
['a grid whose cells do not match', withAsset('rose-stages-sheet', (a) => { a.grid = { cols: 3, rows: 1 }; }), /4 cells for a 3 × 1 grid/],
['a grid that does not divide the sheet', withAsset('care-props-sheet', (a) => { a.grid = { cols: 3, rows: 3 }; (a.cells as unknown[]).push({ id: 'x-1', does: 'x' }, { id: 'x-2', does: 'x' }, { id: 'x-3', does: 'x' }); }), /does not divide/],
['a grid on a single picture', withAsset('garden-chair', (a) => { a.grid = { cols: 1, rows: 1 }; }), /only a sprite sheet/],
['an unknown character', withAsset('app-icon', (a) => { a.character = 'owl'; }), /unknown character "owl"/],
['a shipped character sheet', withAsset('rose-sheet', (a) => { a.shipped = true; }), /never shipped/],
['a sprite on a full background', withAsset('garden-chair', (a) => { a.background = 'full'; }), /must be transparent/],
['a review point STYLE.md §7 does not have', withAsset('garden-chair', (a) => { a.checks = [0, POINTS]; }), new RegExp(`review point ${POINTS} is not in`)],
['a phase the roadmap does not have', withAsset('garden-chair', (a) => { a.phase = 0; }), /phase 0 is not a roadmap phase/],
['a Phase 1 picture listed after Phase 3', withAsset('lanterns-sheet', (a) => { a.phase = 1; }), /lanterns-sheet: phase 1 comes after phase 3; list the pictures in phase order/],
['a picture with no subject', withAsset('garden-chair', (a) => { delete a.subject; }), /no subject/],
['a picture nobody uses', withAsset('garden-chair', (a) => { a.usedBy = []; }), /usedBy is empty/],
['a name from the book in a prompt', withAsset('garden-chair', (a) => { a.subject = 'a chair for the Little Prince'; }), /"Little Prince" \(little-prince\)/],
['a medical word in a cell', withAsset('rose-care-sheet', (a) => { (a.cells as { does: string }[])[0]!.does = 'thirsty, waiting to be healed'; }), /"healed" \(medical\)/],
['the word the game never says, in the shared avoid list', (() => { const m = clone(readManifest()); (m.avoid as string[]).push('a lonely look'); return m; })(), /avoid list: "lonely"/]
];
for (const [what, manifest, message] of cases) {
it(what, () => {
expect(checkManifest(manifest, POINTS).join('\n')).toMatch(message);
});
}
it('a character whose sheet is missing or not a sheet', () => {
const m = clone(readManifest()) as { characters: Record<string, { sheet: string }> } & Manifest;
m.characters.rose!.sheet = 'garden-chair';
expect(checkManifest(m, POINTS).join('\n')).toMatch(/"garden-chair" is a sprite, not a character sheet/);
m.characters.rose!.sheet = 'nowhere';
expect(checkManifest(m, POINTS).join('\n')).toMatch(/"nowhere" is not in the manifest/);
});
});