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

@@ -21,19 +21,8 @@ import { TaskDetailsModel } from '../models/task-details.model';
import { ChecklistComponent } from './checklist.component';
import { setupTestBed } from '@alfresco/adf-core';
import { ProcessTestingModule } from '../../testing/process.testing.module';
declare let jasmine: any;
const fakeTaskDetail = new TaskDetailsModel({
id: 'fake-check-id',
name: 'fake-check-name'
});
const fakeTaskDetailCompleted = new TaskDetailsModel({
id: 'fake-completed-id',
name: 'fake-completed-name',
endDate: '2018-05-23T11:25:14.552+0000'
});
import { TaskListService } from './../services/tasklist.service';
import { Observable } from 'rxjs/Observable';
describe('ChecklistComponent', () => {
@@ -41,12 +30,16 @@ describe('ChecklistComponent', () => {
let fixture: ComponentFixture<ChecklistComponent>;
let element: HTMLElement;
let showChecklistDialog;
let service: TaskListService;
setupTestBed({
imports: [ProcessTestingModule]
});
beforeEach(async(() => {
service = TestBed.get(TaskListService);
spyOn(service, 'getTaskChecklist').and.returnValue(Observable.of([{ id: 'fake-check-changed-id', name: 'fake-check-changed-name' }] ));
fixture = TestBed.createComponent(ChecklistComponent);
checklistComponent = fixture.componentInstance;
element = fixture.nativeElement;
@@ -68,7 +61,10 @@ describe('ChecklistComponent', () => {
beforeEach(() => {
checklistComponent.taskId = 'fake-task-id';
checklistComponent.checklist.push(fakeTaskDetail);
checklistComponent.checklist.push(new TaskDetailsModel({
id: 'fake-check-id',
name: 'fake-check-name'
}));
checklistComponent.readOnly = true;
fixture.detectChanges();
@@ -89,7 +85,10 @@ describe('ChecklistComponent', () => {
beforeEach(() => {
checklistComponent.taskId = 'fake-task-id';
checklistComponent.readOnly = false;
checklistComponent.checklist.push(fakeTaskDetail);
checklistComponent.checklist.push(new TaskDetailsModel({
id: 'fake-check-id',
name: 'fake-check-name'
}));
fixture.detectChanges();
showChecklistDialog = <HTMLElement> element.querySelector('#add-checklist');
@@ -133,12 +132,7 @@ describe('ChecklistComponent', () => {
showChecklistDialog = <HTMLElement> element.querySelector('#add-checklist');
});
beforeEach(() => {
jasmine.Ajax.install();
});
afterEach(() => {
jasmine.Ajax.uninstall();
const overlayContainers = <any> window.document.querySelectorAll('.cdk-overlay-container');
overlayContainers.forEach((overlayContainer) => {
overlayContainer.innerHTML = '';
@@ -146,15 +140,25 @@ describe('ChecklistComponent', () => {
});
it('should show task checklist', () => {
checklistComponent.checklist.push(fakeTaskDetail);
checklistComponent.checklist.push(new TaskDetailsModel({
id: 'fake-check-id',
name: 'fake-check-name'
}));
fixture.detectChanges();
expect(element.querySelector('#check-fake-check-id')).not.toBeNull();
expect(element.querySelector('#check-fake-check-id').textContent).toContain('fake-check-name');
});
it('should not show delete icon when checklist task is completed', () => {
checklistComponent.checklist.push(fakeTaskDetail);
checklistComponent.checklist.push(fakeTaskDetailCompleted);
checklistComponent.checklist.push(new TaskDetailsModel({
id: 'fake-check-id',
name: 'fake-check-name'
}));
checklistComponent.checklist.push(new TaskDetailsModel({
id: 'fake-completed-id',
name: 'fake-completed-name',
endDate: '2018-05-23T11:25:14.552+0000'
}));
fixture.detectChanges();
expect(element.querySelector('#remove-fake-check-id')).not.toBeNull();
expect(element.querySelector('#check-fake-completed-id')).not.toBeNull();
@@ -163,14 +167,14 @@ describe('ChecklistComponent', () => {
});
it('should add checklist', async(() => {
spyOn(service, 'addTask').and.returnValue(Observable.of({
id: 'fake-check-added-id', name: 'fake-check-added-name'
}));
showChecklistDialog.click();
let addButtonDialog = <HTMLElement> window.document.querySelector('#add-check');
addButtonDialog.click();
jasmine.Ajax.requests.mostRecent().respondWith({
status: 200,
contentType: 'json',
responseText: { id: 'fake-check-added-id', name: 'fake-check-added-name' }
});
fixture.whenStable().then(() => {
fixture.detectChanges();
expect(element.querySelector('#check-fake-check-added-id')).not.toBeNull();
@@ -179,17 +183,19 @@ describe('ChecklistComponent', () => {
}));
it('should remove a checklist element', async(() => {
spyOn(service, 'deleteTask').and.returnValue(Observable.of(''));
checklistComponent.taskId = 'new-fake-task-id';
checklistComponent.checklist.push(fakeTaskDetail);
checklistComponent.checklist.push(new TaskDetailsModel({
id: 'fake-check-id',
name: 'fake-check-name'
}));
fixture.detectChanges();
let checklistElementRemove = <HTMLElement> element.querySelector('#remove-fake-check-id');
expect(checklistElementRemove).toBeDefined();
expect(checklistElementRemove).not.toBeNull();
checklistElementRemove.click();
jasmine.Ajax.requests.mostRecent().respondWith({
status: 200,
contentType: 'json'
});
fixture.whenStable().then(() => {
fixture.detectChanges();
expect(element.querySelector('#fake-check-id')).toBeNull();
@@ -197,36 +203,38 @@ describe('ChecklistComponent', () => {
}));
it('should send an event when the checklist is deleted', (done) => {
spyOn(service, 'deleteTask').and.returnValue(Observable.of(''));
let disposableDelete = checklistComponent.checklistTaskDeleted.subscribe(() => {
expect(element.querySelector('#fake-check-id')).toBeNull();
disposableDelete.unsubscribe();
done();
});
checklistComponent.taskId = 'new-fake-task-id';
checklistComponent.checklist.push(fakeTaskDetail);
checklistComponent.checklist.push(new TaskDetailsModel({
id: 'fake-check-id',
name: 'fake-check-name'
}));
fixture.detectChanges();
let checklistElementRemove = <HTMLElement> element.querySelector('#remove-fake-check-id');
expect(checklistElementRemove).toBeDefined();
expect(checklistElementRemove).not.toBeNull();
checklistElementRemove.click();
jasmine.Ajax.requests.mostRecent().respondWith({
status: 200,
contentType: 'json'
});
checklistComponent.checklistTaskDeleted.subscribe(() => {
expect(element.querySelector('#fake-check-id')).toBeNull();
done();
});
});
it('should show load task checklist on change', async(() => {
checklistComponent.taskId = 'new-fake-task-id';
checklistComponent.checklist.push(fakeTaskDetail);
checklistComponent.checklist.push(new TaskDetailsModel({
id: 'fake-check-id',
name: 'fake-check-name'
}));
fixture.detectChanges();
let change = new SimpleChange(null, 'new-fake-task-id', true);
checklistComponent.ngOnChanges({
taskId: change
});
jasmine.Ajax.requests.mostRecent().respondWith({
status: 200,
contentType: 'json',
responseText: { data: [{ id: 'fake-check-changed-id', name: 'fake-check-changed-name' }] }
});
fixture.whenStable().then(() => {
fixture.detectChanges();
expect(element.querySelector('#check-fake-check-changed-id')).not.toBeNull();
@@ -236,7 +244,10 @@ describe('ChecklistComponent', () => {
it('should show empty checklist when task id is null', async(() => {
checklistComponent.taskId = 'new-fake-task-id';
checklistComponent.checklist.push(fakeTaskDetail);
checklistComponent.checklist.push(new TaskDetailsModel({
id: 'fake-check-id',
name: 'fake-check-name'
}));
fixture.detectChanges();
checklistComponent.taskId = null;
let change = new SimpleChange(null, 'new-fake-task-id', true);
@@ -251,22 +262,20 @@ describe('ChecklistComponent', () => {
}));
it('should emit checklist task created event when the checklist is successfully added', (done) => {
checklistComponent.checklistTaskCreated.subscribe((taskAdded: TaskDetailsModel) => {
spyOn(service, 'addTask').and.returnValue(Observable.of({ id: 'fake-check-added-id', name: 'fake-check-added-name' }));
let disposableCreated = checklistComponent.checklistTaskCreated.subscribe((taskAdded: TaskDetailsModel) => {
fixture.detectChanges();
expect(taskAdded.id).toEqual('fake-check-added-id');
expect(taskAdded.name).toEqual('fake-check-added-name');
expect(element.querySelector('#check-fake-check-added-id')).not.toBeNull();
expect(element.querySelector('#check-fake-check-added-id').textContent).toContain('fake-check-added-name');
disposableCreated.unsubscribe();
done();
});
showChecklistDialog.click();
let addButtonDialog = <HTMLElement> window.document.querySelector('#add-check');
addButtonDialog.click();
jasmine.Ajax.requests.mostRecent().respondWith({
status: 200,
contentType: 'json',
responseText: { id: 'fake-check-added-id', name: 'fake-check-added-name' }
});
});
});

View File

@@ -15,20 +15,17 @@
* limitations under the License.
*/
import { Component, EventEmitter, Input, OnChanges, OnInit, Output, SimpleChanges, ViewChild } from '@angular/core';
import { Component, EventEmitter, Input, OnChanges, Output, SimpleChanges, ViewChild } from '@angular/core';
import { MatDialog } from '@angular/material';
import { Observable } from 'rxjs/Observable';
import { Observer } from 'rxjs/Observer';
import { TaskDetailsModel } from '../models/task-details.model';
import { TaskListService } from './../services/tasklist.service';
@Component({
selector: 'adf-checklist',
templateUrl: './checklist.component.html',
styleUrls: ['./checklist.component.scss'],
providers: [TaskListService]
styleUrls: ['./checklist.component.scss']
})
export class ChecklistComponent implements OnInit, OnChanges {
export class ChecklistComponent implements OnChanges {
/** (required) The id of the parent task to which subtasks are
* attached.
@@ -50,7 +47,7 @@ export class ChecklistComponent implements OnInit, OnChanges {
@Output()
checklistTaskCreated: EventEmitter<TaskDetailsModel> = new EventEmitter<TaskDetailsModel>();
/** Emitted when a checklist task is deleted. */
/** Emitted when a checklitst task is deleted. */
@Output()
checklistTaskDeleted: EventEmitter<string> = new EventEmitter<string>();
@@ -65,25 +62,13 @@ export class ChecklistComponent implements OnInit, OnChanges {
checklist: TaskDetailsModel [] = [];
private taskObserver: Observer<TaskDetailsModel>;
task$: Observable<TaskDetailsModel>;
/**
* Constructor
* @param auth
* @param translate
*/
constructor(
private activitiTaskList: TaskListService,
private dialog: MatDialog
) {
this.task$ = new Observable<TaskDetailsModel>(observer => this.taskObserver = observer).share();
}
ngOnInit() {
this.task$.subscribe((task: TaskDetailsModel) => {
this.checklist.push(task);
});
constructor(private activitiTaskList: TaskListService,
private dialog: MatDialog) {
}
ngOnChanges(changes: SimpleChanges) {
@@ -98,9 +83,9 @@ export class ChecklistComponent implements OnInit, OnChanges {
this.checklist = [];
if (this.taskId) {
this.activitiTaskList.getTaskChecklist(this.taskId).subscribe(
(res: TaskDetailsModel[]) => {
res.forEach((task) => {
this.taskObserver.next(task);
(taskDetailsModel: TaskDetailsModel[]) => {
taskDetailsModel.forEach((task) => {
this.checklist.push(task);
});
},
(error) => {
@@ -148,9 +133,6 @@ export class ChecklistComponent implements OnInit, OnChanges {
public cancel() {
this.dialog.closeAll();
// if (this.addNewDialog) {
// this.addNewDialog.nativeElement.close();
// }
this.taskName = '';
}
}

View File

@@ -21,7 +21,6 @@ import { Observable } from 'rxjs/Observable';
import { startTaskMock } from '../../mock';
import { StartTaskModel } from '../models/start-task.model';
import { TaskListService } from '../services/tasklist.service';
import { } from './../assets/start-task.mock';
import { StartTaskComponent } from './start-task.component';
import { ProcessTestingModule } from '../../testing/process.testing.module';
@@ -49,23 +48,6 @@ describe('StartTaskComponent', () => {
imports: [ProcessTestingModule]
});
// beforeEach(async(() => {
// TestBed.configureTestingModule({
// declarations: [
// StartTaskComponent,
// PeopleSearchFieldComponent,
// PeopleListComponent,
// PeopleSelectorComponent
// ],
// providers: [
// TaskListService,
// { provide: TranslationService, useClass: TranslationMock }
// ]
// }).compileComponents().then(() => {
// });
// }));
beforeEach(async(() => {
fixture = TestBed.createComponent(StartTaskComponent);
component = fixture.componentInstance;

View File

@@ -267,7 +267,7 @@ describe('TaskDetailsComponent', () => {
});
it('should show placeholder message if there is no next task', () => {
getTasksSpy.and.returnValue(Observable.of(noDataMock));
getTasksSpy.and.returnValue(Observable.of([]));
component.onComplete();
fixture.detectChanges();
expect(fixture.nativeElement.innerText).toBe('ADF_TASK_LIST.DETAILS.MESSAGES.NONE');

View File

@@ -659,7 +659,6 @@ class EmptyTemplateComponent {
}
describe('Custom EmptyTemplateComponent', () => {
let component: EmptyTemplateComponent;
let fixture: ComponentFixture<EmptyTemplateComponent>;
setupTestBed({
@@ -671,7 +670,6 @@ describe('Custom EmptyTemplateComponent', () => {
beforeEach(() => {
fixture = TestBed.createComponent(EmptyTemplateComponent);
fixture.detectChanges();
component = fixture.componentInstance;
});
it('should render the custom template', async(() => {