redoc/lib/components/ApiInfo/api-info.spec.ts

68 lines
1.8 KiB
TypeScript
Raw Normal View History

2015-12-18 11:36:01 +03:00
'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 { OptionsService } from '../../services/index';
2015-12-18 11:36:01 +03:00
import {
2016-04-30 00:45:53 +03:00
inject,
2016-05-06 00:48:41 +03:00
async,
2016-09-02 23:18:31 +03:00
TestBed
2016-05-06 00:48:41 +03:00
} from '@angular/core/testing';
2016-06-12 20:44:34 +03:00
import { ApiInfo } from './api-info';
2016-10-23 20:18:42 +03:00
import { SpecManager } from '../../utils/spec-manager';
2015-12-18 11:36:01 +03:00
2015-12-19 20:36:28 +03:00
describe('Redoc components', () => {
describe('ApiInfo Component', () => {
let component;
let fixture;
let opts;
2016-11-24 16:29:29 +03:00
let specMgr;
2016-09-02 23:18:31 +03:00
beforeEach(() => {
TestBed.configureTestingModule({ declarations: [ TestAppComponent ] });
});
2016-11-24 16:29:29 +03:00
beforeEach(async(inject([SpecManager, OptionsService], (_specMgr, _opts) => {
opts = _opts;
opts.options = {
scrollYOffset: () => 0,
$scrollParent: window
};
2016-11-24 16:29:29 +03:00
specMgr = _specMgr;
2016-04-30 00:45:53 +03:00
})));
2016-11-24 16:29:29 +03:00
beforeEach(done => {
specMgr.load('/tests/schemas/api-info-test.json').then(done, done.fail);
});
beforeEach(async(() => {
2016-09-02 23:18:31 +03:00
fixture = TestBed.createComponent(TestAppComponent);
2016-07-01 15:53:16 +03:00
component = getChildDebugElement(fixture.debugElement, 'api-info').componentInstance;
fixture.detectChanges();
2016-11-24 16:29:29 +03:00
}));
2015-12-18 11:36:01 +03:00
2015-12-19 14:36:05 +03:00
2016-01-20 16:50:11 +03:00
it('should init component data', () => {
2015-12-19 20:36:28 +03:00
expect(component).not.toBeNull();
expect(component.info).not.toBeNull();
component.info.title.should.be.equal('Swagger Petstore');
2015-12-19 20:36:28 +03:00
});
2015-12-19 14:36:05 +03:00
2016-01-20 16:50:11 +03:00
it('should render api name and version', () => {
2015-12-19 20:36:28 +03:00
let nativeElement = getChildDebugElement(fixture.debugElement, 'api-info').nativeElement;
let headerElement = nativeElement.querySelector('h1');
2016-07-01 18:09:42 +03:00
expect(headerElement.innerText).toContain('Swagger Petstore (v1.0.0)');
2015-12-19 20:36:28 +03:00
});
2015-12-18 11:36:01 +03:00
});
});
2015-12-19 03:26:42 +03:00
/** Test component that contains an ApiInfo. */
@Component({
selector: 'test-app',
2015-12-18 11:36:01 +03:00
template:
`<api-info></api-info>`
})
2016-06-13 20:54:24 +03:00
class TestAppComponent {
2015-12-18 11:36:01 +03:00
}