fix: serializing edited shadows (#5424)

* fix: serializing shadows

* tests: add tests for serializing editted shadows
This commit is contained in:
Beka Westberg
2021-09-03 20:35:23 +00:00
committed by alschmiedt
parent 410365f4a1
commit 448c433abe
2 changed files with 57 additions and 1 deletions

View File

@@ -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;

View File

@@ -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() {