diff --git a/ng2-components/ng2-alfresco-documentlist/src/components/document-list-breadcrumb.component.spec.ts b/ng2-components/ng2-alfresco-documentlist/src/components/document-list-breadcrumb.component.spec.ts new file mode 100644 index 0000000000..9b1ba0fde1 --- /dev/null +++ b/ng2-components/ng2-alfresco-documentlist/src/components/document-list-breadcrumb.component.spec.ts @@ -0,0 +1,109 @@ +/*! + * @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 { + it, + describe, + beforeEach, + expect +} from '@angular/core/testing'; + +import { + DocumentListBreadcrumb, + PathNode +} from './document-list-breadcrumb.component'; +import { DocumentList } from './document-list'; + +describe('DocumentListBreadcrumb', () => { + + let component; + + beforeEach(() => { + component = new DocumentListBreadcrumb(); + }); + + it('should set current path', () => { + let path = '/some/path'; + component.currentFolderPath = path; + expect(component.currentFolderPath).toBe(path); + }); + + it('should init with root folder by default', () => { + expect(component.route.length).toBe(1); + expect(component.route[0]).toEqual( + jasmine.objectContaining({ + name: 'Root', + path: '/' + }) + ); + }); + + it('should fallback to default root for invalid path', () => { + component.currentFolderPath = null; + expect(component.currentFolderPath).toBe('/'); + + expect(component.route.length).toBe(1); + expect(component.route[0]).toEqual( + jasmine.objectContaining({ + name: 'Root', + path: '/' + }) + ); + }); + + it('should parse the route', () => { + component.currentFolderPath = '/some/path'; + + expect(component.route.length).toBe(3); + expect(component.route).toEqual( + jasmine.objectContaining([ + { name: 'Root', path: '/' }, + { name: 'some', path: '/some' }, + { name: 'path', path: '/some/path' } + ]) + ); + }); + + it('should prevent default click behavior', () => { + let event = jasmine.createSpyObj('event', ['preventDefault']); + component.onRoutePathClick(null, event); + expect(event.preventDefault).toHaveBeenCalled(); + }); + + it('should emit navigation event', (done) => { + let node = { name: 'name', path: '/path' }; + component.navigate.subscribe(val => { + expect(val.value.name).toBe(node.name); + expect(val.value.path).toBe(node.path); + done(); + }); + + component.onRoutePathClick(node, null); + }); + + it('should update document list on click', () => { + let documentList = new DocumentList(null, null); + spyOn(documentList, 'displayFolderContent').and.stub(); + + let node = { name: 'name', path: '/path' }; + component.target = documentList; + + component.onRoutePathClick(node, null); + expect(documentList.currentFolderPath).toBe(node.path); + }); + +}); diff --git a/ng2-components/ng2-alfresco-documentlist/src/components/document-list-breadcrumb.component.ts b/ng2-components/ng2-alfresco-documentlist/src/components/document-list-breadcrumb.component.ts index 16d086dfca..5bc4990259 100644 --- a/ng2-components/ng2-alfresco-documentlist/src/components/document-list-breadcrumb.component.ts +++ b/ng2-components/ng2-alfresco-documentlist/src/components/document-list-breadcrumb.component.ts @@ -42,11 +42,11 @@ export class DocumentListBreadcrumb { @Input() set currentFolderPath(val: string) { if (this._currentFolderPath !== val) { - this._currentFolderPath = val; - if (val) { + this._currentFolderPath = val; this.route = this.parsePath(val); } else { + this._currentFolderPath = this.rootFolder.path; this.route = [ this.rootFolder ]; } }