/** * What the inspector shows for a Variables asset: the values of the run while one is on, the * declaration otherwise. A run holds them apart from the document, so the two really do differ – * and a behavior's own variables are properties of an object, never a run's. */ import { describe, expect, it } from 'vitest'; import { SetAssetPropertyCommand } from '../../src/core/commands/assetCommands'; import type { Asset } from '../../src/core/model/Asset'; import type { PropertyBag } from '../../src/core/model/Properties'; import { shownValues } from '../../src/editor/inspector/assetSection'; import type { InspectorHost } from '../../src/editor/inspector/host'; import { EditorState } from '../../src/editor/state'; import { VStack } from '../../src/ui'; import { makeBehavior, makeSpriteScene, makeVariables } from '../helpers'; /** A declaration of `score` = 3, and whatever the run is pretending to hold for it. */ function setup(live: PropertyBag | null) { const f = makeSpriteScene(); const shared = makeVariables(f, 'Score', ['score']); const behavior = makeBehavior(f, 'Counter', ['score']); f.stack.execute(new SetAssetPropertyCommand(shared.id, 'score', 3)); f.stack.execute(new SetAssetPropertyCommand(behavior.id, 'score', 3)); const state = new EditorState(); state.loadProject(f.project, 1); const host: InspectorHost = { state, body: new VStack(), fields: new Map(), nameField: null, project: () => state.project, liveVariables: () => live, }; return { host, shared: shared as Asset, behavior: behavior as Asset }; } describe('the values an asset section shows', () => { it('shows the declaration while nothing runs', () => { const { host, shared } = setup(null); expect(shownValues(host, shared).score).toBe(3); }); it('shows the running value while a run holds one', () => { const { host, shared } = setup({ score: 9 }); expect(shownValues(host, shared).score).toBe(9); }); /** A behavior variable lives on the placed object, so no run holds a value of it to show. */ it('never shows a run value for a behavior', () => { const { host, behavior } = setup({ score: 9 }); expect(shownValues(host, behavior).score).toBe(3); }); });