Files

74 lines
3.6 KiB
TypeScript

import { readFileSync, readdirSync } from 'node:fs';
import { describe, expect, it } from 'vitest';
import { boardData } from '../src/board.js';
import { placeholders } from '../src/placeholders.js';
import { clone, readManifest, readStyle, root } from './fixtures.js';
const manifest = readManifest();
const data = boardData(manifest, readStyle());
const stand = placeholders(manifest);
const page = readFileSync(`${root}tools/art-prep/board/index.html`, 'utf8');
describe('the board data', () => {
it('has the shape the board page reads', () => {
for (const a of data.assets) {
expect(a).toMatchObject({ id: expect.any(String), width: expect.any(Number), height: expect.any(Number), prompt: expect.any(String) });
expect(Array.isArray(a.usedBy) && Array.isArray(a.checks) && Array.isArray(a.attach)).toBe(true);
if (a.type === 'spritesheet') {
expect(a.cells).toHaveLength((a.grid?.cols ?? 0) * (a.grid?.rows ?? 0));
for (const c of a.cells ?? []) expect(c).toMatchObject({ id: expect.any(String), width: expect.any(Number), height: expect.any(Number), prompt: expect.any(String) });
}
}
expect(data.checklist).toHaveLength(10);
expect(data.assets.every((a) => Number.isInteger(a.phase))).toBe(true);
});
it('every card says its phase, so a Phase 3 picture is never mistaken for a Phase 1 one', () => {
expect(page).toContain('`Phase ${a.phase} · sprite sheet');
expect(page).toContain('`Phase ${a.phase} · ${a.type}');
});
it('every kind in the manifest has a group on the board page, or its cards would never show', () => {
for (const type of new Set(data.assets.map((a) => a.type))) expect(page).toContain(`{ type: '${type}',`);
});
it('the page takes the product name from @rosea/schema, never spells it', () => {
expect(page).toContain('<title>%PRODUCT_NAME% Art Board</title>');
expect(page).not.toMatch(/Rosea Domi/);
});
it("shows Claude's review and the move into art/final/ when Claude writes them into a row", () => {
expect(page).toMatch(/r\.claude \? `Claude's review: \$\{r\.claude\}`/);
expect(page).toMatch(/r\.final \? `In art\/final\/:/);
});
});
describe('the stand-ins', () => {
it('one for every picture and every cell, at its own size', () => {
const ids = manifest.assets.flatMap((a) => [a.id, ...(a.cells ?? []).map((c) => c.id)]);
expect([...stand.keys()].sort()).toEqual([...ids].sort());
for (const a of manifest.assets) expect(stand.get(a.id)).toContain(`viewBox="0 0 ${a.width} ${a.height}"`);
expect(stand.get('rose-bud')).toContain('viewBox="0 0 384 1024"');
expect(stand.get('watering-can')).toContain('viewBox="0 0 512 512"');
});
it('a picture with no stand-in drawing stops the build, instead of showing an empty box', () => {
const m = clone(manifest);
(m.assets.find((a) => a.id === 'lanterns-sheet')?.cells as unknown as { id: string }[])[1]!.id = 'lantern-blue';
expect(() => placeholders(m)).toThrow(/no stand-in drawing for "lantern-blue"/);
});
it('load nothing from anywhere', () => {
for (const svg of stand.values()) {
expect(svg.replace('xmlns="http://www.w3.org/2000/svg"', '')).not.toMatch(/https?:|href=|<image|<script/);
}
});
it('art/placeholders/ holds exactly what the generator makes (run pnpm art:board after changing the manifest)', () => {
const dir = `${root}art/placeholders/`;
const files = readdirSync(dir).filter((f) => f.endsWith('.svg'));
expect(files.map((f) => f.slice(0, -4)).sort()).toEqual([...stand.keys()].sort());
for (const [id, svg] of stand) expect(readFileSync(`${dir}${id}.svg`, 'utf8').replace(/\r\n/g, '\n')).toBe(svg);
});
});