From bcd0b66c96e626e254a965c347fdddd01630a230 Mon Sep 17 00:00:00 2001 From: MichalKinas <113341662+MichalKinas@users.noreply.github.com> Date: Fri, 28 Apr 2023 16:39:47 +0200 Subject: [PATCH] [ACS-5135] Tree component emit pagination only when top level entries change (#8519) --- .../tree/components/tree.component.spec.ts | 23 +++++++++++-------- .../src/lib/tree/components/tree.component.ts | 2 -- 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/lib/content-services/src/lib/tree/components/tree.component.spec.ts b/lib/content-services/src/lib/tree/components/tree.component.spec.ts index 9141af530d..c2f13302f8 100644 --- a/lib/content-services/src/lib/tree/components/tree.component.spec.ts +++ b/lib/content-services/src/lib/tree/components/tree.component.spec.ts @@ -87,6 +87,18 @@ describe('TreeComponent', () => { expect(refreshSpy).toHaveBeenCalled(); }); + it('should emit pagination when tree is refreshed', (done) => { + spyOn(component.treeService, 'getSubNodes').and.returnValue(of({ + pagination: {skipCount: 0, maxItems: userPreferenceService.paginationSize}, entries: [] + })); + component.paginationChanged.subscribe((pagination) => { + expect(pagination.skipCount).toBe(0); + expect(pagination.maxItems).toBe(userPreferenceService.paginationSize); + done(); + }); + component.refreshTree(); + }); + it('should show a header title showing displayName property value', () => { spyOn(component, 'isEmpty').and.returnValue(false); component.displayName = 'test'; @@ -145,16 +157,6 @@ describe('TreeComponent', () => { expect(nodeIcons[0].nativeElement.innerText).toContain('chevron_left'); }); - it('should emit pagination when nodes are loaded', (done) => { - component.treeService.treeNodes = Array.from(treeNodesMockExpanded); - component.paginationChanged.subscribe((pagination) => { - expect(pagination.skipCount).toBe(0); - expect(pagination.maxItems).toBe(userPreferenceService.paginationSize); - done(); - }); - component.expandCollapseNode(component.treeService.treeNodes[0]); - }); - it('when node has more items to load loadMore node should appear', () => { component.treeService.treeNodes = Array.from(treeNodesMockExpanded); fixture.detectChanges(); @@ -172,6 +174,7 @@ describe('TreeComponent', () => { it('should call correct server method on collapsing node', () => { component.refreshTree(); + component.treeService.treeNodes[0].isLoading = false; fixture.detectChanges(); const collapseSpy = spyOn(component.treeService, 'collapseNode'); spyOn(component.treeService.treeControl, 'isExpanded').and.returnValue(true); diff --git a/lib/content-services/src/lib/tree/components/tree.component.ts b/lib/content-services/src/lib/tree/components/tree.component.ts index 4cc26741fe..bd89e9112b 100644 --- a/lib/content-services/src/lib/tree/components/tree.component.ts +++ b/lib/content-services/src/lib/tree/components/tree.component.ts @@ -208,7 +208,6 @@ export class TreeComponent implements OnInit, OnDestroy { node.isLoading = true; this.treeService.getSubNodes(node.id, 0, this.userPreferenceService.paginationSize).subscribe((response: TreeResponse) => { this.treeService.expandNode(node, response.entries); - this.paginationChanged.emit(response.pagination); node.isLoading = false; if (this.treeNodesSelection.isSelected(node)) { //timeout used to update nodeCheckboxes query list after new nodes are added so they can be selected @@ -233,7 +232,6 @@ export class TreeComponent implements OnInit, OnDestroy { const loadedChildren: number = this.treeService.getChildren(parentNode).length; this.treeService.getSubNodes(parentNode.id, loadedChildren, this.userPreferenceService.paginationSize).subscribe((response: TreeResponse) => { this.treeService.appendNodes(parentNode, response.entries); - this.paginationChanged.emit(response.pagination); node.isLoading = false; if (this.treeNodesSelection.isSelected(parentNode)) { //timeout used to update nodeCheckboxes query list after new nodes are added so they can be selected