/** * Opening an asset (double-click, Enter, creating one) is selecting it plus a request for its tab. * The editor switches on `open`, never on `selection` alone – so the order and the "already * selected" case are what matter here. */ import { describe, expect, it } from 'vitest'; import { CreateAssetCommand } from '../../src/core/commands/assetCommands'; import { createEmptyProject } from '../../src/core/model/Project'; import { EditorState } from '../../src/editor/state'; function setup(): { state: EditorState; assetId: string; events: string[] } { const state = new EditorState(); state.loadProject(createEmptyProject('p', 'P'), 1); const create = new CreateAssetCommand('behavior', 'B'); expect(state.execute(create)).toBe(true); const events: string[] = []; state.on('selection', () => events.push('selection')); state.on('open', () => events.push('open')); return { state, assetId: create.asset.id, events }; } describe('opening an asset', () => { it('selects it first and asks for the tab after, so the tab finds the selection in place', () => { const { state, assetId, events } = setup(); state.openAsset(assetId); expect(state.selection).toEqual({ kind: 'asset', assetId }); expect(events).toEqual(['selection', 'open']); }); it('still asks for the tab when the asset was selected already – a click did not open it', () => { const { state, assetId, events } = setup(); state.select({ kind: 'asset', assetId }); events.length = 0; state.openAsset(assetId); expect(events).toEqual(['open']); }); it('never fires on a plain selection', () => { const { state, assetId, events } = setup(); state.select({ kind: 'asset', assetId }); expect(events).toEqual(['selection']); }); });