Skip to content

Commit b402c4c

Browse files
FrancescoMolinaroatarix83
authored andcommitted
Merged in task/main-cris/DSC-2336 (pull request DSpace#3157)
Task/main cris/DSC-2336 Approved-by: Giuseppe Digilio
2 parents 6a01aa2 + 368aa84 commit b402c4c

2 files changed

Lines changed: 23 additions & 0 deletions

File tree

src/app/shared/form/vocabulary-treeview/vocabulary-treeview.service.spec.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,25 @@ describe('VocabularyTreeviewService test suite', () => {
288288
expect(serviceAsAny.dataChange.value).toEqual(treeNodeListWithChildren);
289289
});
290290

291+
it('should not add more children if already present and is loadAll is true and onlyFirstTime is true', () => {
292+
pageInfo = Object.assign(new PageInfo(), {
293+
elementsPerPage: 1,
294+
totalElements: 2,
295+
totalPages: 2,
296+
currentPage: 2,
297+
});
298+
spyOn(serviceAsAny, 'getChildrenNodesByParent').and.returnValue(hot('a', {
299+
a: buildPaginatedList(pageInfo, []),
300+
}));
301+
302+
serviceAsAny.dataChange.next(treeNodeListWithLoadMore);
303+
serviceAsAny.nodeMap = nodeMapWithChildren;
304+
scheduler.schedule(() => service.loadMore(item, [], true, true));
305+
scheduler.flush();
306+
307+
expect(serviceAsAny.getChildrenNodesByParent).not.toHaveBeenCalled();
308+
});
309+
291310
it('should add loadMore node properly', () => {
292311
pageInfo = Object.assign(new PageInfo(), {
293312
elementsPerPage: 1,

src/app/shared/form/vocabulary-treeview/vocabulary-treeview.service.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,10 @@ export class VocabularyTreeviewService {
167167
}
168168
const parent: TreeviewNode = this.nodeMap.get(item.otherInformation.id)!;
169169
const children = this.nodeMap.get(item.otherInformation.id)!.children || [];
170+
// If there are children and is invoked with loadAll true we skip the call as it means the node has loaded already all the children
171+
if (children.length && loadAll && onlyFirstTime) {
172+
return;
173+
}
170174
this.getChildrenNodesByParent(item.otherInformation.id, parent.pageInfo, (loadAll && selectedItems.length > 0)).subscribe((list: PaginatedList<VocabularyEntryDetail>) => {
171175
if (onlyFirstTime && parent.children!.length > 0 && !loadAll) {
172176
return;

0 commit comments

Comments
 (0)