2026-06-06 11:45:52 +08:00
|
|
|
// test/priority.test.js
|
|
|
|
|
window.testPriority = async function() {
|
|
|
|
|
console.log('Testing directive priorities...');
|
2026-05-18 18:52:38 +08:00
|
|
|
|
2026-06-06 11:45:52 +08:00
|
|
|
// Test $if vs $text (if should hide text)
|
2026-06-10 12:21:29 +08:00
|
|
|
document.body.innerHTML = '<template id="prio-tpl" $if="prioState.show"><div id="prio-test" $text="prioState.msg"></div></template>';
|
|
|
|
|
const state = NewState({ show: true, msg: 'visible' });
|
|
|
|
|
window.prioState = state; // Global for testing
|
2026-06-06 11:45:52 +08:00
|
|
|
document.documentElement._thisObj = { state };
|
2026-06-10 12:21:29 +08:00
|
|
|
globalThis._unsafeRefreshState(document.documentElement);
|
2026-05-18 18:52:38 +08:00
|
|
|
|
2026-06-10 12:21:29 +08:00
|
|
|
await new Promise(r => setTimeout(r, 50));
|
2026-06-06 11:45:52 +08:00
|
|
|
|
2026-06-10 12:21:29 +08:00
|
|
|
const node = $('#prio-test');
|
|
|
|
|
if (!node) throw new Error('Priority visibility failed: node not found');
|
|
|
|
|
if (node.textContent !== 'visible') throw new Error('Priority content failed: ' + node.textContent);
|
|
|
|
|
|
|
|
|
|
state.show = false;
|
|
|
|
|
await new Promise(r => setTimeout(r, 50));
|
2026-06-06 11:45:52 +08:00
|
|
|
if ($('#prio-test')) throw new Error('Priority $if failed: node should be removed');
|
2026-05-18 18:52:38 +08:00
|
|
|
|
2026-06-06 11:45:52 +08:00
|
|
|
console.log('priority.js tests passed');
|
2026-06-10 12:21:29 +08:00
|
|
|
delete window.prioState;
|
2026-05-18 18:52:38 +08:00
|
|
|
return true;
|
|
|
|
|
}
|