2015-12-21 00:34:20 +03:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
import { getChildDebugElement } from 'tests/helpers';
|
2016-03-27 18:25:46 +03:00
|
|
|
import {Component, provide} from 'angular2/core';
|
2015-12-21 00:34:20 +03:00
|
|
|
|
|
|
|
import {
|
|
|
|
TestComponentBuilder,
|
2016-04-30 00:45:53 +03:00
|
|
|
async,
|
|
|
|
inject,
|
2015-12-21 00:34:20 +03:00
|
|
|
beforeEach,
|
|
|
|
beforeEachProviders,
|
|
|
|
it
|
|
|
|
} from 'angular2/testing';
|
|
|
|
|
|
|
|
import ApiLogo from 'lib/components/ApiLogo/api-logo';
|
|
|
|
import SchemaManager from 'lib/utils/SchemaManager';
|
|
|
|
|
|
|
|
|
|
|
|
describe('Redoc components', () => {
|
|
|
|
describe('ApiLogo Component', () => {
|
|
|
|
let builder;
|
|
|
|
let component;
|
|
|
|
let fixture;
|
|
|
|
let schemaMgr;
|
|
|
|
|
|
|
|
let schemaUrl = '/tests/schemas/api-info-test.json';
|
|
|
|
beforeEachProviders(() => [
|
|
|
|
provide(SchemaManager, {useValue: new SchemaManager()})
|
|
|
|
]);
|
2016-04-30 00:45:53 +03:00
|
|
|
beforeEach(async(inject([TestComponentBuilder, SchemaManager], (tcb, _schemaMgr) => {
|
2015-12-21 00:34:20 +03:00
|
|
|
builder = tcb;
|
|
|
|
schemaMgr = _schemaMgr;
|
2016-04-30 00:45:53 +03:00
|
|
|
return schemaMgr.load(schemaUrl);
|
|
|
|
})));
|
2015-12-21 00:34:20 +03:00
|
|
|
beforeEach((done) => {
|
|
|
|
builder.createAsync(TestApp).then(_fixture => {
|
|
|
|
fixture = _fixture;
|
|
|
|
component = getChildDebugElement(fixture.debugElement, 'api-logo').componentInstance;
|
|
|
|
fixture.detectChanges();
|
|
|
|
done();
|
|
|
|
}, err => done.fail(err));
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
it('should init component data', () => {
|
|
|
|
expect(component).not.toBeNull();
|
|
|
|
expect(component.data).not.toBeNull();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should not display image when no x-logo', () => {
|
|
|
|
component.data.should.be.empty;
|
|
|
|
let nativeElement = getChildDebugElement(fixture.debugElement, 'api-logo').nativeElement;
|
|
|
|
let imgElement = nativeElement.querySelector('img');
|
|
|
|
expect(imgElement).toBeNull();
|
|
|
|
|
|
|
|
// update schemaUrl to load other schema in the next test
|
2016-02-01 15:47:21 +03:00
|
|
|
schemaUrl = '/tests/schemas/extended-petstore.yml';
|
2015-12-21 00:34:20 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
it('should load values from spec and use transparent bgColor by default', () => {
|
|
|
|
component.data.imgUrl.should.endWith('petstore-logo.png');
|
|
|
|
component.data.bgColor.should.be.equal('transparent');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
/** Test component that contains an ApiInfo. */
|
2016-03-27 18:25:46 +03:00
|
|
|
@Component({
|
|
|
|
selector: 'test-app',
|
2015-12-21 00:34:20 +03:00
|
|
|
directives: [ApiLogo],
|
|
|
|
providers: [SchemaManager],
|
|
|
|
template:
|
|
|
|
`<api-logo></api-logo>`
|
|
|
|
})
|
|
|
|
class TestApp {
|
|
|
|
}
|