mirror of
https://github.com/Redocly/redoc.git
synced 2025-02-07 13:30:33 +03:00
Fix unit tests
This commit is contained in:
parent
a94afe5f2d
commit
9389d7dc15
|
@ -12,7 +12,7 @@ import { OptionsService, MenuService } from '../../services/index';
|
||||||
export class ApiInfo extends BaseComponent implements OnInit {
|
export class ApiInfo extends BaseComponent implements OnInit {
|
||||||
info: any = {};
|
info: any = {};
|
||||||
specUrl: String;
|
specUrl: String;
|
||||||
constructor(specMgr:SpecManager, private optionsService: OptionsService) {
|
constructor(specMgr: SpecManager, private optionsService: OptionsService) {
|
||||||
super(specMgr);
|
super(specMgr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -10,7 +10,7 @@ h2, h3 {
|
||||||
}
|
}
|
||||||
|
|
||||||
:host h2 {
|
:host h2 {
|
||||||
margin-top: 40px;
|
padding-top: 40px;
|
||||||
}
|
}
|
||||||
|
|
||||||
h3 {
|
h3 {
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
import { Component, ChangeDetectionStrategy, OnInit, HostListener } from '@angular/core';
|
import { Component, ChangeDetectionStrategy, OnInit, HostListener } from '@angular/core';
|
||||||
import { SpecManager, BaseComponent } from '../base';
|
import { SpecManager, BaseComponent } from '../base';
|
||||||
|
|
||||||
import { ComponentParser } from '../../services/';
|
import { ComponentParser } from '../../services/component-parser.service';
|
||||||
|
|
||||||
const AUTH_TYPES = {
|
const AUTH_TYPES = {
|
||||||
'oauth2': 'OAuth2',
|
'oauth2': 'OAuth2',
|
||||||
|
|
|
@ -98,6 +98,7 @@ describe('Menu service', () => {
|
||||||
selector: 'test-app',
|
selector: 'test-app',
|
||||||
template:
|
template:
|
||||||
`<div id='parent' style='height: 500px; overflow:auto'>
|
`<div id='parent' style='height: 500px; overflow:auto'>
|
||||||
|
<api-info></api-info>
|
||||||
<methods-list></methods-list>
|
<methods-list></methods-list>
|
||||||
</div>`
|
</div>`
|
||||||
})
|
})
|
||||||
|
|
|
@ -141,10 +141,11 @@ export class MenuService {
|
||||||
let ptr = decodeURIComponent(hash.substr(namespace.length + 1));
|
let ptr = decodeURIComponent(hash.substr(namespace.length + 1));
|
||||||
if (namespace === 'operation') {
|
if (namespace === 'operation') {
|
||||||
$el = this.getMethodElByOperId(ptr);
|
$el = this.getMethodElByOperId(ptr);
|
||||||
} else if (namespace === 'tag'){
|
} else if (namespace === 'tag') {
|
||||||
let sectionId = ptr.split('/')[0];
|
let sectionId = ptr.split('/')[0];
|
||||||
ptr = ptr.substr(sectionId.length) || null;
|
ptr = ptr.substr(sectionId.length) || null;
|
||||||
sectionId = namespace + (sectionId ? '/' + sectionId : '');
|
sectionId = namespace + (sectionId ? '/' + sectionId : '');
|
||||||
|
$el = this.getMethodElByPtr(ptr, sectionId);
|
||||||
} else {
|
} else {
|
||||||
$el = this.getMethodElByPtr(null, namespace + '/' + ptr);
|
$el = this.getMethodElByPtr(null, namespace + '/' + ptr);
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,8 +4,6 @@ import { Injectable } from '@angular/core';
|
||||||
import * as slugify from 'slugify';
|
import * as slugify from 'slugify';
|
||||||
import * as Remarkable from 'remarkable';
|
import * as Remarkable from 'remarkable';
|
||||||
|
|
||||||
import { SecurityDefinitions } from '../components/';
|
|
||||||
|
|
||||||
declare var Prism: any;
|
declare var Prism: any;
|
||||||
const md = new Remarkable({
|
const md = new Remarkable({
|
||||||
html: true,
|
html: true,
|
||||||
|
@ -28,15 +26,12 @@ interface HeadersHandler {
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class MdRenderer {
|
export class MdRenderer {
|
||||||
|
public firstLevelHeadings: string[] = [];
|
||||||
|
|
||||||
private _origRules:any = {};
|
private _origRules:any = {};
|
||||||
private _preProcessors:Function[] = [];
|
private _preProcessors:Function[] = [];
|
||||||
|
|
||||||
public firstLevelHeadings: string[] = [];
|
|
||||||
constructor(private raw: boolean = false) {
|
constructor(private raw: boolean = false) {
|
||||||
// TODO
|
|
||||||
if (!raw) {
|
|
||||||
this.addPreprocessor(SecurityDefinitions.insertTagIntoDescription);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
addPreprocessor(p: Function) {
|
addPreprocessor(p: Function) {
|
||||||
|
|
|
@ -4,7 +4,7 @@ import { Pipe, PipeTransform } from '@angular/core';
|
||||||
import { DomSanitizer } from '@angular/platform-browser';
|
import { DomSanitizer } from '@angular/platform-browser';
|
||||||
import { isString, stringify, isBlank } from './helpers';
|
import { isString, stringify, isBlank } from './helpers';
|
||||||
import JsonPointer from './JsonPointer';
|
import JsonPointer from './JsonPointer';
|
||||||
import { MdRenderer} from './';
|
import { MdRenderer } from './';
|
||||||
import { JsonFormatter } from './JsonFormatterPipe';
|
import { JsonFormatter } from './JsonFormatterPipe';
|
||||||
|
|
||||||
declare var Prism: any;
|
declare var Prism: any;
|
||||||
|
|
|
@ -5,7 +5,7 @@ import { JsonPointer } from './JsonPointer';
|
||||||
import { parse as urlParse, resolve as urlResolve } from 'url';
|
import { parse as urlParse, resolve as urlResolve } from 'url';
|
||||||
import { BehaviorSubject } from 'rxjs/BehaviorSubject';
|
import { BehaviorSubject } from 'rxjs/BehaviorSubject';
|
||||||
|
|
||||||
import { MdRenderer } from './';
|
import { MdRenderer } from './md-renderer';
|
||||||
|
|
||||||
export class SpecManager {
|
export class SpecManager {
|
||||||
public _schema: any = {};
|
public _schema: any = {};
|
||||||
|
@ -77,6 +77,10 @@ export class SpecManager {
|
||||||
preprocess() {
|
preprocess() {
|
||||||
let mdRender = new MdRenderer();
|
let mdRender = new MdRenderer();
|
||||||
if (!this._schema.info.description) this._schema.info.description = '';
|
if (!this._schema.info.description) this._schema.info.description = '';
|
||||||
|
if (this._schema.securityDefinitions) {
|
||||||
|
let SecurityDefinitions = require('../components/').SecurityDefinitions;
|
||||||
|
mdRender.addPreprocessor(SecurityDefinitions.insertTagIntoDescription);
|
||||||
|
}
|
||||||
this._schema.info['x-redoc-html-description'] = mdRender.renderMd(this._schema.info.description);
|
this._schema.info['x-redoc-html-description'] = mdRender.renderMd(this._schema.info.description);
|
||||||
this._schema.info['x-redoc-markdown-headers'] = mdRender.firstLevelHeadings;
|
this._schema.info['x-redoc-markdown-headers'] = mdRender.firstLevelHeadings;
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,11 +22,14 @@ var TestBed = require('@angular/core/testing').TestBed;
|
||||||
var ErrorHandler = require('@angular/core').ErrorHandler;
|
var ErrorHandler = require('@angular/core').ErrorHandler;
|
||||||
var BrowserDynamicTestingModule = require('@angular/platform-browser-dynamic/testing').BrowserDynamicTestingModule;
|
var BrowserDynamicTestingModule = require('@angular/platform-browser-dynamic/testing').BrowserDynamicTestingModule;
|
||||||
var platformBrowserDynamicTesting = require('@angular/platform-browser-dynamic/testing').platformBrowserDynamicTesting;
|
var platformBrowserDynamicTesting = require('@angular/platform-browser-dynamic/testing').platformBrowserDynamicTesting;
|
||||||
var services = require('../lib/services/index');
|
|
||||||
var SpecManager = require('../lib/utils/spec-manager').SpecManager;
|
var SpecManager = require('../lib/utils/spec-manager').SpecManager;
|
||||||
|
var services = require('../lib/services/index');
|
||||||
var REDOC_PIPES = require('../lib/utils/pipes').REDOC_PIPES;
|
var REDOC_PIPES = require('../lib/utils/pipes').REDOC_PIPES;
|
||||||
var REDOC_COMMON_DIRECTIVES = require('../lib/shared/components/index').REDOC_COMMON_DIRECTIVES;
|
var sharedComponents = require('../lib/shared/components/');
|
||||||
var REDOC_DIRECTIVES = require('../lib/components/index').REDOC_DIRECTIVES;
|
var REDOC_COMMON_DIRECTIVES = sharedComponents.REDOC_COMMON_DIRECTIVES;
|
||||||
|
var components = require('../lib/components/');
|
||||||
|
var REDOC_DIRECTIVES = components.REDOC_DIRECTIVES;
|
||||||
|
|
||||||
TestBed.initTestEnvironment(
|
TestBed.initTestEnvironment(
|
||||||
BrowserDynamicTestingModule,
|
BrowserDynamicTestingModule,
|
||||||
|
@ -43,10 +46,18 @@ beforeEach(function() {
|
||||||
services.MenuService,
|
services.MenuService,
|
||||||
services.WarningsService,
|
services.WarningsService,
|
||||||
services.OptionsService,
|
services.OptionsService,
|
||||||
{ provide: ErrorHandler, useClass: services.CustomErrorHandler }
|
services.ComponentParser,
|
||||||
|
services.ContentProjector,
|
||||||
|
{ provide: ErrorHandler, useClass: services.CustomErrorHandler },
|
||||||
|
{ provide: services.COMPONENT_PARSER_ALLOWED, useValue: { 'security-definitions': components.SecurityDefinitions }}
|
||||||
],
|
],
|
||||||
declarations: [REDOC_PIPES, REDOC_DIRECTIVES, REDOC_COMMON_DIRECTIVES]
|
declarations: [REDOC_PIPES, REDOC_DIRECTIVES, REDOC_COMMON_DIRECTIVES]
|
||||||
});
|
});
|
||||||
|
TestBed.overrideModule(BrowserDynamicTestingModule, {
|
||||||
|
set: {
|
||||||
|
entryComponents: [ sharedComponents.DynamicNg2Wrapper, components.SecurityDefinitions ]
|
||||||
|
},
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user