AAE-23165 Not blocking task completion when there's no value selected in required radio buttons widget (#9836)

* AAE-23165 Fix

* AAE-23165 Update
This commit is contained in:
Wiktor Danielewski
2024-06-20 15:18:29 +02:00
committed by GitHub
parent 9a544307d4
commit af552bfbb9
2 changed files with 51 additions and 41 deletions

View File

@@ -22,7 +22,6 @@ import { FormFieldModel } from './form-field.model';
import { FormModel } from './form.model'; import { FormModel } from './form.model';
describe('FormFieldModel', () => { describe('FormFieldModel', () => {
it('should store the form reference', () => { it('should store the form reference', () => {
const form = new FormModel(); const form = new FormModel();
const model = new FormFieldModel(form); const model = new FormFieldModel(form);
@@ -70,7 +69,7 @@ describe('FormFieldModel', () => {
expect(field.options).toBeDefined(); expect(field.options).toBeDefined();
expect(field.options.length).toBe(0); expect(field.options.length).toBe(0);
field = new FormFieldModel(new FormModel(), {options: null}); field = new FormFieldModel(new FormModel(), { options: null });
expect(field.options).toBeDefined(); expect(field.options).toBeDefined();
expect(field.options.length).toBe(0); expect(field.options.length).toBe(0);
}); });
@@ -79,13 +78,13 @@ describe('FormFieldModel', () => {
let field = new FormFieldModel(new FormModel(), null); let field = new FormFieldModel(new FormModel(), null);
expect(field.params).toEqual({}); expect(field.params).toEqual({});
field = new FormFieldModel(new FormModel(), {params: null}); field = new FormFieldModel(new FormModel(), { params: null });
expect(field.params).toEqual({}); expect(field.params).toEqual({});
}); });
it('should update form on every value change', () => { it('should update form on every value change', () => {
const form = new FormModel(); const form = new FormModel();
const field = new FormFieldModel(form, {id: 'field1'}); const field = new FormFieldModel(form, { id: 'field1' });
const value = 10; const value = 10;
spyOn(field, 'updateForm').and.callThrough(); spyOn(field, 'updateForm').and.callThrough();
@@ -107,7 +106,7 @@ describe('FormFieldModel', () => {
it('should take own readonly state if form is writable', () => { it('should take own readonly state if form is writable', () => {
const form = new FormModel(); const form = new FormModel();
const field = new FormFieldModel(form, {readOnly: true}); const field = new FormFieldModel(form, { readOnly: true });
expect(form.readOnly).toBeFalsy(); expect(form.readOnly).toBeFalsy();
expect(field.readOnly).toBeTruthy(); expect(field.readOnly).toBeTruthy();
@@ -251,7 +250,7 @@ describe('FormFieldModel', () => {
expect(field.value).toBe('28-04-2017'); expect(field.value).toBe('28-04-2017');
}); });
it('should set the value to today\'s date when the value is today', () => { it('should set the value to todays date when the value is today', () => {
const form = new FormModel(); const form = new FormModel();
const field = new FormFieldModel(form, { const field = new FormFieldModel(form, {
fieldType: 'FormFieldRepresentation', fieldType: 'FormFieldRepresentation',
@@ -488,9 +487,9 @@ describe('FormFieldModel', () => {
const field = new FormFieldModel(new FormModel(), { const field = new FormFieldModel(new FormModel(), {
type: FormFieldTypes.DROPDOWN, type: FormFieldTypes.DROPDOWN,
options: [ options: [
{id: 'empty', name: 'Choose option...'}, { id: 'empty', name: 'Choose option...' },
{id: 'fake-option-2', name: 'fake label 2'}, { id: 'fake-option-2', name: 'fake label 2' },
{id: 'fake-option-3', name: 'fake label 3'} { id: 'fake-option-3', name: 'fake label 3' }
], ],
value: 'fake-option-2' value: 'fake-option-2'
}); });
@@ -502,9 +501,9 @@ describe('FormFieldModel', () => {
const field = new FormFieldModel(new FormModel(), { const field = new FormFieldModel(new FormModel(), {
type: FormFieldTypes.DROPDOWN, type: FormFieldTypes.DROPDOWN,
options: [ options: [
{id: 'fake-option-1', name: 'fake label 1'}, { id: 'fake-option-1', name: 'fake label 1' },
{id: 'fake-option-2', name: 'fake label 2'}, { id: 'fake-option-2', name: 'fake label 2' },
{id: 'fake-option-3', name: 'fake label 3'} { id: 'fake-option-3', name: 'fake label 3' }
], ],
value: [], value: [],
selectionType: 'multiple' selectionType: 'multiple'
@@ -517,8 +516,8 @@ describe('FormFieldModel', () => {
const field = new FormFieldModel(new FormModel(), { const field = new FormFieldModel(new FormModel(), {
type: FormFieldTypes.RADIO_BUTTONS, type: FormFieldTypes.RADIO_BUTTONS,
options: [ options: [
{id: 'opt1', name: 'Option 1'}, { id: 'opt1', name: 'Option 1' },
{id: 'opt2', name: 'Option 2'} { id: 'opt2', name: 'Option 2' }
], ],
value: 'opt2' value: 'opt2'
}); });
@@ -582,8 +581,8 @@ describe('FormFieldModel', () => {
id: 'dropdown-2', id: 'dropdown-2',
type: FormFieldTypes.DROPDOWN, type: FormFieldTypes.DROPDOWN,
options: [ options: [
{id: 'opt1', name: 'Option 1'}, { id: 'opt1', name: 'Option 1' },
{id: 'opt2', name: 'Option 2'} { id: 'opt2', name: 'Option 2' }
] ]
}); });
@@ -597,8 +596,8 @@ describe('FormFieldModel', () => {
id: 'radio-1', id: 'radio-1',
type: FormFieldTypes.RADIO_BUTTONS, type: FormFieldTypes.RADIO_BUTTONS,
options: [ options: [
{id: 'opt1', name: 'Option 1'}, { id: 'opt1', name: 'Option 1' },
{id: 'opt2', name: 'Option 2'} { id: 'opt2', name: 'Option 2' }
] ]
}); });
@@ -606,19 +605,34 @@ describe('FormFieldModel', () => {
expect(form.values['radio-1']).toEqual(field.options[1]); expect(form.values['radio-1']).toEqual(field.options[1]);
}); });
it('radio button value should be null when no default is set', () => { it('should update form with null when radio button value does NOT match any option', () => {
const form = new FormModel(); const form = new FormModel();
const field = new FormFieldModel(form, { const field = new FormFieldModel(form, {
id: 'radio-2', id: 'radio-2',
type: FormFieldTypes.RADIO_BUTTONS, type: FormFieldTypes.RADIO_BUTTONS,
options: [ options: [
{id: 'opt1', name: 'Option 1'}, { id: 'opt1', name: 'Option 1' },
{id: 'opt2', name: 'Option 2'} { id: 'opt2', name: 'Option 2' }
] ]
}); });
field.value = 'missing'; field.value = 'missing';
expect(form.values['radio-2']).toBeUndefined(); expect(form.values['radio-2']).toBe(null);
});
it('should update form with null when radio button value is null', () => {
const form = new FormModel();
const field = new FormFieldModel(form, {
id: 'radio-2',
type: FormFieldTypes.RADIO_BUTTONS,
options: [
{ id: 'opt1', name: 'Option 1' },
{ id: 'opt2', name: 'Option 2' }
]
});
field.value = null;
expect(form.values['radio-2']).toBe(null);
}); });
it('should not update form with display-only field value', () => { it('should not update form with display-only field value', () => {
@@ -641,8 +655,8 @@ describe('FormFieldModel', () => {
id: 'dropdown-happy', id: 'dropdown-happy',
type: FormFieldTypes.DROPDOWN, type: FormFieldTypes.DROPDOWN,
options: [ options: [
{id: 'opt1', name: 'Option 1'}, { id: 'opt1', name: 'Option 1' },
{id: 'opt2', name: 'Option 2'} { id: 'opt2', name: 'Option 2' }
] ]
}); });
@@ -714,8 +728,8 @@ describe('FormFieldModel', () => {
required: false, required: false,
readOnly: true, readOnly: true,
options: [ options: [
{id: 'opt1', name: 'Option 1'}, { id: 'opt1', name: 'Option 1' },
{id: 'opt2', name: 'Option 2'} { id: 'opt2', name: 'Option 2' }
] ]
}); });
field.updateForm(); field.updateForm();
@@ -737,8 +751,8 @@ describe('FormFieldModel', () => {
restIdProperty: 'fake-id-property', restIdProperty: 'fake-id-property',
restLabelProperty: 'fake-label-property', restLabelProperty: 'fake-label-property',
options: [ options: [
{id: 'opt1', name: 'Option 1'}, { id: 'opt1', name: 'Option 1' },
{id: 'opt2', name: 'Option 2'} { id: 'opt2', name: 'Option 2' }
] ]
}); });
field.updateForm(); field.updateForm();
@@ -759,8 +773,8 @@ describe('FormFieldModel', () => {
restUrl: 'fake-url-just-to-show', restUrl: 'fake-url-just-to-show',
optionType: 'rest', optionType: 'rest',
options: [ options: [
{id: 'opt1', name: 'Option 1'}, { id: 'opt1', name: 'Option 1' },
{id: 'opt2', name: 'Option 2'} { id: 'opt2', name: 'Option 2' }
] ]
}); });
field.updateForm(); field.updateForm();
@@ -783,8 +797,8 @@ describe('FormFieldModel', () => {
restLabelProperty: 'banLabel', restLabelProperty: 'banLabel',
optionType: 'rest', optionType: 'rest',
options: [ options: [
{id: 'opt1', name: 'Option 1'}, { id: 'opt1', name: 'Option 1' },
{id: 'opt2', name: 'Option 2'} { id: 'opt2', name: 'Option 2' }
] ]
}); });
field.updateForm(); field.updateForm();
@@ -805,8 +819,8 @@ describe('FormFieldModel', () => {
restUrl: '<whatever-url-you-like-we-do-not-mind>', restUrl: '<whatever-url-you-like-we-do-not-mind>',
optionType: 'rest', optionType: 'rest',
options: [ options: [
{id: 'opt1', name: 'Option 1'}, { id: 'opt1', name: 'Option 1' },
{id: 'opt2', name: 'Option 2'} { id: 'opt2', name: 'Option 2' }
] ]
}); });
field.updateForm(); field.updateForm();
@@ -840,7 +854,6 @@ describe('FormFieldModel', () => {
}); });
describe('variables', () => { describe('variables', () => {
let form: FormModel; let form: FormModel;
beforeEach(() => { beforeEach(() => {
@@ -907,7 +920,6 @@ describe('FormFieldModel', () => {
expect(field.value).toBe('default hello'); expect(field.value).toBe('default hello');
}); });
}); });
it('should validate readOnly field if it is validatable', () => { it('should validate readOnly field if it is validatable', () => {

View File

@@ -406,10 +406,8 @@ export class FormFieldModel extends FormWidgetModel {
break; break;
} }
case FormFieldTypes.RADIO_BUTTONS: { case FormFieldTypes.RADIO_BUTTONS: {
const radioButton: FormFieldOption[] = this.options.filter((opt) => opt.id === this.value); const radioButton: FormFieldOption = this.options.find((opt) => opt.id === this.value);
if (radioButton.length > 0) { this.form.values[this.id] = radioButton || null;
this.form.values[this.id] = radioButton[0];
}
break; break;
} }
case FormFieldTypes.UPLOAD: { case FormFieldTypes.UPLOAD: {
@@ -472,7 +470,7 @@ export class FormFieldModel extends FormWidgetModel {
case FormFieldTypes.DECIMAL: { case FormFieldTypes.DECIMAL: {
this.form.values[this.id] = parseFloat(this.value); this.form.values[this.id] = parseFloat(this.value);
break; break;
}; }
case FormFieldTypes.BOOLEAN: { case FormFieldTypes.BOOLEAN: {
this.form.values[this.id] = this.value !== null && this.value !== undefined ? this.value : false; this.form.values[this.id] = this.value !== null && this.value !== undefined ? this.value : false;
break; break;