Warning, /firebird/packages/firebird-core/src/painters/painter-registration.spec.ts is written in an unsupported language. File is not indexed.
0001 // Painter registration rejects reserved knob names (they collide with keys
0002 // the display owns), and keeps accepting the built-in painters.
0003 import { Object3D } from 'three';
0004 import { DataModelPainter } from './data-model-painter';
0005 import {
0006 EventPiecePainter,
0007 PainterMeta,
0008 RESERVED_PAINTER_KNOB_KEYS,
0009 assertPainterKnobKeys,
0010 } from './event-piece-painter';
0011 import { TrajectoryPainter } from './trajectory.painter';
0012 import { BatchedTrajectoryPainter } from './batched-trajectory.painter';
0013 import { BoxHitSimplePainter } from './box-hit-simple.painter';
0014
0015 function painterWithKnob(key: string) {
0016 return class extends EventPiecePainter {
0017 static meta: PainterMeta = {
0018 id: `knob-${key}`,
0019 forPieceTypes: ['spec.Type'],
0020 configs: [{ key: 'width', default: 1 }, { key, default: true }],
0021 };
0022 paint(): void { /* nothing to draw */ }
0023 override dispose(): void { /* nothing to free */ }
0024 };
0025 }
0026
0027 describe('painter registration', () => {
0028 it('reserves the knob names time and visible', () => {
0029 expect([...RESERVED_PAINTER_KNOB_KEYS].sort()).toEqual(['time', 'visible']);
0030 });
0031
0032 for (const reserved of ['time', 'visible']) {
0033 it(`throws for a painter that declares the knob '${reserved}'`, () => {
0034 const registry = new DataModelPainter();
0035 const painterClass = painterWithKnob(reserved);
0036 expect(() => registry.registerPainter('spec.Type', painterClass))
0037 .toThrowError(new RegExp(`'knob-${reserved}'.*'${reserved}'.*reserved`));
0038 expect(registry.piecePainterRegistry['spec.Type'] ?? []).not.toContain(painterClass);
0039 });
0040 }
0041
0042 it('accepts other knob names and painters without meta', () => {
0043 const registry = new DataModelPainter();
0044 expect(() => registry.registerPainter('spec.Type', painterWithKnob('visibleFraction'))).not.toThrow();
0045 class NoMeta extends EventPiecePainter {
0046 constructor(node: Object3D, piece: any) { super(node, piece); }
0047 paint(): void { /* nothing to draw */ }
0048 override dispose(): void { /* nothing to free */ }
0049 }
0050 expect(() => assertPainterKnobKeys(NoMeta)).not.toThrow();
0051 });
0052
0053 it('accepts the built-in painters', () => {
0054 for (const painterClass of [TrajectoryPainter, BatchedTrajectoryPainter, BoxHitSimplePainter]) {
0055 expect(() => assertPainterKnobKeys(painterClass)).not.toThrow();
0056 }
0057 });
0058 });