mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-07-24 17:32:15 +00:00
[AAE-3273] Manage empty option in retrieve content metadata dropdowns (#6024)
* AAE-3273 Manage empty option in retrieve content metadata dropdowns * AAE-3273 Add unit tests * AAE-3273 Refactor add not present fields * AAE-3273 Add unit test in core
This commit is contained in:
committed by
GitHub
parent
a7af27cfad
commit
c1435c53e0
@@ -24,6 +24,7 @@ import { FormFieldModel } from './form-field.model';
|
||||
import { FormOutcomeModel } from './form-outcome.model';
|
||||
import { FormModel } from './form.model';
|
||||
import { TabModel } from './tab.model';
|
||||
import { fakeMetadataForm } from 'process-services-cloud/src/lib/form/mocks/cloud-form.mock';
|
||||
|
||||
describe('FormModel', () => {
|
||||
let formService: FormService;
|
||||
@@ -558,4 +559,34 @@ describe('FormModel', () => {
|
||||
expect(missing).toBeUndefined();
|
||||
});
|
||||
});
|
||||
|
||||
describe('add values not present', () => {
|
||||
let form: FormModel;
|
||||
|
||||
beforeEach(() => {
|
||||
form = new FormModel(fakeMetadataForm);
|
||||
form.values['pfx_property_three'] = {};
|
||||
form.values['pfx_property_four'] = 'empty';
|
||||
form.values['pfx_property_five'] = 'green';
|
||||
});
|
||||
|
||||
it('should not find a process variable', () => {
|
||||
const values = {
|
||||
pfx_property_one: 'testValue',
|
||||
pfx_property_two: true,
|
||||
pfx_property_three: 'opt_1',
|
||||
pfx_property_four: 'option_2',
|
||||
pfx_property_five: 'orange',
|
||||
pfx_property_none: 'no_form_field'
|
||||
};
|
||||
|
||||
const data = form.addValuesNotPresent(values);
|
||||
|
||||
expect(data).toContain({ name: 'pfx_property_one', value: 'testValue' });
|
||||
expect(data).toContain({ name: 'pfx_property_two', value: true });
|
||||
expect(data).toContain({ name: 'pfx_property_three', value: 'opt_1' });
|
||||
expect(data).toContain({ name: 'pfx_property_four', value: 'option_2' });
|
||||
expect(data).toContain({ name: 'pfx_property_five', value: 'green' });
|
||||
});
|
||||
});
|
||||
});
|
||||
|
@@ -375,4 +375,24 @@ export class FormModel {
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
addValuesNotPresent(valuesToSetIfNotPresent: FormValues): { name: string; value: any }[] {
|
||||
const keys = Object.keys(valuesToSetIfNotPresent);
|
||||
keys.forEach(key => {
|
||||
if (!this.values[key] || this.isEmptyDropdownOption(key)) {
|
||||
this.values[key] = valuesToSetIfNotPresent[key];
|
||||
}
|
||||
});
|
||||
const data = [];
|
||||
const fields = Object.keys(this.values);
|
||||
fields.forEach(field => data.push({ name: field, value: this.values[field] }));
|
||||
return data;
|
||||
}
|
||||
|
||||
private isEmptyDropdownOption(key: string): boolean {
|
||||
if (this.getFieldById(key) && (this.getFieldById(key).type === FormFieldTypes.DROPDOWN)) {
|
||||
return typeof this.values[key] === 'string' ? this.values[key] === 'empty' : Object.keys(this.values[key]).length === 0;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user