Skip to content

Commit

Permalink
fix: serializing edited shadows (google#5424)
Browse files Browse the repository at this point in the history
* fix: serializing shadows

* tests: add tests for serializing editted shadows
  • Loading branch information
BeksOmega authored and alschmiedt committed Sep 20, 2021
1 parent 410365f commit 448c433
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 1 deletion.
2 changes: 1 addition & 1 deletion core/serialization/blocks.js
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ const saveNextBlocks = function(block, state) {
* shadow block, or any connected real block.
*/
const saveConnection = function(connection) {
const shadow = connection.getShadowState();
const shadow = connection.getShadowState(true);
const child = connection.targetBlock();
if (!shadow && !child) {
return null;
Expand Down
56 changes: 56 additions & 0 deletions tests/mocha/jso_serialization_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -431,6 +431,62 @@ suite('JSO Serialization', function() {
};
});

suite('Editing shadow value', function() {
test('Not overwritten', function() {
const block = this.workspace.newBlock('text_print');
block.getInput('TEXT').connection.setShadowState({
'type': 'text',
'id': 'id'
});
block.getInputTargetBlock('TEXT').setFieldValue('new value', 'TEXT');
const jso = Blockly.serialization.blocks.save(block);
this.assertInput(
jso,
'TEXT',
{
'shadow': {
'type': 'text',
'id': 'id',
'fields': {
'TEXT': 'new value'
}
}
});
});

test('Overwritten', function() {
const block = this.workspace.newBlock('text_print');
block.getInput('TEXT').connection.setShadowState({
'type': 'text',
'id': 'id'
});
block.getInputTargetBlock('TEXT').setFieldValue('new value', 'TEXT');
const childBlock = this.workspace.newBlock('text');
block.getInput('TEXT').connection.connect(
childBlock.outputConnection);
const jso = Blockly.serialization.blocks.save(block);
this.assertInput(
jso,
'TEXT',
{
'shadow': {
'type': 'text',
'id': 'id',
'fields': {
'TEXT': 'new value'
}
},
'block': {
'type': 'text',
'id': 'id3',
'fields': {
'TEXT': ''
}
},
});
});
});

suite('Value', function() {
suite('With serialization', function() {
test('Child', function() {
Expand Down

0 comments on commit 448c433

Please sign in to comment.