@@ -32,7 +32,6 @@ describe('ApiResourceExampleDocument', () => {
3232 return localStorage . jsonTableEnabled ;
3333 }
3434
35-
3635 describe ( '_tableChanged()' , ( ) => {
3736 let element = /** @type ApiResourceExampleDocument */ ( null ) ;
3837 beforeEach ( async ( ) => {
@@ -312,6 +311,23 @@ describe('ApiResourceExampleDocument', () => {
312311 return element . _ensureArray ( schema [ key ] ) ;
313312 }
314313
314+ async function resolveWhenReady ( elm , model , path , method , payloadIndex ) {
315+ return new Promise ( ( resolve ) => {
316+ let payload = getPayload ( elm , model , path , method ) ;
317+ if ( payloadIndex !== undefined ) {
318+ payload = payload [ payloadIndex ]
319+ }
320+ elm . examples = payload ;
321+ elm . addEventListener ( 'has-examples-changed' , function f ( e ) {
322+ if ( ! e . detail . value ) {
323+ return ;
324+ }
325+ elm . removeEventListener ( 'has-examples-changed' , f ) ;
326+ setTimeout ( ( ) => resolve ( ) ) ;
327+ } ) ;
328+ } ) ;
329+ }
330+
315331 describe ( '__computeExamples()' , ( ) => {
316332 [
317333 [ 'Regular model' , false ] ,
@@ -529,6 +545,34 @@ describe('ApiResourceExampleDocument', () => {
529545 } ) ;
530546 } ) ;
531547
548+ describe ( 'APIC-332' , ( ) => {
549+ [
550+ [ 'Regular model' , false ] ,
551+ [ 'Compact model' , true ]
552+ ] . forEach ( ( item ) => {
553+ describe ( String ( item [ 0 ] ) , ( ) => {
554+ let amf ;
555+ before ( async ( ) => {
556+ amf = await AmfLoader . load ( item [ 1 ] , 'APIC-332' ) ;
557+ } ) ;
558+
559+ let element = /** @type ApiResourceExampleDocument */ ( null ) ;
560+ beforeEach ( async ( ) => {
561+ element = await basicFixture ( ) ;
562+ element . amf = amf ;
563+ await nextFrame ( ) ;
564+ } ) ;
565+
566+ it ( 'renders description for an example' , async ( ) => {
567+ element . mediaType = 'application/json' ;
568+ await resolveWhenReady ( element , amf , '/organization' , 'post' , 0 ) ;
569+ const description = /** @type HTMLElement */ ( element . shadowRoot . querySelector ( '.example-description' ) ) ;
570+ assert . equal ( description . innerText , 'This description for the example is never shown' ) ;
571+ } ) ;
572+ } ) ;
573+ } ) ;
574+ } ) ;
575+
532576 describe ( '_computeExampleTitle()' , ( ) => {
533577 let element = /** @type ApiResourceExampleDocument */ ( null ) ;
534578
@@ -562,6 +606,29 @@ describe('ApiResourceExampleDocument', () => {
562606 } ) ;
563607 } ) ;
564608
609+ describe ( '_computeExampleDescription()' , ( ) => {
610+ let element = /** @type ApiResourceExampleDocument */ ( null ) ;
611+
612+ beforeEach ( async ( ) => {
613+ element = await basicFixture ( ) ;
614+ await nextFrame ( ) ;
615+ } ) ;
616+
617+ it ( 'returns empty if no description is present' , ( ) => {
618+ const example = { } ;
619+ const description = element . _computeExampleDescription ( example ) ;
620+ assert . equal ( description , '' ) ;
621+ } ) ;
622+
623+ it ( 'returns description if present' , ( ) => {
624+ const example = {
625+ description : "example description" ,
626+ } ;
627+ const title = element . _computeExampleDescription ( example ) ;
628+ assert . equal ( title , example . description ) ;
629+ } ) ;
630+ } ) ;
631+
565632 describe ( 'a11y' , ( ) => {
566633 let element = /** @type ApiResourceExampleDocument */ ( null ) ;
567634 let amf ;
@@ -574,20 +641,6 @@ describe('ApiResourceExampleDocument', () => {
574641 element . amf = amf ;
575642 } ) ;
576643
577- async function resolveWhenReady ( elm , model , path , method ) {
578- return new Promise ( ( resolve ) => {
579- const payloads = getPayload ( elm , model , path , method ) ;
580- elm . examples = payloads ;
581- elm . addEventListener ( 'has-examples-changed' , function f ( e ) {
582- if ( ! e . detail . value ) {
583- return ;
584- }
585- elm . removeEventListener ( 'has-examples-changed' , f ) ;
586- setTimeout ( ( ) => resolve ( ) ) ;
587- } ) ;
588- } ) ;
589- }
590-
591644 it ( 'passes accessibility test' , async ( ) => {
592645 await resolveWhenReady ( element , amf , '/IncludedInType' , 'post' ) ;
593646 await assert . isAccessible ( element , {
0 commit comments