diff --git a/blocks/procedures.js b/blocks/procedures.js
index 49ce8a046..c5b7a6307 100644
--- a/blocks/procedures.js
+++ b/blocks/procedures.js
@@ -591,6 +591,7 @@ const procedureDefMutator = {
}
}
+ this.doProcedureUpdate();
this.setStatements_(state['hasStatements'] === false ? false : true);
// Call mutate callers for backwards compatibility.
diff --git a/tests/mocha/blocks/procedures_test.js b/tests/mocha/blocks/procedures_test.js
index ae8a5ba2c..ed293a5b1 100644
--- a/tests/mocha/blocks/procedures_test.js
+++ b/tests/mocha/blocks/procedures_test.js
@@ -1985,6 +1985,55 @@ suite('Procedures', function() {
});
});
+ suite('extra serialization test cases', function() {
+ test('definitions with parameters are properly rendered', function() {
+ Blockly.serialization.workspaces.load({
+ "blocks": {
+ "languageVersion": 0,
+ "blocks": [
+ {
+ "type": "procedures_defnoreturn",
+ "extraState": {
+ "procedureId": "procId",
+ "params": [
+ {
+ "name": "x",
+ "id": "varId",
+ "paramId": "paramId",
+ },
+ ],
+ },
+ "fields": {
+ "NAME": "do something",
+ },
+ },
+ ],
+ },
+ "procedures": [
+ {
+ "id": "procId",
+ "name": "do something",
+ "returnTypes": null,
+ "parameters": [
+ {
+ "id": "paramId",
+ "name": "x",
+ },
+ ],
+ },
+ ],
+ "variables": [
+ {
+ "name": "x",
+ "id": "varId",
+ },
+ ],
+ }, this.workspace);
+ assertDefBlockStructure(
+ this.workspace.getTopBlocks(false)[0], false, ['x'], ['varId']);
+ });
+ });
+
const testSuites = [
{title: 'procedures_defreturn', hasReturn: true,
defType: 'procedures_defreturn', callType: 'procedures_callreturn'},
@@ -2480,7 +2529,7 @@ suite('Procedures', function() {
*/
const testCases = [
{
- title: 'Minimal definition',
+ title: 'XML - Minimal definition',
xml: '',
expectedXml:
'' +
' do something' +
@@ -2509,8 +2558,7 @@ suite('Procedures', function() {
},
},
{
- title: 'With vars definition',
- skip: true,
+ title: 'XML - With vars definition',
xml:
'\n' +
' \n' +
@@ -2535,8 +2583,7 @@ suite('Procedures', function() {
},
},
{
- title: 'With pre-created vars definition',
- skip: true,
+ title: 'XML - With pre-created vars definition',
xml:
'\n' +
' \n' +
@@ -2559,31 +2606,7 @@ suite('Procedures', function() {
},
},
{
- title: 'With pre-created typed vars definition',
- skip: true,
- xml:
- '\n' +
- ' \n' +
- ' \n' +
- ' \n' +
- ' do something\n' +
- '',
- expectedXml:
- '\n' +
- ' \n' +
- ' \n' +
- ' \n' +
- ' do something\n' +
- '',
- assertBlockStructure:
- (block) => {
- assertDefBlockStructure(block, testSuite.hasReturn,
- ['preCreatedTypedVar'], ['preCreatedTypedVarId']);
- },
- },
- {
- title: 'No statements definition',
+ title: 'XML - No statements definition',
xml:
'\n' +
' \n' +
@@ -2601,7 +2624,7 @@ suite('Procedures', function() {
},
},
{
- title: 'Minimal caller',
+ title: 'XML - Minimal caller',
xml: '',
expectedXml:
'\n' +
' \n' +
@@ -2630,7 +2653,7 @@ suite('Procedures', function() {
},
},
{
- title: 'With pre-created vars caller',
+ title: 'XML - With pre-created vars caller',
xml:
'\n' +
' \n' +
@@ -2649,6 +2672,226 @@ suite('Procedures', function() {
assertCallBlockStructure(block, ['preCreatedVar'], ['preCreatedVarId']);
},
},
+ {
+ title: 'JSON - Minimal definition',
+ json: {
+ 'type': testSuite.defType,
+ },
+ expectedJson: {
+ 'type': testSuite.defType,
+ 'id': '1',
+ 'fields': {
+ 'NAME': 'unnamed',
+ },
+ 'extraState': {
+ 'procedureId': '1',
+ },
+ },
+ assertBlockStructure:
+ (block) => {
+ assertDefBlockStructure(block, testSuite.hasReturn);
+ },
+ },
+ {
+ title: 'JSON - Common definition',
+ json: {
+ 'type': testSuite.defType,
+ 'fields': {
+ 'NAME': 'do something',
+ },
+ },
+ expectedJson: {
+ 'type': testSuite.defType,
+ 'id': '1',
+ 'fields': {
+ 'NAME': 'do something',
+ },
+ 'extraState': {
+ 'procedureId': '1',
+ },
+ },
+ assertBlockStructure:
+ (block) => {
+ assertDefBlockStructure(block, testSuite.hasReturn);
+ },
+ },
+ {
+ title: 'JSON - With vars definition',
+ json: {
+ 'type': testSuite.defType,
+ 'fields': {
+ 'NAME': 'do something',
+ },
+ 'extraState': {
+ 'params': [
+ {
+ 'name': 'x',
+ 'id': 'arg1',
+ },
+ {
+ 'name': 'y',
+ 'id': 'arg2',
+ },
+ ],
+ },
+ },
+ expectedJson: {
+ 'type': testSuite.defType,
+ 'id': '1',
+ 'fields': {
+ 'NAME': 'do something',
+ },
+ 'extraState': {
+ 'procedureId': '1',
+ 'params': [
+ {
+ 'name': 'x',
+ 'id': 'arg1',
+ 'paramId': '1',
+ },
+ {
+ 'name': 'y',
+ 'id': 'arg2',
+ 'paramId': '1',
+ },
+ ],
+ },
+ },
+ assertBlockStructure:
+ (block) => {
+ assertDefBlockStructure(
+ block, testSuite.hasReturn, ['x', 'y'], ['arg1', 'arg2']);
+ },
+ },
+ {
+ title: 'JSON - With pre-created vars definition',
+ json: {
+ 'type': testSuite.defType,
+ 'extraState': {
+ 'params': [
+ {
+ 'name': 'preCreatedVar',
+ 'id': 'preCreatedVarId',
+ },
+ ],
+ },
+ 'fields': {
+ 'NAME': 'do something',
+ },
+ },
+ expectedJson: {
+ 'type': testSuite.defType,
+ 'id': '1',
+ 'fields': {
+ 'NAME': 'do something',
+ },
+ 'extraState': {
+ 'procedureId': '1',
+ 'params': [
+ {
+ 'name': 'preCreatedVar',
+ 'id': 'preCreatedVarId',
+ 'paramId': '1',
+ },
+ ],
+ },
+ },
+ assertBlockStructure:
+ (block) => {
+ assertDefBlockStructure(block, testSuite.hasReturn,
+ ['preCreatedVar'], ['preCreatedVarId']);
+ },
+ },
+ {
+ title: 'JSON - No statements definition',
+ json: {
+ 'type': 'procedures_defreturn',
+ 'fields': {
+ 'NAME': 'do something',
+ },
+ 'extraState': {
+ 'hasStatements': false,
+ },
+ },
+ expectedJson: {
+ 'type': 'procedures_defreturn',
+ 'id': '1',
+ 'fields': {
+ 'NAME': 'do something',
+ },
+ 'extraState': {
+ 'procedureId': '1',
+ 'hasStatements': false,
+ },
+ },
+ assertBlockStructure:
+ (block) => {
+ assertDefBlockStructure(block, true, [], [], false);
+ },
+ },
+ {
+ title: 'JSON - Minimal caller',
+ json: {
+ 'type': testSuite.callType,
+ },
+ expectedJson: {
+ 'type': testSuite.callType,
+ 'id': '1',
+ 'extraState': {
+ 'name': 'unnamed',
+ },
+ },
+ assertBlockStructure:
+ (block) => {
+ assertCallBlockStructure(block);
+ },
+ },
+ {
+ title: 'JSON - Common caller',
+ json: {
+ 'type': testSuite.callType,
+ 'extraState': {
+ 'name': 'do something',
+ },
+ },
+ expectedJson: {
+ 'type': testSuite.callType,
+ 'id': '1',
+ 'extraState': {
+ 'name': 'do something',
+ },
+ },
+ assertBlockStructure:
+ (block) => {
+ assertCallBlockStructure(block);
+ },
+ },
+ {
+ title: 'JSON - With pre-created vars caller',
+ json: {
+ 'type': testSuite.callType,
+ 'extraState': {
+ 'name': 'do something',
+ 'params': [
+ 'preCreatedVar',
+ ],
+ },
+ },
+ expectedJson: {
+ 'type': testSuite.callType,
+ 'id': '1',
+ 'extraState': {
+ 'name': 'do something',
+ 'params': [
+ 'preCreatedVar',
+ ],
+ },
+ },
+ assertBlockStructure:
+ (block) => {
+ assertCallBlockStructure(block, ['preCreatedVar'], ['preCreatedVarId']);
+ },
+ },
];
runSerializationTestSuite(testCases);
});
diff --git a/tests/mocha/test_helpers/serialization.js b/tests/mocha/test_helpers/serialization.js
index 94fc511d5..09c340921 100644
--- a/tests/mocha/test_helpers/serialization.js
+++ b/tests/mocha/test_helpers/serialization.js
@@ -79,7 +79,7 @@ export const runSerializationTestSuite = (testCases) => {
return function() {
if (testCase.json) {
const block = Blockly.serialization.blocks.append(
- testCase.json, this.workspace);
+ testCase.json, this.workspace, {recordUndo: true});
this.clock.runAll();
const generatedJson = Blockly.serialization.blocks.save(block);
const expectedJson = testCase.expectedJson || testCase.json;