mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2026-09-09 18:03:21 +00:00
fix test
This commit is contained in:
@@ -146,7 +146,7 @@ describe('FormFieldModel', () => {
|
||||
});
|
||||
|
||||
expect(field.options).toEqual([{ id: 'id_one', name: 'One' }]);
|
||||
expect(field.value).toEqual([{ id: 'id_one', name: 'One' }]);
|
||||
expect(field.value).toEqual({ id: 'id_one', name: 'One' });
|
||||
});
|
||||
|
||||
it('should add value (selected options) to field options if NOT present (multiple selection)', () => {
|
||||
@@ -179,21 +179,6 @@ describe('FormFieldModel', () => {
|
||||
expect(field.value).toEqual({ id: 'empty', name: 'Chose one...' });
|
||||
});
|
||||
|
||||
it('should assign "empty" option as value if value is null and "empty" option is present in options', () => {
|
||||
const field = new FormFieldModel(new FormModel(), {
|
||||
type: FormFieldTypes.DROPDOWN,
|
||||
options: [
|
||||
{ id: '', name: 'Chose one...' },
|
||||
{ id: 'one', name: 'One' }
|
||||
],
|
||||
value: null
|
||||
});
|
||||
|
||||
expect(field.hasEmptyValue).toBe(true);
|
||||
expect(field.emptyOption).toEqual({ id: '', name: 'Chose one...' });
|
||||
expect(field.value).toEqual({ id: '', name: 'Chose one...' });
|
||||
});
|
||||
|
||||
it('should set hasEmptyValue to true if "empty" option is present in options', () => {
|
||||
const field = new FormFieldModel(new FormModel(), {
|
||||
type: FormFieldTypes.DROPDOWN,
|
||||
@@ -287,7 +272,8 @@ describe('FormFieldModel', () => {
|
||||
options: [],
|
||||
value: { id: 'delayed-option-id', name: 'Delayed option' }
|
||||
});
|
||||
expect(field.value).toBe({ id: 'delayed-option-id', name: 'Delayed option' });
|
||||
|
||||
expect(field.value).toEqual({ id: 'delayed-option-id', name: 'Delayed option' });
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -1038,7 +1024,7 @@ describe('FormFieldModel', () => {
|
||||
expect(field.options).toEqual(staticOptions);
|
||||
});
|
||||
|
||||
it('should selected option appear in form values', () => {
|
||||
it('should selected option appear in form values string', () => {
|
||||
const field = getFieldConfig('manual', staticOptions, 'opt2');
|
||||
|
||||
field.updateForm();
|
||||
@@ -1047,13 +1033,13 @@ describe('FormFieldModel', () => {
|
||||
expect(field.form.values['dropdown_field']).toEqual({ id: 'opt2', name: 'Option 2' });
|
||||
});
|
||||
|
||||
it('should selected option appear in form values', () => {
|
||||
it('should selected option appear in form values obj', () => {
|
||||
const field = getFieldConfig('manual', staticOptions, { id: 'opt3', name: 'opt3' });
|
||||
|
||||
field.updateForm();
|
||||
|
||||
expect(field.value).toEqual('opt2');
|
||||
expect(field.form.values['dropdown_field']).toEqual({ id: 'opt2', name: 'Option 2' });
|
||||
expect(field.value).toEqual({ id: 'opt3', name: 'opt3' });
|
||||
expect(field.form.values['dropdown_field']).toEqual({ id: 'opt3', name: 'opt3' });
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
+1
-1
@@ -1008,7 +1008,7 @@ describe('DropdownCloudWidgetComponent', () => {
|
||||
widget['setFormControlValue']();
|
||||
|
||||
expect(widget.dropdownControl.setValue).toHaveBeenCalledWith({ id: 'testValueObj', name: 'testValueObjName' }, { emitEvent: false });
|
||||
expect(widget.dropdownControl.value).toEqual({ id: 'testValue', name: '' });
|
||||
expect(widget.dropdownControl.value).toEqual({ id: 'testValueObj', name: 'testValueObjName' });
|
||||
});
|
||||
|
||||
it('should display options persisted from process variable', async () => {
|
||||
|
||||
+5
-1
@@ -195,8 +195,12 @@ export class DropdownCloudWidgetComponent extends WidgetComponent implements OnI
|
||||
}
|
||||
|
||||
private setFormControlValue(): void {
|
||||
if (this.field?.value && typeof this.field?.value === 'object') {
|
||||
if (Array.isArray(this.field.value)) {
|
||||
this.dropdownControl.setValue(this.field?.value, { emitEvent: false });
|
||||
} else if (this.field?.value && typeof this.field?.value === 'object') {
|
||||
this.dropdownControl.setValue({ id: this.field?.value.id, name: this.field?.value.name }, { emitEvent: false });
|
||||
} else if (this.field.value === null) {
|
||||
this.dropdownControl.setValue(this.field?.value, { emitEvent: false });
|
||||
} else {
|
||||
this.dropdownControl.setValue({ id: this.field?.value, name: '' }, { emitEvent: false });
|
||||
}
|
||||
|
||||
+1
-11
@@ -35,7 +35,7 @@ describe('defaultValueValidator', () => {
|
||||
|
||||
it('should return null when a valid option is selected', () => {
|
||||
const validator = defaultValueValidator(mockField);
|
||||
const control = new FormControl('opt_1');
|
||||
const control = new FormControl({ id: 'opt_1' });
|
||||
|
||||
const result = validator(control);
|
||||
|
||||
@@ -59,14 +59,4 @@ describe('defaultValueValidator', () => {
|
||||
|
||||
expect(result).toEqual({ required: true });
|
||||
});
|
||||
|
||||
it('should return null when the field has no options', () => {
|
||||
mockField.options = [];
|
||||
const validator = defaultValueValidator(mockField);
|
||||
const control = new FormControl('opt_1');
|
||||
|
||||
const result = validator(control);
|
||||
|
||||
expect(result).toBeNull();
|
||||
});
|
||||
});
|
||||
|
||||
@@ -941,7 +941,7 @@ describe('FormComponent', () => {
|
||||
|
||||
let dropdownField = formFields.find((field) => field.id === 'dropdownId');
|
||||
let radioField = formFields.find((field) => field.id === 'radio');
|
||||
expect(dropdownField.value).toBe('empty');
|
||||
expect(dropdownField.value).toEqual({ id: 'empty', name: 'Choose one...' });
|
||||
expect(radioField.value).toBeNull();
|
||||
|
||||
const formValues: any = {};
|
||||
@@ -961,7 +961,7 @@ describe('FormComponent', () => {
|
||||
dropdownField = formFields.find((field) => field.id === 'dropdownId');
|
||||
radioField = formFields.find((field) => field.id === 'radio');
|
||||
|
||||
expect(dropdownField.value).toBe({
|
||||
expect(dropdownField.value).toEqual({
|
||||
id: 'dropdown_option_2',
|
||||
name: 'Dropdown option 2'
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user