mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-08-07 17:48:54 +00:00
committed by
Mario Romano
parent
26fb2374d2
commit
dc28d5b679
@@ -0,0 +1,61 @@
|
||||
/*!
|
||||
* @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 { DataColumn } from 'ng2-alfresco-datatable';
|
||||
|
||||
import { DocumentListComponent } from './../document-list.component';
|
||||
import { DocumentListServiceMock } from './../../assets/document-list.service.mock';
|
||||
import { ContentColumnListComponent } from './content-column-list.component';
|
||||
|
||||
describe('ContentColumnList', () => {
|
||||
|
||||
let documentList: DocumentListComponent;
|
||||
let columnList: ContentColumnListComponent;
|
||||
|
||||
beforeEach(() => {
|
||||
let service = new DocumentListServiceMock();
|
||||
documentList = new DocumentListComponent(service, null, null);
|
||||
columnList = new ContentColumnListComponent(documentList);
|
||||
});
|
||||
|
||||
it('should register column within parent document list', () => {
|
||||
let columns = documentList.data.getColumns();
|
||||
expect(columns.length).toBe(0);
|
||||
|
||||
let column = <DataColumn> {};
|
||||
let result = columnList.registerColumn(column);
|
||||
|
||||
expect(result).toBeTruthy();
|
||||
expect(columns.length).toBe(1);
|
||||
expect(columns[0]).toBe(column);
|
||||
});
|
||||
|
||||
it('should require document list instance to register action', () => {
|
||||
columnList = new ContentColumnListComponent(null);
|
||||
let col = <DataColumn> {};
|
||||
expect(columnList.registerColumn(col)).toBeFalsy();
|
||||
});
|
||||
|
||||
it('should require action instance to register', () => {
|
||||
spyOn(documentList.actions, 'push').and.callThrough();
|
||||
let result = columnList.registerColumn(null);
|
||||
|
||||
expect(result).toBeFalsy();
|
||||
expect(documentList.actions.push).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
});
|
@@ -0,0 +1,44 @@
|
||||
/*!
|
||||
* @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 { Component } from '@angular/core';
|
||||
import { DataColumn } from 'ng2-alfresco-datatable';
|
||||
|
||||
import { DocumentListComponent } from './../document-list.component';
|
||||
|
||||
@Component({
|
||||
selector: 'content-columns',
|
||||
template: ''
|
||||
})
|
||||
export class ContentColumnListComponent {
|
||||
|
||||
constructor(private documentList: DocumentListComponent) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers column model within the parent document list component.
|
||||
* @param column Column definition model to register.
|
||||
*/
|
||||
registerColumn(column: DataColumn): boolean {
|
||||
if (this.documentList && column) {
|
||||
let columns = this.documentList.data.getColumns();
|
||||
columns.push(column);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
@@ -0,0 +1,71 @@
|
||||
/*!
|
||||
* @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 { DocumentListComponent } from './../document-list.component';
|
||||
import { ContentColumnComponent } from './content-column.component';
|
||||
import { DocumentListServiceMock } from './../../assets/document-list.service.mock';
|
||||
import { ContentColumnListComponent } from './content-column-list.component';
|
||||
|
||||
describe('ContentColumn', () => {
|
||||
|
||||
let documentList: DocumentListComponent;
|
||||
let columnList: ContentColumnListComponent;
|
||||
|
||||
beforeEach(() => {
|
||||
let service = new DocumentListServiceMock();
|
||||
documentList = new DocumentListComponent(service, null, null);
|
||||
columnList = new ContentColumnListComponent(documentList);
|
||||
});
|
||||
|
||||
it('should register model within parent column list', () => {
|
||||
spyOn(columnList, 'registerColumn').and.callThrough();
|
||||
|
||||
let column = new ContentColumnComponent(columnList);
|
||||
column.ngOnInit();
|
||||
|
||||
expect(columnList.registerColumn).toHaveBeenCalled();
|
||||
|
||||
let columns = documentList.data.getColumns();
|
||||
expect(columns.length).toBe(1);
|
||||
expect(columns[0]).toBe(column);
|
||||
});
|
||||
|
||||
it('should setup screen reader title for thumbnail column', () => {
|
||||
let column = new ContentColumnComponent(columnList);
|
||||
column.key = '$thumbnail';
|
||||
column.ngOnInit();
|
||||
|
||||
expect(column.srTitle).toBe('Thumbnail');
|
||||
});
|
||||
|
||||
it('should register on init', () => {
|
||||
let column = new ContentColumnComponent(columnList);
|
||||
spyOn(column, 'register').and.callThrough();
|
||||
|
||||
column.ngOnInit();
|
||||
expect(column.register).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('should require action list to register action with', () => {
|
||||
let column = new ContentColumnComponent(columnList);
|
||||
expect(column.register()).toBeTruthy();
|
||||
|
||||
column = new ContentColumnComponent(null);
|
||||
expect(column.register()).toBeFalsy();
|
||||
});
|
||||
|
||||
});
|
@@ -0,0 +1,69 @@
|
||||
/*!
|
||||
* @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 { Component, OnInit, Input } from '@angular/core';
|
||||
import { DataColumn } from 'ng2-alfresco-datatable';
|
||||
|
||||
import { ContentColumnListComponent } from './content-column-list.component';
|
||||
|
||||
@Component({
|
||||
selector: 'content-column',
|
||||
template: ''
|
||||
})
|
||||
export class ContentColumnComponent implements OnInit, DataColumn {
|
||||
|
||||
@Input()
|
||||
key: string;
|
||||
|
||||
@Input()
|
||||
type: string = 'text';
|
||||
|
||||
@Input()
|
||||
format: string;
|
||||
|
||||
@Input()
|
||||
sortable: boolean = false;
|
||||
|
||||
@Input()
|
||||
title: string = '';
|
||||
|
||||
/**
|
||||
* Title to be used for screen readers.
|
||||
*/
|
||||
@Input('sr-title')
|
||||
srTitle: string;
|
||||
|
||||
@Input('class')
|
||||
cssClass: string;
|
||||
|
||||
constructor(private list: ContentColumnListComponent) {}
|
||||
|
||||
ngOnInit() {
|
||||
if (!this.srTitle && this.key === '$thumbnail') {
|
||||
this.srTitle = 'Thumbnail';
|
||||
}
|
||||
|
||||
this.register();
|
||||
}
|
||||
|
||||
register(): boolean {
|
||||
if (this.list) {
|
||||
return this.list.registerColumn(this);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user