ApiInfo component spec

This commit is contained in:
Roman Hotsiy 2015-12-18 10:36:01 +02:00
parent 36c51dee3d
commit 1513f21637
3 changed files with 92 additions and 0 deletions

View File

@ -0,0 +1,61 @@
'use strict';
import { getChildDebugElement } from 'tests/helpers';
import {Component, View, provide} from 'angular2/core';
import {
TestComponentBuilder,
injectAsync,
beforeEach,
beforeEachProviders,
it
} from 'angular2/testing';
import ApiInfo from 'lib/components/ApiInfo/api-info';
import SchemaManager from 'lib/utils/SchemaManager';
describe('ApiInfo Component', () => {
let builder;
beforeEachProviders(() => [
provide(SchemaManager, {useValue: new SchemaManager()})
]);
beforeEach(injectAsync([TestComponentBuilder, SchemaManager], (tcb, schemaMgr) => {
builder = tcb;
return schemaMgr.load('/tests/schemas/api-info-test.json').then(() => null, (err) => { throw err; });
}));
it('shold init component data', (done) => {
builder.createAsync(TestApp).then(fixture => {
let apiInfoComponent = getChildDebugElement(fixture.debugElement, 'api-info').componentInstance;
expect(apiInfoComponent).not.toBeNull();
fixture.detectChanges();
expect(apiInfoComponent.data).not.toBeNull();
apiInfoComponent.data.title.should.be.equal('Swagger Petstore');
done();
}, err => done.fail(err));
});
it('shold render api name and version', (done) => {
builder.createAsync(TestApp).then(fixture => {
let nativeElement = getChildDebugElement(fixture.debugElement, 'api-info').nativeElement;
let headerElement = nativeElement.querySelector('h1');
fixture.detectChanges();
expect(headerElement).toHaveText('Swagger Petstore (1.0.0)');
done();
}, err => done.fail(err));
});
});
/** Test component that contains an MdButton. */
@Component({selector: 'test-app'})
@View({
directives: [ApiInfo],
providers: [SchemaManager],
template:
`<api-info></api-info>`
})
class TestApp {
}

11
tests/helpers.js Normal file
View File

@ -0,0 +1,11 @@
'use strict';
import {BrowserDomAdapter} from 'angular2/platform/browser';
BrowserDomAdapter.makeCurrent();
/** Gets a child DebugElement by tag name. */
export function getChildDebugElement(parent, tagName) {
return parent.query(debugEl => {
return debugEl.nativeElement.tagName && debugEl.nativeElement.tagName.toLowerCase() === tagName;
});
}

View File

@ -0,0 +1,20 @@
{
"swagger": "2.0",
"info": {
"description": "This is a sample server Petstore server. You can find out more about Swagger at [http://swagger.io](http://swagger.io) or on [irc.freenode.net, #swagger](http://swagger.io/irc/). For this sample, you can use the api key `special-key` to test the authorization filters.",
"version": "1.0.0",
"title": "Swagger Petstore",
"termsOfService": "http://swagger.io/terms/",
"contact": {
"email": "apiteam@swagger.io"
},
"license": {
"name": "Apache 2.0",
"url": "http://www.apache.org/licenses/LICENSE-2.0.html"
}
},
"host": "petstore.swagger.io",
"basePath": "/v2/",
"schemes": ["http"],
"paths": {}
}