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

92 lines
6.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 46 Phase 1 pictures: the rose sheet first, then her stages, care, moments and touch, the care things, chair, garden, letter, icons, the gardener and her planet', () => {
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(46);
expect(pictures).toEqual(expect.arrayContaining([
'rose-bud', 'rose-full-bloom', 'rose-waiting', 'rose-tickled', 'rose-gentle', 'petal-folded', 'weeds-growing',
'watering-can-pouring', 'garden-chair', 'garden-sunset', 'garden-night', 'letter-header', 'app-icon', 'app-icon-maskable', 'favicon-mark',
'gardener-sheet', 'gardener-pour', 'gardener-pull', 'home-planet-day', 'home-planet-night'
]));
});
it('then 52 for Phases 2–5: the fox sheet first, the fox, berries, visitors, mementos, the book, five planet drafts, paths, lanterns, traces, the sky, the share frame', () => {
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(52);
expect(pictures).toEqual(expect.arrayContaining([
'fox-watching', 'fox-petted', 'rose-hips', 'bush-ripe', 'visitor-robin', 'memento-feather', 'geographers-book',
'planet-king', 'planet-geographer', 'path-road', 'lantern-lit', 'petal-trace', 'sky-light', 'wave-lamp-lit', 'foxes-meeting', 'share-frame'
]));
expect(new Set(m.assets.map((a) => a.phase))).toEqual(new Set([1, 2, 3, 4, 5]));
});
it('draws no grown-up on a planet: every planet asks for nobody there', () => {
for (const a of readManifest().assets.filter((x) => x.id.startsWith('planet-'))) {
expect(a.subject).toContain('Nobody is there');
expect(a.avoid).toContain('a person or any figure on the hill');
}
});
});
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/],
['an allowance for a line the shared list does not have', withAsset('gardener-sheet', (a) => { a.allow = ['a dragon']; }), /allows "a dragon", which is not in the shared avoid list/],
['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/);
});
});