2016-01-24 22:27:15 +03:00
|
|
|
'use strict';
|
|
|
|
|
2016-05-06 12:46:41 +03:00
|
|
|
import { Component, provide } from '@angular/core';
|
2016-01-24 22:27:15 +03:00
|
|
|
import {
|
|
|
|
inject,
|
|
|
|
beforeEach,
|
|
|
|
beforeEachProviders,
|
|
|
|
it
|
2016-05-06 00:48:41 +03:00
|
|
|
} from '@angular/core/testing';
|
|
|
|
import { TestComponentBuilder } from '@angular/compiler/testing';
|
2016-01-24 22:27:15 +03:00
|
|
|
|
2016-06-12 20:44:34 +03:00
|
|
|
import { getChildDebugElement } from '../../../tests/helpers';
|
2016-05-06 12:46:41 +03:00
|
|
|
|
|
|
|
|
2016-06-12 20:44:34 +03:00
|
|
|
import { JsonSchema } from './json-schema';
|
|
|
|
import { SchemaManager } from '../../utils/SchemaManager';;
|
2016-01-24 22:27:15 +03:00
|
|
|
|
|
|
|
describe('Redoc components', () => {
|
|
|
|
describe('JsonSchema Component', () => {
|
|
|
|
let builder;
|
|
|
|
let component;
|
|
|
|
let schemaMgr = new SchemaManager();
|
|
|
|
let fixture;
|
|
|
|
beforeEachProviders(() => [
|
2016-06-12 20:44:34 +03:00
|
|
|
provide(SchemaManager, {useValue: schemaMgr})
|
2016-01-24 22:27:15 +03:00
|
|
|
]);
|
|
|
|
beforeEach(inject([TestComponentBuilder], (tcb) => {
|
|
|
|
builder = tcb;
|
|
|
|
}));
|
|
|
|
beforeEach((done) => {
|
2016-06-13 20:54:24 +03:00
|
|
|
builder.createAsync(TestAppComponent).then(_fixture => {
|
2016-01-24 22:27:15 +03:00
|
|
|
fixture = _fixture;
|
|
|
|
let debugEl = getChildDebugElement(fixture.debugElement, 'json-schema');
|
|
|
|
component = debugEl.componentInstance;
|
|
|
|
done();
|
|
|
|
}, err => done.fail(err));
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should init component', () => {
|
|
|
|
component.pointer = '';
|
2016-06-12 20:44:34 +03:00
|
|
|
(<any>schemaMgr)._schema = {type: 'object'};
|
2016-01-24 22:27:15 +03:00
|
|
|
fixture.detectChanges();
|
|
|
|
expect(component).not.toBeNull();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should set isTrivial for non-object/array types', () => {
|
|
|
|
component.pointer = '';
|
2016-06-12 20:44:34 +03:00
|
|
|
(<any>schemaMgr)._schema = {type: 'string'};
|
2016-01-24 22:27:15 +03:00
|
|
|
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 = '';
|
2016-06-12 20:44:34 +03:00
|
|
|
(<any>schemaMgr)._schema = {type: 'object', properties: {
|
2016-01-24 22:27:15 +03:00
|
|
|
test: {}
|
|
|
|
}};
|
|
|
|
fixture.detectChanges();
|
2016-06-22 19:13:57 +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>`
|
|
|
|
})
|
2016-06-13 20:54:24 +03:00
|
|
|
class TestAppComponent {
|
2016-01-24 22:27:15 +03:00
|
|
|
}
|