mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-07-24 17:32:15 +00:00
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:
committed by
Denys Vuika
parent
22006395c7
commit
eb0f91c5db
@@ -16,28 +16,25 @@
|
||||
*/
|
||||
|
||||
import { Component, DebugElement } from '@angular/core';
|
||||
import { async, ComponentFixture, fakeAsync, TestBed, tick } from '@angular/core/testing';
|
||||
import { ComponentFixture, TestBed } from '@angular/core/testing';
|
||||
import { By } from '@angular/platform-browser';
|
||||
import { Router } from '@angular/router';
|
||||
import { RouterTestingModule } from '@angular/router/testing';
|
||||
import { Observable } from 'rxjs/Observable';
|
||||
import { TranslationService } from '../services';
|
||||
import { AlfrescoApiService } from '../services/alfresco-api.service';
|
||||
import { NotificationService } from '../services/notification.service';
|
||||
import { NodeRestoreDirective } from './node-restore.directive';
|
||||
import { setupTestBed } from '../testing/setupTestBed';
|
||||
import { CoreModule } from '../core.module';
|
||||
import { AlfrescoApiServiceMock } from '../mock/alfresco-api.service.mock';
|
||||
import { NoopAnimationsModule } from '@angular/platform-browser/animations';
|
||||
|
||||
@Component({
|
||||
template: `
|
||||
<div [adf-restore]="selection"
|
||||
(restore)="done()">
|
||||
(restore)="doneSpy()">
|
||||
</div>`
|
||||
})
|
||||
class TestComponent {
|
||||
selection = [];
|
||||
|
||||
done = jasmine.createSpy('done');
|
||||
doneSpy = jasmine.createSpy('doneSpy');
|
||||
}
|
||||
|
||||
describe('NodeRestoreDirective', () => {
|
||||
@@ -45,17 +42,15 @@ describe('NodeRestoreDirective', () => {
|
||||
let element: DebugElement;
|
||||
let component: TestComponent;
|
||||
let alfrescoService: AlfrescoApiService;
|
||||
let translation: TranslationService;
|
||||
let notification: NotificationService;
|
||||
let router: Router;
|
||||
let nodesService;
|
||||
let coreApi;
|
||||
let directiveInstance;
|
||||
let restoreNodeSpy: any;
|
||||
|
||||
setupTestBed({
|
||||
imports: [
|
||||
CoreModule.forRoot(),
|
||||
RouterTestingModule
|
||||
NoopAnimationsModule
|
||||
],
|
||||
declarations: [
|
||||
TestComponent
|
||||
@@ -65,7 +60,7 @@ describe('NodeRestoreDirective', () => {
|
||||
]
|
||||
});
|
||||
|
||||
beforeEach(async(() => {
|
||||
beforeEach(() => {
|
||||
fixture = TestBed.createComponent(TestComponent);
|
||||
component = fixture.componentInstance;
|
||||
element = fixture.debugElement.query(By.directive(NodeRestoreDirective));
|
||||
@@ -74,18 +69,15 @@ describe('NodeRestoreDirective', () => {
|
||||
alfrescoService = TestBed.get(AlfrescoApiService);
|
||||
nodesService = alfrescoService.getInstance().nodes;
|
||||
coreApi = alfrescoService.getInstance().core;
|
||||
translation = TestBed.get(TranslationService);
|
||||
notification = TestBed.get(NotificationService);
|
||||
router = TestBed.get(Router);
|
||||
}));
|
||||
|
||||
beforeEach(() => {
|
||||
spyOn(translation, 'instant').and.returnValue('message');
|
||||
restoreNodeSpy = spyOn(nodesService, 'restoreNode').and.returnValue(Promise.resolve());
|
||||
spyOn(coreApi.nodesApi, 'getDeletedNodes').and.returnValue(Promise.resolve({
|
||||
list: { entries: [] }
|
||||
}));
|
||||
|
||||
});
|
||||
|
||||
it('should not restore when selection is empty', () => {
|
||||
spyOn(nodesService, 'restoreNode');
|
||||
|
||||
component.selection = [];
|
||||
|
||||
fixture.detectChanges();
|
||||
@@ -94,54 +86,47 @@ describe('NodeRestoreDirective', () => {
|
||||
expect(nodesService.restoreNode).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('should not restore nodes when selection has nodes without path', () => {
|
||||
spyOn(nodesService, 'restoreNode');
|
||||
|
||||
component.selection = [ { entry: { id: '1' } } ];
|
||||
it('should not restore nodes when selection has nodes without path', (done) => {
|
||||
component.selection = [{ entry: { id: '1' } }];
|
||||
|
||||
fixture.detectChanges();
|
||||
element.triggerEventHandler('click', null);
|
||||
fixture.whenStable().then(() => {
|
||||
element.triggerEventHandler('click', null);
|
||||
|
||||
expect(nodesService.restoreNode).not.toHaveBeenCalled();
|
||||
expect(nodesService.restoreNode).not.toHaveBeenCalled();
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should call restore when selection has nodes with path', fakeAsync(() => {
|
||||
spyOn(directiveInstance, 'restoreNotification').and.callFake(() => null);
|
||||
spyOn(nodesService, 'restoreNode').and.returnValue(Promise.resolve());
|
||||
spyOn(coreApi.nodesApi, 'getDeletedNodes').and.returnValue(Promise.resolve({
|
||||
list: { entries: [] }
|
||||
}));
|
||||
|
||||
it('should call restore when selection has nodes with path', (done) => {
|
||||
component.selection = [{ entry: { id: '1', path: ['somewhere-over-the-rainbow'] } }];
|
||||
|
||||
fixture.detectChanges();
|
||||
element.triggerEventHandler('click', null);
|
||||
tick();
|
||||
|
||||
expect(nodesService.restoreNode).toHaveBeenCalled();
|
||||
}));
|
||||
|
||||
describe('refresh()', () => {
|
||||
it('should reset selection', fakeAsync(() => {
|
||||
spyOn(directiveInstance, 'restoreNotification').and.callFake(() => null);
|
||||
spyOn(nodesService, 'restoreNode').and.returnValue(Promise.resolve());
|
||||
spyOn(coreApi.nodesApi, 'getDeletedNodes').and.returnValue(Promise.resolve({
|
||||
list: { entries: [] }
|
||||
}));
|
||||
fixture.whenStable().then(() => {
|
||||
expect(nodesService.restoreNode).toHaveBeenCalled();
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
describe('reset', () => {
|
||||
it('should reset selection', (done) => {
|
||||
component.selection = [{ entry: { id: '1', path: ['somewhere-over-the-rainbow'] } }];
|
||||
|
||||
directiveInstance.restore.subscribe(() => {
|
||||
expect(directiveInstance.selection.length).toBe(0);
|
||||
done();
|
||||
});
|
||||
|
||||
fixture.detectChanges();
|
||||
|
||||
expect(directiveInstance.selection.length).toBe(1);
|
||||
fixture.whenStable().then(() => {
|
||||
expect(directiveInstance.selection.length).toBe(1);
|
||||
element.triggerEventHandler('click', null);
|
||||
});
|
||||
});
|
||||
|
||||
element.triggerEventHandler('click', null);
|
||||
tick();
|
||||
|
||||
expect(directiveInstance.selection.length).toBe(0);
|
||||
}));
|
||||
|
||||
it('should reset status', fakeAsync(() => {
|
||||
it('should reset status', () => {
|
||||
directiveInstance.restoreProcessStatus.fail = [{}];
|
||||
directiveInstance.restoreProcessStatus.success = [{}];
|
||||
|
||||
@@ -149,39 +134,34 @@ describe('NodeRestoreDirective', () => {
|
||||
|
||||
expect(directiveInstance.restoreProcessStatus.fail).toEqual([]);
|
||||
expect(directiveInstance.restoreProcessStatus.success).toEqual([]);
|
||||
}));
|
||||
});
|
||||
|
||||
it('should emit event on finish', fakeAsync(() => {
|
||||
spyOn(directiveInstance, 'restoreNotification').and.callFake(() => null);
|
||||
spyOn(nodesService, 'restoreNode').and.returnValue(Promise.resolve());
|
||||
spyOn(coreApi.nodesApi, 'getDeletedNodes').and.returnValue(Promise.resolve({
|
||||
list: { entries: [] }
|
||||
}));
|
||||
it('should emit event on finish', (done) => {
|
||||
spyOn(element.nativeElement, 'dispatchEvent');
|
||||
|
||||
directiveInstance.restore.subscribe(() => {
|
||||
expect(component.doneSpy).toHaveBeenCalled();
|
||||
done();
|
||||
});
|
||||
|
||||
component.selection = [{ entry: { id: '1', path: ['somewhere-over-the-rainbow'] } }];
|
||||
|
||||
fixture.detectChanges();
|
||||
element.triggerEventHandler('click', null);
|
||||
tick();
|
||||
|
||||
expect(component.done).toHaveBeenCalled();
|
||||
}));
|
||||
});
|
||||
});
|
||||
|
||||
describe('notification', () => {
|
||||
beforeEach(() => {
|
||||
spyOn(coreApi.nodesApi, 'getDeletedNodes').and.returnValue(Promise.resolve({
|
||||
list: { entries: [] }
|
||||
}));
|
||||
});
|
||||
|
||||
it('should notify on multiple fails', fakeAsync(() => {
|
||||
it('should notify on multiple fails', (done) => {
|
||||
const error = { message: '{ "error": {} }' };
|
||||
|
||||
spyOn(notification, 'openSnackMessageAction').and.returnValue({ onAction: () => Observable.throw(null) });
|
||||
directiveInstance.restore.subscribe((event) => {
|
||||
expect(event.message).toEqual('CORE.RESTORE_NODE.PARTIAL_PLURAL');
|
||||
done();
|
||||
});
|
||||
|
||||
spyOn(nodesService, 'restoreNode').and.callFake((id) => {
|
||||
restoreNodeSpy.and.callFake((id) => {
|
||||
if (id === '1') {
|
||||
return Promise.resolve();
|
||||
}
|
||||
@@ -203,19 +183,18 @@ describe('NodeRestoreDirective', () => {
|
||||
|
||||
fixture.detectChanges();
|
||||
element.triggerEventHandler('click', null);
|
||||
tick();
|
||||
});
|
||||
|
||||
expect(translation.instant).toHaveBeenCalledWith(
|
||||
'CORE.RESTORE_NODE.PARTIAL_PLURAL',
|
||||
{ number: 2 }
|
||||
);
|
||||
}));
|
||||
|
||||
it('should notify fail when restored node exist, error 409', fakeAsync(() => {
|
||||
it('should notify fail when restored node exist, error 409', (done) => {
|
||||
const error = { message: '{ "error": { "statusCode": 409 } }' };
|
||||
|
||||
spyOn(notification, 'openSnackMessageAction').and.returnValue({ onAction: () => Observable.throw(null) });
|
||||
spyOn(nodesService, 'restoreNode').and.returnValue(Promise.reject(error));
|
||||
directiveInstance.restore.subscribe((event) => {
|
||||
expect(event.message).toEqual('CORE.RESTORE_NODE.NODE_EXISTS');
|
||||
|
||||
done();
|
||||
});
|
||||
|
||||
restoreNodeSpy.and.returnValue(Promise.reject(error));
|
||||
|
||||
component.selection = [
|
||||
{ entry: { id: '1', name: 'name1', path: ['somewhere-over-the-rainbow'] } }
|
||||
@@ -223,19 +202,18 @@ describe('NodeRestoreDirective', () => {
|
||||
|
||||
fixture.detectChanges();
|
||||
element.triggerEventHandler('click', null);
|
||||
tick();
|
||||
});
|
||||
|
||||
expect(translation.instant).toHaveBeenCalledWith(
|
||||
'CORE.RESTORE_NODE.NODE_EXISTS',
|
||||
{ name: 'name1' }
|
||||
);
|
||||
}));
|
||||
|
||||
it('should notify fail when restored node returns different statusCode', fakeAsync(() => {
|
||||
it('should notify fail when restored node returns different statusCode', (done) => {
|
||||
const error = { message: '{ "error": { "statusCode": 404 } }' };
|
||||
|
||||
spyOn(notification, 'openSnackMessageAction').and.returnValue({ onAction: () => Observable.throw(null) });
|
||||
spyOn(nodesService, 'restoreNode').and.returnValue(Promise.reject(error));
|
||||
restoreNodeSpy.and.returnValue(Promise.reject(error));
|
||||
|
||||
directiveInstance.restore.subscribe((event) => {
|
||||
expect(event.message).toEqual('CORE.RESTORE_NODE.GENERIC');
|
||||
|
||||
done();
|
||||
});
|
||||
|
||||
component.selection = [
|
||||
{ entry: { id: '1', name: 'name1', path: ['somewhere-over-the-rainbow'] } }
|
||||
@@ -243,19 +221,17 @@ describe('NodeRestoreDirective', () => {
|
||||
|
||||
fixture.detectChanges();
|
||||
element.triggerEventHandler('click', null);
|
||||
tick();
|
||||
});
|
||||
|
||||
expect(translation.instant).toHaveBeenCalledWith(
|
||||
'CORE.RESTORE_NODE.GENERIC',
|
||||
{ name: 'name1' }
|
||||
);
|
||||
}));
|
||||
|
||||
it('should notify fail when restored node location is missing', fakeAsync(() => {
|
||||
it('should notify fail when restored node location is missing', (done) => {
|
||||
const error = { message: '{ "error": { } }' };
|
||||
|
||||
spyOn(notification, 'openSnackMessageAction').and.returnValue({ onAction: () => Observable.throw(null) });
|
||||
spyOn(nodesService, 'restoreNode').and.returnValue(Promise.reject(error));
|
||||
restoreNodeSpy.and.returnValue(Promise.reject(error));
|
||||
|
||||
directiveInstance.restore.subscribe((event) => {
|
||||
expect(event.message).toEqual('CORE.RESTORE_NODE.LOCATION_MISSING');
|
||||
done();
|
||||
});
|
||||
|
||||
component.selection = [
|
||||
{ entry: { id: '1', name: 'name1', path: ['somewhere-over-the-rainbow'] } }
|
||||
@@ -263,17 +239,17 @@ describe('NodeRestoreDirective', () => {
|
||||
|
||||
fixture.detectChanges();
|
||||
element.triggerEventHandler('click', null);
|
||||
tick();
|
||||
});
|
||||
|
||||
expect(translation.instant).toHaveBeenCalledWith(
|
||||
'CORE.RESTORE_NODE.LOCATION_MISSING',
|
||||
{ name: 'name1' }
|
||||
);
|
||||
}));
|
||||
it('should notify success when restore multiple nodes', (done) => {
|
||||
|
||||
it('should notify success when restore multiple nodes', fakeAsync(() => {
|
||||
spyOn(notification, 'openSnackMessageAction').and.returnValue({ onAction: () => Observable.throw(null) });
|
||||
spyOn(nodesService, 'restoreNode').and.callFake((id) => {
|
||||
directiveInstance.restore.subscribe((event) => {
|
||||
expect(event.message).toEqual('CORE.RESTORE_NODE.PLURAL');
|
||||
|
||||
done();
|
||||
});
|
||||
|
||||
restoreNodeSpy.and.callFake((id) => {
|
||||
if (id === '1') {
|
||||
return Promise.resolve();
|
||||
}
|
||||
@@ -290,16 +266,15 @@ describe('NodeRestoreDirective', () => {
|
||||
|
||||
fixture.detectChanges();
|
||||
element.triggerEventHandler('click', null);
|
||||
tick();
|
||||
|
||||
expect(translation.instant).toHaveBeenCalledWith(
|
||||
'CORE.RESTORE_NODE.PLURAL'
|
||||
);
|
||||
}));
|
||||
});
|
||||
|
||||
it('should notify success on restore selected node', fakeAsync(() => {
|
||||
spyOn(notification, 'openSnackMessageAction').and.returnValue({ onAction: () => Observable.throw(null) });
|
||||
spyOn(nodesService, 'restoreNode').and.returnValue(Promise.resolve());
|
||||
it('should notify success on restore selected node', (done) => {
|
||||
directiveInstance.restore.subscribe((event) => {
|
||||
expect(event.message).toEqual('CORE.RESTORE_NODE.SINGULAR');
|
||||
|
||||
done();
|
||||
});
|
||||
|
||||
component.selection = [
|
||||
{ entry: { id: '1', name: 'name1', path: ['somewhere-over-the-rainbow'] } }
|
||||
@@ -307,36 +282,8 @@ describe('NodeRestoreDirective', () => {
|
||||
|
||||
fixture.detectChanges();
|
||||
element.triggerEventHandler('click', null);
|
||||
tick();
|
||||
|
||||
expect(translation.instant).toHaveBeenCalledWith(
|
||||
'CORE.RESTORE_NODE.SINGULAR',
|
||||
{ name: 'name1' }
|
||||
);
|
||||
}));
|
||||
});
|
||||
|
||||
it('should navigate to restored node location onAction', fakeAsync(() => {
|
||||
spyOn(router, 'navigate');
|
||||
spyOn(nodesService, 'restoreNode').and.returnValue(Promise.resolve());
|
||||
spyOn(notification, 'openSnackMessageAction').and.returnValue({ onAction: () => Observable.of({}) });
|
||||
|
||||
component.selection = [
|
||||
{
|
||||
entry: {
|
||||
id: '1',
|
||||
name: 'name1',
|
||||
path: {
|
||||
elements: ['somewhere-over-the-rainbow']
|
||||
}
|
||||
}
|
||||
}
|
||||
];
|
||||
|
||||
fixture.detectChanges();
|
||||
element.triggerEventHandler('click', null);
|
||||
tick();
|
||||
|
||||
expect(router.navigate).toHaveBeenCalled();
|
||||
}));
|
||||
});
|
||||
});
|
||||
|
Reference in New Issue
Block a user