[ACS-5135] Tree component emit pagination only when top level entries change (#8519)

This commit is contained in:
MichalKinas 2023-04-28 16:39:47 +02:00 committed by GitHub
parent 81fea0fe40
commit bcd0b66c96
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 12 deletions

View File

@ -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);

View File

@ -208,7 +208,6 @@ export class TreeComponent<T extends TreeNode> implements OnInit, OnDestroy {
node.isLoading = true;
this.treeService.getSubNodes(node.id, 0, this.userPreferenceService.paginationSize).subscribe((response: TreeResponse<T>) => {
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<T extends TreeNode> implements OnInit, OnDestroy {
const loadedChildren: number = this.treeService.getChildren(parentNode).length;
this.treeService.getSubNodes(parentNode.id, loadedChildren, this.userPreferenceService.paginationSize).subscribe((response: TreeResponse<T>) => {
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