// Exercise the original UI libraries in a static DOM; browser evidence is separate.
import test from 'node:test';
import assert from 'node:assert/strict';
import fs from 'node:fs';
import {JSDOM} from '../../codex/output/fuc-theme/test-tools/node_modules/jsdom/lib/api.js';
const dom=new JSDOM('
',{url:'http://xb.loc/',runScripts:'outside-only',pretendToBeVisual:true});
for(const key of ['window','document','DOMParser','localStorage'])globalThis[key]=dom.window[key];
globalThis.innerWidth=1280;
const root=document.getElementById('app');
const append=document.head.append.bind(document.head);
document.head.append=node=>{append(node);if(node.tagName==='SCRIPT')queueMicrotask(()=>{try{window.eval(fs.readFileSync(new URL(node.src),'utf8'));node.onload?.();}catch(error){node.onerror?.(error);}});};
const ui=await import('../../theme/Fuc/assets/interactions.mjs');await ui.interactionsReady;
const $=window.jQuery;
const event=(element,name)=>new Promise(resolve=>$(element).one(name,resolve));
test('auth feedback waits for original OK confirmation and subscription reset supports cancel',async()=>{
let finished=false;const notice=ui.authFeedback('登录成功','登录成功').then(()=>finished=true);
await new Promise(resolve=>setTimeout(resolve,0));assert.equal(finished,false);
assert.equal(document.querySelector('.swal2-title').innerText,'登录成功');
assert.equal(document.querySelector('.swal2-confirm').textContent,'OK');
document.querySelector('.swal2-confirm').click();await notice;assert.equal(finished,true);
const confirmation=ui.confirmSubscriptionReset();await new Promise(resolve=>setTimeout(resolve,0));
assert.equal(document.querySelector('.swal2-confirm').textContent,'确定重置');
assert.equal(document.querySelector('.swal2-cancel').textContent,'取消');
document.querySelector('.swal2-cancel').click();assert.equal((await confirmation).value,undefined);
});
test('original modal completes enter and exit before removing backdrop and body lock',async()=>{
assert.equal($.fn.modal.Constructor.VERSION,'4.3.1','landing Bootstrap 5 must not replace user Bootstrap 4');
root.innerHTML='
';
const first=document.getElementById('first'),second=document.getElementById('second'),trigger=root.querySelectorAll('a')[1];
const shown=event(trigger,'shown.bs.tab');ui.selectTab(trigger);await shown;
assert.equal(root.querySelector('#first'),first);assert.equal(root.querySelector('#second'),second);
assert.equal(second.classList.contains('show'),true);assert.equal(first.classList.contains('active'),false);assert.equal(trigger.getAttribute('aria-selected'),'true');
});
test('FAQ collapse animates height and returns to stable collapse classes',async()=>{
root.innerHTML='
Content
';
const target=root.lastElementChild,shown=event(target,'shown.bs.collapse');
ui.toggleCollapse(target,root.firstElementChild);assert.equal(target.classList.contains('collapsing'),true);await shown;
assert.equal(target.classList.contains('show'),true);
assert.equal(root.firstElementChild.getAttribute('aria-expanded'),'true');
const hidden=event(target,'hidden.bs.collapse');ui.toggleCollapse(target,root.firstElementChild);await hidden;
assert.equal(target.className,'collapse');
assert.equal(root.firstElementChild.getAttribute('aria-expanded'),'false');
assert.equal(root.firstElementChild.classList.contains('collapsed'),true);
});
test('FAQ accordion restores the previous arrow when another answer opens',async()=>{
root.innerHTML='
';
const first=root.querySelector('#one'),second=root.querySelector('#two'),buttons=root.querySelectorAll('button');
let shown=event(first,'shown.bs.collapse');ui.toggleCollapse(first,buttons[0]);await shown;
shown=event(second,'shown.bs.collapse');ui.toggleCollapse(second,buttons[1]);await shown;
assert.equal(buttons[0].getAttribute('aria-expanded'),'false');assert.equal(buttons[1].getAttribute('aria-expanded'),'true');
assert.equal(first.classList.contains('show'),false);
});
test('Waves is attached and mobile menu backdrop restores scroll on close',()=>{
root.innerHTML='