From 8c27dcddac4a5f5d5a11794d9cd64d3ae5e2cbc5 Mon Sep 17 00:00:00 2001 From: Beka Westberg Date: Mon, 9 Jan 2023 21:45:37 +0000 Subject: [PATCH] chore: add test for loading two procedure defs --- tests/mocha/blocks/procedures_test.js | 54 ++++++++++++++++++++++++++- 1 file changed, 53 insertions(+), 1 deletion(-) diff --git a/tests/mocha/blocks/procedures_test.js b/tests/mocha/blocks/procedures_test.js index 12c3ffdb2fd..87d0aa531b4 100644 --- a/tests/mocha/blocks/procedures_test.js +++ b/tests/mocha/blocks/procedures_test.js @@ -1985,7 +1985,7 @@ suite('Procedures', function() { }); }); - suite('extra serialization test cases', function() { + suite('full workspace serialization test cases', function() { test('definitions with parameters are properly rendered', function() { Blockly.serialization.workspaces.load({ "blocks": { @@ -2032,6 +2032,58 @@ suite('Procedures', function() { assertDefBlockStructure( this.workspace.getTopBlocks(false)[0], false, ['x'], ['varId']); }); + test( + 'multiple definitions pointing to the same model end up with ' + + 'different models', + function() { + Blockly.serialization.workspaces.load({ + "blocks": { + "languageVersion": 0, + "blocks": [ + { + "type": "procedures_defnoreturn", + "extraState": { + "procedureId": "procId", + }, + "fields": { + "NAME": "do something", + }, + }, + { + "type": "procedures_defnoreturn", + "y": 10, + "extraState": { + "procedureId": "procId", + }, + "fields": { + "NAME": "do something", + }, + }, + ], + }, + "procedures": [ + { + "id": "procId", + "name": "do something", + "returnTypes": null, + }, + ], + }, this.workspace); + const def1 = this.workspace.getTopBlocks(true)[0]; + const def2 = this.workspace.getTopBlocks(true)[1]; + chai.assert.equal( + def1.getProcedureModel().getName(), + 'do something', + 'Expected the first procedure definition to have the name in XML'); + chai.assert.equal( + def2.getProcedureModel().getName(), + 'do something2', + 'Expected the second procedure definition to be renamed'); + chai.assert.notEqual( + def1.getProcedureModel(), + def2.getProcedureModel(), + 'Expected the procedures to have different models'); + }); }); const testSuites = [