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

72 lines
1.9 KiB
TypeScript
Raw Normal View History

'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 {
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 { JsonSchemaLazy } from './json-schema-lazy';
2016-06-22 21:17:48 +03:00
import { SpecManager } from '../../utils/SpecManager';
describe('Redoc components', () => {
describe('JsonSchemaLazy Component', () => {
let builder;
let component;
let specMgr = new SpecManager();
let fixture;
beforeEachProviders(() => [
provide(SpecManager, {useValue: specMgr})
]);
2016-06-29 19:06:42 +03:00
beforeEach(inject([TestComponentBuilder], (tcb, dcl) => {
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-lazy');
2016-06-12 20:44:34 +03:00
component = <JsonSchemaLazy>debugEl.componentInstance;
2016-06-29 19:06:42 +03:00
spyOn(component, '_loadAfterSelf').and.callThrough();
done();
}, err => done.fail(err));
});
it('should init component', () => {
expect(component).not.toBeNull();
});
it('should run loadNextToLocation on load', () => {
component.pointer = '#/def';
fixture.detectChanges();
component.load();
2016-06-29 19:06:42 +03:00
expect(component._loadAfterSelf).toHaveBeenCalled();
});
it('should not run loadNextToLocation if already loaded', () => {
component.pointer = '#/def';
fixture.detectChanges();
component.load();
component.load();
2016-06-29 19:06:42 +03:00
expect(component._loadAfterSelf.calls.count()).toEqual(1);
});
});
});
/** Test component that contains a Method. */
@Component({
selector: 'test-app',
directives: [JsonSchemaLazy],
template:
`<json-schema-lazy></json-schema-lazy>`
})
2016-06-13 20:54:24 +03:00
class TestAppComponent {
}