Add sanitization for missing label to mapper

[MAILPOET-2592]
This commit is contained in:
Rostislav Wolny
2020-01-07 10:14:52 +01:00
committed by Rostislav Wolný
parent 2a70a7cf2f
commit 8806e4e8f8
2 changed files with 12 additions and 2 deletions

View File

@@ -78,8 +78,8 @@ export default (data, customFields = []) => {
if (item.params && has(item.params, 'label_within')) {
mapped.attributes.labelWithinInput = !!item.params.label_within;
}
if (item.params && has(item.params, 'label')) {
mapped.attributes.label = item.params.label;
if (item.params) {
mapped.attributes.label = item.params.label ? item.params.label : null;
}
switch (item.id) {
case 'email':
@@ -121,11 +121,13 @@ export default (data, customFields = []) => {
name: 'mailpoet-form/submit-button',
};
case 'divider':
delete mapped.attributes.label;
return {
...mapped,
name: 'mailpoet-form/divider',
};
case 'html':
delete mapped.attributes.label;
return {
...mapped,
name: 'mailpoet-form/html',

View File

@@ -219,6 +219,14 @@ describe('Form Body To Blocks', () => {
expect(block.attributes.labelWithinInput).to.be.equal(true);
});
it('Should add a label if label is missing in data', () => {
const input = { ...emailInput, position: '1' };
delete input.params.label;
const [block] = formBodyToBlocks([{ ...emailInput, position: '1' }]);
checkBlockBasics(block);
expect(block.attributes.label).to.be.equal(null);
});
it('Should map first name input to block', () => {
const [block] = formBodyToBlocks([{ ...firstNameInput, position: '1' }]);
checkBlockBasics(block);