redoc/lib/components/EndpointLink/endpoint-link.spec.ts

83 lines
2.1 KiB
TypeScript
Raw Normal View History

2017-02-26 00:38:19 +03:00
'use strict';
import { Component } from '@angular/core';
import {
inject,
async,
TestBed
} from '@angular/core/testing';
import { getChildDebugElement } from '../../../tests/helpers';
import { EndpointLink } from './endpoint-link';
import { SpecManager } from '../../utils/spec-manager';
import { OptionsService } from '../../services/';
2017-02-26 00:38:19 +03:00
describe('Redoc components', () => {
beforeEach(() => {
TestBed.configureTestingModule({ declarations: [ TestAppComponent ] });
});
describe('EndpointLink Component', () => {
let builder;
let component: EndpointLink;
let specMgr: SpecManager;
let opts: OptionsService;
2017-02-26 00:38:19 +03:00
beforeEach(async(inject([SpecManager, OptionsService], (_specMgr, _opts) => {
2017-02-26 00:38:19 +03:00
specMgr = _specMgr;
opts = _opts;
2017-02-26 00:38:19 +03:00
})));
beforeEach(() => {
specMgr.apiUrl = 'http://test.com/v1';
specMgr._schema = {
info: {},
host: 'petstore.swagger.io',
baseName: '/v2',
schemes: ['https', 'http'],
'x-servers': [
{
url: '//test.com/v2'
},
{
url: 'ws://test.com/v3',
description: 'test'
}
]
};
specMgr.init();
component = new EndpointLink(specMgr, opts);
2017-02-26 00:38:19 +03:00
});
it('should replace // with appropriate protocol', () => {
component.ngOnInit();
component.servers[0].url.should.be.equal('https://test.com/v2');
});
it('should preserve other protocols', () => {
component.ngOnInit();
component.servers[1].url.should.be.equal('ws://test.com/v3');
});
it('should fallback to host + basePath + schemas if no x-servers', () => {
specMgr._schema['x-servers'] = null;
specMgr.init();
component.ngOnInit();
component.servers.should.be.lengthOf(1);
component.servers[0].url.should.be.equal('https://petstore.swagger.io');
});
});
});
2017-03-30 15:17:08 +03:00
/** Test component that contains an Operation. */
2017-02-26 00:38:19 +03:00
@Component({
selector: 'test-app',
template:
2017-03-30 15:17:08 +03:00
`<operation pointer='#/paths/~1user~1{username}/put'></operation>`
2017-02-26 00:38:19 +03:00
})
class TestAppComponent {
}