Unit tests

This commit is contained in:
Denys Vuika
2016-07-07 17:05:03 +01:00
parent 9e2df15424
commit 32c00b7e99
4 changed files with 278 additions and 164 deletions

View File

@@ -27,6 +27,11 @@ import { DocumentListService } from './../services/document-list.service';
export class ShareDataTableAdapter implements DataTableAdapter {
static ERR_ROW_NOT_FOUND: string = 'Row not found';
static ERR_COL_NOT_FOUND: string = 'Column not found';
static DEFAULT_DATE_FORMAT: string = 'medium';
private sorting: DataSorting;
private rows: DataRow[];
private columns: DataColumn[];
@@ -59,20 +64,20 @@ export class ShareDataTableAdapter implements DataTableAdapter {
getValue(row: DataRow, col: DataColumn): any {
if (!row) {
throw new Error('Row not found');
throw new Error(ShareDataTableAdapter.ERR_ROW_NOT_FOUND);
}
if (!col) {
throw new Error('Column not found');
throw new Error(ShareDataTableAdapter.ERR_COL_NOT_FOUND);
}
let value = row.getValue(col.key);
if (col.type === 'date') {
let datePipe = new DatePipe();
let format = col.format || 'medium';
let format = col.format || ShareDataTableAdapter.DEFAULT_DATE_FORMAT;
try {
return datePipe.transform(value, format);
} catch (err) {
console.error(`DocumentList: error parsing date ${value} to format ${format}`);
console.error(`Error parsing date ${value} to format ${format}`);
}
}
@@ -168,25 +173,31 @@ export class ShareDataTableAdapter implements DataTableAdapter {
let data = page.list.entries;
if (data && data.length > 0) {
rows = data.map(item => new ShareDataRow(item));
// Sort by first sortable or just first column
let sortable = this.columns.filter(c => c.sortable);
if (sortable.length > 0) {
this.sort(sortable[0].key, 'asc');
} else {
this.sort(this.columns[0].key, 'asc');
if (this.columns && this.columns.length > 0) {
let sortable = this.columns.filter(c => c.sortable);
if (sortable.length > 0) {
this.sort(sortable[0].key, 'asc');
} else {
this.sort(this.columns[0].key, 'asc');
}
}
}
}
this.rows = rows;
},
error => console.log(error));
error => console.error(error));
}
}
}
export class ShareDataRow implements DataRow {
static ERR_OBJECT_NOT_FOUND: string = 'Object source not found';
isSelected: boolean = false;
get node(): MinimalNodeEntity {
@@ -195,7 +206,7 @@ export class ShareDataRow implements DataRow {
constructor(private obj: MinimalNodeEntity) {
if (!obj) {
throw new Error('Object source not found');
throw new Error(ShareDataRow.ERR_OBJECT_NOT_FOUND);
}
}