Sort tests by groups

This commit is contained in:
Roman Hotsiy 2015-12-19 19:36:28 +02:00
parent b06ac81937
commit 53f7f3a007
11 changed files with 708 additions and 694 deletions

View File

@ -12,55 +12,56 @@ import {
import {Tabs, Tab} from 'lib/common/components/Tabs/tabs';
describe('Common components', () => {
describe('Tabs Component', () => {
let builder;
let component;
let nativeElement;
let childDebugEls;
let fixture;
describe('Tabs Component', () => {
let builder;
let component;
let nativeElement;
let childDebugEls;
let fixture;
beforeEach(inject([TestComponentBuilder], (tcb) => {
builder = tcb;
}));
beforeEach((done) => {
builder.createAsync(TestApp).then(_fixture => {
fixture = _fixture;
let debugEl = getChildDebugElement(fixture.debugElement, 'tabs');
childDebugEls = getChildDebugElementAll(debugEl, 'tab');
component = debugEl.componentInstance;
nativeElement = debugEl.nativeElement;
done();
}, err => done.fail(err));
});
beforeEach(inject([TestComponentBuilder], (tcb) => {
builder = tcb;
}));
beforeEach((done) => {
builder.createAsync(TestApp).then(_fixture => {
fixture = _fixture;
let debugEl = getChildDebugElement(fixture.debugElement, 'tabs');
childDebugEls = getChildDebugElementAll(debugEl, 'tab');
component = debugEl.componentInstance;
nativeElement = debugEl.nativeElement;
done();
}, err => done.fail(err));
});
it('should init component', () => {
expect(component).not.toBeNull();
});
it('should init component', () => {
expect(component).not.toBeNull();
});
it('should handle inner tabs', () => {
component.tabs.should.have.lengthOf(2);
childDebugEls.should.have.lengthOf(2);
});
it('should handle inner tabs', () => {
component.tabs.should.have.lengthOf(2);
childDebugEls.should.have.lengthOf(2);
});
it('should activate first tab by default', () => {
let tabs = childDebugEls.map(debugEl => debugEl.componentInstance);
let [tab1, tab2] = tabs;
it('should activate first tab by default', () => {
let tabs = childDebugEls.map(debugEl => debugEl.componentInstance);
let [tab1, tab2] = tabs;
tab1.active.should.be.true;
tab2.active.should.be.false;
});
tab1.active.should.be.true;
tab2.active.should.be.false;
});
it('should change active tab on click', () => {
fixture.detectChanges();
let headerEls = nativeElement.querySelectorAll('li');
let tabs = childDebugEls.map(debugEl => debugEl.componentInstance);
let [tab1, tab2] = tabs;
it('should change active tab on click', () => {
fixture.detectChanges();
let headerEls = nativeElement.querySelectorAll('li');
let tabs = childDebugEls.map(debugEl => debugEl.componentInstance);
let [tab1, tab2] = tabs;
mouseclick(headerEls[0]);
tab1.active.should.be.false;
tab2.active.should.be.true;
mouseclick(headerEls[0]);
tab1.active.should.be.false;
tab2.active.should.be.true;
});
});
});

View File

@ -12,82 +12,83 @@ import {
import Zippy from 'lib/common/components/Zippy/zippy';
describe('Common components', () => {
describe('Zippy Component', () => {
let builder;
let component;
let nativeElement;
let fixture;
describe('Zippy Component', () => {
let builder;
let component;
let nativeElement;
let fixture;
beforeEach(inject([TestComponentBuilder], (tcb) => {
builder = tcb;
}));
beforeEach((done) => {
builder.createAsync(TestApp).then(_fixture => {
fixture = _fixture;
let debugEl = getChildDebugElement(fixture.debugElement, 'zippy');
component = debugEl.componentInstance;
nativeElement = debugEl.nativeElement;
done();
}, err => done.fail(err));
});
beforeEach(inject([TestComponentBuilder], (tcb) => {
builder = tcb;
}));
beforeEach((done) => {
builder.createAsync(TestApp).then(_fixture => {
fixture = _fixture;
let debugEl = getChildDebugElement(fixture.debugElement, 'zippy');
component = debugEl.componentInstance;
nativeElement = debugEl.nativeElement;
done();
}, err => done.fail(err));
});
it('should init component', () => {
expect(component).not.toBeNull();
});
it('should init component', () => {
expect(component).not.toBeNull();
});
it('should init component defaults', () => {
component.empty.should.be.false;
component.visible.should.be.false;
component.type.should.be.equal('general');
});
it('should init component defaults', () => {
component.empty.should.be.false;
component.visible.should.be.false;
component.type.should.be.equal('general');
});
it('should init properties from dom params', () => {
fixture.detectChanges();
component.visible.should.be.true;
component.empty.should.be.true;
component.title.should.be.equal('Zippy');
component.type.should.be.equal('test');
});
it('should init properties from dom params', () => {
fixture.detectChanges();
component.visible.should.be.true;
component.empty.should.be.true;
component.title.should.be.equal('Zippy');
component.type.should.be.equal('test');
});
it('project inner content', () => {
fixture.detectChanges();
let contentEl = nativeElement.querySelector('.zippy-content');
expect(contentEl).toHaveText('\n test\n ');
});
it('project inner content', () => {
fixture.detectChanges();
let contentEl = nativeElement.querySelector('.zippy-content');
expect(contentEl).toHaveText('\n test\n ');
});
it('should open and close zippy', () => {
fixture.detectChanges();
component.empty = false;
component.visible = true;
fixture.detectChanges();
it('should open and close zippy', () => {
fixture.detectChanges();
component.empty = false;
component.visible = true;
fixture.detectChanges();
let testComponent = fixture.debugElement.componentInstance;
let testComponent = fixture.debugElement.componentInstance;
let titleEl = nativeElement.querySelector('.zippy-title');
mouseclick(titleEl);
fixture.detectChanges();
component.visible.should.be.false;
testComponent.opened.should.be.false;
let titleEl = nativeElement.querySelector('.zippy-title');
mouseclick(titleEl);
fixture.detectChanges();
component.visible.should.be.false;
testComponent.opened.should.be.false;
mouseclick(titleEl);
fixture.detectChanges();
component.visible.should.be.true;
testComponent.opened.should.be.true;
});
mouseclick(titleEl);
fixture.detectChanges();
component.visible.should.be.true;
testComponent.opened.should.be.true;
});
it('should disable empty zippy', () => {
fixture.detectChanges();
component.empty = true;
fixture.detectChanges();
it('should disable empty zippy', () => {
fixture.detectChanges();
component.empty = true;
fixture.detectChanges();
let testComponent = fixture.debugElement.componentInstance;
let testComponent = fixture.debugElement.componentInstance;
let titleEl = nativeElement.querySelector('.zippy-title');
mouseclick(titleEl);
fixture.detectChanges();
testComponent.clickCount.should.be.equal(0);
let titleEl = nativeElement.querySelector('.zippy-title');
mouseclick(titleEl);
fixture.detectChanges();
testComponent.clickCount.should.be.equal(0);
});
});
});

View File

@ -15,37 +15,39 @@ import ApiInfo from 'lib/components/ApiInfo/api-info';
import SchemaManager from 'lib/utils/SchemaManager';
describe('ApiInfo Component', () => {
let builder;
let component;
let fixture;
beforeEachProviders(() => [
provide(SchemaManager, {useValue: new SchemaManager()})
]);
beforeEach(injectAsync([TestComponentBuilder, SchemaManager], (tcb, schemaMgr) => {
builder = tcb;
return schemaMgr.load('/tests/schemas/api-info-test.json').then(() => null, (err) => { throw err; });
}));
beforeEach((done) => {
builder.createAsync(TestApp).then(_fixture => {
fixture = _fixture;
component = getChildDebugElement(fixture.debugElement, 'api-info').componentInstance;
fixture.detectChanges();
done();
}, err => done.fail(err));
});
describe('Redoc components', () => {
describe('ApiInfo Component', () => {
let builder;
let component;
let fixture;
beforeEachProviders(() => [
provide(SchemaManager, {useValue: new SchemaManager()})
]);
beforeEach(injectAsync([TestComponentBuilder, SchemaManager], (tcb, schemaMgr) => {
builder = tcb;
return schemaMgr.load('/tests/schemas/api-info-test.json').then(() => null, (err) => { throw err; });
}));
beforeEach((done) => {
builder.createAsync(TestApp).then(_fixture => {
fixture = _fixture;
component = getChildDebugElement(fixture.debugElement, 'api-info').componentInstance;
fixture.detectChanges();
done();
}, err => done.fail(err));
});
it('shold init component data', () => {
expect(component).not.toBeNull();
expect(component.data).not.toBeNull();
component.data.title.should.be.equal('Swagger Petstore');
});
it('shold init component data', () => {
expect(component).not.toBeNull();
expect(component.data).not.toBeNull();
component.data.title.should.be.equal('Swagger Petstore');
});
it('shold render api name and version', () => {
let nativeElement = getChildDebugElement(fixture.debugElement, 'api-info').nativeElement;
let headerElement = nativeElement.querySelector('h1');
expect(headerElement).toHaveText('Swagger Petstore (1.0.0)');
it('shold render api name and version', () => {
let nativeElement = getChildDebugElement(fixture.debugElement, 'api-info').nativeElement;
let headerElement = nativeElement.querySelector('h1');
expect(headerElement).toHaveText('Swagger Petstore (1.0.0)');
});
});
});

View File

@ -14,39 +14,40 @@ import {
import Method from 'lib/components/Method/method';
import SchemaManager from 'lib/utils/SchemaManager';
describe('Method Component', () => {
let builder;
let component;
beforeEachProviders(() => [
provide(SchemaManager, {useValue: new SchemaManager()})
]);
beforeEach(injectAsync([TestComponentBuilder, SchemaManager], (tcb, schemaMgr) => {
builder = tcb;
return schemaMgr.load('/tests/schemas/extended-petstore.json').then(() => null, (err) => { throw err; });
}));
beforeEach((done) => {
builder.createAsync(TestApp).then(fixture => {
component = getChildDebugElement(fixture.debugElement, 'method').componentInstance;
fixture.detectChanges();
done();
}, err => done.fail(err));
});
describe('Redoc components', () => {
describe('Method Component', () => {
let builder;
let component;
beforeEachProviders(() => [
provide(SchemaManager, {useValue: new SchemaManager()})
]);
beforeEach(injectAsync([TestComponentBuilder, SchemaManager], (tcb, schemaMgr) => {
builder = tcb;
return schemaMgr.load('/tests/schemas/extended-petstore.json').then(() => null, (err) => { throw err; });
}));
beforeEach((done) => {
builder.createAsync(TestApp).then(fixture => {
component = getChildDebugElement(fixture.debugElement, 'method').componentInstance;
fixture.detectChanges();
done();
}, err => done.fail(err));
});
it('should init component', () => {
expect(component).not.toBeNull();
});
it('should init component', () => {
expect(component).not.toBeNull();
});
it('should init basic component data', () => {
component.data.apiUrl.should.be.equal('http://petstore.swagger.io/v2');
component.data.httpMethod.should.be.equal('put');
component.data.path.should.be.equal('/user/{username}');
});
it('should init basic component data', () => {
component.data.apiUrl.should.be.equal('http://petstore.swagger.io/v2');
component.data.httpMethod.should.be.equal('put');
component.data.path.should.be.equal('/user/{username}');
});
it('should main tag', () => {
component.data.methodInfo.tags.should.be.empty;
it('should main tag', () => {
component.data.methodInfo.tags.should.be.empty;
});
});
});

View File

@ -14,43 +14,43 @@ import {
import MethodsList from 'lib/components/MethodsList/methods-list';
import SchemaManager from 'lib/utils/SchemaManager';
describe('ApiInfo Component', () => {
let builder;
let component;
let fixture;
beforeEachProviders(() => [
provide(SchemaManager, {useValue: new SchemaManager()})
]);
beforeEach(injectAsync([TestComponentBuilder, SchemaManager], (tcb, schemaMgr) => {
builder = tcb;
return schemaMgr.load('/tests/schemas/methods-list-component.json').then(() => null, (err) => { throw err; });
}));
beforeEach((done) => {
builder.createAsync(TestApp).then(_fixture => {
fixture = _fixture;
component = getChildDebugElement(fixture.debugElement, 'methods-list').componentInstance;
fixture.detectChanges();
done();
}, err => { throw err; });
});
describe('Redoc components', () => {
describe('ApiInfo Component', () => {
let builder;
let component;
let fixture;
beforeEachProviders(() => [
provide(SchemaManager, {useValue: new SchemaManager()})
]);
beforeEach(injectAsync([TestComponentBuilder, SchemaManager], (tcb, schemaMgr) => {
builder = tcb;
return schemaMgr.load('/tests/schemas/methods-list-component.json').then(() => null, (err) => { throw err; });
}));
beforeEach((done) => {
builder.createAsync(TestApp).then(_fixture => {
fixture = _fixture;
component = getChildDebugElement(fixture.debugElement, 'methods-list').componentInstance;
fixture.detectChanges();
done();
}, err => { throw err; });
});
it('should init component and component data', () => {
expect(component).not.toBeNull();
});
it('should init component and component data', () => {
expect(component).not.toBeNull();
});
it('should get correct tags list', () => {
expect(component.data.tags).not.toBeNull();
component.data.tags.should.have.lengthOf(2);
component.data.tags[0].name.should.be.equal('traitTag');
component.data.tags[0].methods.should.be.empty;
component.data.tags[1].name.should.be.equal('tag1');
component.data.tags[1].methods.should.have.lengthOf(2);
it('should get correct tags list', () => {
expect(component.data.tags).not.toBeNull();
component.data.tags.should.have.lengthOf(2);
component.data.tags[0].name.should.be.equal('traitTag');
component.data.tags[0].methods.should.be.empty;
component.data.tags[1].name.should.be.equal('tag1');
component.data.tags[1].methods.should.have.lengthOf(2);
});
});
});
/** Test component that contains an ApiInfo. */
@Component({selector: 'test-app'})
@View({

View File

@ -14,35 +14,35 @@ import {
import Redoc from 'lib/components/Redoc/redoc';
import SchemaManager from 'lib/utils/SchemaManager';
describe('Redoc Component', () => {
let builder;
beforeEachProviders(() => [
provide(SchemaManager, {useValue: new SchemaManager()})
]);
beforeEach(injectAsync([TestComponentBuilder, SchemaManager], (tcb, schemaMgr) => {
builder = tcb;
return schemaMgr.load('/tests/schemas/extended-petstore.json').then(() => null, (err) => { throw err; });
}));
describe('Redoc components', () => {
describe('Redoc Component', () => {
let builder;
beforeEachProviders(() => [
provide(SchemaManager, {useValue: new SchemaManager()})
]);
beforeEach(injectAsync([TestComponentBuilder, SchemaManager], (tcb, schemaMgr) => {
builder = tcb;
return schemaMgr.load('/tests/schemas/extended-petstore.json').then(() => null, (err) => { throw err; });
}));
it('should init component', (done) => {
builder.createAsync(TestApp).then(fixture => {
let component = getChildDebugElement(fixture.debugElement, 'redoc').componentInstance;
expect(component).not.toBeNull();
done();
}, err => done.fail(err));
});
it('should init component', (done) => {
builder.createAsync(TestApp).then(fixture => {
let component = getChildDebugElement(fixture.debugElement, 'redoc').componentInstance;
expect(component).not.toBeNull();
done();
}, err => done.fail(err));
});
it('should init components tree without errors', (done) => {
builder.createAsync(TestApp).then(fixture => {
(() => fixture.detectChanges()).should.not.throw();
done();
}, err => done.fail(err));
it('should init components tree without errors', (done) => {
builder.createAsync(TestApp).then(fixture => {
(() => fixture.detectChanges()).should.not.throw();
done();
}, err => done.fail(err));
});
});
});
/** Test component that contains a Redoc. */
@Component({selector: 'test-app'})
@View({

View File

@ -3,195 +3,197 @@
import SchemaManager from 'lib/utils/SchemaManager';
import {BaseComponent} from 'lib/components/base';
describe('BaseComponent', () => {
let schemaMgr;
let component;
describe('Redoc components', () => {
describe('BaseComponent', () => {
let schemaMgr;
let component;
beforeAll(() => {
schemaMgr = new SchemaManager();
schemaMgr._schema = {tags: []};
});
beforeEach(() => {
component = new BaseComponent(schemaMgr);
});
it('should set instance properties', () => {
component.schemaMgr.should.be.equal(schemaMgr);
component.schema.should.be.of.type('object');
expect(component.componentSchema).toBeNull();
});
it('should set componentSchema based on pointer on ngOnInit', () => {
component.pointer = '/tags';
component.ngOnInit();
component.componentSchema.should.be.equal(schemaMgr._schema.tags);
});
it('should call prepareModel and init virtual methods after init', () => {
sinon.spy(component, 'prepareModel');
sinon.spy(component, 'init');
component.ngOnInit();
component.prepareModel.calledOnce.should.be.true;
component.init.calledOnce.should.be.true;
});
describe('dereference', () => {
beforeAll((done) => {
schemaMgr.load('/tests/schemas/base-component-dereference.json').then(
() => done()
);
beforeAll(() => {
schemaMgr = new SchemaManager();
schemaMgr._schema = {tags: []};
});
describe('simple dereference', () => {
let paramWithRef;
beforeAll(() => {
component.pointer = '/paths/test1/get';
component.ngOnInit();
component.dereference();
paramWithRef = component.componentSchema.parameters[0];
beforeEach(() => {
component = new BaseComponent(schemaMgr);
});
it('should set instance properties', () => {
component.schemaMgr.should.be.equal(schemaMgr);
component.schema.should.be.of.type('object');
expect(component.componentSchema).toBeNull();
});
it('should set componentSchema based on pointer on ngOnInit', () => {
component.pointer = '/tags';
component.ngOnInit();
component.componentSchema.should.be.equal(schemaMgr._schema.tags);
});
it('should call prepareModel and init virtual methods after init', () => {
sinon.spy(component, 'prepareModel');
sinon.spy(component, 'init');
component.ngOnInit();
component.prepareModel.calledOnce.should.be.true;
component.init.calledOnce.should.be.true;
});
describe('dereference', () => {
beforeAll((done) => {
schemaMgr.load('/tests/schemas/base-component-dereference.json').then(
() => done()
);
});
it('should not contain $ref property', () => {
expect(paramWithRef.$ref).toBeUndefined();
describe('simple dereference', () => {
let paramWithRef;
beforeAll(() => {
component.pointer = '/paths/test1/get';
component.ngOnInit();
component.dereference();
paramWithRef = component.componentSchema.parameters[0];
});
it('should not contain $ref property', () => {
expect(paramWithRef.$ref).toBeUndefined();
});
it('should inject Title if not exist based on reference', () => {
paramWithRef.title.should.be.equal('Simple');
});
it('should inject pointer', () => {
paramWithRef._pointer.should.be.equal('#/definitions/Simple');
});
it('should insert correct definition instead of reference', () => {
delete paramWithRef.title;
delete paramWithRef._pointer;
paramWithRef.should.be.deepEqual(schemaMgr.schema.definitions.Simple);
});
});
it('should inject Title if not exist based on reference', () => {
paramWithRef.title.should.be.equal('Simple');
describe('nested dereference', () => {
let paramWithRef;
beforeAll(() => {
component.pointer = '/paths/test2/get';
component.ngOnInit();
component.dereference();
paramWithRef = component.componentSchema.parameters[0];
});
it('should not touch title if exist', () => {
paramWithRef.title.should.be.equal('NesteTitle');
});
it('should resolve nested schema', () => {
expect(paramWithRef.properties.subschema.$ref).toBeUndefined();
paramWithRef._pointer.should.be.equal('#/definitions/Nested');
paramWithRef.properties.subschema._pointer.should.be.equal('#/definitions/Simple');
paramWithRef.properties.subschema.type.should.be.equal('object');
});
});
it('should inject pointer', () => {
paramWithRef._pointer.should.be.equal('#/definitions/Simple');
});
describe('array schema dereference', () => {
let paramWithRef;
beforeAll(() => {
component.pointer = '/paths/test3/get';
component.ngOnInit();
component.dereference();
paramWithRef = component.componentSchema.parameters[0];
});
it('should insert correct definition instead of reference', () => {
delete paramWithRef.title;
delete paramWithRef._pointer;
paramWithRef.should.be.deepEqual(schemaMgr.schema.definitions.Simple);
it('should resolve array schema', () => {
expect(paramWithRef.$ref).toBeUndefined();
expect(paramWithRef.items.schema.$ref).toBeUndefined();
paramWithRef.type.should.be.equal('array');
paramWithRef._pointer.should.be.equal('#/definitions/ArrayOfSimple');
paramWithRef.items.schema._pointer.should.be.equal('#/definitions/Simple');
paramWithRef.items.schema.type.should.be.equal('object');
});
});
});
describe('nested dereference', () => {
let paramWithRef;
beforeAll(() => {
component.pointer = '/paths/test2/get';
component.ngOnInit();
component.dereference();
paramWithRef = component.componentSchema.parameters[0];
describe('mergeAllOf', () => {
beforeAll((done) => {
schemaMgr.load('tests/schemas/base-component-joinallof.json').then(() => done());
});
it('should not touch title if exist', () => {
paramWithRef.title.should.be.equal('NesteTitle');
describe('Simple allOf merge', () => {
let joined;
beforeAll(() => {
component.pointer = '/definitions/SimpleAllOf';
component.ngOnInit();
component.dereference();
component.joinAllOf();
joined = component.componentSchema;
});
it('should remove $allOf field', () => {
expect(joined.allOf).toBeNull();
});
it('should set type object', () => {
joined.type.should.be.equal('object');
});
it('should merge properties', () => {
Object.keys(joined.properties).length.should.be.equal(3);
Object.keys(joined.properties).should.be.deepEqual(['prop1', 'prop2', 'prop3']);
});
it('should merge required', () => {
joined.required.length.should.be.equal(2);
joined.required.should.be.deepEqual(['prop1', 'prop3']);
});
});
it('should resolve nested schema', () => {
expect(paramWithRef.properties.subschema.$ref).toBeUndefined();
paramWithRef._pointer.should.be.equal('#/definitions/Nested');
paramWithRef.properties.subschema._pointer.should.be.equal('#/definitions/Simple');
paramWithRef.properties.subschema.type.should.be.equal('object');
});
});
describe('AllOf with refrence', () => {
let joined;
beforeAll(() => {
component.pointer = '/definitions/AllOfWithRef';
component.ngOnInit();
component.dereference();
component.joinAllOf();
joined = component.componentSchema;
});
describe('array schema dereference', () => {
let paramWithRef;
beforeAll(() => {
component.pointer = '/paths/test3/get';
component.ngOnInit();
component.dereference();
paramWithRef = component.componentSchema.parameters[0];
it('should remove $allOf field', () => {
expect(joined.allOf).toBeNull();
});
it('should set type object', () => {
joined.type.should.be.equal('object');
});
it('should merge properties', () => {
Object.keys(joined.properties).length.should.be.equal(2);
Object.keys(joined.properties).should.be.deepEqual(['id', 'prop3']);
});
it('should merge required', () => {
joined.required.length.should.be.equal(2);
joined.required.should.be.deepEqual(['id', 'prop3']);
});
});
it('should resolve array schema', () => {
expect(paramWithRef.$ref).toBeUndefined();
expect(paramWithRef.items.schema.$ref).toBeUndefined();
paramWithRef.type.should.be.equal('array');
paramWithRef._pointer.should.be.equal('#/definitions/ArrayOfSimple');
paramWithRef.items.schema._pointer.should.be.equal('#/definitions/Simple');
paramWithRef.items.schema.type.should.be.equal('object');
});
});
});
describe('Incorrect or not supported allOf', () => {
it('should throw when properties or required is set on the same level as allOf', () => {
component.pointer = '/definitions/BadAllOf2';
component.ngOnInit();
component.dereference();
(() => component.joinAllOf()).should.throw();
});
describe('mergeAllOf', () => {
beforeAll((done) => {
schemaMgr.load('tests/schemas/base-component-joinallof.json').then(() => done());
});
describe('Simple allOf merge', () => {
let joined;
beforeAll(() => {
component.pointer = '/definitions/SimpleAllOf';
component.ngOnInit();
component.dereference();
component.joinAllOf();
joined = component.componentSchema;
it('should throw when merging non-object schemas', () => {
component.pointer = '/definitions/BadAllOf1';
component.ngOnInit();
component.dereference();
(() => component.joinAllOf()).should.throw();
});
});
it('should remove $allOf field', () => {
expect(joined.allOf).toBeNull();
xdescribe('Merge array allOf', () => {
});
it('should set type object', () => {
joined.type.should.be.equal('object');
});
it('should merge properties', () => {
Object.keys(joined.properties).length.should.be.equal(3);
Object.keys(joined.properties).should.be.deepEqual(['prop1', 'prop2', 'prop3']);
});
it('should merge required', () => {
joined.required.length.should.be.equal(2);
joined.required.should.be.deepEqual(['prop1', 'prop3']);
});
});
describe('AllOf with refrence', () => {
let joined;
beforeAll(() => {
component.pointer = '/definitions/AllOfWithRef';
component.ngOnInit();
component.dereference();
component.joinAllOf();
joined = component.componentSchema;
});
it('should remove $allOf field', () => {
expect(joined.allOf).toBeNull();
});
it('should set type object', () => {
joined.type.should.be.equal('object');
});
it('should merge properties', () => {
Object.keys(joined.properties).length.should.be.equal(2);
Object.keys(joined.properties).should.be.deepEqual(['id', 'prop3']);
});
it('should merge required', () => {
joined.required.length.should.be.equal(2);
joined.required.should.be.deepEqual(['id', 'prop3']);
});
});
describe('Incorrect or not supported allOf', () => {
it('should throw when properties or required is set on the same level as allOf', () => {
component.pointer = '/definitions/BadAllOf2';
component.ngOnInit();
component.dereference();
(() => component.joinAllOf()).should.throw();
});
it('should throw when merging non-object schemas', () => {
component.pointer = '/definitions/BadAllOf1';
component.ngOnInit();
component.dereference();
(() => component.joinAllOf()).should.throw();
});
});
xdescribe('Merge array allOf', () => {
});
});
});

View File

@ -2,25 +2,26 @@
import {JsonPointer} from 'lib/utils/JsonPointer';
// test extended JsonPointer
describe('Utils', () => {
describe('JsonPointer', () => {
it('should return correct base name', ()=> {
JsonPointer.baseName('/level1/level2/name').should.be.equal('name');
JsonPointer.baseName('/level1/level2/name', 2).should.be.equal('level2');
JsonPointer.baseName('/level1/level2/name', 3).should.be.equal('level1');
});
describe('JsonPointer', () => {
it('should return correct base name', ()=> {
JsonPointer.baseName('/level1/level2/name').should.be.equal('name');
JsonPointer.baseName('/level1/level2/name', 2).should.be.equal('level2');
JsonPointer.baseName('/level1/level2/name', 3).should.be.equal('level1');
});
it('should return correct dir name', ()=> {
JsonPointer.dirName('/level1/level2/name').should.be.equal('/level1/level2');
JsonPointer.dirName('/level1/level2/name', 2).should.be.equal('/level1');
JsonPointer.dirName('/level1/level2/name', 3).should.be.equal('');
});
it('should return correct dir name', ()=> {
JsonPointer.dirName('/level1/level2/name').should.be.equal('/level1/level2');
JsonPointer.dirName('/level1/level2/name', 2).should.be.equal('/level1');
JsonPointer.dirName('/level1/level2/name', 3).should.be.equal('');
});
it('should handle relative pointers (starting with #) without errors', ()=> {
JsonPointer.parse('#/level1/level2/name').should.be.deepEqual(['level1', 'level2', 'name']);
});
it('should handle relative pointers (starting with #) without errors', ()=> {
JsonPointer.parse('#/level1/level2/name').should.be.deepEqual(['level1', 'level2', 'name']);
});
it('should join correctly', ()=> {
JsonPointer.join('#/level1', ['level2', 'name']).should.be.equal('/level1/level2/name');
it('should join correctly', ()=> {
JsonPointer.join('#/level1', ['level2', 'name']).should.be.equal('/level1/level2/name');
});
});
});

View File

@ -1,44 +1,36 @@
'use strict';
import SchemaManager from 'lib/utils/SchemaManager';
describe('Schema manager', () => {
let schemaMgr;
describe('Utils', () => {
describe('Schema manager', () => {
let schemaMgr;
beforeEach(() => {
schemaMgr = new SchemaManager();
});
it('Should initialize with empty schema', ()=> {
schemaMgr.schema.should.be.empty;
});
it('Should be a singleton', ()=> {
(new SchemaManager()).should.be.equal(schemaMgr);
SchemaManager.instance().should.be.equal(schemaMgr);
});
it('load should return a promise', ()=> {
schemaMgr.load('/tests/schemas/extended-petstore.json').should.be.instanceof(Promise);
});
it('load should reject promise for invalid url', (done)=> {
schemaMgr.load('/nonexisting/schema.json').then(() => {
throw new Error('Succees handler should not be called');
}, () => {
done();
beforeEach(() => {
schemaMgr = new SchemaManager();
});
});
it('load should resolve promise for valid url', (done)=> {
schemaMgr.load('/tests/schemas/extended-petstore.json').then(() => {
done();
}, () => {
throw new Error('Error handler should not be called');
it('Should initialize with empty schema', ()=> {
schemaMgr.schema.should.be.empty;
});
});
describe('Schema manager basic functionality', ()=> {
beforeAll(function (done) {
it('Should be a singleton', ()=> {
(new SchemaManager()).should.be.equal(schemaMgr);
SchemaManager.instance().should.be.equal(schemaMgr);
});
it('load should return a promise', ()=> {
schemaMgr.load('/tests/schemas/extended-petstore.json').should.be.instanceof(Promise);
});
it('load should reject promise for invalid url', (done)=> {
schemaMgr.load('/nonexisting/schema.json').then(() => {
throw new Error('Succees handler should not be called');
}, () => {
done();
});
});
it('load should resolve promise for valid url', (done)=> {
schemaMgr.load('/tests/schemas/extended-petstore.json').then(() => {
done();
}, () => {
@ -46,182 +38,192 @@ describe('Schema manager', () => {
});
});
it('should contain non-empty schema', ()=> {
schemaMgr.schema.should.be.an.Object();
schemaMgr.schema.should.be.not.empty;
});
it('should correctly init api url', ()=> {
schemaMgr.apiUrl.should.be.equal('http://petstore.swagger.io/v2');
});
describe('byPointer method', () => {
it('should return correct schema part', ()=> {
let part = schemaMgr.byPointer('/tags/3');
part.should.be.deepEqual(schemaMgr.schema.tags[3]);
part.should.be.equal(schemaMgr.schema.tags[3]);
describe('Schema manager basic functionality', ()=> {
beforeAll(function (done) {
schemaMgr.load('/tests/schemas/extended-petstore.json').then(() => {
done();
}, () => {
throw new Error('Error handler should not be called');
});
});
it('should return null for incorrect pointer', ()=> {
let part = schemaMgr.byPointer('/incorrect/pointer');
expect(part).toBeNull();
it('should contain non-empty schema', ()=> {
schemaMgr.schema.should.be.an.Object();
schemaMgr.schema.should.be.not.empty;
});
it('should correctly init api url', ()=> {
schemaMgr.apiUrl.should.be.equal('http://petstore.swagger.io/v2');
});
describe('byPointer method', () => {
it('should return correct schema part', ()=> {
let part = schemaMgr.byPointer('/tags/3');
part.should.be.deepEqual(schemaMgr.schema.tags[3]);
part.should.be.equal(schemaMgr.schema.tags[3]);
});
it('should return null for incorrect pointer', ()=> {
let part = schemaMgr.byPointer('/incorrect/pointer');
expect(part).toBeNull();
});
});
});
});
describe('getTagsMap method', () => {
beforeAll(function () {
schemaMgr._schema = {
describe('getTagsMap method', () => {
beforeAll(function () {
schemaMgr._schema = {
tags: [
{name: 'tag1', description: 'info1'},
{name: 'tag2', description: 'info2', 'x-traitTag': true}
]
};
});
it('should return correct tags map', () => {
let tagsMap = schemaMgr.getTagsMap();
let expectedResult = {
tag1: {description: 'info1', 'x-traitTag': false},
tag2: {description: 'info2', 'x-traitTag': true}
};
tagsMap.should.be.deepEqual(expectedResult);
});
it('should return empty array for non-specified tags', () => {
delete schemaMgr._schema.tags;
let tagsMap = schemaMgr.getTagsMap();
tagsMap.should.be.empty;
});
});
describe('buildMenuTree method', () => {
let suitSchema = {
tags: [
{name: 'tag1', description: 'info1'},
{name: 'tag2', description: 'info2', 'x-traitTag': true}
]
};
});
it('should return correct tags map', () => {
let tagsMap = schemaMgr.getTagsMap();
let expectedResult = {
tag1: {description: 'info1', 'x-traitTag': false},
tag2: {description: 'info2', 'x-traitTag': true}
};
tagsMap.should.be.deepEqual(expectedResult);
});
it('should return empty array for non-specified tags', () => {
delete schemaMgr._schema.tags;
let tagsMap = schemaMgr.getTagsMap();
tagsMap.should.be.empty;
});
});
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'
{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;
let menuTree;
let entries;
beforeAll(() => {
schemaMgr._schema = suitSchema;
menuTree = schemaMgr.buildMenuTree();
entries = Array.from(menuTree.entries());
});
beforeAll(() => {
schemaMgr._schema = suitSchema;
menuTree = schemaMgr.buildMenuTree();
entries = Array.from(menuTree.entries());
});
it('should return instance of Map', () => {
menuTree.should.be.instanceof(Map);
});
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 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 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 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('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.keys('pointer', 'summary');
let methSchema = schemaMgr.byPointer(methodInfo.pointer);
expect(methSchema).not.toBeNull();
if (methSchema.summary) {
methSchema.summary.should.be.equal(methodInfo.summary);
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.keys('pointer', 'summary');
let methSchema = schemaMgr.byPointer(methodInfo.pointer);
expect(methSchema).not.toBeNull();
if (methSchema.summary) {
methSchema.summary.should.be.equal(methodInfo.summary);
}
}
}
}
});
});
describe('getMethodParams method', () => {
beforeAll((done) => {
schemaMgr.load('/tests/schemas/schema-mgr-methodparams.json').then(() => {
done();
}, () => {
done(new Error('Error handler should not be called'));
});
});
it('should propagate path parameters', () => {
let params = schemaMgr.getMethodParams('/paths/test1/get');
params.length.should.be.equal(2);
params[0].name.should.be.equal('methodParam');
params[1].name.should.be.equal('pathParam');
describe('getMethodParams method', () => {
beforeAll((done) => {
schemaMgr.load('/tests/schemas/schema-mgr-methodparams.json').then(() => {
done();
}, () => {
done(new Error('Error handler should not be called'));
});
});
it('should propagate path parameters', () => {
let params = schemaMgr.getMethodParams('/paths/test1/get');
params.length.should.be.equal(2);
params[0].name.should.be.equal('methodParam');
params[1].name.should.be.equal('pathParam');
});
it('should inject correct pointers', () => {
let params = schemaMgr.getMethodParams('/paths/test1/get');
params[0]._pointer.should.be.equal('/paths/test1/get/parameters/0');
params[1]._pointer.should.be.equal('/paths/test1/parameters/0');
});
it('should accept pointer directly to parameters', () => {
let params = schemaMgr.getMethodParams('/paths/test1/get/parameters', true);
expect(params).not.toBeNull();
params.length.should.be.equal(2);
});
it('should resolve path params from Parameters Definitions Object', () => {
let params = schemaMgr.getMethodParams('/paths/test2/get', true);
params.length.should.be.equal(2);
params[0].name.should.be.equal('methodParam');
params[1].name.should.be.equal('extParam');
params[1]._pointer.should.be.equal('#/parameters/extparam');
});
it('should resolve method params from Parameters Definitions Object', () => {
let params = schemaMgr.getMethodParams('/paths/test3/get', true);
params.length.should.be.equal(1);
params[0].name.should.be.equal('extParam');
params[0]._pointer.should.be.equal('#/parameters/extparam');
});
it('should throw for parameters other than array', () => {
let func = () => schemaMgr.getMethodParams('/paths/test4/get', true);
expect(func).toThrow();
});
});
it('should inject correct pointers', () => {
let params = schemaMgr.getMethodParams('/paths/test1/get');
params[0]._pointer.should.be.equal('/paths/test1/get/parameters/0');
params[1]._pointer.should.be.equal('/paths/test1/parameters/0');
});
it('should accept pointer directly to parameters', () => {
let params = schemaMgr.getMethodParams('/paths/test1/get/parameters', true);
expect(params).not.toBeNull();
params.length.should.be.equal(2);
});
it('should resolve path params from Parameters Definitions Object', () => {
let params = schemaMgr.getMethodParams('/paths/test2/get', true);
params.length.should.be.equal(2);
params[0].name.should.be.equal('methodParam');
params[1].name.should.be.equal('extParam');
params[1]._pointer.should.be.equal('#/parameters/extparam');
});
it('should resolve method params from Parameters Definitions Object', () => {
let params = schemaMgr.getMethodParams('/paths/test3/get', true);
params.length.should.be.equal(1);
params[0].name.should.be.equal('extParam');
params[0]._pointer.should.be.equal('#/parameters/extparam');
});
it('should throw for parameters other than array', () => {
let func = () => schemaMgr.getMethodParams('/paths/test4/get', true);
expect(func).toThrow();
});
});
});

View File

@ -1,31 +1,33 @@
'use strict';
import {statusCodeType} from 'lib/utils/helpers';
describe('statusCodeType', () => {
it('Should return info for status codes within 100 and 200', ()=> {
statusCodeType(100).should.be.equal('info');
statusCodeType(150).should.be.equal('info');
statusCodeType(199).should.be.equal('info');
});
describe('Utils', () => {
describe('statusCodeType', () => {
it('Should return info for status codes within 100 and 200', ()=> {
statusCodeType(100).should.be.equal('info');
statusCodeType(150).should.be.equal('info');
statusCodeType(199).should.be.equal('info');
});
it('Should return success for status codes within 200 and 300', ()=> {
statusCodeType(200).should.be.equal('success');
statusCodeType(250).should.be.equal('success');
statusCodeType(299).should.be.equal('success');
});
it('Should return redirect for status codes within 300 and 400', ()=> {
statusCodeType(300).should.be.equal('redirect');
statusCodeType(350).should.be.equal('redirect');
statusCodeType(399).should.be.equal('redirect');
});
it('Should return error for status codes above 400', ()=> {
statusCodeType(400).should.be.equal('error');
statusCodeType(500).should.be.equal('error');
statusCodeType(599).should.be.equal('error');
});
it('Should return success for status codes within 200 and 300', ()=> {
statusCodeType(200).should.be.equal('success');
statusCodeType(250).should.be.equal('success');
statusCodeType(299).should.be.equal('success');
});
it('Should return redirect for status codes within 300 and 400', ()=> {
statusCodeType(300).should.be.equal('redirect');
statusCodeType(350).should.be.equal('redirect');
statusCodeType(399).should.be.equal('redirect');
});
it('Should return error for status codes above 400', ()=> {
statusCodeType(400).should.be.equal('error');
statusCodeType(500).should.be.equal('error');
statusCodeType(599).should.be.equal('error');
});
it('Should throw for incorrect HTTP code', ()=> {
(() => statusCodeType(99)).should.throw('invalid HTTP code');
(() => statusCodeType(600)).should.throw('invalid HTTP code');
it('Should throw for incorrect HTTP code', ()=> {
(() => statusCodeType(99)).should.throw('invalid HTTP code');
(() => statusCodeType(600)).should.throw('invalid HTTP code');
});
});
});

View File

@ -2,105 +2,107 @@
import {KeysPipe, ValuesPipe, JsonPointerEscapePipe, MarkedPipe} from 'lib/utils/pipes';
describe('KeysPipe and ValuesPipe', () => {
let obj;
var keysPipe, valuesPipe;
describe('Pipes', () => {
describe('KeysPipe and ValuesPipe', () => {
let obj;
var keysPipe, valuesPipe;
beforeEach(() => {
obj = {
a: 1,
b: 2,
c: 3
};
keysPipe = new KeysPipe();
valuesPipe = new ValuesPipe();
});
describe('KeysPipe transform', () => {
it('should return keys', () => {
var val = keysPipe.transform(obj);
val.should.be.deepEqual(['a', 'b', 'c']);
beforeEach(() => {
obj = {
a: 1,
b: 2,
c: 3
};
keysPipe = new KeysPipe();
valuesPipe = new ValuesPipe();
});
it('should not support other objects', () => {
(() => keysPipe.transform(45)).should.throw();
(() => keysPipe.transform('45')).should.throw();
describe('KeysPipe transform', () => {
it('should return keys', () => {
var val = keysPipe.transform(obj);
val.should.be.deepEqual(['a', 'b', 'c']);
});
it('should not support other objects', () => {
(() => keysPipe.transform(45)).should.throw();
(() => keysPipe.transform('45')).should.throw();
});
it('should not throw on blank input', () => {
(() => valuesPipe.transform()).should.not.throw();
});
});
it('should not throw on blank input', () => {
(() => valuesPipe.transform()).should.not.throw();
describe('KeysPipe transform', () => {
it('should return values', () => {
var val = valuesPipe.transform(obj);
val.should.be.deepEqual([1, 2, 3]);
});
it('should not support other objects', () => {
(() => valuesPipe.transform(45)).should.throw();
(() => valuesPipe.transform('45')).should.throw();
});
it('should not throw on blank input', () => {
(() => keysPipe.transform()).should.not.throw();
});
});
});
describe('KeysPipe transform', () => {
it('should return values', () => {
var val = valuesPipe.transform(obj);
val.should.be.deepEqual([1, 2, 3]);
describe('JsonPointerEscapePipe', () => {
let unescaped;
let escaped;
var pipe;
beforeEach(() => {
unescaped = 'test/path~1';
escaped = 'test~1path~01';
pipe = new JsonPointerEscapePipe();
});
it('should not support other objects', () => {
(() => valuesPipe.transform(45)).should.throw();
(() => valuesPipe.transform('45')).should.throw();
describe('JsonPointerEscapePipe transform', () => {
it('should escpae pointer', () => {
var val = pipe.transform(unescaped);
val.should.be.equal(escaped);
});
it('should not support other objects', () => {
(() => pipe.transform(45)).should.throw();
(() => pipe.transform({})).should.throw();
});
it('should not throw on blank input', () => {
(() => pipe.transform()).should.not.throw();
});
});
});
describe('MarkedPipe', () => {
let unmarked;
let marked;
var pipe;
beforeEach(() => {
unmarked = 'test\n';
marked = '<p>test</p>\n';
pipe = new MarkedPipe();
});
it('should not throw on blank input', () => {
(() => keysPipe.transform()).should.not.throw();
});
});
});
describe('JsonPointerEscapePipe', () => {
let unescaped;
let escaped;
var pipe;
beforeEach(() => {
unescaped = 'test/path~1';
escaped = 'test~1path~01';
pipe = new JsonPointerEscapePipe();
});
describe('JsonPointerEscapePipe transform', () => {
it('should escpae pointer', () => {
var val = pipe.transform(unescaped);
val.should.be.equal(escaped);
});
it('should not support other objects', () => {
(() => pipe.transform(45)).should.throw();
(() => pipe.transform({})).should.throw();
});
it('should not throw on blank input', () => {
(() => pipe.transform()).should.not.throw();
});
});
});
describe('MarkedPipe', () => {
let unmarked;
let marked;
var pipe;
beforeEach(() => {
unmarked = 'test\n';
marked = '<p>test</p>\n';
pipe = new MarkedPipe();
});
describe('MarkedPipe transform', () => {
it('should escpae pointer', () => {
var val = pipe.transform(unmarked);
val.should.be.equal(marked);
});
it('should not support other objects', () => {
(() => pipe.transform(45)).should.throw();
(() => pipe.transform({})).should.throw();
});
it('should not throw on blank input', () => {
(() => pipe.transform()).should.not.throw();
describe('MarkedPipe transform', () => {
it('should escpae pointer', () => {
var val = pipe.transform(unmarked);
val.should.be.equal(marked);
});
it('should not support other objects', () => {
(() => pipe.transform(45)).should.throw();
(() => pipe.transform({})).should.throw();
});
it('should not throw on blank input', () => {
(() => pipe.transform()).should.not.throw();
});
});
});
});