Merge pull request #1302 from Alfresco/dev-mromano-1255

#1255 remove onInit, we already add comments with onChange
This commit is contained in:
Mario Romano 2016-12-16 17:41:40 +00:00 committed by GitHub
commit d675de3d95
2 changed files with 12 additions and 12 deletions

View File

@ -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);

View File

@ -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<Comment>(observer => this.commentObserver = observer).share();
}
ngOnInit() {
this.comment$.subscribe((comment: Comment) => {
this.comments.push(comment);
});
this.getTaskComments(this.taskId);
}
ngOnChanges(changes: SimpleChanges) {