import assert from 'node:assert/strict'; import test from 'node:test'; import {readFile} from 'node:fs/promises'; import {createElement as h} from 'react'; import {renderToStaticMarkup} from 'react-dom/server'; import {LoadingRegion,Description,SettingsCard,ComparisonTable} from '../packages/ui-react/dist/index.js'; test('composed loading draws exactly one owner even with multiple pending descendants',()=>{ const child=h(LoadingRegion,{loading:true,label:'child'},h('span',null,'retained')); const markup=renderToStaticMarkup(h(LoadingRegion,{aggregate:true,loading:true,label:'equipment'},child,child,h(LoadingRegion,{aggregate:true,loading:true,label:'nested'},child))); assert.equal((markup.match(/role="status"/g)||[]).length,1);assert.match(markup,/aria-label="equipment"/);assert.equal((markup.match(/retained/g)||[]).length,3); }); test('independent surfaces keep their loaders and resolved content has no indicator',()=>{ const markup=renderToStaticMarkup(h('div',null,h(LoadingRegion,{loading:true,label:'a'}),h(LoadingRegion,{loading:true,label:'b'}))); assert.equal((markup.match(/role="status"/g)||[]).length,2); assert.doesNotMatch(renderToStaticMarkup(h(LoadingRegion,{aggregate:true,loading:false,label:'done'},h(LoadingRegion,{loading:false,label:'child'},'ready'))),/role="status"/); }); test('comparison has one label column, arbitrary entity columns and semantic headers',()=>{ for(const count of [1,2,3,4,8]){ const markup=renderToStaticMarkup(h(ComparisonTable,{label:'VESC',heading:'VESC',columns:Array.from({length:count},(_,i)=>({id:String(i),label:'id'+i})),rows:[{id:'position',label:'Расположение',cells:Array(count).fill('Левый')},{id:'current',label:'Ток',cells:[]}]})); assert.equal((markup.match(/scope="col"/g)||[]).length,count+1);assert.equal((markup.match(/scope="row"/g)||[]).length,2);assert.equal((markup.match(//g)||[]).length,2*count);assert.match(markup,/tabindex="0"/); } }); test('SettingsCard and standalone explanatory paragraphs use one typography component',()=>{ assert.match(renderToStaticMarkup(h(Description,null,'help')),/class="nodedc-description"/); assert.match(renderToStaticMarkup(h(SettingsCard,{title:'Settings',description:'help'})),/

help/); }); test('legacy card paragraphs and live descriptions share small muted typography, without targeting controls',async()=>{ const css=await readFile(new URL('../packages/ui-core/styles.css',import.meta.url),'utf8'); const blocks=[...css.matchAll(/([^{}]+)\{([^{}]*)\}/g)].map(([,selectors,body])=>({selectors,body})); const copy=blocks.find(b=>b.selectors.includes('.nodedc-description')&&b.body.includes('font-size:')); assert.ok(copy); assert.match(copy.selectors,/\.nodedc-settings-card__titles p/); assert.match(copy.selectors,/\.nodedc-settings-card__body :where\(p:not\(\[class\]\)\)/); for(const declaration of ['font-family: inherit','font-weight: 400','color: var(--nodedc-text-muted)','font-size: var(--nodedc-font-size-sm)','line-height: 1.4'])assert.ok(copy.body.includes(declaration),declaration); assert.doesNotMatch(copy.selectors,/h[1-6]|button|input|select/); const markup=renderToStaticMarkup(h(Description,{role:'status','aria-live':'polite'},'Waiting for device')); assert.match(markup,/role="status"/);assert.match(markup,/aria-live="polite"/);assert.match(markup,/class="nodedc-description"/); });