From a671d2f0050e14013e737841cec4dc347c6f3cd6 Mon Sep 17 00:00:00 2001 From: Roman Hotsiy Date: Fri, 1 Jul 2016 15:53:16 +0300 Subject: [PATCH 01/10] update to the latest angular --- karma.conf.js | 1 - lib/components/ApiInfo/api-info.spec.ts | 29 ++----- lib/components/ApiLogo/api-logo.spec.ts | 22 ++---- .../JsonSchema/json-schema-lazy.spec.ts | 34 ++++----- lib/components/JsonSchema/json-schema.spec.ts | 27 +++---- lib/components/Method/method.spec.ts | 22 ++---- .../MethodsList/methods-list.spec.ts | 20 ++--- lib/components/Redoc/redoc.spec.ts | 76 +++++++------------ lib/components/SideMenu/side-menu.spec.ts | 22 ++---- lib/components/base.ts | 4 +- lib/services/menu.service.spec.ts | 42 +++------- lib/services/options.service.spec.ts | 4 - .../schema-normalizer.service.spec.ts | 5 -- .../StickySidebar/sticky-sidebar.spec.ts | 24 ++---- .../StickySidebar/sticky-sidebar.ts | 2 +- lib/shared/components/Tabs/tabs.spec.ts | 21 ++--- lib/shared/components/Zippy/zippy.spec.ts | 20 ++--- package.json | 30 +++----- system.config.js | 54 +++++-------- tests/setup.ts | 9 ++- 20 files changed, 151 insertions(+), 317 deletions(-) diff --git a/karma.conf.js b/karma.conf.js index 9966e216..e7c94a7a 100644 --- a/karma.conf.js +++ b/karma.conf.js @@ -39,7 +39,6 @@ module.exports = function (config) { //load angular dependencies and browser polyfills files: [ 'node_modules/zone.js/dist/zone.js', - 'node_modules/zone.js/dist/fake-async-test.js', 'node_modules/zone.js/dist/async-test.js', 'node_modules/zone.js/dist/jasmine-patch.js', 'node_modules/zone.js/dist/long-stack-trace-zone.js', diff --git a/lib/components/ApiInfo/api-info.spec.ts b/lib/components/ApiInfo/api-info.spec.ts index 5d0f26b4..d85efd66 100644 --- a/lib/components/ApiInfo/api-info.spec.ts +++ b/lib/components/ApiInfo/api-info.spec.ts @@ -1,47 +1,32 @@ 'use strict'; import { getChildDebugElement } from '../../../tests/helpers'; -import { Component, provide } from '@angular/core'; +import { Component } from '@angular/core'; import { inject, async, - expect, - beforeEach, - beforeEachProviders, - it + TestComponentBuilder } from '@angular/core/testing'; -import { TestComponentBuilder } from '@angular/compiler/testing'; - import { ApiInfo } from './api-info'; import { SpecManager } from '../../utils/SpecManager'; -import { OptionsService } from '../../services/index'; describe('Redoc components', () => { describe('ApiInfo Component', () => { let builder; let component; let fixture; - beforeEachProviders(() => [ - provide(SpecManager, {useValue: new SpecManager()}), - provide(OptionsService, {useClass: OptionsService}) - ]); beforeEach(async(inject([TestComponentBuilder, SpecManager], (tcb, specMgr) => { builder = tcb; return specMgr.load('/tests/schemas/api-info-test.json'); }))); - beforeEach((done) => { - builder.createAsync(TestAppComponent).then(_fixture => { - fixture = _fixture; - component = getChildDebugElement(fixture.debugElement, 'api-info').componentInstance; - fixture.detectChanges(); - done(); - }, err => { - done.fail(err); - }); + beforeEach(() => { + fixture = builder.createSync(TestAppComponent); + component = getChildDebugElement(fixture.debugElement, 'api-info').componentInstance; + fixture.detectChanges(); }); @@ -54,7 +39,7 @@ describe('Redoc components', () => { it('should 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)'); + expect(headerElement.innerText).toContain('Swagger Petstore (1.0.0)'); }); }); }); diff --git a/lib/components/ApiLogo/api-logo.spec.ts b/lib/components/ApiLogo/api-logo.spec.ts index e9a6fbf3..79484ff0 100644 --- a/lib/components/ApiLogo/api-logo.spec.ts +++ b/lib/components/ApiLogo/api-logo.spec.ts @@ -1,18 +1,14 @@ 'use strict'; import { getChildDebugElement } from '../../../tests/helpers'; -import {Component, provide} from '@angular/core'; +import { Component } from '@angular/core'; import { inject, async, - beforeEach, - beforeEachProviders, - it + TestComponentBuilder } from '@angular/core/testing'; -import { TestComponentBuilder } from '@angular/compiler/testing'; - import { ApiLogo } from './api-logo'; import { SpecManager } from '../../utils/SpecManager'; @@ -25,21 +21,15 @@ describe('Redoc components', () => { let specMgr; let schemaUrl = '/tests/schemas/api-info-test.json'; - beforeEachProviders(() => [ - provide(SpecManager, {useValue: new SpecManager()}) - ]); beforeEach(async(inject([TestComponentBuilder, SpecManager], (tcb, _specMgr) => { builder = tcb; specMgr = _specMgr; return specMgr.load(schemaUrl); }))); - beforeEach((done) => { - builder.createAsync(TestAppComponent).then(_fixture => { - fixture = _fixture; - component = getChildDebugElement(fixture.debugElement, 'api-logo').componentInstance; - fixture.detectChanges(); - done(); - }, err => done.fail(err)); + beforeEach(() => { + fixture = builder.createSync(TestAppComponent); + component = getChildDebugElement(fixture.debugElement, 'api-logo').componentInstance; + fixture.detectChanges(); }); diff --git a/lib/components/JsonSchema/json-schema-lazy.spec.ts b/lib/components/JsonSchema/json-schema-lazy.spec.ts index d1026189..d5977d50 100644 --- a/lib/components/JsonSchema/json-schema-lazy.spec.ts +++ b/lib/components/JsonSchema/json-schema-lazy.spec.ts @@ -1,41 +1,33 @@ 'use strict'; import { getChildDebugElement } from '../../../tests/helpers'; -import { Component, provide } from '@angular/core'; +import { Component } from '@angular/core'; import { inject, - beforeEach, - beforeEachProviders, - it + TestComponentBuilder } from '@angular/core/testing'; -import { TestComponentBuilder } from '@angular/compiler/testing'; - - import { JsonSchemaLazy } from './json-schema-lazy'; -import { SpecManager } from '../../utils/SpecManager'; describe('Redoc components', () => { describe('JsonSchemaLazy Component', () => { let builder; let component; - let specMgr = new SpecManager(); let fixture; - beforeEachProviders(() => [ - provide(SpecManager, {useValue: specMgr}) - ]); - beforeEach(inject([TestComponentBuilder], (tcb, dcl) => { + + beforeEach(inject([TestComponentBuilder], (tcb) => { builder = tcb; })); - beforeEach((done) => { - builder.createAsync(TestAppComponent).then(_fixture => { - fixture = _fixture; - let debugEl = getChildDebugElement(fixture.debugElement, 'json-schema-lazy'); - component = debugEl.componentInstance; - spyOn(component, '_loadAfterSelf').and.callThrough(); - done(); - }, err => done.fail(err)); + beforeEach(() => { + fixture = builder.createSync(TestAppComponent); + let debugEl = getChildDebugElement(fixture.debugElement, 'json-schema-lazy'); + component = debugEl.componentInstance; + spyOn(component, '_loadAfterSelf').and.stub(); + }); + + afterEach(() => { + component._loadAfterSelf.and.callThrough(); }); it('should init component', () => { diff --git a/lib/components/JsonSchema/json-schema.spec.ts b/lib/components/JsonSchema/json-schema.spec.ts index 166658b9..962116f2 100644 --- a/lib/components/JsonSchema/json-schema.spec.ts +++ b/lib/components/JsonSchema/json-schema.spec.ts @@ -1,13 +1,10 @@ 'use strict'; -import { Component, provide } from '@angular/core'; +import { Component } from '@angular/core'; import { inject, - beforeEach, - beforeEachProviders, - it + TestComponentBuilder } from '@angular/core/testing'; -import { TestComponentBuilder } from '@angular/compiler/testing'; import { getChildDebugElement } from '../../../tests/helpers'; @@ -19,21 +16,17 @@ describe('Redoc components', () => { describe('JsonSchema Component', () => { let builder; let component; - let specMgr = new SpecManager(); let fixture; - beforeEachProviders(() => [ - provide(SpecManager, {useValue: specMgr}) - ]); - beforeEach(inject([TestComponentBuilder], (tcb) => { + let specMgr; + + beforeEach(inject([TestComponentBuilder, SpecManager], (tcb, _spec) => { builder = tcb; + specMgr = _spec; })); - beforeEach((done) => { - builder.createAsync(TestAppComponent).then(_fixture => { - fixture = _fixture; - let debugEl = getChildDebugElement(fixture.debugElement, 'json-schema'); - component = debugEl.componentInstance; - done(); - }, err => done.fail(err)); + beforeEach(() => { + fixture = builder.createSync(TestAppComponent); + let debugEl = getChildDebugElement(fixture.debugElement, 'json-schema'); + component = debugEl.componentInstance; }); it('should init component', () => { diff --git a/lib/components/Method/method.spec.ts b/lib/components/Method/method.spec.ts index 699ed0da..21cdc51a 100644 --- a/lib/components/Method/method.spec.ts +++ b/lib/components/Method/method.spec.ts @@ -1,14 +1,11 @@ 'use strict'; -import { Component, provide } from '@angular/core'; +import { Component } from '@angular/core'; import { inject, async, - beforeEach, - beforeEachProviders, - it + TestComponentBuilder } from '@angular/core/testing'; -import { TestComponentBuilder } from '@angular/compiler/testing'; import { getChildDebugElement } from '../../../tests/helpers'; @@ -19,19 +16,16 @@ describe('Redoc components', () => { describe('Method Component', () => { let builder; let component; - beforeEachProviders(() => [ - provide(SpecManager, {useValue: new SpecManager()}) - ]); + beforeEach(async(inject([TestComponentBuilder, SpecManager], (tcb, specMgr) => { builder = tcb; return specMgr.load('/tests/schemas/extended-petstore.yml'); }))); - beforeEach((done) => { - builder.createAsync(TestAppComponent).then(fixture => { - component = getChildDebugElement(fixture.debugElement, 'method').componentInstance; - fixture.detectChanges(); - done(); - }, err => done.fail(err)); + + beforeEach(() => { + let fixture = builder.createSync(TestAppComponent); + component = getChildDebugElement(fixture.debugElement, 'method').componentInstance; + fixture.detectChanges(); }); diff --git a/lib/components/MethodsList/methods-list.spec.ts b/lib/components/MethodsList/methods-list.spec.ts index 9918761a..75394166 100644 --- a/lib/components/MethodsList/methods-list.spec.ts +++ b/lib/components/MethodsList/methods-list.spec.ts @@ -4,11 +4,8 @@ import { Component, provide } from '@angular/core'; import { inject, async, - beforeEach, - beforeEachProviders, - it + TestComponentBuilder } from '@angular/core/testing'; -import { TestComponentBuilder } from '@angular/compiler/testing'; import { getChildDebugElement } from '../../../tests/helpers'; @@ -21,20 +18,15 @@ describe('Redoc components', () => { let builder; let component; let fixture; - beforeEachProviders(() => [ - provide(SpecManager, {useValue: new SpecManager()}) - ]); + beforeEach(async(inject([TestComponentBuilder, SpecManager], (tcb, specMgr) => { builder = tcb; return specMgr.load('/tests/schemas/methods-list-component.json'); }))); - beforeEach((done) => { - builder.createAsync(TestAppComponent).then(_fixture => { - fixture = _fixture; - component = getChildDebugElement(fixture.debugElement, 'methods-list').componentInstance; - fixture.detectChanges(); - done(); - }, err => done.fail(err) ); + beforeEach(() => { + fixture = builder.createSync(TestAppComponent); + component = getChildDebugElement(fixture.debugElement, 'methods-list').componentInstance; + fixture.detectChanges(); }); diff --git a/lib/components/Redoc/redoc.spec.ts b/lib/components/Redoc/redoc.spec.ts index 4ae11b74..073810e8 100644 --- a/lib/components/Redoc/redoc.spec.ts +++ b/lib/components/Redoc/redoc.spec.ts @@ -1,15 +1,12 @@ 'use strict'; import { getChildDebugElement } from '../../../tests/helpers'; -import { Component, provide, ComponentRef } from '@angular/core'; +import { Component, ComponentRef } from '@angular/core'; import { BrowserDomAdapter } from '@angular/platform-browser/src/browser/browser_adapter'; import { inject, - async, - beforeEach, - beforeEachProviders, - it + async } from '@angular/core/testing'; import { TestComponentBuilder } from '@angular/compiler/testing'; @@ -24,40 +21,27 @@ describe('Redoc components', () => { describe('Redoc Component', () => { let builder; let specMgr; - beforeEachProviders(() => [ - provide(SpecManager, {useValue: new SpecManager()}), - ]); + beforeEach(async(inject([TestComponentBuilder, SpecManager, OptionsService], (tcb, _specMgr, _optsMgr) => { optsMgr = _optsMgr; builder = tcb; specMgr = _specMgr; + return specMgr.load('/tests/schemas/extended-petstore.yml'); }))); - beforeEach((done) => { - return specMgr.load('/tests/schemas/extended-petstore.yml') - .then(() => done()) - .catch(err => done.fail(err)); + + it('should init component', () => { + let fixture = builder.createSync(TestAppComponent); + let component = getChildDebugElement(fixture.debugElement, 'redoc').componentInstance; + expect(component).not.toBeNull(); + fixture.destroy(); }); - - it('should init component', (done) => { - builder.createAsync(TestAppComponent).then(fixture => { - let component = getChildDebugElement(fixture.debugElement, 'redoc').componentInstance; - expect(component).not.toBeNull(); - fixture.destroy(); - done(); - }, err => done.fail(err)); - }); - - it('should init components tree without errors', (done) => { - builder.createAsync(TestAppComponent).then(fixture => { - (() => fixture.detectChanges()).should.not.throw(); - fixture.destroy(); - done(); - }, err => { - return done.fail(err); - }); + it('should init components tree without errors', () => { + let fixture = builder.createSync(TestAppComponent); + (() => fixture.detectChanges()).should.not.throw(); + fixture.destroy(); }); }); @@ -103,29 +87,25 @@ describe('Redoc components', () => { let builder; let fixture; let element; + let dom; let destroySpy; - let dom = new BrowserDomAdapter(); - beforeEachProviders(() => [ - provide(SpecManager, {useValue: new SpecManager()}), - provide(BrowserDomAdapter, {useValue: new BrowserDomAdapter()}), - provide(OptionsService, {useValue: optsMgr}) - ]); - beforeEach(async(inject([TestComponentBuilder, SpecManager], (tcb, specMgr) => { + + beforeEach(async(inject([TestComponentBuilder, SpecManager, OptionsService, BrowserDomAdapter], + (tcb, specMgr, opts, _dom) => { builder = tcb; + optsMgr = opts; + dom = _dom; return specMgr.load('/tests/schemas/methods-list-component.json'); }))); - beforeEach((done) => { - builder.createAsync(TestAppComponent).then(_fixture => { - fixture = _fixture; - element = getChildDebugElement(fixture.debugElement, 'methods-list').nativeElement; - destroySpy = jasmine.createSpy('spy'); - Redoc.appRef = >{ - destroy: destroySpy - }; - fixture.detectChanges(); - done(); - }, err => { throw err; }); + beforeEach(() => { + fixture = builder.createSync(TestAppComponent); + element = getChildDebugElement(fixture.debugElement, 'methods-list').nativeElement; + destroySpy = jasmine.createSpy('spy'); + Redoc.appRef = >{ + destroy: destroySpy + }; + fixture.detectChanges(); }); afterEach(()=> { diff --git a/lib/components/SideMenu/side-menu.spec.ts b/lib/components/SideMenu/side-menu.spec.ts index c2f0d999..fce798f3 100644 --- a/lib/components/SideMenu/side-menu.spec.ts +++ b/lib/components/SideMenu/side-menu.spec.ts @@ -6,10 +6,7 @@ import { OptionsService } from '../../services/index'; import { inject, - async, - beforeEach, - beforeEachProviders, - it + async } from '@angular/core/testing'; import { TestComponentBuilder } from '@angular/compiler/testing'; @@ -25,9 +22,7 @@ describe('Redoc components', () => { let builder; let component; let fixture; - beforeEachProviders(() => [ - provide(SpecManager, {useValue: new SpecManager()}) - ]); + beforeEach(async(inject([TestComponentBuilder, SpecManager, OptionsService], (tcb, specMgr, opts) => { builder = tcb; @@ -39,15 +34,10 @@ describe('Redoc components', () => { return specMgr.load('/tests/schemas/extended-petstore.yml'); }))); - beforeEach((done) => { - builder.createAsync(TestAppComponent).then(_fixture => { - fixture = _fixture; - component = getChildDebugElement(fixture.debugElement, 'side-menu').componentInstance; - fixture.detectChanges(); - done(); - }, err => { - throw err; - }); + beforeEach(() => { + fixture = builder.createSync(TestAppComponent); + component = getChildDebugElement(fixture.debugElement, 'side-menu').componentInstance; + fixture.detectChanges(); }); afterEach(() => { diff --git a/lib/components/base.ts b/lib/components/base.ts index eadcca3a..8e847fd9 100644 --- a/lib/components/base.ts +++ b/lib/components/base.ts @@ -60,9 +60,7 @@ export function RedocComponent(options) { inputs: inputs, outputs: options.outputs, providers: options.providers, - changeDetection: options.detect ? - (options.onPushOnly ? ChangeDetectionStrategy.OnPush : ChangeDetectionStrategy.Default) : - ChangeDetectionStrategy.Detached, + changeDetection: options.onPushOnly ? ChangeDetectionStrategy.OnPush : ChangeDetectionStrategy.Default, animations: options.animations, templateUrl: options.templateUrl, template: options.template, diff --git a/lib/services/menu.service.spec.ts b/lib/services/menu.service.spec.ts index b273fad1..df8697de 100644 --- a/lib/services/menu.service.spec.ts +++ b/lib/services/menu.service.spec.ts @@ -1,17 +1,11 @@ 'use strict'; -import { provide, Component } from '@angular/core'; -import { BrowserDomAdapter } from '@angular/platform-browser/src/browser/browser_adapter'; +import { Component } from '@angular/core'; import { inject, - beforeEach, - describe, - beforeEachProviders, - it, - async + async, + TestComponentBuilder } from '@angular/core/testing'; -import { TestComponentBuilder } from '@angular/compiler/testing'; - import { MenuService } from './menu.service'; import { Hash } from './hash.service'; import { ScrollService } from './scroll.service'; @@ -21,37 +15,21 @@ import { SpecManager } from '../utils/SpecManager';; describe('Menu service', () => { let menu, hashService, scroll; let builder; - let specMgr = new SpecManager(); + let specMgr; - beforeEachProviders(() => [ - provide(BrowserDomAdapter, {useClass: BrowserDomAdapter}), - provide(Hash, {useClass: Hash}), - provide(ScrollService, {useClass: ScrollService}), - provide(SpecManager, {useValue: new SpecManager()}) - ]); - - beforeEach(async(inject([Hash, ScrollService, TestComponentBuilder, SpecManager], - (_hash, _scroll, tcb, _specMgr) => { + beforeEach(async(inject([TestComponentBuilder, SpecManager, Hash, ScrollService], + (tcb, _specMgr, _hash, _scroll, _menu) => { hashService = _hash; scroll = _scroll; builder = tcb; specMgr = _specMgr; + return specMgr.load('/tests/schemas/extended-petstore.yml'); }))); - beforeEach(done => { - specMgr.load('/tests/schemas/extended-petstore.yml').then(r => { - done(); - }).catch(e => { - done.fail(e); - }); - }); - - beforeEach(done => { + beforeEach(() => { menu = new MenuService(hashService, scroll, specMgr); - builder.createAsync(TestAppComponent).then(fixture => { - fixture.detectChanges(); - done(); - }).catch(err => done.fail(err) ); + let fixture = builder.createSync(TestAppComponent); + fixture.detectChanges(); }); it('should run hashScroll when hash changed', (done) => { diff --git a/lib/services/options.service.spec.ts b/lib/services/options.service.spec.ts index da53645a..d5354aee 100644 --- a/lib/services/options.service.spec.ts +++ b/lib/services/options.service.spec.ts @@ -1,10 +1,6 @@ 'use strict'; import { BrowserDomAdapter } from '@angular/platform-browser/src/browser/browser_adapter'; -import { - it -} from '@angular/core/testing'; - import { OptionsService } from './options.service'; describe('Options Service', () => { diff --git a/lib/services/schema-normalizer.service.spec.ts b/lib/services/schema-normalizer.service.spec.ts index 7ca23d47..64d11026 100644 --- a/lib/services/schema-normalizer.service.spec.ts +++ b/lib/services/schema-normalizer.service.spec.ts @@ -1,10 +1,5 @@ 'use strict'; import { SchemaNormalizer } from './schema-normalizer.service'; -import { - describe, - it -} from '@angular/core/testing'; - import { SpecManager } from '../utils/SpecManager';; describe('Spec Helper', () => { diff --git a/lib/shared/components/StickySidebar/sticky-sidebar.spec.ts b/lib/shared/components/StickySidebar/sticky-sidebar.spec.ts index a35fdea5..d84d4231 100644 --- a/lib/shared/components/StickySidebar/sticky-sidebar.spec.ts +++ b/lib/shared/components/StickySidebar/sticky-sidebar.spec.ts @@ -1,18 +1,12 @@ 'use strict'; import { getChildDebugElementByType } from '../../../../tests/helpers'; -import { Component, provide } from '@angular/core'; -import { BrowserDomAdapter } from '@angular/platform-browser/src/browser/browser_adapter'; - +import { Component } from '@angular/core'; import { inject, - beforeEach, - beforeEachProviders, - it + TestComponentBuilder } from '@angular/core/testing'; -import { TestComponentBuilder } from '@angular/compiler/testing'; - import { StickySidebar } from '../index'; describe('Common components', () => { @@ -21,20 +15,12 @@ describe('Common components', () => { let component; let fixture; - beforeEachProviders(() => [ - provide(BrowserDomAdapter, {useValue: new BrowserDomAdapter()}) - ]); beforeEach(inject([TestComponentBuilder], (tcb) => { builder = tcb; + fixture = builder.createSync(TestApp); + let debugEl = getChildDebugElementByType(fixture.debugElement, StickySidebar); + component = debugEl.injector.get(StickySidebar); })); - beforeEach((done) => { - builder.createAsync(TestApp).then(_fixture => { - fixture = _fixture; - let debugEl = getChildDebugElementByType(fixture.debugElement, StickySidebar); - component = debugEl.injector.get(StickySidebar); - done(); - }, err => done.fail(err)); - }); it('should init component', () => { diff --git a/lib/shared/components/StickySidebar/sticky-sidebar.ts b/lib/shared/components/StickySidebar/sticky-sidebar.ts index 7f9c7a9c..e3d2af06 100644 --- a/lib/shared/components/StickySidebar/sticky-sidebar.ts +++ b/lib/shared/components/StickySidebar/sticky-sidebar.ts @@ -1,7 +1,7 @@ 'use strict'; import { Directive, ElementRef, Input, OnInit, OnDestroy } from '@angular/core'; -import {BrowserDomAdapter} from '@angular/platform-browser/src/browser/browser_adapter'; +import { BrowserDomAdapter } from '@angular/platform-browser/src/browser/browser_adapter'; @Directive({ selector: '[sticky-sidebar]' diff --git a/lib/shared/components/Tabs/tabs.spec.ts b/lib/shared/components/Tabs/tabs.spec.ts index 05a1f196..c48e0f61 100644 --- a/lib/shared/components/Tabs/tabs.spec.ts +++ b/lib/shared/components/Tabs/tabs.spec.ts @@ -5,12 +5,9 @@ import { Component } from '@angular/core'; import { inject, - beforeEach, - it + TestComponentBuilder } from '@angular/core/testing'; -import { TestComponentBuilder } from '@angular/compiler/testing'; - import {Tabs, Tab} from '../index'; describe('Common components', () => { @@ -24,18 +21,12 @@ describe('Common components', () => { beforeEach(inject([TestComponentBuilder], (tcb) => { builder = tcb; + fixture = builder.createSync(TestApp); + hostComponent = fixture.debugElement.componentInstance; + debugEl = getChildDebugElement(fixture.debugElement, 'tabs'); + childDebugEls = getChildDebugElementAll(debugEl, 'tab'); + component = debugEl.componentInstance; })); - beforeEach((done) => { - builder.createAsync(TestApp).then(_fixture => { - fixture = _fixture; - hostComponent = fixture.debugElement.componentInstance; - debugEl = getChildDebugElement(fixture.debugElement, 'tabs'); - childDebugEls = getChildDebugElementAll(debugEl, 'tab'); - component = debugEl.componentInstance; - done(); - }, err => done.fail(err)); - }); - it('should init component', () => { expect(component).not.toBeNull(); diff --git a/lib/shared/components/Zippy/zippy.spec.ts b/lib/shared/components/Zippy/zippy.spec.ts index 7be746b1..01310c2f 100644 --- a/lib/shared/components/Zippy/zippy.spec.ts +++ b/lib/shared/components/Zippy/zippy.spec.ts @@ -5,12 +5,10 @@ import { getChildDebugElement, mouseclick } from '../../../../tests/helpers'; import { Component } from '@angular/core'; import { inject, - beforeEach, - it, - expect + expect, + TestComponentBuilder } from '@angular/core/testing'; -import { TestComponentBuilder } from '@angular/compiler/testing'; import { Zippy } from '../index'; describe('Common components', () => { @@ -22,17 +20,11 @@ describe('Common components', () => { beforeEach(inject([TestComponentBuilder], (tcb) => { builder = tcb; + fixture = builder.createSync(TestApp); + let debugEl = getChildDebugElement(fixture.debugElement, 'zippy'); + component = debugEl.componentInstance; + nativeElement = debugEl.nativeElement; })); - beforeEach((done) => { - builder.createAsync(TestApp).then(_fixture => { - fixture = _fixture; - let debugEl = getChildDebugElement(fixture.debugElement, 'zippy'); - component = debugEl.componentInstance; - nativeElement = debugEl.nativeElement; - done(); - }, err => done.fail(err)); - }); - it('should init component', () => { expect(component).not.toBeNull(); diff --git a/package.json b/package.json index bc0195e8..22a19ed8 100644 --- a/package.json +++ b/package.json @@ -32,17 +32,11 @@ "jspm": { "configFile": "system.config.js", "dependencies": { - "@angular/common": "npm:@angular/common@^2.0.0-rc.2", - "@angular/common@2.0.0-rc.3": "npm:@angular/common@2.0.0-rc.3", - "@angular/compiler": "npm:@angular/compiler@^2.0.0-rc.2", - "@angular/compiler@2.0.0-rc.3": "npm:@angular/compiler@2.0.0-rc.3", - "@angular/core": "npm:@angular/core@^2.0.0-rc.2", - "@angular/core@2.0.0-rc.3": "npm:@angular/core@2.0.0-rc.3", - "@angular/platform-browser": "npm:@angular/platform-browser@^2.0.0-rc.2", - "@angular/platform-browser-dynamic": "npm:@angular/platform-browser-dynamic@^2.0.0-rc.2", - "@angular/platform-browser-dynamic@2.0.0-rc.3": "npm:@angular/platform-browser-dynamic@2.0.0-rc.3", - "@angular/platform-browser@2.0.0-rc.3": "npm:@angular/platform-browser@2.0.0-rc.3", - "@angular/platform-server@2.0.0-rc.3": "npm:@angular/platform-server@2.0.0-rc.3", + "@angular/common@2.0.0-rc.4": "npm:@angular/common@2.0.0-rc.4", + "@angular/compiler@2.0.0-rc.4": "npm:@angular/compiler@2.0.0-rc.4", + "@angular/core@2.0.0-rc.4": "npm:@angular/core@2.0.0-rc.4", + "@angular/platform-browser-dynamic@2.0.0-rc.4": "npm:@angular/platform-browser-dynamic@2.0.0-rc.4", + "@angular/platform-browser@2.0.0-rc.4": "npm:@angular/platform-browser@2.0.0-rc.4", "dropkickjs": "npm:dropkickjs@^2.1.8", "es6-shim": "github:es-shims/es6-shim@^0.33.6", "hint.css": "npm:hint.css@^2.2.1", @@ -82,12 +76,12 @@ } }, "devDependencies": { - "@angular/common": "^2.0.0-rc.3", - "@angular/compiler": "^2.0.0-rc.3", - "@angular/core": "^2.0.0-rc.2", - "@angular/platform-browser": "^2.0.0-rc.3", - "@angular/platform-browser-dynamic": "^2.0.0-rc.3", - "@angular/platform-server": "^2.0.0-rc.3", + "@angular/common": "^2.0.0-rc.4", + "@angular/compiler": "^2.0.0-rc.4", + "@angular/core": "^2.0.0-rc.4", + "@angular/platform-browser": "^2.0.0-rc.4", + "@angular/platform-browser-dynamic": "^2.0.0-rc.4", + "@angular/platform-server": "^2.0.0-rc.4", "babel-polyfill": "^6.3.14", "branch-release": "^1.0.3", "browser-sync": "^2.10.1", @@ -139,7 +133,7 @@ "should": "^9.0.2", "sinon": "^1.17.2", "systemjs-builder": "^0.15.16", - "tslint": "^3.11.0", + "tslint": "^3.13.0", "tslint-stylish": "^2.1.0-beta", "typescript": "^1.8.10", "vinyl-paths": "^2.0.0", diff --git a/system.config.js b/system.config.js index 671df661..c91cace9 100644 --- a/system.config.js +++ b/system.config.js @@ -16,17 +16,11 @@ System.config({ }, map: { - "@angular/common": "npm:@angular/common@2.0.0-rc.3", - "@angular/common@2.0.0-rc.3": "npm:@angular/common@2.0.0-rc.3", - "@angular/compiler": "npm:@angular/compiler@2.0.0-rc.3", - "@angular/compiler@2.0.0-rc.3": "npm:@angular/compiler@2.0.0-rc.3", - "@angular/core": "npm:@angular/core@2.0.0-rc.3", - "@angular/core@2.0.0-rc.3": "npm:@angular/core@2.0.0-rc.3", - "@angular/platform-browser": "npm:@angular/platform-browser@2.0.0-rc.3", - "@angular/platform-browser-dynamic": "npm:@angular/platform-browser-dynamic@2.0.0-rc.3", - "@angular/platform-browser-dynamic@2.0.0-rc.3": "npm:@angular/platform-browser-dynamic@2.0.0-rc.3", - "@angular/platform-browser@2.0.0-rc.3": "npm:@angular/platform-browser@2.0.0-rc.3", - "@angular/platform-server@2.0.0-rc.3": "npm:@angular/platform-server@2.0.0-rc.3", + "@angular/common": "npm:@angular/common@2.0.0-rc.4", + "@angular/compiler": "npm:@angular/compiler@2.0.0-rc.4", + "@angular/core": "npm:@angular/core@2.0.0-rc.4", + "@angular/platform-browser-dynamic": "npm:@angular/platform-browser-dynamic@2.0.0-rc.4", + "@angular/platform-browser": "npm:@angular/platform-browser@2.0.0-rc.4", "babel": "npm:babel-core@5.8.34", "babel-runtime": "npm:babel-runtime@5.8.34", "clean-css": "npm:clean-css@3.4.17", @@ -122,39 +116,32 @@ System.config({ "github:jspm/nodelibs-zlib@0.1.0": { "browserify-zlib": "npm:browserify-zlib@0.1.4" }, - "npm:@angular/common@2.0.0-rc.3": { - "@angular/core": "npm:@angular/core@2.0.0-rc.3", + "npm:@angular/common@2.0.0-rc.4": { + "@angular/core": "npm:@angular/core@2.0.0-rc.4", "process": "github:jspm/nodelibs-process@0.1.2" }, - "npm:@angular/compiler@2.0.0-rc.3": { - "@angular/core": "npm:@angular/core@2.0.0-rc.3", + "npm:@angular/compiler@2.0.0-rc.4": { + "@angular/core": "npm:@angular/core@2.0.0-rc.4", "process": "github:jspm/nodelibs-process@0.1.2" }, - "npm:@angular/core@2.0.0-rc.3": { + "npm:@angular/core@2.0.0-rc.4": { "process": "github:jspm/nodelibs-process@0.1.2", "rxjs": "npm:rxjs@5.0.0-beta.6", "zone.js": "npm:zone.js@0.6.12" }, - "npm:@angular/platform-browser-dynamic@2.0.0-rc.3": { - "@angular/common": "npm:@angular/common@2.0.0-rc.3", - "@angular/compiler": "npm:@angular/compiler@2.0.0-rc.3", - "@angular/core": "npm:@angular/core@2.0.0-rc.3", - "@angular/platform-browser": "npm:@angular/platform-browser@2.0.0-rc.3", + "npm:@angular/platform-browser-dynamic@2.0.0-rc.4": { + "@angular/common": "npm:@angular/common@2.0.0-rc.4", + "@angular/compiler": "npm:@angular/compiler@2.0.0-rc.4", + "@angular/core": "npm:@angular/core@2.0.0-rc.4", + "@angular/platform-browser": "npm:@angular/platform-browser@2.0.0-rc.4", "process": "github:jspm/nodelibs-process@0.1.2" }, - "npm:@angular/platform-browser@2.0.0-rc.3": { - "@angular/common": "npm:@angular/common@2.0.0-rc.3", - "@angular/compiler": "npm:@angular/compiler@2.0.0-rc.3", - "@angular/core": "npm:@angular/core@2.0.0-rc.3", + "npm:@angular/platform-browser@2.0.0-rc.4": { + "@angular/common": "npm:@angular/common@2.0.0-rc.4", + "@angular/compiler": "npm:@angular/compiler@2.0.0-rc.4", + "@angular/core": "npm:@angular/core@2.0.0-rc.4", "process": "github:jspm/nodelibs-process@0.1.2" }, - "npm:@angular/platform-server@2.0.0-rc.3": { - "@angular/common": "npm:@angular/common@2.0.0-rc.3", - "@angular/compiler": "npm:@angular/compiler@2.0.0-rc.3", - "@angular/core": "npm:@angular/core@2.0.0-rc.3", - "@angular/platform-browser": "npm:@angular/platform-browser@2.0.0-rc.3", - "parse5": "npm:parse5@1.3.2" - }, "npm:amdefine@1.0.0": { "fs": "github:jspm/nodelibs-fs@0.1.2", "module": "github:jspm/nodelibs-module@0.1.0", @@ -686,9 +673,6 @@ System.config({ "pbkdf2": "npm:pbkdf2@3.0.4", "systemjs-json": "github:systemjs/plugin-json@0.1.2" }, - "npm:parse5@1.3.2": { - "process": "github:jspm/nodelibs-process@0.1.2" - }, "npm:path-browserify@0.0.0": { "process": "github:jspm/nodelibs-process@0.1.2" }, diff --git a/tests/setup.ts b/tests/setup.ts index ec80345a..82a0493e 100644 --- a/tests/setup.ts +++ b/tests/setup.ts @@ -2,7 +2,8 @@ import {setBaseTestProviders} from '@angular/core/testing'; import { BrowserDomAdapter } from '@angular/platform-browser/src/browser/browser_adapter'; -import { OptionsService, RedocEventsService} from '../lib/services/index'; +import { OptionsService, RedocEventsService, Hash, ScrollService, MenuService } from '../lib/services/index'; +import { SpecManager } from '../lib/utils/SpecManager'; import { provide } from '@angular/core'; import { @@ -15,6 +16,10 @@ setBaseTestProviders( TEST_BROWSER_DYNAMIC_PLATFORM_PROVIDERS, provide(BrowserDomAdapter, {useClass: BrowserDomAdapter}), provide(OptionsService, {useClass: OptionsService}), - provide(RedocEventsService, {useClass: RedocEventsService}) + provide(RedocEventsService, {useClass: RedocEventsService}), + provide(SpecManager, {useClass: SpecManager}), + provide(Hash, {useClass: Hash}), + provide(ScrollService, {useClass: ScrollService}), + provide(MenuService, {useClass: MenuService}) ], [TEST_BROWSER_DYNAMIC_APPLICATION_PROVIDERS]); From 81d06316ed2801de07ce68eed3f5b2cd35403302 Mon Sep 17 00:00:00 2001 From: Roman Hotsiy Date: Fri, 1 Jul 2016 16:30:35 +0300 Subject: [PATCH 02/10] Add trackBy to tags --- lib/components/MethodsList/methods-list.html | 2 +- lib/components/MethodsList/methods-list.spec.ts | 2 +- lib/components/MethodsList/methods-list.ts | 4 ++++ 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/components/MethodsList/methods-list.html b/lib/components/MethodsList/methods-list.html index 6d867af0..c9c873cf 100644 --- a/lib/components/MethodsList/methods-list.html +++ b/lib/components/MethodsList/methods-list.html @@ -1,5 +1,5 @@
-
+

{{tag.name}}

diff --git a/lib/components/MethodsList/methods-list.spec.ts b/lib/components/MethodsList/methods-list.spec.ts index 75394166..b8e6be02 100644 --- a/lib/components/MethodsList/methods-list.spec.ts +++ b/lib/components/MethodsList/methods-list.spec.ts @@ -1,6 +1,6 @@ 'use strict'; -import { Component, provide } from '@angular/core'; +import { Component } from '@angular/core'; import { inject, async, diff --git a/lib/components/MethodsList/methods-list.ts b/lib/components/MethodsList/methods-list.ts index a919cdfe..0e9e11d4 100644 --- a/lib/components/MethodsList/methods-list.ts +++ b/lib/components/MethodsList/methods-list.ts @@ -46,4 +46,8 @@ export class MethodsList extends BaseComponent { trackByPointer(idx, el) { return el.pointer; } + + trackByTagName(idx, el) { + return el.name; + } } From 4a475677f79b5a00996bdd882ef97223aac1d864 Mon Sep 17 00:00:00 2001 From: Roman Hotsiy Date: Fri, 1 Jul 2016 16:30:45 +0300 Subject: [PATCH 03/10] Clean up tests --- lib/components/Redoc/redoc.spec.ts | 4 ++-- lib/components/Redoc/redoc.ts | 5 ++--- lib/components/SideMenu/side-menu.spec.ts | 2 +- lib/services/schema-normalizer.service.spec.ts | 9 +++++++++ tests/schemas/base-component-dereference.json | 2 -- 5 files changed, 14 insertions(+), 8 deletions(-) diff --git a/lib/components/Redoc/redoc.spec.ts b/lib/components/Redoc/redoc.spec.ts index 073810e8..9fc6ae14 100644 --- a/lib/components/Redoc/redoc.spec.ts +++ b/lib/components/Redoc/redoc.spec.ts @@ -58,7 +58,7 @@ describe('Redoc components', () => { }); it('should return promise', () => { - let res = Redoc.init(); + let res = Redoc.init().catch(() => {/**/}); res.should.be.instanceof(Promise); }); @@ -66,7 +66,7 @@ describe('Redoc components', () => { spyOn(Redoc, 'hideLoadingAnimation').and.callThrough(); spyOn(Redoc, 'displayError').and.callThrough(); let res = Redoc.init(); - return res.then(() => { + return res.catch(() => { expect(Redoc.hideLoadingAnimation).toHaveBeenCalled(); expect(Redoc.displayError).toHaveBeenCalled(); }); diff --git a/lib/components/Redoc/redoc.ts b/lib/components/Redoc/redoc.ts index e523a4d3..6a6de353 100644 --- a/lib/components/Redoc/redoc.ts +++ b/lib/components/Redoc/redoc.ts @@ -79,10 +79,10 @@ export class Redoc extends BaseComponent implements AfterViewInit { Redoc.hideLoadingAnimation(); Redoc.appRef = appRef; console.log('ReDoc bootstrapped!'); - }, err => { - console.log(err); + }).catch(err => { Redoc.hideLoadingAnimation(); Redoc.displayError(err); + throw err; }); } @@ -97,7 +97,6 @@ export class Redoc extends BaseComponent implements AfterViewInit { } static displayError(err) { - console.log(err); let redocEl = dom.query('redoc'); if (!redocEl) return; let heading = 'Oops... ReDoc failed to render this spec'; diff --git a/lib/components/SideMenu/side-menu.spec.ts b/lib/components/SideMenu/side-menu.spec.ts index fce798f3..f4d139d6 100644 --- a/lib/components/SideMenu/side-menu.spec.ts +++ b/lib/components/SideMenu/side-menu.spec.ts @@ -1,7 +1,7 @@ 'use strict'; import { getChildDebugElement } from '../../../tests/helpers'; -import { Component, provide } from '@angular/core'; +import { Component } from '@angular/core'; import { OptionsService } from '../../services/index'; import { diff --git a/lib/services/schema-normalizer.service.spec.ts b/lib/services/schema-normalizer.service.spec.ts index 64d11026..cab630df 100644 --- a/lib/services/schema-normalizer.service.spec.ts +++ b/lib/services/schema-normalizer.service.spec.ts @@ -111,9 +111,18 @@ describe('Spec Helper', () => { let resolved; beforeAll(() => { let pointer = '/paths/test5/get/parameters/0'; + spyOn(console, 'warn').and.stub(); resolved = normalizer.normalize(specMgr.byPointer(pointer), pointer); }); + afterAll(() => { + (console.warn).and.callThrough(); + }); + + it('should print warning to console', () => { + expect(console.warn).toHaveBeenCalled(); + }); + it('should skip other fields', () => { expect(resolved.$ref).toBeUndefined(); expect(resolved.title).toBeDefined(); diff --git a/tests/schemas/base-component-dereference.json b/tests/schemas/base-component-dereference.json index df5dcebc..21e9bf41 100644 --- a/tests/schemas/base-component-dereference.json +++ b/tests/schemas/base-component-dereference.json @@ -110,8 +110,6 @@ "parameters": [ { "$ref": "#/definitions/CircularTransitive", - "title": "test", - "description": "test" } ] } From b22b8d2122dd42bcf81f8363f961aa185686c735 Mon Sep 17 00:00:00 2001 From: Roman Hotsiy Date: Fri, 1 Jul 2016 17:24:59 +0300 Subject: [PATCH 04/10] Refactor menu generation + handle methods without tags --- lib/components/Method/method.html | 2 +- lib/components/Method/method.ts | 2 + lib/components/MethodsList/methods-list.html | 2 +- lib/components/MethodsList/methods-list.ts | 22 +++----- lib/components/SideMenu/side-menu.html | 3 +- lib/components/SideMenu/side-menu.scss | 4 ++ lib/services/menu.service.ts | 5 +- lib/services/schema-helper.service.ts | 54 ++++++++++++++++++++ lib/utils/SpecManager.ts | 47 ----------------- 9 files changed, 74 insertions(+), 67 deletions(-) diff --git a/lib/components/Method/method.html b/lib/components/Method/method.html index adbf9284..333ceaa3 100644 --- a/lib/components/Method/method.html +++ b/lib/components/Method/method.html @@ -1,7 +1,7 @@

- {{data.methodInfo.summary}} + {{data.summary}}

{{tag}} diff --git a/lib/components/Method/method.ts b/lib/components/Method/method.ts index 23d54b14..781b2afe 100644 --- a/lib/components/Method/method.ts +++ b/lib/components/Method/method.ts @@ -8,6 +8,7 @@ import { ResponsesList } from '../ResponsesList/responses-list'; import { ResponsesSamples } from '../ResponsesSamples/responses-samples'; import { SchemaSample } from '../SchemaSample/schema-sample'; import { RequestSamples } from '../RequestSamples/request-samples'; +import { SchemaHelper } from '../../services/schema-helper.service'; @RedocComponent({ selector: 'method', @@ -31,6 +32,7 @@ export class Method extends BaseComponent { this.data.methodInfo = this.componentSchema; this.data.methodInfo.tags = this.filterMainTags(this.data.methodInfo.tags); this.data.bodyParam = this.findBodyParam(); + this.data.summary = SchemaHelper.methodSummary(this.componentSchema); if (this.componentSchema.operationId) { this.data.methodAnchor = 'operation/' + encodeURIComponent(this.componentSchema.operationId); } else { diff --git a/lib/components/MethodsList/methods-list.html b/lib/components/MethodsList/methods-list.html index c9c873cf..6f42f8b6 100644 --- a/lib/components/MethodsList/methods-list.html +++ b/lib/components/MethodsList/methods-list.html @@ -1,6 +1,6 @@
-
+

{{tag.name}}

diff --git a/lib/components/MethodsList/methods-list.ts b/lib/components/MethodsList/methods-list.ts index 0e9e11d4..0add692f 100644 --- a/lib/components/MethodsList/methods-list.ts +++ b/lib/components/MethodsList/methods-list.ts @@ -4,6 +4,7 @@ import { forwardRef } from '@angular/core'; import { RedocComponent, BaseComponent, SpecManager } from '../base'; import { Method } from '../Method/method'; import { EncodeURIComponentPipe } from '../../utils/pipes'; +import { SchemaHelper } from '../../services/index'; @RedocComponent({ selector: 'methods-list', @@ -24,21 +25,14 @@ export class MethodsList extends BaseComponent { // follow SwaggerUI behavior for cases when one method has more than one tag: // duplicate methods - let menuStructure = this.specMgr.buildMenuTree(); - let tags = Array.from(menuStructure.entries()) - .map((entry) => { - let [tag, {description, methods}] = entry; - // inject tag name into method info - methods = methods || []; - methods.forEach(method => { - method.tag = tag; - }); - return { - name: tag, - description: description, - methods: methods - }; + let tags = SchemaHelper.buildMenuTree(this.specMgr.schema); + tags.forEach(tagInfo => { + // inject tag name into method info + tagInfo.methods = tagInfo.methods || []; + tagInfo.methods.forEach(method => { + method.tag = name; }); + }); this.data.tags = tags; // TODO: check $ref field } diff --git a/lib/components/SideMenu/side-menu.html b/lib/components/SideMenu/side-menu.html index c0929bf8..8b7ee961 100644 --- a/lib/components/SideMenu/side-menu.html +++ b/lib/components/SideMenu/side-menu.html @@ -9,7 +9,8 @@