mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-08-07 17:48:54 +00:00
[ACS-7365] Optimise Search providers and unit tests (#9477)
refactor: optimise node selector imports and tests
This commit is contained in:
@@ -20,7 +20,6 @@ import { CoreTestingModule } from '@alfresco/adf-core';
|
||||
import { ContentService } from '../common/services/content.service';
|
||||
import { CheckAllowableOperationDirective } from './check-allowable-operation.directive';
|
||||
import { TestBed } from '@angular/core/testing';
|
||||
import { TranslateModule } from '@ngx-translate/core';
|
||||
import { NodeAllowableOperationSubject } from '../interfaces/node-allowable-operation-subject.interface';
|
||||
|
||||
@Component({
|
||||
@@ -36,10 +35,7 @@ describe('CheckAllowableOperationDirective', () => {
|
||||
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({
|
||||
imports: [
|
||||
TranslateModule.forRoot(),
|
||||
CoreTestingModule
|
||||
]
|
||||
imports: [CoreTestingModule]
|
||||
});
|
||||
changeDetectorMock = { detectChanges: () => {} } as ChangeDetectorRef;
|
||||
});
|
||||
@@ -126,7 +122,6 @@ describe('CheckAllowableOperationDirective', () => {
|
||||
});
|
||||
|
||||
describe('Angular component as subject', () => {
|
||||
|
||||
it('disables decorated component', () => {
|
||||
const contentService = TestBed.inject(ContentService);
|
||||
spyOn(contentService, 'hasAllowableOperations').and.returnValue(false);
|
||||
|
@@ -19,7 +19,6 @@ import { fakeAsync, TestBed, tick } from '@angular/core/testing';
|
||||
import { LibraryMembershipDirective } from './library-membership.directive';
|
||||
import { NO_ERRORS_SCHEMA, SimpleChange } from '@angular/core';
|
||||
import { of, throwError, Subject } from 'rxjs';
|
||||
import { TranslateModule } from '@ngx-translate/core';
|
||||
import { AlfrescoApiService, CoreModule, CoreTestingModule } from '@alfresco/adf-core';
|
||||
import { ContentDirectiveModule } from './content-directive.module';
|
||||
import { SitesService } from '../common/services/sites.service';
|
||||
@@ -38,12 +37,7 @@ describe('LibraryMembershipDirective', () => {
|
||||
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({
|
||||
imports: [
|
||||
TranslateModule.forRoot(),
|
||||
ContentDirectiveModule,
|
||||
CoreModule.forRoot(),
|
||||
CoreTestingModule
|
||||
],
|
||||
imports: [ContentDirectiveModule, CoreModule.forRoot(), CoreTestingModule],
|
||||
schemas: [NO_ERRORS_SCHEMA]
|
||||
});
|
||||
|
||||
@@ -70,7 +64,9 @@ describe('LibraryMembershipDirective', () => {
|
||||
|
||||
describe('markMembershipRequest', () => {
|
||||
beforeEach(() => {
|
||||
getMembershipSpy = spyOn(directive.sitesApi, 'getSiteMembershipRequestForPerson').and.returnValue(Promise.resolve({ entry: requestedMembershipResponse }));
|
||||
getMembershipSpy = spyOn(directive.sitesApi, 'getSiteMembershipRequestForPerson').and.returnValue(
|
||||
Promise.resolve({ entry: requestedMembershipResponse })
|
||||
);
|
||||
});
|
||||
|
||||
it('should not check membership requests if no entry is selected', fakeAsync(() => {
|
||||
@@ -111,8 +107,12 @@ describe('LibraryMembershipDirective', () => {
|
||||
describe('toggleMembershipRequest', () => {
|
||||
beforeEach(() => {
|
||||
mockSupportedVersion = false;
|
||||
getMembershipSpy = spyOn(directive.sitesApi, 'getSiteMembershipRequestForPerson').and.returnValue(Promise.resolve({ entry: requestedMembershipResponse }));
|
||||
addMembershipSpy = spyOn(directive.sitesApi, 'createSiteMembershipRequestForPerson').and.returnValue(Promise.resolve({ entry: requestedMembershipResponse }));
|
||||
getMembershipSpy = spyOn(directive.sitesApi, 'getSiteMembershipRequestForPerson').and.returnValue(
|
||||
Promise.resolve({ entry: requestedMembershipResponse })
|
||||
);
|
||||
addMembershipSpy = spyOn(directive.sitesApi, 'createSiteMembershipRequestForPerson').and.returnValue(
|
||||
Promise.resolve({ entry: requestedMembershipResponse })
|
||||
);
|
||||
deleteMembershipSpy = spyOn(directive.sitesApi, 'deleteSiteMembershipRequestForPerson').and.returnValue(Promise.resolve());
|
||||
});
|
||||
|
||||
|
@@ -20,14 +20,10 @@ import { ComponentFixture, TestBed } from '@angular/core/testing';
|
||||
import { By } from '@angular/platform-browser';
|
||||
import { NodeDeleteDirective } from './node-delete.directive';
|
||||
import { CoreTestingModule } from '@alfresco/adf-core';
|
||||
import { TranslateModule } from '@ngx-translate/core';
|
||||
import { ContentDirectiveModule } from './content-directive.module';
|
||||
|
||||
@Component({
|
||||
template: `
|
||||
<div id="delete-component" [adf-delete]="selection"
|
||||
(delete)="onDelete()">
|
||||
</div>`
|
||||
template: ` <div id="delete-component" [adf-delete]="selection" (delete)="onDelete()"></div>`
|
||||
})
|
||||
class TestComponent {
|
||||
selection = [];
|
||||
@@ -35,16 +31,11 @@ class TestComponent {
|
||||
@ViewChild(NodeDeleteDirective, { static: true })
|
||||
deleteDirective: NodeDeleteDirective;
|
||||
|
||||
onDelete() {
|
||||
}
|
||||
onDelete() {}
|
||||
}
|
||||
|
||||
@Component({
|
||||
template: `
|
||||
<div id="delete-component" [adf-check-allowable-operation]="selection"
|
||||
[adf-delete]="selection"
|
||||
(delete)="onDelete($event)">
|
||||
</div>`
|
||||
template: ` <div id="delete-component" [adf-check-allowable-operation]="selection" [adf-delete]="selection" (delete)="onDelete($event)"></div>`
|
||||
})
|
||||
class TestWithPermissionsComponent {
|
||||
selection = [];
|
||||
@@ -56,13 +47,8 @@ class TestWithPermissionsComponent {
|
||||
}
|
||||
|
||||
@Component({
|
||||
template: `
|
||||
delete permanent
|
||||
<div id="delete-permanent"
|
||||
[adf-delete]="selection"
|
||||
[permanent]="permanent"
|
||||
(delete)="onDelete($event)">
|
||||
</div>`
|
||||
template: ` delete permanent
|
||||
<div id="delete-permanent" [adf-delete]="selection" [permanent]="permanent" (delete)="onDelete($event)"></div>`
|
||||
})
|
||||
class TestDeletePermanentComponent {
|
||||
selection = [];
|
||||
@@ -90,16 +76,8 @@ describe('NodeDeleteDirective', () => {
|
||||
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({
|
||||
imports: [
|
||||
TranslateModule.forRoot(),
|
||||
CoreTestingModule,
|
||||
ContentDirectiveModule
|
||||
],
|
||||
declarations: [
|
||||
TestComponent,
|
||||
TestWithPermissionsComponent,
|
||||
TestDeletePermanentComponent
|
||||
]
|
||||
imports: [CoreTestingModule, ContentDirectiveModule],
|
||||
declarations: [TestComponent, TestWithPermissionsComponent, TestDeletePermanentComponent]
|
||||
});
|
||||
fixture = TestBed.createComponent(TestComponent);
|
||||
fixtureWithPermissions = TestBed.createComponent(TestWithPermissionsComponent);
|
||||
@@ -114,8 +92,9 @@ describe('NodeDeleteDirective', () => {
|
||||
deleteNodeSpy = spyOn(component.deleteDirective.nodesApi, 'deleteNode').and.returnValue(Promise.resolve());
|
||||
|
||||
deleteNodePermanentSpy = spyOn(componentWithPermanentDelete.deleteDirective.nodesApi, 'deleteNode').and.returnValue(Promise.resolve());
|
||||
purgeDeletedNodePermanentSpy = spyOn(componentWithPermanentDelete.deleteDirective.trashcanApi, 'deleteDeletedNode').and.returnValue(Promise.resolve());
|
||||
|
||||
purgeDeletedNodePermanentSpy = spyOn(componentWithPermanentDelete.deleteDirective.trashcanApi, 'deleteDeletedNode').and.returnValue(
|
||||
Promise.resolve()
|
||||
);
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
@@ -126,7 +105,6 @@ describe('NodeDeleteDirective', () => {
|
||||
});
|
||||
|
||||
describe('Delete', () => {
|
||||
|
||||
it('should do nothing if selection is empty', () => {
|
||||
component.selection = [];
|
||||
|
||||
@@ -141,9 +119,7 @@ describe('NodeDeleteDirective', () => {
|
||||
fixture.detectChanges();
|
||||
|
||||
disposableDelete = component.deleteDirective.delete.subscribe((message) => {
|
||||
expect(message).toBe(
|
||||
'CORE.DELETE_NODE.SINGULAR'
|
||||
);
|
||||
expect(message).toBe('CORE.DELETE_NODE.SINGULAR');
|
||||
});
|
||||
|
||||
element.nativeElement.click();
|
||||
@@ -158,9 +134,7 @@ describe('NodeDeleteDirective', () => {
|
||||
fixture.detectChanges();
|
||||
|
||||
disposableDelete = component.deleteDirective.delete.subscribe((message) => {
|
||||
expect(message).toBe(
|
||||
'CORE.DELETE_NODE.ERROR_SINGULAR'
|
||||
);
|
||||
expect(message).toBe('CORE.DELETE_NODE.ERROR_SINGULAR');
|
||||
});
|
||||
|
||||
element.nativeElement.click();
|
||||
@@ -169,16 +143,11 @@ describe('NodeDeleteDirective', () => {
|
||||
});
|
||||
|
||||
it('should notify nodes deletion', async () => {
|
||||
component.selection = [
|
||||
{ entry: { id: '1', name: 'name1' } },
|
||||
{ entry: { id: '2', name: 'name2' } }
|
||||
];
|
||||
component.selection = [{ entry: { id: '1', name: 'name1' } }, { entry: { id: '2', name: 'name2' } }];
|
||||
fixture.detectChanges();
|
||||
|
||||
disposableDelete = component.deleteDirective.delete.subscribe((message) => {
|
||||
expect(message).toBe(
|
||||
'CORE.DELETE_NODE.PLURAL'
|
||||
);
|
||||
expect(message).toBe('CORE.DELETE_NODE.PLURAL');
|
||||
});
|
||||
|
||||
element.nativeElement.click();
|
||||
@@ -189,16 +158,11 @@ describe('NodeDeleteDirective', () => {
|
||||
it('should notify failed nodes deletion', async () => {
|
||||
deleteNodeSpy.and.returnValue(Promise.reject(new Error('error')));
|
||||
|
||||
component.selection = [
|
||||
{ entry: { id: '1', name: 'name1' } },
|
||||
{ entry: { id: '2', name: 'name2' } }
|
||||
];
|
||||
component.selection = [{ entry: { id: '1', name: 'name1' } }, { entry: { id: '2', name: 'name2' } }];
|
||||
fixture.detectChanges();
|
||||
|
||||
disposableDelete = component.deleteDirective.delete.subscribe((message) => {
|
||||
expect(message).toBe(
|
||||
'CORE.DELETE_NODE.ERROR_PLURAL'
|
||||
);
|
||||
expect(message).toBe('CORE.DELETE_NODE.ERROR_PLURAL');
|
||||
});
|
||||
|
||||
element.nativeElement.click();
|
||||
@@ -215,16 +179,11 @@ describe('NodeDeleteDirective', () => {
|
||||
}
|
||||
});
|
||||
|
||||
component.selection = [
|
||||
{ entry: { id: '1', name: 'name1' } },
|
||||
{ entry: { id: '2', name: 'name2' } }
|
||||
];
|
||||
component.selection = [{ entry: { id: '1', name: 'name1' } }, { entry: { id: '2', name: 'name2' } }];
|
||||
fixture.detectChanges();
|
||||
|
||||
disposableDelete = component.deleteDirective.delete.subscribe((message) => {
|
||||
expect(message).toBe(
|
||||
'CORE.DELETE_NODE.PARTIAL_SINGULAR'
|
||||
);
|
||||
expect(message).toBe('CORE.DELETE_NODE.PARTIAL_SINGULAR');
|
||||
});
|
||||
|
||||
element.nativeElement.click();
|
||||
@@ -249,9 +208,7 @@ describe('NodeDeleteDirective', () => {
|
||||
fixture.detectChanges();
|
||||
|
||||
disposableDelete = component.deleteDirective.delete.subscribe((message) => {
|
||||
expect(message).toBe(
|
||||
'CORE.DELETE_NODE.PARTIAL_PLURAL'
|
||||
);
|
||||
expect(message).toBe('CORE.DELETE_NODE.PARTIAL_PLURAL');
|
||||
});
|
||||
|
||||
element.nativeElement.click();
|
||||
@@ -317,13 +274,10 @@ describe('NodeDeleteDirective', () => {
|
||||
});
|
||||
|
||||
describe('Permanent', () => {
|
||||
|
||||
it('should call the api with permanent delete option if permanent directive input is true', () => {
|
||||
fixtureWithPermanentComponent.detectChanges();
|
||||
|
||||
componentWithPermanentDelete.selection = [
|
||||
{ entry: { id: '1', name: 'name1' } }
|
||||
];
|
||||
componentWithPermanentDelete.selection = [{ entry: { id: '1', name: 'name1' } }];
|
||||
|
||||
fixtureWithPermanentComponent.detectChanges();
|
||||
elementWithPermanentDelete.nativeElement.click();
|
||||
@@ -334,9 +288,7 @@ describe('NodeDeleteDirective', () => {
|
||||
it('should call the trashcan api if permanent directive input is true and the file is already in the trashcan ', () => {
|
||||
fixtureWithPermanentComponent.detectChanges();
|
||||
|
||||
componentWithPermanentDelete.selection = [
|
||||
{ entry: { id: '1', name: 'name1', archivedAt: 'archived' } }
|
||||
];
|
||||
componentWithPermanentDelete.selection = [{ entry: { id: '1', name: 'name1', archivedAt: 'archived' } }];
|
||||
|
||||
fixtureWithPermanentComponent.detectChanges();
|
||||
elementWithPermanentDelete.nativeElement.click();
|
||||
|
@@ -21,7 +21,6 @@ import { MatDialog } from '@angular/material/dialog';
|
||||
import { Component, DebugElement, ViewChild } from '@angular/core';
|
||||
import { AlfrescoApiService, CoreTestingModule } from '@alfresco/adf-core';
|
||||
import { NodeDownloadDirective } from './node-download.directive';
|
||||
import { TranslateModule } from '@ngx-translate/core';
|
||||
import { ContentDirectiveModule } from '@alfresco/adf-content-services';
|
||||
|
||||
@Component({
|
||||
@@ -53,14 +52,8 @@ describe('NodeDownloadDirective', () => {
|
||||
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({
|
||||
imports: [
|
||||
ContentDirectiveModule,
|
||||
TranslateModule.forRoot(),
|
||||
CoreTestingModule
|
||||
],
|
||||
declarations: [
|
||||
TestComponent
|
||||
]
|
||||
imports: [ContentDirectiveModule, CoreTestingModule],
|
||||
declarations: [TestComponent]
|
||||
});
|
||||
fixture = TestBed.createComponent(TestComponent);
|
||||
component = fixture.componentInstance;
|
||||
@@ -108,7 +101,7 @@ describe('NodeDownloadDirective', () => {
|
||||
}
|
||||
};
|
||||
spyOn(contentService, 'getVersionContentUrl');
|
||||
const node = {entry: {id: 'node-id', isFile: true}};
|
||||
const node = { entry: { id: 'node-id', isFile: true } };
|
||||
component.selection = [node];
|
||||
|
||||
fixture.detectChanges();
|
||||
@@ -136,7 +129,7 @@ describe('NodeDownloadDirective', () => {
|
||||
fixture.detectChanges();
|
||||
element.triggerEventHandler('click', null);
|
||||
|
||||
expect(dialogSpy.calls.argsFor(0)[1].data).toEqual({ nodeIds: [ 'node-1', 'node-2' ] });
|
||||
expect(dialogSpy.calls.argsFor(0)[1].data).toEqual({ nodeIds: ['node-1', 'node-2'] });
|
||||
});
|
||||
|
||||
it('should download selected shared files nodes as zip', () => {
|
||||
@@ -147,7 +140,7 @@ describe('NodeDownloadDirective', () => {
|
||||
fixture.detectChanges();
|
||||
element.triggerEventHandler('click', null);
|
||||
|
||||
expect(dialogSpy.calls.argsFor(0)[1].data).toEqual({ nodeIds: [ 'shared-node-1', 'shared-node-2' ] });
|
||||
expect(dialogSpy.calls.argsFor(0)[1].data).toEqual({ nodeIds: ['shared-node-1', 'shared-node-2'] });
|
||||
});
|
||||
|
||||
it('should download selected folder node as zip', () => {
|
||||
@@ -157,7 +150,7 @@ describe('NodeDownloadDirective', () => {
|
||||
fixture.detectChanges();
|
||||
element.triggerEventHandler('click', null);
|
||||
|
||||
expect(dialogSpy.calls.argsFor(0)[1].data).toEqual({ nodeIds: [ 'node-id' ] });
|
||||
expect(dialogSpy.calls.argsFor(0)[1].data).toEqual({ nodeIds: ['node-id'] });
|
||||
});
|
||||
|
||||
it('should create link element to download file node', () => {
|
||||
|
@@ -18,23 +18,18 @@
|
||||
import { SimpleChange } from '@angular/core';
|
||||
import { fakeAsync, TestBed, tick } from '@angular/core/testing';
|
||||
import { NodeFavoriteDirective } from './node-favorite.directive';
|
||||
import { TranslateModule } from '@ngx-translate/core';
|
||||
import { AlfrescoApiService, CoreTestingModule } from '@alfresco/adf-core';
|
||||
|
||||
describe('NodeFavoriteDirective', () => {
|
||||
|
||||
let directive: NodeFavoriteDirective;
|
||||
let alfrescoApiService: AlfrescoApiService;
|
||||
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({
|
||||
imports: [
|
||||
TranslateModule.forRoot(),
|
||||
CoreTestingModule
|
||||
]
|
||||
imports: [CoreTestingModule]
|
||||
});
|
||||
alfrescoApiService = TestBed.inject(AlfrescoApiService);
|
||||
directive = new NodeFavoriteDirective( alfrescoApiService);
|
||||
directive = new NodeFavoriteDirective(alfrescoApiService);
|
||||
});
|
||||
|
||||
describe('selection input change event', () => {
|
||||
@@ -42,7 +37,7 @@ describe('NodeFavoriteDirective', () => {
|
||||
spyOn(directive, 'markFavoritesNodes');
|
||||
|
||||
const change = new SimpleChange(null, [], true);
|
||||
directive.ngOnChanges({selection: change});
|
||||
directive.ngOnChanges({ selection: change });
|
||||
|
||||
expect(directive.markFavoritesNodes).not.toHaveBeenCalledWith();
|
||||
});
|
||||
@@ -53,17 +48,14 @@ describe('NodeFavoriteDirective', () => {
|
||||
let selection = [{ entry: { id: '1', name: 'name1' } }];
|
||||
|
||||
let change = new SimpleChange(null, selection, true);
|
||||
directive.ngOnChanges({selection: change});
|
||||
directive.ngOnChanges({ selection: change });
|
||||
|
||||
expect(directive.markFavoritesNodes).toHaveBeenCalledWith(selection);
|
||||
|
||||
selection = [
|
||||
{ entry: { id: '1', name: 'name1' } },
|
||||
{ entry: { id: '2', name: 'name2' } }
|
||||
];
|
||||
selection = [{ entry: { id: '1', name: 'name1' } }, { entry: { id: '2', name: 'name2' } }];
|
||||
|
||||
change = new SimpleChange(null, selection, true);
|
||||
directive.ngOnChanges({selection: change});
|
||||
directive.ngOnChanges({ selection: change });
|
||||
|
||||
expect(directive.markFavoritesNodes).toHaveBeenCalledWith(selection);
|
||||
});
|
||||
@@ -71,18 +63,16 @@ describe('NodeFavoriteDirective', () => {
|
||||
it('should reset favorites if selection is empty', fakeAsync(() => {
|
||||
spyOn(directive.favoritesApi, 'getFavorite').and.returnValue(Promise.resolve(null));
|
||||
|
||||
const selection = [
|
||||
{ entry: { id: '1', name: 'name1' } }
|
||||
];
|
||||
const selection = [{ entry: { id: '1', name: 'name1' } }];
|
||||
|
||||
let change = new SimpleChange(null, selection, true);
|
||||
directive.ngOnChanges({selection: change});
|
||||
directive.ngOnChanges({ selection: change });
|
||||
tick();
|
||||
|
||||
expect(directive.hasFavorites()).toBe(true);
|
||||
|
||||
change = new SimpleChange(null, [], true);
|
||||
directive.ngOnChanges({selection: change});
|
||||
directive.ngOnChanges({ selection: change });
|
||||
tick();
|
||||
|
||||
expect(directive.hasFavorites()).toBe(false);
|
||||
@@ -97,26 +87,20 @@ describe('NodeFavoriteDirective', () => {
|
||||
});
|
||||
|
||||
it('should check each selected node if it is a favorite', fakeAsync(() => {
|
||||
const selection = [
|
||||
{ entry: { id: '1', name: 'name1' } },
|
||||
{ entry: { id: '2', name: 'name2' } }
|
||||
];
|
||||
const selection = [{ entry: { id: '1', name: 'name1' } }, { entry: { id: '2', name: 'name2' } }];
|
||||
|
||||
const change = new SimpleChange(null, selection, true);
|
||||
directive.ngOnChanges({selection: change});
|
||||
directive.ngOnChanges({ selection: change });
|
||||
|
||||
tick();
|
||||
expect(favoritesApiSpy.calls.count()).toBe(2);
|
||||
}));
|
||||
|
||||
it('should not check processed node when another is unselected', fakeAsync(() => {
|
||||
let selection = [
|
||||
{ entry: { id: '1', name: 'name1' } },
|
||||
{ entry: { id: '2', name: 'name2' } }
|
||||
];
|
||||
let selection = [{ entry: { id: '1', name: 'name1' } }, { entry: { id: '2', name: 'name2' } }];
|
||||
|
||||
let change = new SimpleChange(null, selection, true);
|
||||
directive.ngOnChanges({selection: change});
|
||||
directive.ngOnChanges({ selection: change });
|
||||
|
||||
tick();
|
||||
expect(directive.favorites.length).toBe(2);
|
||||
@@ -124,12 +108,10 @@ describe('NodeFavoriteDirective', () => {
|
||||
|
||||
favoritesApiSpy.calls.reset();
|
||||
|
||||
selection = [
|
||||
{ entry: { id: '2', name: 'name2' } }
|
||||
];
|
||||
selection = [{ entry: { id: '2', name: 'name2' } }];
|
||||
|
||||
change = new SimpleChange(null, selection, true);
|
||||
directive.ngOnChanges({selection: change});
|
||||
directive.ngOnChanges({ selection: change });
|
||||
|
||||
tick();
|
||||
expect(directive.favorites.length).toBe(1);
|
||||
@@ -137,13 +119,10 @@ describe('NodeFavoriteDirective', () => {
|
||||
}));
|
||||
|
||||
it('should not check processed nodes when another is selected', fakeAsync(() => {
|
||||
let selection = [
|
||||
{ entry: { id: '1', name: 'name1' } },
|
||||
{ entry: { id: '2', name: 'name2' } }
|
||||
];
|
||||
let selection = [{ entry: { id: '1', name: 'name1' } }, { entry: { id: '2', name: 'name2' } }];
|
||||
|
||||
let change = new SimpleChange(null, selection, true);
|
||||
directive.ngOnChanges({selection: change});
|
||||
directive.ngOnChanges({ selection: change });
|
||||
|
||||
tick();
|
||||
|
||||
@@ -152,14 +131,10 @@ describe('NodeFavoriteDirective', () => {
|
||||
|
||||
favoritesApiSpy.calls.reset();
|
||||
|
||||
selection = [
|
||||
{ entry: { id: '1', name: 'name1' } },
|
||||
{ entry: { id: '2', name: 'name2' } },
|
||||
{ entry: { id: '3', name: 'name3' } }
|
||||
];
|
||||
selection = [{ entry: { id: '1', name: 'name1' } }, { entry: { id: '2', name: 'name2' } }, { entry: { id: '3', name: 'name3' } }];
|
||||
|
||||
change = new SimpleChange(null, selection, true);
|
||||
directive.ngOnChanges({selection: change});
|
||||
directive.ngOnChanges({ selection: change });
|
||||
tick();
|
||||
|
||||
expect(directive.favorites.length).toBe(3);
|
||||
@@ -183,7 +158,7 @@ describe('NodeFavoriteDirective', () => {
|
||||
|
||||
it('should not perform action if favorites collection is empty', fakeAsync(() => {
|
||||
const change = new SimpleChange(null, [], true);
|
||||
directive.ngOnChanges({selection: change});
|
||||
directive.ngOnChanges({ selection: change });
|
||||
tick();
|
||||
|
||||
directive.toggleFavorite();
|
||||
@@ -225,10 +200,7 @@ describe('NodeFavoriteDirective', () => {
|
||||
it('should call removeFavoriteSite() if all are favorites', () => {
|
||||
removeFavoriteSpy.and.returnValue(Promise.resolve());
|
||||
|
||||
directive.favorites = [
|
||||
{ entry: { id: '1', name: 'name1', isFavorite: true } },
|
||||
{ entry: { id: '2', name: 'name2', isFavorite: true } }
|
||||
];
|
||||
directive.favorites = [{ entry: { id: '1', name: 'name1', isFavorite: true } }, { entry: { id: '2', name: 'name2', isFavorite: true } }];
|
||||
|
||||
directive.toggleFavorite();
|
||||
|
||||
@@ -239,9 +211,7 @@ describe('NodeFavoriteDirective', () => {
|
||||
removeFavoriteSpy.and.returnValue(Promise.resolve());
|
||||
spyOn(directive.toggle, 'emit');
|
||||
|
||||
directive.favorites = [
|
||||
{ entry: { id: '1', name: 'name1', isFavorite: true } }
|
||||
];
|
||||
directive.favorites = [{ entry: { id: '1', name: 'name1', isFavorite: true } }];
|
||||
|
||||
directive.toggleFavorite();
|
||||
tick();
|
||||
@@ -253,9 +223,7 @@ describe('NodeFavoriteDirective', () => {
|
||||
addFavoriteSpy.and.returnValue(Promise.resolve());
|
||||
spyOn(directive.toggle, 'emit');
|
||||
|
||||
directive.favorites = [
|
||||
{ entry: { id: '1', name: 'name1', isFavorite: false } }
|
||||
];
|
||||
directive.favorites = [{ entry: { id: '1', name: 'name1', isFavorite: false } }];
|
||||
|
||||
directive.toggleFavorite();
|
||||
tick();
|
||||
@@ -268,9 +236,7 @@ describe('NodeFavoriteDirective', () => {
|
||||
removeFavoriteSpy.and.returnValue(Promise.reject(error));
|
||||
spyOn(directive.error, 'emit');
|
||||
|
||||
directive.favorites = [
|
||||
{ entry: { id: '1', name: 'name1', isFavorite: true } }
|
||||
];
|
||||
directive.favorites = [{ entry: { id: '1', name: 'name1', isFavorite: true } }];
|
||||
|
||||
directive.toggleFavorite();
|
||||
tick();
|
||||
@@ -283,9 +249,7 @@ describe('NodeFavoriteDirective', () => {
|
||||
addFavoriteSpy.and.returnValue(Promise.reject(error));
|
||||
spyOn(directive.error, 'emit');
|
||||
|
||||
directive.favorites = [
|
||||
{ entry: { id: '1', name: 'name1', isFavorite: false } }
|
||||
];
|
||||
directive.favorites = [{ entry: { id: '1', name: 'name1', isFavorite: false } }];
|
||||
|
||||
directive.toggleFavorite();
|
||||
tick();
|
||||
@@ -296,9 +260,7 @@ describe('NodeFavoriteDirective', () => {
|
||||
it('should set isFavorites items to false', fakeAsync(() => {
|
||||
removeFavoriteSpy.and.returnValue(Promise.resolve());
|
||||
|
||||
directive.favorites = [
|
||||
{ entry: { id: '1', name: 'name1', isFavorite: true } }
|
||||
];
|
||||
directive.favorites = [{ entry: { id: '1', name: 'name1', isFavorite: true } }];
|
||||
|
||||
directive.toggleFavorite();
|
||||
tick();
|
||||
@@ -309,9 +271,7 @@ describe('NodeFavoriteDirective', () => {
|
||||
it('should set isFavorites items to true', fakeAsync(() => {
|
||||
addFavoriteSpy.and.returnValue(Promise.resolve());
|
||||
|
||||
directive.favorites = [
|
||||
{ entry: { id: '1', name: 'name1', isFavorite: false } }
|
||||
];
|
||||
directive.favorites = [{ entry: { id: '1', name: 'name1', isFavorite: false } }];
|
||||
|
||||
directive.toggleFavorite();
|
||||
tick();
|
||||
@@ -321,16 +281,13 @@ describe('NodeFavoriteDirective', () => {
|
||||
});
|
||||
|
||||
describe('getFavorite()', () => {
|
||||
|
||||
it('should not hit server when using 6.x api', fakeAsync(() => {
|
||||
spyOn(directive.favoritesApi, 'getFavorite').and.callThrough();
|
||||
|
||||
const selection = [
|
||||
{ entry: { id: '1', name: 'name1', isFavorite: true } }
|
||||
];
|
||||
const selection = [{ entry: { id: '1', name: 'name1', isFavorite: true } }];
|
||||
|
||||
const change = new SimpleChange(null, selection, true);
|
||||
directive.ngOnChanges({selection: change});
|
||||
directive.ngOnChanges({ selection: change });
|
||||
tick();
|
||||
|
||||
expect(directive.favorites[0].entry.isFavorite).toBe(true);
|
||||
@@ -340,12 +297,10 @@ describe('NodeFavoriteDirective', () => {
|
||||
it('should process node as favorite', fakeAsync(() => {
|
||||
spyOn(directive.favoritesApi, 'getFavorite').and.returnValue(Promise.resolve(null));
|
||||
|
||||
const selection = [
|
||||
{ entry: { id: '1', name: 'name1' } }
|
||||
];
|
||||
const selection = [{ entry: { id: '1', name: 'name1' } }];
|
||||
|
||||
const change = new SimpleChange(null, selection, true);
|
||||
directive.ngOnChanges({selection: change});
|
||||
directive.ngOnChanges({ selection: change });
|
||||
tick();
|
||||
|
||||
expect(directive.favorites[0].entry.isFavorite).toBe(true);
|
||||
@@ -354,12 +309,10 @@ describe('NodeFavoriteDirective', () => {
|
||||
it('should not process node as favorite', fakeAsync(() => {
|
||||
spyOn(directive.favoritesApi, 'getFavorite').and.returnValue(Promise.reject(new Error('error')));
|
||||
|
||||
const selection = [
|
||||
{ entry: { id: '1', name: 'name1' } }
|
||||
];
|
||||
const selection = [{ entry: { id: '1', name: 'name1' } }];
|
||||
|
||||
const change = new SimpleChange(null, selection, true);
|
||||
directive.ngOnChanges({selection: change});
|
||||
directive.ngOnChanges({ selection: change });
|
||||
tick();
|
||||
|
||||
expect(directive.favorites[0].entry.isFavorite).toBe(false);
|
||||
@@ -376,10 +329,7 @@ describe('NodeFavoriteDirective', () => {
|
||||
});
|
||||
|
||||
it('should return false when some are not favorite', () => {
|
||||
directive.favorites = [
|
||||
{ entry: { id: '1', name: 'name1', isFavorite: true } },
|
||||
{ entry: { id: '2', name: 'name2', isFavorite: false } }
|
||||
];
|
||||
directive.favorites = [{ entry: { id: '1', name: 'name1', isFavorite: true } }, { entry: { id: '2', name: 'name2', isFavorite: false } }];
|
||||
|
||||
const hasFavorites = directive.hasFavorites();
|
||||
|
||||
@@ -387,10 +337,7 @@ describe('NodeFavoriteDirective', () => {
|
||||
});
|
||||
|
||||
it('return true when all are favorite', () => {
|
||||
directive.favorites = [
|
||||
{ entry: { id: '1', name: 'name1', isFavorite: true } },
|
||||
{ entry: { id: '2', name: 'name2', isFavorite: true } }
|
||||
];
|
||||
directive.favorites = [{ entry: { id: '1', name: 'name1', isFavorite: true } }, { entry: { id: '2', name: 'name2', isFavorite: true } }];
|
||||
|
||||
const hasFavorites = directive.hasFavorites();
|
||||
|
||||
|
@@ -22,7 +22,6 @@ import { NodeLockDirective } from './node-lock.directive';
|
||||
import { Node } from '@alfresco/js-api';
|
||||
import { ContentNodeDialogService } from '../content-node-selector/content-node-dialog.service';
|
||||
import { ContentTestingModule } from '../testing/content.testing.module';
|
||||
import { TranslateModule } from '@ngx-translate/core';
|
||||
|
||||
const fakeNode = {
|
||||
id: 'fake',
|
||||
@@ -45,13 +44,8 @@ describe('NodeLock Directive', () => {
|
||||
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({
|
||||
imports: [
|
||||
TranslateModule.forRoot(),
|
||||
ContentTestingModule
|
||||
],
|
||||
declarations: [
|
||||
TestComponent
|
||||
]
|
||||
imports: [ContentTestingModule],
|
||||
declarations: [TestComponent]
|
||||
});
|
||||
fixture = TestBed.createComponent(TestComponent);
|
||||
component = fixture.componentInstance;
|
||||
|
@@ -19,15 +19,11 @@ import { Component, DebugElement } from '@angular/core';
|
||||
import { ComponentFixture, TestBed } from '@angular/core/testing';
|
||||
import { By } from '@angular/platform-browser';
|
||||
import { NodeRestoreDirective } from './node-restore.directive';
|
||||
import { TranslateModule } from '@ngx-translate/core';
|
||||
import { TranslationService, CoreTestingModule } from '@alfresco/adf-core';
|
||||
import { ContentDirectiveModule } from './content-directive.module';
|
||||
|
||||
@Component({
|
||||
template: `
|
||||
<div [adf-restore]="selection"
|
||||
(restore)="doneSpy()">
|
||||
</div>`
|
||||
template: ` <div [adf-restore]="selection" (restore)="doneSpy()"></div>`
|
||||
})
|
||||
class TestComponent {
|
||||
selection = [];
|
||||
@@ -46,14 +42,8 @@ describe('NodeRestoreDirective', () => {
|
||||
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({
|
||||
imports: [
|
||||
TranslateModule.forRoot(),
|
||||
CoreTestingModule,
|
||||
ContentDirectiveModule
|
||||
],
|
||||
declarations: [
|
||||
TestComponent
|
||||
]
|
||||
imports: [CoreTestingModule, ContentDirectiveModule],
|
||||
declarations: [TestComponent]
|
||||
});
|
||||
fixture = TestBed.createComponent(TestComponent);
|
||||
component = fixture.componentInstance;
|
||||
@@ -63,9 +53,11 @@ describe('NodeRestoreDirective', () => {
|
||||
trashcanApi = directiveInstance['trashcanApi'];
|
||||
|
||||
restoreNodeSpy = spyOn(trashcanApi, 'restoreDeletedNode').and.returnValue(Promise.resolve());
|
||||
spyOn(trashcanApi, 'listDeletedNodes').and.returnValue(Promise.resolve({
|
||||
list: { entries: [] }
|
||||
}));
|
||||
spyOn(trashcanApi, 'listDeletedNodes').and.returnValue(
|
||||
Promise.resolve({
|
||||
list: { entries: [] }
|
||||
})
|
||||
);
|
||||
|
||||
translationService = TestBed.inject(TranslationService);
|
||||
spyOn(translationService, 'instant').and.callFake((key) => key);
|
||||
@@ -146,7 +138,6 @@ describe('NodeRestoreDirective', () => {
|
||||
});
|
||||
|
||||
describe('notification', () => {
|
||||
|
||||
it('should notify on multiple fails', (done) => {
|
||||
const error = { message: '{ "error": {} }' };
|
||||
|
||||
@@ -184,9 +175,7 @@ describe('NodeRestoreDirective', () => {
|
||||
|
||||
restoreNodeSpy.and.returnValue(Promise.reject(error));
|
||||
|
||||
component.selection = [
|
||||
{ entry: { id: '1', name: 'name1', path: ['somewhere-over-the-rainbow'] } }
|
||||
];
|
||||
component.selection = [{ entry: { id: '1', name: 'name1', path: ['somewhere-over-the-rainbow'] } }];
|
||||
|
||||
fixture.detectChanges();
|
||||
element.triggerEventHandler('click', null);
|
||||
@@ -203,9 +192,7 @@ describe('NodeRestoreDirective', () => {
|
||||
done();
|
||||
});
|
||||
|
||||
component.selection = [
|
||||
{ entry: { id: '1', name: 'name1', path: ['somewhere-over-the-rainbow'] } }
|
||||
];
|
||||
component.selection = [{ entry: { id: '1', name: 'name1', path: ['somewhere-over-the-rainbow'] } }];
|
||||
|
||||
fixture.detectChanges();
|
||||
element.triggerEventHandler('click', null);
|
||||
@@ -221,16 +208,13 @@ describe('NodeRestoreDirective', () => {
|
||||
done();
|
||||
});
|
||||
|
||||
component.selection = [
|
||||
{ entry: { id: '1', name: 'name1', path: ['somewhere-over-the-rainbow'] } }
|
||||
];
|
||||
component.selection = [{ entry: { id: '1', name: 'name1', path: ['somewhere-over-the-rainbow'] } }];
|
||||
|
||||
fixture.detectChanges();
|
||||
element.triggerEventHandler('click', null);
|
||||
});
|
||||
|
||||
it('should notify success when restore multiple nodes', (done) => {
|
||||
|
||||
directiveInstance.restore.subscribe((event: any) => {
|
||||
expect(event.message).toEqual('CORE.RESTORE_NODE.PLURAL');
|
||||
|
||||
@@ -246,7 +230,6 @@ describe('NodeRestoreDirective', () => {
|
||||
|
||||
fixture.detectChanges();
|
||||
element.triggerEventHandler('click', null);
|
||||
|
||||
});
|
||||
|
||||
it('should notify success on restore selected node', (done) => {
|
||||
@@ -256,13 +239,10 @@ describe('NodeRestoreDirective', () => {
|
||||
done();
|
||||
});
|
||||
|
||||
component.selection = [
|
||||
{ entry: { id: '1', name: 'name1', path: ['somewhere-over-the-rainbow'] } }
|
||||
];
|
||||
component.selection = [{ entry: { id: '1', name: 'name1', path: ['somewhere-over-the-rainbow'] } }];
|
||||
|
||||
fixture.detectChanges();
|
||||
element.triggerEventHandler('click', null);
|
||||
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
Reference in New Issue
Block a user