unit test performance (#3194)

* DataTable (-4 sec)

* PaginationComponent (-1 sec)

* DocumentList

* custom testbed setup, test upgrades

* test fixes

* more test fixes

* remove fdescribe

* test fixes

* test fixes

* more test fixes

* test fixes

* upgrade tests

* update tests

* upgrade tests

* upgrade tests

* upgrade tests

* upgrade tests

* update tests

* translate loader fixes

* auth and cookie fixes

* upgrade tests

* upgrade tests

* test fixes

* almost there

* diable broken tests

* process tests (part 1)

* fix lint issues

* another test upgrade

* almost there

* cleanup

* insights testing upgrade

* improve tests

* tests cleanup

* tests cleanup

* cleanup tests

* test cleanup

* favorite nodes tests

* rebase fix syntax

* fix core test

* give up test focus

* flush tabs

* fix search test

* Update document-list.component.spec.ts

* fix document list lock

* increase tick time

* remove duplicate test
This commit is contained in:
Denys Vuika
2018-04-23 09:55:22 +01:00
committed by Eugenio Romano
parent 9fbfcfa96e
commit 382ea3c1b3
204 changed files with 3093 additions and 4389 deletions

View File

@@ -16,10 +16,12 @@
*/
import { Component, ViewChildren } from '@angular/core';
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { By } from '@angular/platform-browser';
import { HighlightTransformService } from '../services/highlight-transform.service';
import { HighlightDirective } from './highlight.directive';
import { setupTestBed } from '../testing/setupTestBed';
import { CoreModule } from '../core.module';
const template: string = `
<div id="outerDiv1" adf-highlight adf-highlight-selector=".highlightable" adf-highlight-class="highlight-for-free-willy">
@@ -42,16 +44,14 @@ describe('HighlightDirective', () => {
let fixture: ComponentFixture<TestComponent>;
let component: TestComponent;
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [
TestComponent
],
providers: [
HighlightTransformService
]
}).compileComponents();
}));
setupTestBed({
imports: [
CoreModule.forRoot()
],
declarations: [
TestComponent
]
});
beforeEach(() => {
fixture = TestBed.createComponent(TestComponent);

View File

@@ -16,12 +16,13 @@
*/
import { Component } from '@angular/core';
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { Router } from '@angular/router';
import { RouterTestingModule } from '@angular/router/testing';
import { Observable } from 'rxjs/Observable';
import { AuthenticationService } from '../services';
import { setupTestBed } from '../testing/setupTestBed';
import { CoreModule } from '../core.module';
describe('LogoutDirective', () => {
@@ -35,16 +36,15 @@ describe('LogoutDirective', () => {
let router: Router;
let authService: AuthenticationService;
beforeEach(async(() => {
TestBed.configureTestingModule({
imports: [
RouterTestingModule
],
declarations: [
TestComponent
]
}).compileComponents();
}));
setupTestBed({
imports: [
CoreModule.forRoot(),
RouterTestingModule
],
declarations: [
TestComponent
]
});
beforeEach(() => {
router = TestBed.get(Router);

View File

@@ -20,6 +20,11 @@ import { async, ComponentFixture, fakeAsync, TestBed, tick } from '@angular/core
import { By } from '@angular/platform-browser';
import { AlfrescoApiService } from '../services/alfresco-api.service';
import { NodeDeleteDirective } from './node-delete.directive';
import { setupTestBed } from '../testing/setupTestBed';
import { CoreModule } from '../core.module';
import { AlfrescoApiServiceMock } from '../mock/alfresco-api.service.mock';
import { TranslationService } from '../services/translation.service';
import { TranslationMock } from '../mock/translation.service.mock';
@Component({
template: `
@@ -31,9 +36,9 @@ class TestComponent {
selection = [];
@ViewChild(NodeDeleteDirective)
deleteDirective;
deleteDirective: NodeDeleteDirective;
onDelete = jasmine.createSpy('onDelete');
onDelete(event) {}
}
@Component({
@@ -47,7 +52,7 @@ class TestWithPermissionsComponent {
selection = [];
@ViewChild(NodeDeleteDirective)
deleteDirective;
deleteDirective: NodeDeleteDirective;
onDelete = jasmine.createSpy('onDelete');
}
@@ -65,14 +70,14 @@ class TestDeletePermanentComponent {
selection = [];
@ViewChild(NodeDeleteDirective)
deleteDirective;
deleteDirective: NodeDeleteDirective;
permanent = true;
onDelete = jasmine.createSpy('onDelete');
}
describe('NodeleteDirective', () => {
describe('NodeDeleteDirective', () => {
let fixture: ComponentFixture<TestComponent>;
let fixtureWithPermissions: ComponentFixture<TestWithPermissionsComponent>;
let fixtureWithPermanentComponent: ComponentFixture<TestDeletePermanentComponent>;
@@ -85,33 +90,42 @@ describe('NodeleteDirective', () => {
let alfrescoApi: AlfrescoApiService;
let nodeApi;
setupTestBed({
imports: [
CoreModule.forRoot()
],
declarations: [
TestComponent,
TestWithPermissionsComponent,
TestDeletePermanentComponent
],
providers: [
{ provide: AlfrescoApiService, useClass: AlfrescoApiServiceMock },
{ provide: TranslationService, useClass: TranslationMock }
]
});
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [
TestComponent,
TestWithPermissionsComponent,
TestDeletePermanentComponent
]
})
.compileComponents()
.then(() => {
fixture = TestBed.createComponent(TestComponent);
fixtureWithPermissions = TestBed.createComponent(TestWithPermissionsComponent);
fixtureWithPermanentComponent = TestBed.createComponent(TestDeletePermanentComponent);
fixture = TestBed.createComponent(TestComponent);
fixtureWithPermissions = TestBed.createComponent(TestWithPermissionsComponent);
fixtureWithPermanentComponent = TestBed.createComponent(TestDeletePermanentComponent);
component = fixture.componentInstance;
componentWithPermissions = fixtureWithPermissions.componentInstance;
componentWithPermanentDelete = fixtureWithPermanentComponent.componentInstance;
component = fixture.componentInstance;
componentWithPermissions = fixtureWithPermissions.componentInstance;
componentWithPermanentDelete = fixtureWithPermanentComponent.componentInstance;
element = fixture.debugElement.query(By.directive(NodeDeleteDirective));
elementWithPermissions = fixtureWithPermissions.debugElement.query(By.directive(NodeDeleteDirective));
elementWithPermanentDelete = fixtureWithPermanentComponent.debugElement.query(By.directive(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;
});
alfrescoApi = TestBed.get(AlfrescoApiService);
nodeApi = alfrescoApi.getInstance().nodes;
}));
afterEach(() => {
fixture.destroy();
});
describe('Delete', () => {
it('should do nothing if selection is empty', () => {
@@ -269,18 +283,19 @@ describe('NodeleteDirective', () => {
});
});
it('should emit event when delete is done', fakeAsync(() => {
component.onDelete.calls.reset();
spyOn(nodeApi, 'deleteNode').and.returnValue(Promise.resolve());
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();
tick();
expect(component.onDelete).toHaveBeenCalled();
}));
element.nativeElement.click();
fixture.detectChanges();
component.deleteDirective.delete.subscribe(() => {
done();
});
});
it('should disable the button if no node are selected', fakeAsync(() => {
component.selection = [];
@@ -329,13 +344,13 @@ describe('NodeleteDirective', () => {
describe('Permanent', () => {
it('should call the api with permamnet delete option if permanent directive input is true', fakeAsync(() => {
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());
fixtureWithPermanentComponent.detectChanges();
componentWithPermanentDelete.selection = [
{ entry: { id: '1', name: 'name1' }
{ entry: { id: '1', name: 'name1' } }
];
fixtureWithPermanentComponent.detectChanges();
@@ -346,7 +361,7 @@ describe('NodeleteDirective', () => {
expect(deleteApi).toHaveBeenCalledWith('1', { permanent: true });
}));
it('should call the traschan api if permanent directive input is true and the file is already in the trashcan ', fakeAsync(() => {
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());
fixtureWithPermanentComponent.detectChanges();

View File

@@ -96,8 +96,9 @@ export class NodeDeleteDirective implements OnChanges {
Observable.forkJoin(...batch)
.subscribe((data: ProcessedNodeData[]) => {
const processedItems: ProcessStatus = this.processStatus(data);
const message = this.getMessage(processedItems);
this.delete.emit(this.getMessage(processedItems));
this.delete.emit(message);
});
}
}
@@ -112,9 +113,9 @@ export class NodeDeleteDirective implements OnChanges {
let promise;
if (node.entry.hasOwnProperty('archivedAt')) {
promise = this.alfrescoApiService.getInstance().nodes.purgeDeletedNode(id);
promise = this.alfrescoApiService.nodesApi.purgeDeletedNode(id);
} else {
promise = this.alfrescoApiService.getInstance().nodes.deleteNode(id, { permanent: this.permanent });
promise = this.alfrescoApiService.nodesApi.deleteNode(id, { permanent: this.permanent });
}
return Observable.fromPromise(promise)

View File

@@ -15,97 +15,71 @@
* limitations under the License.
*/
import { Component, DebugElement } from '@angular/core';
import { async, ComponentFixture, fakeAsync, TestBed, tick } from '@angular/core/testing';
import { By } from '@angular/platform-browser';
import { AlfrescoApiService } from '../services/alfresco-api.service';
import { SimpleChange } from '@angular/core';
import { fakeAsync, tick } from '@angular/core/testing';
import { NodeFavoriteDirective } from './node-favorite.directive';
@Component({
template: `
<div [adf-node-favorite]="selection"
(toggle)="done()">
</div>`
})
class TestComponent {
selection;
done = jasmine.createSpy('done');
}
import { AlfrescoApiServiceMock } from '../mock/alfresco-api.service.mock';
import { AppConfigService, StorageService } from '@alfresco/adf-core';
describe('NodeFavoriteDirective', () => {
let component: TestComponent;
let fixture: ComponentFixture<TestComponent>;
let element: DebugElement;
let directiveInstance;
let apiService;
let favoritesApi;
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [
TestComponent
]
})
.compileComponents()
.then(() => {
fixture = TestBed.createComponent(TestComponent);
component = fixture.componentInstance;
element = fixture.debugElement.query(By.directive(NodeFavoriteDirective));
directiveInstance = element.injector.get(NodeFavoriteDirective);
let directive;
let alfrescoApiService;
apiService = TestBed.get(AlfrescoApiService);
favoritesApi = apiService.getInstance().core.favoritesApi;
});
}));
beforeEach(() => {
alfrescoApiService = new AlfrescoApiServiceMock(new AppConfigService(null), new StorageService());
directive = new NodeFavoriteDirective( alfrescoApiService);
});
describe('selection input change event', () => {
it('should not call markFavoritesNodes() if input list is empty', () => {
spyOn(directiveInstance, 'markFavoritesNodes');
spyOn(directive, 'markFavoritesNodes');
component.selection = [];
const change = new SimpleChange(null, [], true);
directive.ngOnChanges({'selection': change});
fixture.detectChanges();
expect(directiveInstance.markFavoritesNodes).not.toHaveBeenCalledWith();
expect(directive.markFavoritesNodes).not.toHaveBeenCalledWith();
});
it('should call markFavoritesNodes() on input change', () => {
spyOn(directiveInstance, 'markFavoritesNodes');
spyOn(directive, 'markFavoritesNodes');
component.selection = [{ entry: { id: '1', name: 'name1' } }];
let selection = [{ entry: { id: '1', name: 'name1' } }];
fixture.detectChanges();
let change = new SimpleChange(null, selection, true);
directive.ngOnChanges({'selection': change});
expect(directiveInstance.markFavoritesNodes).toHaveBeenCalledWith(component.selection);
expect(directive.markFavoritesNodes).toHaveBeenCalledWith(selection);
component.selection = [
selection = [
{ entry: { id: '1', name: 'name1' } },
{ entry: { id: '1', name: 'name1' } }
{ entry: { id: '2', name: 'name2' } }
];
fixture.detectChanges();
change = new SimpleChange(null, selection, true);
directive.ngOnChanges({'selection': change});
expect(directiveInstance.markFavoritesNodes).toHaveBeenCalledWith(component.selection);
expect(directive.markFavoritesNodes).toHaveBeenCalledWith(selection);
});
it('should reset favorites if selection is empty', fakeAsync(() => {
spyOn(favoritesApi, 'getFavorite').and.returnValue(Promise.resolve());
spyOn(alfrescoApiService.getInstance().core.favoritesApi, 'getFavorite').and.returnValue(Promise.resolve());
component.selection = [
let selection = [
{ entry: { id: '1', name: 'name1' } }
];
fixture.detectChanges();
let change = new SimpleChange(null, selection, true);
directive.ngOnChanges({'selection': change});
tick();
expect(directiveInstance.hasFavorites()).toBe(true);
expect(directive.hasFavorites()).toBe(true);
component.selection = [];
fixture.detectChanges();
change = new SimpleChange(null, [], true);
directive.ngOnChanges({'selection': change});
tick();
expect(directiveInstance.hasFavorites()).toBe(false);
expect(directive.hasFavorites()).toBe(false);
}));
});
@@ -113,76 +87,78 @@ describe('NodeFavoriteDirective', () => {
let favoritesApiSpy;
beforeEach(() => {
favoritesApiSpy = spyOn(favoritesApi, 'getFavorite');
favoritesApiSpy = spyOn(alfrescoApiService.getInstance().core.favoritesApi, 'getFavorite')
.and.returnValue(Promise.resolve());
});
it('should check each selected node if it is a favorite', fakeAsync(() => {
favoritesApiSpy.and.returnValue(Promise.resolve());
component.selection = [
const selection = [
{ entry: { id: '1', name: 'name1' } },
{ entry: { id: '2', name: 'name2' } }
];
fixture.detectChanges();
tick();
let change = new SimpleChange(null, selection, true);
directive.ngOnChanges({'selection': change});
tick();
expect(favoritesApiSpy.calls.count()).toBe(2);
}));
it('should not check processed node when another is unselected', fakeAsync(() => {
favoritesApiSpy.and.returnValue(Promise.resolve());
component.selection = [
let selection = [
{ entry: { id: '1', name: 'name1' } },
{ entry: { id: '2', name: 'name2' } }
];
fixture.detectChanges();
tick();
let change = new SimpleChange(null, selection, true);
directive.ngOnChanges({'selection': change});
expect(directiveInstance.favorites.length).toBe(2);
tick();
expect(directive.favorites.length).toBe(2);
expect(favoritesApiSpy.calls.count()).toBe(2);
favoritesApiSpy.calls.reset();
component.selection = [
selection = [
{ entry: { id: '2', name: 'name2' } }
];
fixture.detectChanges();
tick();
change = new SimpleChange(null, selection, true);
directive.ngOnChanges({'selection': change});
expect(directiveInstance.favorites.length).toBe(1);
tick();
expect(directive.favorites.length).toBe(1);
expect(favoritesApiSpy).not.toHaveBeenCalled();
}));
it('should not check processed nodes when another is selected', fakeAsync(() => {
favoritesApiSpy.and.returnValue(Promise.resolve());
component.selection = [
let selection = [
{ entry: { id: '1', name: 'name1' } },
{ entry: { id: '2', name: 'name2' } }
];
fixture.detectChanges();
let change = new SimpleChange(null, selection, true);
directive.ngOnChanges({'selection': change});
tick();
expect(directiveInstance.favorites.length).toBe(2);
expect(directive.favorites.length).toBe(2);
expect(favoritesApiSpy.calls.count()).toBe(2);
favoritesApiSpy.calls.reset();
component.selection = [
selection = [
{ entry: { id: '1', name: 'name1' } },
{ entry: { id: '2', name: 'name2' } },
{ entry: { id: '3', name: 'name3' } }
];
fixture.detectChanges();
change = new SimpleChange(null, selection, true);
directive.ngOnChanges({'selection': change});
tick();
expect(directiveInstance.favorites.length).toBe(3);
expect(directive.favorites.length).toBe(3);
expect(favoritesApiSpy.calls.count()).toBe(1);
}));
});
@@ -192,8 +168,8 @@ describe('NodeFavoriteDirective', () => {
let addFavoriteSpy;
beforeEach(() => {
removeFavoriteSpy = spyOn(favoritesApi, 'removeFavoriteSite');
addFavoriteSpy = spyOn(favoritesApi, 'addFavorite');
removeFavoriteSpy = spyOn(alfrescoApiService.getInstance().core.favoritesApi, 'removeFavoriteSite');
addFavoriteSpy = spyOn(alfrescoApiService.getInstance().core.favoritesApi, 'addFavorite');
});
afterEach(() => {
@@ -201,170 +177,172 @@ describe('NodeFavoriteDirective', () => {
addFavoriteSpy.calls.reset();
});
it('should not perform action if favorites collection is empty', () => {
component.selection = [];
it('should not perform action if favorites collection is empty', fakeAsync(() => {
let change = new SimpleChange(null, [], true);
directive.ngOnChanges({'selection': change});
tick();
fixture.detectChanges();
element.triggerEventHandler('click', null);
directive.toggleFavorite();
expect(removeFavoriteSpy).not.toHaveBeenCalled();
expect(addFavoriteSpy).not.toHaveBeenCalled();
});
}));
it('should call addFavorite() if none is a favorite', fakeAsync(() => {
it('should call addFavorite() if none is a favorite', () => {
addFavoriteSpy.and.returnValue(Promise.resolve());
directiveInstance.favorites = [
directive.favorites = [
{ entry: { id: '1', name: 'name1', isFavorite: false } },
{ entry: { id: '2', name: 'name2', isFavorite: false } }
];
element.triggerEventHandler('click', null);
tick();
directive.toggleFavorite();
expect(addFavoriteSpy.calls.argsFor(0)[1].length).toBe(2);
}));
});
it('should call addFavorite() on node that is not a favorite in selection', fakeAsync(() => {
it('should call addFavorite() on node that is not a favorite in selection', () => {
addFavoriteSpy.and.returnValue(Promise.resolve());
directiveInstance.favorites = [
directive.favorites = [
{ entry: { id: '1', name: 'name1', isFile: true, isFolder: false, isFavorite: false } },
{ entry: { id: '2', name: 'name2', isFile: true, isFolder: false, isFavorite: true } }
];
element.triggerEventHandler('click', null);
tick();
directive.toggleFavorite();
const callArgs = addFavoriteSpy.calls.argsFor(0)[1];
const callParameter = callArgs[0];
expect(callArgs.length).toBe(1);
expect(callParameter.target.file.guid).toBe('1');
}));
});
it('should call removeFavoriteSite() if all are favorites', fakeAsync(() => {
it('should call removeFavoriteSite() if all are favorites', () => {
removeFavoriteSpy.and.returnValue(Promise.resolve());
directiveInstance.favorites = [
directive.favorites = [
{ entry: { id: '1', name: 'name1', isFavorite: true } },
{ entry: { id: '2', name: 'name2', isFavorite: true } }
];
element.triggerEventHandler('click', null);
tick();
directive.toggleFavorite();
expect(removeFavoriteSpy.calls.count()).toBe(2);
}));
});
it('should emit event when removeFavoriteSite() is done', fakeAsync(() => {
removeFavoriteSpy.and.returnValue(Promise.resolve());
spyOn(directive.toggle, 'emit');
directiveInstance.favorites = [
directive.favorites = [
{ entry: { id: '1', name: 'name1', isFavorite: true } }
];
element.triggerEventHandler('click', null);
directive.toggleFavorite();
tick();
expect(component.done).toHaveBeenCalled();
expect(directive.toggle.emit).toHaveBeenCalled();
}));
it('should emit event when addFavorite() is done', fakeAsync(() => {
addFavoriteSpy.and.returnValue(Promise.resolve());
spyOn(directive.toggle, 'emit');
directiveInstance.favorites = [
directive.favorites = [
{ entry: { id: '1', name: 'name1', isFavorite: false } }
];
element.triggerEventHandler('click', null);
directive.toggleFavorite();
tick();
expect(component.done).toHaveBeenCalled();
expect(directive.toggle.emit).toHaveBeenCalled();
}));
it('should set isFavorites items to false', fakeAsync(() => {
removeFavoriteSpy.and.returnValue(Promise.resolve());
directiveInstance.favorites = [
directive.favorites = [
{ entry: { id: '1', name: 'name1', isFavorite: true } }
];
element.triggerEventHandler('click', null);
directive.toggleFavorite();
tick();
expect(directiveInstance.hasFavorites()).toBe(false);
expect(directive.hasFavorites()).toBe(false);
}));
it('should set isFavorites items to true', fakeAsync(() => {
addFavoriteSpy.and.returnValue(Promise.resolve());
directiveInstance.favorites = [
directive.favorites = [
{ entry: { id: '1', name: 'name1', isFavorite: false } }
];
element.triggerEventHandler('click', null);
directive.toggleFavorite();
tick();
expect(directiveInstance.hasFavorites()).toBe(true);
expect(directive.hasFavorites()).toBe(true);
}));
});
describe('getFavorite()', () => {
it('should process node as favorite', fakeAsync(() => {
spyOn(favoritesApi, 'getFavorite').and.returnValue(Promise.resolve());
spyOn(alfrescoApiService.getInstance().core.favoritesApi, 'getFavorite').and.returnValue(Promise.resolve());
component.selection = [
const selection = [
{ entry: { id: '1', name: 'name1' } }
];
fixture.detectChanges();
let change = new SimpleChange(null, selection, true);
directive.ngOnChanges({'selection': change});
tick();
expect(directiveInstance.favorites[0].entry.isFavorite).toBe(true);
expect(directive.favorites[0].entry.isFavorite).toBe(true);
}));
it('should not process node as favorite', fakeAsync(() => {
spyOn(favoritesApi, 'getFavorite').and.returnValue(Promise.reject(null));
spyOn(alfrescoApiService.getInstance().core.favoritesApi, 'getFavorite').and.returnValue(Promise.reject({}));
component.selection = [
const selection = [
{ entry: { id: '1', name: 'name1' } }
];
fixture.detectChanges();
let change = new SimpleChange(null, selection, true);
directive.ngOnChanges({'selection': change});
tick();
expect(directiveInstance.favorites[0].entry.isFavorite).toBe(false);
expect(directive.favorites[0].entry.isFavorite).toBe(false);
}));
});
describe('hasFavorites()', () => {
it('should return false when favorites collection is empty', () => {
directiveInstance.favorites = [];
directive.favorites = [];
const hasFavorites = directiveInstance.hasFavorites();
const hasFavorites = directive.hasFavorites();
expect(hasFavorites).toBe(false);
});
it('should return false when some are not favorite', () => {
directiveInstance.favorites = [
directive.favorites = [
{ entry: { id: '1', name: 'name1', isFavorite: true } },
{ entry: { id: '2', name: 'name2', isFavorite: false } }
];
const hasFavorites = directiveInstance.hasFavorites();
const hasFavorites = directive.hasFavorites();
expect(hasFavorites).toBe(false);
});
it('return true when all are favorite', () => {
directiveInstance.favorites = [
directive.favorites = [
{ entry: { id: '1', name: 'name1', isFavorite: true } },
{ entry: { id: '2', name: 'name2', isFavorite: true } }
];
const hasFavorites = directiveInstance.hasFavorites();
const hasFavorites = directive.hasFavorites();
expect(hasFavorites).toBe(true);
});

View File

@@ -29,7 +29,7 @@ import 'rxjs/observable/forkJoin';
exportAs: 'adfFavorite'
})
export class NodeFavoriteDirective implements OnChanges {
private favorites: any[] = [];
favorites: any[] = [];
/** Array of nodes to toggle as favorites. */
@Input('adf-node-favorite')
@@ -68,7 +68,7 @@ export class NodeFavoriteDirective implements OnChanges {
// shared files have nodeId
const id = selected.entry.nodeId || selected.entry.id;
return Observable.fromPromise(this.alfrescoApiService.getInstance().core.favoritesApi.removeFavoriteSite('-me-', id));
return Observable.fromPromise(this.alfrescoApiService.favoritesApi.removeFavoriteSite('-me-', id));
});
Observable.forkJoin(batch).subscribe(() => {
@@ -81,7 +81,7 @@ export class NodeFavoriteDirective implements OnChanges {
const notFavorite = this.favorites.filter((node) => !node.entry.isFavorite);
const body: FavoriteBody[] = notFavorite.map((node) => this.createFavoriteBody(node));
Observable.fromPromise(this.alfrescoApiService.getInstance().core.favoritesApi.addFavorite('-me-', <any> body))
Observable.fromPromise(this.alfrescoApiService.favoritesApi.addFavorite('-me-', <any> body))
.subscribe(() => {
notFavorite.map(selected => selected.entry.isFavorite = true);
this.toggle.emit();
@@ -98,7 +98,9 @@ export class NodeFavoriteDirective implements OnChanges {
const result = this.diff(selection, this.favorites);
const batch = this.getProcessBatch(result);
Observable.forkJoin(batch).subscribe((data) => this.favorites.push(...data));
Observable.forkJoin(batch).subscribe((data) => {
this.favorites.push(...data);
});
}
hasFavorites(): boolean {
@@ -118,8 +120,7 @@ export class NodeFavoriteDirective implements OnChanges {
// shared files have nodeId
const id = (<any> selected).entry.nodeId || selected.entry.id;
const promise = this.alfrescoApiService.getInstance()
.core.favoritesApi.getFavorite('-me-', id);
const promise = this.alfrescoApiService.favoritesApi.getFavorite('-me-', id);
return Observable.from(promise)
.map(() => ({

View File

@@ -25,7 +25,9 @@ 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';
@Component({
template: `
<div [adf-restore]="selection"
@@ -50,29 +52,31 @@ describe('NodeRestoreDirective', () => {
let coreApi;
let directiveInstance;
beforeEach(async(() => {
TestBed.configureTestingModule({
imports: [
RouterTestingModule
],
declarations: [
TestComponent
]
})
.compileComponents()
.then(() => {
fixture = TestBed.createComponent(TestComponent);
component = fixture.componentInstance;
element = fixture.debugElement.query(By.directive(NodeRestoreDirective));
directiveInstance = element.injector.get(NodeRestoreDirective);
setupTestBed({
imports: [
CoreModule.forRoot(),
RouterTestingModule
],
declarations: [
TestComponent
],
providers: [
{ provide: AlfrescoApiService, useClass: AlfrescoApiServiceMock }
]
});
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(async(() => {
fixture = TestBed.createComponent(TestComponent);
component = fixture.componentInstance;
element = fixture.debugElement.query(By.directive(NodeRestoreDirective));
directiveInstance = element.injector.get(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(() => {