Add sanitization for missing label to mapper
[MAILPOET-2592]
This commit is contained in:
committed by
Rostislav Wolný
parent
2a70a7cf2f
commit
8806e4e8f8
@@ -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',
|
||||
|
@@ -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);
|
||||
|
Reference in New Issue
Block a user