From e5740fabe5d7a048a5f2690681234342e40d0bc5 Mon Sep 17 00:00:00 2001 From: Roman Hotsiy Date: Sat, 28 Jan 2017 15:57:22 +0200 Subject: [PATCH] fix tests --- lib/components/base.ts | 10 +++++----- lib/services/marker.service.ts | 5 +---- lib/services/search.service.ts | 10 +++++----- lib/shared/components/Zippy/zippy.spec.ts | 24 ++++++++++------------- lib/utils/spec-manager.ts | 4 ++-- tests/spec-bundle.js | 2 ++ 6 files changed, 25 insertions(+), 30 deletions(-) diff --git a/lib/components/base.ts b/lib/components/base.ts index bf195723..982a0608 100644 --- a/lib/components/base.ts +++ b/lib/components/base.ts @@ -51,7 +51,7 @@ export class BaseComponent implements OnInit, OnDestroy { } } -export class BaseSearchableComponent extends BaseComponent { +export abstract class BaseSearchableComponent extends BaseComponent implements OnDestroy { searchSubscription: Subscription; constructor(public specMgr: SpecManager, public app: AppStateService) { super(specMgr); @@ -71,14 +71,14 @@ export class BaseSearchableComponent extends BaseComponent { } ngOnDestroy() { - this.searchSubscription.unsubscribe(); + if (this.searchSubscription) { + this.searchSubscription.unsubscribe(); + } } /** + Used to destroy component * @abstract */ - ensureSearchIsShown(ptr: string) { - // empy - } + abstract ensureSearchIsShown(ptr: string); } diff --git a/lib/services/marker.service.ts b/lib/services/marker.service.ts index cc4a537b..d853ddd2 100644 --- a/lib/services/marker.service.ts +++ b/lib/services/marker.service.ts @@ -51,7 +51,7 @@ export class Marker { } else { for (let i=0; i < Math.min(diff, ROLL_LEN); i++) { let oldInst = this.rolledInstances.shift(); - oldInst && oldInst.unmark(); + if (oldInst) oldInst.unmark(); let idx = newIdx + Math.floor(ROLL_LEN/2) - i; let newMark = this.newMarkerAtMenuItem(idx); @@ -84,7 +84,4 @@ export class Marker { this.term = null; this.remark(); } - - updateMark() { - } } diff --git a/lib/services/search.service.ts b/lib/services/search.service.ts index 0e9c3b25..6011a2cf 100644 --- a/lib/services/search.service.ts +++ b/lib/services/search.service.ts @@ -17,7 +17,7 @@ const index = lunr(function () { this.field('title', {boost: 1.5}); this.field('body'); this.ref('pointer'); -}) +}); const store:StringMap = {}; @@ -54,7 +54,7 @@ export class SearchService { } indexPaths(swagger:any) { - const paths = swagger.paths + const paths = swagger.paths; const basePtr = '#/paths'; Object.keys(paths).forEach(path => { let opearations = paths[path]; @@ -74,7 +74,7 @@ export class SearchService { body: operation.description }); this.indexOperationResponses(operation, operationPointer); - this.indexOperationParameters(operation, operationPointer) + this.indexOperationParameters(operation, operationPointer); } indexOperationParameters(operation: any, operationPointer: string) { @@ -143,13 +143,13 @@ export class SearchService { menuId: menuPointer, title, body - }) + }); if (schema.properties) { Object.keys(schema.properties).forEach(propName => { let propPtr = JsonPointer.join(absolutePointer, ['properties', propName]); this.indexSchema(schema.properties[propName], propName, propPtr, menuPointer); - }) + }); } } } diff --git a/lib/shared/components/Zippy/zippy.spec.ts b/lib/shared/components/Zippy/zippy.spec.ts index 2dd7e178..db246662 100644 --- a/lib/shared/components/Zippy/zippy.spec.ts +++ b/lib/shared/components/Zippy/zippy.spec.ts @@ -16,7 +16,7 @@ describe('Common components', () => { }); describe('Zippy Component', () => { let builder; - let component; + let component: Zippy; let nativeElement; let fixture; @@ -33,13 +33,13 @@ describe('Common components', () => { it('should init component defaults', () => { component.empty.should.be.false(); - component.visible.should.be.false(); + component.open.should.be.false(); component.type.should.be.equal('general'); }); it('should init properties from dom params', () => { fixture.detectChanges(); - component.visible.should.be.true(); + component.open.should.be.true(); component.empty.should.be.true(); component.title.should.be.equal('Zippy'); component.type.should.be.equal('test'); @@ -54,7 +54,7 @@ describe('Common components', () => { it('should open and close zippy', (done) => { fixture.detectChanges(); component.empty = false; - component.visible = true; + component.open = true; fixture.detectChanges(); let testComponent = fixture.debugElement.componentInstance; @@ -62,13 +62,13 @@ describe('Common components', () => { let titleEl = nativeElement.querySelector('.zippy-title'); mouseclick(titleEl); fixture.detectChanges(); - component.visible.should.be.false(); + component.open.should.be.false(); testComponent.opened.should.be.false(); mouseclick(titleEl); fixture.detectChanges(); setTimeout(() => { - component.visible.should.be.true(); + component.open.should.be.true(); testComponent.opened.should.be.true(); testComponent.clickCount.should.be.equal(2); done(); @@ -95,21 +95,17 @@ describe('Common components', () => { @Component({ selector: 'test-app', template: - `test` + `test` }) class TestApp { opened: boolean; clickCount: number; constructor() { this.opened = false; - this.clickCount = 0; + this.clickCount = -1; // initial change detection } - open() { - this.opened = true; - this.clickCount++; - } - close() { - this.opened = false; + open(val) { + this.opened = val; this.clickCount++; } } diff --git a/lib/utils/spec-manager.ts b/lib/utils/spec-manager.ts index 27fe56c7..df367561 100644 --- a/lib/utils/spec-manager.ts +++ b/lib/utils/spec-manager.ts @@ -15,7 +15,7 @@ export interface DescendantInfo { $ref: string; name: string; active?: boolean; - idx: number; + idx?: number; } export class SpecManager { @@ -208,7 +208,7 @@ export class SpecManager { } } - res.push({name: derivedName, $ref: `#/definitions/${defName}`, idx: null}); + res.push({name: derivedName, $ref: `#/definitions/${defName}`}); } return res; } diff --git a/tests/spec-bundle.js b/tests/spec-bundle.js index 8a2964ba..ed92f3fa 100644 --- a/tests/spec-bundle.js +++ b/tests/spec-bundle.js @@ -48,6 +48,8 @@ beforeEach(function() { services.OptionsService, services.ComponentParser, services.ContentProjector, + services.Marker, + services.SearchService, { provide: sharedComponents.LazyTasksService, useClass: sharedComponents.LazyTasksServiceSync }, { provide: ErrorHandler, useClass: services.CustomErrorHandler }, { provide: services.COMPONENT_PARSER_ALLOWED, useValue: { 'security-definitions': components.SecurityDefinitions }}