@@ -8,9 +8,14 @@ import {
88 getContextAPIs ,
99 getContextTokens ,
1010 getPublishedPackageNames ,
11+ searchContextAPIs ,
1112 type PartialAPIResult
1213} from './utils.js' ;
1314
15+ vi . mock ( '@internals/metadata' , ( ) => ( {
16+ ApiService : { search : vi . fn ( ) }
17+ } ) ) ;
18+
1419describe ( 'getPublishedPackageNames' , ( ) => {
1520 const projects = [
1621 {
@@ -613,4 +618,88 @@ describe('attributeMetadataToMarkdown', () => {
613618
614619 expect ( markdown . includes ( '| `disabled` | `string` |`true` |' ) ) . toBe ( true ) ;
615620 } ) ;
621+
622+ it ( 'should use the built-in example for nve-layout' , ( ) => {
623+ const attribute : Attribute = {
624+ name : 'nve-layout' ,
625+ description : 'Layout utility attribute' ,
626+ example : '' ,
627+ markdown : '' ,
628+ values : [ { name : 'row' } , { name : 'column' } ]
629+ } ;
630+
631+ const markdown = attributeMetadataToMarkdown ( attribute ) ;
632+
633+ expect ( markdown ) . toContain ( '## nve-layout' ) ;
634+ expect ( markdown ) . toContain ( 'nve-layout="row gap:sm"' ) ;
635+ expect ( markdown ) . toContain ( 'nve-layout="grid gap:sm span-items:6"' ) ;
636+ } ) ;
637+
638+ it ( 'should use the built-in example for nve-text' , ( ) => {
639+ const attribute : Attribute = {
640+ name : 'nve-text' ,
641+ description : 'Typography utility attribute' ,
642+ example : '' ,
643+ markdown : '' ,
644+ values : [ { name : 'heading' } , { name : 'body' } ]
645+ } ;
646+
647+ const markdown = attributeMetadataToMarkdown ( attribute ) ;
648+
649+ expect ( markdown ) . toContain ( '## nve-text' ) ;
650+ expect ( markdown ) . toContain ( 'nve-text="heading"' ) ;
651+ expect ( markdown ) . toContain ( 'nve-text="monospace"' ) ;
652+ } ) ;
653+ } ) ;
654+
655+ describe ( 'searchContextAPIs' , ( ) => {
656+ beforeEach ( ( ) => {
657+ vi . clearAllMocks ( ) ;
658+ } ) ;
659+
660+ it ( 'should attach markdown to attribute results that have values' , async ( ) => {
661+ const { ApiService } = await import ( '@internals/metadata' ) ;
662+ vi . mocked ( ApiService . search ) . mockResolvedValue ( [
663+ { name : 'nve-layout' , description : 'Layout utility' , values : [ { name : 'row' } ] , markdown : '' }
664+ ] as never ) ;
665+
666+ const results = ( await searchContextAPIs ( 'layout' ) ) as Attribute [ ] ;
667+
668+ expect ( results ) . toHaveLength ( 1 ) ;
669+ expect ( results [ 0 ] . markdown ) . toContain ( '## nve-layout' ) ;
670+ } ) ;
671+
672+ it ( 'should leave element results without a markdown field untouched' , async ( ) => {
673+ const { ApiService } = await import ( '@internals/metadata' ) ;
674+ vi . mocked ( ApiService . search ) . mockResolvedValue ( [
675+ { name : 'nve-button' , manifest : { metadata : { markdown : 'x' } } }
676+ ] as never ) ;
677+
678+ const results = ( await searchContextAPIs ( 'button' ) ) as Element [ ] ;
679+
680+ expect ( results ) . toHaveLength ( 1 ) ;
681+ expect ( ( results [ 0 ] as Attribute ) . markdown ) . toBeUndefined ( ) ;
682+ } ) ;
683+
684+ it ( 'should limit results to the configured limit' , async ( ) => {
685+ const { ApiService } = await import ( '@internals/metadata' ) ;
686+ vi . mocked ( ApiService . search ) . mockResolvedValue (
687+ Array . from ( { length : 5 } , ( _ , index ) => ( { name : `nve-item-${ index } ` } ) ) as never
688+ ) ;
689+
690+ const results = await searchContextAPIs ( 'item' , { limit : 2 } ) ;
691+
692+ expect ( results ) . toHaveLength ( 2 ) ;
693+ } ) ;
694+
695+ it ( 'should return every result when no limit is provided' , async ( ) => {
696+ const { ApiService } = await import ( '@internals/metadata' ) ;
697+ vi . mocked ( ApiService . search ) . mockResolvedValue (
698+ Array . from ( { length : 5 } , ( _ , index ) => ( { name : `nve-item-${ index } ` } ) ) as never
699+ ) ;
700+
701+ const results = await searchContextAPIs ( 'item' , { } ) ;
702+
703+ expect ( results ) . toHaveLength ( 5 ) ;
704+ } ) ;
616705} ) ;
0 commit comments