Skip to content

Commit f775370

Browse files
authored
test: endpoints and methods documentation (#729)
* test: endpoints and methods documentation * fix: tests * fix: tests
1 parent 3cb66e9 commit f775370

File tree

4 files changed

+155
-5
lines changed

4 files changed

+155
-5
lines changed

demo/models/test-api/test-api.raml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,9 @@ securitySchemes:
199199
securedBy: [passthrough]
200200
/test-query-parameters:
201201
displayName: Query parameters
202+
description: Query parameters endpoint
202203
post:
204+
description: Post method description
203205
queryParameters:
204206
page:
205207
description: Specify the page that you want to retrieve

test/api-console-documentation.test.js

Lines changed: 126 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,19 @@ import { fixture, assert, html, aTimeout, waitUntil } from '@open-wc/testing';
22
import { AmfLoader, ApiDescribe } from './amf-loader.js';
33
import '../api-console.js';
44
import {
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
});

test/testHelper.d.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ export declare function navigationToggleEndpointsSection(element: ApiConsole): E
1313
export declare function navigationEndpointsList(element: ApiConsole): NodeListOf<Element>|null;
1414
export declare function navigationToggleEndpoint(element: ApiConsole, path: string): Element|null;
1515
export declare function navigationSelectEndpointMethod(element: ApiConsole, path: string, method: string): void;
16+
export declare function navigationSelectEndpointOverview(element: ApiConsole, path: string, noOverview: boolean): void;
1617

1718
export declare function navigationDocumentationSection(element: ApiConsole): Element|null;
1819
export declare function navigationDocumentationList(element: ApiConsole): NodeListOf<Element>|null;
@@ -35,6 +36,8 @@ export declare function documentationSummary(element: ApiConsole): Element|null;
3536
export declare function documentationDocument(element: ApiConsole): Element|null;
3637
export declare function documentationSecurity(element: ApiConsole): Element|null;
3738
export declare function documentationType(element: ApiConsole): Element|null;
39+
export declare function documentationEndpoint(element: ApiConsole): Element|null;
40+
export declare function documentationMethod(element: ApiConsole): Element|null;
3841
export declare function documentationTryItButton(element: ApiConsole): Element|null;
3942

4043
/** Request panel * */

test/testHelper.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,20 @@ export const navigationSelectEndpointMethod = async (element, path, method) => {
5454
endpointMethod.parentElement.click();
5555
};
5656

57+
export const navigationSelectEndpointOverview = async (element, path, noOverview) => {
58+
const endpoint = navigationToggleEndpoint(element, path);
59+
await nextFrame();
60+
await nextFrame();
61+
62+
if (noOverview) {
63+
endpoint.querySelector('.endpoint-name-overview').click();
64+
} else {
65+
const endpointOperations = endpoint.nextElementSibling;
66+
const endpointMethod = endpointOperations.querySelector(`[data-endpoint-overview="${path}"]`);
67+
endpointMethod.click();
68+
}
69+
};
70+
5771
export const navigationDocumentationSection = (element) => {
5872
const apiNavigation = navigationTree(element);
5973
return apiNavigation.shadowRoot.querySelector('.documentation');
@@ -143,6 +157,16 @@ export const documentationType = (element) => {
143157
return documentation.shadowRoot.querySelector('api-type-documentation');
144158
};
145159

160+
export const documentationEndpoint = (element) => {
161+
const documentation = documentationPanel(element);
162+
return documentation.shadowRoot.querySelector('api-endpoint-documentation');
163+
};
164+
165+
export const documentationMethod = (element) => {
166+
const documentation = documentationPanel(element);
167+
return documentation.shadowRoot.querySelector('api-method-documentation');
168+
};
169+
146170
export const documentationTryItButton = (element) => {
147171
const documentation = documentationPanel(element);
148172
const methodDocumentation = documentation.shadowRoot.querySelector('api-method-documentation');

0 commit comments

Comments
 (0)