mirror of
https://github.com/Redocly/redoc.git
synced 2025-01-31 01:54:08 +03:00
ApiInfo component spec
This commit is contained in:
parent
36c51dee3d
commit
1513f21637
61
lib/components/ApiInfo/api-info.spec.js
Normal file
61
lib/components/ApiInfo/api-info.spec.js
Normal 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
11
tests/helpers.js
Normal 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;
|
||||||
|
});
|
||||||
|
}
|
20
tests/schemas/api-info-test.json
Normal file
20
tests/schemas/api-info-test.json
Normal 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": {}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user