2016-01-24 22:27:15 +03:00
|
|
|
'use strict';
|
|
|
|
|
2016-06-12 20:44:34 +03:00
|
|
|
import { getChildDebugElement } from '../../../tests/helpers';
|
2016-05-06 12:46:41 +03:00
|
|
|
import { Component, provide } from '@angular/core';
|
|
|
|
import { DynamicComponentLoader } 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 { JsonSchemaLazy } from './json-schema-lazy';
|
2016-06-22 21:17:48 +03:00
|
|
|
import { SpecManager } from '../../utils/SpecManager';
|
2016-01-24 22:27:15 +03:00
|
|
|
|
|
|
|
describe('Redoc components', () => {
|
|
|
|
describe('JsonSchemaLazy Component', () => {
|
|
|
|
let builder;
|
|
|
|
let component;
|
2016-06-23 17:36:38 +03:00
|
|
|
let specMgr = new SpecManager();
|
2016-01-24 22:27:15 +03:00
|
|
|
let fixture;
|
|
|
|
let loader;
|
2016-06-12 20:44:34 +03:00
|
|
|
let appRefMock = {
|
|
|
|
instance: {
|
|
|
|
pointer: ''
|
|
|
|
},
|
2016-06-13 20:54:24 +03:00
|
|
|
hostView: { changeDetectorRef: {detectChanges : () => undefined} }
|
2016-01-24 22:27:15 +03:00
|
|
|
};
|
|
|
|
beforeEachProviders(() => [
|
2016-06-23 17:36:38 +03:00
|
|
|
provide(SpecManager, {useValue: specMgr})
|
2016-01-24 22:27:15 +03:00
|
|
|
]);
|
|
|
|
beforeEach(inject([TestComponentBuilder, DynamicComponentLoader], (tcb, dcl) => {
|
|
|
|
builder = tcb;
|
|
|
|
loader = dcl;
|
2016-06-12 20:44:34 +03:00
|
|
|
spyOn(loader, 'loadNextToLocation').and.returnValue({then: (fn) => fn(appRefMock)});
|
2016-01-24 22:27:15 +03:00
|
|
|
}));
|
|
|
|
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-lazy');
|
2016-06-12 20:44:34 +03:00
|
|
|
component = <JsonSchemaLazy>debugEl.componentInstance;
|
2016-01-24 22:27:15 +03:00
|
|
|
done();
|
|
|
|
}, err => done.fail(err));
|
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(() => {
|
|
|
|
loader.loadNextToLocation.and.callThrough();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should init component', () => {
|
|
|
|
expect(component).not.toBeNull();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should run loadNextToLocation on load', () => {
|
|
|
|
component.pointer = '#/def';
|
|
|
|
fixture.detectChanges();
|
|
|
|
component.load();
|
|
|
|
expect(loader.loadNextToLocation).toHaveBeenCalled();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should not run loadNextToLocation if already loaded', () => {
|
|
|
|
component.pointer = '#/def';
|
|
|
|
fixture.detectChanges();
|
|
|
|
component.load();
|
|
|
|
component.load();
|
|
|
|
expect(loader.loadNextToLocation.calls.count()).toEqual(1);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should init json-schema with correct pointer', () => {
|
|
|
|
component.pointer = '#/def';
|
|
|
|
fixture.detectChanges();
|
|
|
|
component.load();
|
2016-06-12 20:44:34 +03:00
|
|
|
expect(appRefMock.instance.pointer).toEqual(component.pointer);
|
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: [JsonSchemaLazy],
|
|
|
|
template:
|
|
|
|
`<json-schema-lazy></json-schema-lazy>`
|
|
|
|
})
|
2016-06-13 20:54:24 +03:00
|
|
|
class TestAppComponent {
|
2016-01-24 22:27:15 +03:00
|
|
|
}
|