Skip to content

Commit 68a1595

Browse files
committed
test: navigation for raml fragments
1 parent 3f616c8 commit 68a1595

File tree

10 files changed

+245
-5
lines changed

10 files changed

+245
-5
lines changed

demo/apis.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,14 @@
1919
"models/APIC-557/APIC-557.yaml": "OAS 3.0",
2020
"models/APIC-538/APIC-538.raml": "RAML 1.0",
2121
"models/test-api/test-api.raml": "RAML 1.0",
22+
"models/test-api/basicAuth.raml": "RAML 1.0",
23+
"models/test-api/documentation.raml": "RAML 1.0",
24+
"models/test-api/extension.raml": "RAML 1.0",
25+
"models/test-api/library.raml": "RAML 1.0",
26+
"models/test-api/overlay.raml": "RAML 1.0",
27+
"models/test-api/person.raml": "RAML 1.0",
28+
"models/test-api/resourceType.raml": "RAML 1.0",
29+
"models/test-api/secured.raml": "RAML 1.0",
2230
"models/anyOf/anyOf.yaml": "ASYNC 2.0",
2331
"models/streetlights/streetlights.yaml": "ASYNC 2.0",
2432
"models/visual-tests-raml/visual-tests-raml.raml": "RAML 1.0"
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#%RAML 1.0 SecurityScheme
2+
3+
type: Basic Authentication
4+
displayName: BasicAuth
5+
description: This security scheme validates requests to the API using client ID and client Secret as basic auth
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#%RAML 1.0 DocumentationItem
2+
3+
title: Home
4+
content: |
5+
Welcome to the _Zencoder API_ Documentation. The _Zencoder API_
6+
allows you to connect your application to our encoding service
7+
and encode videos without going through the web interface. You
8+
may also benefit from one of our
9+
[integration libraries](https://app.zencoder.com/docs/faq/basics/libraries)
10+
for different languages.
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#%RAML 1.0 Extension
2+
extends: api.raml
3+
usage: This extension defines additional resources for version 2 of the API.
4+
version: v2
5+
/test-v2:
6+
get:

demo/models/test-api/library.raml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#%RAML 1.0 Library
2+
3+
types:
4+
myType:
5+
properties:
6+
foo: boolean
7+
bar: string

demo/models/test-api/overlay.raml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#%RAML 1.0 Overlay
2+
extends: test-api.raml
3+
usage: Test API v2
4+
version: v2
5+
/test-headers:
6+
displayName: Headers V2
7+
post:

demo/models/test-api/person.raml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#%RAML 1.0 DataType
2+
3+
type: object
4+
properties:
5+
name: string
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#%RAML 1.0 ResourceType
2+
3+
delete?:
4+
headers:
5+
Accept:
6+
description: Is used to set specified media type.
7+
responses:
8+
403:
9+
description: |
10+
API rate limit exceeded.

demo/models/test-api/secured.raml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#%RAML 1.0 Trait
2+
3+
queryParameters:
4+
<<tokenName>>:
5+
description: A valid <<tokenName>> is required

test/api-console-navigation.test.js

Lines changed: 182 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,11 @@ describe('API Console navigation', () => {
2020
`));
2121
}
2222

23+
const testEndpoint = (endpoint, path, name) => {
24+
assert.equal(endpoint.getAttribute('data-endpoint-path'), path)
25+
assert.equal(endpoint.querySelector('.endpoint-name').innerText, name)
26+
}
27+
2328
const googleApi = 'google-drive-api';
2429

2530
[
@@ -74,11 +79,6 @@ describe('API Console navigation', () => {
7479
});
7580

7681
describe('Endpoints section', () => {
77-
const testEndpoint = (endpoint, path, name) => {
78-
assert.equal(endpoint.getAttribute('data-endpoint-path'), path)
79-
assert.equal(endpoint.querySelector('.endpoint-name').innerText, name)
80-
}
81-
8282
const testGoogleEndpoints = (elem, fullPaths = false) => {
8383
const endpointsList = navigationEndpointsList(elem);
8484
assert.ok(endpointsList);
@@ -325,4 +325,181 @@ describe('API Console navigation', () => {
325325
});
326326
});
327327
});
328+
329+
[
330+
new ApiDescribe('Regular model'),
331+
new ApiDescribe('Compact model', true)
332+
].forEach(({label, compact}) => {
333+
describe(label, () => {
334+
let element;
335+
let amf;
336+
337+
describe('RAML Fragments', () => {
338+
describe('SecurityScheme fragment', () => {
339+
before(async () => {
340+
amf = await AmfLoader.load({compact, fileName: 'basicAuth'});
341+
});
342+
343+
beforeEach(async () => {
344+
element = await amfFixture(amf);
345+
});
346+
347+
it(`should only render security section`, async () => {
348+
assert.notOk(navigationSummarySection(element));
349+
assert.notOk(navigationEndpointsSection(element));
350+
assert.notOk(navigationDocumentationSection(element));
351+
assert.notOk(navigationTypesSection(element));
352+
assert.ok(navigationSecuritySection(element));
353+
});
354+
355+
it(`should list all security items`, async () => {
356+
const securityList = navigationSecurityList(element);
357+
assert.ok(securityList);
358+
assert.lengthOf(securityList, 1);
359+
assert.equal(securityList[0].innerText.trim(), 'BasicAuth');
360+
});
361+
});
362+
363+
describe('DocumentationItem fragment', () => {
364+
before(async () => {
365+
amf = await AmfLoader.load({compact, fileName: 'documentation'});
366+
});
367+
368+
beforeEach(async () => {
369+
element = await amfFixture(amf);
370+
});
371+
372+
it(`should only render documentation section`, async () => {
373+
assert.notOk(navigationSummarySection(element));
374+
assert.notOk(navigationEndpointsSection(element));
375+
assert.ok(navigationDocumentationSection(element));
376+
assert.notOk(navigationTypesSection(element));
377+
assert.notOk(navigationSecuritySection(element));
378+
});
379+
380+
it(`should list all documentation items`, async () => {
381+
const documentationList = navigationDocumentationList(element);
382+
assert.ok(documentationList);
383+
assert.lengthOf(documentationList, 1);
384+
assert.equal(documentationList[0].innerText.trim(), 'Home');
385+
});
386+
});
387+
388+
describe('Extension fragment', () => {
389+
before(async () => {
390+
amf = await AmfLoader.load({compact, fileName: 'extension'});
391+
});
392+
393+
beforeEach(async () => {
394+
element = await amfFixture(amf);
395+
});
396+
397+
it(`should render all extended elements`, async () => {
398+
assert.ok(navigationSummarySection(element));
399+
assert.ok(navigationEndpointsSection(element));
400+
assert.notOk(navigationDocumentationSection(element));
401+
assert.notOk(navigationTypesSection(element));
402+
assert.notOk(navigationSecuritySection(element));
403+
});
404+
405+
it(`should list all endpoints`, async () => {
406+
const endpointsList = navigationEndpointsList(element);
407+
assert.ok(endpointsList);
408+
assert.lengthOf(endpointsList, 1);
409+
testEndpoint(endpointsList[0], "/test-v2", "/test-v2");
410+
});
411+
});
412+
413+
describe('Library fragment', () => {
414+
before(async () => {
415+
amf = await AmfLoader.load({compact, fileName: 'library'});
416+
});
417+
418+
beforeEach(async () => {
419+
element = await amfFixture(amf);
420+
});
421+
422+
it(`should only render types section`, async () => {
423+
assert.notOk(navigationSummarySection(element));
424+
assert.notOk(navigationEndpointsSection(element));
425+
assert.notOk(navigationDocumentationSection(element));
426+
assert.ok(navigationTypesSection(element));
427+
assert.notOk(navigationSecuritySection(element));
428+
});
429+
430+
it(`should list all type items`, async () => {
431+
const documentationList = navigationTypesList(element);
432+
assert.ok(documentationList);
433+
assert.lengthOf(documentationList, 1);
434+
assert.equal(documentationList[0].innerText.trim(), 'myType')
435+
});
436+
});
437+
438+
describe('Overlay fragment', () => {
439+
before(async () => {
440+
amf = await AmfLoader.load({compact, fileName: 'overlay'});
441+
});
442+
443+
beforeEach(async () => {
444+
element = await amfFixture(amf);
445+
});
446+
447+
it(`should render all sections in spec`, async () => {
448+
assert.ok(navigationSummarySection(element));
449+
assert.ok(navigationEndpointsSection(element));
450+
assert.notOk(navigationDocumentationSection(element));
451+
assert.notOk(navigationTypesSection(element));
452+
assert.ok(navigationSecuritySection(element));
453+
});
454+
455+
it(`should list all endpoints`, async () => {
456+
const endpointsList = navigationEndpointsList(element);
457+
assert.ok(endpointsList);
458+
assert.lengthOf(endpointsList, 4);
459+
460+
[
461+
["/test-headers", "Headers V2"],
462+
["/test-custom-scheme", "Custom security scheme"],
463+
["/test-oauth10-scheme", "Oauth 1.0 security scheme"],
464+
["/test-oauth20-scheme", "Oauth 2.0 security scheme"]
465+
].forEach(([path, name], index) => testEndpoint(endpointsList[index], path, name))
466+
});
467+
468+
it(`should list all security items`, async () => {
469+
const securityList = navigationSecurityList(element);
470+
assert.ok(securityList);
471+
assert.lengthOf(securityList, 3);
472+
assert.equal(securityList[0].innerText.trim(), 'customScheme - x-custom');
473+
assert.equal(securityList[1].innerText.trim(), 'oauth_1_0 - OAuth 1.0');
474+
assert.equal(securityList[2].innerText.trim(), 'oauth_2_0 - OAuth 2.0');
475+
});
476+
});
477+
478+
describe('DataType fragment', () => {
479+
before(async () => {
480+
amf = await AmfLoader.load({compact, fileName: 'person'});
481+
});
482+
483+
beforeEach(async () => {
484+
element = await amfFixture(amf);
485+
});
486+
487+
it(`should render all sections in spec`, async () => {
488+
assert.notOk(navigationSummarySection(element));
489+
assert.notOk(navigationEndpointsSection(element));
490+
assert.notOk(navigationDocumentationSection(element));
491+
assert.ok(navigationTypesSection(element));
492+
assert.notOk(navigationSecuritySection(element));
493+
});
494+
495+
it(`should list all type items`, async () => {
496+
const documentationList = navigationTypesList(element);
497+
assert.ok(documentationList);
498+
assert.lengthOf(documentationList, 1);
499+
assert.equal(documentationList[0].innerText.trim(), 'type')
500+
});
501+
});
502+
});
503+
});
504+
});
328505
});

0 commit comments

Comments
 (0)