From f3ada4ef8589b9f14b673ca3296dcebd8ec6dc5b Mon Sep 17 00:00:00 2001 From: Sushmitha V <58967843+Sushmitha100796@users.noreply.github.com> Date: Fri, 14 May 2021 21:47:41 +0530 Subject: [PATCH] =?UTF-8?q?[ACA-4409]=20Resolved=20-=20More=20button=20is?= =?UTF-8?q?=20displayed=20on=20Destination=20Picker=20=E2=80=A6=20(#7018)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * [ACA-4409] Resolved - More button is displayed on Destination Picker on a folder even if its files are not displayed * [ACA-4409] Updated param names * [ACA-4409] Refactored the changes * Removed fit and fdescribe * Resolved lint error --- ...content-node-selector-panel.component.html | 2 +- ...tent-node-selector-panel.component.spec.ts | 70 +++++++++++++++++-- .../content-node-selector-panel.component.ts | 12 +++- 3 files changed, 76 insertions(+), 8 deletions(-) diff --git a/lib/content-services/src/lib/content-node-selector/content-node-selector-panel.component.html b/lib/content-services/src/lib/content-node-selector/content-node-selector-panel.component.html index 621b208cd6..a417ee5ce7 100644 --- a/lib/content-services/src/lib/content-node-selector/content-node-selector-panel.component.html +++ b/lib/content-services/src/lib/content-node-selector/content-node-selector-panel.component.html @@ -84,7 +84,7 @@ sortingMode="server" [where]="where" (folderChange)="onFolderChange($event)" - (ready)="onFolderLoaded()" + (ready)="onFolderLoaded($event)" (nodeSelected)="onCurrentSelection($event)" data-automation-id="content-node-selector-document-list"> diff --git a/lib/content-services/src/lib/content-node-selector/content-node-selector-panel.component.spec.ts b/lib/content-services/src/lib/content-node-selector/content-node-selector-panel.component.spec.ts index e9b579a0d0..032fc91d2e 100644 --- a/lib/content-services/src/lib/content-node-selector/content-node-selector-panel.component.spec.ts +++ b/lib/content-services/src/lib/content-node-selector/content-node-selector-panel.component.spec.ts @@ -18,8 +18,8 @@ import { CUSTOM_ELEMENTS_SCHEMA } from '@angular/core'; import { ComponentFixture, fakeAsync, TestBed, tick } from '@angular/core/testing'; import { By } from '@angular/platform-browser'; -import { Node, NodeEntry, NodePaging, RequestScope, ResultSetPaging, SiteEntry, SitePaging } from '@alfresco/js-api'; -import { AppConfigService, FileModel, FileUploadStatus, NodesApiService, setupTestBed, SitesService, UploadService, FileUploadCompleteEvent } from '@alfresco/adf-core'; +import { Node, NodeEntry, NodePaging, RequestScope, ResultSetPaging, SiteEntry, SitePaging, UserInfo } from '@alfresco/js-api'; +import { AppConfigService, FileModel, FileUploadStatus, NodesApiService, setupTestBed, SitesService, UploadService, FileUploadCompleteEvent, DataRow, ThumbnailService, ContentService, DataColumn } from '@alfresco/adf-core'; import { of, throwError } from 'rxjs'; import { DropdownBreadcrumbComponent } from '../breadcrumb'; import { ContentNodeSelectorPanelComponent } from './content-node-selector-panel.component'; @@ -28,7 +28,7 @@ import { DocumentListService } from '../document-list/services/document-list.ser import { DocumentListComponent } from '../document-list/components/document-list.component'; import { DropdownSitesComponent } from '../site-dropdown/sites-dropdown.component'; import { CustomResourcesService } from '../document-list/services/custom-resources.service'; -import { NodeEntryEvent, ShareDataRow } from '../document-list'; +import { NodeEntryEvent, ShareDataRow, ShareDataTableAdapter } from '../document-list'; import { TranslateModule } from '@ngx-translate/core'; import { SearchQueryBuilderService } from '../search'; import { mockQueryBody } from '../mock/search-query.mock'; @@ -66,6 +66,8 @@ describe('ContentNodeSelectorPanelComponent', () => { let searchQueryBuilderService: SearchQueryBuilderService; let contentNodeSelectorPanelService: ContentNodeSelectorPanelService; let uploadService: UploadService; + let thumbnailService: ThumbnailService; + let contentService: ContentService; function typeToSearchBox(searchTerm = 'string-to-search') { const searchInput = fixture.debugElement.query(By.css('[data-automation-id="content-node-selector-search-input"]')); @@ -97,6 +99,9 @@ describe('ContentNodeSelectorPanelComponent', () => { sitesService = TestBed.inject(SitesService); contentNodeSelectorPanelService = TestBed.inject(ContentNodeSelectorPanelService); uploadService = TestBed.inject(UploadService); + contentService = TestBed.inject(ContentService); + thumbnailService = TestBed.inject(ThumbnailService); + searchQueryBuilderService = component.queryBuilderService; component.queryBuilderService.resetToDefaults(); @@ -1016,25 +1021,78 @@ describe('ContentNodeSelectorPanelComponent', () => { describe('Chosen node', () => { const entry: Node = { id: 'fakeid'}; - const nodePage: NodePaging = { list: {}, pagination: {} }; + const nodePage: NodePaging = { list: { pagination: {} } }; let hasAllowableOperations; + const fakeFolderNode = { id: 'fakeNodeId', isFolder: true }; function returnHasPermission(): boolean { return hasAllowableOperations; } beforeEach(() => { + const schema = [ {}]; + const rows = [ {}, {}]; + component.documentList.data = new ShareDataTableAdapter(thumbnailService, contentService, schema); + spyOn(component.documentList.data, 'getRows').and.returnValue(rows); spyOn(sitesService, 'getSites').and.returnValue(of({ list: { entries: [] } })); }); it('should the selection become the currently navigated folder when the folder loads (Acts as destination for cases like copy action)', () => { - const fakeFolderNode = { id: 'fakeNodeId', isFolder: true }; component.documentList.folderNode = fakeFolderNode; - component.onFolderLoaded(); + component.onFolderLoaded(nodePage); expect(component.chosenNode).toEqual([fakeFolderNode]); }); + it('should update the pagination after filtering rows on copy and move action', () => { + component.documentList.folderNode = fakeFolderNode; + const fakeNodePage: NodePaging = { + list: { + pagination: { + hasMoreItems: true, + maxItems: 1, + totalItems: 2 + }, + entries: [ + { + entry: { + id: '123', + name: 'MyFolder', + isFile: false, + isFolder: true, + nodeType: 'mock', + modifiedAt: new Date(), + modifiedByUser: new UserInfo(), + createdAt: new Date(), + createdByUser: new UserInfo() + } + }, + { + entry: { + id: '456', + name: 'MyFolder2', + isFile: false, + isFolder: true, + nodeType: 'mock', + modifiedAt: new Date(), + modifiedByUser: new UserInfo(), + createdAt: new Date(), + createdByUser: new UserInfo() + } + } + ] + } + }; + component.documentList.ready.emit(fakeNodePage); + component.onFolderLoaded(fakeNodePage); + + expect(fakeNodePage.list.pagination.hasMoreItems).toBe(true); + fakeNodePage.list.pagination.maxItems = 25; + component.onFolderLoaded(fakeNodePage); + + expect(fakeNodePage.list.pagination.hasMoreItems).toBe(false); + }); + describe('in the case when isSelectionValid is a custom function for checking permissions,', () => { beforeEach(() => { diff --git a/lib/content-services/src/lib/content-node-selector/content-node-selector-panel.component.ts b/lib/content-services/src/lib/content-node-selector/content-node-selector-panel.component.ts index e140f66aa5..ea9283ded2 100644 --- a/lib/content-services/src/lib/content-node-selector/content-node-selector-panel.component.ts +++ b/lib/content-services/src/lib/content-node-selector/content-node-selector-panel.component.ts @@ -563,13 +563,23 @@ export class ContentNodeSelectorPanelComponent implements OnInit, OnDestroy { /** * Attempts to set the currently loaded node */ - onFolderLoaded(): void { + onFolderLoaded(nodePaging: NodePaging): void { + this.updatePaginationAfterRowFilter(nodePaging); if (!this.showingSearchResults) { this.attemptNodeSelection(this.documentList.folderNode); } this.folderLoaded.emit(); } + /** + * Updates pagination.hasMoreItems to false after filtering only folders during 'COPY' and 'MOVE' action + */ + updatePaginationAfterRowFilter(nodePaging: NodePaging): void { + if (this.documentList.data.getRows().length < nodePaging.list.pagination.maxItems) { + nodePaging.list.pagination.hasMoreItems = false; + } + } + /** * Returns whether breadcrumb has to be shown or not */