// @requirements REQ-PRODUCT-AUTHORED-PREVIEW
// @requirements REQ-PRODUCT-DRAFT-PREVIEW
// @requirements REQ-PRODUCT-CARTRIDGES REQ-PRODUCT-SAFE-CONTENT REQ-PRODUCT-A11Y REQ-PRODUCT-MOBILE
import {test} from 'node:test';
import assert from 'node:assert/strict';
import {JSDOM} from 'jsdom';
import {mountLegalPreview} from '@notabenda/core/setup/preview';
import {mountSetup} from '@notabenda/core/setup/ui';
import {selectCartridges} from '@notabenda/core/cartridges';
import {fixture} from './helpers.mjs';
function browser(){
const dom=new JSDOM('',{url:'https://adopter.example.test/setup'}),d=dom.window.document;
dom.window.HTMLDialogElement.prototype.showModal=function(){if(!this.isConnected)throw Error('Disconnected');this.open=true;};
dom.window.HTMLDialogElement.prototype.close=function(){if(!this.open)return;this.open=false;this.dispatchEvent(new dom.window.Event('close'));};
dom.window.URL.createObjectURL=()=> 'blob:fixture';dom.window.URL.revokeObjectURL=()=>{};
return {dom,d};
}
test('page preview projects declared public facts without publishing, persisting or changing review status',async()=>{
const config=await fixture(),before=structuredClone(config),{dom,d}=browser();let effects=0;
dom.window.fetch=()=>{effects++;throw Error('No network');};dom.window.Storage.prototype.setItem=()=>{effects++;throw Error('No persistence');};
const ui=mountLegalPreview(d.querySelector('#mount'),{config});
try{
const dialog=d.querySelector('dialog');assert.equal(dialog.open,false);d.querySelector('#opener').focus();ui.open();assert.equal(dialog.open,true);assert.equal(d.activeElement.textContent,'Configuration preview');
assert.match(dialog.textContent,/Juniper Notes/);assert.match(dialog.textContent,/including placeholders/);assert.match(dialog.textContent,/Draft — for review/);assert.doesNotMatch(dialog.textContent,/Synthetic private note/);assert.deepEqual(config,before);assert.equal(effects,0);
assert.equal(dialog.querySelector('.nb-document').dataset.documentKind,'privacy');
}finally{ui.destroy();dom.window.close();}
});
test('switching documents keeps a fixed snapshot and preserves exact supplied text without executing expressions',async()=>{
const config=await fixture({reviewed:true});config.documents.terms.sections[0].paragraphs.push(' {process.env.SECRET}');
const {dom,d}=browser(),ui=mountLegalPreview(d.querySelector('#mount'),{config,initialDocument:'terms'});
try{
ui.open();assert.equal(d.querySelector('.nb-draft'),null);assert.equal(d.querySelector('dialog script'),null);assert.equal(dom.window.previewExecuted,undefined);assert.match(d.querySelector('dialog').textContent,/