redoc/lib/components/ApiLogo/api-logo.spec.ts

69 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-07-01 15:53:16 +03:00
import { Component } from '@angular/core';
import {
2016-04-30 00:45:53 +03:00
inject,
2016-05-06 00:48:41 +03:00
async,
2016-07-01 15:53:16 +03:00
TestComponentBuilder
2016-05-06 00:48:41 +03:00
} from '@angular/core/testing';
2016-06-12 20:44:34 +03:00
import { ApiLogo } from './api-logo';
2016-06-22 21:17:48 +03:00
import { SpecManager } from '../../utils/SpecManager';
describe('Redoc components', () => {
describe('ApiLogo Component', () => {
let builder;
let component;
let fixture;
let specMgr;
let schemaUrl = '/tests/schemas/api-info-test.json';
beforeEach(async(inject([TestComponentBuilder, SpecManager], (tcb, _specMgr) => {
builder = tcb;
specMgr = _specMgr;
return specMgr.load(schemaUrl);
2016-04-30 00:45:53 +03:00
})));
2016-07-01 15:53:16 +03:00
beforeEach(() => {
fixture = builder.createSync(TestAppComponent);
component = getChildDebugElement(fixture.debugElement, 'api-logo').componentInstance;
fixture.detectChanges();
});
it('should init component data', () => {
expect(component).not.toBeNull();
expect(component.logo).not.toBeNull();
});
it('should not display image when no x-logo', () => {
component.logo.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';
});
it('should load values from spec and use transparent bgColor by default', () => {
component.logo.imgUrl.should.endWith('petstore-logo.png');
component.logo.bgColor.should.be.equal('transparent');
});
});
});
/** Test component that contains an ApiInfo. */
@Component({
selector: 'test-app',
directives: [ApiLogo],
2016-06-22 21:17:48 +03:00
providers: [SpecManager],
template:
`<api-logo></api-logo>`
})
2016-06-13 20:54:24 +03:00
class TestAppComponent {
}