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', () => { it('should load comments when taskId specified', () => {
component.taskId = '123'; let change = new SimpleChange(null, '123');
fixture.detectChanges(); component.ngOnChanges({ 'taskId': change });
expect(getCommentsSpy).toHaveBeenCalled(); expect(getCommentsSpy).toHaveBeenCalled();
}); });
it('should emit an error when an error occurs loading comments', () => { it('should emit an error when an error occurs loading comments', () => {
let emitSpy = spyOn(component.error, 'emit'); let emitSpy = spyOn(component.error, 'emit');
getCommentsSpy.and.returnValue(Observable.throw({})); getCommentsSpy.and.returnValue(Observable.throw({}));
component.taskId = '123';
fixture.detectChanges(); let change = new SimpleChange(null, '123');
component.ngOnChanges({ 'taskId': change });
expect(emitSpy).toHaveBeenCalled(); expect(emitSpy).toHaveBeenCalled();
}); });
@ -94,8 +97,9 @@ describe('ActivitiTaskDetails', () => {
}); });
it('should display comments when the task has comments', async(() => { it('should display comments when the task has comments', async(() => {
component.taskId = '123'; let change = new SimpleChange(null, '123');
fixture.detectChanges(); component.ngOnChanges({ 'taskId': change });
fixture.whenStable().then(() => { fixture.whenStable().then(() => {
fixture.detectChanges(); fixture.detectChanges();
expect(fixture.debugElement.queryAll(By.css('ul.mdl-list li')).length).toBe(3); expect(fixture.debugElement.queryAll(By.css('ul.mdl-list li')).length).toBe(3);

View File

@ -15,7 +15,7 @@
* limitations under the License. * 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 { AlfrescoTranslationService } from 'ng2-alfresco-core';
import { ActivitiTaskListService } from './../services/activiti-tasklist.service'; import { ActivitiTaskListService } from './../services/activiti-tasklist.service';
import { Comment } from '../models/comment.model'; import { Comment } from '../models/comment.model';
@ -30,7 +30,7 @@ let dialogPolyfill: any;
styleUrls: ['./activiti-comments.component.css'], styleUrls: ['./activiti-comments.component.css'],
providers: [ActivitiTaskListService] providers: [ActivitiTaskListService]
}) })
export class ActivitiComments implements OnInit, OnChanges { export class ActivitiComments implements OnChanges {
@Input() @Input()
taskId: string; taskId: string;
@ -64,13 +64,9 @@ export class ActivitiComments implements OnInit, OnChanges {
} }
this.comment$ = new Observable<Comment>(observer => this.commentObserver = observer).share(); this.comment$ = new Observable<Comment>(observer => this.commentObserver = observer).share();
}
ngOnInit() {
this.comment$.subscribe((comment: Comment) => { this.comment$.subscribe((comment: Comment) => {
this.comments.push(comment); this.comments.push(comment);
}); });
this.getTaskComments(this.taskId);
} }
ngOnChanges(changes: SimpleChanges) { ngOnChanges(changes: SimpleChanges) {