2016-01-24 22:27:15 +03:00
|
|
|
'use strict';
|
|
|
|
|
2016-07-01 15:53:16 +03:00
|
|
|
import { Component } from '@angular/core';
|
2016-01-24 22:27:15 +03:00
|
|
|
import {
|
|
|
|
inject,
|
2016-09-02 23:18:31 +03:00
|
|
|
TestBed
|
2016-05-06 00:48:41 +03:00
|
|
|
} from '@angular/core/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';
|
2016-10-23 20:18:42 +03:00
|
|
|
import { SpecManager } from '../../utils/spec-manager';;
|
2016-01-24 22:27:15 +03:00
|
|
|
|
|
|
|
describe('Redoc components', () => {
|
2016-09-02 23:18:31 +03:00
|
|
|
beforeEach(() => {
|
|
|
|
TestBed.configureTestingModule({ declarations: [ TestAppComponent ] });
|
|
|
|
});
|
2016-01-24 22:27:15 +03:00
|
|
|
describe('JsonSchema Component', () => {
|
|
|
|
let builder;
|
|
|
|
let component;
|
|
|
|
let fixture;
|
2016-07-01 15:53:16 +03:00
|
|
|
let specMgr;
|
|
|
|
|
2016-09-02 23:18:31 +03:00
|
|
|
beforeEach(inject([SpecManager], ( _spec) => {
|
|
|
|
|
2016-07-01 15:53:16 +03:00
|
|
|
specMgr = _spec;
|
2016-01-24 22:27:15 +03:00
|
|
|
}));
|
2016-07-26 14:07:25 +03:00
|
|
|
|
2016-07-01 15:53:16 +03:00
|
|
|
beforeEach(() => {
|
2016-09-02 23:18:31 +03:00
|
|
|
fixture = TestBed.createComponent(TestAppComponent);
|
2016-07-01 15:53:16 +03:00
|
|
|
let debugEl = getChildDebugElement(fixture.debugElement, 'json-schema');
|
|
|
|
component = debugEl.componentInstance;
|
2016-01-24 22:27:15 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
it('should init component', () => {
|
|
|
|
component.pointer = '';
|
2016-08-22 12:12:13 +03:00
|
|
|
(<SpecManager>specMgr)._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', () => {
|
2016-07-26 14:07:25 +03:00
|
|
|
component.pointer = '#';
|
2016-06-23 17:36:38 +03:00
|
|
|
(<any>specMgr)._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
|
|
|
});
|
|
|
|
|
2016-08-12 20:41:58 +03:00
|
|
|
it('should use < anything > notation for prop without type', () => {
|
2016-07-26 14:07:25 +03:00
|
|
|
component.pointer = '#';
|
2016-06-23 17:36:38 +03:00
|
|
|
(<any>specMgr)._schema = {type: 'object', properties: {
|
2016-01-24 22:27:15 +03:00
|
|
|
test: {}
|
|
|
|
}};
|
|
|
|
fixture.detectChanges();
|
2016-08-12 20:41:58 +03:00
|
|
|
component.schema._properties[0]._displayType.should.be.equal('< anything >');
|
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
|
|
|
template:
|
|
|
|
`<json-schema></json-schema>`
|
|
|
|
})
|
2016-06-13 20:54:24 +03:00
|
|
|
class TestAppComponent {
|
2016-01-24 22:27:15 +03:00
|
|
|
}
|