redoc/lib/components/JsonSchema/json-schema.spec.ts

75 lines
2.0 KiB
TypeScript
Raw Normal View History

'use strict';
2016-05-06 12:46:41 +03:00
import { Component, provide } from '@angular/core';
import {
inject,
beforeEach,
beforeEachProviders,
it
2016-05-06 00:48:41 +03:00
} from '@angular/core/testing';
import { TestComponentBuilder } from '@angular/compiler/testing';
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';
2016-06-22 21:17:48 +03:00
import { SpecManager } from '../../utils/SpecManager';;
describe('Redoc components', () => {
describe('JsonSchema Component', () => {
let builder;
let component;
let specMgr = new SpecManager();
let fixture;
beforeEachProviders(() => [
provide(SpecManager, {useValue: specMgr})
]);
beforeEach(inject([TestComponentBuilder], (tcb) => {
builder = tcb;
}));
beforeEach((done) => {
2016-06-13 20:54:24 +03:00
builder.createAsync(TestAppComponent).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 = '';
(<any>specMgr)._schema = {type: 'object'};
fixture.detectChanges();
expect(component).not.toBeNull();
});
it('should set isTrivial for non-object/array types', () => {
component.pointer = '';
(<any>specMgr)._schema = {type: 'string'};
fixture.detectChanges();
component.schema.isTrivial.should.be.true();
});
it('should use < * > notation for prop without type', () => {
component.pointer = '';
(<any>specMgr)._schema = {type: 'object', properties: {
test: {}
}};
fixture.detectChanges();
2016-06-22 19:13:57 +03:00
component.schema._properties[0]._displayType.should.be.equal('< * >');
});
});
});
/** Test component that contains a Method. */
@Component({
selector: 'test-app',
directives: [JsonSchema],
2016-06-22 21:17:48 +03:00
providers: [SpecManager],
template:
`<json-schema></json-schema>`
})
2016-06-13 20:54:24 +03:00
class TestAppComponent {
}