[ADF-5165] Fix Checkbok widget in completed tasks (#5979)

This commit is contained in:
davidcanonieto
2020-08-12 17:58:09 +01:00
committed by GitHub
parent 47883a3504
commit 9b3efb5502
2 changed files with 152 additions and 1 deletions

View File

@@ -249,6 +249,150 @@ describe('FormFieldModel', () => {
expect(field.value).toBe('28-04-2017');
});
it('should parse the checkbox set to "true" when it is readonly', () => {
const form = new FormModel();
const field = new FormFieldModel(form, {
fieldType: 'FormFieldRepresentation',
id: 'checkbox',
name: 'Checkbox',
type: 'readonly',
value: 'true',
required: false,
readOnly: true,
params: {
field: {
id: 'checkbox',
name: 'Checkbox',
type: 'boolean',
value: null,
required: false,
readOnly: false
}
}
});
expect(field.value).toBeTruthy();
});
it('should parse the checkbox set to null when it is readonly', () => {
const form = new FormModel();
const field = new FormFieldModel(form, {
fieldType: 'FormFieldRepresentation',
id: 'checkbox',
name: 'Checkbox',
type: 'readonly',
value: null,
required: false,
readOnly: true,
params: {
field: {
id: 'checkbox',
name: 'Checkbox',
type: 'boolean',
value: null,
required: false,
readOnly: false
}
}
});
expect(field.value).toBeFalsy();
});
it('should parse the checkbox set to "false" when it is readonly', () => {
const form = new FormModel();
const field = new FormFieldModel(form, {
fieldType: 'FormFieldRepresentation',
id: 'checkbox',
name: 'Checkbox',
type: 'readonly',
value: 'false',
required: false,
readOnly: true,
params: {
field: {
id: 'checkbox',
name: 'Checkbox',
type: 'boolean',
value: null,
required: false,
readOnly: false
}
}
});
expect(field.value).toBeFalsy();
});
it('should parse the checkbox set to "true" when it is editable', () => {
const form = new FormModel();
const field = new FormFieldModel(form, {
fieldType: 'FormFieldRepresentation',
id: 'checkbox',
name: 'Checkbox',
type: 'boolean',
value: 'true',
required: false,
readOnly: true,
params: {
field: {
id: 'checkbox',
name: 'Checkbox',
type: 'boolean',
value: null,
required: false,
readOnly: false
}
}
});
expect(field.value).toBeTruthy();
});
it('should parse the checkbox set to null when it is editable', () => {
const form = new FormModel();
const field = new FormFieldModel(form, {
fieldType: 'FormFieldRepresentation',
id: 'checkbox',
name: 'Checkbox',
type: 'boolean',
value: null,
required: false,
readOnly: true,
params: {
field: {
id: 'checkbox',
name: 'Checkbox',
type: 'boolean',
value: null,
required: false,
readOnly: false
}
}
});
expect(field.value).toBeFalsy();
});
it('should parse the checkbox set to "false" when it is editable', () => {
const form = new FormModel();
const field = new FormFieldModel(form, {
fieldType: 'FormFieldRepresentation',
id: 'checkbox',
name: 'Checkbox',
type: 'boolean',
value: 'false',
required: false,
readOnly: true,
params: {
field: {
id: 'checkbox',
name: 'Checkbox',
type: 'boolean',
value: null,
required: false,
readOnly: false
}
}
});
expect(field.value).toBeFalsy();
});
it('should return the label of selected dropdown value ', () => {
const field = new FormFieldModel(new FormModel(), {
type: FormFieldTypes.DROPDOWN,

View File

@@ -320,7 +320,7 @@ export class FormFieldModel extends FormWidgetModel {
}
}
if (json.type === FormFieldTypes.BOOLEAN) {
if (this.isCheckboxField(json)) {
value = json.value === 'true' || json.value === true ? true : false;
}
@@ -447,4 +447,11 @@ export class FormFieldModel extends FormWidgetModel {
json.type === FormFieldTypes.DATETIME;
}
private isCheckboxField(json: any): boolean {
return (json.params &&
json.params.field &&
json.params.field.type === FormFieldTypes.BOOLEAN) ||
json.type === FormFieldTypes.BOOLEAN;
}
}