mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-07-24 17:32:15 +00:00
enable prefer-const rule for tslint, fix issues (#4409)
* enable prefer-const rule for tslint, fix issues * Update content-node-selector.component.spec.ts * Update content-node-selector.component.spec.ts * fix const * fix lint issues * update tests * update tests * update tests * fix code * fix page class
This commit is contained in:
committed by
Eugenio Romano
parent
26c5982a1a
commit
a7a48e8b2b
@@ -144,28 +144,28 @@ describe('CommentListComponent', () => {
|
||||
|
||||
fixture.detectChanges();
|
||||
fixture.whenStable().then(() => {
|
||||
let comment = fixture.debugElement.query(By.css('#adf-comment-1'));
|
||||
const comment = fixture.debugElement.query(By.css('#adf-comment-1'));
|
||||
comment.triggerEventHandler('click', null);
|
||||
});
|
||||
}));
|
||||
|
||||
it('should deselect the previous selected comment when a new one is clicked', async(() => {
|
||||
processCommentOne.isSelected = true;
|
||||
let commentOne = Object.assign({}, processCommentOne);
|
||||
let commentTwo = Object.assign({}, processCommentTwo);
|
||||
const commentOne = Object.assign({}, processCommentOne);
|
||||
const commentTwo = Object.assign({}, processCommentTwo);
|
||||
commentList.selectedComment = commentOne;
|
||||
commentList.comments = [commentOne, commentTwo];
|
||||
|
||||
commentList.clickRow.subscribe((selectedComment) => {
|
||||
fixture.detectChanges();
|
||||
let commentSelectedList = fixture.nativeElement.querySelectorAll('.adf-is-selected');
|
||||
const commentSelectedList = fixture.nativeElement.querySelectorAll('.adf-is-selected');
|
||||
expect(commentSelectedList.length).toBe(1);
|
||||
expect(commentSelectedList[0].textContent).toContain('2nd Test Comment');
|
||||
});
|
||||
|
||||
fixture.detectChanges();
|
||||
fixture.whenStable().then(() => {
|
||||
let comment = fixture.debugElement.query(By.css('#adf-comment-2'));
|
||||
const comment = fixture.debugElement.query(By.css('#adf-comment-2'));
|
||||
comment.triggerEventHandler('click', null);
|
||||
});
|
||||
}));
|
||||
@@ -183,7 +183,7 @@ describe('CommentListComponent', () => {
|
||||
fixture.detectChanges();
|
||||
|
||||
fixture.whenStable().then(() => {
|
||||
let elements = fixture.nativeElement.querySelectorAll('#comment-message');
|
||||
const elements = fixture.nativeElement.querySelectorAll('#comment-message');
|
||||
expect(elements.length).toBe(1);
|
||||
expect(elements[0].innerText).toBe(processCommentOne.message);
|
||||
expect(fixture.nativeElement.querySelector('#comment-message:empty')).toBeNull();
|
||||
@@ -195,7 +195,7 @@ describe('CommentListComponent', () => {
|
||||
fixture.detectChanges();
|
||||
|
||||
fixture.whenStable().then(() => {
|
||||
let elements = fixture.nativeElement.querySelectorAll('#comment-user');
|
||||
const elements = fixture.nativeElement.querySelectorAll('#comment-user');
|
||||
expect(elements.length).toBe(1);
|
||||
expect(elements[0].innerText).toBe(processCommentOne.createdBy.firstName + ' ' + processCommentOne.createdBy.lastName);
|
||||
expect(fixture.nativeElement.querySelector('#comment-user:empty')).toBeNull();
|
||||
@@ -203,7 +203,7 @@ describe('CommentListComponent', () => {
|
||||
}));
|
||||
|
||||
it('comment date time should start with few seconds ago when comment date is few seconds ago', async(() => {
|
||||
let commentFewSecond = Object.assign({}, processCommentOne);
|
||||
const commentFewSecond = Object.assign({}, processCommentOne);
|
||||
commentFewSecond.created = new Date();
|
||||
|
||||
commentList.comments = [commentFewSecond];
|
||||
@@ -216,7 +216,7 @@ describe('CommentListComponent', () => {
|
||||
}));
|
||||
|
||||
it('comment date time should start with Yesterday when comment date is yesterday', async(() => {
|
||||
let commentOld = Object.assign({}, processCommentOne);
|
||||
const commentOld = Object.assign({}, processCommentOne);
|
||||
commentOld.created = new Date((Date.now() - 24 * 3600 * 1000));
|
||||
commentList.comments = [commentOld];
|
||||
fixture.detectChanges();
|
||||
@@ -228,7 +228,7 @@ describe('CommentListComponent', () => {
|
||||
}));
|
||||
|
||||
it('comment date time should not start with Today/Yesterday when comment date is before yesterday', async(() => {
|
||||
let commentOld = Object.assign({}, processCommentOne);
|
||||
const commentOld = Object.assign({}, processCommentOne);
|
||||
commentOld.created = new Date((Date.now() - 24 * 3600 * 1000 * 2));
|
||||
commentList.comments = [commentOld];
|
||||
fixture.detectChanges();
|
||||
@@ -245,7 +245,7 @@ describe('CommentListComponent', () => {
|
||||
fixture.detectChanges();
|
||||
|
||||
fixture.whenStable().then(() => {
|
||||
let elements = fixture.nativeElement.querySelectorAll('#comment-user-icon');
|
||||
const elements = fixture.nativeElement.querySelectorAll('#comment-user-icon');
|
||||
expect(elements.length).toBe(1);
|
||||
expect(elements[0].innerText).toContain(commentList.getUserShortName(processCommentOne.createdBy));
|
||||
expect(fixture.nativeElement.querySelector('#comment-user-icon:empty')).toBeNull();
|
||||
@@ -257,7 +257,7 @@ describe('CommentListComponent', () => {
|
||||
fixture.detectChanges();
|
||||
|
||||
fixture.whenStable().then(() => {
|
||||
let elements = fixture.nativeElement.querySelectorAll('.adf-people-img');
|
||||
const elements = fixture.nativeElement.querySelectorAll('.adf-people-img');
|
||||
expect(elements.length).toBe(1);
|
||||
expect(fixture.nativeElement.getElementsByClassName('adf-people-img')[0].src).toContain('content-user-image');
|
||||
});
|
||||
@@ -268,7 +268,7 @@ describe('CommentListComponent', () => {
|
||||
fixture.detectChanges();
|
||||
|
||||
fixture.whenStable().then(() => {
|
||||
let elements = fixture.nativeElement.querySelectorAll('.adf-people-img');
|
||||
const elements = fixture.nativeElement.querySelectorAll('.adf-people-img');
|
||||
expect(elements.length).toBe(1);
|
||||
expect(fixture.nativeElement.getElementsByClassName('adf-people-img')[0].src).toContain('process-user-image');
|
||||
});
|
||||
@@ -279,7 +279,7 @@ describe('CommentListComponent', () => {
|
||||
fixture.detectChanges();
|
||||
|
||||
fixture.whenStable().then(() => {
|
||||
let elements = fixture.nativeElement.querySelectorAll('.adf-comment-user-icon');
|
||||
const elements = fixture.nativeElement.querySelectorAll('.adf-comment-user-icon');
|
||||
expect(elements.length).toBe(1);
|
||||
});
|
||||
}));
|
||||
@@ -289,7 +289,7 @@ describe('CommentListComponent', () => {
|
||||
fixture.detectChanges();
|
||||
|
||||
fixture.whenStable().then(() => {
|
||||
let elements = fixture.nativeElement.querySelectorAll('.adf-comment-user-icon');
|
||||
const elements = fixture.nativeElement.querySelectorAll('.adf-comment-user-icon');
|
||||
expect(elements.length).toBe(1);
|
||||
});
|
||||
}));
|
||||
|
@@ -77,24 +77,24 @@ describe('CommentsComponent', () => {
|
||||
});
|
||||
|
||||
it('should load comments when taskId specified', () => {
|
||||
let change = new SimpleChange(null, '123', true);
|
||||
const change = new SimpleChange(null, '123', true);
|
||||
component.ngOnChanges({'taskId': change});
|
||||
|
||||
expect(getProcessCommentsSpy).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('should load comments when nodeId specified', () => {
|
||||
let change = new SimpleChange(null, '123', true);
|
||||
const change = new SimpleChange(null, '123', true);
|
||||
component.ngOnChanges({'nodeId': change});
|
||||
|
||||
expect(getContentCommentsSpy).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('should emit an error when an error occurs loading comments', () => {
|
||||
let emitSpy = spyOn(component.error, 'emit');
|
||||
const emitSpy = spyOn(component.error, 'emit');
|
||||
getProcessCommentsSpy.and.returnValue(throwError({}));
|
||||
|
||||
let change = new SimpleChange(null, '123', true);
|
||||
const change = new SimpleChange(null, '123', true);
|
||||
component.ngOnChanges({'taskId': change});
|
||||
|
||||
expect(emitSpy).toHaveBeenCalled();
|
||||
@@ -106,7 +106,7 @@ describe('CommentsComponent', () => {
|
||||
});
|
||||
|
||||
it('should display comments when the task has comments', async(() => {
|
||||
let change = new SimpleChange(null, '123', true);
|
||||
const change = new SimpleChange(null, '123', true);
|
||||
component.ngOnChanges({'taskId': change});
|
||||
|
||||
fixture.whenStable().then(() => {
|
||||
@@ -117,11 +117,11 @@ describe('CommentsComponent', () => {
|
||||
}));
|
||||
|
||||
it('should display comments count when the task has comments', async(() => {
|
||||
let change = new SimpleChange(null, '123', true);
|
||||
const change = new SimpleChange(null, '123', true);
|
||||
component.ngOnChanges({'taskId': change});
|
||||
fixture.whenStable().then(() => {
|
||||
fixture.detectChanges();
|
||||
let element = fixture.nativeElement.querySelector('#comment-header');
|
||||
const element = fixture.nativeElement.querySelector('#comment-header');
|
||||
expect(element.innerText).toBe('COMMENTS.HEADER');
|
||||
});
|
||||
}));
|
||||
@@ -136,7 +136,7 @@ describe('CommentsComponent', () => {
|
||||
}));
|
||||
|
||||
it('should display comments input by default', async(() => {
|
||||
let change = new SimpleChange(null, '123', true);
|
||||
const change = new SimpleChange(null, '123', true);
|
||||
component.ngOnChanges({'taskId': change});
|
||||
fixture.whenStable().then(() => {
|
||||
fixture.detectChanges();
|
||||
@@ -155,8 +155,8 @@ describe('CommentsComponent', () => {
|
||||
|
||||
describe('change detection taskId', () => {
|
||||
|
||||
let change = new SimpleChange('123', '456', true);
|
||||
let nullChange = new SimpleChange('123', null, true);
|
||||
const change = new SimpleChange('123', '456', true);
|
||||
const nullChange = new SimpleChange('123', null, true);
|
||||
|
||||
beforeEach(async(() => {
|
||||
component.taskId = '123';
|
||||
@@ -184,8 +184,8 @@ describe('CommentsComponent', () => {
|
||||
|
||||
describe('change detection node', () => {
|
||||
|
||||
let change = new SimpleChange('123', '456', true);
|
||||
let nullChange = new SimpleChange('123', null, true);
|
||||
const change = new SimpleChange('123', '456', true);
|
||||
const nullChange = new SimpleChange('123', null, true);
|
||||
|
||||
beforeEach(async(() => {
|
||||
component.nodeId = '123';
|
||||
@@ -220,7 +220,7 @@ describe('CommentsComponent', () => {
|
||||
}));
|
||||
|
||||
it('should sanitize comment when user input contains html elements', async(() => {
|
||||
let element = fixture.nativeElement.querySelector('.adf-comments-input-add');
|
||||
const element = fixture.nativeElement.querySelector('.adf-comments-input-add');
|
||||
component.message = '<div class="text-class"><button onclick=""><h1>action</h1></button></div>';
|
||||
element.dispatchEvent(new Event('click'));
|
||||
fixture.detectChanges();
|
||||
@@ -231,7 +231,7 @@ describe('CommentsComponent', () => {
|
||||
}));
|
||||
|
||||
it('should normalize comment when user input contains spaces sequence', async(() => {
|
||||
let element = fixture.nativeElement.querySelector('.adf-comments-input-add');
|
||||
const element = fixture.nativeElement.querySelector('.adf-comments-input-add');
|
||||
component.message = 'test comment';
|
||||
element.dispatchEvent(new Event('click'));
|
||||
fixture.detectChanges();
|
||||
@@ -242,7 +242,7 @@ describe('CommentsComponent', () => {
|
||||
}));
|
||||
|
||||
it('should add break lines to comment when user input contains new line characters', async(() => {
|
||||
let element = fixture.nativeElement.querySelector('.adf-comments-input-add');
|
||||
const element = fixture.nativeElement.querySelector('.adf-comments-input-add');
|
||||
component.message = 'these\nare\nparagraphs\n';
|
||||
element.dispatchEvent(new Event('click'));
|
||||
fixture.detectChanges();
|
||||
@@ -253,21 +253,21 @@ describe('CommentsComponent', () => {
|
||||
}));
|
||||
|
||||
it('should call service to add a comment when add button is pressed', async(() => {
|
||||
let element = fixture.nativeElement.querySelector('.adf-comments-input-add');
|
||||
const element = fixture.nativeElement.querySelector('.adf-comments-input-add');
|
||||
component.message = 'Test Comment';
|
||||
element.dispatchEvent(new Event('click'));
|
||||
fixture.detectChanges();
|
||||
fixture.whenStable().then(() => {
|
||||
fixture.detectChanges();
|
||||
expect(addProcessCommentSpy).toHaveBeenCalled();
|
||||
let elements = fixture.nativeElement.querySelectorAll('#comment-message');
|
||||
const elements = fixture.nativeElement.querySelectorAll('#comment-message');
|
||||
expect(elements.length).toBe(1);
|
||||
expect(elements[0].innerText).toBe('Test Comment');
|
||||
});
|
||||
}));
|
||||
|
||||
it('should not call service to add a comment when comment is empty', async(() => {
|
||||
let element = fixture.nativeElement.querySelector('.adf-comments-input-add');
|
||||
const element = fixture.nativeElement.querySelector('.adf-comments-input-add');
|
||||
component.message = '';
|
||||
element.dispatchEvent(new Event('click'));
|
||||
fixture.detectChanges();
|
||||
@@ -278,7 +278,7 @@ describe('CommentsComponent', () => {
|
||||
}));
|
||||
|
||||
it('should clear comment when escape key is pressed', async(() => {
|
||||
let event = new KeyboardEvent('keyup', {'key': 'Escape'});
|
||||
const event = new KeyboardEvent('keyup', {'key': 'Escape'});
|
||||
let element = fixture.nativeElement.querySelector('#comment-input');
|
||||
element.dispatchEvent(event);
|
||||
fixture.detectChanges();
|
||||
@@ -290,7 +290,7 @@ describe('CommentsComponent', () => {
|
||||
}));
|
||||
|
||||
it('should emit an error when an error occurs adding the comment', () => {
|
||||
let emitSpy = spyOn(component.error, 'emit');
|
||||
const emitSpy = spyOn(component.error, 'emit');
|
||||
addProcessCommentSpy.and.returnValue(throwError({}));
|
||||
component.message = 'Test comment';
|
||||
component.add();
|
||||
@@ -308,21 +308,21 @@ describe('CommentsComponent', () => {
|
||||
}));
|
||||
|
||||
it('should call service to add a comment when add button is pressed', async(() => {
|
||||
let element = fixture.nativeElement.querySelector('.adf-comments-input-add');
|
||||
const element = fixture.nativeElement.querySelector('.adf-comments-input-add');
|
||||
component.message = 'Test Comment';
|
||||
element.dispatchEvent(new Event('click'));
|
||||
fixture.detectChanges();
|
||||
fixture.whenStable().then(() => {
|
||||
fixture.detectChanges();
|
||||
expect(addContentCommentSpy).toHaveBeenCalled();
|
||||
let elements = fixture.nativeElement.querySelectorAll('#comment-message');
|
||||
const elements = fixture.nativeElement.querySelectorAll('#comment-message');
|
||||
expect(elements.length).toBe(1);
|
||||
expect(elements[0].innerText).toBe('Test Comment');
|
||||
});
|
||||
}));
|
||||
|
||||
it('should sanitize comment when user input contains html elements', async(() => {
|
||||
let element = fixture.nativeElement.querySelector('.adf-comments-input-add');
|
||||
const element = fixture.nativeElement.querySelector('.adf-comments-input-add');
|
||||
component.message = '<div class="text-class"><button onclick=""><h1>action</h1></button></div>';
|
||||
element.dispatchEvent(new Event('click'));
|
||||
fixture.detectChanges();
|
||||
@@ -333,7 +333,7 @@ describe('CommentsComponent', () => {
|
||||
}));
|
||||
|
||||
it('should normalize comment when user input contains spaces sequence', async(() => {
|
||||
let element = fixture.nativeElement.querySelector('.adf-comments-input-add');
|
||||
const element = fixture.nativeElement.querySelector('.adf-comments-input-add');
|
||||
component.message = 'test comment';
|
||||
element.dispatchEvent(new Event('click'));
|
||||
fixture.detectChanges();
|
||||
@@ -344,7 +344,7 @@ describe('CommentsComponent', () => {
|
||||
}));
|
||||
|
||||
it('should add break lines to comment when user input contains new line characters', async(() => {
|
||||
let element = fixture.nativeElement.querySelector('.adf-comments-input-add');
|
||||
const element = fixture.nativeElement.querySelector('.adf-comments-input-add');
|
||||
component.message = 'these\nare\nparagraphs\n';
|
||||
element.dispatchEvent(new Event('click'));
|
||||
fixture.detectChanges();
|
||||
@@ -355,7 +355,7 @@ describe('CommentsComponent', () => {
|
||||
}));
|
||||
|
||||
it('should not call service to add a comment when comment is empty', async(() => {
|
||||
let element = fixture.nativeElement.querySelector('.adf-comments-input-add');
|
||||
const element = fixture.nativeElement.querySelector('.adf-comments-input-add');
|
||||
component.message = '';
|
||||
element.dispatchEvent(new Event('click'));
|
||||
fixture.detectChanges();
|
||||
@@ -366,7 +366,7 @@ describe('CommentsComponent', () => {
|
||||
}));
|
||||
|
||||
it('should clear comment when escape key is pressed', async(() => {
|
||||
let event = new KeyboardEvent('keyup', {'key': 'Escape'});
|
||||
const event = new KeyboardEvent('keyup', {'key': 'Escape'});
|
||||
let element = fixture.nativeElement.querySelector('#comment-input');
|
||||
element.dispatchEvent(event);
|
||||
fixture.detectChanges();
|
||||
@@ -378,7 +378,7 @@ describe('CommentsComponent', () => {
|
||||
}));
|
||||
|
||||
it('should emit an error when an error occurs adding the comment', () => {
|
||||
let emitSpy = spyOn(component.error, 'emit');
|
||||
const emitSpy = spyOn(component.error, 'emit');
|
||||
addContentCommentSpy.and.returnValue(throwError({}));
|
||||
component.message = 'Test comment';
|
||||
component.add();
|
||||
|
@@ -83,8 +83,8 @@ export class CommentsComponent implements OnChanges {
|
||||
(comments: CommentModel[]) => {
|
||||
if (comments && comments instanceof Array) {
|
||||
comments = comments.sort((comment1: CommentModel, comment2: CommentModel) => {
|
||||
let date1 = new Date(comment1.created);
|
||||
let date2 = new Date(comment2.created);
|
||||
const date1 = new Date(comment1.created);
|
||||
const date2 = new Date(comment2.created);
|
||||
return date1 > date2 ? -1 : date1 < date2 ? 1 : 0;
|
||||
});
|
||||
comments.forEach((currentComment) => {
|
||||
|
Reference in New Issue
Block a user