/** * The empty host the Inspector, the Variables tab and the Tilemap panel build their rows into: what * each panel hands in reaches the rows, and folding a group lays the scroll out anew. */ import { describe, expect, it, vi } from 'vitest'; import { createEmptyProject } from '../../src/core/model/Project'; import { emptyHost } from '../../src/editor/inspector/host'; import { EditorState } from '../../src/editor/state'; import type { ScrollContainer } from '../../src/ui'; function setup() { const state = new EditorState(); state.loadProject(createEmptyProject('p', 'P'), 1); const scroll = { relayoutContent: vi.fn() }; return { state, scroll, asScroll: scroll as unknown as ScrollContainer }; } describe('an empty inspector host', () => { it('carries what the panel hands in, and nothing live without it', () => { const { state, asScroll } = setup(); const live = { hp: 3 }; const follow = vi.fn(); const host = emptyHost(state, asScroll, { foldScope: 'variables', listLimit: 7, liveVariables: () => live, followReference: follow, }); expect(host.foldScope).toBe('variables'); expect(host.listLimit).toBe(7); expect(host.liveVariables('any')).toBe(live); expect(host.followReference).toBe(follow); const plain = emptyHost(state, asScroll); expect(plain.foldScope).toBeUndefined(); expect(plain.liveVariables('any')).toBeNull(); host.body.destroy({ children: true }); plain.body.destroy({ children: true }); }); it('reads the project through the state, which a load replaces', () => { const { state, asScroll } = setup(); const host = emptyHost(state, asScroll); state.loadProject(createEmptyProject('q', 'Q'), 1); expect(host.project().id).toBe('q'); host.body.destroy({ children: true }); }); it('lays the scroll out anew when a group folds', () => { const { state, scroll, asScroll } = setup(); const host = emptyHost(state, asScroll); (host.body as unknown as { onFold: () => void }).onFold(); expect(scroll.relayoutContent).toHaveBeenCalledTimes(1); host.body.destroy({ children: true }); }); });