Add data mappers for custom html block
[MAILPOET-2462]
This commit is contained in:
committed by
Pavel Dohnal
parent
5d5bcd6ab0
commit
d3bc831f69
@@ -83,6 +83,17 @@ export default (blocks) => {
|
||||
static: '0',
|
||||
params: '',
|
||||
};
|
||||
case 'mailpoet-form/custom-html':
|
||||
return {
|
||||
...mapped,
|
||||
id: 'html',
|
||||
type: 'html',
|
||||
name: 'Custom text or HTML',
|
||||
static: '0',
|
||||
params: {
|
||||
text: block.attributes && block.attributes.content ? block.attributes.content : '',
|
||||
},
|
||||
};
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
|
@@ -70,6 +70,15 @@ export default (data) => {
|
||||
name: 'mailpoet-form/divider',
|
||||
clientId: `divider_${index}`,
|
||||
};
|
||||
case 'html':
|
||||
return {
|
||||
...mapped,
|
||||
name: 'mailpoet-form/custom-html',
|
||||
clientId: `custom_html_${index}`,
|
||||
attributes: {
|
||||
content: item.params && item.params.text ? item.params.text : '',
|
||||
},
|
||||
};
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
|
@@ -67,6 +67,16 @@ const dividerBlock = {
|
||||
attributes: {},
|
||||
};
|
||||
|
||||
const customHtmlBlock = {
|
||||
clientId: 'some_random_321',
|
||||
isValid: true,
|
||||
innerBlocks: [],
|
||||
name: 'mailpoet-form/custom-html',
|
||||
attributes: {
|
||||
content: 'HTML content',
|
||||
},
|
||||
};
|
||||
|
||||
const checkBodyInputBasics = (input) => {
|
||||
expect(input.id).to.be.a('string');
|
||||
expect(parseInt(input.position, 10)).to.be.a('number');
|
||||
@@ -202,6 +212,18 @@ describe('Blocks to Form Body', () => {
|
||||
expect(divider2.position).to.be.equal('2');
|
||||
});
|
||||
|
||||
it('Should custom html block to form data', () => {
|
||||
const [html] = formBlocksToBody([customHtmlBlock]);
|
||||
checkBodyInputBasics(html);
|
||||
expect(html.id).to.be.equal('html');
|
||||
expect(html.name).to.be.equal('Custom text or HTML');
|
||||
expect(html.type).to.be.equal('html');
|
||||
expect(html.position).to.be.equal('1');
|
||||
expect(html.unique).to.be.equal('0');
|
||||
expect(html.static).to.be.equal('0');
|
||||
expect(html.params.text).to.be.equal('HTML content');
|
||||
});
|
||||
|
||||
it('Should map multiple blocks at once', () => {
|
||||
const unknownBlock = {
|
||||
name: 'unknown',
|
||||
|
@@ -82,6 +82,18 @@ const divider = {
|
||||
position: null,
|
||||
};
|
||||
|
||||
const customHtml = {
|
||||
type: 'html,',
|
||||
name: 'Custom text or HTML',
|
||||
id: 'html',
|
||||
unique: '0',
|
||||
static: '0',
|
||||
params: {
|
||||
text: 'test',
|
||||
},
|
||||
position: null,
|
||||
};
|
||||
|
||||
const checkBlockBasics = (block) => {
|
||||
expect(block.clientId).to.be.a('string');
|
||||
expect(block.name).to.be.a('string');
|
||||
@@ -191,10 +203,26 @@ describe('Form Body To Blocks', () => {
|
||||
checkBlockBasics(block1);
|
||||
expect(block1.clientId).to.be.equal('divider_0');
|
||||
expect(block1.name).to.be.equal('mailpoet-form/divider');
|
||||
checkBlockBasics(block2);
|
||||
expect(block2.clientId).to.be.equal('divider_1');
|
||||
expect(block2.name).to.be.equal('mailpoet-form/divider');
|
||||
});
|
||||
|
||||
it('Should map custom html to blocks', () => {
|
||||
const [block1, block2] = formBodyToBlocks([
|
||||
{ ...customHtml, position: '1', params: { text: '123' } },
|
||||
{ ...customHtml, position: '2', params: { text: 'nice one' } },
|
||||
]);
|
||||
checkBlockBasics(block1);
|
||||
expect(block1.clientId).to.be.equal('custom_html_0');
|
||||
expect(block1.name).to.be.equal('mailpoet-form/custom-html');
|
||||
expect(block1.attributes.content).to.be.equal('123');
|
||||
checkBlockBasics(block2);
|
||||
expect(block2.clientId).to.be.equal('custom_html_1');
|
||||
expect(block2.name).to.be.equal('mailpoet-form/custom-html');
|
||||
expect(block2.attributes.content).to.be.equal('nice one');
|
||||
});
|
||||
|
||||
it('Should ignore unknown input type', () => {
|
||||
const blocks = formBodyToBlocks([{ ...submitInput, id: 'some-nonsense' }]);
|
||||
expect(blocks).to.be.empty;
|
||||
|
Reference in New Issue
Block a user