Files
feuerwerk/tests/core/kinds.test.ts
T
adminandClaude Opus 5.5 0e8585665a
game-maker / gate (push) Successful in 2m47s
game-maker / suite (push) Successful in 8m41s
Load the 500 weight and draw missing glyphs as SVG icons (#214)
The theme asks for Source Sans 3 at weight 500, but fonts.ts only
loaded 400, 600 and 700. The browser synthesised the 500 text. The
issue comment also asked for the symbols the font lacks to become SVG
icons. A scan of src/ against the font's cmap found 20 such characters
in 30 places.

- fonts.ts loads source-sans-3-latin-500-normal.woff2 as well.
- Menus draw their ticks and the "current" dot as icons. The dot is a
  new MenuItem.current field and no longer part of the label text.
- Inspector action buttons (reset, apply, fit width/height) are
  icons. The menu arrow behind them is the drawn Dropdown chevron.
- Kind marks come from a table in markIcons.ts. Picture kinds use an
  icon, # and Aa stay text because the font has them.
- Scene marks in the asset panel, sound play/stop and the transition
  arrows are icons too.
- Apply is an icon although the font has the arrow. It sits next to
  the reset icon and would look different as a glyph.
- A new Icon widget draws on redraw like Button, so Node tests need no
  DOMParser.
- Tests find icons through the SVG id. The new hook
  __gm.locateIcons(id) and the harness helpers findIcon/clickIcon
  replace locate() on the old characters.

Findings:
- Weight 700 is loaded but the theme never uses it. Left as is.
- The old scene-mark check in module 35 accepted any play glyph on
  screen. It now checks the mark on the start scene's row.
- Module 44 needs the textures from module 37 and fails without it.

Tests:
- ./check.sh: 145 files, 2187 tests, exit 0 (before 144 / 2143).
- New tests/ui/fonts.test.ts: every theme weight is loaded, and every
  character in src/ exists in every shipped face. The cmap reader
  matches fontTools (231 characters).
- Icon tests cover the 19 new files. Each kind mark is either an
  icon or text, never both.
- e2e 1-16,22,30,34,35,43,44: 586 green, 0 FAIL, then 44 stopped
  for lack of module 37. e2e 1-16,37,44,47,48: 618 green.
  e2e 1-14 on the final build: 454 green.
- Two new e2e checks: loaded weights in 14, a reset icon pixel in 04.
- Counter-probes all fail as expected: 500 removed, a play glyph put
  back, the struct icon removed (one unit test each). In the browser,
  500 removed and reset icon hidden fail exactly the two new checks.
- Editor-suite check sum 1312 (1310 measured by CI at 056a622, +2).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-23 08:13:22 +02:00

135 lines
5.3 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.
/**
* The kind table is the one place a kind is described. Everything a kind needs – its lists, its
* name and mark, its empty value, its tag, its port – has to follow from the row alone, so each
* check here walks the table rather than naming a kind.
*/
import { describe, expect, it } from 'vitest';
import { AddVariableCommand } from '../../src/core/commands/variableCommands';
import { declaredPortType, portDefOf } from '../../src/core/graph';
import { BUILT_IN_NODES } from '../../src/core/graph/nodes';
import { tagOf, untag } from '../../src/core/model/Properties';
import { findAsset } from '../../src/core/model/Project';
import {
coerceField,
DECLARED_PORT_KINDS,
emptyOf,
FIELD_KINDS,
isKindWith,
isTaggedKind,
KIND,
KINDS,
kindLabel,
kindMark,
LIST_ITEM_KINDS,
plainKindOf,
STRUCT_FIELD_KINDS,
VARIABLE_KINDS,
} from '../../src/core/properties/kinds';
import { itemKindOf, listItemOf, makeItem } from '../../src/core/properties/listItems';
import { deserializeProject } from '../../src/core/store/serialize';
import { makeBehavior, makeProject, roundTrip } from '../helpers';
const TAGGED = FIELD_KINDS.filter(isTaggedKind);
/** A value of the type a tagged kind travels as, distinct from the kind's empty value. */
const sampleOf = (kind: (typeof TAGGED)[number]) => (KIND[kind].travels === 'number' ? 0xff0000 : 'walk-up');
describe('the kind table', () => {
// The marks are held with the pictures that stand in for most of them (tests/ui/svg-icons.test.ts).
it('has a word for every kind a user can pick', () => {
const picked = new Set([...VARIABLE_KINDS, ...FIELD_KINDS, ...DECLARED_PORT_KINDS]);
for (const kind of picked) expect(kindLabel(kind), kind).not.toBe(kind);
expect(kindMark('no such kind')).toBe('?');
});
it('derives the kind lists from the roles, the depth rules on top', () => {
for (const row of KINDS) {
expect(VARIABLE_KINDS.includes(row.kind as never), row.kind).toBe(isKindWith('variable', row.kind));
expect(FIELD_KINDS.includes(row.kind as never), row.kind).toBe(isKindWith('field', row.kind));
expect(DECLARED_PORT_KINDS.includes(row.kind as never), row.kind).toBe(isKindWith('port', row.kind));
}
expect(LIST_ITEM_KINDS).toEqual([...FIELD_KINDS, 'struct']);
expect(STRUCT_FIELD_KINDS).toEqual([...FIELD_KINDS, 'list']);
});
it('reads nothing as the empty value of a kind, and the empty value as itself', () => {
for (const kind of FIELD_KINDS) {
expect(coerceField(undefined, kind), kind).toBe(emptyOf(kind));
expect(coerceField(emptyOf(kind), kind), kind).toBe(emptyOf(kind));
}
});
it('reads a bare value as the untagged kind travelling its way', () => {
for (const kind of FIELD_KINDS) {
if (isTaggedKind(kind)) continue;
expect(plainKindOf(KIND[kind].travels), kind).toBe(kind);
expect(itemKindOf(emptyOf(kind)), kind).toBe(kind);
}
});
});
describe('a tagged kind', () => {
it('wraps what it reads, and reads back as itself', () => {
for (const kind of TAGGED) {
const item = makeItem(kind, sampleOf(kind));
expect(tagOf(item), kind).toBe(kind);
expect(itemKindOf(item), kind).toBe(kind);
expect(untag(item), kind).toBe(sampleOf(kind));
expect(listItemOf(item), kind).toEqual(item);
// The bare value beside it is the plain kind – which is why the tag is needed at all.
expect(itemKindOf(sampleOf(kind)), kind).toBe(plainKindOf(KIND[kind].travels));
}
});
it('survives a save and load in a list variable and in a node parameter', () => {
for (const kind of TAGGED) {
const item = makeItem(kind, sampleOf(kind));
const f = makeProject();
const behavior = makeBehavior(f, 'B');
f.stack.execute(new AddVariableCommand(behavior.id, 'items', 'list'));
findAsset(f.project, behavior.id)!.props.items = [item, sampleOf(kind)];
expect(findAsset(roundTrip(f.project), behavior.id)?.props.items, kind).toEqual([item, sampleOf(kind)]);
const loaded = deserializeProject({
id: 'p',
assets: [
{
id: 'b',
type: 'behavior',
name: 'B',
graph: { nodes: [{ id: 'n', type: 'List', x: 0, y: 0, params: { value: [item] } }], edges: [] },
},
],
});
const asset = findAsset(loaded, 'b');
expect(asset?.type === 'behavior' && asset.graph.nodes[0]?.params.value, kind).toEqual([item]);
}
});
});
describe('a declared port', () => {
it('travels as the table says, and carries the field that edits it only when tagged', () => {
for (const kind of DECLARED_PORT_KINDS) {
expect(declaredPortType(kind), kind).toBe(KIND[kind].travels);
expect(portDefOf({ key: 'p', kind }).field?.kind, kind).toBe(isTaggedKind(kind) ? kind : undefined);
}
});
});
describe('the literal nodes', () => {
it('are one per kind: named, typed and edited as the kind they hand out', () => {
for (const [type, kind] of [
['Number', 'number'],
['Boolean', 'boolean'],
['String', 'text'],
['Texture', 'texture'],
['StateMachine', 'statemachine'],
['List', 'list'],
] as const) {
const def = BUILT_IN_NODES.find((d) => d.type === type)!;
expect(def.label, type).toBe(kindLabel(kind));
expect(def.outputs[0]?.type, type).toBe(KIND[kind].travels);
expect(def.params[0]?.kind, type).toBe(kind);
}
});
});