Eugenio Romano 07c247ca11 [ADF-2500] fix trashcan bug plus refactoring documentlist (#3136)
* [ADF-2500] The full content of Trashcan is not displayed.

fix pagination problem and add tests

* refactor code

* custom resources services

* move custom resources in separate service part 2

* move custom resources in separate service part 3

* move isCustomResources in custom resources

* move getCorrispondinNodeIds in custom services

* reorganize code

* add pagination interface

* remove permissions check document list and use the common cs method
remove the merge option and move it in the paginator

* make infinte scrolling always use the target

* restore loading infinite page

* fix license header

* fix type problems

* breadcrumb test service

* fix test

* export CustomResourcesService

* fix test pagination

* fix content ndoe test

* remove timeout content node selector test

* fix after rebase

* ripristinate observalbe in search service

* fix wrong type return stub document list test

* fix search service

* fix test document list

* move handle error in common method

* restore observable in search control

* Update search-control.component.spec.ts

* fix after rebase

* add import switchmap

* core import in karma conf

* missing commas

* fix mocks

* fix mock searchquerybody

* search test fix
2018-04-09 10:31:43 +01:00

234 lines
7.7 KiB
TypeScript

/*!
* @license
* Copyright 2016 Alfresco Software, Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { CUSTOM_ELEMENTS_SCHEMA, SimpleChange } from '@angular/core';
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { PathElementEntity } from 'alfresco-js-api';
import { DataTableModule } from '@alfresco/adf-core';
import { fakeNodeWithCreatePermission } from '../mock';
import { CustomResourcesService, DocumentListService, DocumentListComponent } from '../document-list';
import { BreadcrumbComponent } from './breadcrumb.component';
declare let jasmine: any;
describe('Breadcrumb', () => {
let component: BreadcrumbComponent;
let fixture: ComponentFixture<BreadcrumbComponent>;
let documentList: DocumentListComponent;
beforeEach(async(() => {
TestBed.configureTestingModule({
imports: [
DataTableModule
],
declarations: [
DocumentListComponent,
BreadcrumbComponent
],
providers: [
DocumentListService,
CustomResourcesService
],
schemas: [
CUSTOM_ELEMENTS_SCHEMA
]
}).compileComponents();
}));
beforeEach(() => {
fixture = TestBed.createComponent(BreadcrumbComponent);
component = fixture.componentInstance;
documentList = TestBed.createComponent<DocumentListComponent>(DocumentListComponent).componentInstance;
});
it('should prevent default click behavior', () => {
let event = jasmine.createSpyObj('event', ['preventDefault']);
component.onRoutePathClick(null, event);
expect(event.preventDefault).toHaveBeenCalled();
});
it('should root be present as default node if the path is null', () => {
let change = new SimpleChange(null, fakeNodeWithCreatePermission, true);
component.root = 'default';
component.ngOnChanges({ 'folderNode': change });
expect(component.route[0].name).toBe('default');
});
it('should emit navigation event', (done) => {
let node = <PathElementEntity> { id: '-id-', name: 'name' };
component.navigate.subscribe(val => {
expect(val).toBe(node);
done();
});
component.onRoutePathClick(node, null);
});
it('should update document list on click', (done) => {
spyOn(documentList, 'loadFolderByNodeId').and.stub();
let node = <PathElementEntity> { id: '-id-', name: 'name' };
component.target = documentList;
component.onRoutePathClick(node, null);
setTimeout(() => {
expect(documentList.loadFolderByNodeId).toHaveBeenCalledWith(node.id);
done();
}, 0);
});
it('should not parse the route when node not provided', () => {
expect(component.parseRoute(null)).toEqual([]);
});
it('should not parase the route when node has no path', () => {
const node: any = {};
expect(component.parseRoute(node)).toEqual([]);
});
it('should append the node to the route', () => {
const node: any = {
id: 'test-id',
name: 'test-name',
path: {
elements: [
{ id: 'element-id', name: 'element-name' }
]
}
};
const route = component.parseRoute(node);
expect(route.length).toBe(2);
expect(route[1].id).toBe(node.id);
expect(route[1].name).toBe(node.name);
});
it('should trim the route if custom root id provided', () => {
const node: any = {
id: 'test-id',
name: 'test-name',
path: {
elements: [
{ id: 'element-1-id', name: 'element-1-name' },
{ id: 'element-2-id', name: 'element-2-name' },
{ id: 'element-3-id', name: 'element-3-name' }
]
}
};
component.rootId = 'element-2-id';
const route = component.parseRoute(node);
expect(route.length).toBe(3);
expect(route[0].id).toBe('element-2-id');
expect(route[0].name).toBe('element-2-name');
expect(route[2].id).toBe(node.id);
expect(route[2].name).toBe(node.name);
});
it('should rename root node if custom name provided', () => {
const node: any = {
id: 'test-id',
name: 'test-name',
path: {
elements: [
{ id: 'element-1-id', name: 'element-1-name' },
{ id: 'element-2-id', name: 'element-2-name' },
{ id: 'element-3-id', name: 'element-3-name' }
]
}
};
component.root = 'custom root';
const route = component.parseRoute(node);
expect(route.length).toBe(4);
expect(route[0].id).toBe('element-1-id');
expect(route[0].name).toBe('custom root');
});
it('should replace root id if nothing to trim in the path', () => {
const node: any = {
id: 'test-id',
name: 'test-name',
path: {
elements: [
{ id: 'element-1-id', name: 'element-1-name' },
{ id: 'element-2-id', name: 'element-2-name' },
{ id: 'element-3-id', name: 'element-3-name' }
]
}
};
component.rootId = 'custom-id';
const route = component.parseRoute(node);
expect(route.length).toBe(4);
expect(route[0].id).toBe('custom-id');
expect(route[0].name).toBe('element-1-name');
});
it('should replace both id and name of the root element', () => {
const node: any = {
id: 'test-id',
name: 'test-name',
path: {
elements: [
{ id: 'element-1-id', name: 'element-1-name' },
{ id: 'element-2-id', name: 'element-2-name' },
{ id: 'element-3-id', name: 'element-3-name' }
]
}
};
component.root = 'custom-name';
component.rootId = 'custom-id';
const route = component.parseRoute(node);
expect(route.length).toBe(4);
expect(route[0].id).toBe('custom-id');
expect(route[0].name).toBe('custom-name');
});
it('should apply the transformation function when there is one', () => {
const node: any = {
id: null,
name: null,
path: {
elements: [
{ id: 'element-1-id', name: 'element-1-name' },
{ id: 'element-2-id', name: 'element-2-name' },
{ id: 'element-3-id', name: 'element-3-name' }
]
}
};
component.transform = ((transformNode) => {
transformNode.id = 'test-id';
transformNode.name = 'test-name';
return transformNode;
});
let change = new SimpleChange(null, node, true);
component.ngOnChanges({ 'folderNode': change });
expect(component.route.length).toBe(4);
expect(component.route[3].id).toBe('test-id');
expect(component.route[3].name).toBe('test-name');
});
});