mirror of
https://github.com/google/blockly.git
synced 2026-01-07 17:10:11 +01:00
fix: dragging variables from flyout (#5434)
* fix: dragging variables from flyout * fix: rename positionBlock_ to positionNewBlock_ * fix: type * fix: try alternative method for handling variables in flyout
This commit is contained in:
committed by
alschmiedt
parent
ee221520a9
commit
0e0c5fea0e
@@ -394,21 +394,50 @@ suite('Variable Fields', function() {
|
||||
workspaceTeardown.call(this, this.workspace);
|
||||
});
|
||||
|
||||
test('Untyped', function() {
|
||||
const block = this.workspace.newBlock('row_block');
|
||||
const field = new Blockly.FieldVariable('x');
|
||||
block.getInput('INPUT').appendField(field, 'VAR');
|
||||
const jso = Blockly.serialization.blocks.save(block);
|
||||
chai.assert.deepEqual(jso['fields'], {'VAR': {'id': 'id2'}});
|
||||
suite('Full', function() {
|
||||
test('Untyped', function() {
|
||||
const block = this.workspace.newBlock('row_block');
|
||||
const field = new Blockly.FieldVariable('x');
|
||||
block.getInput('INPUT').appendField(field, 'VAR');
|
||||
const jso = Blockly.serialization.blocks.save(block);
|
||||
chai.assert.deepEqual(
|
||||
jso['fields'], {'VAR': {'id': 'id2', 'name': 'x', 'type': ''}});
|
||||
});
|
||||
|
||||
test('Typed', function() {
|
||||
const block = this.workspace.newBlock('row_block');
|
||||
const field =
|
||||
new Blockly.FieldVariable('x', undefined, undefined, 'String');
|
||||
block.getInput('INPUT').appendField(field, 'VAR');
|
||||
const jso = Blockly.serialization.blocks.save(block);
|
||||
chai.assert.deepEqual(
|
||||
jso['fields'], {'VAR': {'id': 'id2', 'name': 'x', 'type': 'String'}});
|
||||
});
|
||||
});
|
||||
|
||||
test('Typed', function() {
|
||||
const block = this.workspace.newBlock('row_block');
|
||||
const field =
|
||||
new Blockly.FieldVariable('x', undefined, undefined, ['String']);
|
||||
block.getInput('INPUT').appendField(field, 'VAR');
|
||||
const jso = Blockly.serialization.blocks.save(block);
|
||||
chai.assert.deepEqual(jso['fields'], {'VAR': {'id': 'id2'}});
|
||||
suite('Not full', function() {
|
||||
test('Untyped', function() {
|
||||
const block = this.workspace.newBlock('row_block');
|
||||
const field = new Blockly.FieldVariable('x');
|
||||
block.getInput('INPUT').appendField(field, 'VAR');
|
||||
const jso = Blockly.serialization.blocks.save(
|
||||
block, {doFullSerialization: false});
|
||||
chai.assert.deepEqual(jso['fields'], {'VAR': {'id': 'id2'}});
|
||||
chai.assert.isUndefined(jso['fields']['VAR']['name']);
|
||||
chai.assert.isUndefined(jso['fields']['VAR']['type']);
|
||||
});
|
||||
|
||||
test('Typed', function() {
|
||||
const block = this.workspace.newBlock('row_block');
|
||||
const field =
|
||||
new Blockly.FieldVariable('x', undefined, undefined, 'String');
|
||||
block.getInput('INPUT').appendField(field, 'VAR');
|
||||
const jso = Blockly.serialization.blocks.save(
|
||||
block, {doFullSerialization: false});
|
||||
chai.assert.deepEqual(jso['fields'], {'VAR': {'id': 'id2'}});
|
||||
chai.assert.isUndefined(jso['fields']['VAR']['name']);
|
||||
chai.assert.isUndefined(jso['fields']['VAR']['type']);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@@ -699,6 +699,78 @@ suite('JSO Serialization', function() {
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
suite('Do full serialization', function() {
|
||||
suite('True', function() {
|
||||
test('Single block', function() {
|
||||
var block = this.workspace.newBlock('variables_get');
|
||||
var jso = Blockly.serialization.blocks.save(block);
|
||||
chai.assert.deepEqual(
|
||||
jso['fields']['VAR'], {'id': 'id2', 'name': 'item', 'type': ''});
|
||||
});
|
||||
|
||||
test('Input block', function() {
|
||||
var block = this.workspace.newBlock('row_block');
|
||||
var childBlock = this.workspace.newBlock('variables_get');
|
||||
block.getInput('INPUT').connection.connect(
|
||||
childBlock.outputConnection);
|
||||
var jso = Blockly.serialization.blocks.save(block);
|
||||
chai.assert.deepEqual(
|
||||
jso['inputs']['INPUT']['block']['fields']['VAR'],
|
||||
{'id': 'id4', 'name': 'item', 'type': ''});
|
||||
});
|
||||
|
||||
test('Next block', function() {
|
||||
var block = this.workspace.newBlock('stack_block');
|
||||
var childBlock = this.workspace.newBlock('variables_set');
|
||||
block.nextConnection.connect(childBlock.previousConnection);
|
||||
var jso = Blockly.serialization.blocks.save(block);
|
||||
chai.assert.deepEqual(
|
||||
jso['next']['block']['fields']['VAR'],
|
||||
{'id': 'id4', 'name': 'item', 'type': ''});
|
||||
});
|
||||
});
|
||||
|
||||
suite('False', function() {
|
||||
test('Single block', function() {
|
||||
var block = this.workspace.newBlock('variables_get');
|
||||
var jso = Blockly.serialization.blocks.save(
|
||||
block, {doFullSerialization: false});
|
||||
chai.assert.deepEqual(jso['fields']['VAR'], {'id': 'id2'});
|
||||
chai.assert.isUndefined(jso['fields']['VAR']['name']);
|
||||
chai.assert.isUndefined(jso['fields']['VAR']['type']);
|
||||
});
|
||||
|
||||
test('Input block', function() {
|
||||
var block = this.workspace.newBlock('row_block');
|
||||
var childBlock = this.workspace.newBlock('variables_get');
|
||||
block.getInput('INPUT').connection.connect(
|
||||
childBlock.outputConnection);
|
||||
var jso = Blockly.serialization.blocks.save(
|
||||
block, {doFullSerialization: false});
|
||||
chai.assert.deepEqual(
|
||||
jso['inputs']['INPUT']['block']['fields']['VAR'], {'id': 'id4'});
|
||||
chai.assert.isUndefined(
|
||||
jso['inputs']['INPUT']['block']['fields']['VAR']['name']);
|
||||
chai.assert.isUndefined(
|
||||
jso['inputs']['INPUT']['block']['fields']['VAR']['type']);
|
||||
});
|
||||
|
||||
test('Next block', function() {
|
||||
var block = this.workspace.newBlock('stack_block');
|
||||
var childBlock = this.workspace.newBlock('variables_set');
|
||||
block.nextConnection.connect(childBlock.previousConnection);
|
||||
var jso = Blockly.serialization.blocks.save(
|
||||
block, {doFullSerialization: false});
|
||||
chai.assert.deepEqual(
|
||||
jso['next']['block']['fields']['VAR'], {'id': 'id4'});
|
||||
chai.assert.isUndefined(
|
||||
jso['next']['block']['fields']['VAR']['name']);
|
||||
chai.assert.isUndefined(
|
||||
jso['next']['block']['fields']['VAR']['type']);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
suite('Variables', function() {
|
||||
|
||||
Reference in New Issue
Block a user