import assert from 'node:assert/strict'; import {test} from 'node:test'; import {OwnedFeedback} from '../../YouleNexus/assets/framework/presentation/owned-feedback.ts'; test('loading owners include legacy platform activity and only last release hides the surface',()=>{ const shown:boolean[]=[];const owned=new OwnedFeedback({loading:v=>shown.push(v),tip(){},closeTip(){}}); const a=owned.beginLoading(),b=owned.beginLoading();owned.setPlatformLoading(true);a.close();b.close();assert.equal(shown[shown.length-1],true); owned.setPlatformLoading(false);assert.equal(shown[shown.length-1],false);a.close();assert.equal(shown.length,6); }); test('closing an old tip owner never closes a newer business or platform tip',()=>{ const log:string[]=[];const owned=new OwnedFeedback({loading(){},tip:message=>log.push(message),closeTip:()=>log.push('closed')}); const first=owned.showBusinessTip('first',1),second=owned.showBusinessTip('second',1);first.close();assert.deepEqual(log,['first','second']); second.close();second.close();assert.deepEqual(log,['first','second','closed']);owned.dispose();assert.throws(()=>owned.beginLoading(),/disposed/); }); test('feedback cleanup attempts both surfaces and old owner handles become inert',()=>{ const log:string[]=[];const owned=new OwnedFeedback({loading:v=>{log.push('loading:'+v);if(!v)throw Error('loading cleanup');},tip(){},closeTip:()=>{log.push('tip');throw Error('tip cleanup');}}); const handle=owned.beginLoading();assert.throws(()=>owned.dispose(),error=>{assert.equal((error as Error&{errors:unknown[]}).errors.length,2);return true;}); assert.deepEqual(log,['loading:true','loading:false','tip']);assert.doesNotThrow(()=>handle.close());assert.doesNotThrow(()=>owned.dispose()); });