mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-07-31 17:38:48 +00:00
Form renderer enhancements (#1839)
- readonly mode for “Dynamic Table” - “Display Value” now just uses “Dynamic Table” if needed (previously rendered the table itself) - support for “tableEditable” settings
This commit is contained in:
committed by
Mario Romano
parent
95711616ca
commit
1dd283b0d8
@@ -15,6 +15,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { CUSTOM_ELEMENTS_SCHEMA } from '@angular/core';
|
||||
import { ComponentFixture, TestBed, async } from '@angular/core/testing';
|
||||
import { CoreModule, LogServiceMock } from 'ng2-alfresco-core';
|
||||
import { Observable } from 'rxjs/Rx';
|
||||
@@ -25,7 +26,6 @@ import { EcmModelService } from '../../../services/ecm-model.service';
|
||||
import { FormFieldModel } from './../core/form-field.model';
|
||||
import { FormFieldTypes } from '../core/form-field-types';
|
||||
import { FormModel } from '../core/form.model';
|
||||
import { DynamicTableColumn, DynamicTableRow } from './../dynamic-table/dynamic-table.widget.model';
|
||||
import { WidgetVisibilityService } from '../../../services/widget-visibility.service';
|
||||
|
||||
describe('DisplayValueWidget', () => {
|
||||
@@ -608,135 +608,6 @@ describe('DisplayValueWidget', () => {
|
||||
expect(widget.value).toBe(value);
|
||||
});
|
||||
|
||||
it('should setup [DYNAMIC_TABLE] field', () => {
|
||||
let columns = [{id: '1', visible: false}, {id: '2', visible: true}];
|
||||
let rows = [{}, {}];
|
||||
|
||||
widget.field = new FormFieldModel(null, {
|
||||
type: FormFieldTypes.DISPLAY_VALUE,
|
||||
params: {
|
||||
field: {
|
||||
type: FormFieldTypes.DYNAMIC_TABLE
|
||||
}
|
||||
},
|
||||
columnDefinitions: columns,
|
||||
value: rows
|
||||
});
|
||||
widget.ngOnInit();
|
||||
|
||||
expect(widget.columns.length).toBe(2);
|
||||
expect(widget.columns[0].id).toBe(columns[0].id);
|
||||
expect(widget.columns[1].id).toBe(columns[1].id);
|
||||
|
||||
expect(widget.visibleColumns.length).toBe(1);
|
||||
expect(widget.visibleColumns[0].id).toBe(columns[1].id);
|
||||
|
||||
expect(widget.rows.length).toBe(2);
|
||||
});
|
||||
|
||||
it('should setup [DYNAMIC_TABLE] field with empty schema', () => {
|
||||
widget.field = new FormFieldModel(null, {
|
||||
type: FormFieldTypes.DISPLAY_VALUE,
|
||||
params: {
|
||||
field: {
|
||||
type: FormFieldTypes.DYNAMIC_TABLE
|
||||
}
|
||||
},
|
||||
columnDefinitions: null,
|
||||
value: null
|
||||
});
|
||||
widget.ngOnInit();
|
||||
|
||||
expect(widget.value).toBeNull();
|
||||
expect(widget.columns).toEqual([]);
|
||||
expect(widget.rows).toEqual([]);
|
||||
});
|
||||
|
||||
it('should retrieve default cell value', () => {
|
||||
const value = '<value>';
|
||||
let row = <DynamicTableRow> {value: {key: value}};
|
||||
let column = <DynamicTableColumn> {id: 'key'};
|
||||
|
||||
expect(widget.getCellValue(row, column)).toBe(value);
|
||||
});
|
||||
|
||||
it('should retrieve dropdown cell value', () => {
|
||||
const value = {id: '1', name: 'one'};
|
||||
let row = <DynamicTableRow> {value: {key: value}};
|
||||
let column = <DynamicTableColumn> {id: 'key', type: 'Dropdown'};
|
||||
|
||||
expect(widget.getCellValue(row, column)).toBe(value.name);
|
||||
});
|
||||
|
||||
it('should fallback to empty cell value for dropdown', () => {
|
||||
let row = <DynamicTableRow> {value: {}};
|
||||
let column = <DynamicTableColumn> {id: 'key', type: 'Dropdown'};
|
||||
|
||||
expect(widget.getCellValue(row, column)).toBe('');
|
||||
});
|
||||
|
||||
it('should retrieve boolean cell value', () => {
|
||||
let row1 = <DynamicTableRow> {value: {key: true}};
|
||||
let row2 = <DynamicTableRow> {value: {key: 'positive'}};
|
||||
let row3 = <DynamicTableRow> {value: {key: null}};
|
||||
let column = <DynamicTableColumn> {id: 'key', type: 'Boolean'};
|
||||
|
||||
expect(widget.getCellValue(row1, column)).toBe(true);
|
||||
expect(widget.getCellValue(row2, column)).toBe(true);
|
||||
expect(widget.getCellValue(row3, column)).toBe(false);
|
||||
});
|
||||
|
||||
it('should retrieve date cell value', () => {
|
||||
const value = '2016-10-04T00:00:00.000Z';
|
||||
let row = <DynamicTableRow> {value: {key: value}};
|
||||
let column = <DynamicTableColumn> {id: 'key', type: 'Date'};
|
||||
|
||||
expect(widget.getCellValue(row, column)).toBe('4-10-2016');
|
||||
});
|
||||
|
||||
it('should fallback to empty cell value for date', () => {
|
||||
let row = <DynamicTableRow> {value: {}};
|
||||
let column = <DynamicTableColumn> {id: 'key', type: 'Date'};
|
||||
|
||||
expect(widget.getCellValue(row, column)).toBe('');
|
||||
});
|
||||
|
||||
it('should retrieve empty text cell value', () => {
|
||||
let row = <DynamicTableRow> {value: {}};
|
||||
let column = <DynamicTableColumn> {id: 'key'};
|
||||
|
||||
expect(widget.getCellValue(row, column)).toBe('');
|
||||
});
|
||||
|
||||
it('should prepend default amount currency', () => {
|
||||
const value = '10';
|
||||
let row = <DynamicTableRow> {value: {key: value}};
|
||||
let column = <DynamicTableColumn> {id: 'key', type: 'Amount'};
|
||||
|
||||
const expected = `$ ${value}`;
|
||||
expect(widget.getCellValue(row, column)).toBe(expected);
|
||||
});
|
||||
|
||||
it('should prepend custom amount currency', () => {
|
||||
const value = '10';
|
||||
const currency = 'GBP';
|
||||
let row = <DynamicTableRow> {value: {key: value}};
|
||||
let column = <DynamicTableColumn> {id: 'key', type: 'Amount', amountCurrency: currency};
|
||||
|
||||
const expected = `${currency} ${value}`;
|
||||
expect(widget.getCellValue(row, column)).toBe(expected);
|
||||
});
|
||||
|
||||
it('should use zero for missing amount', () => {
|
||||
const value = null;
|
||||
const currency = 'GBP';
|
||||
let row = <DynamicTableRow> {value: {key: value}};
|
||||
let column = <DynamicTableColumn> {id: 'key', type: 'Amount', amountCurrency: currency};
|
||||
|
||||
const expected = `${currency} 0`;
|
||||
expect(widget.getCellValue(row, column)).toBe(expected);
|
||||
});
|
||||
|
||||
describe('UI check', () => {
|
||||
let widgetUI: DisplayValueWidget;
|
||||
let fixture: ComponentFixture<DisplayValueWidget>;
|
||||
@@ -748,12 +619,16 @@ describe('DisplayValueWidget', () => {
|
||||
window['componentHandler'] = componentHandler;
|
||||
TestBed.configureTestingModule({
|
||||
imports: [CoreModule],
|
||||
declarations: [DisplayValueWidget, ActivitiContent],
|
||||
declarations: [
|
||||
DisplayValueWidget,
|
||||
ActivitiContent
|
||||
],
|
||||
providers: [
|
||||
EcmModelService,
|
||||
FormService,
|
||||
WidgetVisibilityService
|
||||
]
|
||||
],
|
||||
schemas: [ CUSTOM_ELEMENTS_SCHEMA ]
|
||||
}).compileComponents().then(() => {
|
||||
fixture = TestBed.createComponent(DisplayValueWidget);
|
||||
widgetUI = fixture.componentInstance;
|
||||
|
Reference in New Issue
Block a user