diff --git a/ng2-components/ng2-activiti-tasklist/src/components/activiti-comments.component.spec.ts b/ng2-components/ng2-activiti-tasklist/src/components/activiti-comments.component.spec.ts index 0802e0d4fd..e9ddf508ff 100644 --- a/ng2-components/ng2-activiti-tasklist/src/components/activiti-comments.component.spec.ts +++ b/ng2-components/ng2-activiti-tasklist/src/components/activiti-comments.component.spec.ts @@ -75,16 +75,19 @@ describe('ActivitiTaskDetails', () => { }); it('should load comments when taskId specified', () => { - component.taskId = '123'; - fixture.detectChanges(); + let change = new SimpleChange(null, '123'); + component.ngOnChanges({ 'taskId': change }); + expect(getCommentsSpy).toHaveBeenCalled(); }); it('should emit an error when an error occurs loading comments', () => { let emitSpy = spyOn(component.error, 'emit'); getCommentsSpy.and.returnValue(Observable.throw({})); - component.taskId = '123'; - fixture.detectChanges(); + + let change = new SimpleChange(null, '123'); + component.ngOnChanges({ 'taskId': change }); + expect(emitSpy).toHaveBeenCalled(); }); @@ -94,8 +97,9 @@ describe('ActivitiTaskDetails', () => { }); it('should display comments when the task has comments', async(() => { - component.taskId = '123'; - fixture.detectChanges(); + let change = new SimpleChange(null, '123'); + component.ngOnChanges({ 'taskId': change }); + fixture.whenStable().then(() => { fixture.detectChanges(); expect(fixture.debugElement.queryAll(By.css('ul.mdl-list li')).length).toBe(3); diff --git a/ng2-components/ng2-activiti-tasklist/src/components/activiti-comments.component.ts b/ng2-components/ng2-activiti-tasklist/src/components/activiti-comments.component.ts index 38bb5f7f2a..bf01cf92d9 100644 --- a/ng2-components/ng2-activiti-tasklist/src/components/activiti-comments.component.ts +++ b/ng2-components/ng2-activiti-tasklist/src/components/activiti-comments.component.ts @@ -15,7 +15,7 @@ * limitations under the License. */ -import { Component, Input, Output, OnInit, ViewChild, OnChanges, SimpleChanges, EventEmitter } from '@angular/core'; +import { Component, Input, Output, ViewChild, OnChanges, SimpleChanges, EventEmitter } from '@angular/core'; import { AlfrescoTranslationService } from 'ng2-alfresco-core'; import { ActivitiTaskListService } from './../services/activiti-tasklist.service'; import { Comment } from '../models/comment.model'; @@ -30,7 +30,7 @@ let dialogPolyfill: any; styleUrls: ['./activiti-comments.component.css'], providers: [ActivitiTaskListService] }) -export class ActivitiComments implements OnInit, OnChanges { +export class ActivitiComments implements OnChanges { @Input() taskId: string; @@ -64,13 +64,9 @@ export class ActivitiComments implements OnInit, OnChanges { } this.comment$ = new Observable(observer => this.commentObserver = observer).share(); - } - - ngOnInit() { this.comment$.subscribe((comment: Comment) => { this.comments.push(comment); }); - this.getTaskComments(this.taskId); } ngOnChanges(changes: SimpleChanges) {