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,7 +16,7 @@
|
||||
*/
|
||||
|
||||
import { Component, DebugElement, ViewChild } 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 { AlfrescoApiService } from '../services/alfresco-api.service';
|
||||
import { NodeDeleteDirective } from './node-delete.directive';
|
||||
@@ -38,7 +38,8 @@ class TestComponent {
|
||||
@ViewChild(NodeDeleteDirective)
|
||||
deleteDirective: NodeDeleteDirective;
|
||||
|
||||
onDelete(event) {}
|
||||
onDelete(event) {
|
||||
}
|
||||
}
|
||||
|
||||
@Component({
|
||||
@@ -89,6 +90,9 @@ describe('NodeDeleteDirective', () => {
|
||||
let componentWithPermanentDelete: TestDeletePermanentComponent;
|
||||
let alfrescoApi: AlfrescoApiService;
|
||||
let nodeApi;
|
||||
let deleteNodeSpy: any;
|
||||
let purgeDeletedNodeSpy: any;
|
||||
let disposableDelete: any;
|
||||
|
||||
setupTestBed({
|
||||
imports: [
|
||||
@@ -105,7 +109,12 @@ describe('NodeDeleteDirective', () => {
|
||||
]
|
||||
});
|
||||
|
||||
beforeEach(async(() => {
|
||||
beforeEach(() => {
|
||||
alfrescoApi = TestBed.get(AlfrescoApiService);
|
||||
nodeApi = alfrescoApi.nodesApi;
|
||||
deleteNodeSpy = spyOn(nodeApi, 'deleteNode').and.returnValue(Promise.resolve());
|
||||
purgeDeletedNodeSpy = spyOn(nodeApi, 'purgeDeletedNode').and.returnValue(Promise.resolve());
|
||||
|
||||
fixture = TestBed.createComponent(TestComponent);
|
||||
fixtureWithPermissions = TestBed.createComponent(TestWithPermissionsComponent);
|
||||
fixtureWithPermanentComponent = TestBed.createComponent(TestDeletePermanentComponent);
|
||||
@@ -117,33 +126,30 @@ describe('NodeDeleteDirective', () => {
|
||||
element = fixture.debugElement.query(By.directive(NodeDeleteDirective));
|
||||
elementWithPermissions = fixtureWithPermissions.debugElement.query(By.directive(NodeDeleteDirective));
|
||||
elementWithPermanentDelete = fixtureWithPermanentComponent.debugElement.query(By.directive(NodeDeleteDirective));
|
||||
|
||||
alfrescoApi = TestBed.get(AlfrescoApiService);
|
||||
nodeApi = alfrescoApi.getInstance().nodes;
|
||||
}));
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
if (disposableDelete) {
|
||||
disposableDelete.unsubscribe();
|
||||
}
|
||||
fixture.destroy();
|
||||
});
|
||||
|
||||
describe('Delete', () => {
|
||||
|
||||
it('should do nothing if selection is empty', () => {
|
||||
spyOn(nodeApi, 'deleteNode');
|
||||
component.selection = [];
|
||||
|
||||
fixture.detectChanges();
|
||||
element.nativeElement.click();
|
||||
|
||||
expect(nodeApi.deleteNode).not.toHaveBeenCalled();
|
||||
expect(deleteNodeSpy).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('should process node successfully', (done) => {
|
||||
spyOn(nodeApi, 'deleteNode').and.returnValue(Promise.resolve());
|
||||
|
||||
component.selection = <any> [{ entry: { id: '1', name: 'name1' } }];
|
||||
|
||||
component.deleteDirective.delete.subscribe((message) => {
|
||||
disposableDelete = component.deleteDirective.delete.subscribe((message) => {
|
||||
expect(message).toBe(
|
||||
'CORE.DELETE_NODE.SINGULAR'
|
||||
);
|
||||
@@ -158,11 +164,11 @@ describe('NodeDeleteDirective', () => {
|
||||
});
|
||||
|
||||
it('should notify failed node deletion', (done) => {
|
||||
spyOn(nodeApi, 'deleteNode').and.returnValue(Promise.reject('error'));
|
||||
deleteNodeSpy.and.returnValue(Promise.reject('error'));
|
||||
|
||||
component.selection = [{ entry: { id: '1', name: 'name1' } }];
|
||||
|
||||
component.deleteDirective.delete.subscribe((message) => {
|
||||
disposableDelete = component.deleteDirective.delete.subscribe((message) => {
|
||||
expect(message).toBe(
|
||||
'CORE.DELETE_NODE.ERROR_SINGULAR'
|
||||
);
|
||||
@@ -177,14 +183,12 @@ describe('NodeDeleteDirective', () => {
|
||||
});
|
||||
|
||||
it('should notify nodes deletion', (done) => {
|
||||
spyOn(nodeApi, 'deleteNode').and.returnValue(Promise.resolve());
|
||||
|
||||
component.selection = [
|
||||
{ entry: { id: '1', name: 'name1' } },
|
||||
{ entry: { id: '2', name: 'name2' } }
|
||||
];
|
||||
|
||||
component.deleteDirective.delete.subscribe((message) => {
|
||||
disposableDelete = component.deleteDirective.delete.subscribe((message) => {
|
||||
expect(message).toBe(
|
||||
'CORE.DELETE_NODE.PLURAL'
|
||||
);
|
||||
@@ -199,14 +203,14 @@ describe('NodeDeleteDirective', () => {
|
||||
});
|
||||
|
||||
it('should notify failed nodes deletion', (done) => {
|
||||
spyOn(nodeApi, 'deleteNode').and.returnValue(Promise.reject('error'));
|
||||
deleteNodeSpy.and.returnValue(Promise.reject('error'));
|
||||
|
||||
component.selection = [
|
||||
{ entry: { id: '1', name: 'name1' } },
|
||||
{ entry: { id: '2', name: 'name2' } }
|
||||
];
|
||||
|
||||
component.deleteDirective.delete.subscribe((message) => {
|
||||
disposableDelete = component.deleteDirective.delete.subscribe((message) => {
|
||||
expect(message).toBe(
|
||||
'CORE.DELETE_NODE.ERROR_PLURAL'
|
||||
);
|
||||
@@ -221,7 +225,7 @@ describe('NodeDeleteDirective', () => {
|
||||
});
|
||||
|
||||
it('should notify partial deletion when only one node is successful', (done) => {
|
||||
spyOn(nodeApi, 'deleteNode').and.callFake((id) => {
|
||||
deleteNodeSpy.and.callFake((id) => {
|
||||
if (id === '1') {
|
||||
return Promise.reject('error');
|
||||
} else {
|
||||
@@ -234,7 +238,7 @@ describe('NodeDeleteDirective', () => {
|
||||
{ entry: { id: '2', name: 'name2' } }
|
||||
];
|
||||
|
||||
component.deleteDirective.delete.subscribe((message) => {
|
||||
disposableDelete = component.deleteDirective.delete.subscribe((message) => {
|
||||
expect(message).toBe(
|
||||
'CORE.DELETE_NODE.PARTIAL_SINGULAR'
|
||||
);
|
||||
@@ -249,7 +253,7 @@ describe('NodeDeleteDirective', () => {
|
||||
});
|
||||
|
||||
it('should notify partial deletion when some nodes are successful', (done) => {
|
||||
spyOn(nodeApi, 'deleteNode').and.callFake((id) => {
|
||||
deleteNodeSpy.and.callFake((id) => {
|
||||
if (id === '1') {
|
||||
return Promise.reject(null);
|
||||
}
|
||||
@@ -269,7 +273,7 @@ describe('NodeDeleteDirective', () => {
|
||||
{ entry: { id: '3', name: 'name3' } }
|
||||
];
|
||||
|
||||
component.deleteDirective.delete.subscribe((message) => {
|
||||
disposableDelete = component.deleteDirective.delete.subscribe((message) => {
|
||||
expect(message).toBe(
|
||||
'CORE.DELETE_NODE.PARTIAL_PLURAL'
|
||||
);
|
||||
@@ -284,36 +288,39 @@ describe('NodeDeleteDirective', () => {
|
||||
});
|
||||
|
||||
it('should emit event when delete is done', (done) => {
|
||||
spyOn(alfrescoApi.nodesApi, 'deleteNode').and.returnValue(Promise.resolve());
|
||||
|
||||
component.selection = <any> [{ entry: { id: '1', name: 'name1' } }];
|
||||
fixture.detectChanges();
|
||||
|
||||
element.nativeElement.click();
|
||||
fixture.detectChanges();
|
||||
|
||||
component.deleteDirective.delete.subscribe(() => {
|
||||
disposableDelete = component.deleteDirective.delete.subscribe(() => {
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should disable the button if no node are selected', fakeAsync(() => {
|
||||
it('should disable the button if no node are selected', (done) => {
|
||||
component.selection = [];
|
||||
|
||||
fixture.detectChanges();
|
||||
fixture.whenStable().then(() => {
|
||||
expect(element.nativeElement.disabled).toEqual(true);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
expect(element.nativeElement.disabled).toEqual(true);
|
||||
}));
|
||||
|
||||
it('should disable the button if selected node is null', fakeAsync(() => {
|
||||
it('should disable the button if selected node is null', (done) => {
|
||||
component.selection = null;
|
||||
|
||||
fixture.detectChanges();
|
||||
|
||||
expect(element.nativeElement.disabled).toEqual(true);
|
||||
}));
|
||||
fixture.whenStable().then(() => {
|
||||
expect(element.nativeElement.disabled).toEqual(true);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should enable the button if nodes are selected', fakeAsync(() => {
|
||||
it('should enable the button if nodes are selected', (done) => {
|
||||
component.selection = [
|
||||
{ entry: { id: '1', name: 'name1' } },
|
||||
{ entry: { id: '2', name: 'name2' } },
|
||||
@@ -322,10 +329,13 @@ describe('NodeDeleteDirective', () => {
|
||||
|
||||
fixture.detectChanges();
|
||||
|
||||
expect(element.nativeElement.disabled).toEqual(false);
|
||||
}));
|
||||
fixture.whenStable().then(() => {
|
||||
expect(element.nativeElement.disabled).toEqual(false);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should not enable the button if adf-node-permission is present', fakeAsync(() => {
|
||||
it('should not enable the button if adf-node-permission is present', (done) => {
|
||||
elementWithPermissions.nativeElement.disabled = false;
|
||||
componentWithPermissions.selection = [];
|
||||
|
||||
@@ -339,14 +349,15 @@ describe('NodeDeleteDirective', () => {
|
||||
|
||||
fixtureWithPermissions.detectChanges();
|
||||
|
||||
expect(elementWithPermissions.nativeElement.disabled).toEqual(false);
|
||||
}));
|
||||
fixture.whenStable().then(() => {
|
||||
expect(elementWithPermissions.nativeElement.disabled).toEqual(false);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
describe('Permanent', () => {
|
||||
|
||||
it('should call the api with permanent delete option if permanent directive input is true', fakeAsync(() => {
|
||||
let deleteApi = spyOn(nodeApi, 'deleteNode').and.returnValue(Promise.resolve());
|
||||
|
||||
it('should call the api with permanent delete option if permanent directive input is true', (done) => {
|
||||
fixtureWithPermanentComponent.detectChanges();
|
||||
|
||||
componentWithPermanentDelete.selection = [
|
||||
@@ -356,14 +367,14 @@ describe('NodeDeleteDirective', () => {
|
||||
fixtureWithPermanentComponent.detectChanges();
|
||||
|
||||
elementWithPermanentDelete.nativeElement.click();
|
||||
tick();
|
||||
|
||||
expect(deleteApi).toHaveBeenCalledWith('1', { permanent: true });
|
||||
}));
|
||||
|
||||
it('should call the trashcan api if permanent directive input is true and the file is already in the trashcan ', fakeAsync(() => {
|
||||
let deleteApi = spyOn(nodeApi, 'purgeDeletedNode').and.returnValue(Promise.resolve());
|
||||
fixture.whenStable().then(() => {
|
||||
expect(deleteNodeSpy).toHaveBeenCalledWith('1', { permanent: true });
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should call the trashcan api if permanent directive input is true and the file is already in the trashcan ', (done) => {
|
||||
fixtureWithPermanentComponent.detectChanges();
|
||||
|
||||
componentWithPermanentDelete.selection = [
|
||||
@@ -373,10 +384,12 @@ describe('NodeDeleteDirective', () => {
|
||||
fixtureWithPermanentComponent.detectChanges();
|
||||
|
||||
elementWithPermanentDelete.nativeElement.click();
|
||||
tick();
|
||||
|
||||
expect(deleteApi).toHaveBeenCalledWith('1');
|
||||
}));
|
||||
fixture.whenStable().then(() => {
|
||||
expect(purgeDeletedNodeSpy).toHaveBeenCalledWith('1');
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
});
|
||||
|
Reference in New Issue
Block a user