Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 2 commits into from
Jan 11, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ import {
DataTableModule,
ObjectDataTableAdapter,
ShowHeaderMode,
ThumbnailService
ThumbnailService,
ContentService
} from '@alfresco/adf-core';
import { Subject, of, throwError } from 'rxjs';
import {
Expand All @@ -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', () => {

Expand All @@ -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;
Expand Down Expand Up @@ -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: {} });
Expand Down Expand Up @@ -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();

Expand All @@ -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();

Expand All @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,7 @@ import {
RequestPaginationModel,
AlfrescoApiService,
UserPreferenceValues,
LockService,
DataRow
LockService
} from '@alfresco/adf-core';

import { Node, NodeEntry, NodePaging, Pagination } from '@alfresco/js-api';
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -932,29 +920,17 @@ export class DocumentListComponent implements OnInit, OnChanges, OnDestroy, Afte
}

getPreselectNodesBasedOnSelectionMode(): NodeEntry[] {
let selectedNodes: NodeEntry[] = [];

if (this.hasPreselectNodes()) {
if (this.isSingleSelectionMode()) {
selectedNodes = [this.preselectNodes[0]];
} else {
selectedNodes = this.preselectNodes;
}
}

return selectedNodes;
return this.hasPreselectNodes() ? (this.isSingleSelectionMode() ? [this.preselectNodes[0]] : this.preselectNodes) : [];
}

private onPreselectNodes() {
onPreselectNodes() {
if (this.hasPreselectNodes()) {
let selectedNodes: DataRow[] = [];
const preselectedNodes = [...this.isSingleSelectionMode() ? [this.data.getPreselectRows()[0]] : this.data.getPreselectRows()];
const selectedNodes = [...this.selection, ...preselectedNodes];

if (this.isSingleSelectionMode()) {
selectedNodes = [this.data.getPreselectRows()[0]];
} else {
selectedNodes = this.data.getPreselectRows();
for (const node of preselectedNodes) {
this.dataTable.selectRow(node, true);
}

this.onNodeSelect({ row: undefined, selection: <ShareDataRow[]> selectedNodes });
}
}
Expand Down