mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-07-24 17:32:15 +00:00
[ADF-2310] Error is thrown if isSelectionValid optional property is not defined (#2957)
* [ADF-2310] Error is thrown if isSelectionValid optional property is not defined * [ADF-2310] added unit tests for the change and removed unneeded import * fix tests * [ADF-2310] add missing async * [ADF-2310] add more async function to unit tests
This commit is contained in:
committed by
Eugenio Romano
parent
4513cb0e09
commit
ed9289d6df
@@ -21,7 +21,6 @@ import { By } from '@angular/platform-browser';
|
|||||||
import { MinimalNodeEntryEntity, SiteEntry, SitePaging } from 'alfresco-js-api';
|
import { MinimalNodeEntryEntity, SiteEntry, SitePaging } from 'alfresco-js-api';
|
||||||
import {
|
import {
|
||||||
AlfrescoApiService,
|
AlfrescoApiService,
|
||||||
ContentService,
|
|
||||||
TranslationService,
|
TranslationService,
|
||||||
SearchService,
|
SearchService,
|
||||||
SitesService,
|
SitesService,
|
||||||
@@ -76,10 +75,6 @@ describe('ContentNodeSelectorComponent', () => {
|
|||||||
_observer.next(result);
|
_observer.next(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
function returnAlwaysTrue(entry: MinimalNodeEntryEntity) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
function setupTestbed(plusProviders) {
|
function setupTestbed(plusProviders) {
|
||||||
TestBed.configureTestingModule({
|
TestBed.configureTestingModule({
|
||||||
imports: [
|
imports: [
|
||||||
@@ -95,7 +90,6 @@ describe('ContentNodeSelectorComponent', () => {
|
|||||||
],
|
],
|
||||||
providers: [
|
providers: [
|
||||||
AlfrescoApiService,
|
AlfrescoApiService,
|
||||||
ContentService,
|
|
||||||
SearchService,
|
SearchService,
|
||||||
TranslationService,
|
TranslationService,
|
||||||
DocumentListService,
|
DocumentListService,
|
||||||
@@ -215,9 +209,6 @@ describe('ContentNodeSelectorComponent', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should show the breadcrumb for the selected node when search results are displayed', (done) => {
|
it('should show the breadcrumb for the selected node when search results are displayed', (done) => {
|
||||||
const alfrescoContentService = TestBed.get(ContentService);
|
|
||||||
spyOn(alfrescoContentService, 'hasPermission').and.returnValue(true);
|
|
||||||
|
|
||||||
typeToSearchBox();
|
typeToSearchBox();
|
||||||
|
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
@@ -238,9 +229,6 @@ describe('ContentNodeSelectorComponent', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should NOT show the breadcrumb for the selected node when not on search results list', (done) => {
|
it('should NOT show the breadcrumb for the selected node when not on search results list', (done) => {
|
||||||
const alfrescoContentService = TestBed.get(ContentService);
|
|
||||||
spyOn(alfrescoContentService, 'hasPermission').and.returnValue(true);
|
|
||||||
|
|
||||||
typeToSearchBox();
|
typeToSearchBox();
|
||||||
|
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
@@ -327,6 +315,10 @@ describe('ContentNodeSelectorComponent', () => {
|
|||||||
|
|
||||||
spyOn(documentListService, 'getFolderNode').and.returnValue(Promise.resolve(expectedDefaultFolderNode));
|
spyOn(documentListService, 'getFolderNode').and.returnValue(Promise.resolve(expectedDefaultFolderNode));
|
||||||
spyOn(component.documentList, 'loadFolderNodesByFolderNodeId').and.returnValue(Promise.resolve());
|
spyOn(component.documentList, 'loadFolderNodesByFolderNodeId').and.returnValue(Promise.resolve());
|
||||||
|
|
||||||
|
const sitesService = TestBed.get(SitesService);
|
||||||
|
spyOn(sitesService, 'getSites').and.returnValue(Observable.of({ list: { entries: [] } }));
|
||||||
|
|
||||||
getCorrespondingNodeIdsSpy = spyOn(component.documentList, 'getCorrespondingNodeIds').and
|
getCorrespondingNodeIdsSpy = spyOn(component.documentList, 'getCorrespondingNodeIds').and
|
||||||
.callFake(id => {
|
.callFake(id => {
|
||||||
if (id === '-sites-') {
|
if (id === '-sites-') {
|
||||||
@@ -652,7 +644,7 @@ describe('ContentNodeSelectorComponent', () => {
|
|||||||
}, 300);
|
}, 300);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('button\'s callback should load the next batch of results by calling the search api', () => {
|
it('button\'s callback should load the next batch of results by calling the search api', async(() => {
|
||||||
const skipCount = 8;
|
const skipCount = 8;
|
||||||
component.searchTerm = 'kakarot';
|
component.searchTerm = 'kakarot';
|
||||||
|
|
||||||
@@ -661,7 +653,7 @@ describe('ContentNodeSelectorComponent', () => {
|
|||||||
fixture.whenStable().then(() => {
|
fixture.whenStable().then(() => {
|
||||||
expect(searchSpy).toHaveBeenCalledWith(defaultSearchOptions('kakarot', undefined, skipCount));
|
expect(searchSpy).toHaveBeenCalledWith(defaultSearchOptions('kakarot', undefined, skipCount));
|
||||||
});
|
});
|
||||||
});
|
}));
|
||||||
|
|
||||||
it('should be shown when pagination\'s hasMoreItems is true', () => {
|
it('should be shown when pagination\'s hasMoreItems is true', () => {
|
||||||
component.pagination = {
|
component.pagination = {
|
||||||
@@ -729,72 +721,94 @@ describe('ContentNodeSelectorComponent', () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('Action button for the chosen node', () => {
|
describe('Chosen node', () => {
|
||||||
|
|
||||||
const entry: MinimalNodeEntryEntity = <MinimalNodeEntryEntity> { list: {entries: [{}]}};
|
const entry: MinimalNodeEntryEntity = <MinimalNodeEntryEntity> {};
|
||||||
const nodePage: NodePaging = <NodePaging> {list: {}, pagination: {}};
|
const nodePage: NodePaging = <NodePaging> {list: {}, pagination: {}};
|
||||||
let hasPermission;
|
let hasPermission;
|
||||||
|
|
||||||
|
function returnHasPermission(): boolean {
|
||||||
|
return hasPermission;
|
||||||
|
}
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
const alfrescoContentService = TestBed.get(ContentService);
|
const sitesService = TestBed.get(SitesService);
|
||||||
spyOn(alfrescoContentService, 'hasPermission').and.callFake(() => hasPermission);
|
spyOn(sitesService, 'getSites').and.returnValue(Observable.of({ list: { entries: [] } }));
|
||||||
component.isSelectionValid = returnAlwaysTrue.bind(this);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should become enabled after loading node with the necessary permissions', async(() => {
|
describe('in the case when isSelectionValid is a custom function for checking permissions,', () => {
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
component.isSelectionValid = returnHasPermission;
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should NOT be null after selecting node with the necessary permissions', async(() => {
|
||||||
hasPermission = true;
|
hasPermission = true;
|
||||||
component.documentList.folderNode = entry;
|
component.documentList.folderNode = entry;
|
||||||
|
|
||||||
component.select.subscribe((nodes) => {
|
component.select.subscribe((nodes) => {
|
||||||
expect(nodes).toBeDefined();
|
expect(nodes).toBeDefined();
|
||||||
expect(nodes).not.toBeNull();
|
expect(nodes).not.toBeNull();
|
||||||
|
expect(component.chosenNode).toBe(entry);
|
||||||
});
|
});
|
||||||
|
|
||||||
component.documentList.ready.emit(nodePage);
|
component.documentList.ready.emit(nodePage);
|
||||||
fixture.detectChanges();
|
fixture.detectChanges();
|
||||||
}));
|
}));
|
||||||
|
|
||||||
it('should remain disabled after loading node without the necessary permissions', () => {
|
it('should be null after selecting node without the necessary permissions', async(() => {
|
||||||
hasPermission = false;
|
hasPermission = false;
|
||||||
component.documentList.folderNode = entry;
|
component.documentList.folderNode = entry;
|
||||||
|
|
||||||
component.select.subscribe((nodes) => {
|
component.select.subscribe((nodes) => {
|
||||||
expect(nodes).toBeDefined();
|
expect(nodes).toBeDefined();
|
||||||
expect(nodes).not.toBeNull();
|
expect(nodes).toBeNull();
|
||||||
|
expect(component.chosenNode).toBeNull();
|
||||||
});
|
});
|
||||||
|
|
||||||
component.documentList.ready.emit(nodePage);
|
component.documentList.ready.emit(nodePage);
|
||||||
fixture.detectChanges();
|
fixture.detectChanges();
|
||||||
});
|
}));
|
||||||
|
|
||||||
it('should be enabled when clicking on a node (with the right permissions) in the list (onNodeSelect)', () => {
|
it('should NOT be null after clicking on a node (with the right permissions) in the list (onNodeSelect)', async(() => {
|
||||||
hasPermission = true;
|
hasPermission = true;
|
||||||
|
|
||||||
component.select.subscribe((nodes) => {
|
component.select.subscribe((nodes) => {
|
||||||
expect(nodes).toBeDefined();
|
expect(nodes).toBeDefined();
|
||||||
expect(nodes).not.toBeNull();
|
expect(nodes).not.toBeNull();
|
||||||
|
expect(component.chosenNode).toBe(entry);
|
||||||
});
|
});
|
||||||
|
|
||||||
component.onNodeSelect({ detail: { node: { entry } } });
|
component.onNodeSelect({ detail: { node: { entry } } });
|
||||||
fixture.detectChanges();
|
fixture.detectChanges();
|
||||||
});
|
}));
|
||||||
|
|
||||||
it('should remain disabled when clicking on a node (with the WRONG permissions) in the list (onNodeSelect)', () => {
|
it('should remain null when clicking on a node (with the WRONG permissions) in the list (onNodeSelect)', async(() => {
|
||||||
hasPermission = false;
|
hasPermission = false;
|
||||||
|
|
||||||
component.select.subscribe((nodes) => {
|
component.select.subscribe((nodes) => {
|
||||||
expect(nodes).toBeDefined();
|
expect(nodes).toBeDefined();
|
||||||
expect(nodes).not.toBeNull();
|
expect(nodes).toBeNull();
|
||||||
|
expect(component.chosenNode).toBeNull();
|
||||||
});
|
});
|
||||||
|
|
||||||
component.onNodeSelect({ detail: { node: { entry } } });
|
component.onNodeSelect({ detail: { node: { entry } } });
|
||||||
fixture.detectChanges();
|
fixture.detectChanges();
|
||||||
});
|
}));
|
||||||
|
|
||||||
it('should become disabled when clicking on a node (with the WRONG permissions) after previously selecting a right node', () => {
|
it('should become null when clicking on a node (with the WRONG permissions) after previously selecting a right node', async(() => {
|
||||||
component.select.subscribe((nodes) => {
|
component.select.subscribe((nodes) => {
|
||||||
|
|
||||||
|
if (hasPermission) {
|
||||||
expect(nodes).toBeDefined();
|
expect(nodes).toBeDefined();
|
||||||
expect(nodes).not.toBeNull();
|
expect(nodes).not.toBeNull();
|
||||||
|
expect(component.chosenNode).not.toBeNull();
|
||||||
|
|
||||||
|
} else {
|
||||||
|
expect(nodes).toBeDefined();
|
||||||
|
expect(nodes).toBeNull();
|
||||||
|
expect(component.chosenNode).toBeNull();
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
hasPermission = true;
|
hasPermission = true;
|
||||||
@@ -804,9 +818,9 @@ describe('ContentNodeSelectorComponent', () => {
|
|||||||
hasPermission = false;
|
hasPermission = false;
|
||||||
component.onNodeSelect({ detail: { node: { entry } } });
|
component.onNodeSelect({ detail: { node: { entry } } });
|
||||||
fixture.detectChanges();
|
fixture.detectChanges();
|
||||||
});
|
}));
|
||||||
|
|
||||||
it('should emit null when the chosenNode is reset', () => {
|
it('should be null when the chosenNode is reset', async(() => {
|
||||||
hasPermission = true;
|
hasPermission = true;
|
||||||
component.onNodeSelect({ detail: { node: { entry: <MinimalNodeEntryEntity> {} } } });
|
component.onNodeSelect({ detail: { node: { entry: <MinimalNodeEntryEntity> {} } } });
|
||||||
fixture.detectChanges();
|
fixture.detectChanges();
|
||||||
@@ -814,10 +828,115 @@ describe('ContentNodeSelectorComponent', () => {
|
|||||||
component.select.subscribe((nodes) => {
|
component.select.subscribe((nodes) => {
|
||||||
expect(nodes).toBeDefined();
|
expect(nodes).toBeDefined();
|
||||||
expect(nodes).toBeNull();
|
expect(nodes).toBeNull();
|
||||||
|
expect(component.chosenNode).toBeNull();
|
||||||
});
|
});
|
||||||
|
|
||||||
component.resetChosenNode();
|
component.resetChosenNode();
|
||||||
fixture.detectChanges();
|
fixture.detectChanges();
|
||||||
|
}));
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('in the case when isSelectionValid is null', () => {
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
component.isSelectionValid = null;
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should NOT be null after selecting node because isSelectionValid would be reset to defaultValidation function', async(() => {
|
||||||
|
component.documentList.folderNode = entry;
|
||||||
|
fixture.detectChanges();
|
||||||
|
|
||||||
|
component.select.subscribe((nodes) => {
|
||||||
|
expect(nodes).toBeDefined();
|
||||||
|
expect(nodes).not.toBeNull();
|
||||||
|
expect(component.chosenNode).not.toBeNull();
|
||||||
|
expect(component.isSelectionValid).not.toBeNull();
|
||||||
|
});
|
||||||
|
|
||||||
|
component.documentList.ready.emit(nodePage);
|
||||||
|
fixture.detectChanges();
|
||||||
|
}));
|
||||||
|
|
||||||
|
it('should NOT be null after clicking on a node in the list (onNodeSelect)', async(() => {
|
||||||
|
fixture.detectChanges();
|
||||||
|
component.select.subscribe((nodes) => {
|
||||||
|
expect(nodes).toBeDefined();
|
||||||
|
expect(nodes).not.toBeNull();
|
||||||
|
expect(component.chosenNode).not.toBeNull();
|
||||||
|
expect(component.isSelectionValid).not.toBeNull();
|
||||||
|
});
|
||||||
|
|
||||||
|
component.onNodeSelect({ detail: { node: { entry } } });
|
||||||
|
fixture.detectChanges();
|
||||||
|
}));
|
||||||
|
|
||||||
|
it('should be null when the chosenNode is reset', async(() => {
|
||||||
|
fixture.detectChanges();
|
||||||
|
component.onNodeSelect({ detail: { node: { entry: <MinimalNodeEntryEntity> {} } } });
|
||||||
|
fixture.detectChanges();
|
||||||
|
|
||||||
|
component.select.subscribe((nodes) => {
|
||||||
|
expect(nodes).toBeDefined();
|
||||||
|
expect(nodes).toBeNull();
|
||||||
|
expect(component.chosenNode).toBeNull();
|
||||||
|
expect(component.isSelectionValid).not.toBeNull();
|
||||||
|
});
|
||||||
|
|
||||||
|
component.resetChosenNode();
|
||||||
|
fixture.detectChanges();
|
||||||
|
}));
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('in the case when isSelectionValid is not defined', () => {
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
component.isSelectionValid = undefined;
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should NOT be null after selecting node because isSelectionValid would be the defaultValidation function', async(() => {
|
||||||
|
component.documentList.folderNode = entry;
|
||||||
|
fixture.detectChanges();
|
||||||
|
|
||||||
|
component.select.subscribe((nodes) => {
|
||||||
|
expect(nodes).toBeDefined();
|
||||||
|
expect(nodes).not.toBeNull();
|
||||||
|
expect(component.chosenNode).not.toBeNull();
|
||||||
|
expect(component.isSelectionValid).not.toBeNull();
|
||||||
|
});
|
||||||
|
|
||||||
|
component.documentList.ready.emit(nodePage);
|
||||||
|
fixture.detectChanges();
|
||||||
|
}));
|
||||||
|
|
||||||
|
it('should NOT be null after clicking on a node in the list (onNodeSelect)', async(() => {
|
||||||
|
component.select.subscribe((nodes) => {
|
||||||
|
expect(nodes).toBeDefined();
|
||||||
|
expect(nodes).not.toBeNull();
|
||||||
|
expect(component.chosenNode).not.toBeNull();
|
||||||
|
expect(component.isSelectionValid).not.toBeNull();
|
||||||
|
});
|
||||||
|
fixture.detectChanges();
|
||||||
|
|
||||||
|
component.onNodeSelect({ detail: { node: { entry } } });
|
||||||
|
fixture.detectChanges();
|
||||||
|
}));
|
||||||
|
|
||||||
|
it('should be null when the chosenNode is reset', async(() => {
|
||||||
|
fixture.detectChanges();
|
||||||
|
|
||||||
|
component.onNodeSelect({ detail: { node: { entry: <MinimalNodeEntryEntity> {} } } });
|
||||||
|
fixture.detectChanges();
|
||||||
|
|
||||||
|
component.select.subscribe((nodes) => {
|
||||||
|
expect(nodes).toBeDefined();
|
||||||
|
expect(nodes).toBeNull();
|
||||||
|
expect(component.chosenNode).toBeNull();
|
||||||
|
expect(component.isSelectionValid).not.toBeNull();
|
||||||
|
});
|
||||||
|
|
||||||
|
component.resetChosenNode();
|
||||||
|
fixture.detectChanges();
|
||||||
|
}));
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@@ -128,6 +128,7 @@ export class ContentNodeSelectorPanelComponent implements OnInit {
|
|||||||
this.paginationStrategy = PaginationStrategy.Infinite;
|
this.paginationStrategy = PaginationStrategy.Infinite;
|
||||||
|
|
||||||
this.breadcrumbTransform = this.breadcrumbTransform ? this.breadcrumbTransform : null ;
|
this.breadcrumbTransform = this.breadcrumbTransform ? this.breadcrumbTransform : null ;
|
||||||
|
this.isSelectionValid = this.isSelectionValid ? this.isSelectionValid : defaultValidation;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Reference in New Issue
Block a user