Register custom date blocks and add mappings
[MAILPOET-2453]
This commit is contained in:
committed by
Rostislav Wolný
parent
aef6832ca0
commit
080d5c84ac
@ -130,6 +130,21 @@ const customSelectBlock = {
|
||||
},
|
||||
};
|
||||
|
||||
const customDateBlock = {
|
||||
clientId: '5',
|
||||
isValid: true,
|
||||
innerBlocks: [],
|
||||
name: 'mailpoet-form/custom-date',
|
||||
attributes: {
|
||||
label: 'Date',
|
||||
mandatory: false,
|
||||
customFieldId: 6,
|
||||
dateType: 'month_year',
|
||||
dateFormat: 'MM/YYYY',
|
||||
defaultToday: true,
|
||||
},
|
||||
};
|
||||
|
||||
const dividerBlock = {
|
||||
clientId: 'some_random_123',
|
||||
isValid: true,
|
||||
@ -404,6 +419,33 @@ describe('Blocks to Form Body', () => {
|
||||
expect(input.params.values[0]).to.have.property('is_checked', '1');
|
||||
});
|
||||
|
||||
it('Should map custom date field', () => {
|
||||
const customField = {
|
||||
created_at: '2019-12-13T15:22:07+00:00',
|
||||
id: 6,
|
||||
name: 'Custom Date',
|
||||
params: {
|
||||
required: '1',
|
||||
is_default_today: '1',
|
||||
date_type: 'month_year',
|
||||
date_format: 'YYYY/MM',
|
||||
},
|
||||
type: 'date',
|
||||
updated_at: '2019-12-13T15:22:07+00:00',
|
||||
};
|
||||
const [input] = formBlocksToBody([customDateBlock], [customField]);
|
||||
checkBodyInputBasics(input);
|
||||
expect(input.id).to.be.equal('6');
|
||||
expect(input.name).to.be.equal('Custom Date');
|
||||
expect(input.type).to.be.equal('date');
|
||||
expect(input.position).to.be.equal('1');
|
||||
expect(input.params.label).to.be.equal('Date');
|
||||
expect(input.params.required).to.be.undefined;
|
||||
expect(input.params.date_type).to.be.equal('month_year');
|
||||
expect(input.params.date_format).to.be.equal('MM/YYYY');
|
||||
expect(input.params.is_default_today).to.be.equal('1');
|
||||
});
|
||||
|
||||
it('Should map multiple blocks at once', () => {
|
||||
const unknownBlock = {
|
||||
name: 'unknown',
|
||||
|
@ -140,6 +140,21 @@ const customCheckboxInput = {
|
||||
},
|
||||
position: null,
|
||||
};
|
||||
const customDateInput = {
|
||||
type: 'date',
|
||||
name: 'Custom date',
|
||||
id: '6',
|
||||
unique: '1',
|
||||
static: '0',
|
||||
params: {
|
||||
required: '1',
|
||||
label: 'Date',
|
||||
date_type: 'month_year',
|
||||
date_format: 'MM/YYYY',
|
||||
is_default_today: true,
|
||||
},
|
||||
position: null,
|
||||
};
|
||||
const divider = {
|
||||
type: 'divider',
|
||||
name: 'Divider',
|
||||
@ -410,6 +425,31 @@ describe('Form Body To Blocks', () => {
|
||||
expect(block.attributes.values[0]).to.have.property('name', 'option 1');
|
||||
});
|
||||
|
||||
it('Should map custom date input to block', () => {
|
||||
const customField = {
|
||||
created_at: '2019-12-13T15:22:07+00:00',
|
||||
id: 6,
|
||||
name: 'Custom Date',
|
||||
params: {
|
||||
required: '1',
|
||||
is_default_today: '1',
|
||||
date_type: 'month_year',
|
||||
date_format: 'YYYY/MM',
|
||||
},
|
||||
type: 'date',
|
||||
updated_at: '2019-12-13T15:22:07+00:00',
|
||||
};
|
||||
const [block] = formBodyToBlocks([{ ...customDateInput, position: '1' }], [customField]);
|
||||
checkBlockBasics(block);
|
||||
expect(block.clientId).to.be.equal('6_0');
|
||||
expect(block.name).to.be.equal('mailpoet-form/custom-date-customdate');
|
||||
expect(block.attributes.label).to.be.equal('Date');
|
||||
expect(block.attributes.mandatory).to.be.true;
|
||||
expect(block.attributes.dateFormat).to.be.equal('MM/YYYY');
|
||||
expect(block.attributes.dateType).to.be.equal('month_year');
|
||||
expect(block.attributes.defaultToday).to.be.true;
|
||||
});
|
||||
|
||||
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