Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 5 additions & 8 deletions blocks/lists.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1046,22 +1046,19 @@ blocks['lists_split'] = {

/**
* Returns the state of this block as a JSON serializable object.
* This block does not need to serialize any specific state as it is already
* encoded in the dropdown values, but must have an implementation to avoid
* the backward compatible XML mutations being serialized.
*
* @returns The state of this block.
*/
saveExtraState: function (this: SplitBlock): null {
return null;
saveExtraState: function (this: SplitBlock): {mode: string} {
return {'mode': this.getFieldValue('MODE')};
},

/**
* Applies the given state to this block.
* No extra state is needed or expected as it is already encoded in the
* dropdown values.
*/
loadExtraState: function (this: SplitBlock) {},
loadExtraState: function (this: SplitBlock, state: {mode: string}) {
this.updateType_(state['mode']);
},
};

// Register provided blocks.
Expand Down
56 changes: 49 additions & 7 deletions tests/mocha/blocks/lists_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -181,16 +181,58 @@ suite('Lists', function () {
* Test cases for serialization tests.
* @type {Array<SerializationTestCase>}
*/
const testCases = makeTestCasesForBlockNotNeedingExtraState_(
const testCases = [
{
'type': 'lists_split',
'id': '1',
'fields': {
'MODE': 'SPLIT',
title: 'JSON for splitting',
json: {
type: 'lists_split',
id: '1',
extraState: {mode: 'SPLIT'},
fields: {MODE: 'SPLIT'},
inputs: {
DELIM: {
shadow: {
type: 'text',
id: '2',
fields: {
TEXT: ',',
},
},
},
},
},
assertBlockStructure: (block) => {
assert.equal(block.type, 'lists_split');
assert.deepEqual(block.outputConnection.getCheck(), ['Array']);
assert.isTrue(block.getField('MODE').getValue() === 'SPLIT');
},
},
'<mutation mode="SPLIT"></mutation>',
);
{
title: 'JSON for joining',
json: {
type: 'lists_split',
id: '1',
extraState: {mode: 'JOIN'},
fields: {MODE: 'JOIN'},
inputs: {
DELIM: {
shadow: {
type: 'text',
id: '2',
fields: {
TEXT: ',',
},
},
},
},
},
assertBlockStructure: (block) => {
assert.equal(block.type, 'lists_split');
assert.deepEqual(block.outputConnection.getCheck(), ['String']);
assert.isTrue(block.getField('MODE').getValue() === 'JOIN');
},
},
];
runSerializationTestSuite(testCases);
});
});
Loading