/** * What the inspector of a *placed* behavior lists. Every variable a behavior declares is a property * of the object it sits on; what a run shares lives on a Variables asset instead, which is never * placed and so has no object to show rows on. */ import { describe, expect, it } from 'vitest'; import { AddVariableCommand, RemoveVariableCommand } from '../../src/core/commands/variableCommands'; import { isPlaceableType } from '../../src/core/model/AssetTypes'; import { findAsset } from '../../src/core/model/Project'; import { objectRows } from '../../src/editor/inspector/objectSection'; import { makeBehavior, makeSpriteScene, place } from '../helpers'; describe('the rows of a placed behavior', () => { it('lists every variable it declares', () => { const f = makeSpriteScene(); const behavior = makeBehavior(f, 'Counter', ['score', 'lives']); const objectId = place(f, behavior.id, { x: 0, y: 0 }); const rows = () => { const asset = findAsset(f.project, behavior.id)!; return objectRows(f.project, asset, f.object(objectId)).map((def) => def.key); }; expect(rows()).toEqual(['score', 'lives']); f.stack.execute(new RemoveVariableCommand(behavior.id, 'score')); expect(rows()).toEqual(['lives']); f.stack.execute(new AddVariableCommand(behavior.id, 'coins', 'number')); expect(rows()).toEqual(['lives', 'coins']); }); it('cannot place a Variables asset, so its values need no rows', () => { expect(isPlaceableType('variables')).toBe(false); }); });