@@ -2,11 +2,19 @@ import { fixture, assert, html, aTimeout, waitUntil } from '@open-wc/testing';
22import { AmfLoader , ApiDescribe } from './amf-loader.js' ;
33import '../api-console.js' ;
44import {
5- documentationDocument ,
6- documentationPanel , documentationSecurity ,
7- documentationSummary , documentationType , navigationSelectDocumentation ,
8- navigationSelectDocumentationSection , navigationSelectSecurity , navigationSelectSecuritySection ,
9- navigationSelectSummarySection , navigationSelectType , navigationSelectTypesSection
5+ documentationDocument , documentationEndpoint , documentationMethod ,
6+ documentationPanel ,
7+ documentationSecurity ,
8+ documentationSummary ,
9+ documentationType ,
10+ navigationSelectDocumentation ,
11+ navigationSelectDocumentationSection , navigationSelectEndpointMethod ,
12+ navigationSelectEndpointOverview ,
13+ navigationSelectSecurity ,
14+ navigationSelectSecuritySection ,
15+ navigationSelectSummarySection ,
16+ navigationSelectType ,
17+ navigationSelectTypesSection
1018} from './testHelper.js' ;
1119
1220/** @typedef {import('..').ApiConsole } ApiConsole */
@@ -646,6 +654,119 @@ describe('API Console documentation', () => {
646654 } ) ;
647655 } ) ;
648656 } ) ;
657+
658+ describe ( 'Endpoint section' , ( ) => {
659+ let docShadowRoot ;
660+
661+ [ true , false ] . forEach ( ( noOverview ) => {
662+ describe ( `No overview ${ noOverview ? 'enabled' : 'disabled' } ` , ( ) => {
663+ beforeEach ( async ( ) => {
664+ element . noOverview = noOverview ;
665+ await aTimeout ( 50 ) ;
666+ await navigationSelectEndpointOverview ( element , '/test-query-parameters' , noOverview ) ;
667+ await aTimeout ( 100 ) ;
668+ const item = documentationEndpoint ( element ) ;
669+ docShadowRoot = item . shadowRoot ;
670+ } ) ;
671+
672+ it ( 'should render endpoint title' , ( ) => {
673+ assert . equal ( docShadowRoot . querySelector ( '.title' ) . innerText , 'Query Parameters' ) ;
674+ } ) ;
675+
676+ it ( 'should render URL' , ( ) => {
677+ assert . equal ( docShadowRoot . querySelector ( 'api-url' ) . shadowRoot . querySelector ( '.url-area' ) . innerText . trim ( ) , 'https://example/test-query-parameters' ) ;
678+ } ) ;
679+
680+ it ( 'should render description' , ( ) => {
681+ assert . equal ( docShadowRoot . querySelector ( 'arc-marked' ) . querySelector ( '.markdown-body' ) . innerText . trim ( ) , 'Query parameters endpoint' ) ;
682+ } ) ;
683+
684+ it ( 'should render methods' , ( ) => {
685+ const methodsSection = docShadowRoot . querySelector ( '.methods' ) ;
686+ assert . exists ( methodsSection ) ;
687+
688+ const methods = methodsSection . querySelectorAll ( '.method' ) ;
689+ assert . lengthOf ( methods , 3 ) ;
690+ assert . equal ( methods [ 0 ] . querySelector ( '.method-label' ) . innerText , 'POST' ) ;
691+ assert . equal ( methods [ 0 ] . querySelector ( 'arc-marked' ) . querySelector ( '.markdown-body' ) . innerText . trim ( ) , 'Post method description' ) ;
692+ assert . equal ( methods [ 1 ] . querySelector ( '.method-label' ) . innerText , 'PUT' ) ;
693+ assert . equal ( methods [ 2 ] . querySelector ( '.method-label' ) . innerText , 'GET' ) ;
694+ } ) ;
695+ } ) ;
696+ } ) ;
697+ } ) ;
698+
699+ describe ( 'Method section' , ( ) => {
700+ let docShadowRoot ;
701+
702+ beforeEach ( async ( ) => {
703+ await navigationSelectEndpointMethod ( element , '/test-query-parameters' , 'post' ) ;
704+ await aTimeout ( 100 ) ;
705+ const item = documentationMethod ( element ) ;
706+ docShadowRoot = item . shadowRoot ;
707+ } ) ;
708+
709+ it ( 'should render endpoint title' , ( ) => {
710+ assert . equal ( docShadowRoot . querySelector ( '.title' ) . innerText , 'Post' ) ;
711+ } ) ;
712+
713+ it ( 'should render URL' , ( ) => {
714+ const urlArea = docShadowRoot . querySelector ( 'api-url' ) . shadowRoot . querySelector ( '.url-area' ) ;
715+ assert . equal ( urlArea . querySelector ( '.method-label' ) . innerText , 'POST' ) ;
716+ assert . equal ( urlArea . querySelector ( '.url-value' ) . innerText , 'https://example/test-query-parameters' ) ;
717+ } ) ;
718+
719+ it ( 'should render code examples section' , async ( ) => {
720+ const codeExamples = docShadowRoot . querySelector ( '.snippets' ) ;
721+ assert . exists ( codeExamples ) ;
722+ assert . equal ( codeExamples . querySelector ( '.heading3.table-title' ) . innerText , 'Code examples' ) ;
723+
724+ const toggleButton = codeExamples . querySelector ( '.toggle-button' ) ;
725+ assert . exists ( toggleButton ) ;
726+ toggleButton . click ( ) ;
727+ await aTimeout ( 50 ) ;
728+
729+ const codes = codeExamples . querySelector ( 'anypoint-collapse' ) . querySelector ( 'http-code-snippets' ) . shadowRoot ;
730+ assert . exists ( codes . querySelector ( 'curl-http-snippet' ) ) ;
731+
732+ waitUntil ( ( ) => codes . querySelector ( 'anypoint-tab' ) ) ;
733+ const tabs = codes . querySelectorAll ( 'anypoint-tab' ) ;
734+ assert . lengthOf ( tabs , 6 ) ;
735+ // assert.equal(tabs[0].innerText, 'CURL')
736+ // assert.equal(tabs[1].innerText, 'HTTP')
737+ // assert.equal(tabs[2].innerText, 'JAVASCRIPT')
738+ // assert.equal(tabs[3].innerText, 'PYTHON')
739+ // assert.equal(tabs[4].innerText, 'C')
740+ // assert.equal(tabs[5].innerText, 'JAVA')
741+ } ) ;
742+
743+ it ( 'should render query parameters section' , async ( ) => {
744+ const parametersSection = docShadowRoot . querySelector ( 'api-parameters-document' ) . shadowRoot ;
745+ assert . exists ( parametersSection ) ;
746+ assert . equal ( parametersSection . querySelector ( '.heading3' ) . innerText , 'Query parameters' ) ;
747+
748+ const collapse = parametersSection . querySelector ( 'anypoint-collapse' ) ;
749+ await testTypeDocumentShape ( collapse , [ { name : 'page' , type : 'Integer' , description : 'Specify the page that you want to retrieve' , required : 'Required' } , { name : 'per_page' , type : 'Integer' , description : 'Specify the amount of items that will be retrieved per page' , required : 'Required' } ] ) ;
750+ await testTypeDocumentExample ( collapse , '1' , [ { label : 'Min value:' , value : '1' } , { label : 'Max value:' , value : '10' } ] ) ;
751+ await testTypeDocumentExample ( collapse , '50' , [ { label : 'Default value:' , value : '30' } , { label : 'Min value:' , value : '10' } , { label : 'Max value:' , value : '200' } ] ) ;
752+ } ) ;
753+
754+ it ( 'should render body section' , async ( ) => {
755+ const parametersSection = docShadowRoot . querySelector ( 'api-body-document' ) . shadowRoot ;
756+ assert . exists ( parametersSection ) ;
757+ assert . equal ( parametersSection . querySelector ( '.heading3' ) . innerText , 'Body' ) ;
758+
759+ const toggleButton = parametersSection . querySelector ( '.toggle-button' ) ;
760+ assert . exists ( toggleButton ) ;
761+ toggleButton . click ( ) ;
762+ await aTimeout ( 0 ) ;
763+
764+ const collapse = parametersSection . querySelector ( 'anypoint-collapse' ) ;
765+ assert . equal ( collapse . querySelector ( '.media-type-selector' ) . innerText , 'Media type: application/json' ) ;
766+ assert . equal ( collapse . querySelector ( '.any-info' ) . innerText , 'Any instance of data is allowed.' ) ;
767+ assert . equal ( collapse . querySelector ( '.any-info-description' ) . innerText , 'The API file specifies body for this request but it does not specify the data model.' ) ;
768+ } ) ;
769+ } ) ;
649770 } ) ;
650771 } ) ;
651772} ) ;
0 commit comments