fix dynamic table validation (#1741)

- dynamic table widget no longer creates a copy of field model, but
uses original one, fixes the problem with validation and state
management
- update unit tests
This commit is contained in:
Denys Vuika
2017-03-22 09:58:12 +00:00
committed by Mario Romano
parent 88da9a181b
commit 76009fcd46
6 changed files with 24 additions and 23 deletions

View File

@@ -18,7 +18,7 @@
import { LogServiceMock } from 'ng2-alfresco-core';
import { DynamicTableWidget } from './dynamic-table.widget';
import { DynamicTableModel, DynamicTableRow, DynamicTableColumn } from './dynamic-table.widget.model';
import { FormModel, FormFieldTypes } from './../core/index';
import { FormModel, FormFieldTypes, FormFieldModel } from './../core/index';
import { WidgetVisibilityService } from '../../../services/widget-visibility.service';
describe('DynamicTableWidget', () => {
@@ -30,7 +30,8 @@ describe('DynamicTableWidget', () => {
beforeEach(() => {
logService = new LogServiceMock();
table = new DynamicTableModel(null);
const field = new FormFieldModel(new FormModel());
table = new DynamicTableModel(field);
visibilityService = new WidgetVisibilityService(null, logService);
widget = new DynamicTableWidget(null, visibilityService, logService);
widget.content = table;
@@ -223,11 +224,12 @@ describe('DynamicTableWidget', () => {
it('should take validation state from underlying field', () => {
let form = new FormModel();
widget.content = new DynamicTableModel(form, {
let field = new FormFieldModel(form, {
type: FormFieldTypes.DYNAMIC_TABLE,
required: true,
value: null
});
widget.content = new DynamicTableModel(field);
expect(widget.content.field.validate()).toBeFalsy();
expect(widget.isValid()).toBe(widget.content.field.isValid);