mirror of
https://github.com/Redocly/redoc.git
synced 2024-11-22 16:46:34 +03:00
fix tests
This commit is contained in:
parent
060119673f
commit
ac6c203f24
|
@ -30,7 +30,7 @@ export class MethodsList extends BaseComponent {
|
|||
// inject tag name into method info
|
||||
tagInfo.methods = tagInfo.methods || [];
|
||||
tagInfo.methods.forEach(method => {
|
||||
method.tag = name;
|
||||
method.tag = tagInfo.name;
|
||||
});
|
||||
});
|
||||
this.data.tags = tags;
|
||||
|
|
|
@ -95,7 +95,7 @@ describe('Redoc components', () => {
|
|||
builder = tcb;
|
||||
optsMgr = opts;
|
||||
dom = _dom;
|
||||
return specMgr.load('/tests/schemas/methods-list-component.json');
|
||||
return specMgr.load('/tests/schemas/extended-petstore.yml');
|
||||
})));
|
||||
|
||||
beforeEach(() => {
|
||||
|
|
84
lib/services/schema-helper.serivce.spec.ts
Normal file
84
lib/services/schema-helper.serivce.spec.ts
Normal file
|
@ -0,0 +1,84 @@
|
|||
'use strict';
|
||||
import { SchemaHelper } from './schema-helper.service';
|
||||
import { SpecManager } from '../utils/SpecManager';
|
||||
|
||||
describe('Spec Helper', () => {
|
||||
describe('buildMenuTree method', () => {
|
||||
let suitSchema = {
|
||||
tags: [
|
||||
{name: 'tag1', description: 'info1', 'x-traitTag': true},
|
||||
{name: 'tag2', description: 'info2'}
|
||||
],
|
||||
paths: {
|
||||
test: {
|
||||
put: {
|
||||
tags: ['tag1', 'tag3'],
|
||||
summary: 'test put'
|
||||
},
|
||||
get: {
|
||||
tags: ['tag1', 'tag2'],
|
||||
summary: 'test get'
|
||||
},
|
||||
// no tags
|
||||
post: {
|
||||
summary: 'test post'
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
let menuTree;
|
||||
let specMgr;
|
||||
|
||||
beforeAll(() => {
|
||||
specMgr = new SpecManager();
|
||||
specMgr._schema = suitSchema;
|
||||
menuTree = SchemaHelper.buildMenuTree(suitSchema);
|
||||
});
|
||||
|
||||
it('should return instance of Array', () => {
|
||||
menuTree.should.be.instanceof(Array);
|
||||
});
|
||||
|
||||
it('should return Array with correct number of items', () => {
|
||||
//2 - defined tags, 1 - tag3 and 1 [other] tag for no-tags method
|
||||
menuTree.length.should.be.equal(2 + 1 + 1);
|
||||
});
|
||||
|
||||
it('should append not defined tags to the end of list', () => {
|
||||
let info = menuTree[2];
|
||||
info.name.should.be.equal('tag3');
|
||||
info.methods.length.should.be.equal(1);
|
||||
info.methods[0].summary.should.be.equal('test put');
|
||||
});
|
||||
|
||||
it('should append methods without tags to [other] tag', () => {
|
||||
let info = menuTree[3];
|
||||
info.name.should.be.equal('');
|
||||
info.methods.length.should.be.equal(1);
|
||||
info.methods[0].summary.should.be.equal('test post');
|
||||
});
|
||||
|
||||
it('should map x-traitTag to empty methods list', () => {
|
||||
let info = menuTree[0];
|
||||
info['x-traitTag'].should.be.true();
|
||||
info.methods.should.be.empty();
|
||||
});
|
||||
|
||||
it('methods for tag should contain valid pointer and summary', () => {
|
||||
for (let entr of menuTree) {
|
||||
let info = entr;
|
||||
info.should.be.an.Object();
|
||||
info.methods.should.be.an.Array();
|
||||
for (let methodInfo of info.methods) {
|
||||
methodInfo.should.have.properties(['pointer', 'summary']);
|
||||
let methSchema = specMgr.byPointer(methodInfo.pointer);
|
||||
expect(methSchema).not.toBeNull();
|
||||
if (methSchema.summary) {
|
||||
methSchema.summary.should.be.equal(methodInfo.summary);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
|
@ -93,85 +93,6 @@ describe('Utils', () => {
|
|||
});
|
||||
});
|
||||
|
||||
describe('buildMenuTree method', () => {
|
||||
let suitSchema = {
|
||||
tags: [
|
||||
{name: 'tag1', description: 'info1', 'x-traitTag': true},
|
||||
{name: 'tag2', description: 'info2'}
|
||||
],
|
||||
paths: {
|
||||
test: {
|
||||
put: {
|
||||
tags: ['tag1', 'tag3'],
|
||||
summary: 'test put'
|
||||
},
|
||||
get: {
|
||||
tags: ['tag1', 'tag2'],
|
||||
summary: 'test get'
|
||||
},
|
||||
// no tags
|
||||
post: {
|
||||
summary: 'test post'
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
let menuTree;
|
||||
let entries;
|
||||
|
||||
beforeAll(() => {
|
||||
specMgr._schema = suitSchema;
|
||||
menuTree = specMgr.buildMenuTree();
|
||||
entries = Array.from(menuTree.entries());
|
||||
});
|
||||
|
||||
it('should return instance of Map', () => {
|
||||
menuTree.should.be.instanceof(Map);
|
||||
});
|
||||
|
||||
it('should return Map with correct number of entries', () => {
|
||||
//2 - defined tags, 1 - tag3 and 1 [other] tag for no-tags method
|
||||
entries.length.should.be.equal(2 + 1 + 1);
|
||||
});
|
||||
|
||||
it('should append not defined tags to the end of list', () => {
|
||||
let [tag, info] = entries[2];
|
||||
tag.should.be.equal('tag3');
|
||||
info.methods.length.should.be.equal(1);
|
||||
info.methods[0].summary.should.be.equal('test put');
|
||||
});
|
||||
|
||||
it('should append methods without tags to [other] tag', () => {
|
||||
let [tag, info] = entries[3];
|
||||
tag.should.be.equal('[Other]');
|
||||
info.methods.length.should.be.equal(1);
|
||||
info.methods[0].summary.should.be.equal('test post');
|
||||
});
|
||||
|
||||
it('should map x-traitTag to empty methods list', () => {
|
||||
let [, info] = entries[0];
|
||||
info['x-traitTag'].should.be.true();
|
||||
info.methods.should.be.empty();
|
||||
});
|
||||
|
||||
it('methods for tag should contain valid pointer and summary', () => {
|
||||
for (let entr of entries) {
|
||||
let [, info] = entr;
|
||||
info.should.be.an.Object();
|
||||
info.methods.should.be.an.Array();
|
||||
for (let methodInfo of info.methods) {
|
||||
methodInfo.should.have.properties(['pointer', 'summary']);
|
||||
let methSchema = specMgr.byPointer(methodInfo.pointer);
|
||||
expect(methSchema).not.toBeNull();
|
||||
if (methSchema.summary) {
|
||||
methSchema.summary.should.be.equal(methodInfo.summary);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
describe('getMethodParams method', () => {
|
||||
beforeAll((done) => {
|
||||
specMgr.load('/tests/schemas/schema-mgr-methodparams.json').then(() => {
|
||||
|
|
Loading…
Reference in New Issue
Block a user