feat: add JSO serialization and deserialization of variables (#5131)

* Add variable serialization tests

* Fix requires for new file

* Add serialization and deserialization of variables

* Remove only in tests

* Cleanup
This commit is contained in:
Beka Westberg
2021-08-06 08:45:47 -07:00
committed by alschmiedt
parent 56d3cb6c8f
commit 28ff2c84c6
5 changed files with 96 additions and 11 deletions

View File

@@ -26,15 +26,16 @@ suite('JSO', function() {
sharedTestTeardown.call(this);
});
function assertProperty(obj, property, value) {
chai.assert.deepEqual(obj[property], value);
}
function assertNoProperty(obj, property) {
assertProperty(obj, property, undefined);
}
suite('Blocks', function() {
function assertProperty(obj, property, value) {
chai.assert.deepEqual(obj[property], value);
}
function assertNoProperty(obj, property) {
assertProperty(obj, property, undefined);
}
test('Null on insertionMarkers', function() {
const block = this.workspace.newBlock('row_block');
block.setInsertionMarker(true);
@@ -634,4 +635,23 @@ suite('JSO', function() {
});
});
});
suite('Variables', function() {
test('Without type', function() {
const variable = this.workspace.createVariable('testVar', '', 'testId');
const jso = Blockly.serialization.variables.save(variable);
assertProperty(jso, 'name', 'testVar');
assertProperty(jso, 'id', 'testId');
assertNoProperty(jso, 'type');
});
test('With type', function() {
const variable = this.workspace
.createVariable('testVar', 'testType', 'testId');
const jso = Blockly.serialization.variables.save(variable);
assertProperty(jso, 'name', 'testVar');
assertProperty(jso, 'id', 'testId');
assertProperty(jso, 'type', 'testType');
});
});
});