2026-05-14 17:12:01 +08:00
|
|
|
// test/component.test.js
|
2026-06-06 11:45:52 +08:00
|
|
|
window.testComponent = async function() {
|
2026-07-04 09:57:23 +08:00
|
|
|
const { Component, __unsafeRefreshState, $ } = ApigoState;
|
2026-05-14 17:12:01 +08:00
|
|
|
console.log('Testing component.js...');
|
|
|
|
|
|
2026-06-06 11:45:52 +08:00
|
|
|
// 1. Register component
|
|
|
|
|
Component.register('TestComp', container => {
|
|
|
|
|
container.state.msg = 'Component Content';
|
2026-07-04 09:57:23 +08:00
|
|
|
}, document.createRange().createContextualFragment('<div><div id="comp-inner" $text="this.state.msg"></div></div>').firstChild);
|
2026-05-14 17:12:01 +08:00
|
|
|
|
2026-06-06 11:45:52 +08:00
|
|
|
// 2. Render component
|
2026-07-04 09:57:23 +08:00
|
|
|
const comp = document.createElement('TestComp');
|
|
|
|
|
comp.id = 'comp-inst';
|
|
|
|
|
document.body.appendChild(comp);
|
|
|
|
|
__unsafeRefreshState(document.documentElement);
|
2026-05-14 17:12:01 +08:00
|
|
|
|
2026-06-06 11:45:52 +08:00
|
|
|
const instance = $('#comp-inst');
|
|
|
|
|
if (!instance) throw new Error('Component instance not found');
|
2026-05-14 17:12:01 +08:00
|
|
|
|
2026-06-11 11:19:59 +08:00
|
|
|
// Wait for internal scan
|
|
|
|
|
await new Promise(r => setTimeout(r, 50));
|
2026-06-06 11:45:52 +08:00
|
|
|
|
|
|
|
|
const inner = $('#comp-inner');
|
|
|
|
|
if (!inner || inner.textContent !== 'Component Content') {
|
2026-05-14 17:12:01 +08:00
|
|
|
console.log('Current instance innerHTML:', instance.innerHTML);
|
2026-06-11 11:19:59 +08:00
|
|
|
throw new Error('Component rendering failed');
|
2026-05-14 17:12:01 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
console.log('component.js tests passed');
|
|
|
|
|
return true;
|
|
|
|
|
}
|