import { vi } from 'vitest'; import { renderToElementTemplate } from '../../../../../src/element-template/runtime/render/render-direct.js'; import { resetTemplateId } from '../../../../../src/element-template/runtime/template/handle.js'; import { elementTemplateRegistry } from '../../../../../src/element-template/runtime/template/registry.js'; import { installMockNativePapi } from '../../../test-utils/mock/mockNativePapi.js'; import { registerBuiltinRawTextTemplate, registerTemplates } from '../../../test-utils/debug/registry.js'; export interface RootNode extends ElementTemplateHandle { type: 'page'; children?: unknown[]; } export interface CaseContext { root: RootNode; nativeLog: unknown[]; } const templates = [ { templateId: '_et_builtin_raw_text', compiledTemplate: { kind: 'element', type: 'raw-text', attributesArray: [ { kind: 'slot', key: 'text', attrSlotIndex: 0, }, ], children: [], }, }, { templateId: '_et_foo', compiledTemplate: { kind: 'element', type: 'view', attributesArray: [ { kind: 'slot', key: 'id', attrSlotIndex: 0, }, ], children: [ { kind: 'childSlot', type: 'slot', elementSlotIndex: 0 }, { kind: 'childSlot', type: 'slot', elementSlotIndex: 1 }, ], }, }, { templateId: '_et_parent', compiledTemplate: { kind: 'element', type: 'view', attributesArray: [], children: [{ kind: 'childSlot', type: 'slot', elementSlotIndex: 0 }], }, }, { templateId: '_et_child', compiledTemplate: { kind: 'element', type: 'view', attributesArray: [], children: [] }, }, { templateId: '_et_outer', compiledTemplate: { kind: 'element', type: 'view', attributesArray: [], children: [{ kind: 'childSlot', type: 'slot', elementSlotIndex: 0 }], }, }, { templateId: '_et_inner', compiledTemplate: { kind: 'element', type: 'view', attributesArray: [ { kind: 'slot', key: 'title', attrSlotIndex: 0, }, ], children: [{ kind: 'childSlot', type: 'slot', elementSlotIndex: 0 }], }, }, { templateId: '_et_child_a', compiledTemplate: { kind: 'element', type: 'view', attributesArray: [], children: [] }, }, { templateId: '_et_child_b', compiledTemplate: { kind: 'element', type: 'view', attributesArray: [], children: [] }, }, ]; function setup(): CaseContext { vi.resetAllMocks(); elementTemplateRegistry.clear(); resetTemplateId(); const installed = installMockNativePapi({ clearTemplatesOnCleanup: false }); registerBuiltinRawTextTemplate(); registerTemplates(templates); return { root: __CreateTypedElementTemplate('page', null, null, 0, null) as RootNode, nativeLog: installed.nativeLog, }; } export function runCase(runner: (context: CaseContext) => T): T { const context = setup(); try { return runner(context); } finally { // cleanup is automatic } } export { elementTemplateRegistry, renderToElementTemplate };