refactor tests

This commit is contained in:
Roman Hotsiy 2015-12-19 13:36:05 +02:00
parent bde8f742a4
commit 68286279f7
3 changed files with 37 additions and 33 deletions

View File

@ -17,6 +17,8 @@ import SchemaManager from 'lib/utils/SchemaManager';
describe('ApiInfo Component', () => { describe('ApiInfo Component', () => {
let builder; let builder;
let component;
let fixture;
beforeEachProviders(() => [ beforeEachProviders(() => [
provide(SchemaManager, {useValue: new SchemaManager()}) provide(SchemaManager, {useValue: new SchemaManager()})
]); ]);
@ -24,27 +26,26 @@ describe('ApiInfo Component', () => {
builder = tcb; builder = tcb;
return schemaMgr.load('/tests/schemas/api-info-test.json').then(() => null, (err) => { throw err; }); return schemaMgr.load('/tests/schemas/api-info-test.json').then(() => null, (err) => { throw err; });
})); }));
beforeEach((done) => {
builder.createAsync(TestApp).then(_fixture => {
it('shold init component data', (done) => { fixture = _fixture;
builder.createAsync(TestApp).then(fixture => { component = getChildDebugElement(fixture.debugElement, 'api-info').componentInstance;
let apiInfoComponent = getChildDebugElement(fixture.debugElement, 'api-info').componentInstance;
expect(apiInfoComponent).not.toBeNull();
fixture.detectChanges(); fixture.detectChanges();
expect(apiInfoComponent.data).not.toBeNull();
apiInfoComponent.data.title.should.be.equal('Swagger Petstore');
done(); done();
}, err => done.fail(err)); }, err => done.fail(err));
}); });
it('shold render api name and version', (done) => {
builder.createAsync(TestApp).then(fixture => { it('shold init component data', () => {
let nativeElement = getChildDebugElement(fixture.debugElement, 'api-info').nativeElement; expect(component).not.toBeNull();
let headerElement = nativeElement.querySelector('h1'); expect(component.data).not.toBeNull();
fixture.detectChanges(); component.data.title.should.be.equal('Swagger Petstore');
expect(headerElement).toHaveText('Swagger Petstore (1.0.0)'); });
done();
}, err => done.fail(err)); it('shold render api name and version', () => {
let nativeElement = getChildDebugElement(fixture.debugElement, 'api-info').nativeElement;
let headerElement = nativeElement.querySelector('h1');
expect(headerElement).toHaveText('Swagger Petstore (1.0.0)');
}); });
}); });

View File

@ -15,8 +15,9 @@ import Method from 'lib/components/Method/method';
import SchemaManager from 'lib/utils/SchemaManager'; import SchemaManager from 'lib/utils/SchemaManager';
describe('jjj Component', () => { describe('Method Component', () => {
let builder; let builder;
let component;
beforeEachProviders(() => [ beforeEachProviders(() => [
provide(SchemaManager, {useValue: new SchemaManager()}) provide(SchemaManager, {useValue: new SchemaManager()})
]); ]);
@ -24,31 +25,33 @@ describe('jjj Component', () => {
builder = tcb; builder = tcb;
return schemaMgr.load('/tests/schemas/extended-petstore.json').then(() => null, (err) => { throw err; }); return schemaMgr.load('/tests/schemas/extended-petstore.json').then(() => null, (err) => { throw err; });
})); }));
beforeEach((done) => {
it('should init component', (done) => {
builder.createAsync(TestApp).then(fixture => { builder.createAsync(TestApp).then(fixture => {
let component = getChildDebugElement(fixture.debugElement, 'method').componentInstance; component = getChildDebugElement(fixture.debugElement, 'method').componentInstance;
expect(component).not.toBeNull(); fixture.detectChanges();
done(); done();
}, err => done.fail(err)); }, err => done.fail(err));
}); });
it('should init basic component data', (done) => {
builder.createAsync(TestApp).then(fixture => {
let component = getChildDebugElement(fixture.debugElement, 'method').componentInstance;
fixture.detectChanges();
component.data.apiUrl.should.be.equal('http://petstore.swagger.io/v2'); it('should init component', () => {
component.data.httpMethod.should.be.equal('put'); expect(component).not.toBeNull();
component.data.path.should.be.equal('/user/{username}'); });
done();
}, err => done.fail(err)); it('should init basic component data', () => {
component.data.apiUrl.should.be.equal('http://petstore.swagger.io/v2');
component.data.httpMethod.should.be.equal('put');
component.data.path.should.be.equal('/user/{username}');
});
it('should main tag', () => {
component.data.methodInfo.tags.should.be.empty;
}); });
}); });
/** Test component that contains an Method. */ /** Test component that contains a Method. */
@Component({selector: 'test-app'}) @Component({selector: 'test-app'})
@View({ @View({
directives: [Method], directives: [Method],

View File

@ -36,7 +36,7 @@ describe('Redoc Component', () => {
}); });
/** Test component that contains an Redoc. */ /** Test component that contains a Redoc. */
@Component({selector: 'test-app'}) @Component({selector: 'test-app'})
@View({ @View({
directives: [Redoc], directives: [Redoc],