From 43277148b2790bd11bef432c00fcfa8b9e793331 Mon Sep 17 00:00:00 2001 From: Denys Vuika Date: Fri, 15 Sep 2017 14:00:41 +0100 Subject: [PATCH] [ADF-1488] reset selection on Document List data change (#2341) * reset selection on data change * unit tests * fix unit tests --- .../src/services/people.service.spec.ts | 8 ++++---- .../components/document-list.component.spec.ts | 15 +++++++++++++++ .../src/components/document-list.component.ts | 9 +++++++++ 3 files changed, 28 insertions(+), 4 deletions(-) diff --git a/ng2-components/ng2-activiti-tasklist/src/services/people.service.spec.ts b/ng2-components/ng2-activiti-tasklist/src/services/people.service.spec.ts index c59ecc7785..0798c22020 100644 --- a/ng2-components/ng2-activiti-tasklist/src/services/people.service.spec.ts +++ b/ng2-components/ng2-activiti-tasklist/src/services/people.service.spec.ts @@ -89,8 +89,8 @@ describe('PeopleService', () => { (users: User[]) => { expect(users).toBeDefined(); expect(users.length).toBe(2); - expect(users[0].userImage).toContain('/app/rest/users/' + users[0].id + '/picture'); - expect(users[1].userImage).toContain('/app/rest/users/' + users[1].id + '/picture'); + expect(users[0].userImage).toContain('/users/' + users[0].id + '/picture'); + expect(users[1].userImage).toContain('/users/' + users[1].id + '/picture'); done(); }); jasmine.Ajax.requests.mostRecent().respondWith({ @@ -104,7 +104,7 @@ describe('PeopleService', () => { service.addImageToUser(firstInvolvedUser).subscribe( (user: User) => { expect(user).toBeDefined(); - expect(user.userImage).toContain('/app/rest/users/' + user.id + '/picture'); + expect(user.userImage).toContain('/users/' + user.id + '/picture'); expect(user.id).toBe('1'); done(); }); @@ -113,7 +113,7 @@ describe('PeopleService', () => { it('should return user image url', () => { let url = service.getUserImage(firstInvolvedUser); - expect(url).toContain('/app/rest/users/' + firstInvolvedUser.id + '/picture'); + expect(url).toContain('/users/' + firstInvolvedUser.id + '/picture'); }); it('should return empty list when there are no users to involve', (done) => { diff --git a/ng2-components/ng2-alfresco-documentlist/src/components/document-list.component.spec.ts b/ng2-components/ng2-alfresco-documentlist/src/components/document-list.component.spec.ts index 4b521e0fd4..c9ccc2b918 100644 --- a/ng2-components/ng2-alfresco-documentlist/src/components/document-list.component.spec.ts +++ b/ng2-components/ng2-alfresco-documentlist/src/components/document-list.component.spec.ts @@ -183,6 +183,21 @@ describe('DocumentList', () => { }); }); + it('should reset selection upon reload', () => { + spyOn(documentList, 'resetSelection').and.callThrough(); + + documentList.reload(); + fixture.detectChanges(); + + expect(documentList.resetSelection).toHaveBeenCalled(); + }); + + it('should reset selection on loading folder by node id', () => { + spyOn(documentList, 'resetSelection').and.callThrough(); + documentList.loadFolderByNodeId('-trashcan-'); + expect(documentList.resetSelection).toHaveBeenCalled(); + }); + it('should empty template be present when no element are present', (done) => { documentList.currentFolderId = '1d26e465-dea3-42f3-b415-faa8364b9692'; documentList.folderNode = new NodeMinimal(); diff --git a/ng2-components/ng2-alfresco-documentlist/src/components/document-list.component.ts b/ng2-components/ng2-alfresco-documentlist/src/components/document-list.component.ts index f77c4cdadb..374781fd1d 100644 --- a/ng2-components/ng2-alfresco-documentlist/src/components/document-list.component.ts +++ b/ng2-components/ng2-alfresco-documentlist/src/components/document-list.component.ts @@ -255,6 +255,7 @@ export class DocumentListComponent implements OnInit, OnChanges, AfterContentIni this.loadFolderByNodeId(changes.currentFolderId.currentValue); } else if (this.data) { if (changes.node && changes.node.currentValue) { + this.resetSelection(); this.data.loadPage(changes.node.currentValue); } else if (changes.rowFilter) { this.data.setFilter(changes.rowFilter.currentValue); @@ -269,6 +270,8 @@ export class DocumentListComponent implements OnInit, OnChanges, AfterContentIni reload() { this.ngZone.run(() => { + this.resetSelection(); + if (this.folderNode) { this.loadFolder(); } else if (this.currentFolderId) { @@ -399,6 +402,7 @@ export class DocumentListComponent implements OnInit, OnChanges, AfterContentIni // gets folder node and its content loadFolderByNodeId(nodeId: string) { this.loading = true; + this.resetSelection(); if (nodeId === '-trashcan-') { this.loadTrashcan(); @@ -425,6 +429,7 @@ export class DocumentListComponent implements OnInit, OnChanges, AfterContentIni loadFolderNodesByFolderNodeId(id: string, maxItems: number, skipCount: number): Promise { return new Promise((resolve, reject) => { + this.resetSelection(); this.documentListService .getFolder(null, { maxItems: maxItems, @@ -454,6 +459,10 @@ export class DocumentListComponent implements OnInit, OnChanges, AfterContentIni } + resetSelection() { + this.selection = []; + } + private loadTrashcan(): void { const options = { include: [ 'path', 'properties' ],