Add select custom field
[MAILPOET-2453]
This commit is contained in:
committed by
Rostislav Wolný
parent
81c75fafc2
commit
ea11fdf5fb
@@ -107,6 +107,22 @@ const customCheckBox = {
|
||||
},
|
||||
};
|
||||
|
||||
const customSelectBlock = {
|
||||
clientId: '5',
|
||||
isValid: true,
|
||||
innerBlocks: [],
|
||||
name: 'mailpoet-form/custom-select',
|
||||
attributes: {
|
||||
label: 'Select',
|
||||
labelWithinInput: false,
|
||||
mandatory: false,
|
||||
customFieldId: 6,
|
||||
values: [
|
||||
{ name: 'option 1' },
|
||||
{ name: 'option 2' },
|
||||
],
|
||||
},
|
||||
};
|
||||
|
||||
const dividerBlock = {
|
||||
clientId: 'some_random_123',
|
||||
@@ -297,6 +313,33 @@ describe('Blocks to Form Body', () => {
|
||||
expect(input.params.validate).to.eq('alphanum');
|
||||
});
|
||||
|
||||
it('Should map custom select field', () => {
|
||||
const customField = {
|
||||
created_at: '2019-12-10T15:05:06+00:00',
|
||||
id: 6,
|
||||
name: 'Custom Select',
|
||||
params: {
|
||||
label: 'Select',
|
||||
required: '1',
|
||||
values: [
|
||||
{ value: 'option 1' },
|
||||
],
|
||||
},
|
||||
type: 'select',
|
||||
updated_at: '2019-12-10T15:05:06+00:00',
|
||||
};
|
||||
const [input] = formBlocksToBody([customSelectBlock], [customField]);
|
||||
checkBodyInputBasics(input);
|
||||
expect(input.id).to.be.equal('6');
|
||||
expect(input.name).to.be.equal('Custom Select');
|
||||
expect(input.type).to.be.equal('select');
|
||||
expect(input.position).to.be.equal('1');
|
||||
expect(input.params.label).to.be.equal('Select');
|
||||
expect(input.params.values).to.be.an('Array').that.has.length(2);
|
||||
expect(input.params.values[0]).to.have.property('value', 'option 1');
|
||||
expect(input.params.values[1]).to.have.property('value', 'option 2');
|
||||
});
|
||||
|
||||
it('Should map custom radio field', () => {
|
||||
const customField = {
|
||||
created_at: '2019-12-10T15:05:06+00:00',
|
||||
|
@@ -103,6 +103,24 @@ const customRadioInput = {
|
||||
},
|
||||
position: null,
|
||||
};
|
||||
const customSelectInput = {
|
||||
type: 'select',
|
||||
name: 'Custom select',
|
||||
id: '5',
|
||||
unique: '1',
|
||||
static: '0',
|
||||
params: {
|
||||
required: '',
|
||||
label: 'Select',
|
||||
label_within: '1',
|
||||
values: [
|
||||
{
|
||||
value: 'option 1',
|
||||
},
|
||||
],
|
||||
},
|
||||
position: null,
|
||||
};
|
||||
const customCheckboxInput = {
|
||||
type: 'checkbox',
|
||||
name: 'Custom check',
|
||||
@@ -365,6 +383,33 @@ describe('Form Body To Blocks', () => {
|
||||
expect(block.attributes.values[0]).to.have.property('isChecked', true);
|
||||
});
|
||||
|
||||
it('Should map custom select input to block', () => {
|
||||
const customField = {
|
||||
type: 'select',
|
||||
name: 'Custom select',
|
||||
id: 5,
|
||||
params: {
|
||||
required: '',
|
||||
label: 'Select',
|
||||
values: [
|
||||
{
|
||||
value: 'option 1',
|
||||
},
|
||||
],
|
||||
},
|
||||
position: null,
|
||||
};
|
||||
const [block] = formBodyToBlocks([{ ...customSelectInput, position: '1' }], [customField]);
|
||||
checkBlockBasics(block);
|
||||
expect(block.clientId).to.be.equal('5_0');
|
||||
expect(block.name).to.be.equal('mailpoet-form/custom-select-customselect');
|
||||
expect(block.attributes.label).to.be.equal('Select');
|
||||
expect(block.attributes.mandatory).to.be.equal(false);
|
||||
expect(block.attributes.labelWithinInput).to.be.equal(true);
|
||||
expect(block.attributes.values).to.be.an('Array').that.has.length(1);
|
||||
expect(block.attributes.values[0]).to.have.property('name', 'option 1');
|
||||
});
|
||||
|
||||
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