Files
feuerwerk/tests/editor/image-grid.test.ts
T
rootandClaude Fable 5.1 6471671f7d Refactor round: ship web/index.html, drop the remote browser, fix stale comments and README
- `.gitignore` said `index.html` unanchored, which also caught the Vite source page;
  a fresh clone could neither `dev` nor `build`. Anchored to `/index.html`, page added.
- Removed GM_REMOTE (tools/remote/gm-browser.ps1 and the ssh/scp branch in browser.mjs):
  the Windows test machine is gone and the only flaky check that lived on it is closed (#37).
- Removed `npm run preview`, undocumented and unused.
- Comments: wrong number in collider.test.ts (250 → 200), the "declarations used to…"
  history in listItems.ts and friends, the 24 px/28 contradiction, section banners in
  nodes/index.ts, node-catalog.test.ts and api/index.php, name paraphrases, and the stale
  step numbers in tools/e2e/11-…23- from the old global count.
- README: asset types include `animation`, kind order Number/Text/Boolean, tagged colour
  and texture items, 6/5 kinds, the `Texture` node, `./build.sh`, PROJECT_FORMAT_VERSION,
  and the file tree (kinds.ts, listItems.ts, propertyPorts.ts, Breadcrumb.ts, beads.ts,
  tools/assets/).
- tests/helpers.ts takes the duplicated `findObject` and `sceneWithCamera`.

Proof: ./check.sh 797 tests, full e2e ALL PASSED 633 checks against this bundle.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
2026-09-12 15:44:05 +02:00

91 lines
3.0 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 {
CAPTION_HEIGHT,
containRect,
gridMetrics,
TILE_GAP,
TILE_MAX,
TILE_MIN,
tileAt,
tileRect,
} from '../../src/editor/texture/imageGrid';
const WIDTH = 560;
describe('gridMetrics', () => {
it('fits as many columns as the width holds, and spreads the leftover across them', () => {
const m = gridMetrics(WIDTH, 7);
expect(m.columns).toBe(5);
expect(m.tile).toBeGreaterThanOrEqual(TILE_MIN);
expect(m.columns * m.tile + (m.columns - 1) * TILE_GAP).toBeLessThanOrEqual(WIDTH);
});
it('keeps one column in a width too narrow for even that', () => {
expect(gridMetrics(40, 3).columns).toBe(1);
});
it('caps a lone tile instead of blowing one picture up over the whole dialog', () => {
expect(gridMetrics(140, 1).tile).toBe(TILE_MAX);
});
it('reports the height the scroll container has to give it', () => {
const m = gridMetrics(WIDTH, 7);
expect(m.rows).toBe(2);
expect(m.height).toBe(2 * (m.tile + CAPTION_HEIGHT) + TILE_GAP);
expect(gridMetrics(WIDTH, 0).height).toBe(0);
});
});
describe('tileRect', () => {
it('lays the tiles out row by row', () => {
const m = gridMetrics(WIDTH, 7);
expect(tileRect(0, m)).toEqual({ x: 0, y: 0, w: m.tile, h: m.tile + CAPTION_HEIGHT });
expect(tileRect(1, m).x).toBe(m.tile + TILE_GAP);
expect(tileRect(1, m).y).toBe(0);
expect(tileRect(m.columns, m)).toEqual({
x: 0,
y: m.tile + CAPTION_HEIGHT + TILE_GAP,
w: m.tile,
h: m.tile + CAPTION_HEIGHT,
});
});
});
describe('tileAt', () => {
const m = gridMetrics(WIDTH, 7);
it('finds the tile a point is on', () => {
expect(tileAt(2, 2, 7, m)).toBe(0);
expect(tileAt(m.tile + TILE_GAP + 2, 2, 7, m)).toBe(1);
expect(tileAt(2, m.tile + CAPTION_HEIGHT + TILE_GAP + 2, 7, m)).toBe(m.columns);
});
it('takes nothing in the gaps between tiles', () => {
expect(tileAt(m.tile + 2, 2, 7, m)).toBe(-1);
expect(tileAt(2, m.tile + CAPTION_HEIGHT + 2, 7, m)).toBe(-1);
});
it('takes nothing past the last tile – the grid is filled to the box height', () => {
// Seven pictures in five columns fill the second row up to place 6; 7 is the first empty one.
expect(tileAt(tileRect(6, m).x + 2, tileRect(6, m).y + 2, 7, m)).toBe(6);
expect(tileAt(tileRect(7, m).x + 2, tileRect(7, m).y + 2, 7, m)).toBe(-1);
expect(tileAt(2, 4000, 7, m)).toBe(-1);
expect(tileAt(-2, 2, 7, m)).toBe(-1);
});
});
describe('containRect', () => {
it('centres a picture and keeps its ratio', () => {
expect(containRect(64, 32, 100, 100)).toEqual({ x: 0, y: 25, w: 100, h: 50 });
expect(containRect(32, 64, 100, 100)).toEqual({ x: 25, y: 0, w: 50, h: 100 });
});
it('blows a small icon up to the box, so it is recognisable next to a sheet', () => {
expect(containRect(16, 16, 100, 100)).toEqual({ x: 0, y: 0, w: 100, h: 100 });
});
it('has nothing to draw for a picture the server could not read', () => {
expect(containRect(0, 0, 100, 100)).toEqual({ x: 0, y: 0, w: 0, h: 0 });
});
});