[AAE-3467] - Fix Uploaded files are not being attached after selecting more files (#6506)

* Fix selection not working after uploading files, simplify if else conditions

* add unit test
This commit is contained in:
arditdomi 2021-01-11 09:36:10 +00:00 committed by GitHub
parent 8e12e51fb3
commit 9947d6aa40
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 32 additions and 37 deletions

View File

@ -27,7 +27,8 @@ import {
DataTableModule,
ObjectDataTableAdapter,
ShowHeaderMode,
ThumbnailService
ThumbnailService,
ContentService
} from '@alfresco/adf-core';
import { Subject, of, throwError } from 'rxjs';
import {
@ -52,6 +53,7 @@ import { NodeEntry } from '@alfresco/js-api';
import { By } from '@angular/platform-browser';
import { DocumentListModule } from '../document-list.module';
import { TranslateModule } from '@ngx-translate/core';
import { ShareDataRow } from '../data/share-data-row.model';
describe('DocumentList', () => {
@ -60,6 +62,7 @@ describe('DocumentList', () => {
let apiService: AlfrescoApiService;
let customResourcesService: CustomResourcesService;
let thumbnailService: ThumbnailService;
let contentService: ContentService;
let fixture: ComponentFixture<DocumentListComponent>;
let element: HTMLElement;
let eventMock: any;
@ -91,6 +94,7 @@ describe('DocumentList', () => {
apiService = TestBed.inject(AlfrescoApiService);
customResourcesService = TestBed.inject(CustomResourcesService);
thumbnailService = TestBed.inject(ThumbnailService);
contentService = TestBed.inject(ContentService);
spyFolder = spyOn(documentListService, 'getFolder').and.callFake(() => {
return Promise.resolve({ list: {} });
@ -1544,7 +1548,7 @@ describe('DocumentList', () => {
expect(nodeSelectedSpy).toHaveBeenCalled();
});
it('should able to select first node from the preselectNodes when selectionMode set to single', async () => {
it('should be able to select first node from the preselectNodes when selectionMode set to single', async () => {
documentList.selectionMode = 'single';
fixture.detectChanges();
@ -1559,7 +1563,7 @@ describe('DocumentList', () => {
expect(documentList.getPreselectNodesBasedOnSelectionMode().length).toBe(1);
});
it('should able to select all preselectNodes when selectionMode set to multiple', async () => {
it('should be able to select all preselectNodes when selectionMode set to multiple', async () => {
documentList.selectionMode = 'multiple';
fixture.detectChanges();
@ -1574,7 +1578,22 @@ describe('DocumentList', () => {
expect(documentList.getPreselectNodesBasedOnSelectionMode().length).toBe(2);
});
it('should not emit nodeSelected event when preselectNodes undefined/empty', async () => {
it('should call the datatable select row method for each preselected node', async () => {
const datatableSelectRowSpy = spyOn(documentList.dataTable, 'selectRow');
const fakeDatatableRows = [new ShareDataRow(mockPreselectedNodes[0], contentService, null), new ShareDataRow(mockPreselectedNodes[1], contentService, null)];
spyOn(documentList.data, 'getPreselectRows').and.returnValue(fakeDatatableRows);
documentList.selectionMode = 'multiple';
documentList.preselectNodes = mockPreselectedNodes;
documentList.onPreselectNodes();
fixture.detectChanges();
await fixture.whenStable();
expect(datatableSelectRowSpy.calls.count()).toEqual(fakeDatatableRows.length);
});
it('should not emit nodeSelected event when preselectNodes is undefined/empty', async () => {
const nodeSelectedSpy = spyOn(documentList.nodeSelected, 'emit');
fixture.detectChanges();

View File

@ -44,8 +44,7 @@ import {
RequestPaginationModel,
AlfrescoApiService,
UserPreferenceValues,
LockService,
DataRow
LockService
} from '@alfresco/adf-core';
import { Node, NodeEntry, NodePaging, Pagination } from '@alfresco/js-api';
@ -634,13 +633,7 @@ export class DocumentListComponent implements OnInit, OnChanges, OnDestroy, Afte
*/
executeContentAction(node: NodeEntry, action: ContentActionModel) {
if (node && node.entry && action) {
let handlerSub;
if (typeof action.handler === 'function') {
handlerSub = action.handler(node, this, action.permission);
} else {
handlerSub = of(true);
}
const handlerSub = (typeof action.handler === 'function') ? action.handler(node, this, action.permission) : of(true);
if (typeof action.execute === 'function' && handlerSub) {
handlerSub
@ -879,12 +872,7 @@ export class DocumentListComponent implements OnInit, OnChanges, OnDestroy, Afte
private loadLayoutPresets(): void {
const externalSettings = this.appConfig.get('document-list.presets', null);
if (externalSettings) {
this.layoutPresets = Object.assign({}, presetsDefaultModel, externalSettings);
} else {
this.layoutPresets = presetsDefaultModel;
}
this.layoutPresets = externalSettings ? Object.assign({}, presetsDefaultModel, externalSettings) : presetsDefaultModel;
}
private onDataReady(nodePaging: NodePaging) {
@ -932,29 +920,17 @@ export class DocumentListComponent implements OnInit, OnChanges, OnDestroy, Afte
}
getPreselectNodesBasedOnSelectionMode(): NodeEntry[] {
let selectedNodes: NodeEntry[] = [];
return this.hasPreselectNodes() ? (this.isSingleSelectionMode() ? [this.preselectNodes[0]] : this.preselectNodes) : [];
}
onPreselectNodes() {
if (this.hasPreselectNodes()) {
if (this.isSingleSelectionMode()) {
selectedNodes = [this.preselectNodes[0]];
} else {
selectedNodes = this.preselectNodes;
}
}
const preselectedNodes = [...this.isSingleSelectionMode() ? [this.data.getPreselectRows()[0]] : this.data.getPreselectRows()];
const selectedNodes = [...this.selection, ...preselectedNodes];
return selectedNodes;
for (const node of preselectedNodes) {
this.dataTable.selectRow(node, true);
}
private onPreselectNodes() {
if (this.hasPreselectNodes()) {
let selectedNodes: DataRow[] = [];
if (this.isSingleSelectionMode()) {
selectedNodes = [this.data.getPreselectRows()[0]];
} else {
selectedNodes = this.data.getPreselectRows();
}
this.onNodeSelect({ row: undefined, selection: <ShareDataRow[]> selectedNodes });
}
}