fix random test failing part 2 (#3395)

* fix random failing test core search/comment/auth/user

* fix node delete directive

* fix lint issues

* node restore fix

* fix comment test

* remove fdescribe

* fix tests and tslint

* fix upload test

* unsubscribe success event task test

* copy comment object during test

* use the data pipe performance improvement and standard usage

* uncomment random test

* fix comment date random failing test

* disposable unsubscribe

* fix start process

* remove fdescribe

* change start process test and remove commented code

* fix error event check double click

* clone object form test

* refactor date time test

* fix service mock

* fix test dropdown and context

* git hook lint

* fix language test

* unsubscribe documentlist event test

* fix disposable error

* fix console log service error document list

* unusbscribe search test

* clear input field

* remove wrong test
This commit is contained in:
Eugenio Romano
2018-05-29 11:18:17 +02:00
committed by Denys Vuika
parent 22006395c7
commit eb0f91c5db
43 changed files with 4475 additions and 4332 deletions

View File

@@ -25,7 +25,7 @@
{{comment.message}}
</div>
<div matLine id="comment-time" class="adf-comment-message-time">
{{transformDate(comment.created)}}
{{ comment.created | adfTimeAgo: currentLocale }}
</div>
</div>
</mat-list-item>

View File

@@ -31,25 +31,25 @@ const testUser: UserProcessModel = new UserProcessModel({
lastName: 'User',
email: 'tu@domain.com'
});
const testDate = new Date();
const processCommentOne: CommentModel = new CommentModel({
id: 1,
message: 'Test Comment',
created: testDate.toDateString(),
created: new Date(),
createdBy: testUser
});
const processCommentTwo: CommentModel = new CommentModel({
id: 2,
message: '2nd Test Comment',
created: new Date().toDateString(),
created: new Date(),
createdBy: testUser
});
const contentCommentUserPictureDefined: CommentModel = new CommentModel({
id: 2,
message: '2nd Test Comment',
created: new Date().toDateString(),
created: new Date(),
createdBy: {
enabled: true,
firstName: 'some',
@@ -65,7 +65,7 @@ const contentCommentUserPictureDefined: CommentModel = new CommentModel({
const processCommentUserPictureDefined: CommentModel = new CommentModel({
id: 2,
message: '2nd Test Comment',
created: new Date().toDateString(),
created: new Date(),
createdBy: {
id: '1',
firstName: 'Test',
@@ -78,7 +78,7 @@ const processCommentUserPictureDefined: CommentModel = new CommentModel({
const contentCommentUserNoPictureDefined: CommentModel = new CommentModel({
id: 2,
message: '2nd Test Comment',
created: new Date().toDateString(),
created: new Date(),
createdBy: {
enabled: true,
firstName: 'some',
@@ -93,7 +93,7 @@ const contentCommentUserNoPictureDefined: CommentModel = new CommentModel({
const processCommentUserNoPictureDefined: CommentModel = new CommentModel({
id: 2,
message: '2nd Test Comment',
created: new Date().toDateString(),
created: new Date(),
createdBy: {
id: '1',
firstName: 'Test',
@@ -133,13 +133,12 @@ describe('CommentListComponent', () => {
});
it('should emit row click event', async(() => {
commentList.comments = [processCommentOne];
commentList.comments = [Object.assign({}, processCommentOne)];
commentList.clickRow.subscribe(selectedComment => {
expect(selectedComment.id).toEqual(1);
expect(selectedComment.message).toEqual('Test Comment');
expect(selectedComment.createdBy).toEqual(testUser);
expect(selectedComment.created).toEqual(testDate.toDateString());
expect(selectedComment.isSelected).toBeTruthy();
});
@@ -152,8 +151,10 @@ describe('CommentListComponent', () => {
it('should deselect the previous selected comment when a new one is clicked', async(() => {
processCommentOne.isSelected = true;
commentList.selectedComment = processCommentOne;
commentList.comments = [processCommentOne, processCommentTwo];
let commentOne = Object.assign({}, processCommentOne);
let commentTwo = Object.assign({}, processCommentTwo);
commentList.selectedComment = commentOne;
commentList.comments = [commentOne, commentTwo];
commentList.clickRow.subscribe(selectedComment => {
fixture.detectChanges();
@@ -178,7 +179,7 @@ describe('CommentListComponent', () => {
}));
it('should show comment message when input is given', async(() => {
commentList.comments = [processCommentOne];
commentList.comments = [Object.assign({}, processCommentOne)];
fixture.detectChanges();
fixture.whenStable().then(() => {
@@ -190,7 +191,7 @@ describe('CommentListComponent', () => {
}));
it('should show comment user when input is given', async(() => {
commentList.comments = [processCommentOne];
commentList.comments = [Object.assign({}, processCommentOne)];
fixture.detectChanges();
fixture.whenStable().then(() => {
@@ -201,42 +202,35 @@ describe('CommentListComponent', () => {
});
}));
it('should show comment date time when input is given', async(() => {
commentList.comments = [processCommentOne];
fixture.detectChanges();
it('comment date time should start with few seconds ago when comment date is few seconds ago', async(() => {
let commenFewSecond = Object.assign({}, processCommentOne);
commenFewSecond.created = new Date();
fixture.whenStable().then(() => {
let elements = fixture.nativeElement.querySelectorAll('#comment-time');
expect(elements.length).toBe(1);
expect(elements[0].innerText).toBe(commentList.transformDate(testDate.toDateString()));
expect(fixture.nativeElement.querySelector('#comment-time:empty')).toBeNull();
});
}));
it('comment date time should start with Today when comment date is today', async(() => {
commentList.comments = [processCommentOne];
commentList.comments = [commenFewSecond];
fixture.detectChanges();
fixture.whenStable().then(() => {
element = fixture.nativeElement.querySelector('#comment-time');
expect(element.innerText).toContain('Today');
expect(element.innerText).toContain('a few seconds ago');
});
}));
it('comment date time should start with Yesterday when comment date is yesterday', async(() => {
processCommentOne.created = new Date((Date.now() - 24 * 3600 * 1000));
commentList.comments = [processCommentOne];
let commentOld = Object.assign({}, processCommentOne);
commentOld.created = new Date((Date.now() - 24 * 3600 * 1000));
commentList.comments = [commentOld];
fixture.detectChanges();
fixture.whenStable().then(() => {
element = fixture.nativeElement.querySelector('#comment-time');
expect(element.innerText).toContain('Yesterday');
expect(element.innerText).toContain('a day ago');
});
}));
it('comment date time should not start with Today/Yesterday when comment date is before yesterday', async(() => {
processCommentOne.created = new Date((Date.now() - 24 * 3600 * 1000 * 2));
commentList.comments = [processCommentOne];
let commentOld = Object.assign({}, processCommentOne);
commentOld.created = new Date((Date.now() - 24 * 3600 * 1000 * 2));
commentList.comments = [commentOld];
fixture.detectChanges();
fixture.whenStable().then(() => {
@@ -247,7 +241,7 @@ describe('CommentListComponent', () => {
}));
it('should show user icon when input is given', async(() => {
commentList.comments = [processCommentOne];
commentList.comments = [Object.assign({}, processCommentOne)];
fixture.detectChanges();
fixture.whenStable().then(() => {

View File

@@ -19,7 +19,7 @@ import { Component, EventEmitter, Input, Output, ViewEncapsulation } from '@angu
import { CommentModel } from '../models/comment.model';
import { EcmUserService } from '../userinfo/services/ecm-user.service';
import { PeopleProcessService } from '../services/people-process.service';
import { DatePipe } from '@angular/common';
import { UserPreferencesService, UserPreferenceValues } from '../services/user-preferences.service';
@Component({
selector: 'adf-comment-list',
@@ -40,8 +40,14 @@ export class CommentListComponent {
selectedComment: CommentModel;
constructor(private datePipe: DatePipe, public peopleProcessService: PeopleProcessService,
public ecmUserService: EcmUserService) {
currentLocale;
constructor(public peopleProcessService: PeopleProcessService,
public ecmUserService: EcmUserService,
public userPreferenceService: UserPreferencesService) {
userPreferenceService.select(UserPreferenceValues.Locale).subscribe((locale) => {
this.currentLocale = locale;
});
}
selectComment(comment: CommentModel): void {
@@ -78,23 +84,6 @@ export class CommentListComponent {
}
}
transformDate(aDate: string): string {
let formattedDate: string;
let givenDate = Number.parseInt(this.datePipe.transform(aDate, 'yMMdd'));
let today = Number.parseInt(this.datePipe.transform(Date.now(), 'yMMdd'));
if (givenDate === today) {
formattedDate = 'Today, ' + this.datePipe.transform(aDate, 'hh:mm a');
} else {
let yesterday = Number.parseInt(this.datePipe.transform(Date.now() - 24 * 3600 * 1000, 'yMMdd'));
if (givenDate === yesterday) {
formattedDate = 'Yesterday, ' + this.datePipe.transform(aDate, 'hh:mm a');
} else {
formattedDate = this.datePipe.transform(aDate, 'MMM dd y, hh:mm a');
}
}
return formattedDate;
}
private isAContentUsers(user: any): boolean {
return user.avatarId;
}

View File

@@ -22,12 +22,14 @@ import { MaterialModule } from '../material.module';
import { FormsModule, ReactiveFormsModule } from '@angular/forms';
import { DataColumnModule } from '../data-column/data-column.module';
import { DataTableModule } from '../datatable/datatable.module';
import { PipeModule } from '../pipes/pipe.module';
import { CommentListComponent } from './comment-list.component';
import { CommentsComponent } from './comments.component';
@NgModule({
imports: [
PipeModule,
DataColumnModule,
DataTableModule,
FormsModule,