mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-07-24 17:32:15 +00:00
[ADF-1805] rebased documentlist pagination removal (#2668)
* [ADF-1805] rebased documentlist pagination removal * [ADF-1805] fixed some wrong changes]
This commit is contained in:
@@ -17,8 +17,7 @@
|
||||
|
||||
import { CUSTOM_ELEMENTS_SCHEMA, NgZone, SimpleChange, TemplateRef } from '@angular/core';
|
||||
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
|
||||
import { Pagination } from 'alfresco-js-api';
|
||||
import { AlfrescoApiService, TranslationService, AppConfigService, UserPreferencesService } from '@alfresco/adf-core';
|
||||
import { AlfrescoApiService, TranslationService } from '@alfresco/adf-core';
|
||||
import { DataColumn, DataTableComponent } from '@alfresco/adf-core';
|
||||
import { DataTableModule } from '@alfresco/adf-core';
|
||||
import { Observable, Subject } from 'rxjs/Rx';
|
||||
@@ -48,8 +47,6 @@ describe('DocumentList', () => {
|
||||
let fixture: ComponentFixture<DocumentListComponent>;
|
||||
let element: HTMLElement;
|
||||
let eventMock: any;
|
||||
let appConfig: AppConfigService;
|
||||
let userPreferences: UserPreferencesService;
|
||||
|
||||
beforeEach(async(() => {
|
||||
let zone = new NgZone({ enableLongStackTrace: false });
|
||||
@@ -87,8 +84,6 @@ describe('DocumentList', () => {
|
||||
documentList = fixture.componentInstance;
|
||||
documentListService = TestBed.get(DocumentListService);
|
||||
apiService = TestBed.get(AlfrescoApiService);
|
||||
userPreferences = TestBed.get(UserPreferencesService);
|
||||
appConfig = TestBed.get(AppConfigService);
|
||||
|
||||
fixture.detectChanges();
|
||||
});
|
||||
@@ -128,8 +123,7 @@ describe('DocumentList', () => {
|
||||
it('should call action\'s handler with node', () => {
|
||||
let node = new FileNode();
|
||||
let action = new ContentActionModel();
|
||||
action.handler = () => {
|
||||
};
|
||||
action.handler = () => { };
|
||||
|
||||
spyOn(action, 'handler').and.stub();
|
||||
|
||||
@@ -141,8 +135,7 @@ describe('DocumentList', () => {
|
||||
it('should call action\'s handler with node and permission', () => {
|
||||
let node = new FileNode();
|
||||
let action = new ContentActionModel();
|
||||
action.handler = () => {
|
||||
};
|
||||
action.handler = () => { };
|
||||
action.permission = 'fake-permission';
|
||||
spyOn(action, 'handler').and.stub();
|
||||
|
||||
@@ -154,8 +147,7 @@ describe('DocumentList', () => {
|
||||
it('should call action\'s execute with node if it is defined', () => {
|
||||
let node = new FileNode();
|
||||
let action = new ContentActionModel();
|
||||
action.execute = () => {
|
||||
};
|
||||
action.execute = () => { };
|
||||
spyOn(action, 'execute').and.stub();
|
||||
|
||||
documentList.executeContentAction(node, action);
|
||||
@@ -168,8 +160,7 @@ describe('DocumentList', () => {
|
||||
let node = new FileNode();
|
||||
let action = new ContentActionModel();
|
||||
action.handler = () => deleteObservable;
|
||||
action.execute = () => {
|
||||
};
|
||||
action.execute = () => { };
|
||||
spyOn(action, 'execute').and.stub();
|
||||
|
||||
documentList.executeContentAction(node, action);
|
||||
@@ -203,12 +194,14 @@ describe('DocumentList', () => {
|
||||
|
||||
it('should reset selection on loading folder by node id', () => {
|
||||
spyOn(documentList, 'resetSelection').and.callThrough();
|
||||
|
||||
documentList.loadFolderByNodeId('-trashcan-');
|
||||
expect(documentList.resetSelection).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('should reset selection in the datatable also', () => {
|
||||
spyOn(documentList.dataTable, 'resetSelection').and.callThrough();
|
||||
|
||||
documentList.loadFolderByNodeId('-trashcan-');
|
||||
expect(documentList.dataTable.resetSelection).toHaveBeenCalled();
|
||||
});
|
||||
@@ -217,6 +210,7 @@ describe('DocumentList', () => {
|
||||
documentList.currentFolderId = '1d26e465-dea3-42f3-b415-faa8364b9692';
|
||||
documentList.folderNode = new NodeMinimal();
|
||||
documentList.folderNode.id = '1d26e465-dea3-42f3-b415-faa8364b9692';
|
||||
|
||||
documentList.reload();
|
||||
|
||||
fixture.detectChanges();
|
||||
@@ -842,6 +836,7 @@ describe('DocumentList', () => {
|
||||
it('should load folder by ID on init', () => {
|
||||
documentList.currentFolderId = '1d26e465-dea3-42f3-b415-faa8364b9692';
|
||||
spyOn(documentList, 'loadFolderNodesByFolderNodeId').and.returnValue(Promise.resolve());
|
||||
|
||||
documentList.ngOnChanges({ folderNode: new SimpleChange(null, documentList.currentFolderId, true) });
|
||||
expect(documentList.loadFolderNodesByFolderNodeId).toHaveBeenCalled();
|
||||
});
|
||||
@@ -888,11 +883,8 @@ describe('DocumentList', () => {
|
||||
documentList.currentFolderId = '1d26e465-dea3-42f3-b415-faa8364b9692';
|
||||
documentList.folderNode = new NodeMinimal();
|
||||
documentList.folderNode.id = '1d26e465-dea3-42f3-b415-faa8364b9692';
|
||||
documentList.skipCount = 5;
|
||||
documentList.pageSize = 5;
|
||||
spyOn(documentList, 'isPaginationEnabled').and.returnValue(true);
|
||||
documentList.reload();
|
||||
|
||||
documentList.reload();
|
||||
fixture.detectChanges();
|
||||
|
||||
documentList.ready.subscribe(() => {
|
||||
@@ -920,8 +912,6 @@ describe('DocumentList', () => {
|
||||
documentList.currentFolderId = '1d26e465-dea3-42f3-b415-faa8364b9692';
|
||||
documentList.folderNode = new NodeMinimal();
|
||||
documentList.folderNode.id = '1d26e465-dea3-42f3-b415-faa8364b9692';
|
||||
documentList.skipCount = 5;
|
||||
documentList.pageSize = 5;
|
||||
spyOn(documentListService, 'getFolderNode').and.returnValue(Promise.resolve(fakeNodeWithCreatePermission));
|
||||
spyOn(documentListService, 'getFolder').and.returnValue(Promise.resolve(fakeNodeAnswerWithNOEntries));
|
||||
|
||||
@@ -940,8 +930,7 @@ describe('DocumentList', () => {
|
||||
documentList.currentFolderId = '1d26e465-dea3-42f3-b415-faa8364b9692';
|
||||
documentList.folderNode = new NodeMinimal();
|
||||
documentList.folderNode.id = '1d26e465-dea3-42f3-b415-faa8364b9692';
|
||||
documentList.skipCount = 5;
|
||||
documentList.pageSize = 5;
|
||||
|
||||
spyOn(documentListService, 'getFolderNode').and.returnValue(Promise.resolve(fakeNodeWithNoPermission));
|
||||
spyOn(documentListService, 'getFolder').and.returnValue(Promise.resolve(fakeNodeAnswerWithNOEntries));
|
||||
|
||||
@@ -1106,59 +1095,11 @@ describe('DocumentList', () => {
|
||||
documentList.loadFolderByNodeId('-recent-');
|
||||
});
|
||||
|
||||
it('should switch to another page', () => {
|
||||
spyOn(documentList, 'reload').and.stub();
|
||||
|
||||
const page1: Pagination = {
|
||||
maxItems: 5,
|
||||
skipCount: 0
|
||||
};
|
||||
const page2: Pagination = {
|
||||
maxItems: 5,
|
||||
skipCount: 10
|
||||
};
|
||||
|
||||
documentList.onChangePageNumber(page1);
|
||||
expect(documentList.pageSize).toBe(page1.maxItems);
|
||||
expect(documentList.skipCount).toBe(page1.skipCount);
|
||||
|
||||
documentList.onChangePageNumber(page2);
|
||||
expect(documentList.pageSize).toBe(page2.maxItems);
|
||||
expect(documentList.skipCount).toBe(page2.skipCount);
|
||||
|
||||
expect(documentList.reload).toHaveBeenCalledTimes(2);
|
||||
});
|
||||
|
||||
it('should reset pagination when switching sources', () => {
|
||||
spyOn(documentList, 'resetPagination').and.callThrough();
|
||||
|
||||
documentList.ngOnChanges({ currentFolderId: new SimpleChange(null, '-trashcan-', false) });
|
||||
documentList.ngOnChanges({ currentFolderId: new SimpleChange(null, '-sites-', false) });
|
||||
|
||||
expect(documentList.resetPagination).toHaveBeenCalledTimes(2);
|
||||
});
|
||||
|
||||
it('should reset folder node upon changing current folder id', () => {
|
||||
documentList.folderNode = <any> {};
|
||||
|
||||
documentList.ngOnChanges({ currentFolderId: new SimpleChange(null, '-sites-', false) });
|
||||
|
||||
expect(documentList.folderNode).toBeNull();
|
||||
});
|
||||
|
||||
it('should fallback to first page size supported', () => {
|
||||
userPreferences.paginationSize = 10;
|
||||
appConfig.config = Object.assign(appConfig.config, {
|
||||
'document-list': {
|
||||
supportedPageSizes: [20, 30, 40]
|
||||
}
|
||||
});
|
||||
|
||||
let customFixture = TestBed.createComponent<DocumentListComponent>(DocumentListComponent);
|
||||
let component: DocumentListComponent = customFixture.componentInstance;
|
||||
|
||||
customFixture.detectChanges();
|
||||
|
||||
expect(component.supportedPageSizes).toEqual([20, 30, 40]);
|
||||
expect(component.pageSize).toBe(20);
|
||||
});
|
||||
});
|
||||
|
Reference in New Issue
Block a user