2016-01-24 22:27:15 +03:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
import { getChildDebugElement } from 'tests/helpers';
|
2016-03-27 18:25:46 +03:00
|
|
|
import {Component, provide} from 'angular2/core';
|
2016-02-10 18:18:36 +03:00
|
|
|
import OptionsManager from 'lib/options';
|
2016-01-24 22:27:15 +03:00
|
|
|
|
|
|
|
import {
|
|
|
|
TestComponentBuilder,
|
|
|
|
inject,
|
|
|
|
beforeEach,
|
|
|
|
beforeEachProviders,
|
|
|
|
it
|
|
|
|
} from 'angular2/testing';
|
|
|
|
|
|
|
|
import JsonSchema from 'lib/components/JsonSchema/json-schema';
|
|
|
|
import SchemaManager from 'lib/utils/SchemaManager';
|
|
|
|
|
|
|
|
describe('Redoc components', () => {
|
|
|
|
describe('JsonSchema Component', () => {
|
|
|
|
let builder;
|
|
|
|
let component;
|
|
|
|
let schemaMgr = new SchemaManager();
|
|
|
|
let fixture;
|
|
|
|
beforeEachProviders(() => [
|
2016-02-10 18:18:36 +03:00
|
|
|
provide(SchemaManager, {useValue: schemaMgr}),
|
|
|
|
provide(OptionsManager, {useClass: OptionsManager})
|
2016-01-24 22:27:15 +03:00
|
|
|
]);
|
|
|
|
beforeEach(inject([TestComponentBuilder], (tcb) => {
|
|
|
|
builder = tcb;
|
|
|
|
}));
|
|
|
|
beforeEach((done) => {
|
|
|
|
builder.createAsync(TestApp).then(_fixture => {
|
|
|
|
fixture = _fixture;
|
|
|
|
let debugEl = getChildDebugElement(fixture.debugElement, 'json-schema');
|
|
|
|
component = debugEl.componentInstance;
|
|
|
|
done();
|
|
|
|
}, err => done.fail(err));
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should init component', () => {
|
|
|
|
component.pointer = '';
|
|
|
|
schemaMgr._schema = {type: 'object'};
|
|
|
|
fixture.detectChanges();
|
|
|
|
expect(component).not.toBeNull();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should set isTrivial for non-object/array types', () => {
|
|
|
|
component.pointer = '';
|
|
|
|
schemaMgr._schema = {type: 'string'};
|
|
|
|
fixture.detectChanges();
|
2016-03-27 01:44:11 +03:00
|
|
|
component.schema.isTrivial.should.be.true();
|
2016-01-24 22:27:15 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
it('should use < * > notation for prop without type', () => {
|
|
|
|
component.pointer = '';
|
|
|
|
schemaMgr._schema = {type: 'object', properties: {
|
|
|
|
test: {}
|
|
|
|
}};
|
|
|
|
fixture.detectChanges();
|
2016-03-27 01:44:11 +03:00
|
|
|
component.schema.properties[0]._displayType.should.be.equal('< * >');
|
2016-01-24 22:27:15 +03:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
/** Test component that contains a Method. */
|
2016-03-27 18:25:46 +03:00
|
|
|
@Component({
|
|
|
|
selector: 'test-app',
|
2016-01-24 22:27:15 +03:00
|
|
|
directives: [JsonSchema],
|
|
|
|
providers: [SchemaManager],
|
|
|
|
template:
|
|
|
|
`<json-schema></json-schema>`
|
|
|
|
})
|
|
|
|
class TestApp {
|
|
|
|
}
|