mirror of
https://github.com/google/blockly.git
synced 2026-01-07 17:10:11 +01:00
chore: apply prefer-const rule fixes in mocha tests (#5682)
This commit is contained in:
1
package-lock.json
generated
1
package-lock.json
generated
@@ -5,6 +5,7 @@
|
|||||||
"requires": true,
|
"requires": true,
|
||||||
"packages": {
|
"packages": {
|
||||||
"": {
|
"": {
|
||||||
|
"name": "blockly",
|
||||||
"version": "7.20211209.0-beta.0",
|
"version": "7.20211209.0-beta.0",
|
||||||
"license": "Apache-2.0",
|
"license": "Apache-2.0",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
|||||||
@@ -73,12 +73,12 @@ suite('ASTNode', function() {
|
|||||||
]);
|
]);
|
||||||
this.workspace = new Blockly.Workspace();
|
this.workspace = new Blockly.Workspace();
|
||||||
this.cursor = this.workspace.cursor;
|
this.cursor = this.workspace.cursor;
|
||||||
let statementInput1 = this.workspace.newBlock('input_statement');
|
const statementInput1 = this.workspace.newBlock('input_statement');
|
||||||
let statementInput2 = this.workspace.newBlock('input_statement');
|
const statementInput2 = this.workspace.newBlock('input_statement');
|
||||||
let statementInput3 = this.workspace.newBlock('input_statement');
|
const statementInput3 = this.workspace.newBlock('input_statement');
|
||||||
let statementInput4 = this.workspace.newBlock('input_statement');
|
const statementInput4 = this.workspace.newBlock('input_statement');
|
||||||
let fieldWithOutput = this.workspace.newBlock('field_input');
|
const fieldWithOutput = this.workspace.newBlock('field_input');
|
||||||
let valueInput = this.workspace.newBlock('value_input');
|
const valueInput = this.workspace.newBlock('value_input');
|
||||||
|
|
||||||
statementInput1.nextConnection.connect(statementInput2.previousConnection);
|
statementInput1.nextConnection.connect(statementInput2.previousConnection);
|
||||||
statementInput1.inputList[0].connection
|
statementInput1.inputList[0].connection
|
||||||
@@ -101,69 +101,69 @@ suite('ASTNode', function() {
|
|||||||
|
|
||||||
suite('HelperFunctions', function() {
|
suite('HelperFunctions', function() {
|
||||||
test('findNextForInput_', function() {
|
test('findNextForInput_', function() {
|
||||||
let input = this.blocks.statementInput1.inputList[0];
|
const input = this.blocks.statementInput1.inputList[0];
|
||||||
let input2 = this.blocks.statementInput1.inputList[1];
|
const input2 = this.blocks.statementInput1.inputList[1];
|
||||||
let connection = input.connection;
|
const connection = input.connection;
|
||||||
let node = ASTNode.createConnectionNode(connection);
|
const node = ASTNode.createConnectionNode(connection);
|
||||||
let newASTNode = node.findNextForInput_(input);
|
const newASTNode = node.findNextForInput_(input);
|
||||||
chai.assert.equal(newASTNode.getLocation(), input2.connection);
|
chai.assert.equal(newASTNode.getLocation(), input2.connection);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('findPrevForInput_', function() {
|
test('findPrevForInput_', function() {
|
||||||
let input = this.blocks.statementInput1.inputList[0];
|
const input = this.blocks.statementInput1.inputList[0];
|
||||||
let input2 = this.blocks.statementInput1.inputList[1];
|
const input2 = this.blocks.statementInput1.inputList[1];
|
||||||
let connection = input2.connection;
|
const connection = input2.connection;
|
||||||
let node = ASTNode.createConnectionNode(connection);
|
const node = ASTNode.createConnectionNode(connection);
|
||||||
let newASTNode = node.findPrevForInput_(input2);
|
const newASTNode = node.findPrevForInput_(input2);
|
||||||
chai.assert.equal(newASTNode.getLocation(), input.connection);
|
chai.assert.equal(newASTNode.getLocation(), input.connection);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('findNextForField_', function() {
|
test('findNextForField_', function() {
|
||||||
let field = this.blocks.statementInput1.inputList[0].fieldRow[0];
|
const field = this.blocks.statementInput1.inputList[0].fieldRow[0];
|
||||||
let field2 = this.blocks.statementInput1.inputList[0].fieldRow[1];
|
const field2 = this.blocks.statementInput1.inputList[0].fieldRow[1];
|
||||||
let node = ASTNode.createFieldNode(field);
|
const node = ASTNode.createFieldNode(field);
|
||||||
let newASTNode = node.findNextForField_(field);
|
const newASTNode = node.findNextForField_(field);
|
||||||
chai.assert.equal(newASTNode.getLocation(), field2);
|
chai.assert.equal(newASTNode.getLocation(), field2);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('findPrevForField_', function() {
|
test('findPrevForField_', function() {
|
||||||
let field = this.blocks.statementInput1.inputList[0].fieldRow[0];
|
const field = this.blocks.statementInput1.inputList[0].fieldRow[0];
|
||||||
let field2 = this.blocks.statementInput1.inputList[0].fieldRow[1];
|
const field2 = this.blocks.statementInput1.inputList[0].fieldRow[1];
|
||||||
let node = ASTNode.createFieldNode(field2);
|
const node = ASTNode.createFieldNode(field2);
|
||||||
let newASTNode = node.findPrevForField_(field2);
|
const newASTNode = node.findPrevForField_(field2);
|
||||||
chai.assert.equal(newASTNode.getLocation(), field);
|
chai.assert.equal(newASTNode.getLocation(), field);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('navigateBetweenStacks_Forward', function() {
|
test('navigateBetweenStacks_Forward', function() {
|
||||||
let node = new ASTNode(
|
const node = new ASTNode(
|
||||||
ASTNode.types.NEXT, this.blocks.statementInput1.nextConnection);
|
ASTNode.types.NEXT, this.blocks.statementInput1.nextConnection);
|
||||||
let newASTNode = node.navigateBetweenStacks_(true);
|
const newASTNode = node.navigateBetweenStacks_(true);
|
||||||
chai.assert.equal(newASTNode.getLocation(), this.blocks.statementInput4);
|
chai.assert.equal(newASTNode.getLocation(), this.blocks.statementInput4);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('navigateBetweenStacks_Backward', function() {
|
test('navigateBetweenStacks_Backward', function() {
|
||||||
let node = new ASTNode(
|
const node = new ASTNode(
|
||||||
ASTNode.types.BLOCK, this.blocks.statementInput4);
|
ASTNode.types.BLOCK, this.blocks.statementInput4);
|
||||||
let newASTNode = node.navigateBetweenStacks_(false);
|
const newASTNode = node.navigateBetweenStacks_(false);
|
||||||
chai.assert.equal(newASTNode.getLocation(), this.blocks.statementInput1);
|
chai.assert.equal(newASTNode.getLocation(), this.blocks.statementInput1);
|
||||||
});
|
});
|
||||||
test('getOutAstNodeForBlock_', function() {
|
test('getOutAstNodeForBlock_', function() {
|
||||||
let node = new ASTNode(
|
const node = new ASTNode(
|
||||||
ASTNode.types.BLOCK, this.blocks.statementInput2);
|
ASTNode.types.BLOCK, this.blocks.statementInput2);
|
||||||
let newASTNode = node.getOutAstNodeForBlock_(this.blocks.statementInput2);
|
const newASTNode = node.getOutAstNodeForBlock_(this.blocks.statementInput2);
|
||||||
chai.assert.equal(newASTNode.getLocation(), this.blocks.statementInput1);
|
chai.assert.equal(newASTNode.getLocation(), this.blocks.statementInput1);
|
||||||
});
|
});
|
||||||
test('getOutAstNodeForBlock_OneBlock', function() {
|
test('getOutAstNodeForBlock_OneBlock', function() {
|
||||||
let node = new ASTNode(
|
const node = new ASTNode(
|
||||||
ASTNode.types.BLOCK, this.blocks.statementInput4);
|
ASTNode.types.BLOCK, this.blocks.statementInput4);
|
||||||
let newASTNode = node.getOutAstNodeForBlock_(this.blocks.statementInput4);
|
const newASTNode = node.getOutAstNodeForBlock_(this.blocks.statementInput4);
|
||||||
chai.assert.equal(newASTNode.getLocation(), this.blocks.statementInput4);
|
chai.assert.equal(newASTNode.getLocation(), this.blocks.statementInput4);
|
||||||
});
|
});
|
||||||
test('findFirstFieldOrInput_', function() {
|
test('findFirstFieldOrInput_', function() {
|
||||||
let node = new ASTNode(
|
const node = new ASTNode(
|
||||||
ASTNode.types.BLOCK, this.blocks.statementInput4);
|
ASTNode.types.BLOCK, this.blocks.statementInput4);
|
||||||
let field = this.blocks.statementInput4.inputList[0].fieldRow[0];
|
const field = this.blocks.statementInput4.inputList[0].fieldRow[0];
|
||||||
let newASTNode = node.findFirstFieldOrInput_(this.blocks.statementInput4);
|
const newASTNode = node.findFirstFieldOrInput_(this.blocks.statementInput4);
|
||||||
chai.assert.equal(newASTNode.getLocation(), field);
|
chai.assert.equal(newASTNode.getLocation(), field);
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -287,33 +287,33 @@ suite('ASTNode', function() {
|
|||||||
"helpUrl": "",
|
"helpUrl": "",
|
||||||
"nextStatement": null
|
"nextStatement": null
|
||||||
}]);
|
}]);
|
||||||
let noNextConnection = this.workspace.newBlock('top_connection');
|
const noNextConnection = this.workspace.newBlock('top_connection');
|
||||||
let fieldAndInputs = this.workspace.newBlock('fields_and_input');
|
const fieldAndInputs = this.workspace.newBlock('fields_and_input');
|
||||||
let twoFields = this.workspace.newBlock('two_fields');
|
const twoFields = this.workspace.newBlock('two_fields');
|
||||||
let fieldAndInputs2 = this.workspace.newBlock('fields_and_input2');
|
const fieldAndInputs2 = this.workspace.newBlock('fields_and_input2');
|
||||||
let noPrevConnection = this.workspace.newBlock('start_block');
|
const noPrevConnection = this.workspace.newBlock('start_block');
|
||||||
this.blocks.noNextConnection = noNextConnection;
|
this.blocks.noNextConnection = noNextConnection;
|
||||||
this.blocks.fieldAndInputs = fieldAndInputs;
|
this.blocks.fieldAndInputs = fieldAndInputs;
|
||||||
this.blocks.twoFields = twoFields;
|
this.blocks.twoFields = twoFields;
|
||||||
this.blocks.fieldAndInputs2 = fieldAndInputs2;
|
this.blocks.fieldAndInputs2 = fieldAndInputs2;
|
||||||
this.blocks.noPrevConnection = noPrevConnection;
|
this.blocks.noPrevConnection = noPrevConnection;
|
||||||
|
|
||||||
let dummyInput = this.workspace.newBlock('dummy_input');
|
const dummyInput = this.workspace.newBlock('dummy_input');
|
||||||
let dummyInputValue = this.workspace.newBlock('dummy_inputValue');
|
const dummyInputValue = this.workspace.newBlock('dummy_inputValue');
|
||||||
let fieldWithOutput2 = this.workspace.newBlock('field_input');
|
const fieldWithOutput2 = this.workspace.newBlock('field_input');
|
||||||
this.blocks.dummyInput = dummyInput;
|
this.blocks.dummyInput = dummyInput;
|
||||||
this.blocks.dummyInputValue = dummyInputValue;
|
this.blocks.dummyInputValue = dummyInputValue;
|
||||||
this.blocks.fieldWithOutput2 = fieldWithOutput2;
|
this.blocks.fieldWithOutput2 = fieldWithOutput2;
|
||||||
|
|
||||||
let secondBlock = this.workspace.newBlock('input_statement');
|
const secondBlock = this.workspace.newBlock('input_statement');
|
||||||
let outputNextBlock = this.workspace.newBlock('output_next');
|
const outputNextBlock = this.workspace.newBlock('output_next');
|
||||||
this.blocks.secondBlock = secondBlock;
|
this.blocks.secondBlock = secondBlock;
|
||||||
this.blocks.outputNextBlock = outputNextBlock;
|
this.blocks.outputNextBlock = outputNextBlock;
|
||||||
});
|
});
|
||||||
suite('Next', function() {
|
suite('Next', function() {
|
||||||
setup(function() {
|
setup(function() {
|
||||||
this.singleBlockWorkspace = new Blockly.Workspace();
|
this.singleBlockWorkspace = new Blockly.Workspace();
|
||||||
let singleBlock = this.singleBlockWorkspace.newBlock('two_fields');
|
const singleBlock = this.singleBlockWorkspace.newBlock('two_fields');
|
||||||
this.blocks.singleBlock = singleBlock;
|
this.blocks.singleBlock = singleBlock;
|
||||||
});
|
});
|
||||||
teardown(function() {
|
teardown(function() {
|
||||||
@@ -321,192 +321,192 @@ suite('ASTNode', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
test('fromPreviousToBlock', function() {
|
test('fromPreviousToBlock', function() {
|
||||||
let prevConnection = this.blocks.statementInput1.previousConnection;
|
const prevConnection = this.blocks.statementInput1.previousConnection;
|
||||||
let node = ASTNode.createConnectionNode(prevConnection);
|
const node = ASTNode.createConnectionNode(prevConnection);
|
||||||
let nextNode = node.next();
|
const nextNode = node.next();
|
||||||
chai.assert.equal(nextNode.getLocation(), this.blocks.statementInput1);
|
chai.assert.equal(nextNode.getLocation(), this.blocks.statementInput1);
|
||||||
});
|
});
|
||||||
test('fromBlockToNext', function() {
|
test('fromBlockToNext', function() {
|
||||||
let nextConnection = this.blocks.statementInput1.nextConnection;
|
const nextConnection = this.blocks.statementInput1.nextConnection;
|
||||||
let node = ASTNode.createBlockNode(this.blocks.statementInput1);
|
const node = ASTNode.createBlockNode(this.blocks.statementInput1);
|
||||||
let nextNode = node.next();
|
const nextNode = node.next();
|
||||||
chai.assert.equal(nextNode.getLocation(), nextConnection);
|
chai.assert.equal(nextNode.getLocation(), nextConnection);
|
||||||
});
|
});
|
||||||
test('fromBlockToNull', function() {
|
test('fromBlockToNull', function() {
|
||||||
let node = ASTNode.createBlockNode(this.blocks.noNextConnection);
|
const node = ASTNode.createBlockNode(this.blocks.noNextConnection);
|
||||||
let nextNode = node.next();
|
const nextNode = node.next();
|
||||||
chai.assert.isNull(nextNode);
|
chai.assert.isNull(nextNode);
|
||||||
});
|
});
|
||||||
test('fromNextToPrevious', function() {
|
test('fromNextToPrevious', function() {
|
||||||
let nextConnection = this.blocks.statementInput1.nextConnection;
|
const nextConnection = this.blocks.statementInput1.nextConnection;
|
||||||
let prevConnection = this.blocks.statementInput2.previousConnection;
|
const prevConnection = this.blocks.statementInput2.previousConnection;
|
||||||
let node = ASTNode.createConnectionNode(nextConnection);
|
const node = ASTNode.createConnectionNode(nextConnection);
|
||||||
let nextNode = node.next();
|
const nextNode = node.next();
|
||||||
chai.assert.equal(nextNode.getLocation(), prevConnection);
|
chai.assert.equal(nextNode.getLocation(), prevConnection);
|
||||||
});
|
});
|
||||||
test('fromNextToNull', function() {
|
test('fromNextToNull', function() {
|
||||||
let nextConnection = this.blocks.statementInput2.nextConnection;
|
const nextConnection = this.blocks.statementInput2.nextConnection;
|
||||||
let node = ASTNode.createConnectionNode(nextConnection);
|
const node = ASTNode.createConnectionNode(nextConnection);
|
||||||
let nextNode = node.next();
|
const nextNode = node.next();
|
||||||
chai.assert.isNull(nextNode);
|
chai.assert.isNull(nextNode);
|
||||||
});
|
});
|
||||||
test('fromInputToInput', function() {
|
test('fromInputToInput', function() {
|
||||||
let input = this.blocks.statementInput1.inputList[0];
|
const input = this.blocks.statementInput1.inputList[0];
|
||||||
let inputConnection = this.blocks.statementInput1.inputList[1].connection;
|
const inputConnection = this.blocks.statementInput1.inputList[1].connection;
|
||||||
let node = ASTNode.createInputNode(input);
|
const node = ASTNode.createInputNode(input);
|
||||||
let nextNode = node.next();
|
const nextNode = node.next();
|
||||||
chai.assert.equal(nextNode.getLocation(), inputConnection);
|
chai.assert.equal(nextNode.getLocation(), inputConnection);
|
||||||
});
|
});
|
||||||
test('fromInputToStatementInput', function() {
|
test('fromInputToStatementInput', function() {
|
||||||
let input = this.blocks.fieldAndInputs2.inputList[1];
|
const input = this.blocks.fieldAndInputs2.inputList[1];
|
||||||
let inputConnection = this.blocks.fieldAndInputs2.inputList[2].connection;
|
const inputConnection = this.blocks.fieldAndInputs2.inputList[2].connection;
|
||||||
let node = ASTNode.createInputNode(input);
|
const node = ASTNode.createInputNode(input);
|
||||||
let nextNode = node.next();
|
const nextNode = node.next();
|
||||||
chai.assert.equal(nextNode.getLocation(), inputConnection);
|
chai.assert.equal(nextNode.getLocation(), inputConnection);
|
||||||
});
|
});
|
||||||
test('fromInputToField', function() {
|
test('fromInputToField', function() {
|
||||||
let input = this.blocks.fieldAndInputs2.inputList[0];
|
const input = this.blocks.fieldAndInputs2.inputList[0];
|
||||||
let field = this.blocks.fieldAndInputs2.inputList[1].fieldRow[0];
|
const field = this.blocks.fieldAndInputs2.inputList[1].fieldRow[0];
|
||||||
let node = ASTNode.createInputNode(input);
|
const node = ASTNode.createInputNode(input);
|
||||||
let nextNode = node.next();
|
const nextNode = node.next();
|
||||||
chai.assert.equal(nextNode.getLocation(), field);
|
chai.assert.equal(nextNode.getLocation(), field);
|
||||||
});
|
});
|
||||||
test('fromInputToNull', function() {
|
test('fromInputToNull', function() {
|
||||||
let input = this.blocks.fieldAndInputs2.inputList[2];
|
const input = this.blocks.fieldAndInputs2.inputList[2];
|
||||||
let node = ASTNode.createInputNode(input);
|
const node = ASTNode.createInputNode(input);
|
||||||
let nextNode = node.next();
|
const nextNode = node.next();
|
||||||
chai.assert.isNull(nextNode);
|
chai.assert.isNull(nextNode);
|
||||||
});
|
});
|
||||||
test('fromOutputToBlock', function() {
|
test('fromOutputToBlock', function() {
|
||||||
let output = this.blocks.fieldWithOutput.outputConnection;
|
const output = this.blocks.fieldWithOutput.outputConnection;
|
||||||
let node = ASTNode.createConnectionNode(output);
|
const node = ASTNode.createConnectionNode(output);
|
||||||
let nextNode = node.next();
|
const nextNode = node.next();
|
||||||
chai.assert.equal(nextNode.getLocation(), this.blocks.fieldWithOutput);
|
chai.assert.equal(nextNode.getLocation(), this.blocks.fieldWithOutput);
|
||||||
});
|
});
|
||||||
test('fromFieldToInput', function() {
|
test('fromFieldToInput', function() {
|
||||||
let field = this.blocks.statementInput1.inputList[0].fieldRow[1];
|
const field = this.blocks.statementInput1.inputList[0].fieldRow[1];
|
||||||
let inputConnection = this.blocks.statementInput1.inputList[0].connection;
|
const inputConnection = this.blocks.statementInput1.inputList[0].connection;
|
||||||
let node = ASTNode.createFieldNode(field);
|
const node = ASTNode.createFieldNode(field);
|
||||||
let nextNode = node.next();
|
const nextNode = node.next();
|
||||||
chai.assert.equal(nextNode.getLocation(), inputConnection);
|
chai.assert.equal(nextNode.getLocation(), inputConnection);
|
||||||
});
|
});
|
||||||
test('fromFieldToField', function() {
|
test('fromFieldToField', function() {
|
||||||
let field = this.blocks.fieldAndInputs.inputList[0].fieldRow[0];
|
const field = this.blocks.fieldAndInputs.inputList[0].fieldRow[0];
|
||||||
let node = ASTNode.createFieldNode(field);
|
const node = ASTNode.createFieldNode(field);
|
||||||
let field2 = this.blocks.fieldAndInputs.inputList[1].fieldRow[0];
|
const field2 = this.blocks.fieldAndInputs.inputList[1].fieldRow[0];
|
||||||
let nextNode = node.next();
|
const nextNode = node.next();
|
||||||
chai.assert.equal(nextNode.getLocation(), field2);
|
chai.assert.equal(nextNode.getLocation(), field2);
|
||||||
});
|
});
|
||||||
test('fromFieldToNull', function() {
|
test('fromFieldToNull', function() {
|
||||||
let field = this.blocks.twoFields.inputList[0].fieldRow[0];
|
const field = this.blocks.twoFields.inputList[0].fieldRow[0];
|
||||||
let node = ASTNode.createFieldNode(field);
|
const node = ASTNode.createFieldNode(field);
|
||||||
let nextNode = node.next();
|
const nextNode = node.next();
|
||||||
chai.assert.isNull(nextNode);
|
chai.assert.isNull(nextNode);
|
||||||
});
|
});
|
||||||
test('fromStackToStack', function() {
|
test('fromStackToStack', function() {
|
||||||
let node = ASTNode.createStackNode(this.blocks.statementInput1);
|
const node = ASTNode.createStackNode(this.blocks.statementInput1);
|
||||||
let nextNode = node.next();
|
const nextNode = node.next();
|
||||||
chai.assert.equal(nextNode.getLocation(), this.blocks.statementInput4);
|
chai.assert.equal(nextNode.getLocation(), this.blocks.statementInput4);
|
||||||
chai.assert.equal(nextNode.getType(), ASTNode.types.STACK);
|
chai.assert.equal(nextNode.getType(), ASTNode.types.STACK);
|
||||||
});
|
});
|
||||||
test('fromStackToNull', function() {
|
test('fromStackToNull', function() {
|
||||||
let node = ASTNode.createStackNode(this.blocks.singleBlock);
|
const node = ASTNode.createStackNode(this.blocks.singleBlock);
|
||||||
let nextNode = node.next();
|
const nextNode = node.next();
|
||||||
chai.assert.isNull(nextNode);
|
chai.assert.isNull(nextNode);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
suite('Previous', function() {
|
suite('Previous', function() {
|
||||||
test('fromPreviousToNull', function() {
|
test('fromPreviousToNull', function() {
|
||||||
let prevConnection = this.blocks.statementInput1.previousConnection;
|
const prevConnection = this.blocks.statementInput1.previousConnection;
|
||||||
let node = ASTNode.createConnectionNode(prevConnection);
|
const node = ASTNode.createConnectionNode(prevConnection);
|
||||||
let prevNode = node.prev();
|
const prevNode = node.prev();
|
||||||
chai.assert.isNull(prevNode);
|
chai.assert.isNull(prevNode);
|
||||||
});
|
});
|
||||||
test('fromPreviousToNext', function() {
|
test('fromPreviousToNext', function() {
|
||||||
let prevConnection = this.blocks.statementInput2.previousConnection;
|
const prevConnection = this.blocks.statementInput2.previousConnection;
|
||||||
let node = ASTNode.createConnectionNode(prevConnection);
|
const node = ASTNode.createConnectionNode(prevConnection);
|
||||||
let prevNode = node.prev();
|
const prevNode = node.prev();
|
||||||
let nextConnection = this.blocks.statementInput1.nextConnection;
|
const nextConnection = this.blocks.statementInput1.nextConnection;
|
||||||
chai.assert.equal(prevNode.getLocation(), nextConnection);
|
chai.assert.equal(prevNode.getLocation(), nextConnection);
|
||||||
});
|
});
|
||||||
test('fromPreviousToInput', function() {
|
test('fromPreviousToInput', function() {
|
||||||
let prevConnection = this.blocks.statementInput3.previousConnection;
|
const prevConnection = this.blocks.statementInput3.previousConnection;
|
||||||
let node = ASTNode.createConnectionNode(prevConnection);
|
const node = ASTNode.createConnectionNode(prevConnection);
|
||||||
let prevNode = node.prev();
|
const prevNode = node.prev();
|
||||||
chai.assert.isNull(prevNode);
|
chai.assert.isNull(prevNode);
|
||||||
});
|
});
|
||||||
test('fromBlockToPrevious', function() {
|
test('fromBlockToPrevious', function() {
|
||||||
let node = ASTNode.createBlockNode(this.blocks.statementInput1);
|
const node = ASTNode.createBlockNode(this.blocks.statementInput1);
|
||||||
let prevNode = node.prev();
|
const prevNode = node.prev();
|
||||||
let prevConnection = this.blocks.statementInput1.previousConnection;
|
const prevConnection = this.blocks.statementInput1.previousConnection;
|
||||||
chai.assert.equal(prevNode.getLocation(), prevConnection);
|
chai.assert.equal(prevNode.getLocation(), prevConnection);
|
||||||
});
|
});
|
||||||
test('fromBlockToNull', function() {
|
test('fromBlockToNull', function() {
|
||||||
let node = ASTNode.createBlockNode(this.blocks.noPrevConnection);
|
const node = ASTNode.createBlockNode(this.blocks.noPrevConnection);
|
||||||
let prevNode = node.prev();
|
const prevNode = node.prev();
|
||||||
chai.assert.isNull(prevNode);
|
chai.assert.isNull(prevNode);
|
||||||
});
|
});
|
||||||
test('fromBlockToOutput', function() {
|
test('fromBlockToOutput', function() {
|
||||||
let node = ASTNode.createBlockNode(this.blocks.fieldWithOutput);
|
const node = ASTNode.createBlockNode(this.blocks.fieldWithOutput);
|
||||||
let prevNode = node.prev();
|
const prevNode = node.prev();
|
||||||
let outputConnection = this.blocks.fieldWithOutput.outputConnection;
|
const outputConnection = this.blocks.fieldWithOutput.outputConnection;
|
||||||
chai.assert.equal(prevNode.getLocation(), outputConnection);
|
chai.assert.equal(prevNode.getLocation(), outputConnection);
|
||||||
});
|
});
|
||||||
test('fromNextToBlock', function() {
|
test('fromNextToBlock', function() {
|
||||||
let nextConnection = this.blocks.statementInput1.nextConnection;
|
const nextConnection = this.blocks.statementInput1.nextConnection;
|
||||||
let node = ASTNode.createConnectionNode(nextConnection);
|
const node = ASTNode.createConnectionNode(nextConnection);
|
||||||
let prevNode = node.prev();
|
const prevNode = node.prev();
|
||||||
chai.assert.equal(prevNode.getLocation(), this.blocks.statementInput1);
|
chai.assert.equal(prevNode.getLocation(), this.blocks.statementInput1);
|
||||||
});
|
});
|
||||||
test('fromInputToField', function() {
|
test('fromInputToField', function() {
|
||||||
let input = this.blocks.statementInput1.inputList[0];
|
const input = this.blocks.statementInput1.inputList[0];
|
||||||
let node = ASTNode.createInputNode(input);
|
const node = ASTNode.createInputNode(input);
|
||||||
let prevNode = node.prev();
|
const prevNode = node.prev();
|
||||||
chai.assert.equal(prevNode.getLocation(), input.fieldRow[1]);
|
chai.assert.equal(prevNode.getLocation(), input.fieldRow[1]);
|
||||||
});
|
});
|
||||||
test('fromInputToNull', function() {
|
test('fromInputToNull', function() {
|
||||||
let input = this.blocks.fieldAndInputs2.inputList[0];
|
const input = this.blocks.fieldAndInputs2.inputList[0];
|
||||||
let node = ASTNode.createInputNode(input);
|
const node = ASTNode.createInputNode(input);
|
||||||
let prevNode = node.prev();
|
const prevNode = node.prev();
|
||||||
chai.assert.isNull(prevNode);
|
chai.assert.isNull(prevNode);
|
||||||
});
|
});
|
||||||
test('fromInputToInput', function() {
|
test('fromInputToInput', function() {
|
||||||
let input = this.blocks.fieldAndInputs2.inputList[2];
|
const input = this.blocks.fieldAndInputs2.inputList[2];
|
||||||
let inputConnection = this.blocks.fieldAndInputs2.inputList[1].connection;
|
const inputConnection = this.blocks.fieldAndInputs2.inputList[1].connection;
|
||||||
let node = ASTNode.createInputNode(input);
|
const node = ASTNode.createInputNode(input);
|
||||||
let prevNode = node.prev();
|
const prevNode = node.prev();
|
||||||
chai.assert.equal(prevNode.getLocation(), inputConnection);
|
chai.assert.equal(prevNode.getLocation(), inputConnection);
|
||||||
});
|
});
|
||||||
test('fromOutputToNull', function() {
|
test('fromOutputToNull', function() {
|
||||||
let output = this.blocks.fieldWithOutput.outputConnection;
|
const output = this.blocks.fieldWithOutput.outputConnection;
|
||||||
let node = ASTNode.createConnectionNode(output);
|
const node = ASTNode.createConnectionNode(output);
|
||||||
let prevNode = node.prev();
|
const prevNode = node.prev();
|
||||||
chai.assert.isNull(prevNode);
|
chai.assert.isNull(prevNode);
|
||||||
});
|
});
|
||||||
test('fromFieldToNull', function() {
|
test('fromFieldToNull', function() {
|
||||||
let field = this.blocks.statementInput1.inputList[0].fieldRow[0];
|
const field = this.blocks.statementInput1.inputList[0].fieldRow[0];
|
||||||
let node = ASTNode.createFieldNode(field);
|
const node = ASTNode.createFieldNode(field);
|
||||||
let prevNode = node.prev();
|
const prevNode = node.prev();
|
||||||
chai.assert.isNull(prevNode);
|
chai.assert.isNull(prevNode);
|
||||||
});
|
});
|
||||||
test('fromFieldToInput', function() {
|
test('fromFieldToInput', function() {
|
||||||
let field = this.blocks.fieldAndInputs2.inputList[1].fieldRow[0];
|
const field = this.blocks.fieldAndInputs2.inputList[1].fieldRow[0];
|
||||||
let inputConnection = this.blocks.fieldAndInputs2.inputList[0].connection;
|
const inputConnection = this.blocks.fieldAndInputs2.inputList[0].connection;
|
||||||
let node = ASTNode.createFieldNode(field);
|
const node = ASTNode.createFieldNode(field);
|
||||||
let prevNode = node.prev();
|
const prevNode = node.prev();
|
||||||
chai.assert.equal(prevNode.getLocation(), inputConnection);
|
chai.assert.equal(prevNode.getLocation(), inputConnection);
|
||||||
});
|
});
|
||||||
test('fromFieldToField', function() {
|
test('fromFieldToField', function() {
|
||||||
let field = this.blocks.fieldAndInputs.inputList[1].fieldRow[0];
|
const field = this.blocks.fieldAndInputs.inputList[1].fieldRow[0];
|
||||||
let field2 = this.blocks.fieldAndInputs.inputList[0].fieldRow[0];
|
const field2 = this.blocks.fieldAndInputs.inputList[0].fieldRow[0];
|
||||||
let node = ASTNode.createFieldNode(field);
|
const node = ASTNode.createFieldNode(field);
|
||||||
let prevNode = node.prev();
|
const prevNode = node.prev();
|
||||||
chai.assert.equal(prevNode.getLocation(), field2);
|
chai.assert.equal(prevNode.getLocation(), field2);
|
||||||
});
|
});
|
||||||
test('fromStackToStack', function() {
|
test('fromStackToStack', function() {
|
||||||
let node = ASTNode.createStackNode(this.blocks.statementInput4);
|
const node = ASTNode.createStackNode(this.blocks.statementInput4);
|
||||||
let prevNode = node.prev();
|
const prevNode = node.prev();
|
||||||
chai.assert.equal(prevNode.getLocation(), this.blocks.statementInput1);
|
chai.assert.equal(prevNode.getLocation(), this.blocks.statementInput1);
|
||||||
chai.assert.equal(prevNode.getType(), ASTNode.types.STACK);
|
chai.assert.equal(prevNode.getType(), ASTNode.types.STACK);
|
||||||
});
|
});
|
||||||
@@ -521,98 +521,98 @@ suite('ASTNode', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
test('fromInputToOutput', function() {
|
test('fromInputToOutput', function() {
|
||||||
let input = this.blocks.statementInput1.inputList[0];
|
const input = this.blocks.statementInput1.inputList[0];
|
||||||
let node = ASTNode.createInputNode(input);
|
const node = ASTNode.createInputNode(input);
|
||||||
let inNode = node.in();
|
const inNode = node.in();
|
||||||
let outputConnection = this.blocks.fieldWithOutput.outputConnection;
|
const outputConnection = this.blocks.fieldWithOutput.outputConnection;
|
||||||
chai.assert.equal(inNode.getLocation(), outputConnection);
|
chai.assert.equal(inNode.getLocation(), outputConnection);
|
||||||
});
|
});
|
||||||
test('fromInputToNull', function() {
|
test('fromInputToNull', function() {
|
||||||
let input = this.blocks.statementInput2.inputList[0];
|
const input = this.blocks.statementInput2.inputList[0];
|
||||||
let node = ASTNode.createInputNode(input);
|
const node = ASTNode.createInputNode(input);
|
||||||
let inNode = node.in();
|
const inNode = node.in();
|
||||||
chai.assert.isNull(inNode);
|
chai.assert.isNull(inNode);
|
||||||
});
|
});
|
||||||
test('fromInputToPrevious', function() {
|
test('fromInputToPrevious', function() {
|
||||||
let input = this.blocks.statementInput2.inputList[1];
|
const input = this.blocks.statementInput2.inputList[1];
|
||||||
let previousConnection = this.blocks.statementInput3.previousConnection;
|
const previousConnection = this.blocks.statementInput3.previousConnection;
|
||||||
let node = ASTNode.createInputNode(input);
|
const node = ASTNode.createInputNode(input);
|
||||||
let inNode = node.in();
|
const inNode = node.in();
|
||||||
chai.assert.equal(inNode.getLocation(), previousConnection);
|
chai.assert.equal(inNode.getLocation(), previousConnection);
|
||||||
});
|
});
|
||||||
test('fromBlockToInput', function() {
|
test('fromBlockToInput', function() {
|
||||||
let input = this.blocks.valueInput.inputList[0];
|
const input = this.blocks.valueInput.inputList[0];
|
||||||
let node = ASTNode.createBlockNode(this.blocks.valueInput);
|
const node = ASTNode.createBlockNode(this.blocks.valueInput);
|
||||||
let inNode = node.in();
|
const inNode = node.in();
|
||||||
chai.assert.equal(inNode.getLocation(), input.connection);
|
chai.assert.equal(inNode.getLocation(), input.connection);
|
||||||
});
|
});
|
||||||
test('fromBlockToField', function() {
|
test('fromBlockToField', function() {
|
||||||
let node = ASTNode.createBlockNode(this.blocks.statementInput1);
|
const node = ASTNode.createBlockNode(this.blocks.statementInput1);
|
||||||
let inNode = node.in();
|
const inNode = node.in();
|
||||||
let field = this.blocks.statementInput1.inputList[0].fieldRow[0];
|
const field = this.blocks.statementInput1.inputList[0].fieldRow[0];
|
||||||
chai.assert.equal(inNode.getLocation(), field);
|
chai.assert.equal(inNode.getLocation(), field);
|
||||||
});
|
});
|
||||||
test('fromBlockToPrevious', function() {
|
test('fromBlockToPrevious', function() {
|
||||||
let prevConnection = this.blocks.statementInput4.previousConnection;
|
const prevConnection = this.blocks.statementInput4.previousConnection;
|
||||||
let node = ASTNode.createStackNode(this.blocks.statementInput4);
|
const node = ASTNode.createStackNode(this.blocks.statementInput4);
|
||||||
let inNode = node.in();
|
const inNode = node.in();
|
||||||
chai.assert.equal(inNode.getLocation(), prevConnection);
|
chai.assert.equal(inNode.getLocation(), prevConnection);
|
||||||
chai.assert.equal(inNode.getType(), ASTNode.types.PREVIOUS);
|
chai.assert.equal(inNode.getType(), ASTNode.types.PREVIOUS);
|
||||||
});
|
});
|
||||||
test('fromBlockToNull_DummyInput', function() {
|
test('fromBlockToNull_DummyInput', function() {
|
||||||
let node = ASTNode.createBlockNode(this.blocks.dummyInput);
|
const node = ASTNode.createBlockNode(this.blocks.dummyInput);
|
||||||
let inNode = node.in();
|
const inNode = node.in();
|
||||||
chai.assert.isNull(inNode);
|
chai.assert.isNull(inNode);
|
||||||
});
|
});
|
||||||
test('fromBlockToInput_DummyInputValue', function() {
|
test('fromBlockToInput_DummyInputValue', function() {
|
||||||
let node = ASTNode.createBlockNode(this.blocks.dummyInputValue);
|
const node = ASTNode.createBlockNode(this.blocks.dummyInputValue);
|
||||||
let inputConnection = this.blocks.dummyInputValue.inputList[1].connection;
|
const inputConnection = this.blocks.dummyInputValue.inputList[1].connection;
|
||||||
let inNode = node.in();
|
const inNode = node.in();
|
||||||
chai.assert.equal(inNode.getLocation(), inputConnection);
|
chai.assert.equal(inNode.getLocation(), inputConnection);
|
||||||
});
|
});
|
||||||
test('fromOuputToNull', function() {
|
test('fromOuputToNull', function() {
|
||||||
let output = this.blocks.fieldWithOutput.outputConnection;
|
const output = this.blocks.fieldWithOutput.outputConnection;
|
||||||
let node = ASTNode.createConnectionNode(output);
|
const node = ASTNode.createConnectionNode(output);
|
||||||
let inNode = node.in();
|
const inNode = node.in();
|
||||||
chai.assert.isNull(inNode);
|
chai.assert.isNull(inNode);
|
||||||
});
|
});
|
||||||
test('fromFieldToNull', function() {
|
test('fromFieldToNull', function() {
|
||||||
let field = this.blocks.statementInput1.inputList[0].fieldRow[0];
|
const field = this.blocks.statementInput1.inputList[0].fieldRow[0];
|
||||||
let node = ASTNode.createFieldNode(field);
|
const node = ASTNode.createFieldNode(field);
|
||||||
let inNode = node.in();
|
const inNode = node.in();
|
||||||
chai.assert.isNull(inNode);
|
chai.assert.isNull(inNode);
|
||||||
});
|
});
|
||||||
test('fromWorkspaceToStack', function() {
|
test('fromWorkspaceToStack', function() {
|
||||||
let coordinate = new Blockly.utils.Coordinate(100, 100);
|
const coordinate = new Blockly.utils.Coordinate(100, 100);
|
||||||
let node = ASTNode.createWorkspaceNode(this.workspace, coordinate);
|
const node = ASTNode.createWorkspaceNode(this.workspace, coordinate);
|
||||||
let inNode = node.in();
|
const inNode = node.in();
|
||||||
chai.assert.equal(inNode.getLocation(), this.workspace.getTopBlocks()[0]);
|
chai.assert.equal(inNode.getLocation(), this.workspace.getTopBlocks()[0]);
|
||||||
chai.assert.equal(inNode.getType(), ASTNode.types.STACK);
|
chai.assert.equal(inNode.getType(), ASTNode.types.STACK);
|
||||||
});
|
});
|
||||||
test('fromWorkspaceToNull', function() {
|
test('fromWorkspaceToNull', function() {
|
||||||
let coordinate = new Blockly.utils.Coordinate(100, 100);
|
const coordinate = new Blockly.utils.Coordinate(100, 100);
|
||||||
let node = ASTNode.createWorkspaceNode(
|
const node = ASTNode.createWorkspaceNode(
|
||||||
this.emptyWorkspace, coordinate);
|
this.emptyWorkspace, coordinate);
|
||||||
let inNode = node.in();
|
const inNode = node.in();
|
||||||
chai.assert.isNull(inNode);
|
chai.assert.isNull(inNode);
|
||||||
});
|
});
|
||||||
test('fromStackToPrevious', function() {
|
test('fromStackToPrevious', function() {
|
||||||
let node = ASTNode.createStackNode(this.blocks.statementInput1);
|
const node = ASTNode.createStackNode(this.blocks.statementInput1);
|
||||||
let previous = this.blocks.statementInput1.previousConnection;
|
const previous = this.blocks.statementInput1.previousConnection;
|
||||||
let inNode = node.in();
|
const inNode = node.in();
|
||||||
chai.assert.equal(inNode.getLocation(), previous);
|
chai.assert.equal(inNode.getLocation(), previous);
|
||||||
chai.assert.equal(inNode.getType(), ASTNode.types.PREVIOUS);
|
chai.assert.equal(inNode.getType(), ASTNode.types.PREVIOUS);
|
||||||
});
|
});
|
||||||
test('fromStackToOutput', function() {
|
test('fromStackToOutput', function() {
|
||||||
let node = ASTNode.createStackNode(this.blocks.fieldWithOutput2);
|
const node = ASTNode.createStackNode(this.blocks.fieldWithOutput2);
|
||||||
let output = this.blocks.fieldWithOutput2.outputConnection;
|
const output = this.blocks.fieldWithOutput2.outputConnection;
|
||||||
let inNode = node.in();
|
const inNode = node.in();
|
||||||
chai.assert.equal(inNode.getLocation(), output);
|
chai.assert.equal(inNode.getLocation(), output);
|
||||||
chai.assert.equal(inNode.getType(), ASTNode.types.OUTPUT);
|
chai.assert.equal(inNode.getType(), ASTNode.types.OUTPUT);
|
||||||
});
|
});
|
||||||
test('fromStackToBlock', function() {
|
test('fromStackToBlock', function() {
|
||||||
let node = ASTNode.createStackNode(this.blocks.dummyInput);
|
const node = ASTNode.createStackNode(this.blocks.dummyInput);
|
||||||
let inNode = node.in();
|
const inNode = node.in();
|
||||||
chai.assert.equal(inNode.getLocation(), this.blocks.dummyInput);
|
chai.assert.equal(inNode.getLocation(), this.blocks.dummyInput);
|
||||||
chai.assert.equal(inNode.getType(), ASTNode.types.BLOCK);
|
chai.assert.equal(inNode.getType(), ASTNode.types.BLOCK);
|
||||||
});
|
});
|
||||||
@@ -620,86 +620,86 @@ suite('ASTNode', function() {
|
|||||||
|
|
||||||
suite('Out', function() {
|
suite('Out', function() {
|
||||||
setup(function() {
|
setup(function() {
|
||||||
let secondBlock = this.blocks.secondBlock;
|
const secondBlock = this.blocks.secondBlock;
|
||||||
let outputNextBlock = this.blocks.outputNextBlock;
|
const outputNextBlock = this.blocks.outputNextBlock;
|
||||||
this.blocks.noPrevConnection.nextConnection.connect(secondBlock.previousConnection);
|
this.blocks.noPrevConnection.nextConnection.connect(secondBlock.previousConnection);
|
||||||
secondBlock.inputList[0].connection
|
secondBlock.inputList[0].connection
|
||||||
.connect(outputNextBlock.outputConnection);
|
.connect(outputNextBlock.outputConnection);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('fromInputToBlock', function() {
|
test('fromInputToBlock', function() {
|
||||||
let input = this.blocks.statementInput1.inputList[0];
|
const input = this.blocks.statementInput1.inputList[0];
|
||||||
let node = ASTNode.createInputNode(input);
|
const node = ASTNode.createInputNode(input);
|
||||||
let outNode = node.out();
|
const outNode = node.out();
|
||||||
chai.assert.equal(outNode.getType(), ASTNode.types.BLOCK);
|
chai.assert.equal(outNode.getType(), ASTNode.types.BLOCK);
|
||||||
chai.assert.equal(outNode.getLocation(), this.blocks.statementInput1);
|
chai.assert.equal(outNode.getLocation(), this.blocks.statementInput1);
|
||||||
});
|
});
|
||||||
test('fromOutputToInput', function() {
|
test('fromOutputToInput', function() {
|
||||||
let output = this.blocks.fieldWithOutput.outputConnection;
|
const output = this.blocks.fieldWithOutput.outputConnection;
|
||||||
let node = ASTNode.createConnectionNode(output);
|
const node = ASTNode.createConnectionNode(output);
|
||||||
let outNode = node.out();
|
const outNode = node.out();
|
||||||
chai.assert.equal(outNode.getType(), ASTNode.types.INPUT);
|
chai.assert.equal(outNode.getType(), ASTNode.types.INPUT);
|
||||||
chai.assert.equal(outNode.getLocation(),
|
chai.assert.equal(outNode.getLocation(),
|
||||||
this.blocks.statementInput1.inputList[0].connection);
|
this.blocks.statementInput1.inputList[0].connection);
|
||||||
});
|
});
|
||||||
test('fromOutputToStack', function() {
|
test('fromOutputToStack', function() {
|
||||||
let output = this.blocks.fieldWithOutput2.outputConnection;
|
const output = this.blocks.fieldWithOutput2.outputConnection;
|
||||||
let node = ASTNode.createConnectionNode(output);
|
const node = ASTNode.createConnectionNode(output);
|
||||||
let outNode = node.out();
|
const outNode = node.out();
|
||||||
chai.assert.equal(outNode.getType(), ASTNode.types.STACK);
|
chai.assert.equal(outNode.getType(), ASTNode.types.STACK);
|
||||||
chai.assert.equal(outNode.getLocation(), this.blocks.fieldWithOutput2);
|
chai.assert.equal(outNode.getLocation(), this.blocks.fieldWithOutput2);
|
||||||
});
|
});
|
||||||
test('fromFieldToBlock', function() {
|
test('fromFieldToBlock', function() {
|
||||||
let field = this.blocks.statementInput1.inputList[0].fieldRow[0];
|
const field = this.blocks.statementInput1.inputList[0].fieldRow[0];
|
||||||
let node = ASTNode.createFieldNode(field);
|
const node = ASTNode.createFieldNode(field);
|
||||||
let outNode = node.out();
|
const outNode = node.out();
|
||||||
chai.assert.equal(outNode.getType(), ASTNode.types.BLOCK);
|
chai.assert.equal(outNode.getType(), ASTNode.types.BLOCK);
|
||||||
chai.assert.equal(outNode.getLocation(), this.blocks.statementInput1);
|
chai.assert.equal(outNode.getLocation(), this.blocks.statementInput1);
|
||||||
});
|
});
|
||||||
test('fromStackToWorkspace', function() {
|
test('fromStackToWorkspace', function() {
|
||||||
let stub = sinon.stub(this.blocks.statementInput4,
|
const stub = sinon.stub(this.blocks.statementInput4,
|
||||||
"getRelativeToSurfaceXY").returns({x: 10, y:10});
|
"getRelativeToSurfaceXY").returns({x: 10, y:10});
|
||||||
let node = ASTNode.createStackNode(this.blocks.statementInput4);
|
const node = ASTNode.createStackNode(this.blocks.statementInput4);
|
||||||
let outNode = node.out();
|
const outNode = node.out();
|
||||||
chai.assert.equal(outNode.getType(), ASTNode.types.WORKSPACE);
|
chai.assert.equal(outNode.getType(), ASTNode.types.WORKSPACE);
|
||||||
chai.assert.equal(outNode.wsCoordinate_.x, 10);
|
chai.assert.equal(outNode.wsCoordinate_.x, 10);
|
||||||
chai.assert.equal(outNode.wsCoordinate_.y, -10);
|
chai.assert.equal(outNode.wsCoordinate_.y, -10);
|
||||||
stub.restore();
|
stub.restore();
|
||||||
});
|
});
|
||||||
test('fromPreviousToInput', function() {
|
test('fromPreviousToInput', function() {
|
||||||
let previous = this.blocks.statementInput3.previousConnection;
|
const previous = this.blocks.statementInput3.previousConnection;
|
||||||
let inputConnection = this.blocks.statementInput2.inputList[1].connection;
|
const inputConnection = this.blocks.statementInput2.inputList[1].connection;
|
||||||
let node = ASTNode.createConnectionNode(previous);
|
const node = ASTNode.createConnectionNode(previous);
|
||||||
let outNode = node.out();
|
const outNode = node.out();
|
||||||
chai.assert.equal(outNode.getType(), ASTNode.types.INPUT);
|
chai.assert.equal(outNode.getType(), ASTNode.types.INPUT);
|
||||||
chai.assert.equal(outNode.getLocation(), inputConnection);
|
chai.assert.equal(outNode.getLocation(), inputConnection);
|
||||||
});
|
});
|
||||||
test('fromPreviousToStack', function() {
|
test('fromPreviousToStack', function() {
|
||||||
let previous = this.blocks.statementInput2.previousConnection;
|
const previous = this.blocks.statementInput2.previousConnection;
|
||||||
let node = ASTNode.createConnectionNode(previous);
|
const node = ASTNode.createConnectionNode(previous);
|
||||||
let outNode = node.out();
|
const outNode = node.out();
|
||||||
chai.assert.equal(outNode.getType(), ASTNode.types.STACK);
|
chai.assert.equal(outNode.getType(), ASTNode.types.STACK);
|
||||||
chai.assert.equal(outNode.getLocation(), this.blocks.statementInput1);
|
chai.assert.equal(outNode.getLocation(), this.blocks.statementInput1);
|
||||||
});
|
});
|
||||||
test('fromNextToInput', function() {
|
test('fromNextToInput', function() {
|
||||||
let next = this.blocks.statementInput3.nextConnection;
|
const next = this.blocks.statementInput3.nextConnection;
|
||||||
let inputConnection = this.blocks.statementInput2.inputList[1].connection;
|
const inputConnection = this.blocks.statementInput2.inputList[1].connection;
|
||||||
let node = ASTNode.createConnectionNode(next);
|
const node = ASTNode.createConnectionNode(next);
|
||||||
let outNode = node.out();
|
const outNode = node.out();
|
||||||
chai.assert.equal(outNode.getType(), ASTNode.types.INPUT);
|
chai.assert.equal(outNode.getType(), ASTNode.types.INPUT);
|
||||||
chai.assert.equal(outNode.getLocation(), inputConnection);
|
chai.assert.equal(outNode.getLocation(), inputConnection);
|
||||||
});
|
});
|
||||||
test('fromNextToStack', function() {
|
test('fromNextToStack', function() {
|
||||||
let next = this.blocks.statementInput2.nextConnection;
|
const next = this.blocks.statementInput2.nextConnection;
|
||||||
let node = ASTNode.createConnectionNode(next);
|
const node = ASTNode.createConnectionNode(next);
|
||||||
let outNode = node.out();
|
const outNode = node.out();
|
||||||
chai.assert.equal(outNode.getType(), ASTNode.types.STACK);
|
chai.assert.equal(outNode.getType(), ASTNode.types.STACK);
|
||||||
chai.assert.equal(outNode.getLocation(), this.blocks.statementInput1);
|
chai.assert.equal(outNode.getLocation(), this.blocks.statementInput1);
|
||||||
});
|
});
|
||||||
test('fromNextToStack_NoPreviousConnection', function() {
|
test('fromNextToStack_NoPreviousConnection', function() {
|
||||||
let next = this.blocks.secondBlock.nextConnection;
|
const next = this.blocks.secondBlock.nextConnection;
|
||||||
let node = ASTNode.createConnectionNode(next);
|
const node = ASTNode.createConnectionNode(next);
|
||||||
let outNode = node.out();
|
const outNode = node.out();
|
||||||
chai.assert.equal(outNode.getType(), ASTNode.types.STACK);
|
chai.assert.equal(outNode.getType(), ASTNode.types.STACK);
|
||||||
chai.assert.equal(outNode.getLocation(), this.blocks.noPrevConnection);
|
chai.assert.equal(outNode.getLocation(), this.blocks.noPrevConnection);
|
||||||
});
|
});
|
||||||
@@ -708,42 +708,42 @@ suite('ASTNode', function() {
|
|||||||
* next connection attached to an input.
|
* next connection attached to an input.
|
||||||
*/
|
*/
|
||||||
test('fromNextToInput_OutputAndPreviousConnection', function() {
|
test('fromNextToInput_OutputAndPreviousConnection', function() {
|
||||||
let next = this.blocks.outputNextBlock.nextConnection;
|
const next = this.blocks.outputNextBlock.nextConnection;
|
||||||
let node = ASTNode.createConnectionNode(next);
|
const node = ASTNode.createConnectionNode(next);
|
||||||
let outNode = node.out();
|
const outNode = node.out();
|
||||||
chai.assert.equal(outNode.getType(), ASTNode.types.INPUT);
|
chai.assert.equal(outNode.getType(), ASTNode.types.INPUT);
|
||||||
chai.assert.equal(outNode.getLocation(),
|
chai.assert.equal(outNode.getLocation(),
|
||||||
this.blocks.secondBlock.inputList[0].connection);
|
this.blocks.secondBlock.inputList[0].connection);
|
||||||
});
|
});
|
||||||
test('fromBlockToStack', function() {
|
test('fromBlockToStack', function() {
|
||||||
let node = ASTNode.createBlockNode(this.blocks.statementInput2);
|
const node = ASTNode.createBlockNode(this.blocks.statementInput2);
|
||||||
let outNode = node.out();
|
const outNode = node.out();
|
||||||
chai.assert.equal(outNode.getType(), ASTNode.types.STACK);
|
chai.assert.equal(outNode.getType(), ASTNode.types.STACK);
|
||||||
chai.assert.equal(outNode.getLocation(), this.blocks.statementInput1);
|
chai.assert.equal(outNode.getLocation(), this.blocks.statementInput1);
|
||||||
});
|
});
|
||||||
test('fromBlockToInput', function() {
|
test('fromBlockToInput', function() {
|
||||||
let input = this.blocks.statementInput2.inputList[1].connection;
|
const input = this.blocks.statementInput2.inputList[1].connection;
|
||||||
let node = ASTNode.createBlockNode(this.blocks.statementInput3);
|
const node = ASTNode.createBlockNode(this.blocks.statementInput3);
|
||||||
let outNode = node.out();
|
const outNode = node.out();
|
||||||
chai.assert.equal(outNode.getType(), ASTNode.types.INPUT);
|
chai.assert.equal(outNode.getType(), ASTNode.types.INPUT);
|
||||||
chai.assert.equal(outNode.getLocation(), input);
|
chai.assert.equal(outNode.getLocation(), input);
|
||||||
});
|
});
|
||||||
test('fromTopBlockToStack', function() {
|
test('fromTopBlockToStack', function() {
|
||||||
let node = ASTNode.createBlockNode(this.blocks.statementInput1);
|
const node = ASTNode.createBlockNode(this.blocks.statementInput1);
|
||||||
let outNode = node.out();
|
const outNode = node.out();
|
||||||
chai.assert.equal(outNode.getType(), ASTNode.types.STACK);
|
chai.assert.equal(outNode.getType(), ASTNode.types.STACK);
|
||||||
chai.assert.equal(outNode.getLocation(), this.blocks.statementInput1);
|
chai.assert.equal(outNode.getLocation(), this.blocks.statementInput1);
|
||||||
});
|
});
|
||||||
test('fromBlockToStack_OutputConnection', function() {
|
test('fromBlockToStack_OutputConnection', function() {
|
||||||
let node = ASTNode.createBlockNode(this.blocks.fieldWithOutput2);
|
const node = ASTNode.createBlockNode(this.blocks.fieldWithOutput2);
|
||||||
let outNode = node.out();
|
const outNode = node.out();
|
||||||
chai.assert.equal(outNode.getType(), ASTNode.types.STACK);
|
chai.assert.equal(outNode.getType(), ASTNode.types.STACK);
|
||||||
chai.assert.equal(outNode.getLocation(), this.blocks.fieldWithOutput2);
|
chai.assert.equal(outNode.getLocation(), this.blocks.fieldWithOutput2);
|
||||||
});
|
});
|
||||||
test('fromBlockToInput_OutputConnection', function() {
|
test('fromBlockToInput_OutputConnection', function() {
|
||||||
let node = ASTNode.createBlockNode(this.blocks.outputNextBlock);
|
const node = ASTNode.createBlockNode(this.blocks.outputNextBlock);
|
||||||
let inputConnection = this.blocks.secondBlock.inputList[0].connection;
|
const inputConnection = this.blocks.secondBlock.inputList[0].connection;
|
||||||
let outNode = node.out();
|
const outNode = node.out();
|
||||||
chai.assert.equal(outNode.getType(), ASTNode.types.INPUT);
|
chai.assert.equal(outNode.getType(), ASTNode.types.INPUT);
|
||||||
chai.assert.equal(outNode.getLocation(), inputConnection);
|
chai.assert.equal(outNode.getLocation(), inputConnection);
|
||||||
});
|
});
|
||||||
@@ -751,29 +751,29 @@ suite('ASTNode', function() {
|
|||||||
|
|
||||||
suite('createFunctions', function() {
|
suite('createFunctions', function() {
|
||||||
test('createFieldNode', function() {
|
test('createFieldNode', function() {
|
||||||
let field = this.blocks.statementInput1.inputList[0].fieldRow[0];
|
const field = this.blocks.statementInput1.inputList[0].fieldRow[0];
|
||||||
let node = ASTNode.createFieldNode(field);
|
const node = ASTNode.createFieldNode(field);
|
||||||
chai.assert.equal(node.getLocation(), field);
|
chai.assert.equal(node.getLocation(), field);
|
||||||
chai.assert.equal(node.getType(), ASTNode.types.FIELD);
|
chai.assert.equal(node.getType(), ASTNode.types.FIELD);
|
||||||
chai.assert.isFalse(node.isConnection());
|
chai.assert.isFalse(node.isConnection());
|
||||||
});
|
});
|
||||||
test('createConnectionNode', function() {
|
test('createConnectionNode', function() {
|
||||||
let prevConnection = this.blocks.statementInput4.previousConnection;
|
const prevConnection = this.blocks.statementInput4.previousConnection;
|
||||||
let node = ASTNode.createConnectionNode(prevConnection);
|
const node = ASTNode.createConnectionNode(prevConnection);
|
||||||
chai.assert.equal(node.getLocation(), prevConnection);
|
chai.assert.equal(node.getLocation(), prevConnection);
|
||||||
chai.assert.equal(node.getType(), ASTNode.types.PREVIOUS);
|
chai.assert.equal(node.getType(), ASTNode.types.PREVIOUS);
|
||||||
chai.assert.isTrue(node.isConnection());
|
chai.assert.isTrue(node.isConnection());
|
||||||
});
|
});
|
||||||
test('createInputNode', function() {
|
test('createInputNode', function() {
|
||||||
let input = this.blocks.statementInput1.inputList[0];
|
const input = this.blocks.statementInput1.inputList[0];
|
||||||
let node = ASTNode.createInputNode(input);
|
const node = ASTNode.createInputNode(input);
|
||||||
chai.assert.equal(node.getLocation(), input.connection);
|
chai.assert.equal(node.getLocation(), input.connection);
|
||||||
chai.assert.equal(node.getType(), ASTNode.types.INPUT);
|
chai.assert.equal(node.getType(), ASTNode.types.INPUT);
|
||||||
chai.assert.isTrue(node.isConnection());
|
chai.assert.isTrue(node.isConnection());
|
||||||
});
|
});
|
||||||
test('createWorkspaceNode', function() {
|
test('createWorkspaceNode', function() {
|
||||||
let coordinate = new Blockly.utils.Coordinate(100, 100);
|
const coordinate = new Blockly.utils.Coordinate(100, 100);
|
||||||
let node = ASTNode
|
const node = ASTNode
|
||||||
.createWorkspaceNode(this.workspace, coordinate);
|
.createWorkspaceNode(this.workspace, coordinate);
|
||||||
chai.assert.equal(node.getLocation(), this.workspace);
|
chai.assert.equal(node.getLocation(), this.workspace);
|
||||||
chai.assert.equal(node.getType(), ASTNode.types.WORKSPACE);
|
chai.assert.equal(node.getType(), ASTNode.types.WORKSPACE);
|
||||||
@@ -781,26 +781,26 @@ suite('ASTNode', function() {
|
|||||||
chai.assert.isFalse(node.isConnection());
|
chai.assert.isFalse(node.isConnection());
|
||||||
});
|
});
|
||||||
test('createStatementConnectionNode', function() {
|
test('createStatementConnectionNode', function() {
|
||||||
let nextConnection = this.blocks.statementInput1.inputList[1].connection;
|
const nextConnection = this.blocks.statementInput1.inputList[1].connection;
|
||||||
let inputConnection = this.blocks.statementInput1.inputList[1].connection;
|
const inputConnection = this.blocks.statementInput1.inputList[1].connection;
|
||||||
let node = ASTNode.createConnectionNode(nextConnection);
|
const node = ASTNode.createConnectionNode(nextConnection);
|
||||||
chai.assert.equal(node.getLocation(), inputConnection);
|
chai.assert.equal(node.getLocation(), inputConnection);
|
||||||
chai.assert.equal(node.getType(), ASTNode.types.INPUT);
|
chai.assert.equal(node.getType(), ASTNode.types.INPUT);
|
||||||
chai.assert.isTrue(node.isConnection());
|
chai.assert.isTrue(node.isConnection());
|
||||||
});
|
});
|
||||||
test('createTopNode-previous', function() {
|
test('createTopNode-previous', function() {
|
||||||
let block = this.blocks.statementInput1;
|
const block = this.blocks.statementInput1;
|
||||||
let topNode = ASTNode.createTopNode(block);
|
const topNode = ASTNode.createTopNode(block);
|
||||||
chai.assert.equal(topNode.getLocation(), block.previousConnection);
|
chai.assert.equal(topNode.getLocation(), block.previousConnection);
|
||||||
});
|
});
|
||||||
test('createTopNode-block', function() {
|
test('createTopNode-block', function() {
|
||||||
let block = this.blocks.noPrevConnection;
|
const block = this.blocks.noPrevConnection;
|
||||||
let topNode = ASTNode.createTopNode(block);
|
const topNode = ASTNode.createTopNode(block);
|
||||||
chai.assert.equal(topNode.getLocation(), block);
|
chai.assert.equal(topNode.getLocation(), block);
|
||||||
});
|
});
|
||||||
test('createTopNode-output', function() {
|
test('createTopNode-output', function() {
|
||||||
let block = this.blocks.outputNextBlock;
|
const block = this.blocks.outputNextBlock;
|
||||||
let topNode = ASTNode.createTopNode(block);
|
const topNode = ASTNode.createTopNode(block);
|
||||||
chai.assert.equal(topNode.getLocation(), block.outputConnection);
|
chai.assert.equal(topNode.getLocation(), block.outputConnection);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ suite('Block JSON initialization', function() {
|
|||||||
suite('validateTokens_', function() {
|
suite('validateTokens_', function() {
|
||||||
setup(function() {
|
setup(function() {
|
||||||
this.assertError = function(tokens, count, error) {
|
this.assertError = function(tokens, count, error) {
|
||||||
let block = {
|
const block = {
|
||||||
type: 'test',
|
type: 'test',
|
||||||
validateTokens_: Blockly.Block.prototype.validateTokens_,
|
validateTokens_: Blockly.Block.prototype.validateTokens_,
|
||||||
};
|
};
|
||||||
@@ -21,7 +21,7 @@ suite('Block JSON initialization', function() {
|
|||||||
};
|
};
|
||||||
|
|
||||||
this.assertNoError = function(tokens, count) {
|
this.assertNoError = function(tokens, count) {
|
||||||
let block = {
|
const block = {
|
||||||
type: 'test',
|
type: 'test',
|
||||||
validateTokens_: Blockly.Block.prototype.validateTokens_,
|
validateTokens_: Blockly.Block.prototype.validateTokens_,
|
||||||
};
|
};
|
||||||
@@ -68,7 +68,7 @@ suite('Block JSON initialization', function() {
|
|||||||
suite('interpolateArguments_', function() {
|
suite('interpolateArguments_', function() {
|
||||||
setup(function() {
|
setup(function() {
|
||||||
this.assertInterpolation = function(tokens, args, lastAlign, elements) {
|
this.assertInterpolation = function(tokens, args, lastAlign, elements) {
|
||||||
let block = {
|
const block = {
|
||||||
type: 'test',
|
type: 'test',
|
||||||
interpolateArguments_: Blockly.Block.prototype.interpolateArguments_,
|
interpolateArguments_: Blockly.Block.prototype.interpolateArguments_,
|
||||||
stringToFieldJson_: Blockly.Block.prototype.stringToFieldJson_,
|
stringToFieldJson_: Blockly.Block.prototype.stringToFieldJson_,
|
||||||
@@ -304,7 +304,7 @@ suite('Block JSON initialization', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
this.assertField = function(json, expectedType) {
|
this.assertField = function(json, expectedType) {
|
||||||
let block = {
|
const block = {
|
||||||
type: 'test',
|
type: 'test',
|
||||||
fieldFromJson_: Blockly.Block.prototype.fieldFromJson_,
|
fieldFromJson_: Blockly.Block.prototype.fieldFromJson_,
|
||||||
stringToFieldJson_: Blockly.Block.prototype.stringToFieldJson_,
|
stringToFieldJson_: Blockly.Block.prototype.stringToFieldJson_,
|
||||||
@@ -432,12 +432,12 @@ suite('Block JSON initialization', function() {
|
|||||||
|
|
||||||
suite('inputFromJson_', function() {
|
suite('inputFromJson_', function() {
|
||||||
setup(function() {
|
setup(function() {
|
||||||
let Input = function(type) {
|
const Input = function(type) {
|
||||||
this.type = type;
|
this.type = type;
|
||||||
this.setCheck = sinon.fake();
|
this.setCheck = sinon.fake();
|
||||||
this.setAlign = sinon.fake();
|
this.setAlign = sinon.fake();
|
||||||
};
|
};
|
||||||
let Block = function() {
|
const Block = function() {
|
||||||
this.type = 'test';
|
this.type = 'test';
|
||||||
this.appendDummyInput = sinon.fake.returns(new Input());
|
this.appendDummyInput = sinon.fake.returns(new Input());
|
||||||
this.appendValueInput = sinon.fake.returns(new Input());
|
this.appendValueInput = sinon.fake.returns(new Input());
|
||||||
@@ -446,8 +446,8 @@ suite('Block JSON initialization', function() {
|
|||||||
};
|
};
|
||||||
|
|
||||||
this.assertInput = function(json, type, check, align) {
|
this.assertInput = function(json, type, check, align) {
|
||||||
let block = new Block();
|
const block = new Block();
|
||||||
let input = block.inputFromJson_(json);
|
const input = block.inputFromJson_(json);
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case 'input_dummy':
|
case 'input_dummy':
|
||||||
chai.assert.isTrue(block.appendDummyInput.calledOnce,
|
chai.assert.isTrue(block.appendDummyInput.calledOnce,
|
||||||
|
|||||||
@@ -55,10 +55,10 @@ suite('Blocks', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
function createTestBlocks(workspace, isRow) {
|
function createTestBlocks(workspace, isRow) {
|
||||||
let blockType = isRow ? 'row_block' : 'stack_block';
|
const blockType = isRow ? 'row_block' : 'stack_block';
|
||||||
let blockA = workspace.newBlock(blockType);
|
const blockA = workspace.newBlock(blockType);
|
||||||
let blockB = workspace.newBlock(blockType);
|
const blockB = workspace.newBlock(blockType);
|
||||||
let blockC = workspace.newBlock(blockType);
|
const blockC = workspace.newBlock(blockType);
|
||||||
|
|
||||||
if (isRow) {
|
if (isRow) {
|
||||||
blockA.inputList[0].connection.connect(blockB.outputConnection);
|
blockA.inputList[0].connection.connect(blockB.outputConnection);
|
||||||
@@ -121,7 +121,7 @@ suite('Blocks', function() {
|
|||||||
assertUnpluggedHealed(this.blocks);
|
assertUnpluggedHealed(this.blocks);
|
||||||
});
|
});
|
||||||
test('Heal with bad checks', function() {
|
test('Heal with bad checks', function() {
|
||||||
let blocks = this.blocks;
|
const blocks = this.blocks;
|
||||||
|
|
||||||
// A and C can't connect, but both can connect to B.
|
// A and C can't connect, but both can connect to B.
|
||||||
blocks.A.inputList[0].connection.setCheck('type1');
|
blocks.A.inputList[0].connection.setCheck('type1');
|
||||||
@@ -132,21 +132,21 @@ suite('Blocks', function() {
|
|||||||
assertUnpluggedHealFailed(blocks);
|
assertUnpluggedHealFailed(blocks);
|
||||||
});
|
});
|
||||||
test('Parent has multiple inputs', function() {
|
test('Parent has multiple inputs', function() {
|
||||||
let blocks = this.blocks;
|
const blocks = this.blocks;
|
||||||
// Add extra input to parent
|
// Add extra input to parent
|
||||||
blocks.A.appendValueInput("INPUT").setCheck(null);
|
blocks.A.appendValueInput("INPUT").setCheck(null);
|
||||||
blocks.B.unplug(true);
|
blocks.B.unplug(true);
|
||||||
assertUnpluggedHealed(blocks);
|
assertUnpluggedHealed(blocks);
|
||||||
});
|
});
|
||||||
test('Middle has multiple inputs', function() {
|
test('Middle has multiple inputs', function() {
|
||||||
let blocks = this.blocks;
|
const blocks = this.blocks;
|
||||||
// Add extra input to middle block
|
// Add extra input to middle block
|
||||||
blocks.B.appendValueInput("INPUT").setCheck(null);
|
blocks.B.appendValueInput("INPUT").setCheck(null);
|
||||||
blocks.B.unplug(true);
|
blocks.B.unplug(true);
|
||||||
assertUnpluggedHealed(blocks);
|
assertUnpluggedHealed(blocks);
|
||||||
});
|
});
|
||||||
test('Child has multiple inputs', function() {
|
test('Child has multiple inputs', function() {
|
||||||
let blocks = this.blocks;
|
const blocks = this.blocks;
|
||||||
// Add extra input to child block
|
// Add extra input to child block
|
||||||
blocks.C.appendValueInput("INPUT").setCheck(null);
|
blocks.C.appendValueInput("INPUT").setCheck(null);
|
||||||
// Child block input count doesn't matter.
|
// Child block input count doesn't matter.
|
||||||
@@ -154,7 +154,7 @@ suite('Blocks', function() {
|
|||||||
assertUnpluggedHealed(blocks);
|
assertUnpluggedHealed(blocks);
|
||||||
});
|
});
|
||||||
test('Child is shadow', function() {
|
test('Child is shadow', function() {
|
||||||
let blocks = this.blocks;
|
const blocks = this.blocks;
|
||||||
blocks.C.setShadow(true);
|
blocks.C.setShadow(true);
|
||||||
blocks.B.unplug(true);
|
blocks.B.unplug(true);
|
||||||
// Even though we're asking to heal, it will appear as if it has not
|
// Even though we're asking to heal, it will appear as if it has not
|
||||||
@@ -176,7 +176,7 @@ suite('Blocks', function() {
|
|||||||
assertUnpluggedHealed(this.blocks);
|
assertUnpluggedHealed(this.blocks);
|
||||||
});
|
});
|
||||||
test('Heal with bad checks', function() {
|
test('Heal with bad checks', function() {
|
||||||
let blocks = this.blocks;
|
const blocks = this.blocks;
|
||||||
// A and C can't connect, but both can connect to B.
|
// A and C can't connect, but both can connect to B.
|
||||||
blocks.A.nextConnection.setCheck('type1');
|
blocks.A.nextConnection.setCheck('type1');
|
||||||
blocks.C.previousConnection.setCheck('type2');
|
blocks.C.previousConnection.setCheck('type2');
|
||||||
@@ -187,7 +187,7 @@ suite('Blocks', function() {
|
|||||||
assertUnpluggedHealFailed(blocks);
|
assertUnpluggedHealFailed(blocks);
|
||||||
});
|
});
|
||||||
test('Child is shadow', function() {
|
test('Child is shadow', function() {
|
||||||
let blocks = this.blocks;
|
const blocks = this.blocks;
|
||||||
blocks.C.setShadow(true);
|
blocks.C.setShadow(true);
|
||||||
blocks.B.unplug(true);
|
blocks.B.unplug(true);
|
||||||
// Even though we're asking to heal, it will appear as if it has not
|
// Even though we're asking to heal, it will appear as if it has not
|
||||||
@@ -241,7 +241,7 @@ suite('Blocks', function() {
|
|||||||
assertDisposedHealed(this.blocks);
|
assertDisposedHealed(this.blocks);
|
||||||
});
|
});
|
||||||
test('Heal with bad checks', function() {
|
test('Heal with bad checks', function() {
|
||||||
let blocks = this.blocks;
|
const blocks = this.blocks;
|
||||||
|
|
||||||
// A and C can't connect, but both can connect to B.
|
// A and C can't connect, but both can connect to B.
|
||||||
blocks.A.inputList[0].connection.setCheck('type1');
|
blocks.A.inputList[0].connection.setCheck('type1');
|
||||||
@@ -252,21 +252,21 @@ suite('Blocks', function() {
|
|||||||
assertDisposedHealFailed(blocks);
|
assertDisposedHealFailed(blocks);
|
||||||
});
|
});
|
||||||
test('Parent has multiple inputs', function() {
|
test('Parent has multiple inputs', function() {
|
||||||
let blocks = this.blocks;
|
const blocks = this.blocks;
|
||||||
// Add extra input to parent
|
// Add extra input to parent
|
||||||
blocks.A.appendValueInput("INPUT").setCheck(null);
|
blocks.A.appendValueInput("INPUT").setCheck(null);
|
||||||
blocks.B.dispose(true);
|
blocks.B.dispose(true);
|
||||||
assertDisposedHealed(blocks);
|
assertDisposedHealed(blocks);
|
||||||
});
|
});
|
||||||
test('Middle has multiple inputs', function() {
|
test('Middle has multiple inputs', function() {
|
||||||
let blocks = this.blocks;
|
const blocks = this.blocks;
|
||||||
// Add extra input to middle block
|
// Add extra input to middle block
|
||||||
blocks.B.appendValueInput("INPUT").setCheck(null);
|
blocks.B.appendValueInput("INPUT").setCheck(null);
|
||||||
blocks.B.dispose(true);
|
blocks.B.dispose(true);
|
||||||
assertDisposedHealed(blocks);
|
assertDisposedHealed(blocks);
|
||||||
});
|
});
|
||||||
test('Child has multiple inputs', function() {
|
test('Child has multiple inputs', function() {
|
||||||
let blocks = this.blocks;
|
const blocks = this.blocks;
|
||||||
// Add extra input to child block
|
// Add extra input to child block
|
||||||
blocks.C.appendValueInput("INPUT").setCheck(null);
|
blocks.C.appendValueInput("INPUT").setCheck(null);
|
||||||
// Child block input count doesn't matter.
|
// Child block input count doesn't matter.
|
||||||
@@ -274,7 +274,7 @@ suite('Blocks', function() {
|
|||||||
assertDisposedHealed(blocks);
|
assertDisposedHealed(blocks);
|
||||||
});
|
});
|
||||||
test('Child is shadow', function() {
|
test('Child is shadow', function() {
|
||||||
let blocks = this.blocks;
|
const blocks = this.blocks;
|
||||||
blocks.C.setShadow(true);
|
blocks.C.setShadow(true);
|
||||||
blocks.B.dispose(true);
|
blocks.B.dispose(true);
|
||||||
// Even though we're asking to heal, it will appear as if it has not
|
// Even though we're asking to heal, it will appear as if it has not
|
||||||
@@ -296,7 +296,7 @@ suite('Blocks', function() {
|
|||||||
assertDisposedHealed(this.blocks);
|
assertDisposedHealed(this.blocks);
|
||||||
});
|
});
|
||||||
test('Heal with bad checks', function() {
|
test('Heal with bad checks', function() {
|
||||||
let blocks = this.blocks;
|
const blocks = this.blocks;
|
||||||
// A and C can't connect, but both can connect to B.
|
// A and C can't connect, but both can connect to B.
|
||||||
blocks.A.nextConnection.setCheck('type1');
|
blocks.A.nextConnection.setCheck('type1');
|
||||||
blocks.C.previousConnection.setCheck('type2');
|
blocks.C.previousConnection.setCheck('type2');
|
||||||
@@ -307,7 +307,7 @@ suite('Blocks', function() {
|
|||||||
assertDisposedHealFailed(blocks);
|
assertDisposedHealFailed(blocks);
|
||||||
});
|
});
|
||||||
test('Child is shadow', function() {
|
test('Child is shadow', function() {
|
||||||
let blocks = this.blocks;
|
const blocks = this.blocks;
|
||||||
blocks.C.setShadow(true);
|
blocks.C.setShadow(true);
|
||||||
blocks.B.dispose(true);
|
blocks.B.dispose(true);
|
||||||
// Even though we're asking to heal, it will appear as if it has not
|
// Even though we're asking to heal, it will appear as if it has not
|
||||||
@@ -342,7 +342,7 @@ suite('Blocks', function() {
|
|||||||
chai.assert.isNull(this.blockA.getInput('VALUE'));
|
chai.assert.isNull(this.blockA.getInput('VALUE'));
|
||||||
});
|
});
|
||||||
test('Block Connected', function() {
|
test('Block Connected', function() {
|
||||||
let blockB = this.workspace.newBlock('row_block');
|
const blockB = this.workspace.newBlock('row_block');
|
||||||
this.blockA.getInput('VALUE').connection
|
this.blockA.getInput('VALUE').connection
|
||||||
.connect(blockB.outputConnection);
|
.connect(blockB.outputConnection);
|
||||||
|
|
||||||
@@ -351,7 +351,7 @@ suite('Blocks', function() {
|
|||||||
chai.assert.equal(this.blockA.getChildren().length, 0);
|
chai.assert.equal(this.blockA.getChildren().length, 0);
|
||||||
});
|
});
|
||||||
test('Shadow Connected', function() {
|
test('Shadow Connected', function() {
|
||||||
let blockB = this.workspace.newBlock('row_block');
|
const blockB = this.workspace.newBlock('row_block');
|
||||||
blockB.setShadow(true);
|
blockB.setShadow(true);
|
||||||
this.blockA.getInput('VALUE').connection
|
this.blockA.getInput('VALUE').connection
|
||||||
.connect(blockB.outputConnection);
|
.connect(blockB.outputConnection);
|
||||||
@@ -371,7 +371,7 @@ suite('Blocks', function() {
|
|||||||
chai.assert.isNull(this.blockA.getInput('STATEMENT'));
|
chai.assert.isNull(this.blockA.getInput('STATEMENT'));
|
||||||
});
|
});
|
||||||
test('Block Connected', function() {
|
test('Block Connected', function() {
|
||||||
let blockB = this.workspace.newBlock('stack_block');
|
const blockB = this.workspace.newBlock('stack_block');
|
||||||
this.blockA.getInput('STATEMENT').connection
|
this.blockA.getInput('STATEMENT').connection
|
||||||
.connect(blockB.previousConnection);
|
.connect(blockB.previousConnection);
|
||||||
|
|
||||||
@@ -380,7 +380,7 @@ suite('Blocks', function() {
|
|||||||
chai.assert.equal(this.blockA.getChildren().length, 0);
|
chai.assert.equal(this.blockA.getChildren().length, 0);
|
||||||
});
|
});
|
||||||
test('Shadow Connected', function() {
|
test('Shadow Connected', function() {
|
||||||
let blockB = this.workspace.newBlock('stack_block');
|
const blockB = this.workspace.newBlock('stack_block');
|
||||||
blockB.setShadow(true);
|
blockB.setShadow(true);
|
||||||
this.blockA.getInput('STATEMENT').connection
|
this.blockA.getInput('STATEMENT').connection
|
||||||
.connect(blockB.previousConnection);
|
.connect(blockB.previousConnection);
|
||||||
@@ -426,7 +426,7 @@ suite('Blocks', function() {
|
|||||||
suite('Deserialization', function() {
|
suite('Deserialization', function() {
|
||||||
setup(function() {
|
setup(function() {
|
||||||
this.deserializationHelper = function(text) {
|
this.deserializationHelper = function(text) {
|
||||||
let dom = Blockly.Xml.textToDom(text);
|
const dom = Blockly.Xml.textToDom(text);
|
||||||
Blockly.Xml.appendDomToWorkspace(dom, this.workspace);
|
Blockly.Xml.appendDomToWorkspace(dom, this.workspace);
|
||||||
this.assertConnectionsEmpty();
|
this.assertConnectionsEmpty();
|
||||||
this.clock.runAll();
|
this.clock.runAll();
|
||||||
@@ -626,7 +626,7 @@ suite('Blocks', function() {
|
|||||||
});
|
});
|
||||||
suite('Programmatic Block Creation', function() {
|
suite('Programmatic Block Creation', function() {
|
||||||
test('Stack', function() {
|
test('Stack', function() {
|
||||||
let block = this.workspace.newBlock('stack_block');
|
const block = this.workspace.newBlock('stack_block');
|
||||||
this.assertConnectionsEmpty();
|
this.assertConnectionsEmpty();
|
||||||
block.initSvg();
|
block.initSvg();
|
||||||
block.render();
|
block.render();
|
||||||
@@ -635,7 +635,7 @@ suite('Blocks', function() {
|
|||||||
chai.assert.equal(this.getNext().length, 1);
|
chai.assert.equal(this.getNext().length, 1);
|
||||||
});
|
});
|
||||||
test('Row', function() {
|
test('Row', function() {
|
||||||
let block = this.workspace.newBlock('row_block');
|
const block = this.workspace.newBlock('row_block');
|
||||||
this.assertConnectionsEmpty();
|
this.assertConnectionsEmpty();
|
||||||
block.initSvg();
|
block.initSvg();
|
||||||
block.render();
|
block.render();
|
||||||
@@ -644,7 +644,7 @@ suite('Blocks', function() {
|
|||||||
chai.assert.equal(this.getInputs().length, 1);
|
chai.assert.equal(this.getInputs().length, 1);
|
||||||
});
|
});
|
||||||
test('Statement', function() {
|
test('Statement', function() {
|
||||||
let block = this.workspace.newBlock('statement_block');
|
const block = this.workspace.newBlock('statement_block');
|
||||||
this.assertConnectionsEmpty();
|
this.assertConnectionsEmpty();
|
||||||
block.initSvg();
|
block.initSvg();
|
||||||
block.render();
|
block.render();
|
||||||
@@ -655,7 +655,7 @@ suite('Blocks', function() {
|
|||||||
});
|
});
|
||||||
suite('setCollapsed', function() {
|
suite('setCollapsed', function() {
|
||||||
test('Stack', function() {
|
test('Stack', function() {
|
||||||
let block = Blockly.Xml.domToBlock(Blockly.Xml.textToDom(
|
const block = Blockly.Xml.domToBlock(Blockly.Xml.textToDom(
|
||||||
'<block type="stack_block"/>'
|
'<block type="stack_block"/>'
|
||||||
), this.workspace);
|
), this.workspace);
|
||||||
this.clock.runAll();
|
this.clock.runAll();
|
||||||
@@ -671,7 +671,7 @@ suite('Blocks', function() {
|
|||||||
chai.assert.equal(this.getNext().length, 1);
|
chai.assert.equal(this.getNext().length, 1);
|
||||||
});
|
});
|
||||||
test('Multi-Stack', function() {
|
test('Multi-Stack', function() {
|
||||||
let block = Blockly.Xml.domToBlock(Blockly.Xml.textToDom(
|
const block = Blockly.Xml.domToBlock(Blockly.Xml.textToDom(
|
||||||
'<block type="stack_block">' +
|
'<block type="stack_block">' +
|
||||||
' <next>' +
|
' <next>' +
|
||||||
' <block type="stack_block">' +
|
' <block type="stack_block">' +
|
||||||
@@ -696,7 +696,7 @@ suite('Blocks', function() {
|
|||||||
chai.assert.equal(this.getNext().length, 3);
|
chai.assert.equal(this.getNext().length, 3);
|
||||||
});
|
});
|
||||||
test('Row', function() {
|
test('Row', function() {
|
||||||
let block = Blockly.Xml.domToBlock(Blockly.Xml.textToDom(
|
const block = Blockly.Xml.domToBlock(Blockly.Xml.textToDom(
|
||||||
'<block type="row_block"/>'
|
'<block type="row_block"/>'
|
||||||
), this.workspace);
|
), this.workspace);
|
||||||
this.clock.runAll();
|
this.clock.runAll();
|
||||||
@@ -712,7 +712,7 @@ suite('Blocks', function() {
|
|||||||
chai.assert.equal(this.getInputs().length, 1);
|
chai.assert.equal(this.getInputs().length, 1);
|
||||||
});
|
});
|
||||||
test('Multi-Row', function() {
|
test('Multi-Row', function() {
|
||||||
let block = Blockly.Xml.domToBlock(Blockly.Xml.textToDom(
|
const block = Blockly.Xml.domToBlock(Blockly.Xml.textToDom(
|
||||||
'<block type="row_block">' +
|
'<block type="row_block">' +
|
||||||
' <value name="INPUT">' +
|
' <value name="INPUT">' +
|
||||||
' <block type="row_block">' +
|
' <block type="row_block">' +
|
||||||
@@ -763,7 +763,7 @@ suite('Blocks', function() {
|
|||||||
test('Multi-Row Double Collapse', function() {
|
test('Multi-Row Double Collapse', function() {
|
||||||
// Collapse middle -> Collapse top ->
|
// Collapse middle -> Collapse top ->
|
||||||
// Uncollapse top -> Uncollapse middle
|
// Uncollapse top -> Uncollapse middle
|
||||||
let block = Blockly.Xml.domToBlock(Blockly.Xml.textToDom(
|
const block = Blockly.Xml.domToBlock(Blockly.Xml.textToDom(
|
||||||
'<block type="row_block">' +
|
'<block type="row_block">' +
|
||||||
' <value name="INPUT">' +
|
' <value name="INPUT">' +
|
||||||
' <block type="row_block">' +
|
' <block type="row_block">' +
|
||||||
@@ -778,7 +778,7 @@ suite('Blocks', function() {
|
|||||||
chai.assert.equal(this.getOutputs().length, 3);
|
chai.assert.equal(this.getOutputs().length, 3);
|
||||||
chai.assert.equal(this.getInputs().length, 3);
|
chai.assert.equal(this.getInputs().length, 3);
|
||||||
|
|
||||||
let middleBlock = block.getInputTargetBlock('INPUT');
|
const middleBlock = block.getInputTargetBlock('INPUT');
|
||||||
middleBlock.setCollapsed(true);
|
middleBlock.setCollapsed(true);
|
||||||
chai.assert.equal(this.getOutputs().length, 2);
|
chai.assert.equal(this.getOutputs().length, 2);
|
||||||
chai.assert.equal(this.getInputs().length, 1);
|
chai.assert.equal(this.getInputs().length, 1);
|
||||||
@@ -796,7 +796,7 @@ suite('Blocks', function() {
|
|||||||
chai.assert.equal(this.getInputs().length, 3);
|
chai.assert.equal(this.getInputs().length, 3);
|
||||||
});
|
});
|
||||||
test('Statement', function() {
|
test('Statement', function() {
|
||||||
let block = Blockly.Xml.domToBlock(Blockly.Xml.textToDom(
|
const block = Blockly.Xml.domToBlock(Blockly.Xml.textToDom(
|
||||||
'<block type="statement_block"/>'
|
'<block type="statement_block"/>'
|
||||||
), this.workspace);
|
), this.workspace);
|
||||||
this.clock.runAll();
|
this.clock.runAll();
|
||||||
@@ -812,7 +812,7 @@ suite('Blocks', function() {
|
|||||||
chai.assert.equal(this.getNext().length, 2);
|
chai.assert.equal(this.getNext().length, 2);
|
||||||
});
|
});
|
||||||
test('Multi-Statement', function() {
|
test('Multi-Statement', function() {
|
||||||
let block = Blockly.Xml.domToBlock(Blockly.Xml.textToDom(
|
const block = Blockly.Xml.domToBlock(Blockly.Xml.textToDom(
|
||||||
'<block type="statement_block">' +
|
'<block type="statement_block">' +
|
||||||
' <statement name="STATEMENT">' +
|
' <statement name="STATEMENT">' +
|
||||||
' <block type="statement_block">' +
|
' <block type="statement_block">' +
|
||||||
@@ -863,7 +863,7 @@ suite('Blocks', function() {
|
|||||||
chai.assert.equal(this.getNext().length, 6);
|
chai.assert.equal(this.getNext().length, 6);
|
||||||
});
|
});
|
||||||
test('Multi-Statement Double Collapse', function() {
|
test('Multi-Statement Double Collapse', function() {
|
||||||
let block = Blockly.Xml.domToBlock(Blockly.Xml.textToDom(
|
const block = Blockly.Xml.domToBlock(Blockly.Xml.textToDom(
|
||||||
'<block type="statement_block">' +
|
'<block type="statement_block">' +
|
||||||
' <statement name="STATEMENT">' +
|
' <statement name="STATEMENT">' +
|
||||||
' <block type="statement_block">' +
|
' <block type="statement_block">' +
|
||||||
@@ -879,7 +879,7 @@ suite('Blocks', function() {
|
|||||||
chai.assert.equal(this.getPrevious().length, 3);
|
chai.assert.equal(this.getPrevious().length, 3);
|
||||||
chai.assert.equal(this.getNext().length, 6);
|
chai.assert.equal(this.getNext().length, 6);
|
||||||
|
|
||||||
let middleBlock = block.getInputTargetBlock('STATEMENT');
|
const middleBlock = block.getInputTargetBlock('STATEMENT');
|
||||||
middleBlock.setCollapsed(true);
|
middleBlock.setCollapsed(true);
|
||||||
chai.assert.equal(this.getPrevious().length, 2);
|
chai.assert.equal(this.getPrevious().length, 2);
|
||||||
chai.assert.equal(this.getNext().length, 3);
|
chai.assert.equal(this.getNext().length, 3);
|
||||||
@@ -989,7 +989,7 @@ suite('Blocks', function() {
|
|||||||
});
|
});
|
||||||
suite('Remove Connections Programmatically', function() {
|
suite('Remove Connections Programmatically', function() {
|
||||||
test('Output', function() {
|
test('Output', function() {
|
||||||
let block = createRenderedBlock(this.workspace, 'row_block');
|
const block = createRenderedBlock(this.workspace, 'row_block');
|
||||||
|
|
||||||
block.setOutput(false);
|
block.setOutput(false);
|
||||||
|
|
||||||
@@ -997,7 +997,7 @@ suite('Blocks', function() {
|
|||||||
chai.assert.equal(this.getInputs().length, 1);
|
chai.assert.equal(this.getInputs().length, 1);
|
||||||
});
|
});
|
||||||
test('Value', function() {
|
test('Value', function() {
|
||||||
let block = createRenderedBlock(this.workspace, 'row_block');
|
const block = createRenderedBlock(this.workspace, 'row_block');
|
||||||
|
|
||||||
block.removeInput('INPUT');
|
block.removeInput('INPUT');
|
||||||
|
|
||||||
@@ -1005,7 +1005,7 @@ suite('Blocks', function() {
|
|||||||
chai.assert.equal(this.getInputs().length, 0);
|
chai.assert.equal(this.getInputs().length, 0);
|
||||||
});
|
});
|
||||||
test('Previous', function() {
|
test('Previous', function() {
|
||||||
let block = createRenderedBlock(this.workspace, 'stack_block');
|
const block = createRenderedBlock(this.workspace, 'stack_block');
|
||||||
|
|
||||||
block.setPreviousStatement(false);
|
block.setPreviousStatement(false);
|
||||||
|
|
||||||
@@ -1013,7 +1013,7 @@ suite('Blocks', function() {
|
|||||||
chai.assert.equal(this.getNext().length, 1);
|
chai.assert.equal(this.getNext().length, 1);
|
||||||
});
|
});
|
||||||
test('Next', function() {
|
test('Next', function() {
|
||||||
let block = createRenderedBlock(this.workspace, 'stack_block');
|
const block = createRenderedBlock(this.workspace, 'stack_block');
|
||||||
|
|
||||||
block.setNextStatement(false);
|
block.setNextStatement(false);
|
||||||
|
|
||||||
@@ -1021,7 +1021,7 @@ suite('Blocks', function() {
|
|||||||
chai.assert.equal(this.getNext().length, 0);
|
chai.assert.equal(this.getNext().length, 0);
|
||||||
});
|
});
|
||||||
test('Statement', function() {
|
test('Statement', function() {
|
||||||
let block = createRenderedBlock(this.workspace, 'statement_block');
|
const block = createRenderedBlock(this.workspace, 'statement_block');
|
||||||
|
|
||||||
block.removeInput('STATEMENT');
|
block.removeInput('STATEMENT');
|
||||||
|
|
||||||
@@ -1031,7 +1031,7 @@ suite('Blocks', function() {
|
|||||||
});
|
});
|
||||||
suite('Add Connections Programmatically', function() {
|
suite('Add Connections Programmatically', function() {
|
||||||
test('Output', function() {
|
test('Output', function() {
|
||||||
let block = createRenderedBlock(this.workspace, 'empty_block');
|
const block = createRenderedBlock(this.workspace, 'empty_block');
|
||||||
// this.workspace.newBlock('empty_block');
|
// this.workspace.newBlock('empty_block');
|
||||||
// block.initSvg();
|
// block.initSvg();
|
||||||
// block.render();
|
// block.render();
|
||||||
@@ -1041,7 +1041,7 @@ suite('Blocks', function() {
|
|||||||
chai.assert.equal(this.getOutputs().length, 1);
|
chai.assert.equal(this.getOutputs().length, 1);
|
||||||
});
|
});
|
||||||
test('Value', function() {
|
test('Value', function() {
|
||||||
let block = this.workspace.newBlock('empty_block');
|
const block = this.workspace.newBlock('empty_block');
|
||||||
block.initSvg();
|
block.initSvg();
|
||||||
block.render();
|
block.render();
|
||||||
|
|
||||||
@@ -1050,7 +1050,7 @@ suite('Blocks', function() {
|
|||||||
chai.assert.equal(this.getInputs().length, 1);
|
chai.assert.equal(this.getInputs().length, 1);
|
||||||
});
|
});
|
||||||
test('Previous', function() {
|
test('Previous', function() {
|
||||||
let block = this.workspace.newBlock('empty_block');
|
const block = this.workspace.newBlock('empty_block');
|
||||||
block.initSvg();
|
block.initSvg();
|
||||||
block.render();
|
block.render();
|
||||||
|
|
||||||
@@ -1059,7 +1059,7 @@ suite('Blocks', function() {
|
|||||||
chai.assert.equal(this.getPrevious().length, 1);
|
chai.assert.equal(this.getPrevious().length, 1);
|
||||||
});
|
});
|
||||||
test('Next', function() {
|
test('Next', function() {
|
||||||
let block = this.workspace.newBlock('empty_block');
|
const block = this.workspace.newBlock('empty_block');
|
||||||
block.initSvg();
|
block.initSvg();
|
||||||
block.render();
|
block.render();
|
||||||
|
|
||||||
@@ -1068,7 +1068,7 @@ suite('Blocks', function() {
|
|||||||
chai.assert.equal(this.getNext().length, 1);
|
chai.assert.equal(this.getNext().length, 1);
|
||||||
});
|
});
|
||||||
test('Statement', function() {
|
test('Statement', function() {
|
||||||
let block = this.workspace.newBlock('empty_block');
|
const block = this.workspace.newBlock('empty_block');
|
||||||
block.initSvg();
|
block.initSvg();
|
||||||
block.render();
|
block.render();
|
||||||
|
|
||||||
@@ -1081,16 +1081,16 @@ suite('Blocks', function() {
|
|||||||
suite('Comments', function() {
|
suite('Comments', function() {
|
||||||
suite('Set/Get Text', function() {
|
suite('Set/Get Text', function() {
|
||||||
function assertCommentEvent(eventSpy, oldValue, newValue) {
|
function assertCommentEvent(eventSpy, oldValue, newValue) {
|
||||||
let calls = eventSpy.getCalls();
|
const calls = eventSpy.getCalls();
|
||||||
let event = calls[calls.length - 1].args[0];
|
const event = calls[calls.length - 1].args[0];
|
||||||
chai.assert.equal(event.type, eventUtils.BLOCK_CHANGE);
|
chai.assert.equal(event.type, eventUtils.BLOCK_CHANGE);
|
||||||
chai.assert.equal(event.element, 'comment');
|
chai.assert.equal(event.element, 'comment');
|
||||||
chai.assert.equal(event.oldValue, oldValue);
|
chai.assert.equal(event.oldValue, oldValue);
|
||||||
chai.assert.equal(event.newValue, newValue);
|
chai.assert.equal(event.newValue, newValue);
|
||||||
}
|
}
|
||||||
function assertNoCommentEvent(eventSpy) {
|
function assertNoCommentEvent(eventSpy) {
|
||||||
let calls = eventSpy.getCalls();
|
const calls = eventSpy.getCalls();
|
||||||
let event = calls[calls.length - 1].args[0];
|
const event = calls[calls.length - 1].args[0];
|
||||||
chai.assert.notEqual(event.type, eventUtils.BLOCK_CHANGE);
|
chai.assert.notEqual(event.type, eventUtils.BLOCK_CHANGE);
|
||||||
}
|
}
|
||||||
setup(function() {
|
setup(function() {
|
||||||
@@ -1165,7 +1165,7 @@ suite('Blocks', function() {
|
|||||||
});
|
});
|
||||||
test('Set While Visible - Editable', function() {
|
test('Set While Visible - Editable', function() {
|
||||||
this.block.setCommentText('test1');
|
this.block.setCommentText('test1');
|
||||||
let icon = this.block.getCommentIcon();
|
const icon = this.block.getCommentIcon();
|
||||||
icon.setVisible(true);
|
icon.setVisible(true);
|
||||||
|
|
||||||
this.block.setCommentText('test2');
|
this.block.setCommentText('test2');
|
||||||
@@ -1177,7 +1177,7 @@ suite('Blocks', function() {
|
|||||||
this.block.setCommentText('test1');
|
this.block.setCommentText('test1');
|
||||||
// Restored up by call to sinon.restore() in sharedTestTeardown()
|
// Restored up by call to sinon.restore() in sharedTestTeardown()
|
||||||
sinon.stub(this.block, 'isEditable').returns(false);
|
sinon.stub(this.block, 'isEditable').returns(false);
|
||||||
let icon = this.block.getCommentIcon();
|
const icon = this.block.getCommentIcon();
|
||||||
icon.setVisible(true);
|
icon.setVisible(true);
|
||||||
|
|
||||||
this.block.setCommentText('test2');
|
this.block.setCommentText('test2');
|
||||||
@@ -1188,7 +1188,7 @@ suite('Blocks', function() {
|
|||||||
});
|
});
|
||||||
test('Get Text While Editing', function() {
|
test('Get Text While Editing', function() {
|
||||||
this.block.setCommentText('test1');
|
this.block.setCommentText('test1');
|
||||||
let icon = this.block.getCommentIcon();
|
const icon = this.block.getCommentIcon();
|
||||||
icon.setVisible(true);
|
icon.setVisible(true);
|
||||||
icon.textarea_.value = 'test2';
|
icon.textarea_.value = 'test2';
|
||||||
icon.textarea_.dispatchEvent(new Event('input'));
|
icon.textarea_.dispatchEvent(new Event('input'));
|
||||||
@@ -1220,20 +1220,20 @@ suite('Blocks', function() {
|
|||||||
chai.assert.throws(this.block.getFieldValue.bind(this.block), TypeError);
|
chai.assert.throws(this.block.getFieldValue.bind(this.block), TypeError);
|
||||||
});
|
});
|
||||||
test('Getting Field with Wrong Type', function() {
|
test('Getting Field with Wrong Type', function() {
|
||||||
let testFunction = function() {
|
const testFunction = function() {
|
||||||
return 'TEXT';
|
return 'TEXT';
|
||||||
};
|
};
|
||||||
let inputs = [1, null, testFunction, {toString: testFunction}, ['TEXT']];
|
const inputs = [1, null, testFunction, {toString: testFunction}, ['TEXT']];
|
||||||
for (let i = 0; i < inputs.length; i++) {
|
for (let i = 0; i < inputs.length; i++) {
|
||||||
chai.assert.throws(this.block.getField.bind(this.block, inputs[i]),
|
chai.assert.throws(this.block.getField.bind(this.block, inputs[i]),
|
||||||
TypeError);
|
TypeError);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
test('Getting Value of Field with Wrong Type', function() {
|
test('Getting Value of Field with Wrong Type', function() {
|
||||||
let testFunction = function() {
|
const testFunction = function() {
|
||||||
return 'TEXT';
|
return 'TEXT';
|
||||||
};
|
};
|
||||||
let inputs = [1, null, testFunction, {toString: testFunction}, ['TEXT']];
|
const inputs = [1, null, testFunction, {toString: testFunction}, ['TEXT']];
|
||||||
for (let i = 0; i < inputs.length; i++) {
|
for (let i = 0; i < inputs.length; i++) {
|
||||||
chai.assert.throws(
|
chai.assert.throws(
|
||||||
this.block.getFieldValue.bind(this.block, inputs[i]), TypeError);
|
this.block.getFieldValue.bind(this.block, inputs[i]), TypeError);
|
||||||
@@ -1248,10 +1248,10 @@ suite('Blocks', function() {
|
|||||||
chai.assert.throws(this.block.setFieldValue.bind(this.block, 'test'));
|
chai.assert.throws(this.block.setFieldValue.bind(this.block, 'test'));
|
||||||
});
|
});
|
||||||
test('Setting Field with Wrong Type', function() {
|
test('Setting Field with Wrong Type', function() {
|
||||||
let testFunction = function() {
|
const testFunction = function() {
|
||||||
return 'TEXT';
|
return 'TEXT';
|
||||||
};
|
};
|
||||||
let inputs = [1, null, testFunction, {toString: testFunction}, ['TEXT']];
|
const inputs = [1, null, testFunction, {toString: testFunction}, ['TEXT']];
|
||||||
for (let i = 0; i < inputs.length; i++) {
|
for (let i = 0; i < inputs.length; i++) {
|
||||||
chai.assert.throws(this.block.setFieldValue.bind(this.block, 'test',
|
chai.assert.throws(this.block.setFieldValue.bind(this.block, 'test',
|
||||||
inputs[i]), TypeError);
|
inputs[i]), TypeError);
|
||||||
@@ -1269,7 +1269,7 @@ suite('Blocks', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
test('Has Icon', function() {
|
test('Has Icon', function() {
|
||||||
let block = Blockly.Xml.domToBlock(Blockly.Xml.textToDom(
|
const block = Blockly.Xml.domToBlock(Blockly.Xml.textToDom(
|
||||||
'<block type="statement_block"/>'
|
'<block type="statement_block"/>'
|
||||||
), this.workspace);
|
), this.workspace);
|
||||||
block.setCommentText('test text');
|
block.setCommentText('test text');
|
||||||
@@ -1279,14 +1279,14 @@ suite('Blocks', function() {
|
|||||||
chai.assert.isFalse(block.comment.isVisible());
|
chai.assert.isFalse(block.comment.isVisible());
|
||||||
});
|
});
|
||||||
test('Child Has Icon', function() {
|
test('Child Has Icon', function() {
|
||||||
let block = Blockly.Xml.domToBlock(Blockly.Xml.textToDom(
|
const block = Blockly.Xml.domToBlock(Blockly.Xml.textToDom(
|
||||||
'<block type="statement_block">' +
|
'<block type="statement_block">' +
|
||||||
' <statement name="STATEMENT">' +
|
' <statement name="STATEMENT">' +
|
||||||
' <block type="statement_block"/>' +
|
' <block type="statement_block"/>' +
|
||||||
' </statement>' +
|
' </statement>' +
|
||||||
'</block>'
|
'</block>'
|
||||||
), this.workspace);
|
), this.workspace);
|
||||||
let childBlock = block.getInputTargetBlock('STATEMENT');
|
const childBlock = block.getInputTargetBlock('STATEMENT');
|
||||||
childBlock.setCommentText('test text');
|
childBlock.setCommentText('test text');
|
||||||
childBlock.comment.setVisible(true);
|
childBlock.comment.setVisible(true);
|
||||||
chai.assert.isTrue(childBlock.comment.isVisible());
|
chai.assert.isTrue(childBlock.comment.isVisible());
|
||||||
@@ -1294,14 +1294,14 @@ suite('Blocks', function() {
|
|||||||
chai.assert.isFalse(childBlock.comment.isVisible());
|
chai.assert.isFalse(childBlock.comment.isVisible());
|
||||||
});
|
});
|
||||||
test('Next Block Has Icon', function() {
|
test('Next Block Has Icon', function() {
|
||||||
let block = Blockly.Xml.domToBlock(Blockly.Xml.textToDom(
|
const block = Blockly.Xml.domToBlock(Blockly.Xml.textToDom(
|
||||||
'<block type="statement_block">' +
|
'<block type="statement_block">' +
|
||||||
' <next>' +
|
' <next>' +
|
||||||
' <block type="statement_block"/>' +
|
' <block type="statement_block"/>' +
|
||||||
' </next>' +
|
' </next>' +
|
||||||
'</block>'
|
'</block>'
|
||||||
), this.workspace);
|
), this.workspace);
|
||||||
let nextBlock = block.getNextBlock();
|
const nextBlock = block.getNextBlock();
|
||||||
nextBlock.setCommentText('test text');
|
nextBlock.setCommentText('test text');
|
||||||
nextBlock.comment.setVisible(true);
|
nextBlock.comment.setVisible(true);
|
||||||
chai.assert.isTrue(nextBlock.comment.isVisible());
|
chai.assert.isTrue(nextBlock.comment.isVisible());
|
||||||
@@ -1322,7 +1322,7 @@ suite('Blocks', function() {
|
|||||||
chai.assert.isFalse(field.isVisible());
|
chai.assert.isFalse(field.isVisible());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
let icons = block.getIcons();
|
const icons = block.getIcons();
|
||||||
for (let i = 0, icon; (icon = icons[i]); i++) {
|
for (let i = 0, icon; (icon = icons[i]); i++) {
|
||||||
chai.assert.isFalse(icon.isVisible());
|
chai.assert.isFalse(icon.isVisible());
|
||||||
}
|
}
|
||||||
@@ -1355,7 +1355,7 @@ suite('Blocks', function() {
|
|||||||
function isBlockHidden(block) {
|
function isBlockHidden(block) {
|
||||||
let node = block.getSvgRoot();
|
let node = block.getSvgRoot();
|
||||||
do {
|
do {
|
||||||
let visible = node.style.display != 'none';
|
const visible = node.style.display != 'none';
|
||||||
if (!visible) {
|
if (!visible) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -1388,8 +1388,8 @@ suite('Blocks', function() {
|
|||||||
});
|
});
|
||||||
suite('Connecting and Disconnecting', function() {
|
suite('Connecting and Disconnecting', function() {
|
||||||
test('Connect Block to Next', function() {
|
test('Connect Block to Next', function() {
|
||||||
let blockA = createRenderedBlock(this.workspace, 'stack_block');
|
const blockA = createRenderedBlock(this.workspace, 'stack_block');
|
||||||
let blockB = createRenderedBlock(this.workspace, 'stack_block');
|
const blockB = createRenderedBlock(this.workspace, 'stack_block');
|
||||||
|
|
||||||
blockA.setCollapsed(true);
|
blockA.setCollapsed(true);
|
||||||
assertCollapsed(blockA);
|
assertCollapsed(blockA);
|
||||||
@@ -1397,8 +1397,8 @@ suite('Blocks', function() {
|
|||||||
assertNotCollapsed(blockB);
|
assertNotCollapsed(blockB);
|
||||||
});
|
});
|
||||||
test('Connect Block to Value Input', function() {
|
test('Connect Block to Value Input', function() {
|
||||||
let blockA = createRenderedBlock(this.workspace, 'row_block');
|
const blockA = createRenderedBlock(this.workspace, 'row_block');
|
||||||
let blockB = createRenderedBlock(this.workspace, 'row_block');
|
const blockB = createRenderedBlock(this.workspace, 'row_block');
|
||||||
|
|
||||||
blockA.setCollapsed(true);
|
blockA.setCollapsed(true);
|
||||||
assertCollapsed(blockA);
|
assertCollapsed(blockA);
|
||||||
@@ -1409,8 +1409,8 @@ suite('Blocks', function() {
|
|||||||
chai.assert.isFalse(isBlockHidden(blockB));
|
chai.assert.isFalse(isBlockHidden(blockB));
|
||||||
});
|
});
|
||||||
test('Connect Block to Statement Input', function() {
|
test('Connect Block to Statement Input', function() {
|
||||||
let blockA = createRenderedBlock(this.workspace, 'statement_block');
|
const blockA = createRenderedBlock(this.workspace, 'statement_block');
|
||||||
let blockB = createRenderedBlock(this.workspace, 'stack_block');
|
const blockB = createRenderedBlock(this.workspace, 'stack_block');
|
||||||
|
|
||||||
blockA.setCollapsed(true);
|
blockA.setCollapsed(true);
|
||||||
assertCollapsed(blockA);
|
assertCollapsed(blockA);
|
||||||
@@ -1422,9 +1422,9 @@ suite('Blocks', function() {
|
|||||||
chai.assert.isFalse(isBlockHidden(blockB));
|
chai.assert.isFalse(isBlockHidden(blockB));
|
||||||
});
|
});
|
||||||
test('Connect Block to Child of Collapsed - Input', function() {
|
test('Connect Block to Child of Collapsed - Input', function() {
|
||||||
let blockA = createRenderedBlock(this.workspace, 'row_block');
|
const blockA = createRenderedBlock(this.workspace, 'row_block');
|
||||||
let blockB = createRenderedBlock(this.workspace, 'row_block');
|
const blockB = createRenderedBlock(this.workspace, 'row_block');
|
||||||
let blockC = createRenderedBlock(this.workspace, 'row_block');
|
const blockC = createRenderedBlock(this.workspace, 'row_block');
|
||||||
|
|
||||||
blockA.getInput('INPUT').connection.connect(blockB.outputConnection);
|
blockA.getInput('INPUT').connection.connect(blockB.outputConnection);
|
||||||
blockA.setCollapsed(true);
|
blockA.setCollapsed(true);
|
||||||
@@ -1439,9 +1439,9 @@ suite('Blocks', function() {
|
|||||||
chai.assert.isFalse(isBlockHidden(blockC));
|
chai.assert.isFalse(isBlockHidden(blockC));
|
||||||
});
|
});
|
||||||
test('Connect Block to Child of Collapsed - Next', function() {
|
test('Connect Block to Child of Collapsed - Next', function() {
|
||||||
let blockA = createRenderedBlock(this.workspace, 'statement_block');
|
const blockA = createRenderedBlock(this.workspace, 'statement_block');
|
||||||
let blockB = createRenderedBlock(this.workspace, 'stack_block');
|
const blockB = createRenderedBlock(this.workspace, 'stack_block');
|
||||||
let blockC = createRenderedBlock(this.workspace, 'stack_block');
|
const blockC = createRenderedBlock(this.workspace, 'stack_block');
|
||||||
|
|
||||||
blockA.getInput('STATEMENT').connection
|
blockA.getInput('STATEMENT').connection
|
||||||
.connect(blockB.previousConnection);
|
.connect(blockB.previousConnection);
|
||||||
@@ -1457,9 +1457,9 @@ suite('Blocks', function() {
|
|||||||
chai.assert.isFalse(isBlockHidden(blockC));
|
chai.assert.isFalse(isBlockHidden(blockC));
|
||||||
});
|
});
|
||||||
test('Connect Block to Value Input Already Taken', function() {
|
test('Connect Block to Value Input Already Taken', function() {
|
||||||
let blockA = createRenderedBlock(this.workspace, 'row_block');
|
const blockA = createRenderedBlock(this.workspace, 'row_block');
|
||||||
let blockB = createRenderedBlock(this.workspace, 'row_block');
|
const blockB = createRenderedBlock(this.workspace, 'row_block');
|
||||||
let blockC = createRenderedBlock(this.workspace, 'row_block');
|
const blockC = createRenderedBlock(this.workspace, 'row_block');
|
||||||
|
|
||||||
blockA.getInput('INPUT').connection.connect(blockB.outputConnection);
|
blockA.getInput('INPUT').connection.connect(blockB.outputConnection);
|
||||||
blockA.setCollapsed(true);
|
blockA.setCollapsed(true);
|
||||||
@@ -1476,9 +1476,9 @@ suite('Blocks', function() {
|
|||||||
chai.assert.isFalse(isBlockHidden(blockC));
|
chai.assert.isFalse(isBlockHidden(blockC));
|
||||||
});
|
});
|
||||||
test('Connect Block to Statement Input Already Taken', function() {
|
test('Connect Block to Statement Input Already Taken', function() {
|
||||||
let blockA = createRenderedBlock(this.workspace, 'statement_block');
|
const blockA = createRenderedBlock(this.workspace, 'statement_block');
|
||||||
let blockB = createRenderedBlock(this.workspace, 'stack_block');
|
const blockB = createRenderedBlock(this.workspace, 'stack_block');
|
||||||
let blockC = createRenderedBlock(this.workspace, 'stack_block');
|
const blockC = createRenderedBlock(this.workspace, 'stack_block');
|
||||||
|
|
||||||
blockA.getInput('STATEMENT').connection
|
blockA.getInput('STATEMENT').connection
|
||||||
.connect(blockB.previousConnection);
|
.connect(blockB.previousConnection);
|
||||||
@@ -1497,9 +1497,9 @@ suite('Blocks', function() {
|
|||||||
chai.assert.isFalse(isBlockHidden(blockC));
|
chai.assert.isFalse(isBlockHidden(blockC));
|
||||||
});
|
});
|
||||||
test('Connect Block with Child - Input', function() {
|
test('Connect Block with Child - Input', function() {
|
||||||
let blockA = createRenderedBlock(this.workspace, 'row_block');
|
const blockA = createRenderedBlock(this.workspace, 'row_block');
|
||||||
let blockB = createRenderedBlock(this.workspace, 'row_block');
|
const blockB = createRenderedBlock(this.workspace, 'row_block');
|
||||||
let blockC = createRenderedBlock(this.workspace, 'row_block');
|
const blockC = createRenderedBlock(this.workspace, 'row_block');
|
||||||
|
|
||||||
blockB.getInput('INPUT').connection.connect(blockC.outputConnection);
|
blockB.getInput('INPUT').connection.connect(blockC.outputConnection);
|
||||||
blockA.setCollapsed(true);
|
blockA.setCollapsed(true);
|
||||||
@@ -1514,9 +1514,9 @@ suite('Blocks', function() {
|
|||||||
chai.assert.isFalse(isBlockHidden(blockC));
|
chai.assert.isFalse(isBlockHidden(blockC));
|
||||||
});
|
});
|
||||||
test('Connect Block with Child - Statement', function() {
|
test('Connect Block with Child - Statement', function() {
|
||||||
let blockA = createRenderedBlock(this.workspace, 'statement_block');
|
const blockA = createRenderedBlock(this.workspace, 'statement_block');
|
||||||
let blockB = createRenderedBlock(this.workspace, 'stack_block');
|
const blockB = createRenderedBlock(this.workspace, 'stack_block');
|
||||||
let blockC = createRenderedBlock(this.workspace, 'stack_block');
|
const blockC = createRenderedBlock(this.workspace, 'stack_block');
|
||||||
|
|
||||||
blockB.nextConnection.connect(blockC.previousConnection);
|
blockB.nextConnection.connect(blockC.previousConnection);
|
||||||
blockA.setCollapsed(true);
|
blockA.setCollapsed(true);
|
||||||
@@ -1532,8 +1532,8 @@ suite('Blocks', function() {
|
|||||||
chai.assert.isFalse(isBlockHidden(blockC));
|
chai.assert.isFalse(isBlockHidden(blockC));
|
||||||
});
|
});
|
||||||
test('Disconnect Block from Value Input', function() {
|
test('Disconnect Block from Value Input', function() {
|
||||||
let blockA = createRenderedBlock(this.workspace, 'row_block');
|
const blockA = createRenderedBlock(this.workspace, 'row_block');
|
||||||
let blockB = createRenderedBlock(this.workspace, 'row_block');
|
const blockB = createRenderedBlock(this.workspace, 'row_block');
|
||||||
|
|
||||||
blockA.getInput('INPUT').connection.connect(blockB.outputConnection);
|
blockA.getInput('INPUT').connection.connect(blockB.outputConnection);
|
||||||
blockA.setCollapsed(true);
|
blockA.setCollapsed(true);
|
||||||
@@ -1543,8 +1543,8 @@ suite('Blocks', function() {
|
|||||||
chai.assert.isFalse(isBlockHidden(blockB));
|
chai.assert.isFalse(isBlockHidden(blockB));
|
||||||
});
|
});
|
||||||
test('Disconnect Block from Statement Input', function() {
|
test('Disconnect Block from Statement Input', function() {
|
||||||
let blockA = createRenderedBlock(this.workspace, 'statement_block');
|
const blockA = createRenderedBlock(this.workspace, 'statement_block');
|
||||||
let blockB = createRenderedBlock(this.workspace, 'stack_block');
|
const blockB = createRenderedBlock(this.workspace, 'stack_block');
|
||||||
|
|
||||||
blockA.getInput('STATEMENT').connection
|
blockA.getInput('STATEMENT').connection
|
||||||
.connect(blockB.previousConnection);
|
.connect(blockB.previousConnection);
|
||||||
@@ -1555,9 +1555,9 @@ suite('Blocks', function() {
|
|||||||
chai.assert.isFalse(isBlockHidden(blockB));
|
chai.assert.isFalse(isBlockHidden(blockB));
|
||||||
});
|
});
|
||||||
test('Disconnect Block from Child of Collapsed - Input', function() {
|
test('Disconnect Block from Child of Collapsed - Input', function() {
|
||||||
let blockA = createRenderedBlock(this.workspace, 'row_block');
|
const blockA = createRenderedBlock(this.workspace, 'row_block');
|
||||||
let blockB = createRenderedBlock(this.workspace, 'row_block');
|
const blockB = createRenderedBlock(this.workspace, 'row_block');
|
||||||
let blockC = createRenderedBlock(this.workspace, 'row_block');
|
const blockC = createRenderedBlock(this.workspace, 'row_block');
|
||||||
|
|
||||||
blockA.getInput('INPUT').connection.connect(blockB.outputConnection);
|
blockA.getInput('INPUT').connection.connect(blockB.outputConnection);
|
||||||
blockB.getInput('INPUT').connection.connect(blockC.outputConnection);
|
blockB.getInput('INPUT').connection.connect(blockC.outputConnection);
|
||||||
@@ -1570,9 +1570,9 @@ suite('Blocks', function() {
|
|||||||
chai.assert.isFalse(isBlockHidden(blockC));
|
chai.assert.isFalse(isBlockHidden(blockC));
|
||||||
});
|
});
|
||||||
test('Disconnect Block from Child of Collapsed - Next', function() {
|
test('Disconnect Block from Child of Collapsed - Next', function() {
|
||||||
let blockA = createRenderedBlock(this.workspace, 'statement_block');
|
const blockA = createRenderedBlock(this.workspace, 'statement_block');
|
||||||
let blockB = createRenderedBlock(this.workspace, 'stack_block');
|
const blockB = createRenderedBlock(this.workspace, 'stack_block');
|
||||||
let blockC = createRenderedBlock(this.workspace, 'stack_block');
|
const blockC = createRenderedBlock(this.workspace, 'stack_block');
|
||||||
|
|
||||||
blockA.getInput('STATEMENT').connection
|
blockA.getInput('STATEMENT').connection
|
||||||
.connect(blockB.previousConnection);
|
.connect(blockB.previousConnection);
|
||||||
@@ -1586,9 +1586,9 @@ suite('Blocks', function() {
|
|||||||
chai.assert.isFalse(isBlockHidden(blockC));
|
chai.assert.isFalse(isBlockHidden(blockC));
|
||||||
});
|
});
|
||||||
test('Disconnect Block with Child - Input', function() {
|
test('Disconnect Block with Child - Input', function() {
|
||||||
let blockA = createRenderedBlock(this.workspace, 'row_block');
|
const blockA = createRenderedBlock(this.workspace, 'row_block');
|
||||||
let blockB = createRenderedBlock(this.workspace, 'row_block');
|
const blockB = createRenderedBlock(this.workspace, 'row_block');
|
||||||
let blockC = createRenderedBlock(this.workspace, 'row_block');
|
const blockC = createRenderedBlock(this.workspace, 'row_block');
|
||||||
|
|
||||||
blockB.getInput('INPUT').connection.connect(blockC.outputConnection);
|
blockB.getInput('INPUT').connection.connect(blockC.outputConnection);
|
||||||
blockA.getInput('INPUT').connection.connect(blockB.outputConnection);
|
blockA.getInput('INPUT').connection.connect(blockB.outputConnection);
|
||||||
@@ -1602,9 +1602,9 @@ suite('Blocks', function() {
|
|||||||
chai.assert.isFalse(isBlockHidden(blockC));
|
chai.assert.isFalse(isBlockHidden(blockC));
|
||||||
});
|
});
|
||||||
test('Disconnect Block with Child - Statement', function() {
|
test('Disconnect Block with Child - Statement', function() {
|
||||||
let blockA = createRenderedBlock(this.workspace, 'statement_block');
|
const blockA = createRenderedBlock(this.workspace, 'statement_block');
|
||||||
let blockB = createRenderedBlock(this.workspace, 'stack_block');
|
const blockB = createRenderedBlock(this.workspace, 'stack_block');
|
||||||
let blockC = createRenderedBlock(this.workspace, 'stack_block');
|
const blockC = createRenderedBlock(this.workspace, 'stack_block');
|
||||||
|
|
||||||
blockB.nextConnection.connect(blockC.previousConnection);
|
blockB.nextConnection.connect(blockC.previousConnection);
|
||||||
blockA.getInput('STATEMENT').connection
|
blockA.getInput('STATEMENT').connection
|
||||||
@@ -1621,7 +1621,7 @@ suite('Blocks', function() {
|
|||||||
});
|
});
|
||||||
suite('Adding and Removing Block Parts', function() {
|
suite('Adding and Removing Block Parts', function() {
|
||||||
test('Add Previous Connection', function() {
|
test('Add Previous Connection', function() {
|
||||||
let blockA = createRenderedBlock(this.workspace, 'empty_block');
|
const blockA = createRenderedBlock(this.workspace, 'empty_block');
|
||||||
blockA.setCollapsed(true);
|
blockA.setCollapsed(true);
|
||||||
assertCollapsed(blockA);
|
assertCollapsed(blockA);
|
||||||
blockA.setPreviousStatement(true);
|
blockA.setPreviousStatement(true);
|
||||||
@@ -1629,7 +1629,7 @@ suite('Blocks', function() {
|
|||||||
chai.assert.isNotNull(blockA.previousConnection);
|
chai.assert.isNotNull(blockA.previousConnection);
|
||||||
});
|
});
|
||||||
test('Add Next Connection', function() {
|
test('Add Next Connection', function() {
|
||||||
let blockA = createRenderedBlock(this.workspace, 'empty_block');
|
const blockA = createRenderedBlock(this.workspace, 'empty_block');
|
||||||
blockA.setCollapsed(true);
|
blockA.setCollapsed(true);
|
||||||
assertCollapsed(blockA);
|
assertCollapsed(blockA);
|
||||||
blockA.setNextStatement(true);
|
blockA.setNextStatement(true);
|
||||||
@@ -1637,7 +1637,7 @@ suite('Blocks', function() {
|
|||||||
chai.assert.isNotNull(blockA.nextConnection);
|
chai.assert.isNotNull(blockA.nextConnection);
|
||||||
});
|
});
|
||||||
test('Add Input', function() {
|
test('Add Input', function() {
|
||||||
let blockA = createRenderedBlock(this.workspace, 'empty_block');
|
const blockA = createRenderedBlock(this.workspace, 'empty_block');
|
||||||
blockA.setCollapsed(true);
|
blockA.setCollapsed(true);
|
||||||
assertCollapsed(blockA);
|
assertCollapsed(blockA);
|
||||||
blockA.appendDummyInput('NAME');
|
blockA.appendDummyInput('NAME');
|
||||||
@@ -1645,25 +1645,25 @@ suite('Blocks', function() {
|
|||||||
chai.assert.isNotNull(blockA.getInput('NAME'));
|
chai.assert.isNotNull(blockA.getInput('NAME'));
|
||||||
});
|
});
|
||||||
test('Add Field', function() {
|
test('Add Field', function() {
|
||||||
let blockA = createRenderedBlock(this.workspace, 'empty_block');
|
const blockA = createRenderedBlock(this.workspace, 'empty_block');
|
||||||
let input = blockA.appendDummyInput('NAME');
|
const input = blockA.appendDummyInput('NAME');
|
||||||
blockA.setCollapsed(true);
|
blockA.setCollapsed(true);
|
||||||
assertCollapsed(blockA);
|
assertCollapsed(blockA);
|
||||||
input.appendField(new Blockly.FieldLabel('test'), 'FIELD');
|
input.appendField(new Blockly.FieldLabel('test'), 'FIELD');
|
||||||
assertCollapsed(blockA);
|
assertCollapsed(blockA);
|
||||||
let field = blockA.getField('FIELD');
|
const field = blockA.getField('FIELD');
|
||||||
chai.assert.isNotNull(field);
|
chai.assert.isNotNull(field);
|
||||||
chai.assert.equal(field.getText(), 'test');
|
chai.assert.equal(field.getText(), 'test');
|
||||||
});
|
});
|
||||||
test('Add Icon', function() {
|
test('Add Icon', function() {
|
||||||
let blockA = createRenderedBlock(this.workspace, 'empty_block');
|
const blockA = createRenderedBlock(this.workspace, 'empty_block');
|
||||||
blockA.setCollapsed(true);
|
blockA.setCollapsed(true);
|
||||||
assertCollapsed(blockA);
|
assertCollapsed(blockA);
|
||||||
blockA.setCommentText('test');
|
blockA.setCommentText('test');
|
||||||
assertCollapsed(blockA);
|
assertCollapsed(blockA);
|
||||||
});
|
});
|
||||||
test('Remove Previous Connection', function() {
|
test('Remove Previous Connection', function() {
|
||||||
let blockA = createRenderedBlock(this.workspace, 'empty_block');
|
const blockA = createRenderedBlock(this.workspace, 'empty_block');
|
||||||
blockA.setPreviousStatement(true);
|
blockA.setPreviousStatement(true);
|
||||||
blockA.setCollapsed(true);
|
blockA.setCollapsed(true);
|
||||||
assertCollapsed(blockA);
|
assertCollapsed(blockA);
|
||||||
@@ -1672,7 +1672,7 @@ suite('Blocks', function() {
|
|||||||
chai.assert.isNull(blockA.previousConnection);
|
chai.assert.isNull(blockA.previousConnection);
|
||||||
});
|
});
|
||||||
test('Remove Next Connection', function() {
|
test('Remove Next Connection', function() {
|
||||||
let blockA = createRenderedBlock(this.workspace, 'empty_block');
|
const blockA = createRenderedBlock(this.workspace, 'empty_block');
|
||||||
blockA.setNextStatement(true);
|
blockA.setNextStatement(true);
|
||||||
blockA.setCollapsed(true);
|
blockA.setCollapsed(true);
|
||||||
assertCollapsed(blockA);
|
assertCollapsed(blockA);
|
||||||
@@ -1681,7 +1681,7 @@ suite('Blocks', function() {
|
|||||||
chai.assert.isNull(blockA.nextConnection);
|
chai.assert.isNull(blockA.nextConnection);
|
||||||
});
|
});
|
||||||
test('Remove Input', function() {
|
test('Remove Input', function() {
|
||||||
let blockA = createRenderedBlock(this.workspace, 'empty_block');
|
const blockA = createRenderedBlock(this.workspace, 'empty_block');
|
||||||
blockA.appendDummyInput('NAME');
|
blockA.appendDummyInput('NAME');
|
||||||
blockA.setCollapsed(true);
|
blockA.setCollapsed(true);
|
||||||
assertCollapsed(blockA);
|
assertCollapsed(blockA);
|
||||||
@@ -1690,18 +1690,18 @@ suite('Blocks', function() {
|
|||||||
chai.assert.isNull(blockA.getInput('NAME'));
|
chai.assert.isNull(blockA.getInput('NAME'));
|
||||||
});
|
});
|
||||||
test('Remove Field', function() {
|
test('Remove Field', function() {
|
||||||
let blockA = createRenderedBlock(this.workspace, 'empty_block');
|
const blockA = createRenderedBlock(this.workspace, 'empty_block');
|
||||||
let input = blockA.appendDummyInput('NAME');
|
const input = blockA.appendDummyInput('NAME');
|
||||||
input.appendField(new Blockly.FieldLabel('test'), 'FIELD');
|
input.appendField(new Blockly.FieldLabel('test'), 'FIELD');
|
||||||
blockA.setCollapsed(true);
|
blockA.setCollapsed(true);
|
||||||
assertCollapsed(blockA);
|
assertCollapsed(blockA);
|
||||||
input.removeField('FIELD');
|
input.removeField('FIELD');
|
||||||
assertCollapsed(blockA);
|
assertCollapsed(blockA);
|
||||||
let field = blockA.getField('FIELD');
|
const field = blockA.getField('FIELD');
|
||||||
chai.assert.isNull(field);
|
chai.assert.isNull(field);
|
||||||
});
|
});
|
||||||
test('Remove Icon', function() {
|
test('Remove Icon', function() {
|
||||||
let blockA = createRenderedBlock(this.workspace, 'empty_block');
|
const blockA = createRenderedBlock(this.workspace, 'empty_block');
|
||||||
blockA.setCommentText('test');
|
blockA.setCommentText('test');
|
||||||
blockA.setCollapsed(true);
|
blockA.setCollapsed(true);
|
||||||
assertCollapsed(blockA);
|
assertCollapsed(blockA);
|
||||||
@@ -1711,30 +1711,30 @@ suite('Blocks', function() {
|
|||||||
});
|
});
|
||||||
suite('Renaming Vars', function() {
|
suite('Renaming Vars', function() {
|
||||||
test('Simple Rename', function() {
|
test('Simple Rename', function() {
|
||||||
let blockA = createRenderedBlock(this.workspace, 'variable_block');
|
const blockA = createRenderedBlock(this.workspace, 'variable_block');
|
||||||
|
|
||||||
blockA.setCollapsed(true);
|
blockA.setCollapsed(true);
|
||||||
assertCollapsed(blockA, 'x');
|
assertCollapsed(blockA, 'x');
|
||||||
|
|
||||||
let variable = this.workspace.getVariable('x', '');
|
const variable = this.workspace.getVariable('x', '');
|
||||||
this.workspace.renameVariableById(variable.getId(), 'y');
|
this.workspace.renameVariableById(variable.getId(), 'y');
|
||||||
assertCollapsed(blockA, 'y');
|
assertCollapsed(blockA, 'y');
|
||||||
});
|
});
|
||||||
test('Coalesce, Different Case', function() {
|
test('Coalesce, Different Case', function() {
|
||||||
let blockA = createRenderedBlock(this.workspace, 'variable_block');
|
const blockA = createRenderedBlock(this.workspace, 'variable_block');
|
||||||
|
|
||||||
blockA.setCollapsed(true);
|
blockA.setCollapsed(true);
|
||||||
assertCollapsed(blockA, 'x');
|
assertCollapsed(blockA, 'x');
|
||||||
|
|
||||||
let variable = this.workspace.createVariable('y');
|
const variable = this.workspace.createVariable('y');
|
||||||
this.workspace.renameVariableById(variable.getId(), 'X');
|
this.workspace.renameVariableById(variable.getId(), 'X');
|
||||||
assertCollapsed(blockA, 'X');
|
assertCollapsed(blockA, 'X');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
suite('Disabled Blocks', function() {
|
suite('Disabled Blocks', function() {
|
||||||
test('Children of Collapsed Blocks Should Enable Properly', function() {
|
test('Children of Collapsed Blocks Should Enable Properly', function() {
|
||||||
let blockA = createRenderedBlock(this.workspace, 'statement_block');
|
const blockA = createRenderedBlock(this.workspace, 'statement_block');
|
||||||
let blockB = createRenderedBlock(this.workspace, 'stack_block');
|
const blockB = createRenderedBlock(this.workspace, 'stack_block');
|
||||||
blockA.getInput('STATEMENT').connection
|
blockA.getInput('STATEMENT').connection
|
||||||
.connect(blockB.previousConnection);
|
.connect(blockB.previousConnection);
|
||||||
// Disable the block and collapse it.
|
// Disable the block and collapse it.
|
||||||
@@ -1750,8 +1750,8 @@ suite('Blocks', function() {
|
|||||||
chai.assert.isFalse(blockB.getSvgRoot().classList.contains('blocklyDisabled'));
|
chai.assert.isFalse(blockB.getSvgRoot().classList.contains('blocklyDisabled'));
|
||||||
});
|
});
|
||||||
test('Children of Collapsed Block Should Not Update', function() {
|
test('Children of Collapsed Block Should Not Update', function() {
|
||||||
let blockA = createRenderedBlock(this.workspace, 'statement_block');
|
const blockA = createRenderedBlock(this.workspace, 'statement_block');
|
||||||
let blockB = createRenderedBlock(this.workspace, 'stack_block');
|
const blockB = createRenderedBlock(this.workspace, 'stack_block');
|
||||||
blockA.getInput('STATEMENT').connection
|
blockA.getInput('STATEMENT').connection
|
||||||
.connect(blockB.previousConnection);
|
.connect(blockB.previousConnection);
|
||||||
|
|
||||||
@@ -1759,7 +1759,7 @@ suite('Blocks', function() {
|
|||||||
blockA.setEnabled(false);
|
blockA.setEnabled(false);
|
||||||
blockA.setCollapsed(true);
|
blockA.setCollapsed(true);
|
||||||
|
|
||||||
let blockUpdateDisabled = sinon.stub(blockB, 'updateDisabled');
|
const blockUpdateDisabled = sinon.stub(blockB, 'updateDisabled');
|
||||||
|
|
||||||
// Enable the block before expanding it.
|
// Enable the block before expanding it.
|
||||||
blockA.setEnabled(true);
|
blockA.setEnabled(true);
|
||||||
@@ -1769,8 +1769,8 @@ suite('Blocks', function() {
|
|||||||
sinon.assert.notCalled(blockUpdateDisabled);
|
sinon.assert.notCalled(blockUpdateDisabled);
|
||||||
});
|
});
|
||||||
test('Disabled Children of Collapsed Blocks Should Stay Disabled', function() {
|
test('Disabled Children of Collapsed Blocks Should Stay Disabled', function() {
|
||||||
let blockA = createRenderedBlock(this.workspace, 'statement_block');
|
const blockA = createRenderedBlock(this.workspace, 'statement_block');
|
||||||
let blockB = createRenderedBlock(this.workspace, 'stack_block');
|
const blockB = createRenderedBlock(this.workspace, 'stack_block');
|
||||||
blockA.getInput('STATEMENT').connection
|
blockA.getInput('STATEMENT').connection
|
||||||
.connect(blockB.previousConnection);
|
.connect(blockB.previousConnection);
|
||||||
|
|
||||||
@@ -1854,7 +1854,7 @@ suite('Blocks', function() {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
suite('toString', function() {
|
suite('toString', function() {
|
||||||
let toStringTests = [
|
const toStringTests = [
|
||||||
{
|
{
|
||||||
name: 'statement block',
|
name: 'statement block',
|
||||||
xml: '<block type="controls_repeat_ext">' +
|
xml: '<block type="controls_repeat_ext">' +
|
||||||
@@ -1966,7 +1966,7 @@ suite('Blocks', function() {
|
|||||||
// Create mocha test cases for each toString test.
|
// Create mocha test cases for each toString test.
|
||||||
toStringTests.forEach(function(t) {
|
toStringTests.forEach(function(t) {
|
||||||
test(t.name, function() {
|
test(t.name, function() {
|
||||||
let block = Blockly.Xml.domToBlock(Blockly.Xml.textToDom(t.xml),
|
const block = Blockly.Xml.domToBlock(Blockly.Xml.textToDom(t.xml),
|
||||||
this.workspace);
|
this.workspace);
|
||||||
chai.assert.equal(block.toString(), t.toString);
|
chai.assert.equal(block.toString(), t.toString);
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -83,7 +83,7 @@ suite('Comments', function() {
|
|||||||
this.block.id);
|
this.block.id);
|
||||||
});
|
});
|
||||||
test('Not Editable -> Editable', function() {
|
test('Not Editable -> Editable', function() {
|
||||||
let editableStub = sinon.stub(this.block, 'isEditable').returns(false);
|
const editableStub = sinon.stub(this.block, 'isEditable').returns(false);
|
||||||
|
|
||||||
this.comment.setVisible(true);
|
this.comment.setVisible(true);
|
||||||
|
|
||||||
@@ -103,7 +103,7 @@ suite('Comments', function() {
|
|||||||
sinon.restore();
|
sinon.restore();
|
||||||
});
|
});
|
||||||
function assertBubbleSize(comment, height, width) {
|
function assertBubbleSize(comment, height, width) {
|
||||||
let size = comment.getBubbleSize();
|
const size = comment.getBubbleSize();
|
||||||
chai.assert.equal(size.height, height);
|
chai.assert.equal(size.height, height);
|
||||||
chai.assert.equal(size.width, width);
|
chai.assert.equal(size.width, width);
|
||||||
}
|
}
|
||||||
@@ -112,7 +112,7 @@ suite('Comments', function() {
|
|||||||
}
|
}
|
||||||
test('Set Size While Visible', function() {
|
test('Set Size While Visible', function() {
|
||||||
this.comment.setVisible(true);
|
this.comment.setVisible(true);
|
||||||
let bubbleSizeSpy = sinon.spy(this.comment.bubble_, 'setBubbleSize');
|
const bubbleSizeSpy = sinon.spy(this.comment.bubble_, 'setBubbleSize');
|
||||||
|
|
||||||
assertBubbleSizeDefault(this.comment);
|
assertBubbleSizeDefault(this.comment);
|
||||||
this.comment.setBubbleSize(100, 100);
|
this.comment.setBubbleSize(100, 100);
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ suite('Connection checker', function() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
test('Target Null', function() {
|
test('Target Null', function() {
|
||||||
let connection = new Blockly.Connection({}, Blockly.INPUT_VALUE);
|
const connection = new Blockly.Connection({}, Blockly.INPUT_VALUE);
|
||||||
assertReasonHelper(
|
assertReasonHelper(
|
||||||
this.checker,
|
this.checker,
|
||||||
connection,
|
connection,
|
||||||
@@ -35,9 +35,9 @@ suite('Connection checker', function() {
|
|||||||
Blockly.Connection.REASON_TARGET_NULL);
|
Blockly.Connection.REASON_TARGET_NULL);
|
||||||
});
|
});
|
||||||
test('Target Self', function() {
|
test('Target Self', function() {
|
||||||
let block = {workspace: 1};
|
const block = {workspace: 1};
|
||||||
let connection1 = new Blockly.Connection(block, Blockly.INPUT_VALUE);
|
const connection1 = new Blockly.Connection(block, Blockly.INPUT_VALUE);
|
||||||
let connection2 = new Blockly.Connection(block, Blockly.OUTPUT_VALUE);
|
const connection2 = new Blockly.Connection(block, Blockly.OUTPUT_VALUE);
|
||||||
|
|
||||||
assertReasonHelper(
|
assertReasonHelper(
|
||||||
this.checker,
|
this.checker,
|
||||||
@@ -46,9 +46,9 @@ suite('Connection checker', function() {
|
|||||||
Blockly.Connection.REASON_SELF_CONNECTION);
|
Blockly.Connection.REASON_SELF_CONNECTION);
|
||||||
});
|
});
|
||||||
test('Different Workspaces', function() {
|
test('Different Workspaces', function() {
|
||||||
let connection1 = new Blockly.Connection(
|
const connection1 = new Blockly.Connection(
|
||||||
{workspace: 1}, Blockly.INPUT_VALUE);
|
{workspace: 1}, Blockly.INPUT_VALUE);
|
||||||
let connection2 = new Blockly.Connection(
|
const connection2 = new Blockly.Connection(
|
||||||
{workspace: 2}, Blockly.OUTPUT_VALUE);
|
{workspace: 2}, Blockly.OUTPUT_VALUE);
|
||||||
|
|
||||||
assertReasonHelper(
|
assertReasonHelper(
|
||||||
@@ -61,10 +61,10 @@ suite('Connection checker', function() {
|
|||||||
setup(function() {
|
setup(function() {
|
||||||
// We have to declare each separately so that the connections belong
|
// We have to declare each separately so that the connections belong
|
||||||
// on different blocks.
|
// on different blocks.
|
||||||
let prevBlock = { isShadow: function() {}};
|
const prevBlock = { isShadow: function() {}};
|
||||||
let nextBlock = { isShadow: function() {}};
|
const nextBlock = { isShadow: function() {}};
|
||||||
let outBlock = { isShadow: function() {}};
|
const outBlock = { isShadow: function() {}};
|
||||||
let inBlock = { isShadow: function() {}};
|
const inBlock = { isShadow: function() {}};
|
||||||
this.previous = new Blockly.Connection(
|
this.previous = new Blockly.Connection(
|
||||||
prevBlock, Blockly.PREVIOUS_STATEMENT);
|
prevBlock, Blockly.PREVIOUS_STATEMENT);
|
||||||
this.next = new Blockly.Connection(
|
this.next = new Blockly.Connection(
|
||||||
@@ -161,10 +161,10 @@ suite('Connection checker', function() {
|
|||||||
});
|
});
|
||||||
suite('Shadows', function() {
|
suite('Shadows', function() {
|
||||||
test('Previous Shadow', function() {
|
test('Previous Shadow', function() {
|
||||||
let prevBlock = { isShadow: function() { return true; }};
|
const prevBlock = { isShadow: function() { return true; }};
|
||||||
let nextBlock = { isShadow: function() { return false; }};
|
const nextBlock = { isShadow: function() { return false; }};
|
||||||
let prev = new Blockly.Connection(prevBlock, Blockly.PREVIOUS_STATEMENT);
|
const prev = new Blockly.Connection(prevBlock, Blockly.PREVIOUS_STATEMENT);
|
||||||
let next = new Blockly.Connection(nextBlock, Blockly.NEXT_STATEMENT);
|
const next = new Blockly.Connection(nextBlock, Blockly.NEXT_STATEMENT);
|
||||||
|
|
||||||
assertReasonHelper(
|
assertReasonHelper(
|
||||||
this.checker,
|
this.checker,
|
||||||
@@ -173,10 +173,10 @@ suite('Connection checker', function() {
|
|||||||
Blockly.Connection.CAN_CONNECT);
|
Blockly.Connection.CAN_CONNECT);
|
||||||
});
|
});
|
||||||
test('Next Shadow', function() {
|
test('Next Shadow', function() {
|
||||||
let prevBlock = { isShadow: function() { return false; }};
|
const prevBlock = { isShadow: function() { return false; }};
|
||||||
let nextBlock = { isShadow: function() { return true; }};
|
const nextBlock = { isShadow: function() { return true; }};
|
||||||
let prev = new Blockly.Connection(prevBlock, Blockly.PREVIOUS_STATEMENT);
|
const prev = new Blockly.Connection(prevBlock, Blockly.PREVIOUS_STATEMENT);
|
||||||
let next = new Blockly.Connection(nextBlock, Blockly.NEXT_STATEMENT);
|
const next = new Blockly.Connection(nextBlock, Blockly.NEXT_STATEMENT);
|
||||||
|
|
||||||
assertReasonHelper(
|
assertReasonHelper(
|
||||||
this.checker,
|
this.checker,
|
||||||
@@ -185,10 +185,10 @@ suite('Connection checker', function() {
|
|||||||
Blockly.Connection.REASON_SHADOW_PARENT);
|
Blockly.Connection.REASON_SHADOW_PARENT);
|
||||||
});
|
});
|
||||||
test('Prev and Next Shadow', function() {
|
test('Prev and Next Shadow', function() {
|
||||||
let prevBlock = { isShadow: function() { return true; }};
|
const prevBlock = { isShadow: function() { return true; }};
|
||||||
let nextBlock = { isShadow: function() { return true; }};
|
const nextBlock = { isShadow: function() { return true; }};
|
||||||
let prev = new Blockly.Connection(prevBlock, Blockly.PREVIOUS_STATEMENT);
|
const prev = new Blockly.Connection(prevBlock, Blockly.PREVIOUS_STATEMENT);
|
||||||
let next = new Blockly.Connection(nextBlock, Blockly.NEXT_STATEMENT);
|
const next = new Blockly.Connection(nextBlock, Blockly.NEXT_STATEMENT);
|
||||||
|
|
||||||
assertReasonHelper(
|
assertReasonHelper(
|
||||||
this.checker,
|
this.checker,
|
||||||
@@ -197,10 +197,10 @@ suite('Connection checker', function() {
|
|||||||
Blockly.Connection.CAN_CONNECT);
|
Blockly.Connection.CAN_CONNECT);
|
||||||
});
|
});
|
||||||
test('Output Shadow', function() {
|
test('Output Shadow', function() {
|
||||||
let outBlock = { isShadow: function() { return true; }};
|
const outBlock = { isShadow: function() { return true; }};
|
||||||
let inBlock = { isShadow: function() { return false; }};
|
const inBlock = { isShadow: function() { return false; }};
|
||||||
let outCon = new Blockly.Connection(outBlock, Blockly.OUTPUT_VALUE);
|
const outCon = new Blockly.Connection(outBlock, Blockly.OUTPUT_VALUE);
|
||||||
let inCon = new Blockly.Connection(inBlock, Blockly.INPUT_VALUE);
|
const inCon = new Blockly.Connection(inBlock, Blockly.INPUT_VALUE);
|
||||||
|
|
||||||
assertReasonHelper(
|
assertReasonHelper(
|
||||||
this.checker,
|
this.checker,
|
||||||
@@ -209,10 +209,10 @@ suite('Connection checker', function() {
|
|||||||
Blockly.Connection.CAN_CONNECT);
|
Blockly.Connection.CAN_CONNECT);
|
||||||
});
|
});
|
||||||
test('Input Shadow', function() {
|
test('Input Shadow', function() {
|
||||||
let outBlock = { isShadow: function() { return false; }};
|
const outBlock = { isShadow: function() { return false; }};
|
||||||
let inBlock = { isShadow: function() { return true; }};
|
const inBlock = { isShadow: function() { return true; }};
|
||||||
let outCon = new Blockly.Connection(outBlock, Blockly.OUTPUT_VALUE);
|
const outCon = new Blockly.Connection(outBlock, Blockly.OUTPUT_VALUE);
|
||||||
let inCon = new Blockly.Connection(inBlock, Blockly.INPUT_VALUE);
|
const inCon = new Blockly.Connection(inBlock, Blockly.INPUT_VALUE);
|
||||||
|
|
||||||
assertReasonHelper(
|
assertReasonHelper(
|
||||||
this.checker,
|
this.checker,
|
||||||
@@ -221,10 +221,10 @@ suite('Connection checker', function() {
|
|||||||
Blockly.Connection.REASON_SHADOW_PARENT);
|
Blockly.Connection.REASON_SHADOW_PARENT);
|
||||||
});
|
});
|
||||||
test('Output and Input Shadow', function() {
|
test('Output and Input Shadow', function() {
|
||||||
let outBlock = { isShadow: function() { return true; }};
|
const outBlock = { isShadow: function() { return true; }};
|
||||||
let inBlock = { isShadow: function() { return true; }};
|
const inBlock = { isShadow: function() { return true; }};
|
||||||
let outCon = new Blockly.Connection(outBlock, Blockly.OUTPUT_VALUE);
|
const outCon = new Blockly.Connection(outBlock, Blockly.OUTPUT_VALUE);
|
||||||
let inCon = new Blockly.Connection(inBlock, Blockly.INPUT_VALUE);
|
const inCon = new Blockly.Connection(inBlock, Blockly.INPUT_VALUE);
|
||||||
|
|
||||||
assertReasonHelper(
|
assertReasonHelper(
|
||||||
this.checker,
|
this.checker,
|
||||||
|
|||||||
@@ -15,18 +15,18 @@ suite('Connection Database', function() {
|
|||||||
this.database = new Blockly.ConnectionDB(new Blockly.ConnectionChecker());
|
this.database = new Blockly.ConnectionDB(new Blockly.ConnectionChecker());
|
||||||
|
|
||||||
this.assertOrder = function() {
|
this.assertOrder = function() {
|
||||||
let length = this.database.connections_.length;
|
const length = this.database.connections_.length;
|
||||||
for (let i = 1; i < length; i++) {
|
for (let i = 1; i < length; i++) {
|
||||||
chai.assert.isAtMost(this.database.connections_[i - 1].y,
|
chai.assert.isAtMost(this.database.connections_[i - 1].y,
|
||||||
this.database.connections_[i].y);
|
this.database.connections_[i].y);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
this.createConnection = function(x, y, type, opt_database) {
|
this.createConnection = function(x, y, type, opt_database) {
|
||||||
let workspace = {
|
const workspace = {
|
||||||
connectionDBList: []
|
connectionDBList: []
|
||||||
};
|
};
|
||||||
workspace.connectionDBList[type] = opt_database || this.database;
|
workspace.connectionDBList[type] = opt_database || this.database;
|
||||||
let connection = new Blockly.RenderedConnection(
|
const connection = new Blockly.RenderedConnection(
|
||||||
{workspace: workspace}, type);
|
{workspace: workspace}, type);
|
||||||
connection.x = x;
|
connection.x = x;
|
||||||
connection.y = y;
|
connection.y = y;
|
||||||
@@ -34,7 +34,7 @@ suite('Connection Database', function() {
|
|||||||
};
|
};
|
||||||
this.createSimpleTestConnections = function() {
|
this.createSimpleTestConnections = function() {
|
||||||
for (let i = 0; i < 10; i++) {
|
for (let i = 0; i < 10; i++) {
|
||||||
let connection = this.createConnection(0, i, Blockly.PREVIOUS_STATEMENT);
|
const connection = this.createConnection(0, i, Blockly.PREVIOUS_STATEMENT);
|
||||||
this.database.addConnection(connection, i);
|
this.database.addConnection(connection, i);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -43,11 +43,11 @@ suite('Connection Database', function() {
|
|||||||
sharedTestTeardown.call(this);
|
sharedTestTeardown.call(this);
|
||||||
});
|
});
|
||||||
test('Add Connection', function() {
|
test('Add Connection', function() {
|
||||||
let y2 = {y: 2};
|
const y2 = {y: 2};
|
||||||
let y4 = {y: 4};
|
const y4 = {y: 4};
|
||||||
let y1 = {y: 1};
|
const y1 = {y: 1};
|
||||||
let y3a = {y: 3};
|
const y3a = {y: 3};
|
||||||
let y3b = {y: 3};
|
const y3b = {y: 3};
|
||||||
|
|
||||||
this.database.addConnection(y2, 2);
|
this.database.addConnection(y2, 2);
|
||||||
chai.assert.sameOrderedMembers(
|
chai.assert.sameOrderedMembers(
|
||||||
@@ -71,12 +71,12 @@ suite('Connection Database', function() {
|
|||||||
|
|
||||||
});
|
});
|
||||||
test('Remove Connection', function() {
|
test('Remove Connection', function() {
|
||||||
let y2 = {y: 2};
|
const y2 = {y: 2};
|
||||||
let y4 = {y: 4};
|
const y4 = {y: 4};
|
||||||
let y1 = {y: 1};
|
const y1 = {y: 1};
|
||||||
let y3a = {y: 3};
|
const y3a = {y: 3};
|
||||||
let y3b = {y: 3};
|
const y3b = {y: 3};
|
||||||
let y3c = {y: 3};
|
const y3c = {y: 3};
|
||||||
|
|
||||||
this.database.addConnection(y2, 2);
|
this.database.addConnection(y2, 2);
|
||||||
this.database.addConnection(y4, 4);
|
this.database.addConnection(y4, 4);
|
||||||
@@ -113,76 +113,76 @@ suite('Connection Database', function() {
|
|||||||
});
|
});
|
||||||
suite('Get Neighbors', function() {
|
suite('Get Neighbors', function() {
|
||||||
test('Empty Database', function() {
|
test('Empty Database', function() {
|
||||||
let connection = this.createConnection(0, 0, Blockly.NEXT_STATEMENT,
|
const connection = this.createConnection(0, 0, Blockly.NEXT_STATEMENT,
|
||||||
new Blockly.ConnectionDB());
|
new Blockly.ConnectionDB());
|
||||||
chai.assert.isEmpty(this.database.getNeighbours(connection), 100);
|
chai.assert.isEmpty(this.database.getNeighbours(connection), 100);
|
||||||
});
|
});
|
||||||
test('Block At Top', function() {
|
test('Block At Top', function() {
|
||||||
this.createSimpleTestConnections();
|
this.createSimpleTestConnections();
|
||||||
|
|
||||||
let checkConnection = this.createConnection(0, 0, Blockly.NEXT_STATEMENT,
|
const checkConnection = this.createConnection(0, 0, Blockly.NEXT_STATEMENT,
|
||||||
new Blockly.ConnectionDB());
|
new Blockly.ConnectionDB());
|
||||||
let neighbors = this.database.getNeighbours(checkConnection, 4);
|
const neighbors = this.database.getNeighbours(checkConnection, 4);
|
||||||
chai.assert.sameMembers(neighbors, this.database.connections_.slice(0, 5));
|
chai.assert.sameMembers(neighbors, this.database.connections_.slice(0, 5));
|
||||||
});
|
});
|
||||||
test('Block In Middle', function() {
|
test('Block In Middle', function() {
|
||||||
this.createSimpleTestConnections();
|
this.createSimpleTestConnections();
|
||||||
|
|
||||||
let checkConnection = this.createConnection(0, 4, Blockly.NEXT_STATEMENT,
|
const checkConnection = this.createConnection(0, 4, Blockly.NEXT_STATEMENT,
|
||||||
new Blockly.ConnectionDB());
|
new Blockly.ConnectionDB());
|
||||||
let neighbors = this.database.getNeighbours(checkConnection, 2);
|
const neighbors = this.database.getNeighbours(checkConnection, 2);
|
||||||
chai.assert.sameMembers(neighbors, this.database.connections_.slice(2, 7));
|
chai.assert.sameMembers(neighbors, this.database.connections_.slice(2, 7));
|
||||||
});
|
});
|
||||||
test('Block At End', function() {
|
test('Block At End', function() {
|
||||||
this.createSimpleTestConnections();
|
this.createSimpleTestConnections();
|
||||||
|
|
||||||
let checkConnection = this.createConnection(0, 9, Blockly.NEXT_STATEMENT,
|
const checkConnection = this.createConnection(0, 9, Blockly.NEXT_STATEMENT,
|
||||||
new Blockly.ConnectionDB());
|
new Blockly.ConnectionDB());
|
||||||
let neighbors = this.database.getNeighbours(checkConnection, 4);
|
const neighbors = this.database.getNeighbours(checkConnection, 4);
|
||||||
chai.assert.sameMembers(neighbors, this.database.connections_.slice(5, 10));
|
chai.assert.sameMembers(neighbors, this.database.connections_.slice(5, 10));
|
||||||
});
|
});
|
||||||
test('Out of Range X', function() {
|
test('Out of Range X', function() {
|
||||||
this.createSimpleTestConnections();
|
this.createSimpleTestConnections();
|
||||||
|
|
||||||
let checkConnection = this.createConnection(10, 9, Blockly.NEXT_STATEMENT,
|
const checkConnection = this.createConnection(10, 9, Blockly.NEXT_STATEMENT,
|
||||||
new Blockly.ConnectionDB());
|
new Blockly.ConnectionDB());
|
||||||
let neighbors = this.database.getNeighbours(checkConnection, 4);
|
const neighbors = this.database.getNeighbours(checkConnection, 4);
|
||||||
chai.assert.isEmpty(neighbors);
|
chai.assert.isEmpty(neighbors);
|
||||||
});
|
});
|
||||||
test('Out of Range Y', function() {
|
test('Out of Range Y', function() {
|
||||||
this.createSimpleTestConnections();
|
this.createSimpleTestConnections();
|
||||||
|
|
||||||
let checkConnection = this.createConnection(0, 19, Blockly.NEXT_STATEMENT,
|
const checkConnection = this.createConnection(0, 19, Blockly.NEXT_STATEMENT,
|
||||||
new Blockly.ConnectionDB());
|
new Blockly.ConnectionDB());
|
||||||
let neighbors = this.database.getNeighbours(checkConnection, 4);
|
const neighbors = this.database.getNeighbours(checkConnection, 4);
|
||||||
chai.assert.isEmpty(neighbors);
|
chai.assert.isEmpty(neighbors);
|
||||||
});
|
});
|
||||||
test('Out of Range Diagonal', function() {
|
test('Out of Range Diagonal', function() {
|
||||||
this.createSimpleTestConnections();
|
this.createSimpleTestConnections();
|
||||||
|
|
||||||
let checkConnection = this.createConnection(-2, -2, Blockly.NEXT_STATEMENT,
|
const checkConnection = this.createConnection(-2, -2, Blockly.NEXT_STATEMENT,
|
||||||
new Blockly.ConnectionDB());
|
new Blockly.ConnectionDB());
|
||||||
let neighbors = this.database.getNeighbours(checkConnection, 2);
|
const neighbors = this.database.getNeighbours(checkConnection, 2);
|
||||||
chai.assert.isEmpty(neighbors);
|
chai.assert.isEmpty(neighbors);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
suite('Ordering', function() {
|
suite('Ordering', function() {
|
||||||
test('Simple', function() {
|
test('Simple', function() {
|
||||||
for (let i = 0; i < 10; i++) {
|
for (let i = 0; i < 10; i++) {
|
||||||
let connection = this.createConnection(0, i, Blockly.NEXT_STATEMENT);
|
const connection = this.createConnection(0, i, Blockly.NEXT_STATEMENT);
|
||||||
this.database.addConnection(connection, i);
|
this.database.addConnection(connection, i);
|
||||||
}
|
}
|
||||||
this.assertOrder();
|
this.assertOrder();
|
||||||
});
|
});
|
||||||
test('Quasi-Random', function() {
|
test('Quasi-Random', function() {
|
||||||
let xCoords = [-29, -47, -77, 2, 43, 34, -59, -52, -90, -36, -91, 38,
|
const xCoords = [-29, -47, -77, 2, 43, 34, -59, -52, -90, -36, -91, 38,
|
||||||
87, -20, 60, 4, -57, 65, -37, -81, 57, 58, -96, 1, 67, -79, 34, 93,
|
87, -20, 60, 4, -57, 65, -37, -81, 57, 58, -96, 1, 67, -79, 34, 93,
|
||||||
-90, -99, -62, 4, 11, -36, -51, -72, 3, -50, -24, -45, -92, -38, 37,
|
-90, -99, -62, 4, 11, -36, -51, -72, 3, -50, -24, -45, -92, -38, 37,
|
||||||
24, -47, -73, 79, -20, 99, 43, -10, -87, 19, 35, -62, -36, 49, 86,
|
24, -47, -73, 79, -20, 99, 43, -10, -87, 19, 35, -62, -36, 49, 86,
|
||||||
-24, -47, -89, 33, -44, 25, -73, -91, 85, 6, 0, 89, -94, 36, -35, 84,
|
-24, -47, -89, 33, -44, 25, -73, -91, 85, 6, 0, 89, -94, 36, -35, 84,
|
||||||
-9, 96, -21, 52, 10, -95, 7, -67, -70, 62, 9, -40, -95, -9, -94, 55,
|
-9, 96, -21, 52, 10, -95, 7, -67, -70, 62, 9, -40, -95, -9, -94, 55,
|
||||||
57, -96, 55, 8, -48, -57, -87, 81, 23, 65];
|
57, -96, 55, 8, -48, -57, -87, 81, 23, 65];
|
||||||
let yCoords = [-81, 82, 5, 47, 30, 57, -12, 28, 38, 92, -25, -20, 23,
|
const yCoords = [-81, 82, 5, 47, 30, 57, -12, 28, 38, 92, -25, -20, 23,
|
||||||
-51, 73, -90, 8, 28, -51, -15, 81, -60, -6, -16, 77, -62, -42, -24,
|
-51, 73, -90, 8, 28, -51, -15, 81, -60, -6, -16, 77, -62, -42, -24,
|
||||||
35, 95, -46, -7, 61, -16, 14, 91, 57, -38, 27, -39, 92, 47, -98, 11,
|
35, 95, -46, -7, 61, -16, 14, 91, 57, -38, 27, -39, 92, 47, -98, 11,
|
||||||
-33, -72, 64, 38, -64, -88, -35, -59, -76, -94, 45, -25, -100, -95,
|
-33, -72, 64, 38, -64, -88, -35, -59, -76, -94, 45, -25, -100, -95,
|
||||||
@@ -190,9 +190,9 @@ suite('Connection Database', function() {
|
|||||||
-23, 5, -2, -13, -9, 48, 74, -97, -11, 35, -79, -16, -77, 83, -57,
|
-23, 5, -2, -13, -9, 48, 74, -97, -11, 35, -79, -16, -77, 83, -57,
|
||||||
-53, 35, -44, 100, -27, -15, 5, 39, 33, -19, -20, -95];
|
-53, 35, -44, 100, -27, -15, 5, 39, 33, -19, -20, -95];
|
||||||
|
|
||||||
let length = xCoords.length;
|
const length = xCoords.length;
|
||||||
for (let i = 0; i < length; i++) {
|
for (let i = 0; i < length; i++) {
|
||||||
let connection = this.createConnection(xCoords[i], yCoords[i],
|
const connection = this.createConnection(xCoords[i], yCoords[i],
|
||||||
Blockly.NEXT_STATEMENT);
|
Blockly.NEXT_STATEMENT);
|
||||||
this.database.addConnection(connection, yCoords[i]);
|
this.database.addConnection(connection, yCoords[i]);
|
||||||
}
|
}
|
||||||
@@ -215,22 +215,22 @@ suite('Connection Database', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
this.createCheckConnection = function(x, y) {
|
this.createCheckConnection = function(x, y) {
|
||||||
let checkConnection = this.createConnection(x, y, Blockly.NEXT_STATEMENT,
|
const checkConnection = this.createConnection(x, y, Blockly.NEXT_STATEMENT,
|
||||||
new Blockly.ConnectionDB());
|
new Blockly.ConnectionDB());
|
||||||
return checkConnection;
|
return checkConnection;
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
test('Empty Database', function() {
|
test('Empty Database', function() {
|
||||||
let checkConnection = this.createConnection(0, 0, Blockly.NEXT_STATEMENT,
|
const checkConnection = this.createConnection(0, 0, Blockly.NEXT_STATEMENT,
|
||||||
new Blockly.ConnectionDB());
|
new Blockly.ConnectionDB());
|
||||||
chai.assert.isNull(this.database.searchForClosest(
|
chai.assert.isNull(this.database.searchForClosest(
|
||||||
checkConnection, 100, {x: 0, y: 0}).connection);
|
checkConnection, 100, {x: 0, y: 0}).connection);
|
||||||
});
|
});
|
||||||
test('Too Far', function() {
|
test('Too Far', function() {
|
||||||
let connection = this.createConnection(0, 100, Blockly.PREVIOUS_STATEMENT);
|
const connection = this.createConnection(0, 100, Blockly.PREVIOUS_STATEMENT);
|
||||||
this.database.addConnection(connection, 100);
|
this.database.addConnection(connection, 100);
|
||||||
|
|
||||||
let checkConnection = this.createConnection(0, 0, Blockly.NEXT_STATEMENT,
|
const checkConnection = this.createConnection(0, 0, Blockly.NEXT_STATEMENT,
|
||||||
new Blockly.ConnectionDB());
|
new Blockly.ConnectionDB());
|
||||||
chai.assert.isNull(this.database.searchForClosest(
|
chai.assert.isNull(this.database.searchForClosest(
|
||||||
checkConnection, 50, {x: 0, y: 0}).connection);
|
checkConnection, 50, {x: 0, y: 0}).connection);
|
||||||
@@ -238,32 +238,32 @@ suite('Connection Database', function() {
|
|||||||
test('Single in Range', function() {
|
test('Single in Range', function() {
|
||||||
this.createSimpleTestConnections();
|
this.createSimpleTestConnections();
|
||||||
|
|
||||||
let checkConnection = this.createCheckConnection(0, 14);
|
const checkConnection = this.createCheckConnection(0, 14);
|
||||||
|
|
||||||
let last = this.database.connections_[9];
|
const last = this.database.connections_[9];
|
||||||
let closest = this.database.searchForClosest(
|
const closest = this.database.searchForClosest(
|
||||||
checkConnection, 5, {x: 0, y: 0}).connection;
|
checkConnection, 5, {x: 0, y: 0}).connection;
|
||||||
chai.assert.equal(last, closest);
|
chai.assert.equal(last, closest);
|
||||||
});
|
});
|
||||||
test('Many in Range', function() {
|
test('Many in Range', function() {
|
||||||
this.createSimpleTestConnections();
|
this.createSimpleTestConnections();
|
||||||
|
|
||||||
let checkConnection = this.createCheckConnection(0, 10);
|
const checkConnection = this.createCheckConnection(0, 10);
|
||||||
|
|
||||||
let last = this.database.connections_[9];
|
const last = this.database.connections_[9];
|
||||||
let closest = this.database.searchForClosest(
|
const closest = this.database.searchForClosest(
|
||||||
checkConnection, 5, {x: 0, y: 0}).connection;
|
checkConnection, 5, {x: 0, y: 0}).connection;
|
||||||
chai.assert.equal(last, closest);
|
chai.assert.equal(last, closest);
|
||||||
});
|
});
|
||||||
test('No Y-Coord Priority', function() {
|
test('No Y-Coord Priority', function() {
|
||||||
let connection1 = this.createConnection(6, 6, Blockly.PREVIOUS_STATEMENT);
|
const connection1 = this.createConnection(6, 6, Blockly.PREVIOUS_STATEMENT);
|
||||||
this.database.addConnection(connection1, 6);
|
this.database.addConnection(connection1, 6);
|
||||||
let connection2 = this.createConnection(5, 5, Blockly.PREVIOUS_STATEMENT);
|
const connection2 = this.createConnection(5, 5, Blockly.PREVIOUS_STATEMENT);
|
||||||
this.database.addConnection(connection2, 5);
|
this.database.addConnection(connection2, 5);
|
||||||
|
|
||||||
let checkConnection = this.createCheckConnection(4, 6);
|
const checkConnection = this.createCheckConnection(4, 6);
|
||||||
|
|
||||||
let closest = this.database.searchForClosest(
|
const closest = this.database.searchForClosest(
|
||||||
checkConnection, 3, {x: 0, y: 0}).connection;
|
checkConnection, 3, {x: 0, y: 0}).connection;
|
||||||
chai.assert.equal(connection2, closest);
|
chai.assert.equal(connection2, closest);
|
||||||
});
|
});
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -14,7 +14,7 @@ suite('Context Menu Items', function() {
|
|||||||
sharedTestSetup.call(this);
|
sharedTestSetup.call(this);
|
||||||
|
|
||||||
// Creates a WorkspaceSVG
|
// Creates a WorkspaceSVG
|
||||||
let toolbox = document.getElementById('toolbox-categories');
|
const toolbox = document.getElementById('toolbox-categories');
|
||||||
this.workspace = Blockly.inject('blocklyDiv', {toolbox: toolbox});
|
this.workspace = Blockly.inject('blocklyDiv', {toolbox: toolbox});
|
||||||
|
|
||||||
// Declare a new registry to ensure default options are called.
|
// Declare a new registry to ensure default options are called.
|
||||||
@@ -38,7 +38,7 @@ suite('Context Menu Items', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
test('Disabled when nothing to undo', function() {
|
test('Disabled when nothing to undo', function() {
|
||||||
let precondition = this.undoOption.preconditionFn(this.scope);
|
const precondition = this.undoOption.preconditionFn(this.scope);
|
||||||
chai.assert.equal(precondition, 'disabled',
|
chai.assert.equal(precondition, 'disabled',
|
||||||
'Should be disabled when there is nothing to undo');
|
'Should be disabled when there is nothing to undo');
|
||||||
});
|
});
|
||||||
@@ -46,7 +46,7 @@ suite('Context Menu Items', function() {
|
|||||||
test('Enabled when something to undo', function() {
|
test('Enabled when something to undo', function() {
|
||||||
// Create a new block, which should be undoable.
|
// Create a new block, which should be undoable.
|
||||||
this.workspace.newBlock('text');
|
this.workspace.newBlock('text');
|
||||||
let precondition = this.undoOption.preconditionFn(this.scope);
|
const precondition = this.undoOption.preconditionFn(this.scope);
|
||||||
chai.assert.equal(precondition, 'enabled',
|
chai.assert.equal(precondition, 'enabled',
|
||||||
'Should be enabled when there are actions to undo');
|
'Should be enabled when there are actions to undo');
|
||||||
});
|
});
|
||||||
@@ -72,7 +72,7 @@ suite('Context Menu Items', function() {
|
|||||||
test('Disabled when nothing to redo', function() {
|
test('Disabled when nothing to redo', function() {
|
||||||
// Create a new block. There should be something to undo, but not redo.
|
// Create a new block. There should be something to undo, but not redo.
|
||||||
this.workspace.newBlock('text');
|
this.workspace.newBlock('text');
|
||||||
let precondition = this.redoOption.preconditionFn(this.scope);
|
const precondition = this.redoOption.preconditionFn(this.scope);
|
||||||
chai.assert.equal(precondition, 'disabled',
|
chai.assert.equal(precondition, 'disabled',
|
||||||
'Should be disabled when there is nothing to redo');
|
'Should be disabled when there is nothing to redo');
|
||||||
});
|
});
|
||||||
@@ -81,7 +81,7 @@ suite('Context Menu Items', function() {
|
|||||||
// Create a new block, then undo it, which means there is something to redo.
|
// Create a new block, then undo it, which means there is something to redo.
|
||||||
this.workspace.newBlock('text');
|
this.workspace.newBlock('text');
|
||||||
this.workspace.undo(false);
|
this.workspace.undo(false);
|
||||||
let precondition = this.redoOption.preconditionFn(this.scope);
|
const precondition = this.redoOption.preconditionFn(this.scope);
|
||||||
chai.assert.equal(precondition, 'enabled',
|
chai.assert.equal(precondition, 'enabled',
|
||||||
'Should be enabled when there are actions to redo');
|
'Should be enabled when there are actions to redo');
|
||||||
});
|
});
|
||||||
@@ -142,7 +142,7 @@ suite('Context Menu Items', function() {
|
|||||||
|
|
||||||
test('Enabled when uncollapsed blocks', function() {
|
test('Enabled when uncollapsed blocks', function() {
|
||||||
this.workspace.newBlock('text');
|
this.workspace.newBlock('text');
|
||||||
let block2 = this.workspace.newBlock('text');
|
const block2 = this.workspace.newBlock('text');
|
||||||
block2.setCollapsed(true);
|
block2.setCollapsed(true);
|
||||||
chai.assert.equal(this.collapseOption.preconditionFn(this.scope), 'enabled',
|
chai.assert.equal(this.collapseOption.preconditionFn(this.scope), 'enabled',
|
||||||
'Should be enabled when any blocks are expanded');
|
'Should be enabled when any blocks are expanded');
|
||||||
@@ -155,7 +155,7 @@ suite('Context Menu Items', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
test('Hidden when no collapse option', function() {
|
test('Hidden when no collapse option', function() {
|
||||||
let workspaceWithOptions = new Blockly.Workspace(new Blockly.Options({collapse: false}));
|
const workspaceWithOptions = new Blockly.Workspace(new Blockly.Options({collapse: false}));
|
||||||
this.scope.workspace = workspaceWithOptions;
|
this.scope.workspace = workspaceWithOptions;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@@ -168,8 +168,8 @@ suite('Context Menu Items', function() {
|
|||||||
|
|
||||||
test('Collapses all blocks', function() {
|
test('Collapses all blocks', function() {
|
||||||
// All blocks should be collapsed, even if some already were.
|
// All blocks should be collapsed, even if some already were.
|
||||||
let block1 = this.workspace.newBlock('text');
|
const block1 = this.workspace.newBlock('text');
|
||||||
let block2 = this.workspace.newBlock('text');
|
const block2 = this.workspace.newBlock('text');
|
||||||
// Need to render block to properly collapse it.
|
// Need to render block to properly collapse it.
|
||||||
block1.initSvg();
|
block1.initSvg();
|
||||||
block1.render();
|
block1.render();
|
||||||
@@ -196,7 +196,7 @@ suite('Context Menu Items', function() {
|
|||||||
|
|
||||||
test('Enabled when collapsed blocks', function() {
|
test('Enabled when collapsed blocks', function() {
|
||||||
this.workspace.newBlock('text');
|
this.workspace.newBlock('text');
|
||||||
let block2 = this.workspace.newBlock('text');
|
const block2 = this.workspace.newBlock('text');
|
||||||
block2.setCollapsed(true);
|
block2.setCollapsed(true);
|
||||||
|
|
||||||
chai.assert.equal(this.expandOption.preconditionFn(this.scope), 'enabled',
|
chai.assert.equal(this.expandOption.preconditionFn(this.scope), 'enabled',
|
||||||
@@ -210,7 +210,7 @@ suite('Context Menu Items', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
test('Hidden when no collapse option', function() {
|
test('Hidden when no collapse option', function() {
|
||||||
let workspaceWithOptions = new Blockly.Workspace(new Blockly.Options({collapse: false}));
|
const workspaceWithOptions = new Blockly.Workspace(new Blockly.Options({collapse: false}));
|
||||||
this.scope.workspace = workspaceWithOptions;
|
this.scope.workspace = workspaceWithOptions;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@@ -223,8 +223,8 @@ suite('Context Menu Items', function() {
|
|||||||
|
|
||||||
test('Expands all blocks', function() {
|
test('Expands all blocks', function() {
|
||||||
// All blocks should be expanded, even if some already were.
|
// All blocks should be expanded, even if some already were.
|
||||||
let block1 = this.workspace.newBlock('text');
|
const block1 = this.workspace.newBlock('text');
|
||||||
let block2 = this.workspace.newBlock('text');
|
const block2 = this.workspace.newBlock('text');
|
||||||
// Need to render block to properly collapse it.
|
// Need to render block to properly collapse it.
|
||||||
block2.initSvg();
|
block2.initSvg();
|
||||||
block2.render();
|
block2.render();
|
||||||
@@ -260,7 +260,7 @@ suite('Context Menu Items', function() {
|
|||||||
|
|
||||||
test('Deletes all blocks after confirming', function() {
|
test('Deletes all blocks after confirming', function() {
|
||||||
// Mocks the confirmation dialog and calls the callback with 'true' simulating ok.
|
// Mocks the confirmation dialog and calls the callback with 'true' simulating ok.
|
||||||
let confirmStub = sinon.stub(
|
const confirmStub = sinon.stub(
|
||||||
Blockly.dialog, 'confirm').callsArgWith(1, true);
|
Blockly.dialog, 'confirm').callsArgWith(1, true);
|
||||||
|
|
||||||
this.workspace.newBlock('text');
|
this.workspace.newBlock('text');
|
||||||
@@ -273,7 +273,7 @@ suite('Context Menu Items', function() {
|
|||||||
|
|
||||||
test('Does not delete blocks if not confirmed', function() {
|
test('Does not delete blocks if not confirmed', function() {
|
||||||
// Mocks the confirmation dialog and calls the callback with 'false' simulating cancel.
|
// Mocks the confirmation dialog and calls the callback with 'false' simulating cancel.
|
||||||
let confirmStub = sinon.stub(
|
const confirmStub = sinon.stub(
|
||||||
Blockly.dialog, 'confirm').callsArgWith(1, false);
|
Blockly.dialog, 'confirm').callsArgWith(1, false);
|
||||||
|
|
||||||
this.workspace.newBlock('text');
|
this.workspace.newBlock('text');
|
||||||
@@ -285,7 +285,7 @@ suite('Context Menu Items', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
test('No dialog for single block', function() {
|
test('No dialog for single block', function() {
|
||||||
let confirmStub = sinon.stub(Blockly.dialog, 'confirm');
|
const confirmStub = sinon.stub(Blockly.dialog, 'confirm');
|
||||||
this.workspace.newBlock('text');
|
this.workspace.newBlock('text');
|
||||||
this.deleteOption.callback(this.scope);
|
this.deleteOption.callback(this.scope);
|
||||||
this.clock.runAll();
|
this.clock.runAll();
|
||||||
@@ -335,7 +335,7 @@ suite('Context Menu Items', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
test('Calls duplicate', function() {
|
test('Calls duplicate', function() {
|
||||||
let spy = sinon.spy(Blockly.clipboard, 'duplicate');
|
const spy = sinon.spy(Blockly.clipboard, 'duplicate');
|
||||||
|
|
||||||
this.duplicateOption.callback(this.scope);
|
this.duplicateOption.callback(this.scope);
|
||||||
|
|
||||||
@@ -358,7 +358,7 @@ suite('Context Menu Items', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
test('Hidden for IE', function() {
|
test('Hidden for IE', function() {
|
||||||
let oldState = Blockly.utils.userAgent.IE;
|
const oldState = Blockly.utils.userAgent.IE;
|
||||||
try {
|
try {
|
||||||
Blockly.utils.userAgent.IE = true;
|
Blockly.utils.userAgent.IE = true;
|
||||||
chai.assert.equal(this.commentOption.preconditionFn(this.scope), 'hidden');
|
chai.assert.equal(this.commentOption.preconditionFn(this.scope), 'hidden');
|
||||||
|
|||||||
@@ -60,11 +60,11 @@ suite('Cursor', function() {
|
|||||||
]);
|
]);
|
||||||
this.workspace = Blockly.inject('blocklyDiv', {});
|
this.workspace = Blockly.inject('blocklyDiv', {});
|
||||||
this.cursor = this.workspace.getCursor();
|
this.cursor = this.workspace.getCursor();
|
||||||
let blockA = this.workspace.newBlock('input_statement');
|
const blockA = this.workspace.newBlock('input_statement');
|
||||||
let blockB = this.workspace.newBlock('input_statement');
|
const blockB = this.workspace.newBlock('input_statement');
|
||||||
let blockC = this.workspace.newBlock('input_statement');
|
const blockC = this.workspace.newBlock('input_statement');
|
||||||
let blockD = this.workspace.newBlock('input_statement');
|
const blockD = this.workspace.newBlock('input_statement');
|
||||||
let blockE = this.workspace.newBlock('field_input');
|
const blockE = this.workspace.newBlock('field_input');
|
||||||
|
|
||||||
blockA.nextConnection.connect(blockB.previousConnection);
|
blockA.nextConnection.connect(blockB.previousConnection);
|
||||||
blockA.inputList[0].connection.connect(blockE.outputConnection);
|
blockA.inputList[0].connection.connect(blockE.outputConnection);
|
||||||
@@ -83,44 +83,44 @@ suite('Cursor', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
test('Next - From a Previous skip over next connection and block', function() {
|
test('Next - From a Previous skip over next connection and block', function() {
|
||||||
let prevNode = ASTNode.createConnectionNode(this.blocks.A.previousConnection);
|
const prevNode = ASTNode.createConnectionNode(this.blocks.A.previousConnection);
|
||||||
this.cursor.setCurNode(prevNode);
|
this.cursor.setCurNode(prevNode);
|
||||||
this.cursor.next();
|
this.cursor.next();
|
||||||
let curNode = this.cursor.getCurNode();
|
const curNode = this.cursor.getCurNode();
|
||||||
chai.assert.equal(curNode.getLocation(), this.blocks.B.previousConnection);
|
chai.assert.equal(curNode.getLocation(), this.blocks.B.previousConnection);
|
||||||
});
|
});
|
||||||
test('Next - From last block in a stack go to next connection', function() {
|
test('Next - From last block in a stack go to next connection', function() {
|
||||||
let prevNode = ASTNode.createConnectionNode(this.blocks.B.previousConnection);
|
const prevNode = ASTNode.createConnectionNode(this.blocks.B.previousConnection);
|
||||||
this.cursor.setCurNode(prevNode);
|
this.cursor.setCurNode(prevNode);
|
||||||
this.cursor.next();
|
this.cursor.next();
|
||||||
let curNode = this.cursor.getCurNode();
|
const curNode = this.cursor.getCurNode();
|
||||||
chai.assert.equal(curNode.getLocation(), this.blocks.B.nextConnection);
|
chai.assert.equal(curNode.getLocation(), this.blocks.B.nextConnection);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('In - From output connection', function() {
|
test('In - From output connection', function() {
|
||||||
let fieldBlock = this.blocks.E;
|
const fieldBlock = this.blocks.E;
|
||||||
let outputNode = ASTNode.createConnectionNode(fieldBlock.outputConnection);
|
const outputNode = ASTNode.createConnectionNode(fieldBlock.outputConnection);
|
||||||
this.cursor.setCurNode(outputNode);
|
this.cursor.setCurNode(outputNode);
|
||||||
this.cursor.in();
|
this.cursor.in();
|
||||||
let curNode = this.cursor.getCurNode();
|
const curNode = this.cursor.getCurNode();
|
||||||
chai.assert.equal(curNode.getLocation(), fieldBlock.inputList[0].fieldRow[0]);
|
chai.assert.equal(curNode.getLocation(), fieldBlock.inputList[0].fieldRow[0]);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('Prev - From previous connection skip over next connection', function() {
|
test('Prev - From previous connection skip over next connection', function() {
|
||||||
let prevConnection = this.blocks.B.previousConnection;
|
const prevConnection = this.blocks.B.previousConnection;
|
||||||
let prevConnectionNode = ASTNode.createConnectionNode(prevConnection);
|
const prevConnectionNode = ASTNode.createConnectionNode(prevConnection);
|
||||||
this.cursor.setCurNode(prevConnectionNode);
|
this.cursor.setCurNode(prevConnectionNode);
|
||||||
this.cursor.prev();
|
this.cursor.prev();
|
||||||
let curNode = this.cursor.getCurNode();
|
const curNode = this.cursor.getCurNode();
|
||||||
chai.assert.equal(curNode.getLocation(), this.blocks.A.previousConnection);
|
chai.assert.equal(curNode.getLocation(), this.blocks.A.previousConnection);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('Out - From field skip over block node', function() {
|
test('Out - From field skip over block node', function() {
|
||||||
let field = this.blocks.E.inputList[0].fieldRow[0];
|
const field = this.blocks.E.inputList[0].fieldRow[0];
|
||||||
let fieldNode = ASTNode.createFieldNode(field);
|
const fieldNode = ASTNode.createFieldNode(field);
|
||||||
this.cursor.setCurNode(fieldNode);
|
this.cursor.setCurNode(fieldNode);
|
||||||
this.cursor.out();
|
this.cursor.out();
|
||||||
let curNode = this.cursor.getCurNode();
|
const curNode = this.cursor.getCurNode();
|
||||||
chai.assert.equal(curNode.getLocation(), this.blocks.E.outputConnection);
|
chai.assert.equal(curNode.getLocation(), this.blocks.E.outputConnection);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -36,7 +36,7 @@ suite('DropDownDiv', function() {
|
|||||||
sharedTestTeardown.call(this);
|
sharedTestTeardown.call(this);
|
||||||
});
|
});
|
||||||
test('Below, in Bounds', function() {
|
test('Below, in Bounds', function() {
|
||||||
let metrics = Blockly.DropDownDiv.TEST_ONLY.getPositionMetrics(50, 0, 50, -10);
|
const metrics = Blockly.DropDownDiv.TEST_ONLY.getPositionMetrics(50, 0, 50, -10);
|
||||||
// "Above" in value actually means below in render.
|
// "Above" in value actually means below in render.
|
||||||
chai.assert.isAtLeast(metrics.initialY, 0);
|
chai.assert.isAtLeast(metrics.initialY, 0);
|
||||||
chai.assert.isAbove(metrics.finalY, 0);
|
chai.assert.isAbove(metrics.finalY, 0);
|
||||||
@@ -44,7 +44,7 @@ suite('DropDownDiv', function() {
|
|||||||
chai.assert.isTrue(metrics.arrowAtTop);
|
chai.assert.isTrue(metrics.arrowAtTop);
|
||||||
});
|
});
|
||||||
test('Above, in Bounds', function() {
|
test('Above, in Bounds', function() {
|
||||||
let metrics = Blockly.DropDownDiv.TEST_ONLY.getPositionMetrics(50, 100, 50, 90);
|
const metrics = Blockly.DropDownDiv.TEST_ONLY.getPositionMetrics(50, 100, 50, 90);
|
||||||
// "Below" in value actually means above in render.
|
// "Below" in value actually means above in render.
|
||||||
chai.assert.isAtMost(metrics.initialY, 100);
|
chai.assert.isAtMost(metrics.initialY, 100);
|
||||||
chai.assert.isBelow(metrics.finalY, 100);
|
chai.assert.isBelow(metrics.finalY, 100);
|
||||||
@@ -52,7 +52,7 @@ suite('DropDownDiv', function() {
|
|||||||
chai.assert.isFalse(metrics.arrowAtTop);
|
chai.assert.isFalse(metrics.arrowAtTop);
|
||||||
});
|
});
|
||||||
test('Below, out of Bounds', function() {
|
test('Below, out of Bounds', function() {
|
||||||
let metrics = Blockly.DropDownDiv.TEST_ONLY.getPositionMetrics(50, 60, 50, 50);
|
const metrics = Blockly.DropDownDiv.TEST_ONLY.getPositionMetrics(50, 60, 50, 50);
|
||||||
// "Above" in value actually means below in render.
|
// "Above" in value actually means below in render.
|
||||||
chai.assert.isAtLeast(metrics.initialY, 60);
|
chai.assert.isAtLeast(metrics.initialY, 60);
|
||||||
chai.assert.isAbove(metrics.finalY, 60);
|
chai.assert.isAbove(metrics.finalY, 60);
|
||||||
@@ -60,7 +60,7 @@ suite('DropDownDiv', function() {
|
|||||||
chai.assert.isTrue(metrics.arrowAtTop);
|
chai.assert.isTrue(metrics.arrowAtTop);
|
||||||
});
|
});
|
||||||
test('Above, in Bounds', function() {
|
test('Above, in Bounds', function() {
|
||||||
let metrics = Blockly.DropDownDiv.TEST_ONLY.getPositionMetrics(50, 100, 50, 90);
|
const metrics = Blockly.DropDownDiv.TEST_ONLY.getPositionMetrics(50, 100, 50, 90);
|
||||||
// "Below" in value actually means above in render.
|
// "Below" in value actually means above in render.
|
||||||
chai.assert.isAtMost(metrics.initialY, 100);
|
chai.assert.isAtMost(metrics.initialY, 100);
|
||||||
chai.assert.isBelow(metrics.finalY, 100);
|
chai.assert.isBelow(metrics.finalY, 100);
|
||||||
@@ -69,7 +69,7 @@ suite('DropDownDiv', function() {
|
|||||||
});
|
});
|
||||||
test('No Solution, Render At Top', function() {
|
test('No Solution, Render At Top', function() {
|
||||||
this.clientHeightStub.get(function() { return 100; });
|
this.clientHeightStub.get(function() { return 100; });
|
||||||
let metrics = Blockly.DropDownDiv.TEST_ONLY.getPositionMetrics(50, 60, 50, 50);
|
const metrics = Blockly.DropDownDiv.TEST_ONLY.getPositionMetrics(50, 60, 50, 50);
|
||||||
// "Above" in value actually means below in render.
|
// "Above" in value actually means below in render.
|
||||||
chai.assert.equal(metrics.initialY, 0);
|
chai.assert.equal(metrics.initialY, 0);
|
||||||
chai.assert.equal(metrics.finalY, 0);
|
chai.assert.equal(metrics.finalY, 0);
|
||||||
|
|||||||
@@ -57,7 +57,7 @@ suite('Events', function() {
|
|||||||
|
|
||||||
suite('Constructors', function() {
|
suite('Constructors', function() {
|
||||||
test('Abstract', function() {
|
test('Abstract', function() {
|
||||||
let event = new Blockly.Events.Abstract();
|
const event = new Blockly.Events.Abstract();
|
||||||
assertEventEquals(event, undefined, undefined, undefined, {
|
assertEventEquals(event, undefined, undefined, undefined, {
|
||||||
'recordUndo': true,
|
'recordUndo': true,
|
||||||
'group': ''
|
'group': ''
|
||||||
@@ -65,7 +65,7 @@ suite('Events', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
test('UI event without block', function() {
|
test('UI event without block', function() {
|
||||||
let event = new Blockly.Events.UiBase(this.workspace.id);
|
const event = new Blockly.Events.UiBase(this.workspace.id);
|
||||||
assertEventEquals(event, undefined, this.workspace.id, undefined, {
|
assertEventEquals(event, undefined, this.workspace.id, undefined, {
|
||||||
'recordUndo': false,
|
'recordUndo': false,
|
||||||
'group': '',
|
'group': '',
|
||||||
@@ -73,7 +73,7 @@ suite('Events', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
test('Click without block', function() {
|
test('Click without block', function() {
|
||||||
let event = new Blockly.Events.Click(null, this.workspace.id, 'workspace');
|
const event = new Blockly.Events.Click(null, this.workspace.id, 'workspace');
|
||||||
assertEventEquals(event, Blockly.Events.CLICK, this.workspace.id, null, {
|
assertEventEquals(event, Blockly.Events.CLICK, this.workspace.id, null, {
|
||||||
'targetType': 'workspace',
|
'targetType': 'workspace',
|
||||||
'recordUndo': false,
|
'recordUndo': false,
|
||||||
@@ -82,9 +82,9 @@ suite('Events', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
test('Old UI event without block', function() {
|
test('Old UI event without block', function() {
|
||||||
let TEST_GROUP_ID = 'testGroup';
|
const TEST_GROUP_ID = 'testGroup';
|
||||||
eventUtils.setGroup(TEST_GROUP_ID);
|
eventUtils.setGroup(TEST_GROUP_ID);
|
||||||
let event = new Blockly.Events.Ui(null, 'foo', 'bar', 'baz');
|
const event = new Blockly.Events.Ui(null, 'foo', 'bar', 'baz');
|
||||||
assertEventEquals(event, Blockly.Events.UI, '', null, {
|
assertEventEquals(event, Blockly.Events.UI, '', null, {
|
||||||
'element': 'foo',
|
'element': 'foo',
|
||||||
'oldValue': 'bar',
|
'oldValue': 'bar',
|
||||||
@@ -105,7 +105,7 @@ suite('Events', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
test('Block base', function() {
|
test('Block base', function() {
|
||||||
let event = new Blockly.Events.BlockBase(this.block);
|
const event = new Blockly.Events.BlockBase(this.block);
|
||||||
sinon.assert.calledOnce(this.genUidStub);
|
sinon.assert.calledOnce(this.genUidStub);
|
||||||
assertEventEquals(event, undefined,
|
assertEventEquals(event, undefined,
|
||||||
this.workspace.id, this.TEST_BLOCK_ID,
|
this.workspace.id, this.TEST_BLOCK_ID,
|
||||||
@@ -117,7 +117,7 @@ suite('Events', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
test('Block create', function() {
|
test('Block create', function() {
|
||||||
let event = new Blockly.Events.BlockCreate(this.block);
|
const event = new Blockly.Events.BlockCreate(this.block);
|
||||||
sinon.assert.calledOnce(this.genUidStub);
|
sinon.assert.calledOnce(this.genUidStub);
|
||||||
assertEventEquals(event, Blockly.Events.BLOCK_CREATE,
|
assertEventEquals(event, Blockly.Events.BLOCK_CREATE,
|
||||||
this.workspace.id, this.TEST_BLOCK_ID,
|
this.workspace.id, this.TEST_BLOCK_ID,
|
||||||
@@ -128,7 +128,7 @@ suite('Events', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
test('Block delete', function() {
|
test('Block delete', function() {
|
||||||
let event = new Blockly.Events.BlockDelete(this.block);
|
const event = new Blockly.Events.BlockDelete(this.block);
|
||||||
sinon.assert.calledOnce(this.genUidStub);
|
sinon.assert.calledOnce(this.genUidStub);
|
||||||
assertEventEquals(event, Blockly.Events.BLOCK_DELETE,
|
assertEventEquals(event, Blockly.Events.BLOCK_DELETE,
|
||||||
this.workspace.id, this.TEST_BLOCK_ID,
|
this.workspace.id, this.TEST_BLOCK_ID,
|
||||||
@@ -139,9 +139,9 @@ suite('Events', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
test('Old UI event with block', function() {
|
test('Old UI event with block', function() {
|
||||||
let TEST_GROUP_ID = 'testGroup';
|
const TEST_GROUP_ID = 'testGroup';
|
||||||
eventUtils.setGroup(TEST_GROUP_ID);
|
eventUtils.setGroup(TEST_GROUP_ID);
|
||||||
let event = new Blockly.Events.Ui(this.block, 'foo', 'bar', 'baz');
|
const event = new Blockly.Events.Ui(this.block, 'foo', 'bar', 'baz');
|
||||||
sinon.assert.calledOnce(this.genUidStub);
|
sinon.assert.calledOnce(this.genUidStub);
|
||||||
assertEventEquals(event, Blockly.Events.UI, this.workspace.id,
|
assertEventEquals(event, Blockly.Events.UI, this.workspace.id,
|
||||||
this.TEST_BLOCK_ID,
|
this.TEST_BLOCK_ID,
|
||||||
@@ -155,9 +155,9 @@ suite('Events', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
test('Click with block', function() {
|
test('Click with block', function() {
|
||||||
let TEST_GROUP_ID = 'testGroup';
|
const TEST_GROUP_ID = 'testGroup';
|
||||||
eventUtils.setGroup(TEST_GROUP_ID);
|
eventUtils.setGroup(TEST_GROUP_ID);
|
||||||
let event = new Blockly.Events.Click(this.block, null, 'block');
|
const event = new Blockly.Events.Click(this.block, null, 'block');
|
||||||
assertEventEquals(event, Blockly.Events.CLICK, this.workspace.id,
|
assertEventEquals(event, Blockly.Events.CLICK, this.workspace.id,
|
||||||
this.TEST_BLOCK_ID, {
|
this.TEST_BLOCK_ID, {
|
||||||
'targetType': 'block',
|
'targetType': 'block',
|
||||||
@@ -168,10 +168,10 @@ suite('Events', function() {
|
|||||||
|
|
||||||
suite('Block Move', function() {
|
suite('Block Move', function() {
|
||||||
test('by coordinate', function() {
|
test('by coordinate', function() {
|
||||||
let coordinate = new Blockly.utils.Coordinate(3, 4);
|
const coordinate = new Blockly.utils.Coordinate(3, 4);
|
||||||
this.block.xy_ = coordinate;
|
this.block.xy_ = coordinate;
|
||||||
|
|
||||||
let event = new Blockly.Events.BlockMove(this.block);
|
const event = new Blockly.Events.BlockMove(this.block);
|
||||||
sinon.assert.calledOnce(this.genUidStub);
|
sinon.assert.calledOnce(this.genUidStub);
|
||||||
assertEventEquals(event, Blockly.Events.BLOCK_MOVE, this.workspace.id,
|
assertEventEquals(event, Blockly.Events.BLOCK_MOVE, this.workspace.id,
|
||||||
this.TEST_BLOCK_ID, {
|
this.TEST_BLOCK_ID, {
|
||||||
@@ -188,7 +188,7 @@ suite('Events', function() {
|
|||||||
this.parentBlock = createSimpleTestBlock(this.workspace);
|
this.parentBlock = createSimpleTestBlock(this.workspace);
|
||||||
this.block.parentBlock_ = this.parentBlock;
|
this.block.parentBlock_ = this.parentBlock;
|
||||||
this.block.xy_ = new Blockly.utils.Coordinate(3, 4);
|
this.block.xy_ = new Blockly.utils.Coordinate(3, 4);
|
||||||
let event = new Blockly.Events.BlockMove(this.block);
|
const event = new Blockly.Events.BlockMove(this.block);
|
||||||
sinon.assert.calledTwice(this.genUidStub);
|
sinon.assert.calledTwice(this.genUidStub);
|
||||||
assertEventEquals(event, Blockly.Events.BLOCK_MOVE, this.workspace.id,
|
assertEventEquals(event, Blockly.Events.BLOCK_MOVE, this.workspace.id,
|
||||||
this.TEST_BLOCK_ID, {
|
this.TEST_BLOCK_ID, {
|
||||||
@@ -218,7 +218,7 @@ suite('Events', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
test('Block base', function() {
|
test('Block base', function() {
|
||||||
let event = new Blockly.Events.BlockBase(this.block);
|
const event = new Blockly.Events.BlockBase(this.block);
|
||||||
sinon.assert.calledOnce(this.genUidStub);
|
sinon.assert.calledOnce(this.genUidStub);
|
||||||
assertEventEquals(event, undefined,
|
assertEventEquals(event, undefined,
|
||||||
this.workspace.id, this.TEST_BLOCK_ID,
|
this.workspace.id, this.TEST_BLOCK_ID,
|
||||||
@@ -230,7 +230,7 @@ suite('Events', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
test('Block change', function() {
|
test('Block change', function() {
|
||||||
let event = new Blockly.Events.BlockChange(
|
const event = new Blockly.Events.BlockChange(
|
||||||
this.block, 'field', 'FIELD_NAME', 'old', 'new');
|
this.block, 'field', 'FIELD_NAME', 'old', 'new');
|
||||||
sinon.assert.calledOnce(this.genUidStub);
|
sinon.assert.calledOnce(this.genUidStub);
|
||||||
assertEventEquals(event, Blockly.Events.BLOCK_CHANGE,
|
assertEventEquals(event, Blockly.Events.BLOCK_CHANGE,
|
||||||
@@ -247,7 +247,7 @@ suite('Events', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
test('Block create', function() {
|
test('Block create', function() {
|
||||||
let event = new Blockly.Events.BlockCreate(this.block);
|
const event = new Blockly.Events.BlockCreate(this.block);
|
||||||
sinon.assert.calledOnce(this.genUidStub);
|
sinon.assert.calledOnce(this.genUidStub);
|
||||||
assertEventEquals(event, Blockly.Events.BLOCK_CREATE,
|
assertEventEquals(event, Blockly.Events.BLOCK_CREATE,
|
||||||
this.workspace.id, this.TEST_BLOCK_ID,
|
this.workspace.id, this.TEST_BLOCK_ID,
|
||||||
@@ -258,7 +258,7 @@ suite('Events', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
test('Block delete', function() {
|
test('Block delete', function() {
|
||||||
let event = new Blockly.Events.BlockDelete(this.block);
|
const event = new Blockly.Events.BlockDelete(this.block);
|
||||||
sinon.assert.calledOnce(this.genUidStub);
|
sinon.assert.calledOnce(this.genUidStub);
|
||||||
assertEventEquals(event, Blockly.Events.BLOCK_DELETE,
|
assertEventEquals(event, Blockly.Events.BLOCK_DELETE,
|
||||||
this.workspace.id, this.TEST_BLOCK_ID,
|
this.workspace.id, this.TEST_BLOCK_ID,
|
||||||
@@ -273,7 +273,7 @@ suite('Events', function() {
|
|||||||
this.parentBlock = createSimpleTestBlock(this.workspace);
|
this.parentBlock = createSimpleTestBlock(this.workspace);
|
||||||
this.block.parentBlock_ = this.parentBlock;
|
this.block.parentBlock_ = this.parentBlock;
|
||||||
this.block.xy_ = new Blockly.utils.Coordinate(3, 4);
|
this.block.xy_ = new Blockly.utils.Coordinate(3, 4);
|
||||||
let event = new Blockly.Events.BlockMove(this.block);
|
const event = new Blockly.Events.BlockMove(this.block);
|
||||||
sinon.assert.calledTwice(this.genUidStub);
|
sinon.assert.calledTwice(this.genUidStub);
|
||||||
assertEventEquals(event, Blockly.Events.BLOCK_MOVE, this.workspace.id,
|
assertEventEquals(event, Blockly.Events.BLOCK_MOVE, this.workspace.id,
|
||||||
this.TEST_BLOCK_ID,
|
this.TEST_BLOCK_ID,
|
||||||
@@ -302,7 +302,7 @@ suite('Events', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
test('Block change', function() {
|
test('Block change', function() {
|
||||||
let event = new Blockly.Events.BlockChange(
|
const event = new Blockly.Events.BlockChange(
|
||||||
this.block, 'field', 'VAR', 'id1', 'id2');
|
this.block, 'field', 'VAR', 'id1', 'id2');
|
||||||
assertEventEquals(event, Blockly.Events.BLOCK_CHANGE, this.workspace.id,
|
assertEventEquals(event, Blockly.Events.BLOCK_CHANGE, this.workspace.id,
|
||||||
this.TEST_BLOCK_ID,
|
this.TEST_BLOCK_ID,
|
||||||
@@ -319,8 +319,8 @@ suite('Events', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
suite('Serialization', function() {
|
suite('Serialization', function() {
|
||||||
let safeStringify = (json) => {
|
const safeStringify = (json) => {
|
||||||
let cache = [];
|
const cache = [];
|
||||||
return JSON.stringify(json, (key, value) => {
|
return JSON.stringify(json, (key, value) => {
|
||||||
if (typeof value == 'object' && value != null) {
|
if (typeof value == 'object' && value != null) {
|
||||||
if (cache.includes(value)) {
|
if (cache.includes(value)) {
|
||||||
@@ -333,7 +333,7 @@ suite('Events', function() {
|
|||||||
return value;
|
return value;
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
let variableEventTestCases = [
|
const variableEventTestCases = [
|
||||||
{title: 'Var create', class: Blockly.Events.VarCreate,
|
{title: 'Var create', class: Blockly.Events.VarCreate,
|
||||||
getArgs: (thisObj) => [thisObj.variable],
|
getArgs: (thisObj) => [thisObj.variable],
|
||||||
getExpectedJson: () => ({type: 'var_create', varId: 'id1',
|
getExpectedJson: () => ({type: 'var_create', varId: 'id1',
|
||||||
@@ -347,7 +347,7 @@ suite('Events', function() {
|
|||||||
getExpectedJson: () => ({type: 'var_rename', varId: 'id1',
|
getExpectedJson: () => ({type: 'var_rename', varId: 'id1',
|
||||||
oldName: 'name1', newName: 'name2'})},
|
oldName: 'name1', newName: 'name2'})},
|
||||||
];
|
];
|
||||||
let uiEventTestCases = [
|
const uiEventTestCases = [
|
||||||
{title: 'Bubble open', class: Blockly.Events.BubbleOpen,
|
{title: 'Bubble open', class: Blockly.Events.BubbleOpen,
|
||||||
getArgs: (thisObj) => [thisObj.block, true, 'mutator'],
|
getArgs: (thisObj) => [thisObj.block, true, 'mutator'],
|
||||||
getExpectedJson: (thisObj) => ({type: 'bubble_open', isOpen: true,
|
getExpectedJson: (thisObj) => ({type: 'bubble_open', isOpen: true,
|
||||||
@@ -439,7 +439,7 @@ suite('Events', function() {
|
|||||||
getExpectedJson: () => ({type: 'viewport_change', viewTop: 0,
|
getExpectedJson: () => ({type: 'viewport_change', viewTop: 0,
|
||||||
viewLeft: 0, scale: 1.2, oldScale: 1})},
|
viewLeft: 0, scale: 1.2, oldScale: 1})},
|
||||||
];
|
];
|
||||||
let blockEventTestCases = [
|
const blockEventTestCases = [
|
||||||
{
|
{
|
||||||
title: 'Block change',
|
title: 'Block change',
|
||||||
class: Blockly.Events.BlockChange,
|
class: Blockly.Events.BlockChange,
|
||||||
@@ -553,13 +553,13 @@ suite('Events', function() {
|
|||||||
})
|
})
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
let workspaceEventTestCases = [
|
const workspaceEventTestCases = [
|
||||||
{title: 'Finished Loading', class: Blockly.Events.FinishedLoading,
|
{title: 'Finished Loading', class: Blockly.Events.FinishedLoading,
|
||||||
getArgs: (thisObj) => [thisObj.workspace],
|
getArgs: (thisObj) => [thisObj.workspace],
|
||||||
getExpectedJson: (thisObj) => ({type: 'finished_loading',
|
getExpectedJson: (thisObj) => ({type: 'finished_loading',
|
||||||
workspaceId: thisObj.workspace.id})},
|
workspaceId: thisObj.workspace.id})},
|
||||||
];
|
];
|
||||||
let workspaceCommentEventTestCases = [
|
const workspaceCommentEventTestCases = [
|
||||||
{title: 'Comment change', class: Blockly.Events.CommentChange,
|
{title: 'Comment change', class: Blockly.Events.CommentChange,
|
||||||
getArgs: (thisObj) => [thisObj.comment, 'bar', 'foo'],
|
getArgs: (thisObj) => [thisObj.comment, 'bar', 'foo'],
|
||||||
getExpectedJson: (thisObj) => ({type: 'comment_change',
|
getExpectedJson: (thisObj) => ({type: 'comment_change',
|
||||||
@@ -580,7 +580,7 @@ suite('Events', function() {
|
|||||||
getExpectedJson: (thisObj) => ({type: 'comment_move',
|
getExpectedJson: (thisObj) => ({type: 'comment_move',
|
||||||
commentId: thisObj.comment.id, oldCoordinate: '0,0'})},
|
commentId: thisObj.comment.id, oldCoordinate: '0,0'})},
|
||||||
];
|
];
|
||||||
let testSuites = [
|
const testSuites = [
|
||||||
{title: 'Variable events', testCases: variableEventTestCases,
|
{title: 'Variable events', testCases: variableEventTestCases,
|
||||||
setup: (thisObj) => {
|
setup: (thisObj) => {
|
||||||
thisObj.variable =
|
thisObj.variable =
|
||||||
@@ -615,9 +615,9 @@ suite('Events', function() {
|
|||||||
suite('fromJson', function() {
|
suite('fromJson', function() {
|
||||||
testSuite.testCases.forEach((testCase) => {
|
testSuite.testCases.forEach((testCase) => {
|
||||||
test(testCase.title, function() {
|
test(testCase.title, function() {
|
||||||
let event = new testCase.class(...testCase.getArgs(this));
|
const event = new testCase.class(...testCase.getArgs(this));
|
||||||
let event2 = new testCase.class();
|
const event2 = new testCase.class();
|
||||||
let json = event.toJson();
|
const json = event.toJson();
|
||||||
event2.fromJson(json);
|
event2.fromJson(json);
|
||||||
|
|
||||||
chai.assert.equal(
|
chai.assert.equal(
|
||||||
@@ -629,9 +629,9 @@ suite('Events', function() {
|
|||||||
testSuite.testCases.forEach((testCase) => {
|
testSuite.testCases.forEach((testCase) => {
|
||||||
if (testCase.getExpectedJson) {
|
if (testCase.getExpectedJson) {
|
||||||
test(testCase.title, function() {
|
test(testCase.title, function() {
|
||||||
let event = new testCase.class(...testCase.getArgs(this));
|
const event = new testCase.class(...testCase.getArgs(this));
|
||||||
let json = event.toJson();
|
const json = event.toJson();
|
||||||
let expectedJson = testCase.getExpectedJson(this);
|
const expectedJson = testCase.getExpectedJson(this);
|
||||||
|
|
||||||
chai.assert.equal(
|
chai.assert.equal(
|
||||||
safeStringify(json), safeStringify(expectedJson));
|
safeStringify(json), safeStringify(expectedJson));
|
||||||
@@ -657,7 +657,7 @@ suite('Events', function() {
|
|||||||
* @param {!string} id The expected id of the variable.
|
* @param {!string} id The expected id of the variable.
|
||||||
*/
|
*/
|
||||||
function checkVariableValues(container, name, type, id) {
|
function checkVariableValues(container, name, type, id) {
|
||||||
let variable = container.getVariableById(id);
|
const variable = container.getVariableById(id);
|
||||||
chai.assert.isDefined(variable);
|
chai.assert.isDefined(variable);
|
||||||
chai.assert.equal(name, variable.name);
|
chai.assert.equal(name, variable.name);
|
||||||
chai.assert.equal(type, variable.type);
|
chai.assert.equal(type, variable.type);
|
||||||
@@ -666,7 +666,7 @@ suite('Events', function() {
|
|||||||
|
|
||||||
suite('Constructors', function() {
|
suite('Constructors', function() {
|
||||||
test('Var base', function() {
|
test('Var base', function() {
|
||||||
let event = new Blockly.Events.VarBase(this.variable);
|
const event = new Blockly.Events.VarBase(this.variable);
|
||||||
assertEventEquals(event, undefined, this.workspace.id, undefined, {
|
assertEventEquals(event, undefined, this.workspace.id, undefined, {
|
||||||
'varId': 'id1',
|
'varId': 'id1',
|
||||||
'recordUndo': true,
|
'recordUndo': true,
|
||||||
@@ -675,7 +675,7 @@ suite('Events', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
test('Var create', function() {
|
test('Var create', function() {
|
||||||
let event = new Blockly.Events.VarCreate(this.variable);
|
const event = new Blockly.Events.VarCreate(this.variable);
|
||||||
assertEventEquals(event, Blockly.Events.VAR_CREATE, this.workspace.id,
|
assertEventEquals(event, Blockly.Events.VAR_CREATE, this.workspace.id,
|
||||||
undefined,
|
undefined,
|
||||||
{
|
{
|
||||||
@@ -688,7 +688,7 @@ suite('Events', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
test('Var delete', function() {
|
test('Var delete', function() {
|
||||||
let event = new Blockly.Events.VarDelete(this.variable);
|
const event = new Blockly.Events.VarDelete(this.variable);
|
||||||
assertEventEquals(event, Blockly.Events.VAR_DELETE, this.workspace.id,
|
assertEventEquals(event, Blockly.Events.VAR_DELETE, this.workspace.id,
|
||||||
undefined,
|
undefined,
|
||||||
{
|
{
|
||||||
@@ -701,7 +701,7 @@ suite('Events', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
test('Var rename', function() {
|
test('Var rename', function() {
|
||||||
let event = new Blockly.Events.VarRename(this.variable, 'name2');
|
const event = new Blockly.Events.VarRename(this.variable, 'name2');
|
||||||
assertEventEquals(event, Blockly.Events.VAR_RENAME, this.workspace.id,
|
assertEventEquals(event, Blockly.Events.VAR_RENAME, this.workspace.id,
|
||||||
undefined,
|
undefined,
|
||||||
{
|
{
|
||||||
@@ -716,24 +716,24 @@ suite('Events', function() {
|
|||||||
|
|
||||||
suite('Run Forward', function() {
|
suite('Run Forward', function() {
|
||||||
test('Var create', function() {
|
test('Var create', function() {
|
||||||
let json = {type: "var_create", varId: "id2", varType: "type2",
|
const json = {type: "var_create", varId: "id2", varType: "type2",
|
||||||
varName: "name2"};
|
varName: "name2"};
|
||||||
let event = eventUtils.fromJson(json, this.workspace);
|
const event = eventUtils.fromJson(json, this.workspace);
|
||||||
let x = this.workspace.getVariableById('id2');
|
const x = this.workspace.getVariableById('id2');
|
||||||
chai.assert.isNull(x);
|
chai.assert.isNull(x);
|
||||||
event.run(true);
|
event.run(true);
|
||||||
assertVariableValues(this.workspace, 'name2', 'type2', 'id2');
|
assertVariableValues(this.workspace, 'name2', 'type2', 'id2');
|
||||||
});
|
});
|
||||||
|
|
||||||
test('Var delete', function() {
|
test('Var delete', function() {
|
||||||
let event = new Blockly.Events.VarDelete(this.variable);
|
const event = new Blockly.Events.VarDelete(this.variable);
|
||||||
chai.assert.isNotNull(this.workspace.getVariableById('id1'));
|
chai.assert.isNotNull(this.workspace.getVariableById('id1'));
|
||||||
event.run(true);
|
event.run(true);
|
||||||
chai.assert.isNull(this.workspace.getVariableById('id1'));
|
chai.assert.isNull(this.workspace.getVariableById('id1'));
|
||||||
});
|
});
|
||||||
|
|
||||||
test('Var rename', function() {
|
test('Var rename', function() {
|
||||||
let event = new Blockly.Events.VarRename(this.variable, 'name2');
|
const event = new Blockly.Events.VarRename(this.variable, 'name2');
|
||||||
event.run(true);
|
event.run(true);
|
||||||
chai.assert.isNull(this.workspace.getVariable('name1'));
|
chai.assert.isNull(this.workspace.getVariable('name1'));
|
||||||
checkVariableValues(this.workspace, 'name2', 'type1', 'id1');
|
checkVariableValues(this.workspace, 'name2', 'type1', 'id1');
|
||||||
@@ -741,22 +741,22 @@ suite('Events', function() {
|
|||||||
});
|
});
|
||||||
suite('Run Backward', function() {
|
suite('Run Backward', function() {
|
||||||
test('Var create', function() {
|
test('Var create', function() {
|
||||||
let event = new Blockly.Events.VarCreate(this.variable);
|
const event = new Blockly.Events.VarCreate(this.variable);
|
||||||
chai.assert.isNotNull(this.workspace.getVariableById('id1'));
|
chai.assert.isNotNull(this.workspace.getVariableById('id1'));
|
||||||
event.run(false);
|
event.run(false);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('Var delete', function() {
|
test('Var delete', function() {
|
||||||
let json = {type: "var_delete", varId: "id2", varType: "type2",
|
const json = {type: "var_delete", varId: "id2", varType: "type2",
|
||||||
varName: "name2"};
|
varName: "name2"};
|
||||||
let event = eventUtils.fromJson(json, this.workspace);
|
const event = eventUtils.fromJson(json, this.workspace);
|
||||||
chai.assert.isNull(this.workspace.getVariableById('id2'));
|
chai.assert.isNull(this.workspace.getVariableById('id2'));
|
||||||
event.run(false);
|
event.run(false);
|
||||||
assertVariableValues(this.workspace, 'name2', 'type2', 'id2');
|
assertVariableValues(this.workspace, 'name2', 'type2', 'id2');
|
||||||
});
|
});
|
||||||
|
|
||||||
test('Var rename', function() {
|
test('Var rename', function() {
|
||||||
let event = new Blockly.Events.VarRename(this.variable, 'name2');
|
const event = new Blockly.Events.VarRename(this.variable, 'name2');
|
||||||
event.run(false);
|
event.run(false);
|
||||||
chai.assert.isNull(this.workspace.getVariable('name2'));
|
chai.assert.isNull(this.workspace.getVariable('name2'));
|
||||||
checkVariableValues(this.workspace, 'name1', 'type1', 'id1');
|
checkVariableValues(this.workspace, 'name1', 'type1', 'id1');
|
||||||
@@ -778,14 +778,14 @@ suite('Events', function() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
test('No removed, order unchanged', function() {
|
test('No removed, order unchanged', function() {
|
||||||
let block = this.workspace.newBlock('field_variable_test_block', '1');
|
const block = this.workspace.newBlock('field_variable_test_block', '1');
|
||||||
let events = [
|
const events = [
|
||||||
new Blockly.Events.BlockCreate(block),
|
new Blockly.Events.BlockCreate(block),
|
||||||
new Blockly.Events.BlockMove(block),
|
new Blockly.Events.BlockMove(block),
|
||||||
new Blockly.Events.BlockChange(block, 'field', 'VAR', 'id1', 'id2'),
|
new Blockly.Events.BlockChange(block, 'field', 'VAR', 'id1', 'id2'),
|
||||||
new Blockly.Events.Click(block)
|
new Blockly.Events.Click(block)
|
||||||
];
|
];
|
||||||
let filteredEvents = eventUtils.filter(events, true);
|
const filteredEvents = eventUtils.filter(events, true);
|
||||||
chai.assert.equal(filteredEvents.length, 4); // no event should have been removed.
|
chai.assert.equal(filteredEvents.length, 4); // no event should have been removed.
|
||||||
// test that the order hasn't changed
|
// test that the order hasn't changed
|
||||||
chai.assert.isTrue(filteredEvents[0] instanceof Blockly.Events.BlockCreate);
|
chai.assert.isTrue(filteredEvents[0] instanceof Blockly.Events.BlockCreate);
|
||||||
@@ -795,25 +795,25 @@ suite('Events', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
test('Different blocks no removed', function() {
|
test('Different blocks no removed', function() {
|
||||||
let block1 = this.workspace.newBlock('field_variable_test_block', '1');
|
const block1 = this.workspace.newBlock('field_variable_test_block', '1');
|
||||||
let block2 = this.workspace.newBlock('field_variable_test_block', '2');
|
const block2 = this.workspace.newBlock('field_variable_test_block', '2');
|
||||||
let events = [
|
const events = [
|
||||||
new Blockly.Events.BlockCreate(block1),
|
new Blockly.Events.BlockCreate(block1),
|
||||||
new Blockly.Events.BlockMove(block1),
|
new Blockly.Events.BlockMove(block1),
|
||||||
new Blockly.Events.BlockCreate(block2),
|
new Blockly.Events.BlockCreate(block2),
|
||||||
new Blockly.Events.BlockMove(block2)
|
new Blockly.Events.BlockMove(block2)
|
||||||
];
|
];
|
||||||
let filteredEvents = eventUtils.filter(events, true);
|
const filteredEvents = eventUtils.filter(events, true);
|
||||||
chai.assert.equal(filteredEvents.length, 4); // no event should have been removed.
|
chai.assert.equal(filteredEvents.length, 4); // no event should have been removed.
|
||||||
});
|
});
|
||||||
|
|
||||||
test('Forward', function() {
|
test('Forward', function() {
|
||||||
let block = this.workspace.newBlock('field_variable_test_block', '1');
|
const block = this.workspace.newBlock('field_variable_test_block', '1');
|
||||||
let events = [ new Blockly.Events.BlockCreate(block) ];
|
const events = [ new Blockly.Events.BlockCreate(block) ];
|
||||||
addMoveEvent(events, block, 1, 1);
|
addMoveEvent(events, block, 1, 1);
|
||||||
addMoveEvent(events, block, 2, 2);
|
addMoveEvent(events, block, 2, 2);
|
||||||
addMoveEvent(events, block, 3, 3);
|
addMoveEvent(events, block, 3, 3);
|
||||||
let filteredEvents = eventUtils.filter(events, true);
|
const filteredEvents = eventUtils.filter(events, true);
|
||||||
chai.assert.equal(filteredEvents.length, 2); // duplicate moves should have been removed.
|
chai.assert.equal(filteredEvents.length, 2); // duplicate moves should have been removed.
|
||||||
// test that the order hasn't changed
|
// test that the order hasn't changed
|
||||||
chai.assert.isTrue(filteredEvents[0] instanceof Blockly.Events.BlockCreate);
|
chai.assert.isTrue(filteredEvents[0] instanceof Blockly.Events.BlockCreate);
|
||||||
@@ -823,12 +823,12 @@ suite('Events', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
test('Backward', function() {
|
test('Backward', function() {
|
||||||
let block = this.workspace.newBlock('field_variable_test_block', '1');
|
const block = this.workspace.newBlock('field_variable_test_block', '1');
|
||||||
let events = [ new Blockly.Events.BlockCreate(block) ];
|
const events = [ new Blockly.Events.BlockCreate(block) ];
|
||||||
addMoveEvent(events, block, 1, 1);
|
addMoveEvent(events, block, 1, 1);
|
||||||
addMoveEvent(events, block, 2, 2);
|
addMoveEvent(events, block, 2, 2);
|
||||||
addMoveEvent(events, block, 3, 3);
|
addMoveEvent(events, block, 3, 3);
|
||||||
let filteredEvents = eventUtils.filter(events, false);
|
const filteredEvents = eventUtils.filter(events, false);
|
||||||
chai.assert.equal(filteredEvents.length, 2); // duplicate event should have been removed.
|
chai.assert.equal(filteredEvents.length, 2); // duplicate event should have been removed.
|
||||||
// test that the order hasn't changed
|
// test that the order hasn't changed
|
||||||
chai.assert.isTrue(filteredEvents[0] instanceof Blockly.Events.BlockCreate);
|
chai.assert.isTrue(filteredEvents[0] instanceof Blockly.Events.BlockCreate);
|
||||||
@@ -838,34 +838,34 @@ suite('Events', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
test('Merge block move events', function() {
|
test('Merge block move events', function() {
|
||||||
let block = this.workspace.newBlock('field_variable_test_block', '1');
|
const block = this.workspace.newBlock('field_variable_test_block', '1');
|
||||||
let events = [];
|
const events = [];
|
||||||
addMoveEvent(events, block, 0, 0);
|
addMoveEvent(events, block, 0, 0);
|
||||||
addMoveEvent(events, block, 1, 1);
|
addMoveEvent(events, block, 1, 1);
|
||||||
let filteredEvents = eventUtils.filter(events, true);
|
const filteredEvents = eventUtils.filter(events, true);
|
||||||
chai.assert.equal(filteredEvents.length, 1); // second move event merged into first
|
chai.assert.equal(filteredEvents.length, 1); // second move event merged into first
|
||||||
chai.assert.equal(filteredEvents[0].newCoordinate.x, 1);
|
chai.assert.equal(filteredEvents[0].newCoordinate.x, 1);
|
||||||
chai.assert.equal(filteredEvents[0].newCoordinate.y, 1);
|
chai.assert.equal(filteredEvents[0].newCoordinate.y, 1);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('Merge block change events', function() {
|
test('Merge block change events', function() {
|
||||||
let block1 = this.workspace.newBlock('field_variable_test_block', '1');
|
const block1 = this.workspace.newBlock('field_variable_test_block', '1');
|
||||||
let events = [
|
const events = [
|
||||||
new Blockly.Events.BlockChange(block1, 'field', 'VAR', 'item', 'item1'),
|
new Blockly.Events.BlockChange(block1, 'field', 'VAR', 'item', 'item1'),
|
||||||
new Blockly.Events.BlockChange(block1, 'field', 'VAR', 'item1', 'item2')
|
new Blockly.Events.BlockChange(block1, 'field', 'VAR', 'item1', 'item2')
|
||||||
];
|
];
|
||||||
let filteredEvents = eventUtils.filter(events, true);
|
const filteredEvents = eventUtils.filter(events, true);
|
||||||
chai.assert.equal(filteredEvents.length, 1); // second change event merged into first
|
chai.assert.equal(filteredEvents.length, 1); // second change event merged into first
|
||||||
chai.assert.equal(filteredEvents[0].oldValue, 'item');
|
chai.assert.equal(filteredEvents[0].oldValue, 'item');
|
||||||
chai.assert.equal(filteredEvents[0].newValue, 'item2');
|
chai.assert.equal(filteredEvents[0].newValue, 'item2');
|
||||||
});
|
});
|
||||||
|
|
||||||
test('Merge viewport change events', function() {
|
test('Merge viewport change events', function() {
|
||||||
let events = [
|
const events = [
|
||||||
new Blockly.Events.ViewportChange(1, 2, 3, this.workspace, 4),
|
new Blockly.Events.ViewportChange(1, 2, 3, this.workspace, 4),
|
||||||
new Blockly.Events.ViewportChange(5, 6, 7, this.workspace, 8)
|
new Blockly.Events.ViewportChange(5, 6, 7, this.workspace, 8)
|
||||||
];
|
];
|
||||||
let filteredEvents = eventUtils.filter(events, true);
|
const filteredEvents = eventUtils.filter(events, true);
|
||||||
chai.assert.equal(filteredEvents.length, 1); // second change event merged into first
|
chai.assert.equal(filteredEvents.length, 1); // second change event merged into first
|
||||||
chai.assert.equal(filteredEvents[0].viewTop, 5);
|
chai.assert.equal(filteredEvents[0].viewTop, 5);
|
||||||
chai.assert.equal(filteredEvents[0].viewLeft, 6);
|
chai.assert.equal(filteredEvents[0].viewLeft, 6);
|
||||||
@@ -874,10 +874,10 @@ suite('Events', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
test('Merge ui events', function() {
|
test('Merge ui events', function() {
|
||||||
let block1 = this.workspace.newBlock('field_variable_test_block', '1');
|
const block1 = this.workspace.newBlock('field_variable_test_block', '1');
|
||||||
let block2 = this.workspace.newBlock('field_variable_test_block', '2');
|
const block2 = this.workspace.newBlock('field_variable_test_block', '2');
|
||||||
let block3 = this.workspace.newBlock('field_variable_test_block', '3');
|
const block3 = this.workspace.newBlock('field_variable_test_block', '3');
|
||||||
let events = [
|
const events = [
|
||||||
new Blockly.Events.BubbleOpen(block1, true, 'comment'),
|
new Blockly.Events.BubbleOpen(block1, true, 'comment'),
|
||||||
new Blockly.Events.Click(block1),
|
new Blockly.Events.Click(block1),
|
||||||
new Blockly.Events.BubbleOpen(block2, true, 'mutator'),
|
new Blockly.Events.BubbleOpen(block2, true, 'mutator'),
|
||||||
@@ -885,7 +885,7 @@ suite('Events', function() {
|
|||||||
new Blockly.Events.BubbleOpen(block3, true, 'warning'),
|
new Blockly.Events.BubbleOpen(block3, true, 'warning'),
|
||||||
new Blockly.Events.Click(block3)
|
new Blockly.Events.Click(block3)
|
||||||
];
|
];
|
||||||
let filteredEvents = eventUtils.filter(events, true);
|
const filteredEvents = eventUtils.filter(events, true);
|
||||||
// click event merged into corresponding *Open event
|
// click event merged into corresponding *Open event
|
||||||
chai.assert.equal(filteredEvents.length, 3);
|
chai.assert.equal(filteredEvents.length, 3);
|
||||||
chai.assert.isTrue(filteredEvents[0] instanceof Blockly.Events.BubbleOpen);
|
chai.assert.isTrue(filteredEvents[0] instanceof Blockly.Events.BubbleOpen);
|
||||||
@@ -899,12 +899,12 @@ suite('Events', function() {
|
|||||||
test('Colliding events not dropped', function() {
|
test('Colliding events not dropped', function() {
|
||||||
// Tests that events that collide on a (event, block, workspace) tuple
|
// Tests that events that collide on a (event, block, workspace) tuple
|
||||||
// but cannot be merged do not get dropped during filtering.
|
// but cannot be merged do not get dropped during filtering.
|
||||||
let block = this.workspace.newBlock('field_variable_test_block', '1');
|
const block = this.workspace.newBlock('field_variable_test_block', '1');
|
||||||
let events = [
|
const events = [
|
||||||
new Blockly.Events.Click(block),
|
new Blockly.Events.Click(block),
|
||||||
new Blockly.Events.Ui(block, 'stackclick', undefined, undefined)
|
new Blockly.Events.Ui(block, 'stackclick', undefined, undefined)
|
||||||
];
|
];
|
||||||
let filteredEvents = eventUtils.filter(events, true);
|
const filteredEvents = eventUtils.filter(events, true);
|
||||||
// click and stackclick should both exist
|
// click and stackclick should both exist
|
||||||
chai.assert.equal(filteredEvents.length, 2);
|
chai.assert.equal(filteredEvents.length, 2);
|
||||||
chai.assert.isTrue(filteredEvents[0] instanceof Blockly.Events.Click);
|
chai.assert.isTrue(filteredEvents[0] instanceof Blockly.Events.Click);
|
||||||
@@ -919,12 +919,12 @@ suite('Events', function() {
|
|||||||
// that two move events that do get merged (disconnecting and
|
// that two move events that do get merged (disconnecting and
|
||||||
// reconnecting a block in response to a mutator change) are filtered
|
// reconnecting a block in response to a mutator change) are filtered
|
||||||
// from the queue.
|
// from the queue.
|
||||||
let block = this.workspace.newBlock('field_variable_test_block', '1');
|
const block = this.workspace.newBlock('field_variable_test_block', '1');
|
||||||
block.setParent(null);
|
block.setParent(null);
|
||||||
let events = [];
|
const events = [];
|
||||||
addMoveEventParent(events, block, null);
|
addMoveEventParent(events, block, null);
|
||||||
addMoveEventParent(events, block, null);
|
addMoveEventParent(events, block, null);
|
||||||
let filteredEvents = eventUtils.filter(events, true);
|
const filteredEvents = eventUtils.filter(events, true);
|
||||||
// The two events should be merged, but because nothing has changed
|
// The two events should be merged, but because nothing has changed
|
||||||
// they will be filtered out.
|
// they will be filtered out.
|
||||||
chai.assert.equal(filteredEvents.length, 0);
|
chai.assert.equal(filteredEvents.length, 0);
|
||||||
@@ -936,16 +936,16 @@ suite('Events', function() {
|
|||||||
// See github.com/google/blockly/pull/1892 for a worked example showing
|
// See github.com/google/blockly/pull/1892 for a worked example showing
|
||||||
// how merging non-consecutive events can fail when replacing a shadow
|
// how merging non-consecutive events can fail when replacing a shadow
|
||||||
// block.
|
// block.
|
||||||
let block1 = createSimpleTestBlock(this.workspace);
|
const block1 = createSimpleTestBlock(this.workspace);
|
||||||
let block2 = createSimpleTestBlock(this.workspace);
|
const block2 = createSimpleTestBlock(this.workspace);
|
||||||
|
|
||||||
let events = [];
|
const events = [];
|
||||||
addMoveEvent(events, block1, 1, 1);
|
addMoveEvent(events, block1, 1, 1);
|
||||||
addMoveEvent(events, block2, 1, 1);
|
addMoveEvent(events, block2, 1, 1);
|
||||||
events.push(new Blockly.Events.BlockDelete(block2));
|
events.push(new Blockly.Events.BlockDelete(block2));
|
||||||
addMoveEvent(events, block1, 2, 2);
|
addMoveEvent(events, block1, 2, 2);
|
||||||
|
|
||||||
let filteredEvents = eventUtils.filter(events, true);
|
const filteredEvents = eventUtils.filter(events, true);
|
||||||
// Nothing should have merged.
|
// Nothing should have merged.
|
||||||
chai.assert.equal(filteredEvents.length, 4);
|
chai.assert.equal(filteredEvents.length, 4);
|
||||||
// test that the order hasn't changed
|
// test that the order hasn't changed
|
||||||
@@ -964,23 +964,23 @@ suite('Events', function() {
|
|||||||
test('Block dispose triggers Delete', function() {
|
test('Block dispose triggers Delete', function() {
|
||||||
let workspaceSvg;
|
let workspaceSvg;
|
||||||
try {
|
try {
|
||||||
let toolbox = document.getElementById('toolbox-categories');
|
const toolbox = document.getElementById('toolbox-categories');
|
||||||
workspaceSvg = Blockly.inject('blocklyDiv', {toolbox: toolbox});
|
workspaceSvg = Blockly.inject('blocklyDiv', {toolbox: toolbox});
|
||||||
let TEST_BLOCK_ID = 'test_block_id';
|
const TEST_BLOCK_ID = 'test_block_id';
|
||||||
let genUidStub = createGenUidStubWithReturns(
|
const genUidStub = createGenUidStubWithReturns(
|
||||||
[TEST_BLOCK_ID, 'test_group_id']);
|
[TEST_BLOCK_ID, 'test_group_id']);
|
||||||
|
|
||||||
let block = workspaceSvg.newBlock('');
|
const block = workspaceSvg.newBlock('');
|
||||||
block.initSvg();
|
block.initSvg();
|
||||||
block.setCommentText('test comment');
|
block.setCommentText('test comment');
|
||||||
let expectedOldXml = Blockly.Xml.blockToDomWithXY(block);
|
const expectedOldXml = Blockly.Xml.blockToDomWithXY(block);
|
||||||
let expectedId = block.id;
|
const expectedId = block.id;
|
||||||
|
|
||||||
// Run all queued events.
|
// Run all queued events.
|
||||||
this.clock.runAll();
|
this.clock.runAll();
|
||||||
|
|
||||||
this.eventsFireSpy.resetHistory();
|
this.eventsFireSpy.resetHistory();
|
||||||
let changeListenerSpy = createFireChangeListenerSpy(workspaceSvg);
|
const changeListenerSpy = createFireChangeListenerSpy(workspaceSvg);
|
||||||
block.dispose();
|
block.dispose();
|
||||||
|
|
||||||
// Run all queued events.
|
// Run all queued events.
|
||||||
@@ -1007,13 +1007,13 @@ suite('Events', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
test('New block new var', function() {
|
test('New block new var', function() {
|
||||||
let TEST_BLOCK_ID = 'test_block_id';
|
const TEST_BLOCK_ID = 'test_block_id';
|
||||||
let TEST_GROUP_ID = 'test_group_id';
|
const TEST_GROUP_ID = 'test_group_id';
|
||||||
let TEST_VAR_ID = 'test_var_id';
|
const TEST_VAR_ID = 'test_var_id';
|
||||||
let genUidStub = createGenUidStubWithReturns(
|
const genUidStub = createGenUidStubWithReturns(
|
||||||
[TEST_BLOCK_ID, TEST_GROUP_ID, TEST_VAR_ID]);
|
[TEST_BLOCK_ID, TEST_GROUP_ID, TEST_VAR_ID]);
|
||||||
let _ = this.workspace.newBlock('field_variable_test_block');
|
const _ = this.workspace.newBlock('field_variable_test_block');
|
||||||
let TEST_VAR_NAME = 'item'; // As defined in block's json.
|
const TEST_VAR_NAME = 'item'; // As defined in block's json.
|
||||||
|
|
||||||
// Run all queued events.
|
// Run all queued events.
|
||||||
this.clock.runAll();
|
this.clock.runAll();
|
||||||
@@ -1043,18 +1043,18 @@ suite('Events', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
test('New block new var xml', function() {
|
test('New block new var xml', function() {
|
||||||
let TEST_GROUP_ID = 'test_group_id';
|
const TEST_GROUP_ID = 'test_group_id';
|
||||||
let genUidStub = createGenUidStubWithReturns(TEST_GROUP_ID);
|
const genUidStub = createGenUidStubWithReturns(TEST_GROUP_ID);
|
||||||
let dom = Blockly.Xml.textToDom(
|
const dom = Blockly.Xml.textToDom(
|
||||||
'<xml xmlns="https://developers.google.com/blockly/xml">' +
|
'<xml xmlns="https://developers.google.com/blockly/xml">' +
|
||||||
' <block type="field_variable_test_block" id="test_block_id">' +
|
' <block type="field_variable_test_block" id="test_block_id">' +
|
||||||
' <field name="VAR" id="test_var_id">name1</field>' +
|
' <field name="VAR" id="test_var_id">name1</field>' +
|
||||||
' </block>' +
|
' </block>' +
|
||||||
'</xml>');
|
'</xml>');
|
||||||
Blockly.Xml.domToWorkspace(dom, this.workspace);
|
Blockly.Xml.domToWorkspace(dom, this.workspace);
|
||||||
let TEST_BLOCK_ID = 'test_block_id';
|
const TEST_BLOCK_ID = 'test_block_id';
|
||||||
let TEST_VAR_ID = 'test_var_id';
|
const TEST_VAR_ID = 'test_var_id';
|
||||||
let TEST_VAR_NAME = 'name1';
|
const TEST_VAR_NAME = 'name1';
|
||||||
|
|
||||||
// Run all queued events.
|
// Run all queued events.
|
||||||
this.clock.runAll();
|
this.clock.runAll();
|
||||||
@@ -1095,7 +1095,7 @@ suite('Events', function() {
|
|||||||
suite('Disable orphans', function() {
|
suite('Disable orphans', function() {
|
||||||
setup(function() {
|
setup(function() {
|
||||||
// disableOrphans needs a WorkspaceSVG
|
// disableOrphans needs a WorkspaceSVG
|
||||||
let toolbox = document.getElementById('toolbox-categories');
|
const toolbox = document.getElementById('toolbox-categories');
|
||||||
this.workspace = Blockly.inject('blocklyDiv', {toolbox: toolbox});
|
this.workspace = Blockly.inject('blocklyDiv', {toolbox: toolbox});
|
||||||
});
|
});
|
||||||
teardown(function() {
|
teardown(function() {
|
||||||
@@ -1103,7 +1103,7 @@ suite('Events', function() {
|
|||||||
});
|
});
|
||||||
test('Created orphan block is disabled', function() {
|
test('Created orphan block is disabled', function() {
|
||||||
this.workspace.addChangeListener(eventUtils.disableOrphans);
|
this.workspace.addChangeListener(eventUtils.disableOrphans);
|
||||||
let block = this.workspace.newBlock('controls_for');
|
const block = this.workspace.newBlock('controls_for');
|
||||||
block.initSvg();
|
block.initSvg();
|
||||||
block.render();
|
block.render();
|
||||||
|
|
||||||
@@ -1117,7 +1117,7 @@ suite('Events', function() {
|
|||||||
this.workspace.addChangeListener(eventUtils.disableOrphans);
|
this.workspace.addChangeListener(eventUtils.disableOrphans);
|
||||||
|
|
||||||
// Procedure block is never an orphan
|
// Procedure block is never an orphan
|
||||||
let functionBlock = this.workspace.newBlock('procedures_defnoreturn');
|
const functionBlock = this.workspace.newBlock('procedures_defnoreturn');
|
||||||
functionBlock.initSvg();
|
functionBlock.initSvg();
|
||||||
functionBlock.render();
|
functionBlock.render();
|
||||||
|
|
||||||
@@ -1129,11 +1129,11 @@ suite('Events', function() {
|
|||||||
});
|
});
|
||||||
test('Moving a block to top-level disables it', function() {
|
test('Moving a block to top-level disables it', function() {
|
||||||
this.workspace.addChangeListener(eventUtils.disableOrphans);
|
this.workspace.addChangeListener(eventUtils.disableOrphans);
|
||||||
let functionBlock = this.workspace.newBlock('procedures_defnoreturn');
|
const functionBlock = this.workspace.newBlock('procedures_defnoreturn');
|
||||||
functionBlock.initSvg();
|
functionBlock.initSvg();
|
||||||
functionBlock.render();
|
functionBlock.render();
|
||||||
|
|
||||||
let block = this.workspace.newBlock('controls_for');
|
const block = this.workspace.newBlock('controls_for');
|
||||||
block.initSvg();
|
block.initSvg();
|
||||||
block.render();
|
block.render();
|
||||||
|
|
||||||
@@ -1151,11 +1151,11 @@ suite('Events', function() {
|
|||||||
});
|
});
|
||||||
test('Giving block a parent enables it', function() {
|
test('Giving block a parent enables it', function() {
|
||||||
this.workspace.addChangeListener(eventUtils.disableOrphans);
|
this.workspace.addChangeListener(eventUtils.disableOrphans);
|
||||||
let functionBlock = this.workspace.newBlock('procedures_defnoreturn');
|
const functionBlock = this.workspace.newBlock('procedures_defnoreturn');
|
||||||
functionBlock.initSvg();
|
functionBlock.initSvg();
|
||||||
functionBlock.render();
|
functionBlock.render();
|
||||||
|
|
||||||
let block = this.workspace.newBlock('controls_for');
|
const block = this.workspace.newBlock('controls_for');
|
||||||
block.initSvg();
|
block.initSvg();
|
||||||
block.render();
|
block.render();
|
||||||
|
|
||||||
@@ -1170,11 +1170,11 @@ suite('Events', function() {
|
|||||||
});
|
});
|
||||||
test('disableOrphans events are not undoable', function() {
|
test('disableOrphans events are not undoable', function() {
|
||||||
this.workspace.addChangeListener(eventUtils.disableOrphans);
|
this.workspace.addChangeListener(eventUtils.disableOrphans);
|
||||||
let functionBlock = this.workspace.newBlock('procedures_defnoreturn');
|
const functionBlock = this.workspace.newBlock('procedures_defnoreturn');
|
||||||
functionBlock.initSvg();
|
functionBlock.initSvg();
|
||||||
functionBlock.render();
|
functionBlock.render();
|
||||||
|
|
||||||
let block = this.workspace.newBlock('controls_for');
|
const block = this.workspace.newBlock('controls_for');
|
||||||
block.initSvg();
|
block.initSvg();
|
||||||
block.render();
|
block.render();
|
||||||
|
|
||||||
@@ -1187,7 +1187,7 @@ suite('Events', function() {
|
|||||||
// Fire all events
|
// Fire all events
|
||||||
this.clock.runAll();
|
this.clock.runAll();
|
||||||
|
|
||||||
let disabledEvents = this.workspace.getUndoStack().filter(function(e) {
|
const disabledEvents = this.workspace.getUndoStack().filter(function(e) {
|
||||||
return e.element === 'disabled';
|
return e.element === 'disabled';
|
||||||
});
|
});
|
||||||
chai.assert.isEmpty(disabledEvents,
|
chai.assert.isEmpty(disabledEvents,
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ suite('Extensions', function() {
|
|||||||
teardown(function() {
|
teardown(function() {
|
||||||
sharedTestTeardown.call(this);
|
sharedTestTeardown.call(this);
|
||||||
for (let i = 0; i < this.extensionsCleanup_.length; i++) {
|
for (let i = 0; i < this.extensionsCleanup_.length; i++) {
|
||||||
let extension = this.extensionsCleanup_[i];
|
const extension = this.extensionsCleanup_[i];
|
||||||
delete Blockly.Extensions.TEST_ONLY.allExtensions[extension];
|
delete Blockly.Extensions.TEST_ONLY.allExtensions[extension];
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -29,7 +29,7 @@ suite('Extensions', function() {
|
|||||||
|
|
||||||
chai.assert.isUndefined(
|
chai.assert.isUndefined(
|
||||||
Blockly.Extensions.TEST_ONLY.allExtensions['extensions_test_before']);
|
Blockly.Extensions.TEST_ONLY.allExtensions['extensions_test_before']);
|
||||||
let beforeCallback = sinon.spy();
|
const beforeCallback = sinon.spy();
|
||||||
// Extension defined before the block type is defined.
|
// Extension defined before the block type is defined.
|
||||||
Blockly.Extensions.register('extensions_test_before', beforeCallback);
|
Blockly.Extensions.register('extensions_test_before', beforeCallback);
|
||||||
|
|
||||||
@@ -41,7 +41,7 @@ suite('Extensions', function() {
|
|||||||
|
|
||||||
chai.assert.isUndefined(
|
chai.assert.isUndefined(
|
||||||
Blockly.Extensions.TEST_ONLY.allExtensions['extensions_test_after']);
|
Blockly.Extensions.TEST_ONLY.allExtensions['extensions_test_after']);
|
||||||
let afterCallback = sinon.spy();
|
const afterCallback = sinon.spy();
|
||||||
// Extension defined after the block type (but before instantiation).
|
// Extension defined after the block type (but before instantiation).
|
||||||
Blockly.Extensions.register('extensions_test_after', afterCallback);
|
Blockly.Extensions.register('extensions_test_after', afterCallback);
|
||||||
|
|
||||||
@@ -54,7 +54,7 @@ suite('Extensions', function() {
|
|||||||
sinon.assert.notCalled(beforeCallback);
|
sinon.assert.notCalled(beforeCallback);
|
||||||
sinon.assert.notCalled(afterCallback);
|
sinon.assert.notCalled(afterCallback);
|
||||||
|
|
||||||
let block = new Blockly.Block(this.workspace, 'extension_test_block');
|
const block = new Blockly.Block(this.workspace, 'extension_test_block');
|
||||||
|
|
||||||
sinon.assert.calledOnce(beforeCallback);
|
sinon.assert.calledOnce(beforeCallback);
|
||||||
sinon.assert.calledOnce(afterCallback);
|
sinon.assert.calledOnce(afterCallback);
|
||||||
@@ -63,8 +63,8 @@ suite('Extensions', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
test('Parent tooltip when inline', function() {
|
test('Parent tooltip when inline', function() {
|
||||||
let defaultTooltip = "defaultTooltip";
|
const defaultTooltip = "defaultTooltip";
|
||||||
let parentTooltip = "parentTooltip";
|
const parentTooltip = "parentTooltip";
|
||||||
Blockly.defineBlocksWithJsonArray([
|
Blockly.defineBlocksWithJsonArray([
|
||||||
{
|
{
|
||||||
"type": "test_parent_tooltip_when_inline",
|
"type": "test_parent_tooltip_when_inline",
|
||||||
@@ -86,7 +86,7 @@ suite('Extensions', function() {
|
|||||||
}
|
}
|
||||||
]);
|
]);
|
||||||
|
|
||||||
let block =
|
const block =
|
||||||
new Blockly.Block(this.workspace, 'test_parent_tooltip_when_inline');
|
new Blockly.Block(this.workspace, 'test_parent_tooltip_when_inline');
|
||||||
|
|
||||||
// Tooltip is dynamic after extension initialization.
|
// Tooltip is dynamic after extension initialization.
|
||||||
@@ -94,7 +94,7 @@ suite('Extensions', function() {
|
|||||||
chai.assert.equal(block.tooltip(), defaultTooltip);
|
chai.assert.equal(block.tooltip(), defaultTooltip);
|
||||||
|
|
||||||
// Tooltip is normal before connected to parent.
|
// Tooltip is normal before connected to parent.
|
||||||
let parent = new Blockly.Block(this.workspace, 'test_parent');
|
const parent = new Blockly.Block(this.workspace, 'test_parent');
|
||||||
chai.assert.equal(parent.tooltip, parentTooltip);
|
chai.assert.equal(parent.tooltip, parentTooltip);
|
||||||
chai.assert.notExists(parent.inputsInline);
|
chai.assert.notExists(parent.inputsInline);
|
||||||
|
|
||||||
@@ -117,7 +117,7 @@ suite('Extensions', function() {
|
|||||||
test('Basic', function() {
|
test('Basic', function() {
|
||||||
this.extensionsCleanup_.push('mixin_test');
|
this.extensionsCleanup_.push('mixin_test');
|
||||||
|
|
||||||
let testMixin = {
|
const testMixin = {
|
||||||
field: 'FIELD',
|
field: 'FIELD',
|
||||||
method: function() {
|
method: function() {
|
||||||
console.log('TEXT_MIXIN method()');
|
console.log('TEXT_MIXIN method()');
|
||||||
@@ -139,7 +139,7 @@ suite('Extensions', function() {
|
|||||||
"extensions": ["mixin_test"]
|
"extensions": ["mixin_test"]
|
||||||
}]);
|
}]);
|
||||||
|
|
||||||
let block = new Blockly.Block(this.workspace, 'test_block_mixin');
|
const block = new Blockly.Block(this.workspace, 'test_block_mixin');
|
||||||
|
|
||||||
chai.assert.equal(testMixin.field, block.field);
|
chai.assert.equal(testMixin.field, block.field);
|
||||||
chai.assert.equal(testMixin.method, block.method);
|
chai.assert.equal(testMixin.method, block.method);
|
||||||
@@ -174,7 +174,7 @@ suite('Extensions', function() {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
let block = new Blockly.Block(this.workspace, 'mutator_test_block');
|
const block = new Blockly.Block(this.workspace, 'mutator_test_block');
|
||||||
|
|
||||||
// Make sure all of the functions were installed correctly.
|
// Make sure all of the functions were installed correctly.
|
||||||
chai.assert.equal(block.domToMutation(), 'domToMutationFn');
|
chai.assert.equal(block.domToMutation(), 'domToMutationFn');
|
||||||
@@ -197,7 +197,7 @@ suite('Extensions', function() {
|
|||||||
Blockly.Events.disable();
|
Blockly.Events.disable();
|
||||||
chai.assert.isUndefined(
|
chai.assert.isUndefined(
|
||||||
Blockly.Extensions.TEST_ONLY.allExtensions['extensions_test']);
|
Blockly.Extensions.TEST_ONLY.allExtensions['extensions_test']);
|
||||||
let helperFunctionSpy = sinon.spy();
|
const helperFunctionSpy = sinon.spy();
|
||||||
Blockly.Extensions.registerMutator('extensions_test',
|
Blockly.Extensions.registerMutator('extensions_test',
|
||||||
{
|
{
|
||||||
domToMutation: function() {
|
domToMutation: function() {
|
||||||
@@ -210,7 +210,7 @@ suite('Extensions', function() {
|
|||||||
helperFunctionSpy
|
helperFunctionSpy
|
||||||
);
|
);
|
||||||
|
|
||||||
let _ = new Blockly.Block(this.workspace, 'mutator_test_block');
|
const _ = new Blockly.Block(this.workspace, 'mutator_test_block');
|
||||||
|
|
||||||
sinon.assert.calledOnce(helperFunctionSpy);
|
sinon.assert.calledOnce(helperFunctionSpy);
|
||||||
});
|
});
|
||||||
@@ -239,7 +239,7 @@ suite('Extensions', function() {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
let block = new Blockly.Block(this.workspace, 'mutator_test_block');
|
const block = new Blockly.Block(this.workspace, 'mutator_test_block');
|
||||||
|
|
||||||
// Make sure all of the functions were installed correctly.
|
// Make sure all of the functions were installed correctly.
|
||||||
chai.assert.equal(block.domToMutation(), 'domToMutationFn');
|
chai.assert.equal(block.domToMutation(), 'domToMutationFn');
|
||||||
@@ -260,16 +260,16 @@ suite('Extensions', function() {
|
|||||||
|
|
||||||
chai.assert.isUndefined(
|
chai.assert.isUndefined(
|
||||||
Blockly.Extensions.TEST_ONLY.allExtensions['missing_extension']);
|
Blockly.Extensions.TEST_ONLY.allExtensions['missing_extension']);
|
||||||
let workspace = this.workspace;
|
const workspace = this.workspace;
|
||||||
chai.assert.throws(function() {
|
chai.assert.throws(function() {
|
||||||
let _ = new Blockly.Block(workspace, 'missing_extension_block');
|
const _ = new Blockly.Block(workspace, 'missing_extension_block');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
test('Mixin overwrites local value', function() {
|
test('Mixin overwrites local value', function() {
|
||||||
this.extensionsCleanup_.push('mixin_bad_inputList');
|
this.extensionsCleanup_.push('mixin_bad_inputList');
|
||||||
|
|
||||||
let TEST_MIXIN_BAD_INPUTLIST = {
|
const TEST_MIXIN_BAD_INPUTLIST = {
|
||||||
inputList: 'bad inputList' // Defined in constructor
|
inputList: 'bad inputList' // Defined in constructor
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -288,16 +288,16 @@ suite('Extensions', function() {
|
|||||||
"extensions": ["mixin_bad_inputList"]
|
"extensions": ["mixin_bad_inputList"]
|
||||||
}]);
|
}]);
|
||||||
|
|
||||||
let workspace = this.workspace;
|
const workspace = this.workspace;
|
||||||
chai.assert.throws(function() {
|
chai.assert.throws(function() {
|
||||||
let _ = new Blockly.Block(workspace, 'test_block_bad_inputList');
|
const _ = new Blockly.Block(workspace, 'test_block_bad_inputList');
|
||||||
}, /inputList/);
|
}, /inputList/);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('Mixin overwrites prototype', function() {
|
test('Mixin overwrites prototype', function() {
|
||||||
this.extensionsCleanup_.push('mixin_bad_colour_');
|
this.extensionsCleanup_.push('mixin_bad_colour_');
|
||||||
|
|
||||||
let TEST_MIXIN_BAD_COLOUR = {
|
const TEST_MIXIN_BAD_COLOUR = {
|
||||||
colour_: 'bad colour_' // Defined on prototype
|
colour_: 'bad colour_' // Defined on prototype
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -316,9 +316,9 @@ suite('Extensions', function() {
|
|||||||
"extensions": ["mixin_bad_colour_"]
|
"extensions": ["mixin_bad_colour_"]
|
||||||
}]);
|
}]);
|
||||||
|
|
||||||
let workspace = this.workspace;
|
const workspace = this.workspace;
|
||||||
chai.assert.throws(function() {
|
chai.assert.throws(function() {
|
||||||
let _ = new Blockly.Block(workspace, 'test_block_bad_colour');
|
const _ = new Blockly.Block(workspace, 'test_block_bad_colour');
|
||||||
}, /colour_/);
|
}, /colour_/);
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -346,9 +346,9 @@ suite('Extensions', function() {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
let workspace = this.workspace;
|
const workspace = this.workspace;
|
||||||
chai.assert.throws(function() {
|
chai.assert.throws(function() {
|
||||||
let _ = new Blockly.Block(workspace, 'mutator_test_block');
|
const _ = new Blockly.Block(workspace, 'mutator_test_block');
|
||||||
});
|
});
|
||||||
// Should have failed on apply, not on register.
|
// Should have failed on apply, not on register.
|
||||||
chai.assert.isNotNull(
|
chai.assert.isNotNull(
|
||||||
@@ -379,9 +379,9 @@ suite('Extensions', function() {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
let workspace = this.workspace;
|
const workspace = this.workspace;
|
||||||
chai.assert.throws(function() {
|
chai.assert.throws(function() {
|
||||||
let _ = new Blockly.Block(workspace, 'mutator_test_block');
|
const _ = new Blockly.Block(workspace, 'mutator_test_block');
|
||||||
});
|
});
|
||||||
// Should have failed on apply, not on register.
|
// Should have failed on apply, not on register.
|
||||||
chai.assert.isNotNull(
|
chai.assert.isNotNull(
|
||||||
@@ -406,9 +406,9 @@ suite('Extensions', function() {
|
|||||||
return 'extensions_test_fn';
|
return 'extensions_test_fn';
|
||||||
});
|
});
|
||||||
|
|
||||||
let workspace = this.workspace;
|
const workspace = this.workspace;
|
||||||
chai.assert.throws(function() {
|
chai.assert.throws(function() {
|
||||||
let _ = new Blockly.Block(workspace, 'mutator_test_block');
|
const _ = new Blockly.Block(workspace, 'mutator_test_block');
|
||||||
});
|
});
|
||||||
// Should have failed on apply, not on register.
|
// Should have failed on apply, not on register.
|
||||||
chai.assert.isNotNull(
|
chai.assert.isNotNull(
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ suite('Angle Fields', function() {
|
|||||||
* Configuration for field tests with invalid values.
|
* Configuration for field tests with invalid values.
|
||||||
* @type {!Array<!FieldCreationTestCase>}
|
* @type {!Array<!FieldCreationTestCase>}
|
||||||
*/
|
*/
|
||||||
let invalidValueTestCases = [
|
const invalidValueTestCases = [
|
||||||
{title: 'Undefined', value: undefined},
|
{title: 'Undefined', value: undefined},
|
||||||
{title: 'Null', value: null},
|
{title: 'Null', value: null},
|
||||||
{title: 'NaN', value: NaN},
|
{title: 'NaN', value: NaN},
|
||||||
@@ -36,14 +36,14 @@ suite('Angle Fields', function() {
|
|||||||
* @type {!Array<!FieldCreationTestCase>}
|
* @type {!Array<!FieldCreationTestCase>}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
let validValueTestCases = [
|
const validValueTestCases = [
|
||||||
{title: 'Integer', value: 1, expectedValue: 1},
|
{title: 'Integer', value: 1, expectedValue: 1},
|
||||||
{title: 'Float', value: 1.5, expectedValue: 1.5},
|
{title: 'Float', value: 1.5, expectedValue: 1.5},
|
||||||
{title: 'Integer String', value: '1', expectedValue: 1},
|
{title: 'Integer String', value: '1', expectedValue: 1},
|
||||||
{title: 'Float String', value: '1.5', expectedValue: 1.5},
|
{title: 'Float String', value: '1.5', expectedValue: 1.5},
|
||||||
{title: '> 360°', value: 362, expectedValue: 2},
|
{title: '> 360°', value: 362, expectedValue: 2},
|
||||||
];
|
];
|
||||||
let addArgsAndJson = function(testCase) {
|
const addArgsAndJson = function(testCase) {
|
||||||
testCase.args = [testCase.value];
|
testCase.args = [testCase.value];
|
||||||
testCase.json = {'angle': testCase.value};
|
testCase.json = {'angle': testCase.value};
|
||||||
};
|
};
|
||||||
@@ -54,12 +54,12 @@ suite('Angle Fields', function() {
|
|||||||
* The expected default value for the field being tested.
|
* The expected default value for the field being tested.
|
||||||
* @type {*}
|
* @type {*}
|
||||||
*/
|
*/
|
||||||
let defaultFieldValue = 0;
|
const defaultFieldValue = 0;
|
||||||
/**
|
/**
|
||||||
* Asserts that the field property values are set to default.
|
* Asserts that the field property values are set to default.
|
||||||
* @param {FieldTemplate} field The field to check.
|
* @param {FieldTemplate} field The field to check.
|
||||||
*/
|
*/
|
||||||
let assertFieldDefault = function(field) {
|
const assertFieldDefault = function(field) {
|
||||||
testHelpers.assertFieldValue(field, defaultFieldValue);
|
testHelpers.assertFieldValue(field, defaultFieldValue);
|
||||||
};
|
};
|
||||||
/**
|
/**
|
||||||
@@ -67,7 +67,7 @@ suite('Angle Fields', function() {
|
|||||||
* @param {!Blockly.FieldAngle} field The field to check.
|
* @param {!Blockly.FieldAngle} field The field to check.
|
||||||
* @param {!FieldValueTestCase} testCase The test case.
|
* @param {!FieldValueTestCase} testCase The test case.
|
||||||
*/
|
*/
|
||||||
let validTestCaseAssertField = function(field, testCase) {
|
const validTestCaseAssertField = function(field, testCase) {
|
||||||
testHelpers.assertFieldValue(field, testCase.expectedValue);
|
testHelpers.assertFieldValue(field, testCase.expectedValue);
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -93,7 +93,7 @@ suite('Angle Fields', function() {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
suite('Value -> New Value', function() {
|
suite('Value -> New Value', function() {
|
||||||
let initialValue = 1;
|
const initialValue = 1;
|
||||||
setup(function() {
|
setup(function() {
|
||||||
this.field = new Blockly.FieldAngle(initialValue);
|
this.field = new Blockly.FieldAngle(initialValue);
|
||||||
});
|
});
|
||||||
@@ -117,7 +117,7 @@ suite('Angle Fields', function() {
|
|||||||
teardown(function() {
|
teardown(function() {
|
||||||
sinon.restore();
|
sinon.restore();
|
||||||
});
|
});
|
||||||
let testSuites = [
|
const testSuites = [
|
||||||
{title: 'Null Validator',
|
{title: 'Null Validator',
|
||||||
validator:
|
validator:
|
||||||
function() {
|
function() {
|
||||||
@@ -155,13 +155,13 @@ suite('Angle Fields', function() {
|
|||||||
suite('Customizations', function() {
|
suite('Customizations', function() {
|
||||||
suite('Clockwise', function() {
|
suite('Clockwise', function() {
|
||||||
test('JS Configuration', function() {
|
test('JS Configuration', function() {
|
||||||
let field = new Blockly.FieldAngle(0, null, {
|
const field = new Blockly.FieldAngle(0, null, {
|
||||||
clockwise: true
|
clockwise: true
|
||||||
});
|
});
|
||||||
chai.assert.isTrue(field.clockwise_);
|
chai.assert.isTrue(field.clockwise_);
|
||||||
});
|
});
|
||||||
test('JSON Definition', function() {
|
test('JSON Definition', function() {
|
||||||
let field = Blockly.FieldAngle.fromJson({
|
const field = Blockly.FieldAngle.fromJson({
|
||||||
value: 0,
|
value: 0,
|
||||||
clockwise: true
|
clockwise: true
|
||||||
});
|
});
|
||||||
@@ -172,19 +172,19 @@ suite('Angle Fields', function() {
|
|||||||
// runtime (since they are constants) but for testing purposes we
|
// runtime (since they are constants) but for testing purposes we
|
||||||
// can do this.
|
// can do this.
|
||||||
Blockly.FieldAngle.CLOCKWISE = true;
|
Blockly.FieldAngle.CLOCKWISE = true;
|
||||||
let field = new Blockly.FieldAngle();
|
const field = new Blockly.FieldAngle();
|
||||||
chai.assert.isTrue(field.clockwise_);
|
chai.assert.isTrue(field.clockwise_);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
suite('Offset', function() {
|
suite('Offset', function() {
|
||||||
test('JS Configuration', function() {
|
test('JS Configuration', function() {
|
||||||
let field = new Blockly.FieldAngle(0, null, {
|
const field = new Blockly.FieldAngle(0, null, {
|
||||||
offset: 90
|
offset: 90
|
||||||
});
|
});
|
||||||
chai.assert.equal(field.offset_, 90);
|
chai.assert.equal(field.offset_, 90);
|
||||||
});
|
});
|
||||||
test('JSON Definition', function() {
|
test('JSON Definition', function() {
|
||||||
let field = Blockly.FieldAngle.fromJson({
|
const field = Blockly.FieldAngle.fromJson({
|
||||||
value: 0,
|
value: 0,
|
||||||
offset: 90
|
offset: 90
|
||||||
});
|
});
|
||||||
@@ -195,7 +195,7 @@ suite('Angle Fields', function() {
|
|||||||
// runtime (since they are constants) but for testing purposes we
|
// runtime (since they are constants) but for testing purposes we
|
||||||
// can do this.
|
// can do this.
|
||||||
Blockly.FieldAngle.OFFSET = 90;
|
Blockly.FieldAngle.OFFSET = 90;
|
||||||
let field = new Blockly.FieldAngle();
|
const field = new Blockly.FieldAngle();
|
||||||
chai.assert.equal(field.offset_, 90);
|
chai.assert.equal(field.offset_, 90);
|
||||||
});
|
});
|
||||||
test('Null', function() {
|
test('Null', function() {
|
||||||
@@ -203,7 +203,7 @@ suite('Angle Fields', function() {
|
|||||||
// runtime (since they are constants) but for testing purposes we
|
// runtime (since they are constants) but for testing purposes we
|
||||||
// can do this.
|
// can do this.
|
||||||
Blockly.FieldAngle.OFFSET = 90;
|
Blockly.FieldAngle.OFFSET = 90;
|
||||||
let field = Blockly.FieldAngle.fromJson({
|
const field = Blockly.FieldAngle.fromJson({
|
||||||
value: 0,
|
value: 0,
|
||||||
offset: null
|
offset: null
|
||||||
});
|
});
|
||||||
@@ -212,13 +212,13 @@ suite('Angle Fields', function() {
|
|||||||
});
|
});
|
||||||
suite('Wrap', function() {
|
suite('Wrap', function() {
|
||||||
test('JS Configuration', function() {
|
test('JS Configuration', function() {
|
||||||
let field = new Blockly.FieldAngle(0, null, {
|
const field = new Blockly.FieldAngle(0, null, {
|
||||||
wrap: 180
|
wrap: 180
|
||||||
});
|
});
|
||||||
chai.assert.equal(field.wrap_, 180);
|
chai.assert.equal(field.wrap_, 180);
|
||||||
});
|
});
|
||||||
test('JSON Definition', function() {
|
test('JSON Definition', function() {
|
||||||
let field = Blockly.FieldAngle.fromJson({
|
const field = Blockly.FieldAngle.fromJson({
|
||||||
value: 0,
|
value: 0,
|
||||||
wrap: 180
|
wrap: 180
|
||||||
});
|
});
|
||||||
@@ -229,7 +229,7 @@ suite('Angle Fields', function() {
|
|||||||
// runtime (since they are constants) but for testing purposes we
|
// runtime (since they are constants) but for testing purposes we
|
||||||
// can do this.
|
// can do this.
|
||||||
Blockly.FieldAngle.WRAP = 180;
|
Blockly.FieldAngle.WRAP = 180;
|
||||||
let field = new Blockly.FieldAngle();
|
const field = new Blockly.FieldAngle();
|
||||||
chai.assert.equal(field.wrap_, 180);
|
chai.assert.equal(field.wrap_, 180);
|
||||||
});
|
});
|
||||||
test('Null', function() {
|
test('Null', function() {
|
||||||
@@ -237,7 +237,7 @@ suite('Angle Fields', function() {
|
|||||||
// runtime (since they are constants) but for testing purposes we
|
// runtime (since they are constants) but for testing purposes we
|
||||||
// can do this.
|
// can do this.
|
||||||
Blockly.FieldAngle.WRAP = 180;
|
Blockly.FieldAngle.WRAP = 180;
|
||||||
let field = Blockly.FieldAngle.fromJson({
|
const field = Blockly.FieldAngle.fromJson({
|
||||||
value: 0,
|
value: 0,
|
||||||
wrap: null
|
wrap: null
|
||||||
});
|
});
|
||||||
@@ -246,13 +246,13 @@ suite('Angle Fields', function() {
|
|||||||
});
|
});
|
||||||
suite('Round', function() {
|
suite('Round', function() {
|
||||||
test('JS Configuration', function() {
|
test('JS Configuration', function() {
|
||||||
let field = new Blockly.FieldAngle(0, null, {
|
const field = new Blockly.FieldAngle(0, null, {
|
||||||
round: 30
|
round: 30
|
||||||
});
|
});
|
||||||
chai.assert.equal(field.round_, 30);
|
chai.assert.equal(field.round_, 30);
|
||||||
});
|
});
|
||||||
test('JSON Definition', function() {
|
test('JSON Definition', function() {
|
||||||
let field = Blockly.FieldAngle.fromJson({
|
const field = Blockly.FieldAngle.fromJson({
|
||||||
value: 0,
|
value: 0,
|
||||||
round: 30
|
round: 30
|
||||||
});
|
});
|
||||||
@@ -263,7 +263,7 @@ suite('Angle Fields', function() {
|
|||||||
// runtime (since they are constants) but for testing purposes we
|
// runtime (since they are constants) but for testing purposes we
|
||||||
// can do this.
|
// can do this.
|
||||||
Blockly.FieldAngle.ROUND = 30;
|
Blockly.FieldAngle.ROUND = 30;
|
||||||
let field = new Blockly.FieldAngle();
|
const field = new Blockly.FieldAngle();
|
||||||
chai.assert.equal(field.round_, 30);
|
chai.assert.equal(field.round_, 30);
|
||||||
});
|
});
|
||||||
test('Null', function() {
|
test('Null', function() {
|
||||||
@@ -271,7 +271,7 @@ suite('Angle Fields', function() {
|
|||||||
// runtime (since they are constants) but for testing purposes we
|
// runtime (since they are constants) but for testing purposes we
|
||||||
// can do this.
|
// can do this.
|
||||||
Blockly.FieldAngle.ROUND = 30;
|
Blockly.FieldAngle.ROUND = 30;
|
||||||
let field = Blockly.FieldAngle.fromJson({
|
const field = Blockly.FieldAngle.fromJson({
|
||||||
value: 0,
|
value: 0,
|
||||||
round: null
|
round: null
|
||||||
});
|
});
|
||||||
@@ -281,14 +281,14 @@ suite('Angle Fields', function() {
|
|||||||
suite('Mode', function() {
|
suite('Mode', function() {
|
||||||
suite('Compass', function() {
|
suite('Compass', function() {
|
||||||
test('JS Configuration', function() {
|
test('JS Configuration', function() {
|
||||||
let field = new Blockly.FieldAngle(0, null, {
|
const field = new Blockly.FieldAngle(0, null, {
|
||||||
mode: 'compass'
|
mode: 'compass'
|
||||||
});
|
});
|
||||||
chai.assert.equal(field.offset_, 90);
|
chai.assert.equal(field.offset_, 90);
|
||||||
chai.assert.isTrue(field.clockwise_);
|
chai.assert.isTrue(field.clockwise_);
|
||||||
});
|
});
|
||||||
test('JS Configuration', function() {
|
test('JS Configuration', function() {
|
||||||
let field = Blockly.FieldAngle.fromJson({
|
const field = Blockly.FieldAngle.fromJson({
|
||||||
value: 0,
|
value: 0,
|
||||||
mode: 'compass'
|
mode: 'compass'
|
||||||
});
|
});
|
||||||
@@ -298,14 +298,14 @@ suite('Angle Fields', function() {
|
|||||||
});
|
});
|
||||||
suite('Protractor', function() {
|
suite('Protractor', function() {
|
||||||
test('JS Configuration', function() {
|
test('JS Configuration', function() {
|
||||||
let field = new Blockly.FieldAngle(0, null, {
|
const field = new Blockly.FieldAngle(0, null, {
|
||||||
mode: 'protractor'
|
mode: 'protractor'
|
||||||
});
|
});
|
||||||
chai.assert.equal(field.offset_, 0);
|
chai.assert.equal(field.offset_, 0);
|
||||||
chai.assert.isFalse(field.clockwise_);
|
chai.assert.isFalse(field.clockwise_);
|
||||||
});
|
});
|
||||||
test('JS Configuration', function() {
|
test('JS Configuration', function() {
|
||||||
let field = Blockly.FieldAngle.fromJson({
|
const field = Blockly.FieldAngle.fromJson({
|
||||||
value: 0,
|
value: 0,
|
||||||
mode: 'protractor'
|
mode: 'protractor'
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ suite('Checkbox Fields', function() {
|
|||||||
* Configuration for field tests with invalid values.
|
* Configuration for field tests with invalid values.
|
||||||
* @type {!Array<!FieldCreationTestCase>}
|
* @type {!Array<!FieldCreationTestCase>}
|
||||||
*/
|
*/
|
||||||
let invalidValueTestCases = [
|
const invalidValueTestCases = [
|
||||||
{title: 'Undefined', value: undefined},
|
{title: 'Undefined', value: undefined},
|
||||||
{title: 'Null', value: null},
|
{title: 'Null', value: null},
|
||||||
{title: 'NaN', value: NaN},
|
{title: 'NaN', value: NaN},
|
||||||
@@ -34,7 +34,7 @@ suite('Checkbox Fields', function() {
|
|||||||
* Configuration for field tests with valid values.
|
* Configuration for field tests with valid values.
|
||||||
* @type {!Array<!FieldCreationTestCase>}
|
* @type {!Array<!FieldCreationTestCase>}
|
||||||
*/
|
*/
|
||||||
let validValueTestCases = [
|
const validValueTestCases = [
|
||||||
{title: 'Boolean true', value: true, expectedValue: 'TRUE',
|
{title: 'Boolean true', value: true, expectedValue: 'TRUE',
|
||||||
expectedText: 'true'},
|
expectedText: 'true'},
|
||||||
{title: 'Boolean false', value: false, expectedValue: 'FALSE',
|
{title: 'Boolean false', value: false, expectedValue: 'FALSE',
|
||||||
@@ -44,7 +44,7 @@ suite('Checkbox Fields', function() {
|
|||||||
{title: 'String FALSE', value: 'FALSE', expectedValue: 'FALSE',
|
{title: 'String FALSE', value: 'FALSE', expectedValue: 'FALSE',
|
||||||
expectedText: 'false'},
|
expectedText: 'false'},
|
||||||
];
|
];
|
||||||
let addArgsAndJson = function(testCase) {
|
const addArgsAndJson = function(testCase) {
|
||||||
testCase.args = [testCase.value];
|
testCase.args = [testCase.value];
|
||||||
testCase.json = {'checked': testCase.value};
|
testCase.json = {'checked': testCase.value};
|
||||||
};
|
};
|
||||||
@@ -55,12 +55,12 @@ suite('Checkbox Fields', function() {
|
|||||||
* The expected default value for the field being tested.
|
* The expected default value for the field being tested.
|
||||||
* @type {*}
|
* @type {*}
|
||||||
*/
|
*/
|
||||||
let defaultFieldValue = 'FALSE';
|
const defaultFieldValue = 'FALSE';
|
||||||
/**
|
/**
|
||||||
* Asserts that the field property values are set to default.
|
* Asserts that the field property values are set to default.
|
||||||
* @param {!Blockly.FieldCheckbox} field The field to check.
|
* @param {!Blockly.FieldCheckbox} field The field to check.
|
||||||
*/
|
*/
|
||||||
let assertFieldDefault = function(field) {
|
const assertFieldDefault = function(field) {
|
||||||
testHelpers.assertFieldValue(
|
testHelpers.assertFieldValue(
|
||||||
field, defaultFieldValue, defaultFieldValue.toLowerCase());
|
field, defaultFieldValue, defaultFieldValue.toLowerCase());
|
||||||
};
|
};
|
||||||
@@ -69,7 +69,7 @@ suite('Checkbox Fields', function() {
|
|||||||
* @param {!Blockly.FieldCheckbox} field The field to check.
|
* @param {!Blockly.FieldCheckbox} field The field to check.
|
||||||
* @param {!FieldValueTestCase} testCase The test case.
|
* @param {!FieldValueTestCase} testCase The test case.
|
||||||
*/
|
*/
|
||||||
let validTestCaseAssertField = function(field, testCase) {
|
const validTestCaseAssertField = function(field, testCase) {
|
||||||
testHelpers.assertFieldValue(
|
testHelpers.assertFieldValue(
|
||||||
field, testCase.expectedValue, testCase.expectedValue.toLowerCase());
|
field, testCase.expectedValue, testCase.expectedValue.toLowerCase());
|
||||||
};
|
};
|
||||||
@@ -102,7 +102,7 @@ suite('Checkbox Fields', function() {
|
|||||||
setup(function() {
|
setup(function() {
|
||||||
this.field = new Blockly.FieldCheckbox(true);
|
this.field = new Blockly.FieldCheckbox(true);
|
||||||
});
|
});
|
||||||
let testSuites = [
|
const testSuites = [
|
||||||
{title: 'Null Validator',
|
{title: 'Null Validator',
|
||||||
validator:
|
validator:
|
||||||
function() {
|
function() {
|
||||||
@@ -166,40 +166,40 @@ suite('Checkbox Fields', function() {
|
|||||||
chai.assert(field.textContent_.nodeValue, char);
|
chai.assert(field.textContent_.nodeValue, char);
|
||||||
}
|
}
|
||||||
test('Constant', function() {
|
test('Constant', function() {
|
||||||
let checkChar = Blockly.FieldCheckbox.CHECK_CHAR;
|
const checkChar = Blockly.FieldCheckbox.CHECK_CHAR;
|
||||||
// Note: Developers shouldn't actually do this. IMO they should change
|
// Note: Developers shouldn't actually do this. IMO they should change
|
||||||
// the file and then recompile. But this is fine for testing.
|
// the file and then recompile. But this is fine for testing.
|
||||||
Blockly.FieldCheckbox.CHECK_CHAR = '\u2661';
|
Blockly.FieldCheckbox.CHECK_CHAR = '\u2661';
|
||||||
let field = new Blockly.FieldCheckbox(true);
|
const field = new Blockly.FieldCheckbox(true);
|
||||||
assertCharacter(field, '\u2661');
|
assertCharacter(field, '\u2661');
|
||||||
Blockly.FieldCheckbox.CHECK_CHAR = checkChar;
|
Blockly.FieldCheckbox.CHECK_CHAR = checkChar;
|
||||||
});
|
});
|
||||||
test('JS Constructor', function() {
|
test('JS Constructor', function() {
|
||||||
let field = new Blockly.FieldCheckbox(true, null, {
|
const field = new Blockly.FieldCheckbox(true, null, {
|
||||||
checkCharacter: '\u2661'
|
checkCharacter: '\u2661'
|
||||||
});
|
});
|
||||||
assertCharacter(field, '\u2661');
|
assertCharacter(field, '\u2661');
|
||||||
});
|
});
|
||||||
test('JSON Definition', function() {
|
test('JSON Definition', function() {
|
||||||
let field = Blockly.FieldCheckbox.fromJson({
|
const field = Blockly.FieldCheckbox.fromJson({
|
||||||
checkCharacter: '\u2661'
|
checkCharacter: '\u2661'
|
||||||
});
|
});
|
||||||
assertCharacter(field, '\u2661');
|
assertCharacter(field, '\u2661');
|
||||||
});
|
});
|
||||||
test('setCheckCharacter', function() {
|
test('setCheckCharacter', function() {
|
||||||
let field = new Blockly.FieldCheckbox();
|
const field = new Blockly.FieldCheckbox();
|
||||||
assertCharacter(field, Blockly.FieldCheckbox.CHECK_CHAR);
|
assertCharacter(field, Blockly.FieldCheckbox.CHECK_CHAR);
|
||||||
field.setCheckCharacter('\u2661');
|
field.setCheckCharacter('\u2661');
|
||||||
// Don't call assertCharacter b/c we don't want to re-initialize.
|
// Don't call assertCharacter b/c we don't want to re-initialize.
|
||||||
chai.assert.equal(field.textContent_.nodeValue, '\u2661');
|
chai.assert.equal(field.textContent_.nodeValue, '\u2661');
|
||||||
});
|
});
|
||||||
test('setCheckCharacter Before Init', function() {
|
test('setCheckCharacter Before Init', function() {
|
||||||
let field = new Blockly.FieldCheckbox();
|
const field = new Blockly.FieldCheckbox();
|
||||||
field.setCheckCharacter('\u2661');
|
field.setCheckCharacter('\u2661');
|
||||||
assertCharacter(field, '\u2661');
|
assertCharacter(field, '\u2661');
|
||||||
});
|
});
|
||||||
test('Remove Custom Character', function() {
|
test('Remove Custom Character', function() {
|
||||||
let field = new Blockly.FieldCheckbox(true, null, {
|
const field = new Blockly.FieldCheckbox(true, null, {
|
||||||
'checkCharacter': '\u2661'
|
'checkCharacter': '\u2661'
|
||||||
});
|
});
|
||||||
assertCharacter(field, '\u2661');
|
assertCharacter(field, '\u2661');
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ suite('Colour Fields', function() {
|
|||||||
* Configuration for field tests with invalid values.
|
* Configuration for field tests with invalid values.
|
||||||
* @type {!Array<!FieldCreationTestCase>}
|
* @type {!Array<!FieldCreationTestCase>}
|
||||||
*/
|
*/
|
||||||
let invalidValueTestCases = [
|
const invalidValueTestCases = [
|
||||||
{title: 'Undefined', value: undefined},
|
{title: 'Undefined', value: undefined},
|
||||||
{title: 'Null', value: null},
|
{title: 'Null', value: null},
|
||||||
{title: 'NaN', value: NaN},
|
{title: 'NaN', value: NaN},
|
||||||
@@ -35,7 +35,7 @@ suite('Colour Fields', function() {
|
|||||||
* @type {!Array<!FieldCreationTestCase>}
|
* @type {!Array<!FieldCreationTestCase>}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
let validValueTestCases = [
|
const validValueTestCases = [
|
||||||
{title: '#AAAAAA', value: '#AAAAAA', expectedValue: '#aaaaaa',
|
{title: '#AAAAAA', value: '#AAAAAA', expectedValue: '#aaaaaa',
|
||||||
expectedText: '#aaa'},
|
expectedText: '#aaa'},
|
||||||
{title: '#aaaaaa', value: '#aaaaaa', expectedValue: '#aaaaaa',
|
{title: '#aaaaaa', value: '#aaaaaa', expectedValue: '#aaaaaa',
|
||||||
@@ -57,7 +57,7 @@ suite('Colour Fields', function() {
|
|||||||
{title: 'red', value: 'red', expectedValue: '#ff0000',
|
{title: 'red', value: 'red', expectedValue: '#ff0000',
|
||||||
expectedText: '#f00'},
|
expectedText: '#f00'},
|
||||||
];
|
];
|
||||||
let addArgsAndJson = function(testCase) {
|
const addArgsAndJson = function(testCase) {
|
||||||
testCase.args = [testCase.value];
|
testCase.args = [testCase.value];
|
||||||
testCase.json = {'colour': testCase.value};
|
testCase.json = {'colour': testCase.value};
|
||||||
};
|
};
|
||||||
@@ -68,15 +68,15 @@ suite('Colour Fields', function() {
|
|||||||
* The expected default value for the field being tested.
|
* The expected default value for the field being tested.
|
||||||
* @type {*}
|
* @type {*}
|
||||||
*/
|
*/
|
||||||
let defaultFieldValue = Blockly.FieldColour.COLOURS[0];
|
const defaultFieldValue = Blockly.FieldColour.COLOURS[0];
|
||||||
/**
|
/**
|
||||||
* The expected default text for the field being tested.
|
* The expected default text for the field being tested.
|
||||||
* @type {*}
|
* @type {*}
|
||||||
*/
|
*/
|
||||||
let defaultTextValue = (
|
const defaultTextValue = (
|
||||||
function() {
|
function() {
|
||||||
let expectedText = defaultFieldValue;
|
let expectedText = defaultFieldValue;
|
||||||
let m = defaultFieldValue.match(/^#(.)\1(.)\2(.)\3$/);
|
const m = defaultFieldValue.match(/^#(.)\1(.)\2(.)\3$/);
|
||||||
if (m) {
|
if (m) {
|
||||||
expectedText = '#' + m[1] + m[2] + m[3];
|
expectedText = '#' + m[1] + m[2] + m[3];
|
||||||
}
|
}
|
||||||
@@ -86,7 +86,7 @@ suite('Colour Fields', function() {
|
|||||||
* Asserts that the field property values are set to default.
|
* Asserts that the field property values are set to default.
|
||||||
* @param {FieldTemplate} field The field to check.
|
* @param {FieldTemplate} field The field to check.
|
||||||
*/
|
*/
|
||||||
let assertFieldDefault = function(field) {
|
const assertFieldDefault = function(field) {
|
||||||
testHelpers.assertFieldValue(field, defaultFieldValue, defaultTextValue);
|
testHelpers.assertFieldValue(field, defaultFieldValue, defaultTextValue);
|
||||||
};
|
};
|
||||||
/**
|
/**
|
||||||
@@ -94,7 +94,7 @@ suite('Colour Fields', function() {
|
|||||||
* @param {!Blockly.FieldAngle} field The field to check.
|
* @param {!Blockly.FieldAngle} field The field to check.
|
||||||
* @param {!FieldValueTestCase} testCase The test case.
|
* @param {!FieldValueTestCase} testCase The test case.
|
||||||
*/
|
*/
|
||||||
let validTestCaseAssertField = function(field, testCase) {
|
const validTestCaseAssertField = function(field, testCase) {
|
||||||
testHelpers.assertFieldValue(
|
testHelpers.assertFieldValue(
|
||||||
field, testCase.expectedValue, testCase.expectedText);
|
field, testCase.expectedValue, testCase.expectedText);
|
||||||
};
|
};
|
||||||
@@ -138,7 +138,7 @@ suite('Colour Fields', function() {
|
|||||||
setup(function() {
|
setup(function() {
|
||||||
this.field = new Blockly.FieldColour('#aaaaaa');
|
this.field = new Blockly.FieldColour('#aaaaaa');
|
||||||
});
|
});
|
||||||
let testSuites = [
|
const testSuites = [
|
||||||
{title: 'Null Validator',
|
{title: 'Null Validator',
|
||||||
validator:
|
validator:
|
||||||
function() {
|
function() {
|
||||||
@@ -194,13 +194,13 @@ suite('Colour Fields', function() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
test('Constants', function() {
|
test('Constants', function() {
|
||||||
let colours = Blockly.FieldColour.COLOURS;
|
const colours = Blockly.FieldColour.COLOURS;
|
||||||
let titles = Blockly.FieldColour.TITLES;
|
const titles = Blockly.FieldColour.TITLES;
|
||||||
// Note: Developers shouldn't actually do this. IMO they should
|
// Note: Developers shouldn't actually do this. IMO they should
|
||||||
// change the file and then recompile. But this is fine for testing.
|
// change the file and then recompile. But this is fine for testing.
|
||||||
Blockly.FieldColour.COLOURS = ['#aaaaaa'];
|
Blockly.FieldColour.COLOURS = ['#aaaaaa'];
|
||||||
Blockly.FieldColour.TITLES = ['grey'];
|
Blockly.FieldColour.TITLES = ['grey'];
|
||||||
let field = new Blockly.FieldColour();
|
const field = new Blockly.FieldColour();
|
||||||
|
|
||||||
assertColoursAndTitles(field, ['#aaaaaa'], ['grey']);
|
assertColoursAndTitles(field, ['#aaaaaa'], ['grey']);
|
||||||
|
|
||||||
@@ -208,14 +208,14 @@ suite('Colour Fields', function() {
|
|||||||
Blockly.FieldColour.TITLES = titles;
|
Blockly.FieldColour.TITLES = titles;
|
||||||
});
|
});
|
||||||
test('JS Constructor', function() {
|
test('JS Constructor', function() {
|
||||||
let field = new Blockly.FieldColour('#aaaaaa', null, {
|
const field = new Blockly.FieldColour('#aaaaaa', null, {
|
||||||
colourOptions: ['#aaaaaa'],
|
colourOptions: ['#aaaaaa'],
|
||||||
colourTitles: ['grey']
|
colourTitles: ['grey']
|
||||||
});
|
});
|
||||||
assertColoursAndTitles(field, ['#aaaaaa'], ['grey']);
|
assertColoursAndTitles(field, ['#aaaaaa'], ['grey']);
|
||||||
});
|
});
|
||||||
test('JSON Definition', function() {
|
test('JSON Definition', function() {
|
||||||
let field = Blockly.FieldColour.fromJson({
|
const field = Blockly.FieldColour.fromJson({
|
||||||
colour: '#aaaaaa',
|
colour: '#aaaaaa',
|
||||||
colourOptions: ['#aaaaaa'],
|
colourOptions: ['#aaaaaa'],
|
||||||
colourTitles: ['grey']
|
colourTitles: ['grey']
|
||||||
@@ -223,24 +223,24 @@ suite('Colour Fields', function() {
|
|||||||
assertColoursAndTitles(field, ['#aaaaaa'], ['grey']);
|
assertColoursAndTitles(field, ['#aaaaaa'], ['grey']);
|
||||||
});
|
});
|
||||||
test('setColours', function() {
|
test('setColours', function() {
|
||||||
let field = new Blockly.FieldColour();
|
const field = new Blockly.FieldColour();
|
||||||
field.setColours(['#aaaaaa'], ['grey']);
|
field.setColours(['#aaaaaa'], ['grey']);
|
||||||
assertColoursAndTitles(field, ['#aaaaaa'], ['grey']);
|
assertColoursAndTitles(field, ['#aaaaaa'], ['grey']);
|
||||||
});
|
});
|
||||||
test('Titles Undefined', function() {
|
test('Titles Undefined', function() {
|
||||||
let field = new Blockly.FieldColour();
|
const field = new Blockly.FieldColour();
|
||||||
field.setColours(['#aaaaaa']);
|
field.setColours(['#aaaaaa']);
|
||||||
assertColoursAndTitles(field, ['#aaaaaa'], ['#aaaaaa']);
|
assertColoursAndTitles(field, ['#aaaaaa'], ['#aaaaaa']);
|
||||||
});
|
});
|
||||||
test('Some Titles Undefined', function() {
|
test('Some Titles Undefined', function() {
|
||||||
let field = new Blockly.FieldColour();
|
const field = new Blockly.FieldColour();
|
||||||
field.setColours(['#aaaaaa', '#ff0000'], ['grey']);
|
field.setColours(['#aaaaaa', '#ff0000'], ['grey']);
|
||||||
assertColoursAndTitles(field,
|
assertColoursAndTitles(field,
|
||||||
['#aaaaaa', '#ff0000'], ['grey', '#ff0000']);
|
['#aaaaaa', '#ff0000'], ['grey', '#ff0000']);
|
||||||
});
|
});
|
||||||
// This is kinda derpy behavior, but I wanted to document it.
|
// This is kinda derpy behavior, but I wanted to document it.
|
||||||
test('Overwriting Colours While Leaving Titles', function() {
|
test('Overwriting Colours While Leaving Titles', function() {
|
||||||
let field = new Blockly.FieldColour();
|
const field = new Blockly.FieldColour();
|
||||||
field.setColours(['#aaaaaa'], ['grey']);
|
field.setColours(['#aaaaaa'], ['grey']);
|
||||||
field.setColours(['#ff0000']);
|
field.setColours(['#ff0000']);
|
||||||
assertColoursAndTitles(field, ['#ff0000'], ['grey']);
|
assertColoursAndTitles(field, ['#ff0000'], ['grey']);
|
||||||
@@ -252,31 +252,31 @@ suite('Colour Fields', function() {
|
|||||||
chai.assert.equal(field.picker_.firstChild.children.length, columns);
|
chai.assert.equal(field.picker_.firstChild.children.length, columns);
|
||||||
}
|
}
|
||||||
test('Constants', function() {
|
test('Constants', function() {
|
||||||
let columns = Blockly.FieldColour.COLUMNS;
|
const columns = Blockly.FieldColour.COLUMNS;
|
||||||
// Note: Developers shouldn't actually do this. IMO they should edit
|
// Note: Developers shouldn't actually do this. IMO they should edit
|
||||||
// the file and then recompile. But this is fine for testing.
|
// the file and then recompile. But this is fine for testing.
|
||||||
Blockly.FieldColour.COLUMNS = 3;
|
Blockly.FieldColour.COLUMNS = 3;
|
||||||
let field = new Blockly.FieldColour();
|
const field = new Blockly.FieldColour();
|
||||||
|
|
||||||
assertColumns(field, 3);
|
assertColumns(field, 3);
|
||||||
|
|
||||||
Blockly.FieldColour.COLUMNS = columns;
|
Blockly.FieldColour.COLUMNS = columns;
|
||||||
});
|
});
|
||||||
test('JS Constructor', function() {
|
test('JS Constructor', function() {
|
||||||
let field = new Blockly.FieldColour('#ffffff', null, {
|
const field = new Blockly.FieldColour('#ffffff', null, {
|
||||||
columns: 3
|
columns: 3
|
||||||
});
|
});
|
||||||
assertColumns(field, 3);
|
assertColumns(field, 3);
|
||||||
});
|
});
|
||||||
test('JSON Definition', function() {
|
test('JSON Definition', function() {
|
||||||
let field = Blockly.FieldColour.fromJson({
|
const field = Blockly.FieldColour.fromJson({
|
||||||
'colour': '#ffffff',
|
'colour': '#ffffff',
|
||||||
'columns': 3
|
'columns': 3
|
||||||
});
|
});
|
||||||
assertColumns(field, 3);
|
assertColumns(field, 3);
|
||||||
});
|
});
|
||||||
test('setColumns', function() {
|
test('setColumns', function() {
|
||||||
let field = new Blockly.FieldColour();
|
const field = new Blockly.FieldColour();
|
||||||
field.setColumns(3);
|
field.setColumns(3);
|
||||||
assertColumns(field, 3);
|
assertColumns(field, 3);
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ suite('Dropdown Fields', function() {
|
|||||||
* Configuration for field tests with invalid values.
|
* Configuration for field tests with invalid values.
|
||||||
* @type {!Array<!FieldCreationTestCase>}
|
* @type {!Array<!FieldCreationTestCase>}
|
||||||
*/
|
*/
|
||||||
let invalidValueCreationTestCases = [
|
const invalidValueCreationTestCases = [
|
||||||
{title: 'Undefined', args: [undefined]},
|
{title: 'Undefined', args: [undefined]},
|
||||||
{title: 'Array Items not Arrays', args: [undefined]},
|
{title: 'Array Items not Arrays', args: [undefined]},
|
||||||
{title: 'Array Items with Invalid IDs',
|
{title: 'Array Items with Invalid IDs',
|
||||||
@@ -42,7 +42,7 @@ suite('Dropdown Fields', function() {
|
|||||||
* Configuration for field tests with valid values.
|
* Configuration for field tests with valid values.
|
||||||
* @type {!Array<!FieldCreationTestCase>}
|
* @type {!Array<!FieldCreationTestCase>}
|
||||||
*/
|
*/
|
||||||
let validValueCreationTestCases = [
|
const validValueCreationTestCases = [
|
||||||
{title: 'Text Dropdown', value: 'A', expectedValue: 'A', expectedText: 'a',
|
{title: 'Text Dropdown', value: 'A', expectedValue: 'A', expectedText: 'a',
|
||||||
args: [[['a', 'A'], ['b', 'B'], ['c', 'C']]]},
|
args: [[['a', 'A'], ['b', 'B'], ['c', 'C']]]},
|
||||||
{title: 'Image Dropdown', value: 'A', expectedValue: 'A', expectedText: 'a',
|
{title: 'Image Dropdown', value: 'A', expectedValue: 'A', expectedText: 'a',
|
||||||
@@ -62,7 +62,7 @@ suite('Dropdown Fields', function() {
|
|||||||
[{ src:'scrC', alt:'c' }, 'C']];
|
[{ src:'scrC', alt:'c' }, 'C']];
|
||||||
}]},
|
}]},
|
||||||
];
|
];
|
||||||
let addJson = function(testCase) {
|
const addJson = function(testCase) {
|
||||||
testCase.json = {'options': testCase.args[0]};
|
testCase.json = {'options': testCase.args[0]};
|
||||||
};
|
};
|
||||||
invalidValueCreationTestCases.forEach(addJson);
|
invalidValueCreationTestCases.forEach(addJson);
|
||||||
@@ -73,7 +73,7 @@ suite('Dropdown Fields', function() {
|
|||||||
* @param {!Blockly.FieldDropdown} field The field to check.
|
* @param {!Blockly.FieldDropdown} field The field to check.
|
||||||
* @param {!FieldValueTestCase} testCase The test case.
|
* @param {!FieldValueTestCase} testCase The test case.
|
||||||
*/
|
*/
|
||||||
let validTestCaseAssertField = function(field, testCase) {
|
const validTestCaseAssertField = function(field, testCase) {
|
||||||
testHelpers.assertFieldValue(field, testCase.expectedValue, testCase.expectedText);
|
testHelpers.assertFieldValue(field, testCase.expectedValue, testCase.expectedText);
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -89,7 +89,7 @@ suite('Dropdown Fields', function() {
|
|||||||
* Configuration for field tests with invalid values.
|
* Configuration for field tests with invalid values.
|
||||||
* @type {!Array<!FieldCreationTestCase>}
|
* @type {!Array<!FieldCreationTestCase>}
|
||||||
*/
|
*/
|
||||||
let invalidValueSetValueTestCases = [
|
const invalidValueSetValueTestCases = [
|
||||||
{title: 'Null', value: null},
|
{title: 'Null', value: null},
|
||||||
{title: 'Undefined', value: undefined},
|
{title: 'Undefined', value: undefined},
|
||||||
{title: 'Invalid ID', value: 'bad'},
|
{title: 'Invalid ID', value: 'bad'},
|
||||||
@@ -98,7 +98,7 @@ suite('Dropdown Fields', function() {
|
|||||||
* Configuration for field tests with valid values.
|
* Configuration for field tests with valid values.
|
||||||
* @type {!Array<!FieldValueTestCase>}
|
* @type {!Array<!FieldValueTestCase>}
|
||||||
*/
|
*/
|
||||||
let validValueSetValueTestCases = [
|
const validValueSetValueTestCases = [
|
||||||
{title: 'Valid ID', value: 'B', expectedValue: 'B', expectedText: 'b'},
|
{title: 'Valid ID', value: 'B', expectedValue: 'B', expectedText: 'b'},
|
||||||
];
|
];
|
||||||
|
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ suite('Image Fields', function() {
|
|||||||
* Configuration for field tests with invalid values.
|
* Configuration for field tests with invalid values.
|
||||||
* @type {!Array<!FieldCreationTestCase>}
|
* @type {!Array<!FieldCreationTestCase>}
|
||||||
*/
|
*/
|
||||||
let invalidValueTestCases = [
|
const invalidValueTestCases = [
|
||||||
{title: 'Undefined Src', value: undefined, args: [undefined, 1, 1]},
|
{title: 'Undefined Src', value: undefined, args: [undefined, 1, 1]},
|
||||||
{title: 'Undefined Size', value: 'src', args: ['src', undefined, undefined]},
|
{title: 'Undefined Size', value: 'src', args: ['src', undefined, undefined]},
|
||||||
{title: 'Zero Size', value: 'src', args: ['src', 0, 0]},
|
{title: 'Zero Size', value: 'src', args: ['src', 0, 0]},
|
||||||
@@ -30,7 +30,7 @@ suite('Image Fields', function() {
|
|||||||
* Configuration for field tests with valid values.
|
* Configuration for field tests with valid values.
|
||||||
* @type {!Array<!FieldCreationTestCase>}
|
* @type {!Array<!FieldCreationTestCase>}
|
||||||
*/
|
*/
|
||||||
let validValueCreationTestCases = [
|
const validValueCreationTestCases = [
|
||||||
{title: 'With Alt', value: 'src', expectedValue: 'src',
|
{title: 'With Alt', value: 'src', expectedValue: 'src',
|
||||||
args: ['src', 1, 1, 'alt'], expectedText: 'alt'},
|
args: ['src', 1, 1, 'alt'], expectedText: 'alt'},
|
||||||
{title: 'Without Alt', value: 'src', expectedValue: 'src',
|
{title: 'Without Alt', value: 'src', expectedValue: 'src',
|
||||||
@@ -40,7 +40,7 @@ suite('Image Fields', function() {
|
|||||||
* Adds json property to test cases based on args property.
|
* Adds json property to test cases based on args property.
|
||||||
* @param {!Array<!FieldCreationTestCase>} testCase The test case to modify.
|
* @param {!Array<!FieldCreationTestCase>} testCase The test case to modify.
|
||||||
*/
|
*/
|
||||||
let addJson = function(testCase) {
|
const addJson = function(testCase) {
|
||||||
testCase.json = {'src': testCase.args[0], 'width': testCase.args[1],
|
testCase.json = {'src': testCase.args[0], 'width': testCase.args[1],
|
||||||
'height': testCase.args[2]};
|
'height': testCase.args[2]};
|
||||||
if (testCase.args[3]) {
|
if (testCase.args[3]) {
|
||||||
@@ -55,7 +55,7 @@ suite('Image Fields', function() {
|
|||||||
* @param {!Blockly.FieldImage} field The field to check.
|
* @param {!Blockly.FieldImage} field The field to check.
|
||||||
* @param {!FieldValueTestCase} testCase The test case.
|
* @param {!FieldValueTestCase} testCase The test case.
|
||||||
*/
|
*/
|
||||||
let validTestCaseAssertField = function(field, testCase) {
|
const validTestCaseAssertField = function(field, testCase) {
|
||||||
testHelpers.assertFieldValue(field, testCase.expectedValue, testCase.expectedText);
|
testHelpers.assertFieldValue(field, testCase.expectedValue, testCase.expectedText);
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -71,7 +71,7 @@ suite('Image Fields', function() {
|
|||||||
* Configuration for field tests with valid values.
|
* Configuration for field tests with valid values.
|
||||||
* @type {!Array<!FieldValueTestCase>}
|
* @type {!Array<!FieldValueTestCase>}
|
||||||
*/
|
*/
|
||||||
let validValueSetValueTestCases = [
|
const validValueSetValueTestCases = [
|
||||||
{title: 'Good src', value: 'newSrc', expectedValue: 'newSrc',
|
{title: 'Good src', value: 'newSrc', expectedValue: 'newSrc',
|
||||||
expectedText: 'alt'},
|
expectedText: 'alt'},
|
||||||
];
|
];
|
||||||
@@ -92,27 +92,27 @@ suite('Image Fields', function() {
|
|||||||
};
|
};
|
||||||
});
|
});
|
||||||
test('JS Constructor', function() {
|
test('JS Constructor', function() {
|
||||||
let field = new Blockly.FieldImage('src', 10, 10, null, this.onClick);
|
const field = new Blockly.FieldImage('src', 10, 10, null, this.onClick);
|
||||||
chai.assert.equal(field.clickHandler_, this.onClick);
|
chai.assert.equal(field.clickHandler_, this.onClick);
|
||||||
});
|
});
|
||||||
test('setOnClickHandler', function() {
|
test('setOnClickHandler', function() {
|
||||||
let field = new Blockly.FieldImage('src', 10, 10);
|
const field = new Blockly.FieldImage('src', 10, 10);
|
||||||
field.setOnClickHandler(this.onClick);
|
field.setOnClickHandler(this.onClick);
|
||||||
chai.assert.equal(field.clickHandler_, this.onClick);
|
chai.assert.equal(field.clickHandler_, this.onClick);
|
||||||
});
|
});
|
||||||
test('Remove Click Handler', function() {
|
test('Remove Click Handler', function() {
|
||||||
let field = new Blockly.FieldImage('src', 10, 10, null, this.onClick);
|
const field = new Blockly.FieldImage('src', 10, 10, null, this.onClick);
|
||||||
field.setOnClickHandler(null);
|
field.setOnClickHandler(null);
|
||||||
chai.assert.isNull(field.clickHandler_);
|
chai.assert.isNull(field.clickHandler_);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
suite('Alt', function() {
|
suite('Alt', function() {
|
||||||
test('JS Constructor', function() {
|
test('JS Constructor', function() {
|
||||||
let field = new Blockly.FieldImage('src', 10, 10, 'alt');
|
const field = new Blockly.FieldImage('src', 10, 10, 'alt');
|
||||||
chai.assert.equal(field.altText_, 'alt');
|
chai.assert.equal(field.altText_, 'alt');
|
||||||
});
|
});
|
||||||
test('JSON Definition', function() {
|
test('JSON Definition', function() {
|
||||||
let field = Blockly.FieldImage.fromJson({
|
const field = Blockly.FieldImage.fromJson({
|
||||||
src: 'src',
|
src: 'src',
|
||||||
width: 10,
|
width: 10,
|
||||||
height: 10,
|
height: 10,
|
||||||
@@ -138,25 +138,25 @@ suite('Image Fields', function() {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
test('JS Configuration - Simple', function() {
|
test('JS Configuration - Simple', function() {
|
||||||
let field = new Blockly.FieldImage('src', 10, 10, null, null, null, {
|
const field = new Blockly.FieldImage('src', 10, 10, null, null, null, {
|
||||||
alt: 'alt'
|
alt: 'alt'
|
||||||
});
|
});
|
||||||
chai.assert.equal(field.altText_, 'alt');
|
chai.assert.equal(field.altText_, 'alt');
|
||||||
});
|
});
|
||||||
test('JS Configuration - Ignore', function() {
|
test('JS Configuration - Ignore', function() {
|
||||||
let field = new Blockly.FieldImage('src', 10, 10, 'alt', null, null, {
|
const field = new Blockly.FieldImage('src', 10, 10, 'alt', null, null, {
|
||||||
alt: 'configAlt'
|
alt: 'configAlt'
|
||||||
});
|
});
|
||||||
chai.assert.equal(field.altText_, 'configAlt');
|
chai.assert.equal(field.altText_, 'configAlt');
|
||||||
});
|
});
|
||||||
test('JS Configuration - Ignore - \'\'', function() {
|
test('JS Configuration - Ignore - \'\'', function() {
|
||||||
let field = new Blockly.FieldImage('src', 10, 10, '', null, null, {
|
const field = new Blockly.FieldImage('src', 10, 10, '', null, null, {
|
||||||
alt: 'configAlt'
|
alt: 'configAlt'
|
||||||
});
|
});
|
||||||
chai.assert.equal(field.altText_, 'configAlt');
|
chai.assert.equal(field.altText_, 'configAlt');
|
||||||
});
|
});
|
||||||
test('JS Configuration - Ignore - Config \'\'', function() {
|
test('JS Configuration - Ignore - Config \'\'', function() {
|
||||||
let field = new Blockly.FieldImage('src', 10, 10, 'alt', null, null, {
|
const field = new Blockly.FieldImage('src', 10, 10, 'alt', null, null, {
|
||||||
alt: ''
|
alt: ''
|
||||||
});
|
});
|
||||||
chai.assert.equal(field.altText_, '');
|
chai.assert.equal(field.altText_, '');
|
||||||
@@ -164,11 +164,11 @@ suite('Image Fields', function() {
|
|||||||
});
|
});
|
||||||
suite('Flip RTL', function() {
|
suite('Flip RTL', function() {
|
||||||
test('JS Constructor', function() {
|
test('JS Constructor', function() {
|
||||||
let field = new Blockly.FieldImage('src', 10, 10, null, null, true);
|
const field = new Blockly.FieldImage('src', 10, 10, null, null, true);
|
||||||
chai.assert.isTrue(field.getFlipRtl());
|
chai.assert.isTrue(field.getFlipRtl());
|
||||||
});
|
});
|
||||||
test('JSON Definition', function() {
|
test('JSON Definition', function() {
|
||||||
let field = Blockly.FieldImage.fromJson({
|
const field = Blockly.FieldImage.fromJson({
|
||||||
src: 'src',
|
src: 'src',
|
||||||
width: 10,
|
width: 10,
|
||||||
height: 10,
|
height: 10,
|
||||||
@@ -177,19 +177,19 @@ suite('Image Fields', function() {
|
|||||||
chai.assert.isTrue(field.getFlipRtl());
|
chai.assert.isTrue(field.getFlipRtl());
|
||||||
});
|
});
|
||||||
test('JS Configuration - Simple', function() {
|
test('JS Configuration - Simple', function() {
|
||||||
let field = new Blockly.FieldImage('src', 10, 10, null, null, null, {
|
const field = new Blockly.FieldImage('src', 10, 10, null, null, null, {
|
||||||
flipRtl: true
|
flipRtl: true
|
||||||
});
|
});
|
||||||
chai.assert.isTrue(field.getFlipRtl());
|
chai.assert.isTrue(field.getFlipRtl());
|
||||||
});
|
});
|
||||||
test('JS Configuration - Ignore - True', function() {
|
test('JS Configuration - Ignore - True', function() {
|
||||||
let field = new Blockly.FieldImage('src', 10, 10, null, null, true, {
|
const field = new Blockly.FieldImage('src', 10, 10, null, null, true, {
|
||||||
flipRtl: false
|
flipRtl: false
|
||||||
});
|
});
|
||||||
chai.assert.isFalse(field.getFlipRtl());
|
chai.assert.isFalse(field.getFlipRtl());
|
||||||
});
|
});
|
||||||
test('JS Configuration - Ignore - False', function() {
|
test('JS Configuration - Ignore - False', function() {
|
||||||
let field = new Blockly.FieldImage('src', 10, 10, null, null, false, {
|
const field = new Blockly.FieldImage('src', 10, 10, null, null, false, {
|
||||||
flipRtl: true
|
flipRtl: true
|
||||||
});
|
});
|
||||||
chai.assert.isTrue(field.getFlipRtl());
|
chai.assert.isTrue(field.getFlipRtl());
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ suite('Label Serializable Fields', function() {
|
|||||||
* Configuration for field tests with invalid values.
|
* Configuration for field tests with invalid values.
|
||||||
* @type {!Array<!FieldCreationTestCase>}
|
* @type {!Array<!FieldCreationTestCase>}
|
||||||
*/
|
*/
|
||||||
let invalidValueTestCases = [
|
const invalidValueTestCases = [
|
||||||
{title: 'Undefined', value: undefined},
|
{title: 'Undefined', value: undefined},
|
||||||
{title: 'Null', value: null},
|
{title: 'Null', value: null},
|
||||||
];
|
];
|
||||||
@@ -28,7 +28,7 @@ suite('Label Serializable Fields', function() {
|
|||||||
* Configuration for field tests with valid values.
|
* Configuration for field tests with valid values.
|
||||||
* @type {!Array<!FieldCreationTestCase>}
|
* @type {!Array<!FieldCreationTestCase>}
|
||||||
*/
|
*/
|
||||||
let validValueTestCases = [
|
const validValueTestCases = [
|
||||||
{title: 'String', value: 'value', expectedValue: 'value'},
|
{title: 'String', value: 'value', expectedValue: 'value'},
|
||||||
{title: 'Boolean true', value: true, expectedValue: 'true'},
|
{title: 'Boolean true', value: true, expectedValue: 'true'},
|
||||||
{title: 'Boolean false', value: false, expectedValue: 'false'},
|
{title: 'Boolean false', value: false, expectedValue: 'false'},
|
||||||
@@ -36,7 +36,7 @@ suite('Label Serializable Fields', function() {
|
|||||||
{title: 'Number (Falsy)', value: 0, expectedValue: '0'},
|
{title: 'Number (Falsy)', value: 0, expectedValue: '0'},
|
||||||
{title: 'NaN', value: NaN, expectedValue: 'NaN'},
|
{title: 'NaN', value: NaN, expectedValue: 'NaN'},
|
||||||
];
|
];
|
||||||
let addArgsAndJson = function(testCase) {
|
const addArgsAndJson = function(testCase) {
|
||||||
testCase.args = [testCase.value];
|
testCase.args = [testCase.value];
|
||||||
testCase.json = {'text': testCase.value};
|
testCase.json = {'text': testCase.value};
|
||||||
};
|
};
|
||||||
@@ -47,12 +47,12 @@ suite('Label Serializable Fields', function() {
|
|||||||
* The expected default value for the field being tested.
|
* The expected default value for the field being tested.
|
||||||
* @type {*}
|
* @type {*}
|
||||||
*/
|
*/
|
||||||
let defaultFieldValue = '';
|
const defaultFieldValue = '';
|
||||||
/**
|
/**
|
||||||
* Asserts that the field property values are set to default.
|
* Asserts that the field property values are set to default.
|
||||||
* @param {!Blockly.FieldLabelSerializable} field The field to check.
|
* @param {!Blockly.FieldLabelSerializable} field The field to check.
|
||||||
*/
|
*/
|
||||||
let assertFieldDefault = function(field) {
|
const assertFieldDefault = function(field) {
|
||||||
testHelpers.assertFieldValue(field, defaultFieldValue);
|
testHelpers.assertFieldValue(field, defaultFieldValue);
|
||||||
};
|
};
|
||||||
/**
|
/**
|
||||||
@@ -60,7 +60,7 @@ suite('Label Serializable Fields', function() {
|
|||||||
* @param {!Blockly.FieldLabelSerializable} field The field to check.
|
* @param {!Blockly.FieldLabelSerializable} field The field to check.
|
||||||
* @param {!FieldValueTestCase} testCase The test case.
|
* @param {!FieldValueTestCase} testCase The test case.
|
||||||
*/
|
*/
|
||||||
let validTestCaseAssertField = function(field, testCase) {
|
const validTestCaseAssertField = function(field, testCase) {
|
||||||
testHelpers.assertFieldValue(field, testCase.expectedValue);
|
testHelpers.assertFieldValue(field, testCase.expectedValue);
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -86,7 +86,7 @@ suite('Label Serializable Fields', function() {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
suite('Value -> New Value', function() {
|
suite('Value -> New Value', function() {
|
||||||
let initialValue = 'oldValue';
|
const initialValue = 'oldValue';
|
||||||
setup(function() {
|
setup(function() {
|
||||||
this.field = new Blockly.FieldLabelSerializable(initialValue);
|
this.field = new Blockly.FieldLabelSerializable(initialValue);
|
||||||
});
|
});
|
||||||
@@ -122,43 +122,43 @@ suite('Label Serializable Fields', function() {
|
|||||||
labelField.textElement_, cssClass));
|
labelField.textElement_, cssClass));
|
||||||
}
|
}
|
||||||
test('JS Constructor', function() {
|
test('JS Constructor', function() {
|
||||||
let field = new Blockly.FieldLabelSerializable('text', 'testClass');
|
const field = new Blockly.FieldLabelSerializable('text', 'testClass');
|
||||||
assertHasClass(field, 'testClass');
|
assertHasClass(field, 'testClass');
|
||||||
});
|
});
|
||||||
test('JSON Definition', function() {
|
test('JSON Definition', function() {
|
||||||
let field = Blockly.FieldLabelSerializable.fromJson({
|
const field = Blockly.FieldLabelSerializable.fromJson({
|
||||||
class: 'testClass'
|
class: 'testClass'
|
||||||
});
|
});
|
||||||
assertHasClass(field, 'testClass');
|
assertHasClass(field, 'testClass');
|
||||||
});
|
});
|
||||||
test('JS Configuration - Simple', function() {
|
test('JS Configuration - Simple', function() {
|
||||||
let field = new Blockly.FieldLabelSerializable('text', null, {
|
const field = new Blockly.FieldLabelSerializable('text', null, {
|
||||||
class: 'testClass'
|
class: 'testClass'
|
||||||
});
|
});
|
||||||
assertHasClass(field, 'testClass');
|
assertHasClass(field, 'testClass');
|
||||||
});
|
});
|
||||||
test('JS Configuration - Ignore', function() {
|
test('JS Configuration - Ignore', function() {
|
||||||
let field = new Blockly.FieldLabelSerializable('text', 'paramClass', {
|
const field = new Blockly.FieldLabelSerializable('text', 'paramClass', {
|
||||||
class: 'configClass'
|
class: 'configClass'
|
||||||
});
|
});
|
||||||
assertDoesNotHaveClass(field, 'paramClass');
|
assertDoesNotHaveClass(field, 'paramClass');
|
||||||
assertHasClass(field, 'configClass');
|
assertHasClass(field, 'configClass');
|
||||||
});
|
});
|
||||||
test('JS Configuration - Ignore - \'\'', function() {
|
test('JS Configuration - Ignore - \'\'', function() {
|
||||||
let field = new Blockly.FieldLabelSerializable('text', '', {
|
const field = new Blockly.FieldLabelSerializable('text', '', {
|
||||||
class: 'configClass'
|
class: 'configClass'
|
||||||
});
|
});
|
||||||
assertHasClass(field, 'configClass');
|
assertHasClass(field, 'configClass');
|
||||||
});
|
});
|
||||||
test('JS Configuration - Ignore - Config \'\'', function() {
|
test('JS Configuration - Ignore - Config \'\'', function() {
|
||||||
let field = new Blockly.FieldLabelSerializable('text', 'paramClass', {
|
const field = new Blockly.FieldLabelSerializable('text', 'paramClass', {
|
||||||
class: ''
|
class: ''
|
||||||
});
|
});
|
||||||
assertDoesNotHaveClass(field, 'paramClass');
|
assertDoesNotHaveClass(field, 'paramClass');
|
||||||
});
|
});
|
||||||
suite('setClass', function() {
|
suite('setClass', function() {
|
||||||
test('setClass', function() {
|
test('setClass', function() {
|
||||||
let field = new Blockly.FieldLabelSerializable();
|
const field = new Blockly.FieldLabelSerializable();
|
||||||
field.fieldGroup_ = Blockly.utils.dom.createSvgElement(
|
field.fieldGroup_ = Blockly.utils.dom.createSvgElement(
|
||||||
Blockly.utils.Svg.G, {}, null);
|
Blockly.utils.Svg.G, {}, null);
|
||||||
field.constants_ = {
|
field.constants_ = {
|
||||||
@@ -171,12 +171,12 @@ suite('Label Serializable Fields', function() {
|
|||||||
field.textElement_, 'testClass'));
|
field.textElement_, 'testClass'));
|
||||||
});
|
});
|
||||||
test('setClass Before Initialization', function() {
|
test('setClass Before Initialization', function() {
|
||||||
let field = new Blockly.FieldLabelSerializable();
|
const field = new Blockly.FieldLabelSerializable();
|
||||||
field.setClass('testClass');
|
field.setClass('testClass');
|
||||||
assertHasClass(field, 'testClass');
|
assertHasClass(field, 'testClass');
|
||||||
});
|
});
|
||||||
test('Remove Class', function() {
|
test('Remove Class', function() {
|
||||||
let field = new Blockly.FieldLabelSerializable('text', null, {
|
const field = new Blockly.FieldLabelSerializable('text', null, {
|
||||||
class: 'testClass'
|
class: 'testClass'
|
||||||
});
|
});
|
||||||
assertHasClass(field, 'testClass');
|
assertHasClass(field, 'testClass');
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ suite('Label Fields', function() {
|
|||||||
* Configuration for field tests with invalid values.
|
* Configuration for field tests with invalid values.
|
||||||
* @type {!Array<!FieldCreationTestCase>}
|
* @type {!Array<!FieldCreationTestCase>}
|
||||||
*/
|
*/
|
||||||
let invalidValueTestCases = [
|
const invalidValueTestCases = [
|
||||||
{title: 'Undefined', value: undefined},
|
{title: 'Undefined', value: undefined},
|
||||||
{title: 'Null', value: null},
|
{title: 'Null', value: null},
|
||||||
];
|
];
|
||||||
@@ -28,7 +28,7 @@ suite('Label Fields', function() {
|
|||||||
* Configuration for field tests with valid values.
|
* Configuration for field tests with valid values.
|
||||||
* @type {!Array<!FieldCreationTestCase>}
|
* @type {!Array<!FieldCreationTestCase>}
|
||||||
*/
|
*/
|
||||||
let validValueTestCases = [
|
const validValueTestCases = [
|
||||||
{title: 'String', value: 'value', expectedValue: 'value'},
|
{title: 'String', value: 'value', expectedValue: 'value'},
|
||||||
{title: 'Boolean true', value: true, expectedValue: 'true'},
|
{title: 'Boolean true', value: true, expectedValue: 'true'},
|
||||||
{title: 'Boolean false', value: false, expectedValue: 'false'},
|
{title: 'Boolean false', value: false, expectedValue: 'false'},
|
||||||
@@ -36,7 +36,7 @@ suite('Label Fields', function() {
|
|||||||
{title: 'Number (Falsy)', value: 0, expectedValue: '0'},
|
{title: 'Number (Falsy)', value: 0, expectedValue: '0'},
|
||||||
{title: 'NaN', value: NaN, expectedValue: 'NaN'},
|
{title: 'NaN', value: NaN, expectedValue: 'NaN'},
|
||||||
];
|
];
|
||||||
let addArgsAndJson = function(testCase) {
|
const addArgsAndJson = function(testCase) {
|
||||||
testCase.args = [testCase.value];
|
testCase.args = [testCase.value];
|
||||||
testCase.json = {'text': testCase.value};
|
testCase.json = {'text': testCase.value};
|
||||||
};
|
};
|
||||||
@@ -47,12 +47,12 @@ suite('Label Fields', function() {
|
|||||||
* The expected default value for the field being tested.
|
* The expected default value for the field being tested.
|
||||||
* @type {*}
|
* @type {*}
|
||||||
*/
|
*/
|
||||||
let defaultFieldValue = '';
|
const defaultFieldValue = '';
|
||||||
/**
|
/**
|
||||||
* Asserts that the field property values are set to default.
|
* Asserts that the field property values are set to default.
|
||||||
* @param {!Blockly.FieldLabel} field The field to check.
|
* @param {!Blockly.FieldLabel} field The field to check.
|
||||||
*/
|
*/
|
||||||
let assertFieldDefault = function(field) {
|
const assertFieldDefault = function(field) {
|
||||||
testHelpers.assertFieldValue(field, defaultFieldValue);
|
testHelpers.assertFieldValue(field, defaultFieldValue);
|
||||||
};
|
};
|
||||||
/**
|
/**
|
||||||
@@ -60,7 +60,7 @@ suite('Label Fields', function() {
|
|||||||
* @param {!Blockly.FieldLabel} field The field to check.
|
* @param {!Blockly.FieldLabel} field The field to check.
|
||||||
* @param {!FieldValueTestCase} testCase The test case.
|
* @param {!FieldValueTestCase} testCase The test case.
|
||||||
*/
|
*/
|
||||||
let validTestCaseAssertField = function(field, testCase) {
|
const validTestCaseAssertField = function(field, testCase) {
|
||||||
testHelpers.assertFieldValue(field, testCase.expectedValue);
|
testHelpers.assertFieldValue(field, testCase.expectedValue);
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -86,7 +86,7 @@ suite('Label Fields', function() {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
suite('Value -> New Value', function() {
|
suite('Value -> New Value', function() {
|
||||||
let initialValue = 'oldValue';
|
const initialValue = 'oldValue';
|
||||||
setup(function() {
|
setup(function() {
|
||||||
this.field = new Blockly.FieldLabel(initialValue);
|
this.field = new Blockly.FieldLabel(initialValue);
|
||||||
});
|
});
|
||||||
@@ -123,43 +123,43 @@ suite('Label Fields', function() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
test('JS Constructor', function() {
|
test('JS Constructor', function() {
|
||||||
let field = new Blockly.FieldLabel('text', 'testClass');
|
const field = new Blockly.FieldLabel('text', 'testClass');
|
||||||
assertHasClass(field, 'testClass');
|
assertHasClass(field, 'testClass');
|
||||||
});
|
});
|
||||||
test('JSON Definition', function() {
|
test('JSON Definition', function() {
|
||||||
let field = Blockly.FieldLabel.fromJson({
|
const field = Blockly.FieldLabel.fromJson({
|
||||||
class: 'testClass'
|
class: 'testClass'
|
||||||
});
|
});
|
||||||
assertHasClass(field, 'testClass');
|
assertHasClass(field, 'testClass');
|
||||||
});
|
});
|
||||||
test('JS Configuration - Simple', function() {
|
test('JS Configuration - Simple', function() {
|
||||||
let field = new Blockly.FieldLabel('text', null, {
|
const field = new Blockly.FieldLabel('text', null, {
|
||||||
class: 'testClass'
|
class: 'testClass'
|
||||||
});
|
});
|
||||||
assertHasClass(field, 'testClass');
|
assertHasClass(field, 'testClass');
|
||||||
});
|
});
|
||||||
test('JS Configuration - Ignore', function() {
|
test('JS Configuration - Ignore', function() {
|
||||||
let field = new Blockly.FieldLabel('text', 'paramClass', {
|
const field = new Blockly.FieldLabel('text', 'paramClass', {
|
||||||
class: 'configClass'
|
class: 'configClass'
|
||||||
});
|
});
|
||||||
assertDoesNotHaveClass(field, 'paramClass');
|
assertDoesNotHaveClass(field, 'paramClass');
|
||||||
assertHasClass(field, 'configClass');
|
assertHasClass(field, 'configClass');
|
||||||
});
|
});
|
||||||
test('JS Configuration - Ignore - \'\'', function() {
|
test('JS Configuration - Ignore - \'\'', function() {
|
||||||
let field = new Blockly.FieldLabel('text', '', {
|
const field = new Blockly.FieldLabel('text', '', {
|
||||||
class: 'configClass'
|
class: 'configClass'
|
||||||
});
|
});
|
||||||
assertHasClass(field, 'configClass');
|
assertHasClass(field, 'configClass');
|
||||||
});
|
});
|
||||||
test('JS Configuration - Ignore - Config \'\'', function() {
|
test('JS Configuration - Ignore - Config \'\'', function() {
|
||||||
let field = new Blockly.FieldLabel('text', 'paramClass', {
|
const field = new Blockly.FieldLabel('text', 'paramClass', {
|
||||||
class: ''
|
class: ''
|
||||||
});
|
});
|
||||||
assertDoesNotHaveClass(field, 'paramClass');
|
assertDoesNotHaveClass(field, 'paramClass');
|
||||||
});
|
});
|
||||||
suite('setClass', function() {
|
suite('setClass', function() {
|
||||||
test('setClass', function() {
|
test('setClass', function() {
|
||||||
let field = new Blockly.FieldLabel();
|
const field = new Blockly.FieldLabel();
|
||||||
field.fieldGroup_ = Blockly.utils.dom.createSvgElement(
|
field.fieldGroup_ = Blockly.utils.dom.createSvgElement(
|
||||||
Blockly.utils.Svg.G, {}, null);
|
Blockly.utils.Svg.G, {}, null);
|
||||||
field.constants_ = {
|
field.constants_ = {
|
||||||
@@ -172,12 +172,12 @@ suite('Label Fields', function() {
|
|||||||
field.textElement_, 'testClass'));
|
field.textElement_, 'testClass'));
|
||||||
});
|
});
|
||||||
test('setClass Before Initialization', function() {
|
test('setClass Before Initialization', function() {
|
||||||
let field = new Blockly.FieldLabel();
|
const field = new Blockly.FieldLabel();
|
||||||
field.setClass('testClass');
|
field.setClass('testClass');
|
||||||
assertHasClass(field, 'testClass');
|
assertHasClass(field, 'testClass');
|
||||||
});
|
});
|
||||||
test('Remove Class', function() {
|
test('Remove Class', function() {
|
||||||
let field = new Blockly.FieldLabel('text', null, {
|
const field = new Blockly.FieldLabel('text', null, {
|
||||||
class: 'testClass'
|
class: 'testClass'
|
||||||
});
|
});
|
||||||
assertHasClass(field, 'testClass');
|
assertHasClass(field, 'testClass');
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ suite('Multiline Input Fields', function() {
|
|||||||
* Configuration for field tests with invalid values.
|
* Configuration for field tests with invalid values.
|
||||||
* @type {!Array<!FieldCreationTestCase>}
|
* @type {!Array<!FieldCreationTestCase>}
|
||||||
*/
|
*/
|
||||||
let invalidValueTestCases = [
|
const invalidValueTestCases = [
|
||||||
{title: 'Undefined', value: undefined},
|
{title: 'Undefined', value: undefined},
|
||||||
{title: 'Null', value: null},
|
{title: 'Null', value: null},
|
||||||
];
|
];
|
||||||
@@ -28,7 +28,7 @@ suite('Multiline Input Fields', function() {
|
|||||||
* Configuration for field tests with valid values.
|
* Configuration for field tests with valid values.
|
||||||
* @type {!Array<!FieldCreationTestCase>}
|
* @type {!Array<!FieldCreationTestCase>}
|
||||||
*/
|
*/
|
||||||
let validValueTestCases = [
|
const validValueTestCases = [
|
||||||
{title: 'Empty string', value: '', expectedValue: ''},
|
{title: 'Empty string', value: '', expectedValue: ''},
|
||||||
{title: 'String no newline', value: 'value', expectedValue: 'value'},
|
{title: 'String no newline', value: 'value', expectedValue: 'value'},
|
||||||
{title: 'String with newline', value: 'bark bark\n bark bark bark\n bark bar bark bark\n', expectedValue: 'bark bark\n bark bark bark\n bark bar bark bark\n'},
|
{title: 'String with newline', value: 'bark bark\n bark bark bark\n bark bar bark bark\n', expectedValue: 'bark bark\n bark bark bark\n bark bar bark bark\n'},
|
||||||
@@ -38,7 +38,7 @@ suite('Multiline Input Fields', function() {
|
|||||||
{title: 'Number (Falsy)', value: 0, expectedValue: '0'},
|
{title: 'Number (Falsy)', value: 0, expectedValue: '0'},
|
||||||
{title: 'NaN', value: NaN, expectedValue: 'NaN'},
|
{title: 'NaN', value: NaN, expectedValue: 'NaN'},
|
||||||
];
|
];
|
||||||
let addArgsAndJson = function(testCase) {
|
const addArgsAndJson = function(testCase) {
|
||||||
testCase.args = [testCase.value];
|
testCase.args = [testCase.value];
|
||||||
testCase.json = {'text': testCase.value};
|
testCase.json = {'text': testCase.value};
|
||||||
};
|
};
|
||||||
@@ -49,12 +49,12 @@ suite('Multiline Input Fields', function() {
|
|||||||
* The expected default value for the field being tested.
|
* The expected default value for the field being tested.
|
||||||
* @type {*}
|
* @type {*}
|
||||||
*/
|
*/
|
||||||
let defaultFieldValue = '';
|
const defaultFieldValue = '';
|
||||||
/**
|
/**
|
||||||
* Asserts that the field property values are set to default.
|
* Asserts that the field property values are set to default.
|
||||||
* @param {!Blockly.FieldMultilineInput} field The field to check.
|
* @param {!Blockly.FieldMultilineInput} field The field to check.
|
||||||
*/
|
*/
|
||||||
let assertFieldDefault = function(field) {
|
const assertFieldDefault = function(field) {
|
||||||
testHelpers.assertFieldValue(field, defaultFieldValue);
|
testHelpers.assertFieldValue(field, defaultFieldValue);
|
||||||
};
|
};
|
||||||
/**
|
/**
|
||||||
@@ -62,7 +62,7 @@ suite('Multiline Input Fields', function() {
|
|||||||
* @param {!Blockly.FieldMultilineInput} field The field to check.
|
* @param {!Blockly.FieldMultilineInput} field The field to check.
|
||||||
* @param {!FieldValueTestCase} testCase The test case.
|
* @param {!FieldValueTestCase} testCase The test case.
|
||||||
*/
|
*/
|
||||||
let validTestCaseAssertField = function(field, testCase) {
|
const validTestCaseAssertField = function(field, testCase) {
|
||||||
testHelpers.assertFieldValue(field, testCase.expectedValue);
|
testHelpers.assertFieldValue(field, testCase.expectedValue);
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -88,7 +88,7 @@ suite('Multiline Input Fields', function() {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
suite('Value -> New Value', function() {
|
suite('Value -> New Value', function() {
|
||||||
let initialValue = 'oldValue';
|
const initialValue = 'oldValue';
|
||||||
setup(function() {
|
setup(function() {
|
||||||
this.field = new Blockly.FieldMultilineInput(initialValue);
|
this.field = new Blockly.FieldMultilineInput(initialValue);
|
||||||
});
|
});
|
||||||
@@ -108,8 +108,8 @@ suite('Multiline Input Fields', function() {
|
|||||||
});
|
});
|
||||||
const createBlockFn = (value) => {
|
const createBlockFn = (value) => {
|
||||||
return (workspace) => {
|
return (workspace) => {
|
||||||
let block = workspace.newBlock('text_multiline');
|
const block = workspace.newBlock('text_multiline');
|
||||||
let textField = block.getField('TEXT');
|
const textField = block.getField('TEXT');
|
||||||
textField.setValue(value);
|
textField.setValue(value);
|
||||||
return block;
|
return block;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ suite('Number Fields', function() {
|
|||||||
* Configuration for field tests with invalid values.
|
* Configuration for field tests with invalid values.
|
||||||
* @type {!Array<!FieldCreationTestCase>}
|
* @type {!Array<!FieldCreationTestCase>}
|
||||||
*/
|
*/
|
||||||
let invalidValueTestCases = [
|
const invalidValueTestCases = [
|
||||||
{title: 'Undefined', value: undefined},
|
{title: 'Undefined', value: undefined},
|
||||||
{title: 'Null', value: null},
|
{title: 'Null', value: null},
|
||||||
{title: 'NaN', value: NaN},
|
{title: 'NaN', value: NaN},
|
||||||
@@ -30,7 +30,7 @@ suite('Number Fields', function() {
|
|||||||
* Configuration for field tests with valid values.
|
* Configuration for field tests with valid values.
|
||||||
* @type {!Array<!FieldCreationTestCase>}
|
* @type {!Array<!FieldCreationTestCase>}
|
||||||
*/
|
*/
|
||||||
let validValueTestCases = [
|
const validValueTestCases = [
|
||||||
{title: 'Integer', value: 1, expectedValue: 1},
|
{title: 'Integer', value: 1, expectedValue: 1},
|
||||||
{title: 'Float', value: 1.5, expectedValue: 1.5},
|
{title: 'Float', value: 1.5, expectedValue: 1.5},
|
||||||
{title: 'Integer String', value: '1', expectedValue: 1},
|
{title: 'Integer String', value: '1', expectedValue: 1},
|
||||||
@@ -41,7 +41,7 @@ suite('Number Fields', function() {
|
|||||||
{title: 'Negative Infinity String', value: '-Infinity',
|
{title: 'Negative Infinity String', value: '-Infinity',
|
||||||
expectedValue: -Infinity},
|
expectedValue: -Infinity},
|
||||||
];
|
];
|
||||||
let addArgsAndJson = function(testCase) {
|
const addArgsAndJson = function(testCase) {
|
||||||
testCase.args = Array(4).fill(testCase.value);
|
testCase.args = Array(4).fill(testCase.value);
|
||||||
testCase.json = {'value': testCase.value, 'min': testCase.value,
|
testCase.json = {'value': testCase.value, 'min': testCase.value,
|
||||||
'max': testCase.value, 'precision': testCase.value};
|
'max': testCase.value, 'precision': testCase.value};
|
||||||
@@ -53,7 +53,7 @@ suite('Number Fields', function() {
|
|||||||
* The expected default value for the field being tested.
|
* The expected default value for the field being tested.
|
||||||
* @type {*}
|
* @type {*}
|
||||||
*/
|
*/
|
||||||
let defaultFieldValue = 0;
|
const defaultFieldValue = 0;
|
||||||
/**
|
/**
|
||||||
* Asserts that the field property values are as expected.
|
* Asserts that the field property values are as expected.
|
||||||
* @param {!Blockly.FieldNumber} field The field to check.
|
* @param {!Blockly.FieldNumber} field The field to check.
|
||||||
@@ -74,7 +74,7 @@ suite('Number Fields', function() {
|
|||||||
* Asserts that the field property values are set to default.
|
* Asserts that the field property values are set to default.
|
||||||
* @param {!Blockly.FieldNumber} field The field to check.
|
* @param {!Blockly.FieldNumber} field The field to check.
|
||||||
*/
|
*/
|
||||||
let assertFieldDefault = function(field) {
|
const assertFieldDefault = function(field) {
|
||||||
assertNumberField(field, -Infinity, Infinity, 0, defaultFieldValue);
|
assertNumberField(field, -Infinity, Infinity, 0, defaultFieldValue);
|
||||||
};
|
};
|
||||||
/**
|
/**
|
||||||
@@ -82,7 +82,7 @@ suite('Number Fields', function() {
|
|||||||
* @param {!Blockly.FieldNumber} field The field to check.
|
* @param {!Blockly.FieldNumber} field The field to check.
|
||||||
* @param {!FieldValueTestCase} testCase The test case.
|
* @param {!FieldValueTestCase} testCase The test case.
|
||||||
*/
|
*/
|
||||||
let validTestCaseAssertField = function(field, testCase) {
|
const validTestCaseAssertField = function(field, testCase) {
|
||||||
assertNumberField(
|
assertNumberField(
|
||||||
field, testCase.expectedValue, testCase.expectedValue,
|
field, testCase.expectedValue, testCase.expectedValue,
|
||||||
testCase.expectedValue, testCase.expectedValue);
|
testCase.expectedValue, testCase.expectedValue);
|
||||||
@@ -105,7 +105,7 @@ suite('Number Fields', function() {
|
|||||||
validValueTestCases, invalidValueTestCases, defaultFieldValue);
|
validValueTestCases, invalidValueTestCases, defaultFieldValue);
|
||||||
});
|
});
|
||||||
suite('Value -> New Value', function() {
|
suite('Value -> New Value', function() {
|
||||||
let initialValue = 1;
|
const initialValue = 1;
|
||||||
setup(function() {
|
setup(function() {
|
||||||
this.field = new Blockly.FieldNumber(initialValue);
|
this.field = new Blockly.FieldNumber(initialValue);
|
||||||
});
|
});
|
||||||
@@ -113,7 +113,7 @@ suite('Number Fields', function() {
|
|||||||
validValueTestCases, invalidValueTestCases, initialValue);
|
validValueTestCases, invalidValueTestCases, initialValue);
|
||||||
});
|
});
|
||||||
suite('Constraints', function() {
|
suite('Constraints', function() {
|
||||||
let testCases = [
|
const testCases = [
|
||||||
{title: 'Float', json: {}, value: 123.456, expectedValue: 123.456},
|
{title: 'Float', json: {}, value: 123.456, expectedValue: 123.456},
|
||||||
{title: '0.01', json: {precision: .01}, value: 123.456,
|
{title: '0.01', json: {precision: .01}, value: 123.456,
|
||||||
expectedValue: 123.46},
|
expectedValue: 123.46},
|
||||||
@@ -129,19 +129,19 @@ suite('Number Fields', function() {
|
|||||||
suite('Precision', function() {
|
suite('Precision', function() {
|
||||||
testHelpers.runTestCases(testCases, function(testCase) {
|
testHelpers.runTestCases(testCases, function(testCase) {
|
||||||
return function() {
|
return function() {
|
||||||
let field = Blockly.FieldNumber.fromJson(testCase.json);
|
const field = Blockly.FieldNumber.fromJson(testCase.json);
|
||||||
field.setValue(testCase.value);
|
field.setValue(testCase.value);
|
||||||
testHelpers.assertFieldValue(field, testCase.expectedValue);
|
testHelpers.assertFieldValue(field, testCase.expectedValue);
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
test('Null', function() {
|
test('Null', function() {
|
||||||
let field = Blockly.FieldNumber.fromJson({precision: null});
|
const field = Blockly.FieldNumber.fromJson({precision: null});
|
||||||
chai.assert.equal(field.getPrecision(), 0);
|
chai.assert.equal(field.getPrecision(), 0);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
let setValueBoundsTestFn = function(testCase) {
|
const setValueBoundsTestFn = function(testCase) {
|
||||||
return function() {
|
return function() {
|
||||||
let field = Blockly.FieldNumber.fromJson(testCase.json);
|
const field = Blockly.FieldNumber.fromJson(testCase.json);
|
||||||
testCase.values.forEach(function(value, i) {
|
testCase.values.forEach(function(value, i) {
|
||||||
field.setValue(value);
|
field.setValue(value);
|
||||||
testHelpers.assertFieldValue(
|
testHelpers.assertFieldValue(
|
||||||
@@ -150,7 +150,7 @@ suite('Number Fields', function() {
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
suite('Min', function() {
|
suite('Min', function() {
|
||||||
let testCases = [
|
const testCases = [
|
||||||
{title: '-10', json: {min: -10}, values: [-20, 0, 20],
|
{title: '-10', json: {min: -10}, values: [-20, 0, 20],
|
||||||
expectedValues: [-10, 0, 20]},
|
expectedValues: [-10, 0, 20]},
|
||||||
{title: '0', json: {min: 0}, values: [-20, 0, 20],
|
{title: '0', json: {min: 0}, values: [-20, 0, 20],
|
||||||
@@ -160,12 +160,12 @@ suite('Number Fields', function() {
|
|||||||
];
|
];
|
||||||
testHelpers.runTestCases(testCases, setValueBoundsTestFn);
|
testHelpers.runTestCases(testCases, setValueBoundsTestFn);
|
||||||
test('Null', function() {
|
test('Null', function() {
|
||||||
let field = Blockly.FieldNumber.fromJson({min: null});
|
const field = Blockly.FieldNumber.fromJson({min: null});
|
||||||
chai.assert.equal(field.getMin(), -Infinity);
|
chai.assert.equal(field.getMin(), -Infinity);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
suite('Max', function() {
|
suite('Max', function() {
|
||||||
let testCases = [
|
const testCases = [
|
||||||
{title: '-10', json: {max: -10}, values: [-20, 0, 20],
|
{title: '-10', json: {max: -10}, values: [-20, 0, 20],
|
||||||
expectedValues: [-20, -10, -10]},
|
expectedValues: [-20, -10, -10]},
|
||||||
{title: '0', json: {max: 0}, values: [-20, 0, 20],
|
{title: '0', json: {max: 0}, values: [-20, 0, 20],
|
||||||
@@ -175,7 +175,7 @@ suite('Number Fields', function() {
|
|||||||
];
|
];
|
||||||
testHelpers.runTestCases(testCases, setValueBoundsTestFn);
|
testHelpers.runTestCases(testCases, setValueBoundsTestFn);
|
||||||
test('Null', function() {
|
test('Null', function() {
|
||||||
let field = Blockly.FieldNumber.fromJson({max: null});
|
const field = Blockly.FieldNumber.fromJson({max: null});
|
||||||
chai.assert.equal(field.getMax(), Infinity);
|
chai.assert.equal(field.getMax(), Infinity);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@@ -192,7 +192,7 @@ suite('Number Fields', function() {
|
|||||||
teardown(function() {
|
teardown(function() {
|
||||||
sinon.restore();
|
sinon.restore();
|
||||||
});
|
});
|
||||||
let testSuites = [
|
const testSuites = [
|
||||||
{title: 'Null Validator',
|
{title: 'Null Validator',
|
||||||
validator:
|
validator:
|
||||||
function() {
|
function() {
|
||||||
@@ -230,34 +230,34 @@ suite('Number Fields', function() {
|
|||||||
suite('Customizations', function() {
|
suite('Customizations', function() {
|
||||||
suite('Min', function() {
|
suite('Min', function() {
|
||||||
test('JS Constructor', function() {
|
test('JS Constructor', function() {
|
||||||
let field = new Blockly.FieldNumber(0, -10);
|
const field = new Blockly.FieldNumber(0, -10);
|
||||||
assertNumberField(field, -10, Infinity, 0, 0);
|
assertNumberField(field, -10, Infinity, 0, 0);
|
||||||
});
|
});
|
||||||
test('JSON Definition', function() {
|
test('JSON Definition', function() {
|
||||||
let field = Blockly.FieldNumber.fromJson({
|
const field = Blockly.FieldNumber.fromJson({
|
||||||
min: -10,
|
min: -10,
|
||||||
});
|
});
|
||||||
assertNumberField(field, -10, Infinity, 0, 0);
|
assertNumberField(field, -10, Infinity, 0, 0);
|
||||||
});
|
});
|
||||||
test('Set Constraints', function() {
|
test('Set Constraints', function() {
|
||||||
let field = new Blockly.FieldNumber();
|
const field = new Blockly.FieldNumber();
|
||||||
field.setConstraints(-10);
|
field.setConstraints(-10);
|
||||||
assertNumberField(field, -10, Infinity, 0, 0);
|
assertNumberField(field, -10, Infinity, 0, 0);
|
||||||
});
|
});
|
||||||
test('Set Min', function() {
|
test('Set Min', function() {
|
||||||
let field = new Blockly.FieldNumber();
|
const field = new Blockly.FieldNumber();
|
||||||
field.setMin(-10);
|
field.setMin(-10);
|
||||||
assertNumberField(field, -10, Infinity, 0, 0);
|
assertNumberField(field, -10, Infinity, 0, 0);
|
||||||
});
|
});
|
||||||
test('JS Configuration - Simple', function() {
|
test('JS Configuration - Simple', function() {
|
||||||
let field = new Blockly.FieldNumber(
|
const field = new Blockly.FieldNumber(
|
||||||
undefined, undefined, undefined, undefined, undefined, {
|
undefined, undefined, undefined, undefined, undefined, {
|
||||||
min: -10
|
min: -10
|
||||||
});
|
});
|
||||||
assertNumberField(field, -10, Infinity, 0, 0);
|
assertNumberField(field, -10, Infinity, 0, 0);
|
||||||
});
|
});
|
||||||
test('JS Configuration - Ignore', function() {
|
test('JS Configuration - Ignore', function() {
|
||||||
let field = new Blockly.FieldNumber(
|
const field = new Blockly.FieldNumber(
|
||||||
undefined, -1, undefined, undefined, undefined, {
|
undefined, -1, undefined, undefined, undefined, {
|
||||||
min: -10
|
min: -10
|
||||||
});
|
});
|
||||||
@@ -266,34 +266,34 @@ suite('Number Fields', function() {
|
|||||||
});
|
});
|
||||||
suite('Max', function() {
|
suite('Max', function() {
|
||||||
test('JS Constructor', function() {
|
test('JS Constructor', function() {
|
||||||
let field = new Blockly.FieldNumber(0, undefined, 10);
|
const field = new Blockly.FieldNumber(0, undefined, 10);
|
||||||
assertNumberField(field, -Infinity, 10, 0, 0);
|
assertNumberField(field, -Infinity, 10, 0, 0);
|
||||||
});
|
});
|
||||||
test('JSON Definition', function() {
|
test('JSON Definition', function() {
|
||||||
let field = Blockly.FieldNumber.fromJson({
|
const field = Blockly.FieldNumber.fromJson({
|
||||||
max: 10,
|
max: 10,
|
||||||
});
|
});
|
||||||
assertNumberField(field, -Infinity, 10, 0, 0);
|
assertNumberField(field, -Infinity, 10, 0, 0);
|
||||||
});
|
});
|
||||||
test('Set Constraints', function() {
|
test('Set Constraints', function() {
|
||||||
let field = new Blockly.FieldNumber();
|
const field = new Blockly.FieldNumber();
|
||||||
field.setConstraints(undefined, 10);
|
field.setConstraints(undefined, 10);
|
||||||
assertNumberField(field, -Infinity, 10, 0, 0);
|
assertNumberField(field, -Infinity, 10, 0, 0);
|
||||||
});
|
});
|
||||||
test('Set Max', function() {
|
test('Set Max', function() {
|
||||||
let field = new Blockly.FieldNumber();
|
const field = new Blockly.FieldNumber();
|
||||||
field.setMax(10);
|
field.setMax(10);
|
||||||
assertNumberField(field, -Infinity, 10, 0, 0);
|
assertNumberField(field, -Infinity, 10, 0, 0);
|
||||||
});
|
});
|
||||||
test('JS Configuration - Simple', function() {
|
test('JS Configuration - Simple', function() {
|
||||||
let field = new Blockly.FieldNumber(
|
const field = new Blockly.FieldNumber(
|
||||||
undefined, undefined, undefined, undefined, undefined, {
|
undefined, undefined, undefined, undefined, undefined, {
|
||||||
max: 10
|
max: 10
|
||||||
});
|
});
|
||||||
assertNumberField(field, -Infinity, 10, 0, 0);
|
assertNumberField(field, -Infinity, 10, 0, 0);
|
||||||
});
|
});
|
||||||
test('JS Configuration - Ignore', function() {
|
test('JS Configuration - Ignore', function() {
|
||||||
let field = new Blockly.FieldNumber(
|
const field = new Blockly.FieldNumber(
|
||||||
undefined, undefined, 1, undefined, undefined, {
|
undefined, undefined, 1, undefined, undefined, {
|
||||||
max: 10
|
max: 10
|
||||||
});
|
});
|
||||||
@@ -302,34 +302,34 @@ suite('Number Fields', function() {
|
|||||||
});
|
});
|
||||||
suite('Precision', function() {
|
suite('Precision', function() {
|
||||||
test('JS Constructor', function() {
|
test('JS Constructor', function() {
|
||||||
let field = new Blockly.FieldNumber(0, undefined, undefined, 1);
|
const field = new Blockly.FieldNumber(0, undefined, undefined, 1);
|
||||||
assertNumberField(field, -Infinity, Infinity, 1, 0);
|
assertNumberField(field, -Infinity, Infinity, 1, 0);
|
||||||
});
|
});
|
||||||
test('JSON Definition', function() {
|
test('JSON Definition', function() {
|
||||||
let field = Blockly.FieldNumber.fromJson({
|
const field = Blockly.FieldNumber.fromJson({
|
||||||
precision: 1,
|
precision: 1,
|
||||||
});
|
});
|
||||||
assertNumberField(field, -Infinity, Infinity, 1, 0);
|
assertNumberField(field, -Infinity, Infinity, 1, 0);
|
||||||
});
|
});
|
||||||
test('Set Constraints', function() {
|
test('Set Constraints', function() {
|
||||||
let field = new Blockly.FieldNumber();
|
const field = new Blockly.FieldNumber();
|
||||||
field.setConstraints(undefined, undefined, 1);
|
field.setConstraints(undefined, undefined, 1);
|
||||||
assertNumberField(field, -Infinity, Infinity, 1, 0);
|
assertNumberField(field, -Infinity, Infinity, 1, 0);
|
||||||
});
|
});
|
||||||
test('Set Precision', function() {
|
test('Set Precision', function() {
|
||||||
let field = new Blockly.FieldNumber();
|
const field = new Blockly.FieldNumber();
|
||||||
field.setPrecision(1);
|
field.setPrecision(1);
|
||||||
assertNumberField(field, -Infinity, Infinity, 1, 0);
|
assertNumberField(field, -Infinity, Infinity, 1, 0);
|
||||||
});
|
});
|
||||||
test('JS Configuration - Simple', function() {
|
test('JS Configuration - Simple', function() {
|
||||||
let field = new Blockly.FieldNumber(
|
const field = new Blockly.FieldNumber(
|
||||||
undefined, undefined, undefined, undefined, undefined, {
|
undefined, undefined, undefined, undefined, undefined, {
|
||||||
precision: 1
|
precision: 1
|
||||||
});
|
});
|
||||||
assertNumberField(field, -Infinity, Infinity, 1, 0);
|
assertNumberField(field, -Infinity, Infinity, 1, 0);
|
||||||
});
|
});
|
||||||
test('JS Configuration - Ignore', function() {
|
test('JS Configuration - Ignore', function() {
|
||||||
let field = new Blockly.FieldNumber(
|
const field = new Blockly.FieldNumber(
|
||||||
undefined, undefined, undefined, .5, undefined, {
|
undefined, undefined, undefined, .5, undefined, {
|
||||||
precision: 1
|
precision: 1
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -38,7 +38,7 @@ suite('Field Registry', function() {
|
|||||||
}, 'Invalid name');
|
}, 'Invalid name');
|
||||||
});
|
});
|
||||||
test('No fromJson', function() {
|
test('No fromJson', function() {
|
||||||
let fromJson = CustomFieldType.fromJson;
|
const fromJson = CustomFieldType.fromJson;
|
||||||
delete CustomFieldType.fromJson;
|
delete CustomFieldType.fromJson;
|
||||||
chai.assert.throws(function() {
|
chai.assert.throws(function() {
|
||||||
Blockly.fieldRegistry.register('field_custom_test', CustomFieldType);
|
Blockly.fieldRegistry.register('field_custom_test', CustomFieldType);
|
||||||
@@ -46,7 +46,7 @@ suite('Field Registry', function() {
|
|||||||
CustomFieldType.fromJson = fromJson;
|
CustomFieldType.fromJson = fromJson;
|
||||||
});
|
});
|
||||||
test('fromJson not a function', function() {
|
test('fromJson not a function', function() {
|
||||||
let fromJson = CustomFieldType.fromJson;
|
const fromJson = CustomFieldType.fromJson;
|
||||||
CustomFieldType.fromJson = true;
|
CustomFieldType.fromJson = true;
|
||||||
chai.assert.throws(function() {
|
chai.assert.throws(function() {
|
||||||
Blockly.fieldRegistry.register('field_custom_test', CustomFieldType);
|
Blockly.fieldRegistry.register('field_custom_test', CustomFieldType);
|
||||||
@@ -58,24 +58,24 @@ suite('Field Registry', function() {
|
|||||||
test('Simple', function() {
|
test('Simple', function() {
|
||||||
Blockly.fieldRegistry.register('field_custom_test', CustomFieldType);
|
Blockly.fieldRegistry.register('field_custom_test', CustomFieldType);
|
||||||
|
|
||||||
let json = {
|
const json = {
|
||||||
type: 'field_custom_test',
|
type: 'field_custom_test',
|
||||||
value: 'ok'
|
value: 'ok'
|
||||||
};
|
};
|
||||||
|
|
||||||
let field = Blockly.fieldRegistry.fromJson(json);
|
const field = Blockly.fieldRegistry.fromJson(json);
|
||||||
|
|
||||||
chai.assert.isNotNull(field);
|
chai.assert.isNotNull(field);
|
||||||
chai.assert.equal(field.getValue(), 'ok');
|
chai.assert.equal(field.getValue(), 'ok');
|
||||||
});
|
});
|
||||||
test('Not Registered', function() {
|
test('Not Registered', function() {
|
||||||
let json = {
|
const json = {
|
||||||
type: 'field_custom_test',
|
type: 'field_custom_test',
|
||||||
value: 'ok'
|
value: 'ok'
|
||||||
};
|
};
|
||||||
|
|
||||||
let spy = sinon.stub(console, 'warn');
|
const spy = sinon.stub(console, 'warn');
|
||||||
let field = Blockly.fieldRegistry.fromJson(json);
|
const field = Blockly.fieldRegistry.fromJson(json);
|
||||||
chai.assert.isNull(field);
|
chai.assert.isNull(field);
|
||||||
chai.assert.isTrue(spy.called);
|
chai.assert.isTrue(spy.called);
|
||||||
spy.restore();
|
spy.restore();
|
||||||
@@ -83,12 +83,12 @@ suite('Field Registry', function() {
|
|||||||
test('Case Different', function() {
|
test('Case Different', function() {
|
||||||
Blockly.fieldRegistry.register('field_custom_test', CustomFieldType);
|
Blockly.fieldRegistry.register('field_custom_test', CustomFieldType);
|
||||||
|
|
||||||
let json = {
|
const json = {
|
||||||
type: 'FIELD_CUSTOM_TEST',
|
type: 'FIELD_CUSTOM_TEST',
|
||||||
value: 'ok'
|
value: 'ok'
|
||||||
};
|
};
|
||||||
|
|
||||||
let field = Blockly.fieldRegistry.fromJson(json);
|
const field = Blockly.fieldRegistry.fromJson(json);
|
||||||
|
|
||||||
chai.assert.isNotNull(field);
|
chai.assert.isNotNull(field);
|
||||||
chai.assert.equal(field.getValue(), 'ok');
|
chai.assert.equal(field.getValue(), 'ok');
|
||||||
|
|||||||
@@ -47,27 +47,27 @@ suite('Abstract Fields', function() {
|
|||||||
/* Test Backwards Compatibility */
|
/* Test Backwards Compatibility */
|
||||||
test('Editable Default(true), Serializable Default(false)', function() {
|
test('Editable Default(true), Serializable Default(false)', function() {
|
||||||
// An old default field should be serialized.
|
// An old default field should be serialized.
|
||||||
let field = new FieldDefault();
|
const field = new FieldDefault();
|
||||||
let stub = sinon.stub(console, 'warn');
|
const stub = sinon.stub(console, 'warn');
|
||||||
chai.assert.isTrue(field.isSerializable());
|
chai.assert.isTrue(field.isSerializable());
|
||||||
sinon.assert.calledOnce(stub);
|
sinon.assert.calledOnce(stub);
|
||||||
stub.restore();
|
stub.restore();
|
||||||
});
|
});
|
||||||
test('Editable False, Serializable Default(false)', function() {
|
test('Editable False, Serializable Default(false)', function() {
|
||||||
// An old non-editable field should not be serialized.
|
// An old non-editable field should not be serialized.
|
||||||
let field = new FieldFalseDefault();
|
const field = new FieldFalseDefault();
|
||||||
chai.assert.isFalse(field.isSerializable());
|
chai.assert.isFalse(field.isSerializable());
|
||||||
});
|
});
|
||||||
/* Test Other Cases */
|
/* Test Other Cases */
|
||||||
test('Editable Default(true), Serializable True', function() {
|
test('Editable Default(true), Serializable True', function() {
|
||||||
// A field that is both editable and serializable should be serialized.
|
// A field that is both editable and serializable should be serialized.
|
||||||
let field = new FieldDefaultTrue();
|
const field = new FieldDefaultTrue();
|
||||||
chai.assert.isTrue(field.isSerializable());
|
chai.assert.isTrue(field.isSerializable());
|
||||||
});
|
});
|
||||||
test('Editable False, Serializable True', function() {
|
test('Editable False, Serializable True', function() {
|
||||||
// A field that is not editable, but overrides serializable to true
|
// A field that is not editable, but overrides serializable to true
|
||||||
// should be serialized (e.g. field_label_serializable)
|
// should be serialized (e.g. field_label_serializable)
|
||||||
let field = new FieldFalseTrue();
|
const field = new FieldFalseTrue();
|
||||||
chai.assert.isTrue(field.isSerializable());
|
chai.assert.isTrue(field.isSerializable());
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@@ -596,22 +596,22 @@ suite('Abstract Fields', function() {
|
|||||||
|
|
||||||
suite('Tooltip', function() {
|
suite('Tooltip', function() {
|
||||||
test('JS Constructor', function() {
|
test('JS Constructor', function() {
|
||||||
let field = new Blockly.Field('value', null, {
|
const field = new Blockly.Field('value', null, {
|
||||||
tooltip: 'test tooltip',
|
tooltip: 'test tooltip',
|
||||||
});
|
});
|
||||||
chai.assert.equal(field.tooltip_, 'test tooltip');
|
chai.assert.equal(field.tooltip_, 'test tooltip');
|
||||||
});
|
});
|
||||||
test('JS Constructor - Dynamic', function() {
|
test('JS Constructor - Dynamic', function() {
|
||||||
let returnTooltip = function() {
|
const returnTooltip = function() {
|
||||||
return 'dynamic tooltip text';
|
return 'dynamic tooltip text';
|
||||||
};
|
};
|
||||||
let field = new Blockly.Field('value', null, {
|
const field = new Blockly.Field('value', null, {
|
||||||
tooltip: returnTooltip
|
tooltip: returnTooltip
|
||||||
});
|
});
|
||||||
chai.assert.equal(field.tooltip_, returnTooltip);
|
chai.assert.equal(field.tooltip_, returnTooltip);
|
||||||
});
|
});
|
||||||
test('JSON Definition', function() {
|
test('JSON Definition', function() {
|
||||||
let field = CustomField.fromJson({
|
const field = CustomField.fromJson({
|
||||||
tooltip: "test tooltip"
|
tooltip: "test tooltip"
|
||||||
});
|
});
|
||||||
chai.assert.equal(field.tooltip_, 'test tooltip');
|
chai.assert.equal(field.tooltip_, 'test tooltip');
|
||||||
@@ -622,13 +622,13 @@ suite('Abstract Fields', function() {
|
|||||||
Blockly.Msg['TOOLTIP'] = 'test tooltip';
|
Blockly.Msg['TOOLTIP'] = 'test tooltip';
|
||||||
});
|
});
|
||||||
test('JS Constructor', function() {
|
test('JS Constructor', function() {
|
||||||
let field = new Blockly.Field('value', null, {
|
const field = new Blockly.Field('value', null, {
|
||||||
tooltip: '%{BKY_TOOLTIP}',
|
tooltip: '%{BKY_TOOLTIP}',
|
||||||
});
|
});
|
||||||
chai.assert.equal(field.tooltip_, 'test tooltip');
|
chai.assert.equal(field.tooltip_, 'test tooltip');
|
||||||
});
|
});
|
||||||
test('JSON Definition', function() {
|
test('JSON Definition', function() {
|
||||||
let field = CustomField.fromJson({
|
const field = CustomField.fromJson({
|
||||||
tooltip: "%{BKY_TOOLTIP}"
|
tooltip: "%{BKY_TOOLTIP}"
|
||||||
});
|
});
|
||||||
chai.assert.equal(field.tooltip_, 'test tooltip');
|
chai.assert.equal(field.tooltip_, 'test tooltip');
|
||||||
@@ -646,53 +646,53 @@ suite('Abstract Fields', function() {
|
|||||||
addBlockTypeToCleanup(this.sharedCleanup, 'tooltip');
|
addBlockTypeToCleanup(this.sharedCleanup, 'tooltip');
|
||||||
Blockly.Blocks['tooltip'] = {
|
Blockly.Blocks['tooltip'] = {
|
||||||
init: function() {
|
init: function() {
|
||||||
let field = new Blockly.FieldTextInput('default');
|
const field = new Blockly.FieldTextInput('default');
|
||||||
field.setTooltip('tooltip');
|
field.setTooltip('tooltip');
|
||||||
this.appendDummyInput()
|
this.appendDummyInput()
|
||||||
.appendField(field, 'TOOLTIP');
|
.appendField(field, 'TOOLTIP');
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
let block = Blockly.Xml.domToBlock(Blockly.Xml.textToDom(
|
const block = Blockly.Xml.domToBlock(Blockly.Xml.textToDom(
|
||||||
'<xml xmlns="https://developers.google.com/blockly/xml">' +
|
'<xml xmlns="https://developers.google.com/blockly/xml">' +
|
||||||
' <block type="tooltip"></block>' +
|
' <block type="tooltip"></block>' +
|
||||||
'</xml>'
|
'</xml>'
|
||||||
).children[0], this.workspace);
|
).children[0], this.workspace);
|
||||||
let field = block.getField('TOOLTIP');
|
const field = block.getField('TOOLTIP');
|
||||||
chai.assert.equal(field.getClickTarget_().tooltip, 'tooltip');
|
chai.assert.equal(field.getClickTarget_().tooltip, 'tooltip');
|
||||||
});
|
});
|
||||||
test('After Append', function() {
|
test('After Append', function() {
|
||||||
addBlockTypeToCleanup(this.sharedCleanup, 'tooltip');
|
addBlockTypeToCleanup(this.sharedCleanup, 'tooltip');
|
||||||
Blockly.Blocks['tooltip'] = {
|
Blockly.Blocks['tooltip'] = {
|
||||||
init: function() {
|
init: function() {
|
||||||
let field = new Blockly.FieldTextInput('default');
|
const field = new Blockly.FieldTextInput('default');
|
||||||
this.appendDummyInput()
|
this.appendDummyInput()
|
||||||
.appendField(field, 'TOOLTIP');
|
.appendField(field, 'TOOLTIP');
|
||||||
field.setTooltip('tooltip');
|
field.setTooltip('tooltip');
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
let block = Blockly.Xml.domToBlock(Blockly.Xml.textToDom(
|
const block = Blockly.Xml.domToBlock(Blockly.Xml.textToDom(
|
||||||
'<xml xmlns="https://developers.google.com/blockly/xml">' +
|
'<xml xmlns="https://developers.google.com/blockly/xml">' +
|
||||||
' <block type="tooltip"></block>' +
|
' <block type="tooltip"></block>' +
|
||||||
'</xml>'
|
'</xml>'
|
||||||
).children[0], this.workspace);
|
).children[0], this.workspace);
|
||||||
let field = block.getField('TOOLTIP');
|
const field = block.getField('TOOLTIP');
|
||||||
chai.assert.equal(field.getClickTarget_().tooltip, 'tooltip');
|
chai.assert.equal(field.getClickTarget_().tooltip, 'tooltip');
|
||||||
});
|
});
|
||||||
test('After Block Creation', function() {
|
test('After Block Creation', function() {
|
||||||
addBlockTypeToCleanup(this.sharedCleanup, 'tooltip');
|
addBlockTypeToCleanup(this.sharedCleanup, 'tooltip');
|
||||||
Blockly.Blocks['tooltip'] = {
|
Blockly.Blocks['tooltip'] = {
|
||||||
init: function() {
|
init: function() {
|
||||||
let field = new Blockly.FieldTextInput('default');
|
const field = new Blockly.FieldTextInput('default');
|
||||||
this.appendDummyInput()
|
this.appendDummyInput()
|
||||||
.appendField(field, 'TOOLTIP');
|
.appendField(field, 'TOOLTIP');
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
let block = Blockly.Xml.domToBlock(Blockly.Xml.textToDom(
|
const block = Blockly.Xml.domToBlock(Blockly.Xml.textToDom(
|
||||||
'<xml xmlns="https://developers.google.com/blockly/xml">' +
|
'<xml xmlns="https://developers.google.com/blockly/xml">' +
|
||||||
' <block type="tooltip"></block>' +
|
' <block type="tooltip"></block>' +
|
||||||
'</xml>'
|
'</xml>'
|
||||||
).children[0], this.workspace);
|
).children[0], this.workspace);
|
||||||
let field = block.getField('TOOLTIP');
|
const field = block.getField('TOOLTIP');
|
||||||
field.setTooltip('tooltip');
|
field.setTooltip('tooltip');
|
||||||
chai.assert.equal(field.getClickTarget_().tooltip, 'tooltip');
|
chai.assert.equal(field.getClickTarget_().tooltip, 'tooltip');
|
||||||
});
|
});
|
||||||
@@ -700,7 +700,7 @@ suite('Abstract Fields', function() {
|
|||||||
addBlockTypeToCleanup(this.sharedCleanup, 'tooltip');
|
addBlockTypeToCleanup(this.sharedCleanup, 'tooltip');
|
||||||
Blockly.Blocks['tooltip'] = {
|
Blockly.Blocks['tooltip'] = {
|
||||||
init: function() {
|
init: function() {
|
||||||
let field = new Blockly.FieldTextInput('default');
|
const field = new Blockly.FieldTextInput('default');
|
||||||
field.setTooltip(this.tooltipFunc);
|
field.setTooltip(this.tooltipFunc);
|
||||||
this.appendDummyInput()
|
this.appendDummyInput()
|
||||||
.appendField(field, 'TOOLTIP');
|
.appendField(field, 'TOOLTIP');
|
||||||
@@ -710,19 +710,19 @@ suite('Abstract Fields', function() {
|
|||||||
return this.getFieldValue('TOOLTIP');
|
return this.getFieldValue('TOOLTIP');
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
let block = Blockly.Xml.domToBlock(Blockly.Xml.textToDom(
|
const block = Blockly.Xml.domToBlock(Blockly.Xml.textToDom(
|
||||||
'<xml xmlns="https://developers.google.com/blockly/xml">' +
|
'<xml xmlns="https://developers.google.com/blockly/xml">' +
|
||||||
' <block type="tooltip"></block>' +
|
' <block type="tooltip"></block>' +
|
||||||
'</xml>'
|
'</xml>'
|
||||||
).children[0], this.workspace);
|
).children[0], this.workspace);
|
||||||
let field = block.getField('TOOLTIP');
|
const field = block.getField('TOOLTIP');
|
||||||
chai.assert.equal(field.getClickTarget_().tooltip, block.tooltipFunc);
|
chai.assert.equal(field.getClickTarget_().tooltip, block.tooltipFunc);
|
||||||
});
|
});
|
||||||
test('Element', function() {
|
test('Element', function() {
|
||||||
addBlockTypeToCleanup(this.sharedCleanup, 'tooltip');
|
addBlockTypeToCleanup(this.sharedCleanup, 'tooltip');
|
||||||
Blockly.Blocks['tooltip'] = {
|
Blockly.Blocks['tooltip'] = {
|
||||||
init: function() {
|
init: function() {
|
||||||
let field = new Blockly.FieldTextInput('default');
|
const field = new Blockly.FieldTextInput('default');
|
||||||
field.setTooltip(this.element);
|
field.setTooltip(this.element);
|
||||||
this.appendDummyInput()
|
this.appendDummyInput()
|
||||||
.appendField(field, 'TOOLTIP');
|
.appendField(field, 'TOOLTIP');
|
||||||
@@ -731,47 +731,47 @@ suite('Abstract Fields', function() {
|
|||||||
tooltip: 'tooltip'
|
tooltip: 'tooltip'
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
let block = Blockly.Xml.domToBlock(Blockly.Xml.textToDom(
|
const block = Blockly.Xml.domToBlock(Blockly.Xml.textToDom(
|
||||||
'<xml xmlns="https://developers.google.com/blockly/xml">' +
|
'<xml xmlns="https://developers.google.com/blockly/xml">' +
|
||||||
' <block type="tooltip"></block>' +
|
' <block type="tooltip"></block>' +
|
||||||
'</xml>'
|
'</xml>'
|
||||||
).children[0], this.workspace);
|
).children[0], this.workspace);
|
||||||
let field = block.getField('TOOLTIP');
|
const field = block.getField('TOOLTIP');
|
||||||
chai.assert.equal(field.getClickTarget_().tooltip, block.element);
|
chai.assert.equal(field.getClickTarget_().tooltip, block.element);
|
||||||
});
|
});
|
||||||
test('Null', function() {
|
test('Null', function() {
|
||||||
addBlockTypeToCleanup(this.sharedCleanup, 'tooltip');
|
addBlockTypeToCleanup(this.sharedCleanup, 'tooltip');
|
||||||
Blockly.Blocks['tooltip'] = {
|
Blockly.Blocks['tooltip'] = {
|
||||||
init: function() {
|
init: function() {
|
||||||
let field = new Blockly.FieldTextInput('default');
|
const field = new Blockly.FieldTextInput('default');
|
||||||
field.setTooltip(null);
|
field.setTooltip(null);
|
||||||
this.appendDummyInput()
|
this.appendDummyInput()
|
||||||
.appendField(field, 'TOOLTIP');
|
.appendField(field, 'TOOLTIP');
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
let block = Blockly.Xml.domToBlock(Blockly.Xml.textToDom(
|
const block = Blockly.Xml.domToBlock(Blockly.Xml.textToDom(
|
||||||
'<xml xmlns="https://developers.google.com/blockly/xml">' +
|
'<xml xmlns="https://developers.google.com/blockly/xml">' +
|
||||||
' <block type="tooltip"></block>' +
|
' <block type="tooltip"></block>' +
|
||||||
'</xml>'
|
'</xml>'
|
||||||
).children[0], this.workspace);
|
).children[0], this.workspace);
|
||||||
let field = block.getField('TOOLTIP');
|
const field = block.getField('TOOLTIP');
|
||||||
chai.assert.equal(field.getClickTarget_().tooltip, block);
|
chai.assert.equal(field.getClickTarget_().tooltip, block);
|
||||||
});
|
});
|
||||||
test('Undefined', function() {
|
test('Undefined', function() {
|
||||||
addBlockTypeToCleanup(this.sharedCleanup, 'tooltip');
|
addBlockTypeToCleanup(this.sharedCleanup, 'tooltip');
|
||||||
Blockly.Blocks['tooltip'] = {
|
Blockly.Blocks['tooltip'] = {
|
||||||
init: function() {
|
init: function() {
|
||||||
let field = new Blockly.FieldTextInput('default');
|
const field = new Blockly.FieldTextInput('default');
|
||||||
this.appendDummyInput()
|
this.appendDummyInput()
|
||||||
.appendField(field, 'TOOLTIP');
|
.appendField(field, 'TOOLTIP');
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
let block = Blockly.Xml.domToBlock(Blockly.Xml.textToDom(
|
const block = Blockly.Xml.domToBlock(Blockly.Xml.textToDom(
|
||||||
'<xml xmlns="https://developers.google.com/blockly/xml">' +
|
'<xml xmlns="https://developers.google.com/blockly/xml">' +
|
||||||
' <block type="tooltip"></block>' +
|
' <block type="tooltip"></block>' +
|
||||||
'</xml>'
|
'</xml>'
|
||||||
).children[0], this.workspace);
|
).children[0], this.workspace);
|
||||||
let field = block.getField('TOOLTIP');
|
const field = block.getField('TOOLTIP');
|
||||||
chai.assert.equal(field.getClickTarget_().tooltip, block);
|
chai.assert.equal(field.getClickTarget_().tooltip, block);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ suite('Text Input Fields', function() {
|
|||||||
* Configuration for field tests with invalid values.
|
* Configuration for field tests with invalid values.
|
||||||
* @type {!Array<!FieldCreationTestCase>}
|
* @type {!Array<!FieldCreationTestCase>}
|
||||||
*/
|
*/
|
||||||
let invalidValueTestCases = [
|
const invalidValueTestCases = [
|
||||||
{title: 'Undefined', value: undefined},
|
{title: 'Undefined', value: undefined},
|
||||||
{title: 'Null', value: null},
|
{title: 'Null', value: null},
|
||||||
];
|
];
|
||||||
@@ -28,7 +28,7 @@ suite('Text Input Fields', function() {
|
|||||||
* Configuration for field tests with valid values.
|
* Configuration for field tests with valid values.
|
||||||
* @type {!Array<!FieldCreationTestCase>}
|
* @type {!Array<!FieldCreationTestCase>}
|
||||||
*/
|
*/
|
||||||
let validValueTestCases = [
|
const validValueTestCases = [
|
||||||
{title: 'String', value: 'value', expectedValue: 'value'},
|
{title: 'String', value: 'value', expectedValue: 'value'},
|
||||||
{title: 'Boolean true', value: true, expectedValue: 'true'},
|
{title: 'Boolean true', value: true, expectedValue: 'true'},
|
||||||
{title: 'Boolean false', value: false, expectedValue: 'false'},
|
{title: 'Boolean false', value: false, expectedValue: 'false'},
|
||||||
@@ -36,7 +36,7 @@ suite('Text Input Fields', function() {
|
|||||||
{title: 'Number (Falsy)', value: 0, expectedValue: '0'},
|
{title: 'Number (Falsy)', value: 0, expectedValue: '0'},
|
||||||
{title: 'NaN', value: NaN, expectedValue: 'NaN'},
|
{title: 'NaN', value: NaN, expectedValue: 'NaN'},
|
||||||
];
|
];
|
||||||
let addArgsAndJson = function(testCase) {
|
const addArgsAndJson = function(testCase) {
|
||||||
testCase.args = [testCase.value];
|
testCase.args = [testCase.value];
|
||||||
testCase.json = {'text': testCase.value};
|
testCase.json = {'text': testCase.value};
|
||||||
};
|
};
|
||||||
@@ -47,12 +47,12 @@ suite('Text Input Fields', function() {
|
|||||||
* The expected default value for the field being tested.
|
* The expected default value for the field being tested.
|
||||||
* @type {*}
|
* @type {*}
|
||||||
*/
|
*/
|
||||||
let defaultFieldValue = '';
|
const defaultFieldValue = '';
|
||||||
/**
|
/**
|
||||||
* Asserts that the field property values are set to default.
|
* Asserts that the field property values are set to default.
|
||||||
* @param {!Blockly.FieldTextInput} field The field to check.
|
* @param {!Blockly.FieldTextInput} field The field to check.
|
||||||
*/
|
*/
|
||||||
let assertFieldDefault = function(field) {
|
const assertFieldDefault = function(field) {
|
||||||
testHelpers.assertFieldValue(field, defaultFieldValue);
|
testHelpers.assertFieldValue(field, defaultFieldValue);
|
||||||
};
|
};
|
||||||
/**
|
/**
|
||||||
@@ -60,7 +60,7 @@ suite('Text Input Fields', function() {
|
|||||||
* @param {!Blockly.FieldTextInput} field The field to check.
|
* @param {!Blockly.FieldTextInput} field The field to check.
|
||||||
* @param {!FieldValueTestCase} testCase The test case.
|
* @param {!FieldValueTestCase} testCase The test case.
|
||||||
*/
|
*/
|
||||||
let validTestCaseAssertField = function(field, testCase) {
|
const validTestCaseAssertField = function(field, testCase) {
|
||||||
testHelpers.assertFieldValue(field, testCase.expectedValue);
|
testHelpers.assertFieldValue(field, testCase.expectedValue);
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -86,7 +86,7 @@ suite('Text Input Fields', function() {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
suite('Value -> New Value', function() {
|
suite('Value -> New Value', function() {
|
||||||
let initialValue = 'oldValue';
|
const initialValue = 'oldValue';
|
||||||
setup(function() {
|
setup(function() {
|
||||||
this.field = new Blockly.FieldTextInput(initialValue);
|
this.field = new Blockly.FieldTextInput(initialValue);
|
||||||
});
|
});
|
||||||
@@ -111,7 +111,7 @@ suite('Text Input Fields', function() {
|
|||||||
teardown(function() {
|
teardown(function() {
|
||||||
sinon.restore();
|
sinon.restore();
|
||||||
});
|
});
|
||||||
let testSuites = [
|
const testSuites = [
|
||||||
{title: 'Null Validator',
|
{title: 'Null Validator',
|
||||||
validator:
|
validator:
|
||||||
function() {
|
function() {
|
||||||
@@ -151,7 +151,7 @@ suite('Text Input Fields', function() {
|
|||||||
suite('Spellcheck', function() {
|
suite('Spellcheck', function() {
|
||||||
setup(function() {
|
setup(function() {
|
||||||
this.prepField = function(field) {
|
this.prepField = function(field) {
|
||||||
let workspace = {
|
const workspace = {
|
||||||
getScale: function() {
|
getScale: function() {
|
||||||
return 1;
|
return 1;
|
||||||
},
|
},
|
||||||
@@ -190,29 +190,29 @@ suite('Text Input Fields', function() {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
test('Default', function() {
|
test('Default', function() {
|
||||||
let field = new Blockly.FieldTextInput('test');
|
const field = new Blockly.FieldTextInput('test');
|
||||||
this.assertSpellcheck(field, true);
|
this.assertSpellcheck(field, true);
|
||||||
});
|
});
|
||||||
test('JS Constructor', function() {
|
test('JS Constructor', function() {
|
||||||
let field = new Blockly.FieldTextInput('test', null, {
|
const field = new Blockly.FieldTextInput('test', null, {
|
||||||
spellcheck: false
|
spellcheck: false
|
||||||
});
|
});
|
||||||
this.assertSpellcheck(field, false);
|
this.assertSpellcheck(field, false);
|
||||||
});
|
});
|
||||||
test('JSON Definition', function() {
|
test('JSON Definition', function() {
|
||||||
let field = Blockly.FieldTextInput.fromJson({
|
const field = Blockly.FieldTextInput.fromJson({
|
||||||
text: 'test',
|
text: 'test',
|
||||||
spellcheck: false
|
spellcheck: false
|
||||||
});
|
});
|
||||||
this.assertSpellcheck(field, false);
|
this.assertSpellcheck(field, false);
|
||||||
});
|
});
|
||||||
test('setSpellcheck Editor Hidden', function() {
|
test('setSpellcheck Editor Hidden', function() {
|
||||||
let field = new Blockly.FieldTextInput('test');
|
const field = new Blockly.FieldTextInput('test');
|
||||||
field.setSpellcheck(false);
|
field.setSpellcheck(false);
|
||||||
this.assertSpellcheck(field, false);
|
this.assertSpellcheck(field, false);
|
||||||
});
|
});
|
||||||
test('setSpellcheck Editor Shown', function() {
|
test('setSpellcheck Editor Shown', function() {
|
||||||
let field = new Blockly.FieldTextInput('test');
|
const field = new Blockly.FieldTextInput('test');
|
||||||
this.prepField(field);
|
this.prepField(field);
|
||||||
field.showEditor_();
|
field.showEditor_();
|
||||||
field.setSpellcheck(false);
|
field.setSpellcheck(false);
|
||||||
|
|||||||
@@ -10,8 +10,8 @@ const {createGenUidStubWithReturns, createTestBlock, defineRowBlock, sharedTestS
|
|||||||
|
|
||||||
|
|
||||||
suite('Variable Fields', function() {
|
suite('Variable Fields', function() {
|
||||||
let FAKE_VARIABLE_NAME = 'default_name';
|
const FAKE_VARIABLE_NAME = 'default_name';
|
||||||
let FAKE_ID = 'id1';
|
const FAKE_ID = 'id1';
|
||||||
setup(function() {
|
setup(function() {
|
||||||
sharedTestSetup.call(this);
|
sharedTestSetup.call(this);
|
||||||
this.workspace = new Blockly.Workspace();
|
this.workspace = new Blockly.Workspace();
|
||||||
@@ -26,7 +26,7 @@ suite('Variable Fields', function() {
|
|||||||
* Configuration for field creation tests with invalid values.
|
* Configuration for field creation tests with invalid values.
|
||||||
* @type {!Array<!FieldCreationTestCase>}
|
* @type {!Array<!FieldCreationTestCase>}
|
||||||
*/
|
*/
|
||||||
let invalidValueCreationTestCases = [
|
const invalidValueCreationTestCases = [
|
||||||
{title: 'Undefined', value: undefined, args: [undefined]},
|
{title: 'Undefined', value: undefined, args: [undefined]},
|
||||||
{title: 'Null', value: null, args: [null]},
|
{title: 'Null', value: null, args: [null]},
|
||||||
{title: 'Boolean true', value: true, args: [true]},
|
{title: 'Boolean true', value: true, args: [true]},
|
||||||
@@ -39,35 +39,35 @@ suite('Variable Fields', function() {
|
|||||||
* Configuration for field creation tests with valid values.
|
* Configuration for field creation tests with valid values.
|
||||||
* @type {!Array<!FieldCreationTestCase>}
|
* @type {!Array<!FieldCreationTestCase>}
|
||||||
*/
|
*/
|
||||||
let validValueCreationTestCases = [
|
const validValueCreationTestCases = [
|
||||||
{title: 'String', value: 'id2', args: ['name2'],
|
{title: 'String', value: 'id2', args: ['name2'],
|
||||||
expectedValue: 'id2', expectedText: 'name2'},
|
expectedValue: 'id2', expectedText: 'name2'},
|
||||||
];
|
];
|
||||||
let addJson = function(testCase) {
|
const addJson = function(testCase) {
|
||||||
testCase.json = {'variable': testCase.args[0]};
|
testCase.json = {'variable': testCase.args[0]};
|
||||||
};
|
};
|
||||||
invalidValueCreationTestCases.forEach(addJson);
|
invalidValueCreationTestCases.forEach(addJson);
|
||||||
validValueCreationTestCases.forEach(addJson);
|
validValueCreationTestCases.forEach(addJson);
|
||||||
|
|
||||||
let initVariableField = (workspace, fieldVariable) => {
|
const initVariableField = (workspace, fieldVariable) => {
|
||||||
let mockBlock = createTestBlock();
|
const mockBlock = createTestBlock();
|
||||||
mockBlock.workspace = workspace;
|
mockBlock.workspace = workspace;
|
||||||
fieldVariable.setSourceBlock(mockBlock);
|
fieldVariable.setSourceBlock(mockBlock);
|
||||||
|
|
||||||
// No view to initialize, but still need to init the model.
|
// No view to initialize, but still need to init the model.
|
||||||
let genUidStub = createGenUidStubWithReturns(FAKE_ID);
|
const genUidStub = createGenUidStubWithReturns(FAKE_ID);
|
||||||
fieldVariable.initModel();
|
fieldVariable.initModel();
|
||||||
genUidStub.restore();
|
genUidStub.restore();
|
||||||
|
|
||||||
return fieldVariable;
|
return fieldVariable;
|
||||||
};
|
};
|
||||||
let customCreateWithJs = function(testCase) {
|
const customCreateWithJs = function(testCase) {
|
||||||
let fieldVariable = testCase ? new Blockly.FieldVariable(...testCase.args) :
|
const fieldVariable = testCase ? new Blockly.FieldVariable(...testCase.args) :
|
||||||
new Blockly.FieldVariable();
|
new Blockly.FieldVariable();
|
||||||
return initVariableField(this.workspace, fieldVariable);
|
return initVariableField(this.workspace, fieldVariable);
|
||||||
};
|
};
|
||||||
let customCreateWithJson = function(testCase) {
|
const customCreateWithJson = function(testCase) {
|
||||||
let fieldVariable = testCase ?
|
const fieldVariable = testCase ?
|
||||||
Blockly.FieldVariable.fromJson(testCase.json) :
|
Blockly.FieldVariable.fromJson(testCase.json) :
|
||||||
Blockly.FieldVariable.fromJson({});
|
Blockly.FieldVariable.fromJson({});
|
||||||
return initVariableField(this.workspace, fieldVariable);
|
return initVariableField(this.workspace, fieldVariable);
|
||||||
@@ -77,12 +77,12 @@ suite('Variable Fields', function() {
|
|||||||
* The expected default name for the field being tested.
|
* The expected default name for the field being tested.
|
||||||
* @type {*}
|
* @type {*}
|
||||||
*/
|
*/
|
||||||
let defaultFieldName = FAKE_VARIABLE_NAME;
|
const defaultFieldName = FAKE_VARIABLE_NAME;
|
||||||
/**
|
/**
|
||||||
* Asserts that the field property values are set to default.
|
* Asserts that the field property values are set to default.
|
||||||
* @param {!Blockly.FieldVariable} field The field to check.
|
* @param {!Blockly.FieldVariable} field The field to check.
|
||||||
*/
|
*/
|
||||||
let assertFieldDefault = function(field) {
|
const assertFieldDefault = function(field) {
|
||||||
testHelpers.assertFieldValue(field, FAKE_ID, defaultFieldName);
|
testHelpers.assertFieldValue(field, FAKE_ID, defaultFieldName);
|
||||||
};
|
};
|
||||||
/**
|
/**
|
||||||
@@ -90,7 +90,7 @@ suite('Variable Fields', function() {
|
|||||||
* @param {!Blockly.FieldVariable} field The field to check.
|
* @param {!Blockly.FieldVariable} field The field to check.
|
||||||
* @param {!FieldValueTestCase} testCase The test case.
|
* @param {!FieldValueTestCase} testCase The test case.
|
||||||
*/
|
*/
|
||||||
let validTestCaseAssertField = function(field, testCase) {
|
const validTestCaseAssertField = function(field, testCase) {
|
||||||
testHelpers.assertFieldValue(field, FAKE_ID, testCase.expectedText);
|
testHelpers.assertFieldValue(field, FAKE_ID, testCase.expectedText);
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -106,7 +106,7 @@ suite('Variable Fields', function() {
|
|||||||
|
|
||||||
suite('initModel', function() {
|
suite('initModel', function() {
|
||||||
test('No Value Before InitModel', function() {
|
test('No Value Before InitModel', function() {
|
||||||
let fieldVariable = new Blockly.FieldVariable('name1');
|
const fieldVariable = new Blockly.FieldVariable('name1');
|
||||||
chai.assert.equal(fieldVariable.getText(), '');
|
chai.assert.equal(fieldVariable.getText(), '');
|
||||||
chai.assert.isNull(fieldVariable.getValue());
|
chai.assert.isNull(fieldVariable.getValue());
|
||||||
});
|
});
|
||||||
@@ -117,7 +117,7 @@ suite('Variable Fields', function() {
|
|||||||
* Configuration for field tests with invalid values.
|
* Configuration for field tests with invalid values.
|
||||||
* @type {!Array<!FieldCreationTestCase>}
|
* @type {!Array<!FieldCreationTestCase>}
|
||||||
*/
|
*/
|
||||||
let invalidValueTestCases = [
|
const invalidValueTestCases = [
|
||||||
...invalidValueCreationTestCases,
|
...invalidValueCreationTestCases,
|
||||||
{title: 'Variable does not exist', value: 'id3', args: ['name2'],
|
{title: 'Variable does not exist', value: 'id3', args: ['name2'],
|
||||||
expectedValue: 'id2', expectedText: 'name2'},
|
expectedValue: 'id2', expectedText: 'name2'},
|
||||||
@@ -126,7 +126,7 @@ suite('Variable Fields', function() {
|
|||||||
* Configuration for field tests with valid values.
|
* Configuration for field tests with valid values.
|
||||||
* @type {!Array<!FieldCreationTestCase>}
|
* @type {!Array<!FieldCreationTestCase>}
|
||||||
*/
|
*/
|
||||||
let validValueTestCases = [
|
const validValueTestCases = [
|
||||||
{title: 'New variable ID', value: 'id2', args: ['name2'],
|
{title: 'New variable ID', value: 'id2', args: ['name2'],
|
||||||
expectedValue: 'id2', expectedText: 'name2'},
|
expectedValue: 'id2', expectedText: 'name2'},
|
||||||
];
|
];
|
||||||
@@ -154,8 +154,8 @@ suite('Variable Fields', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
suite('Dropdown options', function() {
|
suite('Dropdown options', function() {
|
||||||
let assertDropdownContents = (fieldVariable, expectedVarOptions) => {
|
const assertDropdownContents = (fieldVariable, expectedVarOptions) => {
|
||||||
let dropdownOptions = Blockly.FieldVariable.dropdownCreate.call(
|
const dropdownOptions = Blockly.FieldVariable.dropdownCreate.call(
|
||||||
fieldVariable);
|
fieldVariable);
|
||||||
// Expect variable options, a rename option, and a delete option.
|
// Expect variable options, a rename option, and a delete option.
|
||||||
chai.assert.lengthOf(dropdownOptions, expectedVarOptions.length + 2);
|
chai.assert.lengthOf(dropdownOptions, expectedVarOptions.length + 2);
|
||||||
@@ -172,14 +172,14 @@ suite('Variable Fields', function() {
|
|||||||
this.workspace.createVariable('name1', '', 'id1');
|
this.workspace.createVariable('name1', '', 'id1');
|
||||||
this.workspace.createVariable('name2', '', 'id2');
|
this.workspace.createVariable('name2', '', 'id2');
|
||||||
// Expect that the dropdown options will contain the variables that exist
|
// Expect that the dropdown options will contain the variables that exist
|
||||||
let fieldVariable = initVariableField(
|
const fieldVariable = initVariableField(
|
||||||
this.workspace, new Blockly.FieldVariable('name2'));
|
this.workspace, new Blockly.FieldVariable('name2'));
|
||||||
assertDropdownContents(fieldVariable,
|
assertDropdownContents(fieldVariable,
|
||||||
[['name1', 'id1'], ['name2', 'id2']]);
|
[['name1', 'id1'], ['name2', 'id2']]);
|
||||||
});
|
});
|
||||||
test('Contains variables created after field', function() {
|
test('Contains variables created after field', function() {
|
||||||
// Expect that the dropdown options will contain the variables that exist
|
// Expect that the dropdown options will contain the variables that exist
|
||||||
let fieldVariable = initVariableField(
|
const fieldVariable = initVariableField(
|
||||||
this.workspace, new Blockly.FieldVariable('name1'));
|
this.workspace, new Blockly.FieldVariable('name1'));
|
||||||
// Expect that variables created after field creation will show up too.
|
// Expect that variables created after field creation will show up too.
|
||||||
this.workspace.createVariable('name2', '', 'id2');
|
this.workspace.createVariable('name2', '', 'id2');
|
||||||
@@ -190,7 +190,7 @@ suite('Variable Fields', function() {
|
|||||||
this.workspace.createVariable('name1', '', 'id1');
|
this.workspace.createVariable('name1', '', 'id1');
|
||||||
this.workspace.createVariable('name2', '', 'id2');
|
this.workspace.createVariable('name2', '', 'id2');
|
||||||
// Expect that the dropdown options will contain the variables that exist
|
// Expect that the dropdown options will contain the variables that exist
|
||||||
let fieldVariable = initVariableField(
|
const fieldVariable = initVariableField(
|
||||||
this.workspace, new Blockly.FieldVariable('name1'));
|
this.workspace, new Blockly.FieldVariable('name1'));
|
||||||
// Expect that variables created after field creation will show up too.
|
// Expect that variables created after field creation will show up too.
|
||||||
this.workspace.createVariable('name3', '', 'id3');
|
this.workspace.createVariable('name3', '', 'id3');
|
||||||
@@ -245,13 +245,13 @@ suite('Variable Fields', function() {
|
|||||||
suite('Customizations', function() {
|
suite('Customizations', function() {
|
||||||
suite('Types and Default Types', function() {
|
suite('Types and Default Types', function() {
|
||||||
test('JS Constructor', function() {
|
test('JS Constructor', function() {
|
||||||
let field = new Blockly.FieldVariable(
|
const field = new Blockly.FieldVariable(
|
||||||
'test', undefined, ['Type1'], 'Type1');
|
'test', undefined, ['Type1'], 'Type1');
|
||||||
chai.assert.deepEqual(field.variableTypes, ['Type1']);
|
chai.assert.deepEqual(field.variableTypes, ['Type1']);
|
||||||
chai.assert.equal(field.defaultType_, 'Type1');
|
chai.assert.equal(field.defaultType_, 'Type1');
|
||||||
});
|
});
|
||||||
test('JSON Definition', function() {
|
test('JSON Definition', function() {
|
||||||
let field = Blockly.FieldVariable.fromJson({
|
const field = Blockly.FieldVariable.fromJson({
|
||||||
variable: 'test',
|
variable: 'test',
|
||||||
variableTypes: ['Type1'],
|
variableTypes: ['Type1'],
|
||||||
defaultType: 'Type1'
|
defaultType: 'Type1'
|
||||||
@@ -260,7 +260,7 @@ suite('Variable Fields', function() {
|
|||||||
chai.assert.equal(field.defaultType_, 'Type1');
|
chai.assert.equal(field.defaultType_, 'Type1');
|
||||||
});
|
});
|
||||||
test('JS Configuration - Simple', function() {
|
test('JS Configuration - Simple', function() {
|
||||||
let field = new Blockly.FieldVariable(
|
const field = new Blockly.FieldVariable(
|
||||||
'test', undefined, undefined, undefined, {
|
'test', undefined, undefined, undefined, {
|
||||||
variableTypes: ['Type1'],
|
variableTypes: ['Type1'],
|
||||||
defaultType: 'Type1'
|
defaultType: 'Type1'
|
||||||
@@ -269,7 +269,7 @@ suite('Variable Fields', function() {
|
|||||||
chai.assert.equal(field.defaultType_, 'Type1');
|
chai.assert.equal(field.defaultType_, 'Type1');
|
||||||
});
|
});
|
||||||
test('JS Configuration - Ignore', function() {
|
test('JS Configuration - Ignore', function() {
|
||||||
let field = new Blockly.FieldVariable(
|
const field = new Blockly.FieldVariable(
|
||||||
'test', undefined, ['Type2'], 'Type2', {
|
'test', undefined, ['Type2'], 'Type2', {
|
||||||
variableTypes: ['Type1'],
|
variableTypes: ['Type1'],
|
||||||
defaultType: 'Type1'
|
defaultType: 'Type1'
|
||||||
@@ -287,16 +287,16 @@ suite('Variable Fields', function() {
|
|||||||
test('variableTypes is undefined', function() {
|
test('variableTypes is undefined', function() {
|
||||||
// Expect that since variableTypes is undefined, only type empty string
|
// Expect that since variableTypes is undefined, only type empty string
|
||||||
// will be returned (regardless of what types are available on the workspace).
|
// will be returned (regardless of what types are available on the workspace).
|
||||||
let fieldVariable = new Blockly.FieldVariable('name1');
|
const fieldVariable = new Blockly.FieldVariable('name1');
|
||||||
let resultTypes = fieldVariable.getVariableTypes_();
|
const resultTypes = fieldVariable.getVariableTypes_();
|
||||||
chai.assert.deepEqual(resultTypes, ['']);
|
chai.assert.deepEqual(resultTypes, ['']);
|
||||||
});
|
});
|
||||||
test('variableTypes is explicit', function() {
|
test('variableTypes is explicit', function() {
|
||||||
// Expect that since variableTypes is defined, it will be the return
|
// Expect that since variableTypes is defined, it will be the return
|
||||||
// value, regardless of what types are available on the workspace.
|
// value, regardless of what types are available on the workspace.
|
||||||
let fieldVariable = new Blockly.FieldVariable(
|
const fieldVariable = new Blockly.FieldVariable(
|
||||||
'name1', null, ['type1', 'type2'], 'type1');
|
'name1', null, ['type1', 'type2'], 'type1');
|
||||||
let resultTypes = fieldVariable.getVariableTypes_();
|
const resultTypes = fieldVariable.getVariableTypes_();
|
||||||
chai.assert.deepEqual(resultTypes, ['type1', 'type2']);
|
chai.assert.deepEqual(resultTypes, ['type1', 'type2']);
|
||||||
chai.assert.equal(fieldVariable.defaultType_, 'type1',
|
chai.assert.equal(fieldVariable.defaultType_, 'type1',
|
||||||
'Default type was wrong');
|
'Default type was wrong');
|
||||||
@@ -305,19 +305,19 @@ suite('Variable Fields', function() {
|
|||||||
// Expect all variable types to be returned.
|
// Expect all variable types to be returned.
|
||||||
// The field does not need to be initialized to do this--it just needs
|
// The field does not need to be initialized to do this--it just needs
|
||||||
// a pointer to the workspace.
|
// a pointer to the workspace.
|
||||||
let fieldVariable = new Blockly.FieldVariable('name1');
|
const fieldVariable = new Blockly.FieldVariable('name1');
|
||||||
let mockBlock = createTestBlock();
|
const mockBlock = createTestBlock();
|
||||||
mockBlock.workspace = this.workspace;
|
mockBlock.workspace = this.workspace;
|
||||||
fieldVariable.setSourceBlock(mockBlock);
|
fieldVariable.setSourceBlock(mockBlock);
|
||||||
fieldVariable.variableTypes = null;
|
fieldVariable.variableTypes = null;
|
||||||
|
|
||||||
let resultTypes = fieldVariable.getVariableTypes_();
|
const resultTypes = fieldVariable.getVariableTypes_();
|
||||||
// The empty string is always one of the options.
|
// The empty string is always one of the options.
|
||||||
chai.assert.deepEqual(resultTypes, ['type1', 'type2', '']);
|
chai.assert.deepEqual(resultTypes, ['type1', 'type2', '']);
|
||||||
});
|
});
|
||||||
test('variableTypes is the empty list', function() {
|
test('variableTypes is the empty list', function() {
|
||||||
let fieldVariable = new Blockly.FieldVariable('name1');
|
const fieldVariable = new Blockly.FieldVariable('name1');
|
||||||
let mockBlock = createTestBlock();
|
const mockBlock = createTestBlock();
|
||||||
mockBlock.workspace = this.workspace;
|
mockBlock.workspace = this.workspace;
|
||||||
fieldVariable.setSourceBlock(mockBlock);
|
fieldVariable.setSourceBlock(mockBlock);
|
||||||
fieldVariable.variableTypes = [];
|
fieldVariable.variableTypes = [];
|
||||||
@@ -329,12 +329,12 @@ suite('Variable Fields', function() {
|
|||||||
});
|
});
|
||||||
suite('Default types', function() {
|
suite('Default types', function() {
|
||||||
test('Default type exists', function() {
|
test('Default type exists', function() {
|
||||||
let fieldVariable = new Blockly.FieldVariable(null, null, ['b'], 'b');
|
const fieldVariable = new Blockly.FieldVariable(null, null, ['b'], 'b');
|
||||||
chai.assert.equal(fieldVariable.defaultType_, 'b',
|
chai.assert.equal(fieldVariable.defaultType_, 'b',
|
||||||
'The variable field\'s default type should be "b"');
|
'The variable field\'s default type should be "b"');
|
||||||
});
|
});
|
||||||
test('No default type', function() {
|
test('No default type', function() {
|
||||||
let fieldVariable = new Blockly.FieldVariable(null);
|
const fieldVariable = new Blockly.FieldVariable(null);
|
||||||
chai.assert.equal(fieldVariable.defaultType_, '', 'The variable field\'s default type should be the empty string');
|
chai.assert.equal(fieldVariable.defaultType_, '', 'The variable field\'s default type should be the empty string');
|
||||||
chai.assert.isNull(fieldVariable.variableTypes,
|
chai.assert.isNull(fieldVariable.variableTypes,
|
||||||
'The variable field\'s allowed types should be null');
|
'The variable field\'s allowed types should be null');
|
||||||
@@ -454,7 +454,7 @@ suite('Variable Fields', function() {
|
|||||||
|
|
||||||
test('ID', function() {
|
test('ID', function() {
|
||||||
this.workspace.createVariable('test', '', 'id1');
|
this.workspace.createVariable('test', '', 'id1');
|
||||||
let block = Blockly.serialization.blocks.append({
|
const block = Blockly.serialization.blocks.append({
|
||||||
'type': 'variables_get',
|
'type': 'variables_get',
|
||||||
'fields': {
|
'fields': {
|
||||||
'VAR': {
|
'VAR': {
|
||||||
@@ -463,14 +463,14 @@ suite('Variable Fields', function() {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
this.workspace);
|
this.workspace);
|
||||||
let variable = block.getField('VAR').getVariable();
|
const variable = block.getField('VAR').getVariable();
|
||||||
chai.assert.equal(variable.name, 'test');
|
chai.assert.equal(variable.name, 'test');
|
||||||
chai.assert.equal(variable.type, '');
|
chai.assert.equal(variable.type, '');
|
||||||
chai.assert.equal(variable.getId(), 'id1');
|
chai.assert.equal(variable.getId(), 'id1');
|
||||||
});
|
});
|
||||||
|
|
||||||
test('Name, untyped', function() {
|
test('Name, untyped', function() {
|
||||||
let block = Blockly.serialization.blocks.append({
|
const block = Blockly.serialization.blocks.append({
|
||||||
'type': 'variables_get',
|
'type': 'variables_get',
|
||||||
'fields': {
|
'fields': {
|
||||||
'VAR': {
|
'VAR': {
|
||||||
@@ -479,14 +479,14 @@ suite('Variable Fields', function() {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
this.workspace);
|
this.workspace);
|
||||||
let variable = block.getField('VAR').getVariable();
|
const variable = block.getField('VAR').getVariable();
|
||||||
chai.assert.equal(variable.name, 'test');
|
chai.assert.equal(variable.name, 'test');
|
||||||
chai.assert.equal(variable.type, '');
|
chai.assert.equal(variable.type, '');
|
||||||
chai.assert.equal(variable.getId(), 'id2');
|
chai.assert.equal(variable.getId(), 'id2');
|
||||||
});
|
});
|
||||||
|
|
||||||
test('Name, typed', function() {
|
test('Name, typed', function() {
|
||||||
let block = Blockly.serialization.blocks.append({
|
const block = Blockly.serialization.blocks.append({
|
||||||
'type': 'variables_get',
|
'type': 'variables_get',
|
||||||
'fields': {
|
'fields': {
|
||||||
'VAR': {
|
'VAR': {
|
||||||
@@ -496,7 +496,7 @@ suite('Variable Fields', function() {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
this.workspace);
|
this.workspace);
|
||||||
let variable = block.getField('VAR').getVariable();
|
const variable = block.getField('VAR').getVariable();
|
||||||
chai.assert.equal(variable.name, 'test');
|
chai.assert.equal(variable.name, 'test');
|
||||||
chai.assert.equal(variable.type, 'string');
|
chai.assert.equal(variable.type, 'string');
|
||||||
chai.assert.equal(variable.getId(), 'id2');
|
chai.assert.equal(variable.getId(), 'id2');
|
||||||
|
|||||||
@@ -63,7 +63,7 @@ suite('Flyout', function() {
|
|||||||
});
|
});
|
||||||
suite('toolbox flyout', function() {
|
suite('toolbox flyout', function() {
|
||||||
setup(function() {
|
setup(function() {
|
||||||
let toolbox = document.getElementById('toolbox-categories');
|
const toolbox = document.getElementById('toolbox-categories');
|
||||||
this.workspace = Blockly.inject('blocklyDiv',
|
this.workspace = Blockly.inject('blocklyDiv',
|
||||||
{
|
{
|
||||||
toolbox: toolbox
|
toolbox: toolbox
|
||||||
@@ -170,7 +170,7 @@ suite('Flyout', function() {
|
|||||||
});
|
});
|
||||||
suite('toolbox flyout', function() {
|
suite('toolbox flyout', function() {
|
||||||
setup(function() {
|
setup(function() {
|
||||||
let toolbox = document.getElementById('toolbox-categories');
|
const toolbox = document.getElementById('toolbox-categories');
|
||||||
this.workspace = Blockly.inject('blocklyDiv',
|
this.workspace = Blockly.inject('blocklyDiv',
|
||||||
{
|
{
|
||||||
toolbox: toolbox,
|
toolbox: toolbox,
|
||||||
@@ -247,21 +247,21 @@ suite('Flyout', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
function checkFlyoutInfo(flyoutSpy) {
|
function checkFlyoutInfo(flyoutSpy) {
|
||||||
let flyoutInfo = flyoutSpy.returnValues[0];
|
const flyoutInfo = flyoutSpy.returnValues[0];
|
||||||
let contents = flyoutInfo.contents;
|
const contents = flyoutInfo.contents;
|
||||||
let gaps = flyoutInfo.gaps;
|
const gaps = flyoutInfo.gaps;
|
||||||
|
|
||||||
let expectedGaps = [20, 24, 24];
|
const expectedGaps = [20, 24, 24];
|
||||||
chai.assert.deepEqual(gaps, expectedGaps);
|
chai.assert.deepEqual(gaps, expectedGaps);
|
||||||
|
|
||||||
chai.assert.equal(contents.length, 3, 'Contents');
|
chai.assert.equal(contents.length, 3, 'Contents');
|
||||||
|
|
||||||
chai.assert.equal(contents[0].type, 'block', 'Contents');
|
chai.assert.equal(contents[0].type, 'block', 'Contents');
|
||||||
let block = contents[0]['block'];
|
const block = contents[0]['block'];
|
||||||
chai.assert.instanceOf(block, Blockly.BlockSvg);
|
chai.assert.instanceOf(block, Blockly.BlockSvg);
|
||||||
chai.assert.equal(block.getFieldValue('OP'), 'NEQ');
|
chai.assert.equal(block.getFieldValue('OP'), 'NEQ');
|
||||||
let childA = block.getInputTargetBlock('A');
|
const childA = block.getInputTargetBlock('A');
|
||||||
let childB = block.getInputTargetBlock('B');
|
const childB = block.getInputTargetBlock('B');
|
||||||
chai.assert.isTrue(childA.isShadow());
|
chai.assert.isTrue(childA.isShadow());
|
||||||
chai.assert.isFalse(childB.isShadow());
|
chai.assert.isFalse(childB.isShadow());
|
||||||
chai.assert.equal(childA.getFieldValue('NUM'), 1);
|
chai.assert.equal(childA.getFieldValue('NUM'), 1);
|
||||||
@@ -281,7 +281,7 @@ suite('Flyout', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
test('NodeList', function() {
|
test('NodeList', function() {
|
||||||
let nodeList = document.getElementById('toolbox-simple').childNodes;
|
const nodeList = document.getElementById('toolbox-simple').childNodes;
|
||||||
this.flyout.show(nodeList);
|
this.flyout.show(nodeList);
|
||||||
checkFlyoutInfo(this.createFlyoutSpy);
|
checkFlyoutInfo(this.createFlyoutSpy);
|
||||||
});
|
});
|
||||||
@@ -352,14 +352,14 @@ suite('Flyout', function() {
|
|||||||
this.flyout = this.workspace.getFlyout();
|
this.flyout = this.workspace.getFlyout();
|
||||||
|
|
||||||
this.assertDisabled = function(disabled) {
|
this.assertDisabled = function(disabled) {
|
||||||
let block = this.flyout.getWorkspace().getTopBlocks(false)[0];
|
const block = this.flyout.getWorkspace().getTopBlocks(false)[0];
|
||||||
chai.assert.equal(!block.isEnabled(), disabled);
|
chai.assert.equal(!block.isEnabled(), disabled);
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
suite('XML', function() {
|
suite('XML', function() {
|
||||||
test('True string', function() {
|
test('True string', function() {
|
||||||
let xml = Blockly.Xml.textToDom(
|
const xml = Blockly.Xml.textToDom(
|
||||||
'<xml>' +
|
'<xml>' +
|
||||||
'<block type="text_print" disabled="true"></block>' +
|
'<block type="text_print" disabled="true"></block>' +
|
||||||
'</xml>'
|
'</xml>'
|
||||||
@@ -369,7 +369,7 @@ suite('Flyout', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
test('False string', function() {
|
test('False string', function() {
|
||||||
let xml = Blockly.Xml.textToDom(
|
const xml = Blockly.Xml.textToDom(
|
||||||
'<xml>' +
|
'<xml>' +
|
||||||
'<block type="text_print" disabled="false"></block>' +
|
'<block type="text_print" disabled="false"></block>' +
|
||||||
'</xml>'
|
'</xml>'
|
||||||
@@ -380,7 +380,7 @@ suite('Flyout', function() {
|
|||||||
|
|
||||||
test('Disabled string', function() {
|
test('Disabled string', function() {
|
||||||
// The XML system supports this for some reason!?
|
// The XML system supports this for some reason!?
|
||||||
let xml = Blockly.Xml.textToDom(
|
const xml = Blockly.Xml.textToDom(
|
||||||
'<xml>' +
|
'<xml>' +
|
||||||
'<block type="text_print" disabled="disabled"></block>' +
|
'<block type="text_print" disabled="disabled"></block>' +
|
||||||
'</xml>'
|
'</xml>'
|
||||||
@@ -390,7 +390,7 @@ suite('Flyout', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
test('Different string', function() {
|
test('Different string', function() {
|
||||||
let xml = Blockly.Xml.textToDom(
|
const xml = Blockly.Xml.textToDom(
|
||||||
'<xml>' +
|
'<xml>' +
|
||||||
'<block type="text_print" disabled="random"></block>' +
|
'<block type="text_print" disabled="random"></block>' +
|
||||||
'</xml>'
|
'</xml>'
|
||||||
@@ -402,7 +402,7 @@ suite('Flyout', function() {
|
|||||||
|
|
||||||
suite('JSON', function() {
|
suite('JSON', function() {
|
||||||
test('All undefined', function() {
|
test('All undefined', function() {
|
||||||
let json = [
|
const json = [
|
||||||
{
|
{
|
||||||
'kind': 'block',
|
'kind': 'block',
|
||||||
'type': 'text_print',
|
'type': 'text_print',
|
||||||
@@ -413,7 +413,7 @@ suite('Flyout', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
test('Enabled true', function() {
|
test('Enabled true', function() {
|
||||||
let json = [
|
const json = [
|
||||||
{
|
{
|
||||||
'kind': 'block',
|
'kind': 'block',
|
||||||
'type': 'text_print',
|
'type': 'text_print',
|
||||||
@@ -425,7 +425,7 @@ suite('Flyout', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
test('Enabled false', function() {
|
test('Enabled false', function() {
|
||||||
let json = [
|
const json = [
|
||||||
{
|
{
|
||||||
'kind': 'block',
|
'kind': 'block',
|
||||||
'type': 'text_print',
|
'type': 'text_print',
|
||||||
@@ -437,7 +437,7 @@ suite('Flyout', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
test('Disabled true string', function() {
|
test('Disabled true string', function() {
|
||||||
let json = [
|
const json = [
|
||||||
{
|
{
|
||||||
'kind': 'block',
|
'kind': 'block',
|
||||||
'type': 'text_print',
|
'type': 'text_print',
|
||||||
@@ -449,7 +449,7 @@ suite('Flyout', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
test('Disabled false string', function() {
|
test('Disabled false string', function() {
|
||||||
let json = [
|
const json = [
|
||||||
{
|
{
|
||||||
'kind': 'block',
|
'kind': 'block',
|
||||||
'type': 'text_print',
|
'type': 'text_print',
|
||||||
@@ -461,7 +461,7 @@ suite('Flyout', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
test('Disabled string', function() {
|
test('Disabled string', function() {
|
||||||
let json = [
|
const json = [
|
||||||
{
|
{
|
||||||
'kind': 'block',
|
'kind': 'block',
|
||||||
'type': 'text_print',
|
'type': 'text_print',
|
||||||
@@ -473,7 +473,7 @@ suite('Flyout', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
test('Disabled true value', function() {
|
test('Disabled true value', function() {
|
||||||
let json = [
|
const json = [
|
||||||
{
|
{
|
||||||
'kind': 'block',
|
'kind': 'block',
|
||||||
'type': 'text_print',
|
'type': 'text_print',
|
||||||
@@ -485,7 +485,7 @@ suite('Flyout', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
test('Disabled false value', function() {
|
test('Disabled false value', function() {
|
||||||
let json = [
|
const json = [
|
||||||
{
|
{
|
||||||
'kind': 'block',
|
'kind': 'block',
|
||||||
'type': 'text_print',
|
'type': 'text_print',
|
||||||
@@ -497,7 +497,7 @@ suite('Flyout', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
test('Disabled different string', function() {
|
test('Disabled different string', function() {
|
||||||
let json = [
|
const json = [
|
||||||
{
|
{
|
||||||
'kind': 'block',
|
'kind': 'block',
|
||||||
'type': 'text_print',
|
'type': 'text_print',
|
||||||
@@ -509,7 +509,7 @@ suite('Flyout', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
test('Disabled empty string', function() {
|
test('Disabled empty string', function() {
|
||||||
let json = [
|
const json = [
|
||||||
{
|
{
|
||||||
'kind': 'block',
|
'kind': 'block',
|
||||||
'type': 'text_print',
|
'type': 'text_print',
|
||||||
|
|||||||
@@ -66,8 +66,8 @@ suite('Generator', function() {
|
|||||||
"output": null,
|
"output": null,
|
||||||
"nextStatement": null
|
"nextStatement": null
|
||||||
}]);
|
}]);
|
||||||
let rowBlock = this.workspace.newBlock('row_block');
|
const rowBlock = this.workspace.newBlock('row_block');
|
||||||
let stackBlock = this.workspace.newBlock('stack_block');
|
const stackBlock = this.workspace.newBlock('stack_block');
|
||||||
|
|
||||||
this.blockToCodeTest = function(
|
this.blockToCodeTest = function(
|
||||||
generator, blockDisabled, opt_thisOnly,
|
generator, blockDisabled, opt_thisOnly,
|
||||||
@@ -77,12 +77,12 @@ suite('Generator', function() {
|
|||||||
rowBlock.nextConnection.connect(stackBlock.previousConnection);
|
rowBlock.nextConnection.connect(stackBlock.previousConnection);
|
||||||
rowBlock.disabled = blockDisabled;
|
rowBlock.disabled = blockDisabled;
|
||||||
|
|
||||||
let code = generator.blockToCode(rowBlock, opt_thisOnly);
|
const code = generator.blockToCode(rowBlock, opt_thisOnly);
|
||||||
chai.assert.equal(code, expectedCode, opt_message);
|
chai.assert.equal(code, expectedCode, opt_message);
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
let testCase = [
|
const testCase = [
|
||||||
[Blockly.Dart, 'Dart'],
|
[Blockly.Dart, 'Dart'],
|
||||||
[Blockly.JavaScript, 'JavaScript'],
|
[Blockly.JavaScript, 'JavaScript'],
|
||||||
[Blockly.Lua, 'Lua'],
|
[Blockly.Lua, 'Lua'],
|
||||||
@@ -91,8 +91,8 @@ suite('Generator', function() {
|
|||||||
|
|
||||||
suite('Trivial', function() {
|
suite('Trivial', function() {
|
||||||
testCase.forEach(function(testCase) {
|
testCase.forEach(function(testCase) {
|
||||||
let generator = testCase[0];
|
const generator = testCase[0];
|
||||||
let name = testCase[1];
|
const name = testCase[1];
|
||||||
test(name, function() {
|
test(name, function() {
|
||||||
generator.init(this.workspace);
|
generator.init(this.workspace);
|
||||||
this.blockToCodeTest(generator, false, true, 'row_block');
|
this.blockToCodeTest(generator, false, true, 'row_block');
|
||||||
@@ -104,8 +104,8 @@ suite('Generator', function() {
|
|||||||
|
|
||||||
suite('Disabled block', function() {
|
suite('Disabled block', function() {
|
||||||
testCase.forEach(function(testCase) {
|
testCase.forEach(function(testCase) {
|
||||||
let generator = testCase[0];
|
const generator = testCase[0];
|
||||||
let name = testCase[1];
|
const name = testCase[1];
|
||||||
test(name, function() {
|
test(name, function() {
|
||||||
this.blockToCodeTest(generator, true, true, '');
|
this.blockToCodeTest(generator, true, true, '');
|
||||||
this.blockToCodeTest(generator, true, false, 'stack_block', 'thisOnly=false');
|
this.blockToCodeTest(generator, true, false, 'stack_block', 'thisOnly=false');
|
||||||
@@ -126,9 +126,9 @@ suite('Generator', function() {
|
|||||||
"previousStatement": null,
|
"previousStatement": null,
|
||||||
"nextStatement": null
|
"nextStatement": null
|
||||||
}]);
|
}]);
|
||||||
let blockA = this.workspace.newBlock('test_loop_block');
|
const blockA = this.workspace.newBlock('test_loop_block');
|
||||||
let blockB = this.workspace.newBlock('test_loop_block');
|
const blockB = this.workspace.newBlock('test_loop_block');
|
||||||
let blockC = this.workspace.newBlock('test_loop_block');
|
const blockC = this.workspace.newBlock('test_loop_block');
|
||||||
this.loopTest = function(
|
this.loopTest = function(
|
||||||
generator, opt_thisOnly, expectedCode, opt_message) {
|
generator, opt_thisOnly, expectedCode, opt_message) {
|
||||||
generator.test_loop_block = function(block){
|
generator.test_loop_block = function(block){
|
||||||
@@ -137,14 +137,14 @@ suite('Generator', function() {
|
|||||||
blockA.getInput('DO').connection.connect(blockB.previousConnection);
|
blockA.getInput('DO').connection.connect(blockB.previousConnection);
|
||||||
blockA.nextConnection.connect(blockC.previousConnection);
|
blockA.nextConnection.connect(blockC.previousConnection);
|
||||||
|
|
||||||
let code = generator.blockToCode(blockA, opt_thisOnly);
|
const code = generator.blockToCode(blockA, opt_thisOnly);
|
||||||
chai.assert.equal(code, expectedCode, opt_message);
|
chai.assert.equal(code, expectedCode, opt_message);
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
testCase.forEach(function(testCase) {
|
testCase.forEach(function(testCase) {
|
||||||
let generator = testCase[0];
|
const generator = testCase[0];
|
||||||
let name = testCase[1];
|
const name = testCase[1];
|
||||||
test(name, function() {
|
test(name, function() {
|
||||||
this.loopTest(generator, true, '{ {}}');
|
this.loopTest(generator, true, '{ {}}');
|
||||||
this.loopTest(generator, false, '{ {}}{}', 'thisOnly=false');
|
this.loopTest(generator, false, '{ {}}{}', 'thisOnly=false');
|
||||||
|
|||||||
@@ -11,20 +11,20 @@ const {assertEventFired, assertEventNotFired, defineBasicBlockWithField, dispatc
|
|||||||
|
|
||||||
suite('Gesture', function() {
|
suite('Gesture', function() {
|
||||||
function testGestureIsFieldClick(block, isFieldClick, eventsFireStub){
|
function testGestureIsFieldClick(block, isFieldClick, eventsFireStub){
|
||||||
let field = block.getField('NAME');
|
const field = block.getField('NAME');
|
||||||
let eventTarget = field.getClickTarget_();
|
const eventTarget = field.getClickTarget_();
|
||||||
chai.assert.exists(eventTarget,
|
chai.assert.exists(eventTarget,
|
||||||
'Precondition: missing click target for field');
|
'Precondition: missing click target for field');
|
||||||
|
|
||||||
eventsFireStub.resetHistory();
|
eventsFireStub.resetHistory();
|
||||||
dispatchPointerEvent(eventTarget, 'pointerdown');
|
dispatchPointerEvent(eventTarget, 'pointerdown');
|
||||||
|
|
||||||
let fieldWorkspace = field.sourceBlock_.workspace;
|
const fieldWorkspace = field.sourceBlock_.workspace;
|
||||||
// Gestures triggered on flyouts are stored on targetWorkspace.
|
// Gestures triggered on flyouts are stored on targetWorkspace.
|
||||||
let gestureWorkspace = fieldWorkspace.targetWorkspace || fieldWorkspace;
|
const gestureWorkspace = fieldWorkspace.targetWorkspace || fieldWorkspace;
|
||||||
let gesture = gestureWorkspace.currentGesture_;
|
const gesture = gestureWorkspace.currentGesture_;
|
||||||
chai.assert.exists(gesture, 'Gesture exists after pointerdown.');
|
chai.assert.exists(gesture, 'Gesture exists after pointerdown.');
|
||||||
let isFieldClickSpy = sinon.spy(gesture, 'isFieldClick_');
|
const isFieldClickSpy = sinon.spy(gesture, 'isFieldClick_');
|
||||||
|
|
||||||
dispatchPointerEvent(eventTarget, 'pointerup');
|
dispatchPointerEvent(eventTarget, 'pointerup');
|
||||||
dispatchPointerEvent(eventTarget, 'click');
|
dispatchPointerEvent(eventTarget, 'click');
|
||||||
@@ -45,7 +45,7 @@ suite('Gesture', function() {
|
|||||||
setup(function() {
|
setup(function() {
|
||||||
sharedTestSetup.call(this);
|
sharedTestSetup.call(this);
|
||||||
defineBasicBlockWithField();
|
defineBasicBlockWithField();
|
||||||
let toolbox = document.getElementById('gesture-test-toolbox');
|
const toolbox = document.getElementById('gesture-test-toolbox');
|
||||||
this.workspace = Blockly.inject('blocklyDiv', {toolbox: toolbox});
|
this.workspace = Blockly.inject('blocklyDiv', {toolbox: toolbox});
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -54,14 +54,14 @@ suite('Gesture', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
test('Constructor', function() {
|
test('Constructor', function() {
|
||||||
let e = { id: 'dummy_test_event'};
|
const e = { id: 'dummy_test_event'};
|
||||||
let gesture = new Blockly.Gesture(e, this.workspace);
|
const gesture = new Blockly.Gesture(e, this.workspace);
|
||||||
chai.assert.equal(gesture.mostRecentEvent_, e);
|
chai.assert.equal(gesture.mostRecentEvent_, e);
|
||||||
chai.assert.equal(gesture.creatorWorkspace_, this.workspace);
|
chai.assert.equal(gesture.creatorWorkspace_, this.workspace);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('Field click - Click in workspace', function() {
|
test('Field click - Click in workspace', function() {
|
||||||
let block = this.workspace.newBlock('test_field_block');
|
const block = this.workspace.newBlock('test_field_block');
|
||||||
block.initSvg();
|
block.initSvg();
|
||||||
block.render();
|
block.render();
|
||||||
|
|
||||||
@@ -69,22 +69,22 @@ suite('Gesture', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
test('Field click - Auto close flyout', function() {
|
test('Field click - Auto close flyout', function() {
|
||||||
let flyout = this.workspace.flyout_;
|
const flyout = this.workspace.flyout_;
|
||||||
chai.assert.exists(this.workspace.flyout_,
|
chai.assert.exists(this.workspace.flyout_,
|
||||||
'Precondition: missing flyout');
|
'Precondition: missing flyout');
|
||||||
flyout.autoClose = true;
|
flyout.autoClose = true;
|
||||||
|
|
||||||
let block = getTopFlyoutBlock(flyout);
|
const block = getTopFlyoutBlock(flyout);
|
||||||
testGestureIsFieldClick(block, false, this.eventsFireStub);
|
testGestureIsFieldClick(block, false, this.eventsFireStub);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('Field click - Always open flyout', function() {
|
test('Field click - Always open flyout', function() {
|
||||||
let flyout = this.workspace.flyout_;
|
const flyout = this.workspace.flyout_;
|
||||||
chai.assert.exists(this.workspace.flyout_,
|
chai.assert.exists(this.workspace.flyout_,
|
||||||
'Precondition: missing flyout');
|
'Precondition: missing flyout');
|
||||||
flyout.autoClose = false;
|
flyout.autoClose = false;
|
||||||
|
|
||||||
let block = getTopFlyoutBlock(flyout);
|
const block = getTopFlyoutBlock(flyout);
|
||||||
testGestureIsFieldClick(block, true, this.eventsFireStub);
|
testGestureIsFieldClick(block, true, this.eventsFireStub);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -39,13 +39,13 @@ suite('Inputs', function() {
|
|||||||
suite('Insert Field At', function() {
|
suite('Insert Field At', function() {
|
||||||
suite('Index Bounds', function() {
|
suite('Index Bounds', function() {
|
||||||
test('< 0', function() {
|
test('< 0', function() {
|
||||||
let field = new Blockly.FieldLabel('field');
|
const field = new Blockly.FieldLabel('field');
|
||||||
chai.assert.throws(function() {
|
chai.assert.throws(function() {
|
||||||
this.dummy.insertFieldAt(-1, field);
|
this.dummy.insertFieldAt(-1, field);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
test('> length', function() {
|
test('> length', function() {
|
||||||
let field = new Blockly.FieldLabel('field');
|
const field = new Blockly.FieldLabel('field');
|
||||||
chai.assert.throws(function() {
|
chai.assert.throws(function() {
|
||||||
this.dummy.insertFieldAt(1, field);
|
this.dummy.insertFieldAt(1, field);
|
||||||
});
|
});
|
||||||
@@ -54,7 +54,7 @@ suite('Inputs', function() {
|
|||||||
suite('Values', function() {
|
suite('Values', function() {
|
||||||
// We're mostly just testing that it doesn't throw errors.
|
// We're mostly just testing that it doesn't throw errors.
|
||||||
test('Field', function() {
|
test('Field', function() {
|
||||||
let field = new Blockly.FieldLabel('field');
|
const field = new Blockly.FieldLabel('field');
|
||||||
this.dummy.insertFieldAt(0, field);
|
this.dummy.insertFieldAt(0, field);
|
||||||
chai.assert.equal(this.dummy.fieldRow[0], field);
|
chai.assert.equal(this.dummy.fieldRow[0], field);
|
||||||
});
|
});
|
||||||
@@ -91,25 +91,25 @@ suite('Inputs', function() {
|
|||||||
});
|
});
|
||||||
suite('Prefixes and Suffixes', function() {
|
suite('Prefixes and Suffixes', function() {
|
||||||
test('Prefix', function() {
|
test('Prefix', function() {
|
||||||
let field = new Blockly.FieldLabel('field');
|
const field = new Blockly.FieldLabel('field');
|
||||||
let prefix = new Blockly.FieldLabel('prefix');
|
const prefix = new Blockly.FieldLabel('prefix');
|
||||||
field.prefixField = prefix;
|
field.prefixField = prefix;
|
||||||
|
|
||||||
this.dummy.appendField(field);
|
this.dummy.appendField(field);
|
||||||
chai.assert.deepEqual(this.dummy.fieldRow, [prefix, field]);
|
chai.assert.deepEqual(this.dummy.fieldRow, [prefix, field]);
|
||||||
});
|
});
|
||||||
test('Suffix', function() {
|
test('Suffix', function() {
|
||||||
let field = new Blockly.FieldLabel('field');
|
const field = new Blockly.FieldLabel('field');
|
||||||
let suffix = new Blockly.FieldLabel('suffix');
|
const suffix = new Blockly.FieldLabel('suffix');
|
||||||
field.suffixField = suffix;
|
field.suffixField = suffix;
|
||||||
|
|
||||||
this.dummy.appendField(field);
|
this.dummy.appendField(field);
|
||||||
chai.assert.deepEqual(this.dummy.fieldRow, [field, suffix]);
|
chai.assert.deepEqual(this.dummy.fieldRow, [field, suffix]);
|
||||||
});
|
});
|
||||||
test('Prefix and Suffix', function() {
|
test('Prefix and Suffix', function() {
|
||||||
let field = new Blockly.FieldLabel('field');
|
const field = new Blockly.FieldLabel('field');
|
||||||
let prefix = new Blockly.FieldLabel('prefix');
|
const prefix = new Blockly.FieldLabel('prefix');
|
||||||
let suffix = new Blockly.FieldLabel('suffix');
|
const suffix = new Blockly.FieldLabel('suffix');
|
||||||
field.prefixField = prefix;
|
field.prefixField = prefix;
|
||||||
field.suffixField = suffix;
|
field.suffixField = suffix;
|
||||||
|
|
||||||
@@ -117,7 +117,7 @@ suite('Inputs', function() {
|
|||||||
chai.assert.deepEqual(this.dummy.fieldRow, [prefix, field, suffix]);
|
chai.assert.deepEqual(this.dummy.fieldRow, [prefix, field, suffix]);
|
||||||
});
|
});
|
||||||
test('Dropdown - Prefix', function() {
|
test('Dropdown - Prefix', function() {
|
||||||
let field = new Blockly.FieldDropdown(
|
const field = new Blockly.FieldDropdown(
|
||||||
[
|
[
|
||||||
['prefix option1', 'OPTION1'],
|
['prefix option1', 'OPTION1'],
|
||||||
['prefix option2', 'OPTION2']
|
['prefix option2', 'OPTION2']
|
||||||
@@ -128,7 +128,7 @@ suite('Inputs', function() {
|
|||||||
chai.assert.equal(this.dummy.fieldRow.length, 2);
|
chai.assert.equal(this.dummy.fieldRow.length, 2);
|
||||||
});
|
});
|
||||||
test('Dropdown - Suffix', function() {
|
test('Dropdown - Suffix', function() {
|
||||||
let field = new Blockly.FieldDropdown(
|
const field = new Blockly.FieldDropdown(
|
||||||
[
|
[
|
||||||
['option1 suffix', 'OPTION1'],
|
['option1 suffix', 'OPTION1'],
|
||||||
['option2 suffix', 'OPTION2']
|
['option2 suffix', 'OPTION2']
|
||||||
@@ -139,7 +139,7 @@ suite('Inputs', function() {
|
|||||||
chai.assert.equal(this.dummy.fieldRow.length, 2);
|
chai.assert.equal(this.dummy.fieldRow.length, 2);
|
||||||
});
|
});
|
||||||
test('Dropdown - Prefix and Suffix', function() {
|
test('Dropdown - Prefix and Suffix', function() {
|
||||||
let field = new Blockly.FieldDropdown(
|
const field = new Blockly.FieldDropdown(
|
||||||
[
|
[
|
||||||
['prefix option1 suffix', 'OPTION1'],
|
['prefix option1 suffix', 'OPTION1'],
|
||||||
['prefix option2 suffix', 'OPTION2']
|
['prefix option2 suffix', 'OPTION2']
|
||||||
@@ -152,9 +152,9 @@ suite('Inputs', function() {
|
|||||||
});
|
});
|
||||||
suite('Field Initialization', function() {
|
suite('Field Initialization', function() {
|
||||||
test('Rendered', function() {
|
test('Rendered', function() {
|
||||||
let field = new Blockly.FieldLabel('field');
|
const field = new Blockly.FieldLabel('field');
|
||||||
let setBlockSpy = sinon.spy(field, 'setSourceBlock');
|
const setBlockSpy = sinon.spy(field, 'setSourceBlock');
|
||||||
let initSpy = sinon.spy(field, 'init');
|
const initSpy = sinon.spy(field, 'init');
|
||||||
|
|
||||||
this.dummy.insertFieldAt(0, field);
|
this.dummy.insertFieldAt(0, field);
|
||||||
sinon.assert.calledOnce(setBlockSpy);
|
sinon.assert.calledOnce(setBlockSpy);
|
||||||
@@ -169,9 +169,9 @@ suite('Inputs', function() {
|
|||||||
// TODO: InsertFieldAt does not properly handle initialization in
|
// TODO: InsertFieldAt does not properly handle initialization in
|
||||||
// headless mode.
|
// headless mode.
|
||||||
test.skip('Headless', function() {
|
test.skip('Headless', function() {
|
||||||
let field = new Blockly.FieldLabel('field');
|
const field = new Blockly.FieldLabel('field');
|
||||||
let setBlockSpy = sinon.spy(field, 'setSourceBlock');
|
const setBlockSpy = sinon.spy(field, 'setSourceBlock');
|
||||||
let initModelSpy = sinon.spy(field, 'initModel');
|
const initModelSpy = sinon.spy(field, 'initModel');
|
||||||
|
|
||||||
this.block.rendered = false;
|
this.block.rendered = false;
|
||||||
|
|
||||||
@@ -194,8 +194,8 @@ suite('Inputs', function() {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
test('Rendered', function() {
|
test('Rendered', function() {
|
||||||
let field = new Blockly.FieldLabel('field');
|
const field = new Blockly.FieldLabel('field');
|
||||||
let disposeSpy = sinon.spy(field, 'dispose');
|
const disposeSpy = sinon.spy(field, 'dispose');
|
||||||
this.dummy.appendField(field, 'FIELD');
|
this.dummy.appendField(field, 'FIELD');
|
||||||
|
|
||||||
this.renderStub.resetHistory();
|
this.renderStub.resetHistory();
|
||||||
@@ -207,8 +207,8 @@ suite('Inputs', function() {
|
|||||||
sinon.assert.calledOnce(this.bumpNeighboursStub);
|
sinon.assert.calledOnce(this.bumpNeighboursStub);
|
||||||
});
|
});
|
||||||
test('Headless', function() {
|
test('Headless', function() {
|
||||||
let field = new Blockly.FieldLabel('field');
|
const field = new Blockly.FieldLabel('field');
|
||||||
let disposeSpy = sinon.spy(field, 'dispose');
|
const disposeSpy = sinon.spy(field, 'dispose');
|
||||||
this.dummy.appendField(field, 'FIELD');
|
this.dummy.appendField(field, 'FIELD');
|
||||||
|
|
||||||
this.renderStub.resetHistory();
|
this.renderStub.resetHistory();
|
||||||
|
|||||||
@@ -53,9 +53,9 @@ suite('InsertionMarkers', function() {
|
|||||||
return 'stack[' + block.id + '];\n';
|
return 'stack[' + block.id + '];\n';
|
||||||
};
|
};
|
||||||
Blockly.JavaScript['row_block'] = function(block) {
|
Blockly.JavaScript['row_block'] = function(block) {
|
||||||
let value = Blockly.JavaScript
|
const value = Blockly.JavaScript
|
||||||
.valueToCode(block, 'INPUT', Blockly.JavaScript.ORDER_NONE);
|
.valueToCode(block, 'INPUT', Blockly.JavaScript.ORDER_NONE);
|
||||||
let code = 'row[' + block.id + '](' + value + ')';
|
const code = 'row[' + block.id + '](' + value + ')';
|
||||||
return [code, Blockly.JavaScript.ORDER_NONE];
|
return [code, Blockly.JavaScript.ORDER_NONE];
|
||||||
};
|
};
|
||||||
Blockly.JavaScript['statement_block'] = function(block) {
|
Blockly.JavaScript['statement_block'] = function(block) {
|
||||||
@@ -65,9 +65,9 @@ suite('InsertionMarkers', function() {
|
|||||||
|
|
||||||
this.assertGen = function(xml, expectedCode) {
|
this.assertGen = function(xml, expectedCode) {
|
||||||
Blockly.Xml.domToWorkspace(xml, this.workspace);
|
Blockly.Xml.domToWorkspace(xml, this.workspace);
|
||||||
let block = this.workspace.getBlockById('insertion');
|
const block = this.workspace.getBlockById('insertion');
|
||||||
block.isInsertionMarker_ = true;
|
block.isInsertionMarker_ = true;
|
||||||
let code = Blockly.JavaScript.workspaceToCode(this.workspace);
|
const code = Blockly.JavaScript.workspaceToCode(this.workspace);
|
||||||
chai.assert.equal(code, expectedCode);
|
chai.assert.equal(code, expectedCode);
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
@@ -77,7 +77,7 @@ suite('InsertionMarkers', function() {
|
|||||||
delete Blockly.JavaScript['statement_block'];
|
delete Blockly.JavaScript['statement_block'];
|
||||||
});
|
});
|
||||||
test('Marker Surrounds', function() {
|
test('Marker Surrounds', function() {
|
||||||
let xml = Blockly.Xml.textToDom(
|
const xml = Blockly.Xml.textToDom(
|
||||||
'<xml xmlns="https://developers.google.com/blockly/xml">' +
|
'<xml xmlns="https://developers.google.com/blockly/xml">' +
|
||||||
' <block type="statement_block" id="insertion">' +
|
' <block type="statement_block" id="insertion">' +
|
||||||
' <statement name="STATEMENT">' +
|
' <statement name="STATEMENT">' +
|
||||||
@@ -88,7 +88,7 @@ suite('InsertionMarkers', function() {
|
|||||||
this.assertGen(xml, 'statement[a]{\n};\n');
|
this.assertGen(xml, 'statement[a]{\n};\n');
|
||||||
});
|
});
|
||||||
test('Marker Enclosed', function() {
|
test('Marker Enclosed', function() {
|
||||||
let xml = Blockly.Xml.textToDom(
|
const xml = Blockly.Xml.textToDom(
|
||||||
'<xml xmlns="https://developers.google.com/blockly/xml">' +
|
'<xml xmlns="https://developers.google.com/blockly/xml">' +
|
||||||
' <block type="statement_block" id="a">' +
|
' <block type="statement_block" id="a">' +
|
||||||
' <statement name="STATEMENT">' +
|
' <statement name="STATEMENT">' +
|
||||||
@@ -99,7 +99,7 @@ suite('InsertionMarkers', function() {
|
|||||||
this.assertGen(xml, 'statement[a]{\n};\n');
|
this.assertGen(xml, 'statement[a]{\n};\n');
|
||||||
});
|
});
|
||||||
test('Marker Enclosed and Surrounds', function() {
|
test('Marker Enclosed and Surrounds', function() {
|
||||||
let xml = Blockly.Xml.textToDom(
|
const xml = Blockly.Xml.textToDom(
|
||||||
'<xml xmlns="https://developers.google.com/blockly/xml">' +
|
'<xml xmlns="https://developers.google.com/blockly/xml">' +
|
||||||
' <block type="statement_block" id="a">' +
|
' <block type="statement_block" id="a">' +
|
||||||
' <statement name="STATEMENT">' +
|
' <statement name="STATEMENT">' +
|
||||||
@@ -118,7 +118,7 @@ suite('InsertionMarkers', function() {
|
|||||||
'};\n');
|
'};\n');
|
||||||
});
|
});
|
||||||
test('Marker Prev', function() {
|
test('Marker Prev', function() {
|
||||||
let xml = Blockly.Xml.textToDom(
|
const xml = Blockly.Xml.textToDom(
|
||||||
'<xml xmlns="https://developers.google.com/blockly/xml">' +
|
'<xml xmlns="https://developers.google.com/blockly/xml">' +
|
||||||
' <block type="stack_block" id="insertion">' +
|
' <block type="stack_block" id="insertion">' +
|
||||||
' <next>' +
|
' <next>' +
|
||||||
@@ -129,7 +129,7 @@ suite('InsertionMarkers', function() {
|
|||||||
this.assertGen(xml, 'stack[a];\n');
|
this.assertGen(xml, 'stack[a];\n');
|
||||||
});
|
});
|
||||||
test('Marker Next', function() {
|
test('Marker Next', function() {
|
||||||
let xml = Blockly.Xml.textToDom(
|
const xml = Blockly.Xml.textToDom(
|
||||||
'<xml xmlns="https://developers.google.com/blockly/xml">' +
|
'<xml xmlns="https://developers.google.com/blockly/xml">' +
|
||||||
' <block type="stack_block" id="a">' +
|
' <block type="stack_block" id="a">' +
|
||||||
' <next>' +
|
' <next>' +
|
||||||
@@ -140,7 +140,7 @@ suite('InsertionMarkers', function() {
|
|||||||
this.assertGen(xml, 'stack[a];\n');
|
this.assertGen(xml, 'stack[a];\n');
|
||||||
});
|
});
|
||||||
test('Marker Middle of Stack', function() {
|
test('Marker Middle of Stack', function() {
|
||||||
let xml = Blockly.Xml.textToDom(
|
const xml = Blockly.Xml.textToDom(
|
||||||
'<xml xmlns="https://developers.google.com/blockly/xml">' +
|
'<xml xmlns="https://developers.google.com/blockly/xml">' +
|
||||||
' <block type="stack_block" id="a">' +
|
' <block type="stack_block" id="a">' +
|
||||||
' <next>' +
|
' <next>' +
|
||||||
@@ -157,7 +157,7 @@ suite('InsertionMarkers', function() {
|
|||||||
'stack[b];\n');
|
'stack[b];\n');
|
||||||
});
|
});
|
||||||
test('Marker On Output', function() {
|
test('Marker On Output', function() {
|
||||||
let xml = Blockly.Xml.textToDom(
|
const xml = Blockly.Xml.textToDom(
|
||||||
'<xml xmlns="https://developers.google.com/blockly/xml">' +
|
'<xml xmlns="https://developers.google.com/blockly/xml">' +
|
||||||
' <block type="row_block" id="insertion">' +
|
' <block type="row_block" id="insertion">' +
|
||||||
' <value name="INPUT">' +
|
' <value name="INPUT">' +
|
||||||
@@ -168,7 +168,7 @@ suite('InsertionMarkers', function() {
|
|||||||
this.assertGen(xml, 'row[a]();\n');
|
this.assertGen(xml, 'row[a]();\n');
|
||||||
});
|
});
|
||||||
test('Marker On Input', function() {
|
test('Marker On Input', function() {
|
||||||
let xml = Blockly.Xml.textToDom(
|
const xml = Blockly.Xml.textToDom(
|
||||||
'<xml xmlns="https://developers.google.com/blockly/xml">' +
|
'<xml xmlns="https://developers.google.com/blockly/xml">' +
|
||||||
' <block type="row_block" id="a">' +
|
' <block type="row_block" id="a">' +
|
||||||
' <value name="INPUT">' +
|
' <value name="INPUT">' +
|
||||||
@@ -179,7 +179,7 @@ suite('InsertionMarkers', function() {
|
|||||||
this.assertGen(xml, 'row[a]();\n');
|
this.assertGen(xml, 'row[a]();\n');
|
||||||
});
|
});
|
||||||
test('Marker Middle of Row', function() {
|
test('Marker Middle of Row', function() {
|
||||||
let xml = Blockly.Xml.textToDom(
|
const xml = Blockly.Xml.textToDom(
|
||||||
'<xml xmlns="https://developers.google.com/blockly/xml">' +
|
'<xml xmlns="https://developers.google.com/blockly/xml">' +
|
||||||
' <block type="row_block" id="a">' +
|
' <block type="row_block" id="a">' +
|
||||||
' <value name="INPUT">' +
|
' <value name="INPUT">' +
|
||||||
@@ -194,7 +194,7 @@ suite('InsertionMarkers', function() {
|
|||||||
this.assertGen(xml, 'row[a](row[b]());\n');
|
this.assertGen(xml, 'row[a](row[b]());\n');
|
||||||
});
|
});
|
||||||
test('Marker Detatched', function() {
|
test('Marker Detatched', function() {
|
||||||
let xml = Blockly.Xml.textToDom(
|
const xml = Blockly.Xml.textToDom(
|
||||||
'<xml xmlns="https://developers.google.com/blockly/xml">' +
|
'<xml xmlns="https://developers.google.com/blockly/xml">' +
|
||||||
' <block type="stack_block" id="insertion"/>' +
|
' <block type="stack_block" id="insertion"/>' +
|
||||||
' <block type="stack_block" id="a"/>' +
|
' <block type="stack_block" id="a"/>' +
|
||||||
@@ -206,7 +206,7 @@ suite('InsertionMarkers', function() {
|
|||||||
setup(function() {
|
setup(function() {
|
||||||
this.assertXml = function(xmlIn, expectXml) {
|
this.assertXml = function(xmlIn, expectXml) {
|
||||||
Blockly.Xml.domToWorkspace(xmlIn, this.workspace);
|
Blockly.Xml.domToWorkspace(xmlIn, this.workspace);
|
||||||
let block = this.workspace.getBlockById('insertion');
|
const block = this.workspace.getBlockById('insertion');
|
||||||
block.setInsertionMarker(true);
|
block.setInsertionMarker(true);
|
||||||
let xml = Blockly.Xml.workspaceToDom(this.workspace);
|
let xml = Blockly.Xml.workspaceToDom(this.workspace);
|
||||||
Blockly.Xml.domToWorkspace(xml, this.workspace);
|
Blockly.Xml.domToWorkspace(xml, this.workspace);
|
||||||
@@ -215,7 +215,7 @@ suite('InsertionMarkers', function() {
|
|||||||
};
|
};
|
||||||
});
|
});
|
||||||
test('Marker Surrounds', function() {
|
test('Marker Surrounds', function() {
|
||||||
let xml = Blockly.Xml.textToDom(
|
const xml = Blockly.Xml.textToDom(
|
||||||
'<xml xmlns="https://developers.google.com/blockly/xml">' +
|
'<xml xmlns="https://developers.google.com/blockly/xml">' +
|
||||||
' <block type="statement_block" id="insertion" x="20" y="20">' +
|
' <block type="statement_block" id="insertion" x="20" y="20">' +
|
||||||
' <statement name="STATEMENT">' +
|
' <statement name="STATEMENT">' +
|
||||||
@@ -231,7 +231,7 @@ suite('InsertionMarkers', function() {
|
|||||||
'</xml>');
|
'</xml>');
|
||||||
});
|
});
|
||||||
test('Marker Enclosed', function() {
|
test('Marker Enclosed', function() {
|
||||||
let xml = Blockly.Xml.textToDom(
|
const xml = Blockly.Xml.textToDom(
|
||||||
'<xml xmlns="https://developers.google.com/blockly/xml">' +
|
'<xml xmlns="https://developers.google.com/blockly/xml">' +
|
||||||
' <block type="statement_block" id="a" x="20" y="20">' +
|
' <block type="statement_block" id="a" x="20" y="20">' +
|
||||||
' <statement name="STATEMENT">' +
|
' <statement name="STATEMENT">' +
|
||||||
@@ -245,7 +245,7 @@ suite('InsertionMarkers', function() {
|
|||||||
'</xml>');
|
'</xml>');
|
||||||
});
|
});
|
||||||
test('Marker Enclosed and Surrounds', function() {
|
test('Marker Enclosed and Surrounds', function() {
|
||||||
let xml = Blockly.Xml.textToDom(
|
const xml = Blockly.Xml.textToDom(
|
||||||
'<xml xmlns="https://developers.google.com/blockly/xml">' +
|
'<xml xmlns="https://developers.google.com/blockly/xml">' +
|
||||||
' <block type="statement_block" id="a" x="20" y="20">' +
|
' <block type="statement_block" id="a" x="20" y="20">' +
|
||||||
' <statement name="STATEMENT">' +
|
' <statement name="STATEMENT">' +
|
||||||
@@ -267,7 +267,7 @@ suite('InsertionMarkers', function() {
|
|||||||
'</xml>');
|
'</xml>');
|
||||||
});
|
});
|
||||||
test('Marker Prev', function() {
|
test('Marker Prev', function() {
|
||||||
let xml = Blockly.Xml.textToDom(
|
const xml = Blockly.Xml.textToDom(
|
||||||
'<xml xmlns="https://developers.google.com/blockly/xml">' +
|
'<xml xmlns="https://developers.google.com/blockly/xml">' +
|
||||||
' <block type="stack_block" id="insertion" x="20" y="20">' +
|
' <block type="stack_block" id="insertion" x="20" y="20">' +
|
||||||
' <next>' +
|
' <next>' +
|
||||||
@@ -283,7 +283,7 @@ suite('InsertionMarkers', function() {
|
|||||||
'</xml>');
|
'</xml>');
|
||||||
});
|
});
|
||||||
test('Marker Next', function() {
|
test('Marker Next', function() {
|
||||||
let xml = Blockly.Xml.textToDom(
|
const xml = Blockly.Xml.textToDom(
|
||||||
'<xml xmlns="https://developers.google.com/blockly/xml">' +
|
'<xml xmlns="https://developers.google.com/blockly/xml">' +
|
||||||
' <block type="stack_block" id="a" x="20" y="20">' +
|
' <block type="stack_block" id="a" x="20" y="20">' +
|
||||||
' <next>' +
|
' <next>' +
|
||||||
@@ -297,7 +297,7 @@ suite('InsertionMarkers', function() {
|
|||||||
'</xml>');
|
'</xml>');
|
||||||
});
|
});
|
||||||
test('Marker Middle of Stack', function() {
|
test('Marker Middle of Stack', function() {
|
||||||
let xml = Blockly.Xml.textToDom(
|
const xml = Blockly.Xml.textToDom(
|
||||||
'<xml xmlns="https://developers.google.com/blockly/xml">' +
|
'<xml xmlns="https://developers.google.com/blockly/xml">' +
|
||||||
' <block type="stack_block" id="a" x="20" y="20">' +
|
' <block type="stack_block" id="a" x="20" y="20">' +
|
||||||
' <next>' +
|
' <next>' +
|
||||||
@@ -319,7 +319,7 @@ suite('InsertionMarkers', function() {
|
|||||||
'</xml>');
|
'</xml>');
|
||||||
});
|
});
|
||||||
test('Marker On Output', function() {
|
test('Marker On Output', function() {
|
||||||
let xml = Blockly.Xml.textToDom(
|
const xml = Blockly.Xml.textToDom(
|
||||||
'<xml xmlns="https://developers.google.com/blockly/xml">' +
|
'<xml xmlns="https://developers.google.com/blockly/xml">' +
|
||||||
' <block type="row_block" id="insertion" x="20" y="20">' +
|
' <block type="row_block" id="insertion" x="20" y="20">' +
|
||||||
' <value name="INPUT">' +
|
' <value name="INPUT">' +
|
||||||
@@ -335,7 +335,7 @@ suite('InsertionMarkers', function() {
|
|||||||
'</xml>');
|
'</xml>');
|
||||||
});
|
});
|
||||||
test('Marker On Input', function() {
|
test('Marker On Input', function() {
|
||||||
let xml = Blockly.Xml.textToDom(
|
const xml = Blockly.Xml.textToDom(
|
||||||
'<xml xmlns="https://developers.google.com/blockly/xml">' +
|
'<xml xmlns="https://developers.google.com/blockly/xml">' +
|
||||||
' <block type="row_block" id="a" x="20" y="20">' +
|
' <block type="row_block" id="a" x="20" y="20">' +
|
||||||
' <value name="INPUT">' +
|
' <value name="INPUT">' +
|
||||||
@@ -349,7 +349,7 @@ suite('InsertionMarkers', function() {
|
|||||||
'</xml>');
|
'</xml>');
|
||||||
});
|
});
|
||||||
test('Marker Middle of Row', function() {
|
test('Marker Middle of Row', function() {
|
||||||
let xml = Blockly.Xml.textToDom(
|
const xml = Blockly.Xml.textToDom(
|
||||||
'<xml xmlns="https://developers.google.com/blockly/xml">' +
|
'<xml xmlns="https://developers.google.com/blockly/xml">' +
|
||||||
' <block type="row_block" id="a" x="20" y="20">' +
|
' <block type="row_block" id="a" x="20" y="20">' +
|
||||||
' <value name="INPUT">' +
|
' <value name="INPUT">' +
|
||||||
@@ -371,7 +371,7 @@ suite('InsertionMarkers', function() {
|
|||||||
'</xml>');
|
'</xml>');
|
||||||
});
|
});
|
||||||
test('Marker Detatched', function() {
|
test('Marker Detatched', function() {
|
||||||
let xml = Blockly.Xml.textToDom(
|
const xml = Blockly.Xml.textToDom(
|
||||||
'<xml xmlns="https://developers.google.com/blockly/xml">' +
|
'<xml xmlns="https://developers.google.com/blockly/xml">' +
|
||||||
' <block type="stack_block" id="insertion"/>' +
|
' <block type="stack_block" id="insertion"/>' +
|
||||||
' <block type="stack_block" id="a" x="20" y="20"/>' +
|
' <block type="stack_block" id="a" x="20" y="20"/>' +
|
||||||
|
|||||||
@@ -690,7 +690,7 @@ suite('JSO Deserialization', function() {
|
|||||||
init: function() { },
|
init: function() { },
|
||||||
|
|
||||||
mutationToDom: function() {
|
mutationToDom: function() {
|
||||||
let container = Blockly.utils.xml.createElement('mutation');
|
const container = Blockly.utils.xml.createElement('mutation');
|
||||||
container.setAttribute('value', 'some value');
|
container.setAttribute('value', 'some value');
|
||||||
return container;
|
return container;
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -212,7 +212,7 @@ suite('JSO Serialization', function() {
|
|||||||
test('Xml hooks', function() {
|
test('Xml hooks', function() {
|
||||||
const block = this.workspace.newBlock('row_block');
|
const block = this.workspace.newBlock('row_block');
|
||||||
block.mutationToDom = function() {
|
block.mutationToDom = function() {
|
||||||
let container = Blockly.utils.xml.createElement('mutation');
|
const container = Blockly.utils.xml.createElement('mutation');
|
||||||
container.setAttribute('value', 'some value');
|
container.setAttribute('value', 'some value');
|
||||||
return container;
|
return container;
|
||||||
};
|
};
|
||||||
@@ -703,28 +703,28 @@ suite('JSO Serialization', function() {
|
|||||||
suite('Do full serialization', function() {
|
suite('Do full serialization', function() {
|
||||||
suite('True', function() {
|
suite('True', function() {
|
||||||
test('Single block', function() {
|
test('Single block', function() {
|
||||||
let block = this.workspace.newBlock('variables_get');
|
const block = this.workspace.newBlock('variables_get');
|
||||||
let jso = Blockly.serialization.blocks.save(block);
|
const jso = Blockly.serialization.blocks.save(block);
|
||||||
chai.assert.deepEqual(
|
chai.assert.deepEqual(
|
||||||
jso['fields']['VAR'], {'id': 'id2', 'name': 'item', 'type': ''});
|
jso['fields']['VAR'], {'id': 'id2', 'name': 'item', 'type': ''});
|
||||||
});
|
});
|
||||||
|
|
||||||
test('Input block', function() {
|
test('Input block', function() {
|
||||||
let block = this.workspace.newBlock('row_block');
|
const block = this.workspace.newBlock('row_block');
|
||||||
let childBlock = this.workspace.newBlock('variables_get');
|
const childBlock = this.workspace.newBlock('variables_get');
|
||||||
block.getInput('INPUT').connection.connect(
|
block.getInput('INPUT').connection.connect(
|
||||||
childBlock.outputConnection);
|
childBlock.outputConnection);
|
||||||
let jso = Blockly.serialization.blocks.save(block);
|
const jso = Blockly.serialization.blocks.save(block);
|
||||||
chai.assert.deepEqual(
|
chai.assert.deepEqual(
|
||||||
jso['inputs']['INPUT']['block']['fields']['VAR'],
|
jso['inputs']['INPUT']['block']['fields']['VAR'],
|
||||||
{'id': 'id4', 'name': 'item', 'type': ''});
|
{'id': 'id4', 'name': 'item', 'type': ''});
|
||||||
});
|
});
|
||||||
|
|
||||||
test('Next block', function() {
|
test('Next block', function() {
|
||||||
let block = this.workspace.newBlock('stack_block');
|
const block = this.workspace.newBlock('stack_block');
|
||||||
let childBlock = this.workspace.newBlock('variables_set');
|
const childBlock = this.workspace.newBlock('variables_set');
|
||||||
block.nextConnection.connect(childBlock.previousConnection);
|
block.nextConnection.connect(childBlock.previousConnection);
|
||||||
let jso = Blockly.serialization.blocks.save(block);
|
const jso = Blockly.serialization.blocks.save(block);
|
||||||
chai.assert.deepEqual(
|
chai.assert.deepEqual(
|
||||||
jso['next']['block']['fields']['VAR'],
|
jso['next']['block']['fields']['VAR'],
|
||||||
{'id': 'id4', 'name': 'item', 'type': ''});
|
{'id': 'id4', 'name': 'item', 'type': ''});
|
||||||
@@ -733,8 +733,8 @@ suite('JSO Serialization', function() {
|
|||||||
|
|
||||||
suite('False', function() {
|
suite('False', function() {
|
||||||
test('Single block', function() {
|
test('Single block', function() {
|
||||||
let block = this.workspace.newBlock('variables_get');
|
const block = this.workspace.newBlock('variables_get');
|
||||||
let jso = Blockly.serialization.blocks.save(
|
const jso = Blockly.serialization.blocks.save(
|
||||||
block, {doFullSerialization: false});
|
block, {doFullSerialization: false});
|
||||||
chai.assert.deepEqual(jso['fields']['VAR'], {'id': 'id2'});
|
chai.assert.deepEqual(jso['fields']['VAR'], {'id': 'id2'});
|
||||||
chai.assert.isUndefined(jso['fields']['VAR']['name']);
|
chai.assert.isUndefined(jso['fields']['VAR']['name']);
|
||||||
@@ -742,11 +742,11 @@ suite('JSO Serialization', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
test('Input block', function() {
|
test('Input block', function() {
|
||||||
let block = this.workspace.newBlock('row_block');
|
const block = this.workspace.newBlock('row_block');
|
||||||
let childBlock = this.workspace.newBlock('variables_get');
|
const childBlock = this.workspace.newBlock('variables_get');
|
||||||
block.getInput('INPUT').connection.connect(
|
block.getInput('INPUT').connection.connect(
|
||||||
childBlock.outputConnection);
|
childBlock.outputConnection);
|
||||||
let jso = Blockly.serialization.blocks.save(
|
const jso = Blockly.serialization.blocks.save(
|
||||||
block, {doFullSerialization: false});
|
block, {doFullSerialization: false});
|
||||||
chai.assert.deepEqual(
|
chai.assert.deepEqual(
|
||||||
jso['inputs']['INPUT']['block']['fields']['VAR'], {'id': 'id4'});
|
jso['inputs']['INPUT']['block']['fields']['VAR'], {'id': 'id4'});
|
||||||
@@ -757,10 +757,10 @@ suite('JSO Serialization', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
test('Next block', function() {
|
test('Next block', function() {
|
||||||
let block = this.workspace.newBlock('stack_block');
|
const block = this.workspace.newBlock('stack_block');
|
||||||
let childBlock = this.workspace.newBlock('variables_set');
|
const childBlock = this.workspace.newBlock('variables_set');
|
||||||
block.nextConnection.connect(childBlock.previousConnection);
|
block.nextConnection.connect(childBlock.previousConnection);
|
||||||
let jso = Blockly.serialization.blocks.save(
|
const jso = Blockly.serialization.blocks.save(
|
||||||
block, {doFullSerialization: false});
|
block, {doFullSerialization: false});
|
||||||
chai.assert.deepEqual(
|
chai.assert.deepEqual(
|
||||||
jso['next']['block']['fields']['VAR'], {'id': 'id4'});
|
jso['next']['block']['fields']['VAR'], {'id': 'id4'});
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ suite('JSON Block Definitions', function() {
|
|||||||
suite('defineBlocksWithJsonArray', function() {
|
suite('defineBlocksWithJsonArray', function() {
|
||||||
test('Basic block', function() {
|
test('Basic block', function() {
|
||||||
/** Ensure a block can be instantiated from a JSON definition. */
|
/** Ensure a block can be instantiated from a JSON definition. */
|
||||||
let BLOCK_TYPE = 'test_json_minimal';
|
const BLOCK_TYPE = 'test_json_minimal';
|
||||||
let block;
|
let block;
|
||||||
assertNoWarnings(() => {
|
assertNoWarnings(() => {
|
||||||
Blockly.defineBlocksWithJsonArray([{
|
Blockly.defineBlocksWithJsonArray([{
|
||||||
@@ -36,12 +36,12 @@ suite('JSON Block Definitions', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
test('Null or undefined type id', function() {
|
test('Null or undefined type id', function() {
|
||||||
let BLOCK_TYPE1 = 'test_json_before_bad_blocks';
|
const BLOCK_TYPE1 = 'test_json_before_bad_blocks';
|
||||||
let BLOCK_TYPE2 = 'test_json_after_bad_blocks';
|
const BLOCK_TYPE2 = 'test_json_after_bad_blocks';
|
||||||
|
|
||||||
chai.assert.isUndefined(Blockly.Blocks[BLOCK_TYPE1]);
|
chai.assert.isUndefined(Blockly.Blocks[BLOCK_TYPE1]);
|
||||||
chai.assert.isUndefined(Blockly.Blocks[BLOCK_TYPE2]);
|
chai.assert.isUndefined(Blockly.Blocks[BLOCK_TYPE2]);
|
||||||
let blockTypeCount = Object.keys(Blockly.Blocks).length;
|
const blockTypeCount = Object.keys(Blockly.Blocks).length;
|
||||||
|
|
||||||
assertWarnings(() => {
|
assertWarnings(() => {
|
||||||
Blockly.defineBlocksWithJsonArray([
|
Blockly.defineBlocksWithJsonArray([
|
||||||
@@ -58,12 +58,12 @@ suite('JSON Block Definitions', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
test('Null item', function() {
|
test('Null item', function() {
|
||||||
let BLOCK_TYPE1 = 'test_block_before_null';
|
const BLOCK_TYPE1 = 'test_block_before_null';
|
||||||
let BLOCK_TYPE2 = 'test_block_after_null';
|
const BLOCK_TYPE2 = 'test_block_after_null';
|
||||||
|
|
||||||
chai.assert.isUndefined(Blockly.Blocks[BLOCK_TYPE1]);
|
chai.assert.isUndefined(Blockly.Blocks[BLOCK_TYPE1]);
|
||||||
chai.assert.isUndefined(Blockly.Blocks[BLOCK_TYPE2]);
|
chai.assert.isUndefined(Blockly.Blocks[BLOCK_TYPE2]);
|
||||||
let blockTypeCount = Object.keys(Blockly.Blocks).length;
|
const blockTypeCount = Object.keys(Blockly.Blocks).length;
|
||||||
|
|
||||||
assertWarnings(() => {
|
assertWarnings(() => {
|
||||||
Blockly.defineBlocksWithJsonArray([
|
Blockly.defineBlocksWithJsonArray([
|
||||||
@@ -85,12 +85,12 @@ suite('JSON Block Definitions', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
test('Undefined item', function() {
|
test('Undefined item', function() {
|
||||||
let BLOCK_TYPE1 = 'test_block_before_undefined';
|
const BLOCK_TYPE1 = 'test_block_before_undefined';
|
||||||
let BLOCK_TYPE2 = 'test_block_after_undefined';
|
const BLOCK_TYPE2 = 'test_block_after_undefined';
|
||||||
|
|
||||||
chai.assert.isUndefined(Blockly.Blocks[BLOCK_TYPE1]);
|
chai.assert.isUndefined(Blockly.Blocks[BLOCK_TYPE1]);
|
||||||
chai.assert.isUndefined(Blockly.Blocks[BLOCK_TYPE2]);
|
chai.assert.isUndefined(Blockly.Blocks[BLOCK_TYPE2]);
|
||||||
let blockTypeCount = Object.keys(Blockly.Blocks).length;
|
const blockTypeCount = Object.keys(Blockly.Blocks).length;
|
||||||
assertWarnings(() => {
|
assertWarnings(() => {
|
||||||
Blockly.defineBlocksWithJsonArray([
|
Blockly.defineBlocksWithJsonArray([
|
||||||
{
|
{
|
||||||
@@ -111,33 +111,33 @@ suite('JSON Block Definitions', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
test('message0 creates input', function() {
|
test('message0 creates input', function() {
|
||||||
let BLOCK_TYPE = 'test_json_message0';
|
const BLOCK_TYPE = 'test_json_message0';
|
||||||
let MESSAGE0 = 'message0';
|
const MESSAGE0 = 'message0';
|
||||||
Blockly.defineBlocksWithJsonArray([{
|
Blockly.defineBlocksWithJsonArray([{
|
||||||
"type": BLOCK_TYPE,
|
"type": BLOCK_TYPE,
|
||||||
"message0": MESSAGE0
|
"message0": MESSAGE0
|
||||||
}]);
|
}]);
|
||||||
|
|
||||||
let block = new Blockly.Block(this.workspace_, BLOCK_TYPE);
|
const block = new Blockly.Block(this.workspace_, BLOCK_TYPE);
|
||||||
chai.assert.equal(block.inputList.length, 1);
|
chai.assert.equal(block.inputList.length, 1);
|
||||||
chai.assert.equal(block.inputList[0].fieldRow.length, 1);
|
chai.assert.equal(block.inputList[0].fieldRow.length, 1);
|
||||||
let textField = block.inputList[0].fieldRow[0];
|
const textField = block.inputList[0].fieldRow[0];
|
||||||
chai.assert.equal(Blockly.FieldLabel, textField.constructor);
|
chai.assert.equal(Blockly.FieldLabel, textField.constructor);
|
||||||
chai.assert.equal(MESSAGE0, textField.getText());
|
chai.assert.equal(MESSAGE0, textField.getText());
|
||||||
});
|
});
|
||||||
|
|
||||||
test('message1 and message0 creates two inputs', function() {
|
test('message1 and message0 creates two inputs', function() {
|
||||||
/** Ensure message1 creates a new input. */
|
/** Ensure message1 creates a new input. */
|
||||||
let BLOCK_TYPE = 'test_json_message1';
|
const BLOCK_TYPE = 'test_json_message1';
|
||||||
let MESSAGE0 = 'message0';
|
const MESSAGE0 = 'message0';
|
||||||
let MESSAGE1 = 'message1';
|
const MESSAGE1 = 'message1';
|
||||||
Blockly.defineBlocksWithJsonArray([{
|
Blockly.defineBlocksWithJsonArray([{
|
||||||
"type": BLOCK_TYPE,
|
"type": BLOCK_TYPE,
|
||||||
"message0": MESSAGE0,
|
"message0": MESSAGE0,
|
||||||
"message1": MESSAGE1
|
"message1": MESSAGE1
|
||||||
}]);
|
}]);
|
||||||
|
|
||||||
let block = new Blockly.Block(this.workspace_, BLOCK_TYPE);
|
const block = new Blockly.Block(this.workspace_, BLOCK_TYPE);
|
||||||
chai.assert.equal(block.inputList.length, 2);
|
chai.assert.equal(block.inputList.length, 2);
|
||||||
|
|
||||||
chai.assert.equal(block.inputList[0].fieldRow.length, 1);
|
chai.assert.equal(block.inputList[0].fieldRow.length, 1);
|
||||||
@@ -152,9 +152,9 @@ suite('JSON Block Definitions', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
test('Message string is dereferenced', function() {
|
test('Message string is dereferenced', function() {
|
||||||
let BLOCK_TYPE = 'test_json_message0_i18n';
|
const BLOCK_TYPE = 'test_json_message0_i18n';
|
||||||
let MESSAGE0 = '%{BKY_MESSAGE}';
|
const MESSAGE0 = '%{BKY_MESSAGE}';
|
||||||
let MESSAGE = 'message';
|
const MESSAGE = 'message';
|
||||||
|
|
||||||
addMessageToCleanup(this.sharedCleanup, 'MESSAGE');
|
addMessageToCleanup(this.sharedCleanup, 'MESSAGE');
|
||||||
Blockly.Msg['MESSAGE'] = MESSAGE;
|
Blockly.Msg['MESSAGE'] = MESSAGE;
|
||||||
@@ -163,21 +163,21 @@ suite('JSON Block Definitions', function() {
|
|||||||
"message0": MESSAGE0
|
"message0": MESSAGE0
|
||||||
}]);
|
}]);
|
||||||
|
|
||||||
let block = new Blockly.Block(this.workspace_, BLOCK_TYPE);
|
const block = new Blockly.Block(this.workspace_, BLOCK_TYPE);
|
||||||
chai.assert.equal(block.inputList.length, 1);
|
chai.assert.equal(block.inputList.length, 1);
|
||||||
chai.assert.equal(block.inputList[0].fieldRow.length, 1);
|
chai.assert.equal(block.inputList[0].fieldRow.length, 1);
|
||||||
let textField = block.inputList[0].fieldRow[0];
|
const textField = block.inputList[0].fieldRow[0];
|
||||||
chai.assert.equal(Blockly.FieldLabel, textField.constructor);
|
chai.assert.equal(Blockly.FieldLabel, textField.constructor);
|
||||||
chai.assert.equal(MESSAGE, textField.getText());
|
chai.assert.equal(MESSAGE, textField.getText());
|
||||||
});
|
});
|
||||||
|
|
||||||
test('Dropdown', function() {
|
test('Dropdown', function() {
|
||||||
let BLOCK_TYPE = 'test_json_dropdown';
|
const BLOCK_TYPE = 'test_json_dropdown';
|
||||||
let FIELD_NAME = 'FIELD_NAME';
|
const FIELD_NAME = 'FIELD_NAME';
|
||||||
let LABEL0 = 'LABEL0';
|
const LABEL0 = 'LABEL0';
|
||||||
let VALUE0 = 'VALUE0';
|
const VALUE0 = 'VALUE0';
|
||||||
let LABEL1 = 'LABEL1';
|
const LABEL1 = 'LABEL1';
|
||||||
let VALUE1 = 'VALUE1';
|
const VALUE1 = 'VALUE1';
|
||||||
Blockly.defineBlocksWithJsonArray([{
|
Blockly.defineBlocksWithJsonArray([{
|
||||||
"type": BLOCK_TYPE,
|
"type": BLOCK_TYPE,
|
||||||
"message0": "%1",
|
"message0": "%1",
|
||||||
@@ -193,15 +193,15 @@ suite('JSON Block Definitions', function() {
|
|||||||
]
|
]
|
||||||
}]);
|
}]);
|
||||||
|
|
||||||
let block = new Blockly.Block(this.workspace_, BLOCK_TYPE);
|
const block = new Blockly.Block(this.workspace_, BLOCK_TYPE);
|
||||||
chai.assert.equal(block.inputList.length, 1);
|
chai.assert.equal(block.inputList.length, 1);
|
||||||
chai.assert.equal(block.inputList[0].fieldRow.length, 1);
|
chai.assert.equal(block.inputList[0].fieldRow.length, 1);
|
||||||
let dropdown = block.inputList[0].fieldRow[0];
|
const dropdown = block.inputList[0].fieldRow[0];
|
||||||
chai.assert.equal(dropdown, block.getField(FIELD_NAME));
|
chai.assert.equal(dropdown, block.getField(FIELD_NAME));
|
||||||
chai.assert.equal(Blockly.FieldDropdown, dropdown.constructor);
|
chai.assert.equal(Blockly.FieldDropdown, dropdown.constructor);
|
||||||
chai.assert.equal(VALUE0, dropdown.getValue());
|
chai.assert.equal(VALUE0, dropdown.getValue());
|
||||||
|
|
||||||
let options = dropdown.getOptions();
|
const options = dropdown.getOptions();
|
||||||
chai.assert.equal(LABEL0, options[0][0]);
|
chai.assert.equal(LABEL0, options[0][0]);
|
||||||
chai.assert.equal(VALUE0, options[0][1]);
|
chai.assert.equal(VALUE0, options[0][1]);
|
||||||
chai.assert.equal(LABEL1, options[1][0]);
|
chai.assert.equal(LABEL1, options[1][0]);
|
||||||
@@ -210,31 +210,31 @@ suite('JSON Block Definitions', function() {
|
|||||||
|
|
||||||
|
|
||||||
test('Dropdown with images', function() {
|
test('Dropdown with images', function() {
|
||||||
let BLOCK_TYPE = 'test_json_dropdown';
|
const BLOCK_TYPE = 'test_json_dropdown';
|
||||||
let FIELD_NAME = 'FIELD_NAME';
|
const FIELD_NAME = 'FIELD_NAME';
|
||||||
let IMAGE1_ALT_TEXT = 'Localized message.';
|
const IMAGE1_ALT_TEXT = 'Localized message.';
|
||||||
addMessageToCleanup(this.sharedCleanup, 'ALT_TEXT');
|
addMessageToCleanup(this.sharedCleanup, 'ALT_TEXT');
|
||||||
Blockly.Msg['ALT_TEXT'] = IMAGE1_ALT_TEXT;
|
Blockly.Msg['ALT_TEXT'] = IMAGE1_ALT_TEXT;
|
||||||
let IMAGE0 = {
|
const IMAGE0 = {
|
||||||
'width': 12,
|
'width': 12,
|
||||||
'height': 34,
|
'height': 34,
|
||||||
'src': 'http://image0.src',
|
'src': 'http://image0.src',
|
||||||
'alt': 'IMAGE0 alt text'
|
'alt': 'IMAGE0 alt text'
|
||||||
};
|
};
|
||||||
let VALUE0 = 'VALUE0';
|
const VALUE0 = 'VALUE0';
|
||||||
let IMAGE1 = {
|
const IMAGE1 = {
|
||||||
'width': 56,
|
'width': 56,
|
||||||
'height': 78,
|
'height': 78,
|
||||||
'src': 'http://image1.src',
|
'src': 'http://image1.src',
|
||||||
'alt': '%{BKY_ALT_TEXT}'
|
'alt': '%{BKY_ALT_TEXT}'
|
||||||
};
|
};
|
||||||
let VALUE1 = 'VALUE1';
|
const VALUE1 = 'VALUE1';
|
||||||
let IMAGE2 = {
|
const IMAGE2 = {
|
||||||
'width': 90,
|
'width': 90,
|
||||||
'height': 123,
|
'height': 123,
|
||||||
'src': 'http://image2.src'
|
'src': 'http://image2.src'
|
||||||
};
|
};
|
||||||
let VALUE2 = 'VALUE2';
|
const VALUE2 = 'VALUE2';
|
||||||
|
|
||||||
Blockly.defineBlocksWithJsonArray([{
|
Blockly.defineBlocksWithJsonArray([{
|
||||||
"type": BLOCK_TYPE,
|
"type": BLOCK_TYPE,
|
||||||
@@ -252,10 +252,10 @@ suite('JSON Block Definitions', function() {
|
|||||||
]
|
]
|
||||||
}]);
|
}]);
|
||||||
|
|
||||||
let block = new Blockly.Block(this.workspace_, BLOCK_TYPE);
|
const block = new Blockly.Block(this.workspace_, BLOCK_TYPE);
|
||||||
chai.assert.equal(block.inputList.length, 1);
|
chai.assert.equal(block.inputList.length, 1);
|
||||||
chai.assert.equal(block.inputList[0].fieldRow.length, 1);
|
chai.assert.equal(block.inputList[0].fieldRow.length, 1);
|
||||||
let dropdown = block.inputList[0].fieldRow[0];
|
const dropdown = block.inputList[0].fieldRow[0];
|
||||||
chai.assert.equal(dropdown, block.getField(FIELD_NAME));
|
chai.assert.equal(dropdown, block.getField(FIELD_NAME));
|
||||||
chai.assert.equal(Blockly.FieldDropdown, dropdown.constructor);
|
chai.assert.equal(Blockly.FieldDropdown, dropdown.constructor);
|
||||||
chai.assert.equal(VALUE0, dropdown.getValue());
|
chai.assert.equal(VALUE0, dropdown.getValue());
|
||||||
@@ -266,18 +266,18 @@ suite('JSON Block Definitions', function() {
|
|||||||
chai.assert.equal(actualImage.src, expectedImage.src);
|
chai.assert.equal(actualImage.src, expectedImage.src);
|
||||||
}
|
}
|
||||||
|
|
||||||
let options = dropdown.getOptions();
|
const options = dropdown.getOptions();
|
||||||
let image0 = options[0][0];
|
const image0 = options[0][0];
|
||||||
assertImageEquals(IMAGE0, image0);
|
assertImageEquals(IMAGE0, image0);
|
||||||
chai.assert.equal(IMAGE0.alt, image0.alt);
|
chai.assert.equal(IMAGE0.alt, image0.alt);
|
||||||
chai.assert.equal(options[0][1], VALUE0);
|
chai.assert.equal(options[0][1], VALUE0);
|
||||||
|
|
||||||
let image1 = options[1][0];
|
const image1 = options[1][0];
|
||||||
assertImageEquals(IMAGE1, image1);
|
assertImageEquals(IMAGE1, image1);
|
||||||
chai.assert.equal(IMAGE1.alt, IMAGE1_ALT_TEXT); // Via Msg reference
|
chai.assert.equal(IMAGE1.alt, IMAGE1_ALT_TEXT); // Via Msg reference
|
||||||
chai.assert.equal(VALUE1, options[1][1]);
|
chai.assert.equal(VALUE1, options[1][1]);
|
||||||
|
|
||||||
let image2 = options[2][0];
|
const image2 = options[2][0];
|
||||||
assertImageEquals(IMAGE1, image1);
|
assertImageEquals(IMAGE1, image1);
|
||||||
chai.assert.notExists(image2.alt); // No alt specified.
|
chai.assert.notExists(image2.alt); // No alt specified.
|
||||||
chai.assert.equal(VALUE2, options[2][1]);
|
chai.assert.equal(VALUE2, options[2][1]);
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ suite('Key Down', function() {
|
|||||||
* @param {string=} opt_name An optional name for the test case.
|
* @param {string=} opt_name An optional name for the test case.
|
||||||
*/
|
*/
|
||||||
function runReadOnlyTest(keyEvent, opt_name) {
|
function runReadOnlyTest(keyEvent, opt_name) {
|
||||||
let name = opt_name ? opt_name : 'Not called when readOnly is true';
|
const name = opt_name ? opt_name : 'Not called when readOnly is true';
|
||||||
test(name, function() {
|
test(name, function() {
|
||||||
this.workspace.options.readOnly = true;
|
this.workspace.options.readOnly = true;
|
||||||
document.dispatchEvent(keyEvent);
|
document.dispatchEvent(keyEvent);
|
||||||
@@ -53,7 +53,7 @@ suite('Key Down', function() {
|
|||||||
});
|
});
|
||||||
runReadOnlyTest(createKeyDownEvent(Blockly.utils.KeyCodes.ESC));
|
runReadOnlyTest(createKeyDownEvent(Blockly.utils.KeyCodes.ESC));
|
||||||
test('Not called when focus is on an HTML input', function() {
|
test('Not called when focus is on an HTML input', function() {
|
||||||
let event = createKeyDownEvent(Blockly.utils.KeyCodes.ESC);
|
const event = createKeyDownEvent(Blockly.utils.KeyCodes.ESC);
|
||||||
const input = document.createElement('textarea');
|
const input = document.createElement('textarea');
|
||||||
input.dispatchEvent(event);
|
input.dispatchEvent(event);
|
||||||
sinon.assert.notCalled(this.hideChaffSpy);
|
sinon.assert.notCalled(this.hideChaffSpy);
|
||||||
@@ -72,15 +72,15 @@ suite('Key Down', function() {
|
|||||||
setSelectedBlock(this.workspace);
|
setSelectedBlock(this.workspace);
|
||||||
this.deleteSpy = sinon.spy(Blockly.common.getSelected(), 'dispose');
|
this.deleteSpy = sinon.spy(Blockly.common.getSelected(), 'dispose');
|
||||||
});
|
});
|
||||||
let testCases = [
|
const testCases = [
|
||||||
['Delete', createKeyDownEvent(Blockly.utils.KeyCodes.DELETE)],
|
['Delete', createKeyDownEvent(Blockly.utils.KeyCodes.DELETE)],
|
||||||
['Backspace', createKeyDownEvent(Blockly.utils.KeyCodes.BACKSPACE)]
|
['Backspace', createKeyDownEvent(Blockly.utils.KeyCodes.BACKSPACE)]
|
||||||
];
|
];
|
||||||
// Delete a block.
|
// Delete a block.
|
||||||
suite('Simple', function() {
|
suite('Simple', function() {
|
||||||
testCases.forEach(function(testCase) {
|
testCases.forEach(function(testCase) {
|
||||||
let testCaseName = testCase[0];
|
const testCaseName = testCase[0];
|
||||||
let keyEvent = testCase[1];
|
const keyEvent = testCase[1];
|
||||||
test(testCaseName, function() {
|
test(testCaseName, function() {
|
||||||
document.dispatchEvent(keyEvent);
|
document.dispatchEvent(keyEvent);
|
||||||
sinon.assert.calledOnce(this.hideChaffSpy);
|
sinon.assert.calledOnce(this.hideChaffSpy);
|
||||||
@@ -91,8 +91,8 @@ suite('Key Down', function() {
|
|||||||
// Do not delete a block if workspace is in readOnly mode.
|
// Do not delete a block if workspace is in readOnly mode.
|
||||||
suite('Not called when readOnly is true', function() {
|
suite('Not called when readOnly is true', function() {
|
||||||
testCases.forEach(function(testCase) {
|
testCases.forEach(function(testCase) {
|
||||||
let testCaseName = testCase[0];
|
const testCaseName = testCase[0];
|
||||||
let keyEvent = testCase[1];
|
const keyEvent = testCase[1];
|
||||||
runReadOnlyTest(keyEvent, testCaseName);
|
runReadOnlyTest(keyEvent, testCaseName);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@@ -105,7 +105,7 @@ suite('Key Down', function() {
|
|||||||
this.hideChaffSpy = sinon.spy(
|
this.hideChaffSpy = sinon.spy(
|
||||||
Blockly.WorkspaceSvg.prototype, 'hideChaff');
|
Blockly.WorkspaceSvg.prototype, 'hideChaff');
|
||||||
});
|
});
|
||||||
let testCases = [
|
const testCases = [
|
||||||
['Control C', createKeyDownEvent(Blockly.utils.KeyCodes.C, [Blockly.utils.KeyCodes.CTRL])],
|
['Control C', createKeyDownEvent(Blockly.utils.KeyCodes.C, [Blockly.utils.KeyCodes.CTRL])],
|
||||||
['Meta C', createKeyDownEvent(Blockly.utils.KeyCodes.C, [Blockly.utils.KeyCodes.META])],
|
['Meta C', createKeyDownEvent(Blockly.utils.KeyCodes.C, [Blockly.utils.KeyCodes.META])],
|
||||||
['Alt C', createKeyDownEvent(Blockly.utils.KeyCodes.C, [Blockly.utils.KeyCodes.ALT])]
|
['Alt C', createKeyDownEvent(Blockly.utils.KeyCodes.C, [Blockly.utils.KeyCodes.ALT])]
|
||||||
@@ -113,8 +113,8 @@ suite('Key Down', function() {
|
|||||||
// Copy a block.
|
// Copy a block.
|
||||||
suite('Simple', function() {
|
suite('Simple', function() {
|
||||||
testCases.forEach(function(testCase) {
|
testCases.forEach(function(testCase) {
|
||||||
let testCaseName = testCase[0];
|
const testCaseName = testCase[0];
|
||||||
let keyEvent = testCase[1];
|
const keyEvent = testCase[1];
|
||||||
test(testCaseName, function() {
|
test(testCaseName, function() {
|
||||||
document.dispatchEvent(keyEvent);
|
document.dispatchEvent(keyEvent);
|
||||||
sinon.assert.calledOnce(this.copySpy);
|
sinon.assert.calledOnce(this.copySpy);
|
||||||
@@ -125,16 +125,16 @@ suite('Key Down', function() {
|
|||||||
// Do not copy a block if a workspace is in readonly mode.
|
// Do not copy a block if a workspace is in readonly mode.
|
||||||
suite('Not called when readOnly is true', function() {
|
suite('Not called when readOnly is true', function() {
|
||||||
testCases.forEach(function(testCase) {
|
testCases.forEach(function(testCase) {
|
||||||
let testCaseName = testCase[0];
|
const testCaseName = testCase[0];
|
||||||
let keyEvent = testCase[1];
|
const keyEvent = testCase[1];
|
||||||
runReadOnlyTest(keyEvent, testCaseName);
|
runReadOnlyTest(keyEvent, testCaseName);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
// Do not copy a block if a gesture is in progress.
|
// Do not copy a block if a gesture is in progress.
|
||||||
suite('Gesture in progress', function() {
|
suite('Gesture in progress', function() {
|
||||||
testCases.forEach(function(testCase) {
|
testCases.forEach(function(testCase) {
|
||||||
let testCaseName = testCase[0];
|
const testCaseName = testCase[0];
|
||||||
let keyEvent = testCase[1];
|
const keyEvent = testCase[1];
|
||||||
test(testCaseName, function() {
|
test(testCaseName, function() {
|
||||||
sinon.stub(Blockly.Gesture, 'inProgress').returns(true);
|
sinon.stub(Blockly.Gesture, 'inProgress').returns(true);
|
||||||
document.dispatchEvent(keyEvent);
|
document.dispatchEvent(keyEvent);
|
||||||
@@ -146,8 +146,8 @@ suite('Key Down', function() {
|
|||||||
// Do not copy a block if is is not deletable.
|
// Do not copy a block if is is not deletable.
|
||||||
suite('Block is not deletable', function() {
|
suite('Block is not deletable', function() {
|
||||||
testCases.forEach(function(testCase) {
|
testCases.forEach(function(testCase) {
|
||||||
let testCaseName = testCase[0];
|
const testCaseName = testCase[0];
|
||||||
let keyEvent = testCase[1];
|
const keyEvent = testCase[1];
|
||||||
test(testCaseName, function() {
|
test(testCaseName, function() {
|
||||||
sinon.stub(Blockly.common.getSelected(), 'isDeletable').returns(false);
|
sinon.stub(Blockly.common.getSelected(), 'isDeletable').returns(false);
|
||||||
document.dispatchEvent(keyEvent);
|
document.dispatchEvent(keyEvent);
|
||||||
@@ -159,8 +159,8 @@ suite('Key Down', function() {
|
|||||||
// Do not copy a block if it is not movable.
|
// Do not copy a block if it is not movable.
|
||||||
suite('Block is not movable', function() {
|
suite('Block is not movable', function() {
|
||||||
testCases.forEach(function(testCase) {
|
testCases.forEach(function(testCase) {
|
||||||
let testCaseName = testCase[0];
|
const testCaseName = testCase[0];
|
||||||
let keyEvent = testCase[1];
|
const keyEvent = testCase[1];
|
||||||
test(testCaseName, function() {
|
test(testCaseName, function() {
|
||||||
sinon.stub(Blockly.common.getSelected(), 'isMovable').returns(false);
|
sinon.stub(Blockly.common.getSelected(), 'isMovable').returns(false);
|
||||||
document.dispatchEvent(keyEvent);
|
document.dispatchEvent(keyEvent);
|
||||||
@@ -177,7 +177,7 @@ suite('Key Down', function() {
|
|||||||
this.hideChaffSpy = sinon.spy(
|
this.hideChaffSpy = sinon.spy(
|
||||||
Blockly.WorkspaceSvg.prototype, 'hideChaff');
|
Blockly.WorkspaceSvg.prototype, 'hideChaff');
|
||||||
});
|
});
|
||||||
let testCases = [
|
const testCases = [
|
||||||
['Control Z', createKeyDownEvent(Blockly.utils.KeyCodes.Z, [Blockly.utils.KeyCodes.CTRL])],
|
['Control Z', createKeyDownEvent(Blockly.utils.KeyCodes.Z, [Blockly.utils.KeyCodes.CTRL])],
|
||||||
['Meta Z', createKeyDownEvent(Blockly.utils.KeyCodes.Z, [Blockly.utils.KeyCodes.META])],
|
['Meta Z', createKeyDownEvent(Blockly.utils.KeyCodes.Z, [Blockly.utils.KeyCodes.META])],
|
||||||
['Alt Z', createKeyDownEvent(Blockly.utils.KeyCodes.Z, [Blockly.utils.KeyCodes.ALT])]
|
['Alt Z', createKeyDownEvent(Blockly.utils.KeyCodes.Z, [Blockly.utils.KeyCodes.ALT])]
|
||||||
@@ -185,8 +185,8 @@ suite('Key Down', function() {
|
|||||||
// Undo.
|
// Undo.
|
||||||
suite('Simple', function() {
|
suite('Simple', function() {
|
||||||
testCases.forEach(function(testCase) {
|
testCases.forEach(function(testCase) {
|
||||||
let testCaseName = testCase[0];
|
const testCaseName = testCase[0];
|
||||||
let keyEvent = testCase[1];
|
const keyEvent = testCase[1];
|
||||||
test(testCaseName, function() {
|
test(testCaseName, function() {
|
||||||
document.dispatchEvent(keyEvent);
|
document.dispatchEvent(keyEvent);
|
||||||
sinon.assert.calledOnce(this.undoSpy);
|
sinon.assert.calledOnce(this.undoSpy);
|
||||||
@@ -198,8 +198,8 @@ suite('Key Down', function() {
|
|||||||
// Do not undo if a gesture is in progress.
|
// Do not undo if a gesture is in progress.
|
||||||
suite('Gesture in progress', function() {
|
suite('Gesture in progress', function() {
|
||||||
testCases.forEach(function(testCase) {
|
testCases.forEach(function(testCase) {
|
||||||
let testCaseName = testCase[0];
|
const testCaseName = testCase[0];
|
||||||
let keyEvent = testCase[1];
|
const keyEvent = testCase[1];
|
||||||
test(testCaseName, function() {
|
test(testCaseName, function() {
|
||||||
sinon.stub(Blockly.Gesture, 'inProgress').returns(true);
|
sinon.stub(Blockly.Gesture, 'inProgress').returns(true);
|
||||||
document.dispatchEvent(keyEvent);
|
document.dispatchEvent(keyEvent);
|
||||||
@@ -211,8 +211,8 @@ suite('Key Down', function() {
|
|||||||
// Do not undo if the workspace is in readOnly mode.
|
// Do not undo if the workspace is in readOnly mode.
|
||||||
suite('Not called when readOnly is true', function() {
|
suite('Not called when readOnly is true', function() {
|
||||||
testCases.forEach(function(testCase) {
|
testCases.forEach(function(testCase) {
|
||||||
let testCaseName = testCase[0];
|
const testCaseName = testCase[0];
|
||||||
let keyEvent = testCase[1];
|
const keyEvent = testCase[1];
|
||||||
runReadOnlyTest(keyEvent, testCaseName);
|
runReadOnlyTest(keyEvent, testCaseName);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@@ -224,7 +224,7 @@ suite('Key Down', function() {
|
|||||||
this.hideChaffSpy = sinon.spy(
|
this.hideChaffSpy = sinon.spy(
|
||||||
Blockly.WorkspaceSvg.prototype, 'hideChaff');
|
Blockly.WorkspaceSvg.prototype, 'hideChaff');
|
||||||
});
|
});
|
||||||
let testCases = [
|
const testCases = [
|
||||||
['Control Shift Z', createKeyDownEvent(Blockly.utils.KeyCodes.Z, [Blockly.utils.KeyCodes.CTRL, Blockly.utils.KeyCodes.SHIFT])],
|
['Control Shift Z', createKeyDownEvent(Blockly.utils.KeyCodes.Z, [Blockly.utils.KeyCodes.CTRL, Blockly.utils.KeyCodes.SHIFT])],
|
||||||
['Meta Shift Z', createKeyDownEvent(Blockly.utils.KeyCodes.Z, [Blockly.utils.KeyCodes.META, Blockly.utils.KeyCodes.SHIFT])],
|
['Meta Shift Z', createKeyDownEvent(Blockly.utils.KeyCodes.Z, [Blockly.utils.KeyCodes.META, Blockly.utils.KeyCodes.SHIFT])],
|
||||||
['Alt Shift Z', createKeyDownEvent(Blockly.utils.KeyCodes.Z, [Blockly.utils.KeyCodes.ALT, Blockly.utils.KeyCodes.SHIFT])]
|
['Alt Shift Z', createKeyDownEvent(Blockly.utils.KeyCodes.Z, [Blockly.utils.KeyCodes.ALT, Blockly.utils.KeyCodes.SHIFT])]
|
||||||
@@ -232,8 +232,8 @@ suite('Key Down', function() {
|
|||||||
// Undo.
|
// Undo.
|
||||||
suite('Simple', function() {
|
suite('Simple', function() {
|
||||||
testCases.forEach(function(testCase) {
|
testCases.forEach(function(testCase) {
|
||||||
let testCaseName = testCase[0];
|
const testCaseName = testCase[0];
|
||||||
let keyEvent = testCase[1];
|
const keyEvent = testCase[1];
|
||||||
test(testCaseName, function() {
|
test(testCaseName, function() {
|
||||||
document.dispatchEvent(keyEvent);
|
document.dispatchEvent(keyEvent);
|
||||||
sinon.assert.calledOnce(this.redoSpy);
|
sinon.assert.calledOnce(this.redoSpy);
|
||||||
@@ -245,8 +245,8 @@ suite('Key Down', function() {
|
|||||||
// Do not undo if a gesture is in progress.
|
// Do not undo if a gesture is in progress.
|
||||||
suite('Gesture in progress', function() {
|
suite('Gesture in progress', function() {
|
||||||
testCases.forEach(function(testCase) {
|
testCases.forEach(function(testCase) {
|
||||||
let testCaseName = testCase[0];
|
const testCaseName = testCase[0];
|
||||||
let keyEvent = testCase[1];
|
const keyEvent = testCase[1];
|
||||||
test(testCaseName, function() {
|
test(testCaseName, function() {
|
||||||
sinon.stub(Blockly.Gesture, 'inProgress').returns(true);
|
sinon.stub(Blockly.Gesture, 'inProgress').returns(true);
|
||||||
document.dispatchEvent(keyEvent);
|
document.dispatchEvent(keyEvent);
|
||||||
@@ -258,8 +258,8 @@ suite('Key Down', function() {
|
|||||||
// Do not undo if the workspace is in readOnly mode.
|
// Do not undo if the workspace is in readOnly mode.
|
||||||
suite('Not called when readOnly is true', function() {
|
suite('Not called when readOnly is true', function() {
|
||||||
testCases.forEach(function(testCase) {
|
testCases.forEach(function(testCase) {
|
||||||
let testCaseName = testCase[0];
|
const testCaseName = testCase[0];
|
||||||
let keyEvent = testCase[1];
|
const keyEvent = testCase[1];
|
||||||
runReadOnlyTest(keyEvent, testCaseName);
|
runReadOnlyTest(keyEvent, testCaseName);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -129,56 +129,56 @@ suite('Logic ternary', function() {
|
|||||||
});
|
});
|
||||||
suite('No parent', function() {
|
suite('No parent', function() {
|
||||||
test('Attach inputs same type', function() {
|
test('Attach inputs same type', function() {
|
||||||
let string1 = this.workspace.newBlock('text');
|
const string1 = this.workspace.newBlock('text');
|
||||||
let string2 = this.workspace.newBlock('text_charAt');
|
const string2 = this.workspace.newBlock('text_charAt');
|
||||||
|
|
||||||
connectInputsAndCheckConnections(this.block, string1, string2);
|
connectInputsAndCheckConnections(this.block, string1, string2);
|
||||||
});
|
});
|
||||||
test('Attach inputs different types', function() {
|
test('Attach inputs different types', function() {
|
||||||
let string = this.workspace.newBlock('text');
|
const string = this.workspace.newBlock('text');
|
||||||
let number = this.workspace.newBlock('math_number');
|
const number = this.workspace.newBlock('math_number');
|
||||||
|
|
||||||
connectInputsAndCheckConnections(this.block, string, number);
|
connectInputsAndCheckConnections(this.block, string, number);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
suite('With parent already attached', function() {
|
suite('With parent already attached', function() {
|
||||||
test('Attach inputs same type with matching parent', function() {
|
test('Attach inputs same type with matching parent', function() {
|
||||||
let parent = this.workspace.newBlock('text_trim');
|
const parent = this.workspace.newBlock('text_trim');
|
||||||
|
|
||||||
connectParentAndCheckConnections(this.block, parent, 'TEXT');
|
connectParentAndCheckConnections(this.block, parent, 'TEXT');
|
||||||
|
|
||||||
let string1 = this.workspace.newBlock('text');
|
const string1 = this.workspace.newBlock('text');
|
||||||
let string2 = this.workspace.newBlock('text_charAt');
|
const string2 = this.workspace.newBlock('text_charAt');
|
||||||
|
|
||||||
connectInputsAndCheckConnections(this.block, string1, string2, parent);
|
connectInputsAndCheckConnections(this.block, string1, string2, parent);
|
||||||
});
|
});
|
||||||
test('Attach inputs different types with unchecked parent', function() {
|
test('Attach inputs different types with unchecked parent', function() {
|
||||||
let parent = this.workspace.newBlock('text_print');
|
const parent = this.workspace.newBlock('text_print');
|
||||||
|
|
||||||
connectParentAndCheckConnections(this.block, parent, 'TEXT');
|
connectParentAndCheckConnections(this.block, parent, 'TEXT');
|
||||||
|
|
||||||
let string = this.workspace.newBlock('text');
|
const string = this.workspace.newBlock('text');
|
||||||
let number = this.workspace.newBlock('math_number');
|
const number = this.workspace.newBlock('math_number');
|
||||||
|
|
||||||
connectInputsAndCheckConnections(this.block, string, number, parent);
|
connectInputsAndCheckConnections(this.block, string, number, parent);
|
||||||
});
|
});
|
||||||
test('Attach inputs different types with permissive parent', function() {
|
test('Attach inputs different types with permissive parent', function() {
|
||||||
let parent = this.workspace.newBlock('text_length'); // Allows String or Array
|
const parent = this.workspace.newBlock('text_length'); // Allows String or Array
|
||||||
|
|
||||||
connectParentAndCheckConnections(this.block, parent, 'VALUE');
|
connectParentAndCheckConnections(this.block, parent, 'VALUE');
|
||||||
|
|
||||||
let string = this.workspace.newBlock('text');
|
const string = this.workspace.newBlock('text');
|
||||||
let array = this.workspace.newBlock('lists_create_empty');
|
const array = this.workspace.newBlock('lists_create_empty');
|
||||||
|
|
||||||
connectInputsAndCheckConnections(this.block, string, array, parent);
|
connectInputsAndCheckConnections(this.block, string, array, parent);
|
||||||
});
|
});
|
||||||
test('Attach mismatch type to then causes break with parent', function() {
|
test('Attach mismatch type to then causes break with parent', function() {
|
||||||
let parent = this.workspace.newBlock('text_length'); // Allows String or Array
|
const parent = this.workspace.newBlock('text_length'); // Allows String or Array
|
||||||
|
|
||||||
connectParentAndCheckConnections(this.block, parent, 'VALUE');
|
connectParentAndCheckConnections(this.block, parent, 'VALUE');
|
||||||
|
|
||||||
let string = this.workspace.newBlock('text');
|
const string = this.workspace.newBlock('text');
|
||||||
let number = this.workspace.newBlock('math_number');
|
const number = this.workspace.newBlock('math_number');
|
||||||
|
|
||||||
connectElseInputAndCheckConnections(this.block, string, null, parent);
|
connectElseInputAndCheckConnections(this.block, string, null, parent);
|
||||||
|
|
||||||
@@ -188,12 +188,12 @@ suite('Logic ternary', function() {
|
|||||||
'Disconnected from parent');
|
'Disconnected from parent');
|
||||||
});
|
});
|
||||||
test('Attach mismatch type to else causes break with parent', function() {
|
test('Attach mismatch type to else causes break with parent', function() {
|
||||||
let parent = this.workspace.newBlock('text_length'); // Allows String or Array
|
const parent = this.workspace.newBlock('text_length'); // Allows String or Array
|
||||||
|
|
||||||
connectParentAndCheckConnections(this.block, parent, 'VALUE');
|
connectParentAndCheckConnections(this.block, parent, 'VALUE');
|
||||||
|
|
||||||
let string = this.workspace.newBlock('text');
|
const string = this.workspace.newBlock('text');
|
||||||
let number = this.workspace.newBlock('math_number');
|
const number = this.workspace.newBlock('math_number');
|
||||||
|
|
||||||
connectThenInputAndCheckConnections(this.block, string, null, parent);
|
connectThenInputAndCheckConnections(this.block, string, null, parent);
|
||||||
|
|
||||||
@@ -205,44 +205,44 @@ suite('Logic ternary', function() {
|
|||||||
});
|
});
|
||||||
suite('Attaching parent after inputs', function() {
|
suite('Attaching parent after inputs', function() {
|
||||||
test('Unchecked parent with inputs different types', function() {
|
test('Unchecked parent with inputs different types', function() {
|
||||||
let string = this.workspace.newBlock('text');
|
const string = this.workspace.newBlock('text');
|
||||||
let number = this.workspace.newBlock('math_number');
|
const number = this.workspace.newBlock('math_number');
|
||||||
|
|
||||||
connectInputsAndCheckConnections(this.block, string, number);
|
connectInputsAndCheckConnections(this.block, string, number);
|
||||||
|
|
||||||
let parent = this.workspace.newBlock('text_print');
|
const parent = this.workspace.newBlock('text_print');
|
||||||
connectParentAndCheckConnections(
|
connectParentAndCheckConnections(
|
||||||
this.block, parent, 'TEXT', string, number);
|
this.block, parent, 'TEXT', string, number);
|
||||||
});
|
});
|
||||||
test('Permissive parent with inputs different types', function() {
|
test('Permissive parent with inputs different types', function() {
|
||||||
let string = this.workspace.newBlock('text');
|
const string = this.workspace.newBlock('text');
|
||||||
let array = this.workspace.newBlock('lists_create_empty');
|
const array = this.workspace.newBlock('lists_create_empty');
|
||||||
|
|
||||||
connectInputsAndCheckConnections(this.block, string, array);
|
connectInputsAndCheckConnections(this.block, string, array);
|
||||||
|
|
||||||
let parent = this.workspace.newBlock('text_print');
|
const parent = this.workspace.newBlock('text_print');
|
||||||
connectParentAndCheckConnections(
|
connectParentAndCheckConnections(
|
||||||
this.block, parent, 'TEXT', string, array);
|
this.block, parent, 'TEXT', string, array);
|
||||||
});
|
});
|
||||||
test('Mismatch with then causes break with then', function() {
|
test('Mismatch with then causes break with then', function() {
|
||||||
let number = this.workspace.newBlock('math_number');
|
const number = this.workspace.newBlock('math_number');
|
||||||
let string = this.workspace.newBlock('text');
|
const string = this.workspace.newBlock('text');
|
||||||
|
|
||||||
connectInputsAndCheckConnections(this.block, number, string);
|
connectInputsAndCheckConnections(this.block, number, string);
|
||||||
|
|
||||||
let parent = this.workspace.newBlock('text_trim');
|
const parent = this.workspace.newBlock('text_trim');
|
||||||
connectParentAndCheckConnections(
|
connectParentAndCheckConnections(
|
||||||
this.block, parent, 'TEXT', null, string);
|
this.block, parent, 'TEXT', null, string);
|
||||||
chai.assert.equal(number.getRootBlock(), number,
|
chai.assert.equal(number.getRootBlock(), number,
|
||||||
'Input THEN disconnected');
|
'Input THEN disconnected');
|
||||||
});
|
});
|
||||||
test('Mismatch with else causes break with else', function() {
|
test('Mismatch with else causes break with else', function() {
|
||||||
let string = this.workspace.newBlock('text');
|
const string = this.workspace.newBlock('text');
|
||||||
let number = this.workspace.newBlock('math_number');
|
const number = this.workspace.newBlock('math_number');
|
||||||
|
|
||||||
connectInputsAndCheckConnections(this.block, string, number);
|
connectInputsAndCheckConnections(this.block, string, number);
|
||||||
|
|
||||||
let parent = this.workspace.newBlock('text_trim');
|
const parent = this.workspace.newBlock('text_trim');
|
||||||
connectParentAndCheckConnections(this.block, parent, 'TEXT', string);
|
connectParentAndCheckConnections(this.block, parent, 'TEXT', string);
|
||||||
chai.assert.equal(number.getRootBlock(), number,
|
chai.assert.equal(number.getRootBlock(), number,
|
||||||
'Input ELSE disconnected');
|
'Input ELSE disconnected');
|
||||||
|
|||||||
@@ -10,8 +10,8 @@ const {sharedTestSetup, sharedTestTeardown} = goog.require('Blockly.test.helpers
|
|||||||
|
|
||||||
|
|
||||||
suite('Metrics', function() {
|
suite('Metrics', function() {
|
||||||
let SCROLL_X = 10;
|
const SCROLL_X = 10;
|
||||||
let SCROLL_Y = 10;
|
const SCROLL_Y = 10;
|
||||||
function assertDimensionsMatch(toCheck, left, top, width, height) {
|
function assertDimensionsMatch(toCheck, left, top, width, height) {
|
||||||
chai.assert.equal(top, toCheck.top, 'Top did not match.');
|
chai.assert.equal(top, toCheck.top, 'Top did not match.');
|
||||||
chai.assert.equal(left, toCheck.left, 'Left did not match.');
|
chai.assert.equal(left, toCheck.left, 'Left did not match.');
|
||||||
@@ -62,7 +62,7 @@ suite('Metrics', function() {
|
|||||||
this.getToolboxStub.returns(true);
|
this.getToolboxStub.returns(true);
|
||||||
this.getFlyoutStub.returns(false);
|
this.getFlyoutStub.returns(false);
|
||||||
|
|
||||||
let absoluteMetrics = this.metricsManager.getAbsoluteMetrics();
|
const absoluteMetrics = this.metricsManager.getAbsoluteMetrics();
|
||||||
|
|
||||||
assertDimensionsMatch(absoluteMetrics, 107, 0);
|
assertDimensionsMatch(absoluteMetrics, 107, 0);
|
||||||
});
|
});
|
||||||
@@ -72,7 +72,7 @@ suite('Metrics', function() {
|
|||||||
this.getToolboxStub.returns(true);
|
this.getToolboxStub.returns(true);
|
||||||
this.getFlyoutStub.returns(false);
|
this.getFlyoutStub.returns(false);
|
||||||
|
|
||||||
let absoluteMetrics = this.metricsManager.getAbsoluteMetrics();
|
const absoluteMetrics = this.metricsManager.getAbsoluteMetrics();
|
||||||
|
|
||||||
assertDimensionsMatch(absoluteMetrics, 0, 107);
|
assertDimensionsMatch(absoluteMetrics, 0, 107);
|
||||||
});
|
});
|
||||||
@@ -82,7 +82,7 @@ suite('Metrics', function() {
|
|||||||
this.getToolboxStub.returns(false);
|
this.getToolboxStub.returns(false);
|
||||||
this.getFlyoutStub.returns(true);
|
this.getFlyoutStub.returns(true);
|
||||||
|
|
||||||
let absoluteMetrics = this.metricsManager.getAbsoluteMetrics();
|
const absoluteMetrics = this.metricsManager.getAbsoluteMetrics();
|
||||||
|
|
||||||
assertDimensionsMatch(absoluteMetrics, 107, 0);
|
assertDimensionsMatch(absoluteMetrics, 107, 0);
|
||||||
});
|
});
|
||||||
@@ -92,7 +92,7 @@ suite('Metrics', function() {
|
|||||||
this.getToolboxStub.returns(false);
|
this.getToolboxStub.returns(false);
|
||||||
this.getFlyoutStub.returns(true);
|
this.getFlyoutStub.returns(true);
|
||||||
|
|
||||||
let absoluteMetrics = this.metricsManager.getAbsoluteMetrics();
|
const absoluteMetrics = this.metricsManager.getAbsoluteMetrics();
|
||||||
|
|
||||||
assertDimensionsMatch(absoluteMetrics, 0, 107);
|
assertDimensionsMatch(absoluteMetrics, 0, 107);
|
||||||
});
|
});
|
||||||
@@ -119,7 +119,7 @@ suite('Metrics', function() {
|
|||||||
this.getToolboxStub.returns(true);
|
this.getToolboxStub.returns(true);
|
||||||
this.getFlyoutStub.returns(false);
|
this.getFlyoutStub.returns(false);
|
||||||
|
|
||||||
let viewMetrics = this.metricsManager.getViewMetrics();
|
const viewMetrics = this.metricsManager.getViewMetrics();
|
||||||
|
|
||||||
assertDimensionsMatch(viewMetrics, -SCROLL_X, -SCROLL_Y, 393, 500);
|
assertDimensionsMatch(viewMetrics, -SCROLL_X, -SCROLL_Y, 393, 500);
|
||||||
});
|
});
|
||||||
@@ -130,7 +130,7 @@ suite('Metrics', function() {
|
|||||||
this.getToolboxStub.returns(true);
|
this.getToolboxStub.returns(true);
|
||||||
this.getFlyoutStub.returns(false);
|
this.getFlyoutStub.returns(false);
|
||||||
|
|
||||||
let viewMetrics = this.metricsManager.getViewMetrics();
|
const viewMetrics = this.metricsManager.getViewMetrics();
|
||||||
|
|
||||||
assertDimensionsMatch(viewMetrics, -SCROLL_X, -SCROLL_Y, 500, 393);
|
assertDimensionsMatch(viewMetrics, -SCROLL_X, -SCROLL_Y, 500, 393);
|
||||||
});
|
});
|
||||||
@@ -141,7 +141,7 @@ suite('Metrics', function() {
|
|||||||
this.getToolboxStub.returns(false);
|
this.getToolboxStub.returns(false);
|
||||||
this.getFlyoutStub.returns(true);
|
this.getFlyoutStub.returns(true);
|
||||||
|
|
||||||
let viewMetrics = this.metricsManager.getViewMetrics();
|
const viewMetrics = this.metricsManager.getViewMetrics();
|
||||||
|
|
||||||
assertDimensionsMatch(viewMetrics, -SCROLL_X, -SCROLL_Y, 393, 500);
|
assertDimensionsMatch(viewMetrics, -SCROLL_X, -SCROLL_Y, 393, 500);
|
||||||
});
|
});
|
||||||
@@ -152,13 +152,13 @@ suite('Metrics', function() {
|
|||||||
this.getToolboxStub.returns(false);
|
this.getToolboxStub.returns(false);
|
||||||
this.getFlyoutStub.returns(true);
|
this.getFlyoutStub.returns(true);
|
||||||
|
|
||||||
let viewMetrics = this.metricsManager.getViewMetrics();
|
const viewMetrics = this.metricsManager.getViewMetrics();
|
||||||
|
|
||||||
assertDimensionsMatch(viewMetrics, -SCROLL_X, -SCROLL_Y, 500, 393);
|
assertDimensionsMatch(viewMetrics, -SCROLL_X, -SCROLL_Y, 500, 393);
|
||||||
});
|
});
|
||||||
test('Get view metrics in workspace coordinates ', function() {
|
test('Get view metrics in workspace coordinates ', function() {
|
||||||
let scale = 2;
|
const scale = 2;
|
||||||
let getWorkspaceCoordinates = true;
|
const getWorkspaceCoordinates = true;
|
||||||
|
|
||||||
this.ws.scale = scale;
|
this.ws.scale = scale;
|
||||||
this.toolboxMetricsStub.returns({});
|
this.toolboxMetricsStub.returns({});
|
||||||
@@ -167,7 +167,7 @@ suite('Metrics', function() {
|
|||||||
this.getToolboxStub.returns(false);
|
this.getToolboxStub.returns(false);
|
||||||
this.getFlyoutStub.returns(true);
|
this.getFlyoutStub.returns(true);
|
||||||
|
|
||||||
let viewMetrics =
|
const viewMetrics =
|
||||||
this.metricsManager.getViewMetrics(getWorkspaceCoordinates);
|
this.metricsManager.getViewMetrics(getWorkspaceCoordinates);
|
||||||
|
|
||||||
assertDimensionsMatch(
|
assertDimensionsMatch(
|
||||||
@@ -178,158 +178,158 @@ suite('Metrics', function() {
|
|||||||
|
|
||||||
suite('getContentMetrics', function() {
|
suite('getContentMetrics', function() {
|
||||||
test('Empty in ws coordinates', function() {
|
test('Empty in ws coordinates', function() {
|
||||||
let ws = makeMockWs(1, 0, 0, 0, 0);
|
const ws = makeMockWs(1, 0, 0, 0, 0);
|
||||||
let metricsManager = new Blockly.MetricsManager(ws);
|
const metricsManager = new Blockly.MetricsManager(ws);
|
||||||
let contentMetrics = metricsManager.getContentMetrics(true);
|
const contentMetrics = metricsManager.getContentMetrics(true);
|
||||||
assertDimensionsMatch(contentMetrics, 0, 0, 0, 0);
|
assertDimensionsMatch(contentMetrics, 0, 0, 0, 0);
|
||||||
});
|
});
|
||||||
test('Empty zoom-in in ws coordinates', function() {
|
test('Empty zoom-in in ws coordinates', function() {
|
||||||
let ws = makeMockWs(2, 0, 0, 0, 0);
|
const ws = makeMockWs(2, 0, 0, 0, 0);
|
||||||
let metricsManager = new Blockly.MetricsManager(ws);
|
const metricsManager = new Blockly.MetricsManager(ws);
|
||||||
let contentMetrics = metricsManager.getContentMetrics(true);
|
const contentMetrics = metricsManager.getContentMetrics(true);
|
||||||
assertDimensionsMatch(contentMetrics, 0, 0, 0, 0);
|
assertDimensionsMatch(contentMetrics, 0, 0, 0, 0);
|
||||||
});
|
});
|
||||||
test('Empty zoom-out in ws coordinates', function() {
|
test('Empty zoom-out in ws coordinates', function() {
|
||||||
let ws = makeMockWs(.5, 0, 0, 0, 0);
|
const ws = makeMockWs(.5, 0, 0, 0, 0);
|
||||||
let metricsManager = new Blockly.MetricsManager(ws);
|
const metricsManager = new Blockly.MetricsManager(ws);
|
||||||
let contentMetrics = metricsManager.getContentMetrics(true);
|
const contentMetrics = metricsManager.getContentMetrics(true);
|
||||||
assertDimensionsMatch(contentMetrics, 0, 0, 0, 0);
|
assertDimensionsMatch(contentMetrics, 0, 0, 0, 0);
|
||||||
});
|
});
|
||||||
test('Non empty at origin ws coordinates', function() {
|
test('Non empty at origin ws coordinates', function() {
|
||||||
let ws = makeMockWs(1, 0, 0, 100, 100);
|
const ws = makeMockWs(1, 0, 0, 100, 100);
|
||||||
let metricsManager = new Blockly.MetricsManager(ws);
|
const metricsManager = new Blockly.MetricsManager(ws);
|
||||||
let contentMetrics = metricsManager.getContentMetrics(true);
|
const contentMetrics = metricsManager.getContentMetrics(true);
|
||||||
assertDimensionsMatch(contentMetrics, 0, 0, 100, 100);
|
assertDimensionsMatch(contentMetrics, 0, 0, 100, 100);
|
||||||
});
|
});
|
||||||
test('Non empty at origin zoom-in ws coordinates', function() {
|
test('Non empty at origin zoom-in ws coordinates', function() {
|
||||||
let ws = makeMockWs(2, 0, 0, 100, 100);
|
const ws = makeMockWs(2, 0, 0, 100, 100);
|
||||||
let metricsManager = new Blockly.MetricsManager(ws);
|
const metricsManager = new Blockly.MetricsManager(ws);
|
||||||
let contentMetrics = metricsManager.getContentMetrics(true);
|
const contentMetrics = metricsManager.getContentMetrics(true);
|
||||||
assertDimensionsMatch(contentMetrics, 0, 0, 100, 100);
|
assertDimensionsMatch(contentMetrics, 0, 0, 100, 100);
|
||||||
});
|
});
|
||||||
test('Non empty at origin zoom-out ws coordinates', function() {
|
test('Non empty at origin zoom-out ws coordinates', function() {
|
||||||
let ws = makeMockWs(.5, 0, 0, 100, 100);
|
const ws = makeMockWs(.5, 0, 0, 100, 100);
|
||||||
let metricsManager = new Blockly.MetricsManager(ws);
|
const metricsManager = new Blockly.MetricsManager(ws);
|
||||||
let contentMetrics = metricsManager.getContentMetrics(true);
|
const contentMetrics = metricsManager.getContentMetrics(true);
|
||||||
assertDimensionsMatch(contentMetrics, 0, 0, 100, 100);
|
assertDimensionsMatch(contentMetrics, 0, 0, 100, 100);
|
||||||
});
|
});
|
||||||
test('Non empty positive origin ws coordinates', function() {
|
test('Non empty positive origin ws coordinates', function() {
|
||||||
let ws = makeMockWs(1, 10, 10, 100, 100);
|
const ws = makeMockWs(1, 10, 10, 100, 100);
|
||||||
let metricsManager = new Blockly.MetricsManager(ws);
|
const metricsManager = new Blockly.MetricsManager(ws);
|
||||||
let contentMetrics = metricsManager.getContentMetrics(true);
|
const contentMetrics = metricsManager.getContentMetrics(true);
|
||||||
assertDimensionsMatch(contentMetrics, 10, 10, 100, 100);
|
assertDimensionsMatch(contentMetrics, 10, 10, 100, 100);
|
||||||
});
|
});
|
||||||
test('Non empty positive origin zoom-in ws coordinates', function() {
|
test('Non empty positive origin zoom-in ws coordinates', function() {
|
||||||
let ws = makeMockWs(2, 10, 10, 100, 100);
|
const ws = makeMockWs(2, 10, 10, 100, 100);
|
||||||
let metricsManager = new Blockly.MetricsManager(ws);
|
const metricsManager = new Blockly.MetricsManager(ws);
|
||||||
let contentMetrics = metricsManager.getContentMetrics(true);
|
const contentMetrics = metricsManager.getContentMetrics(true);
|
||||||
// 1 ws unit = 2 pixels at this zoom level.
|
// 1 ws unit = 2 pixels at this zoom level.
|
||||||
assertDimensionsMatch(contentMetrics, 10, 10, 100, 100);
|
assertDimensionsMatch(contentMetrics, 10, 10, 100, 100);
|
||||||
});
|
});
|
||||||
test('Non empty positive origin zoom-out ws coordinates', function() {
|
test('Non empty positive origin zoom-out ws coordinates', function() {
|
||||||
let ws = makeMockWs(.5, 10, 10, 100, 100);
|
const ws = makeMockWs(.5, 10, 10, 100, 100);
|
||||||
let metricsManager = new Blockly.MetricsManager(ws);
|
const metricsManager = new Blockly.MetricsManager(ws);
|
||||||
let contentMetrics = metricsManager.getContentMetrics(true);
|
const contentMetrics = metricsManager.getContentMetrics(true);
|
||||||
// 1 ws unit = 0.5 pixels at this zoom level.
|
// 1 ws unit = 0.5 pixels at this zoom level.
|
||||||
assertDimensionsMatch(contentMetrics, 10, 10, 100, 100);
|
assertDimensionsMatch(contentMetrics, 10, 10, 100, 100);
|
||||||
});
|
});
|
||||||
test('Non empty negative origin ws coordinates', function() {
|
test('Non empty negative origin ws coordinates', function() {
|
||||||
let ws = makeMockWs(1, -10, -10, 100, 100);
|
const ws = makeMockWs(1, -10, -10, 100, 100);
|
||||||
let metricsManager = new Blockly.MetricsManager(ws);
|
const metricsManager = new Blockly.MetricsManager(ws);
|
||||||
let contentMetrics = metricsManager.getContentMetrics(true);
|
const contentMetrics = metricsManager.getContentMetrics(true);
|
||||||
// Pixel and ws units are the same at default zoom.
|
// Pixel and ws units are the same at default zoom.
|
||||||
assertDimensionsMatch(contentMetrics, -10, -10, 100, 100);
|
assertDimensionsMatch(contentMetrics, -10, -10, 100, 100);
|
||||||
});
|
});
|
||||||
test('Non empty negative origin zoom-in ws coordinates', function() {
|
test('Non empty negative origin zoom-in ws coordinates', function() {
|
||||||
let ws = makeMockWs(2, -10, -10, 100, 100);
|
const ws = makeMockWs(2, -10, -10, 100, 100);
|
||||||
let metricsManager = new Blockly.MetricsManager(ws);
|
const metricsManager = new Blockly.MetricsManager(ws);
|
||||||
let contentMetrics = metricsManager.getContentMetrics(true);
|
const contentMetrics = metricsManager.getContentMetrics(true);
|
||||||
assertDimensionsMatch(contentMetrics, -10, -10, 100, 100);
|
assertDimensionsMatch(contentMetrics, -10, -10, 100, 100);
|
||||||
});
|
});
|
||||||
test('Non empty negative origin zoom-out ws coordinates', function() {
|
test('Non empty negative origin zoom-out ws coordinates', function() {
|
||||||
let ws = makeMockWs(.5, -10, -10, 100, 100);
|
const ws = makeMockWs(.5, -10, -10, 100, 100);
|
||||||
let metricsManager = new Blockly.MetricsManager(ws);
|
const metricsManager = new Blockly.MetricsManager(ws);
|
||||||
let contentMetrics = metricsManager.getContentMetrics(true);
|
const contentMetrics = metricsManager.getContentMetrics(true);
|
||||||
assertDimensionsMatch(contentMetrics, -10, -10, 100, 100);
|
assertDimensionsMatch(contentMetrics, -10, -10, 100, 100);
|
||||||
});
|
});
|
||||||
test('Empty in pixel coordinates', function() {
|
test('Empty in pixel coordinates', function() {
|
||||||
let ws = makeMockWs(1, 0, 0, 0, 0);
|
const ws = makeMockWs(1, 0, 0, 0, 0);
|
||||||
let metricsManager = new Blockly.MetricsManager(ws);
|
const metricsManager = new Blockly.MetricsManager(ws);
|
||||||
let contentMetrics = metricsManager.getContentMetrics(false);
|
const contentMetrics = metricsManager.getContentMetrics(false);
|
||||||
assertDimensionsMatch(contentMetrics, 0, 0, 0, 0);
|
assertDimensionsMatch(contentMetrics, 0, 0, 0, 0);
|
||||||
});
|
});
|
||||||
test('Empty zoom-in in pixel coordinates', function() {
|
test('Empty zoom-in in pixel coordinates', function() {
|
||||||
let ws = makeMockWs(2, 0, 0, 0, 0);
|
const ws = makeMockWs(2, 0, 0, 0, 0);
|
||||||
let metricsManager = new Blockly.MetricsManager(ws);
|
const metricsManager = new Blockly.MetricsManager(ws);
|
||||||
let contentMetrics = metricsManager.getContentMetrics(false);
|
const contentMetrics = metricsManager.getContentMetrics(false);
|
||||||
assertDimensionsMatch(contentMetrics, 0, 0, 0, 0);
|
assertDimensionsMatch(contentMetrics, 0, 0, 0, 0);
|
||||||
});
|
});
|
||||||
test('Empty zoom-out in pixel coordinates', function() {
|
test('Empty zoom-out in pixel coordinates', function() {
|
||||||
let ws = makeMockWs(.5, 0, 0, 0, 0);
|
const ws = makeMockWs(.5, 0, 0, 0, 0);
|
||||||
let metricsManager = new Blockly.MetricsManager(ws);
|
const metricsManager = new Blockly.MetricsManager(ws);
|
||||||
let contentMetrics = metricsManager.getContentMetrics(false);
|
const contentMetrics = metricsManager.getContentMetrics(false);
|
||||||
assertDimensionsMatch(contentMetrics, 0, 0, 0, 0);
|
assertDimensionsMatch(contentMetrics, 0, 0, 0, 0);
|
||||||
});
|
});
|
||||||
test('Non empty at origin pixel coordinates', function() {
|
test('Non empty at origin pixel coordinates', function() {
|
||||||
let ws = makeMockWs(1, 0, 0, 100, 100);
|
const ws = makeMockWs(1, 0, 0, 100, 100);
|
||||||
let metricsManager = new Blockly.MetricsManager(ws);
|
const metricsManager = new Blockly.MetricsManager(ws);
|
||||||
let contentMetrics = metricsManager.getContentMetrics(false);
|
const contentMetrics = metricsManager.getContentMetrics(false);
|
||||||
// Pixel and ws units are the same at default zoom.
|
// Pixel and ws units are the same at default zoom.
|
||||||
assertDimensionsMatch(contentMetrics, 0, 0, 100, 100);
|
assertDimensionsMatch(contentMetrics, 0, 0, 100, 100);
|
||||||
});
|
});
|
||||||
test('Non empty at origin zoom-in pixel coordinates', function() {
|
test('Non empty at origin zoom-in pixel coordinates', function() {
|
||||||
let ws = makeMockWs(2, 0, 0, 100, 100);
|
const ws = makeMockWs(2, 0, 0, 100, 100);
|
||||||
let metricsManager = new Blockly.MetricsManager(ws);
|
const metricsManager = new Blockly.MetricsManager(ws);
|
||||||
let contentMetrics = metricsManager.getContentMetrics(false);
|
const contentMetrics = metricsManager.getContentMetrics(false);
|
||||||
// 1 ws unit = 2 pixels at this zoom level.
|
// 1 ws unit = 2 pixels at this zoom level.
|
||||||
assertDimensionsMatch(contentMetrics, 0, 0, 200, 200);
|
assertDimensionsMatch(contentMetrics, 0, 0, 200, 200);
|
||||||
});
|
});
|
||||||
test('Non empty at origin zoom-out pixel coordinates', function() {
|
test('Non empty at origin zoom-out pixel coordinates', function() {
|
||||||
let ws = makeMockWs(.5, 0, 0, 100, 100);
|
const ws = makeMockWs(.5, 0, 0, 100, 100);
|
||||||
let metricsManager = new Blockly.MetricsManager(ws);
|
const metricsManager = new Blockly.MetricsManager(ws);
|
||||||
let contentMetrics = metricsManager.getContentMetrics(false);
|
const contentMetrics = metricsManager.getContentMetrics(false);
|
||||||
// 1 ws unit = 0.5 pixels at this zoom level.
|
// 1 ws unit = 0.5 pixels at this zoom level.
|
||||||
assertDimensionsMatch(contentMetrics, 0, 0, 50, 50);
|
assertDimensionsMatch(contentMetrics, 0, 0, 50, 50);
|
||||||
});
|
});
|
||||||
test('Non empty positive origin pixel coordinates', function() {
|
test('Non empty positive origin pixel coordinates', function() {
|
||||||
let ws = makeMockWs(1, 10, 10, 100, 100);
|
const ws = makeMockWs(1, 10, 10, 100, 100);
|
||||||
let metricsManager = new Blockly.MetricsManager(ws);
|
const metricsManager = new Blockly.MetricsManager(ws);
|
||||||
let contentMetrics = metricsManager.getContentMetrics(false);
|
const contentMetrics = metricsManager.getContentMetrics(false);
|
||||||
// Pixel and ws units are the same at default zoom.
|
// Pixel and ws units are the same at default zoom.
|
||||||
assertDimensionsMatch(contentMetrics, 10, 10, 100, 100);
|
assertDimensionsMatch(contentMetrics, 10, 10, 100, 100);
|
||||||
});
|
});
|
||||||
test('Non empty positive origin zoom-in pixel coordinates', function() {
|
test('Non empty positive origin zoom-in pixel coordinates', function() {
|
||||||
let ws = makeMockWs(2, 10, 10, 100, 100);
|
const ws = makeMockWs(2, 10, 10, 100, 100);
|
||||||
let metricsManager = new Blockly.MetricsManager(ws);
|
const metricsManager = new Blockly.MetricsManager(ws);
|
||||||
let contentMetrics = metricsManager.getContentMetrics(false);
|
const contentMetrics = metricsManager.getContentMetrics(false);
|
||||||
// 1 ws unit = 2 pixels at this zoom level.
|
// 1 ws unit = 2 pixels at this zoom level.
|
||||||
assertDimensionsMatch(contentMetrics, 20, 20, 200, 200);
|
assertDimensionsMatch(contentMetrics, 20, 20, 200, 200);
|
||||||
});
|
});
|
||||||
test('Non empty positive origin zoom-out pixel coordinates', function() {
|
test('Non empty positive origin zoom-out pixel coordinates', function() {
|
||||||
let ws = makeMockWs(.5, 10, 10, 100, 100);
|
const ws = makeMockWs(.5, 10, 10, 100, 100);
|
||||||
let metricsManager = new Blockly.MetricsManager(ws);
|
const metricsManager = new Blockly.MetricsManager(ws);
|
||||||
let contentMetrics = metricsManager.getContentMetrics(false);
|
const contentMetrics = metricsManager.getContentMetrics(false);
|
||||||
// 1 ws unit = 0.5 pixels at this zoom level.
|
// 1 ws unit = 0.5 pixels at this zoom level.
|
||||||
assertDimensionsMatch(contentMetrics, 5, 5, 50, 50);
|
assertDimensionsMatch(contentMetrics, 5, 5, 50, 50);
|
||||||
});
|
});
|
||||||
test('Non empty negative origin pixel coordinates', function() {
|
test('Non empty negative origin pixel coordinates', function() {
|
||||||
let ws = makeMockWs(1, -10, -10, 100, 100);
|
const ws = makeMockWs(1, -10, -10, 100, 100);
|
||||||
let metricsManager = new Blockly.MetricsManager(ws);
|
const metricsManager = new Blockly.MetricsManager(ws);
|
||||||
let contentMetrics = metricsManager.getContentMetrics(false);
|
const contentMetrics = metricsManager.getContentMetrics(false);
|
||||||
// Pixel and ws units are the same at default zoom.
|
// Pixel and ws units are the same at default zoom.
|
||||||
assertDimensionsMatch(contentMetrics, -10, -10, 100, 100);
|
assertDimensionsMatch(contentMetrics, -10, -10, 100, 100);
|
||||||
});
|
});
|
||||||
test('Non empty negative origin zoom-in pixel coordinates', function() {
|
test('Non empty negative origin zoom-in pixel coordinates', function() {
|
||||||
let ws = makeMockWs(2, -10, -10, 100, 100);
|
const ws = makeMockWs(2, -10, -10, 100, 100);
|
||||||
let metricsManager = new Blockly.MetricsManager(ws);
|
const metricsManager = new Blockly.MetricsManager(ws);
|
||||||
let contentMetrics = metricsManager.getContentMetrics(false);
|
const contentMetrics = metricsManager.getContentMetrics(false);
|
||||||
// 1 ws unit = 2 pixels at this zoom level.
|
// 1 ws unit = 2 pixels at this zoom level.
|
||||||
assertDimensionsMatch(contentMetrics, -20, -20, 200, 200);
|
assertDimensionsMatch(contentMetrics, -20, -20, 200, 200);
|
||||||
});
|
});
|
||||||
test('Non empty negative origin zoom-out pixel coordinates', function() {
|
test('Non empty negative origin zoom-out pixel coordinates', function() {
|
||||||
let ws = makeMockWs(.5, -10, -10, 100, 100);
|
const ws = makeMockWs(.5, -10, -10, 100, 100);
|
||||||
let metricsManager = new Blockly.MetricsManager(ws);
|
const metricsManager = new Blockly.MetricsManager(ws);
|
||||||
let contentMetrics = metricsManager.getContentMetrics(false);
|
const contentMetrics = metricsManager.getContentMetrics(false);
|
||||||
// 1 ws unit = 0.5 pixels at this zoom level.
|
// 1 ws unit = 0.5 pixels at this zoom level.
|
||||||
assertDimensionsMatch(contentMetrics, -5, -5, 50, 50);
|
assertDimensionsMatch(contentMetrics, -5, -5, 50, 50);
|
||||||
});
|
});
|
||||||
@@ -337,168 +337,168 @@ suite('Metrics', function() {
|
|||||||
|
|
||||||
suite('getScrollMetrics', function() {
|
suite('getScrollMetrics', function() {
|
||||||
test('Empty workspace in ws coordinates', function() {
|
test('Empty workspace in ws coordinates', function() {
|
||||||
let ws = makeMockWs(1, 0, 0, 0, 0);
|
const ws = makeMockWs(1, 0, 0, 0, 0);
|
||||||
let metricsManager = new Blockly.MetricsManager(ws);
|
const metricsManager = new Blockly.MetricsManager(ws);
|
||||||
// The location of the viewport.
|
// The location of the viewport.
|
||||||
let mockViewMetrics = {top: 0, left: 0, width: 200, height: 200};
|
const mockViewMetrics = {top: 0, left: 0, width: 200, height: 200};
|
||||||
// The bounding box around the blocks on the screen.
|
// The bounding box around the blocks on the screen.
|
||||||
let mockContentMetrics = {top: 0, left: 0, width: 0, height: 0};
|
const mockContentMetrics = {top: 0, left: 0, width: 0, height: 0};
|
||||||
|
|
||||||
let contentMetrics =
|
const contentMetrics =
|
||||||
metricsManager.getScrollMetrics(true, mockViewMetrics, mockContentMetrics);
|
metricsManager.getScrollMetrics(true, mockViewMetrics, mockContentMetrics);
|
||||||
|
|
||||||
// Should add half the view width to all sides.
|
// Should add half the view width to all sides.
|
||||||
assertDimensionsMatch(contentMetrics, -200, -200, 400, 400);
|
assertDimensionsMatch(contentMetrics, -200, -200, 400, 400);
|
||||||
});
|
});
|
||||||
test('Empty workspace zoom-in in ws coordinates', function() {
|
test('Empty workspace zoom-in in ws coordinates', function() {
|
||||||
let ws = makeMockWs(2, 0, 0, 0, 0);
|
const ws = makeMockWs(2, 0, 0, 0, 0);
|
||||||
let metricsManager = new Blockly.MetricsManager(ws);
|
const metricsManager = new Blockly.MetricsManager(ws);
|
||||||
// The location of the viewport.
|
// The location of the viewport.
|
||||||
let mockViewMetrics = {top: 0, left: 0, width: 200, height: 200};
|
const mockViewMetrics = {top: 0, left: 0, width: 200, height: 200};
|
||||||
// The bounding box around the blocks on the screen.
|
// The bounding box around the blocks on the screen.
|
||||||
let mockContentMetrics = {top: 0, left: 0, width: 0, height: 0};
|
const mockContentMetrics = {top: 0, left: 0, width: 0, height: 0};
|
||||||
|
|
||||||
let contentMetrics =
|
const contentMetrics =
|
||||||
metricsManager.getScrollMetrics(true, mockViewMetrics, mockContentMetrics);
|
metricsManager.getScrollMetrics(true, mockViewMetrics, mockContentMetrics);
|
||||||
|
|
||||||
// Should add half the view width to all sides.
|
// Should add half the view width to all sides.
|
||||||
assertDimensionsMatch(contentMetrics, -100, -100, 200, 200);
|
assertDimensionsMatch(contentMetrics, -100, -100, 200, 200);
|
||||||
});
|
});
|
||||||
test('Empty workspace zoom-out in ws coordinates', function() {
|
test('Empty workspace zoom-out in ws coordinates', function() {
|
||||||
let ws = makeMockWs(0.5, 0, 0, 0, 0);
|
const ws = makeMockWs(0.5, 0, 0, 0, 0);
|
||||||
let metricsManager = new Blockly.MetricsManager(ws);
|
const metricsManager = new Blockly.MetricsManager(ws);
|
||||||
// The location of the viewport.
|
// The location of the viewport.
|
||||||
let mockViewMetrics = {top: 0, left: 0, width: 200, height: 200};
|
const mockViewMetrics = {top: 0, left: 0, width: 200, height: 200};
|
||||||
// The bounding box around the blocks on the screen.
|
// The bounding box around the blocks on the screen.
|
||||||
let mockContentMetrics = {top: 0, left: 0, width: 0, height: 0};
|
const mockContentMetrics = {top: 0, left: 0, width: 0, height: 0};
|
||||||
|
|
||||||
let contentMetrics =
|
const contentMetrics =
|
||||||
metricsManager.getScrollMetrics(true, mockViewMetrics, mockContentMetrics);
|
metricsManager.getScrollMetrics(true, mockViewMetrics, mockContentMetrics);
|
||||||
|
|
||||||
// Should add half the view width to all sides.
|
// Should add half the view width to all sides.
|
||||||
assertDimensionsMatch(contentMetrics, -400, -400, 800, 800);
|
assertDimensionsMatch(contentMetrics, -400, -400, 800, 800);
|
||||||
});
|
});
|
||||||
test('Non empty workspace in ws coordinates', function() {
|
test('Non empty workspace in ws coordinates', function() {
|
||||||
let ws = makeMockWs(1, 0, 0, 0, 0);
|
const ws = makeMockWs(1, 0, 0, 0, 0);
|
||||||
let metricsManager = new Blockly.MetricsManager(ws);
|
const metricsManager = new Blockly.MetricsManager(ws);
|
||||||
// The location of the viewport.
|
// The location of the viewport.
|
||||||
let mockViewMetrics = {top: 0, left: 0, width: 200, height: 200};
|
const mockViewMetrics = {top: 0, left: 0, width: 200, height: 200};
|
||||||
// The bounding box around the blocks on the screen.
|
// The bounding box around the blocks on the screen.
|
||||||
let mockContentMetrics = {top: 100, left: 100, width: 50, height: 50};
|
const mockContentMetrics = {top: 100, left: 100, width: 50, height: 50};
|
||||||
|
|
||||||
let contentMetrics =
|
const contentMetrics =
|
||||||
metricsManager.getScrollMetrics(true, mockViewMetrics, mockContentMetrics);
|
metricsManager.getScrollMetrics(true, mockViewMetrics, mockContentMetrics);
|
||||||
|
|
||||||
// Should add half of the view width to all sides.
|
// Should add half of the view width to all sides.
|
||||||
assertDimensionsMatch(contentMetrics, -50, -50, 350, 350);
|
assertDimensionsMatch(contentMetrics, -50, -50, 350, 350);
|
||||||
});
|
});
|
||||||
test('Non empty workspace zoom-in in ws coordinates', function() {
|
test('Non empty workspace zoom-in in ws coordinates', function() {
|
||||||
let ws = makeMockWs(2, 0, 0, 0, 0);
|
const ws = makeMockWs(2, 0, 0, 0, 0);
|
||||||
let metricsManager = new Blockly.MetricsManager(ws);
|
const metricsManager = new Blockly.MetricsManager(ws);
|
||||||
// The location of the viewport.
|
// The location of the viewport.
|
||||||
let mockViewMetrics = {top: 0, left: 0, width: 200, height: 200};
|
const mockViewMetrics = {top: 0, left: 0, width: 200, height: 200};
|
||||||
// The bounding box around the blocks on the screen.
|
// The bounding box around the blocks on the screen.
|
||||||
let mockContentMetrics = {top: 100, left: 100, width: 50, height: 50};
|
const mockContentMetrics = {top: 100, left: 100, width: 50, height: 50};
|
||||||
|
|
||||||
let contentMetrics =
|
const contentMetrics =
|
||||||
metricsManager.getScrollMetrics(true, mockViewMetrics, mockContentMetrics);
|
metricsManager.getScrollMetrics(true, mockViewMetrics, mockContentMetrics);
|
||||||
|
|
||||||
// Should add half of the view width to all sides.
|
// Should add half of the view width to all sides.
|
||||||
assertDimensionsMatch(contentMetrics, -25, -25, 175, 175);
|
assertDimensionsMatch(contentMetrics, -25, -25, 175, 175);
|
||||||
});
|
});
|
||||||
test('Non empty workspace zoom-out in ws coordinates', function() {
|
test('Non empty workspace zoom-out in ws coordinates', function() {
|
||||||
let ws = makeMockWs(0.5, 0, 0, 0, 0);
|
const ws = makeMockWs(0.5, 0, 0, 0, 0);
|
||||||
let metricsManager = new Blockly.MetricsManager(ws);
|
const metricsManager = new Blockly.MetricsManager(ws);
|
||||||
// The location of the viewport.
|
// The location of the viewport.
|
||||||
let mockViewMetrics = {top: 0, left: 0, width: 200, height: 200};
|
const mockViewMetrics = {top: 0, left: 0, width: 200, height: 200};
|
||||||
// The bounding box around the blocks on the screen.
|
// The bounding box around the blocks on the screen.
|
||||||
let mockContentMetrics = {top: 100, left: 100, width: 50, height: 50};
|
const mockContentMetrics = {top: 100, left: 100, width: 50, height: 50};
|
||||||
|
|
||||||
let contentMetrics =
|
const contentMetrics =
|
||||||
metricsManager.getScrollMetrics(true, mockViewMetrics, mockContentMetrics);
|
metricsManager.getScrollMetrics(true, mockViewMetrics, mockContentMetrics);
|
||||||
|
|
||||||
// Should add half of the view width to all sides.
|
// Should add half of the view width to all sides.
|
||||||
assertDimensionsMatch(contentMetrics, -100, -100, 700, 700);
|
assertDimensionsMatch(contentMetrics, -100, -100, 700, 700);
|
||||||
});
|
});
|
||||||
test('Empty workspace in pixel coordinates', function() {
|
test('Empty workspace in pixel coordinates', function() {
|
||||||
let ws = makeMockWs(1, 0, 0, 0, 0);
|
const ws = makeMockWs(1, 0, 0, 0, 0);
|
||||||
let metricsManager = new Blockly.MetricsManager(ws);
|
const metricsManager = new Blockly.MetricsManager(ws);
|
||||||
// The location of the viewport.
|
// The location of the viewport.
|
||||||
let mockViewMetrics = {top: 0, left: 0, width: 200, height: 200};
|
const mockViewMetrics = {top: 0, left: 0, width: 200, height: 200};
|
||||||
// The bounding box around the blocks on the screen.
|
// The bounding box around the blocks on the screen.
|
||||||
let mockContentMetrics = {top: 0, left: 0, width: 0, height: 0};
|
const mockContentMetrics = {top: 0, left: 0, width: 0, height: 0};
|
||||||
|
|
||||||
let contentMetrics =
|
const contentMetrics =
|
||||||
metricsManager.getScrollMetrics(false, mockViewMetrics, mockContentMetrics);
|
metricsManager.getScrollMetrics(false, mockViewMetrics, mockContentMetrics);
|
||||||
|
|
||||||
// Should add half the view width to all sides.
|
// Should add half the view width to all sides.
|
||||||
assertDimensionsMatch(contentMetrics, -200, -200, 400, 400);
|
assertDimensionsMatch(contentMetrics, -200, -200, 400, 400);
|
||||||
});
|
});
|
||||||
test('Empty workspace zoom-in in pixel coordinates', function() {
|
test('Empty workspace zoom-in in pixel coordinates', function() {
|
||||||
let ws = makeMockWs(2, 0, 0, 0, 0);
|
const ws = makeMockWs(2, 0, 0, 0, 0);
|
||||||
let metricsManager = new Blockly.MetricsManager(ws);
|
const metricsManager = new Blockly.MetricsManager(ws);
|
||||||
// The location of the viewport.
|
// The location of the viewport.
|
||||||
let mockViewMetrics = {top: 0, left: 0, width: 200, height: 200};
|
const mockViewMetrics = {top: 0, left: 0, width: 200, height: 200};
|
||||||
// The bounding box around the blocks on the screen.
|
// The bounding box around the blocks on the screen.
|
||||||
let mockContentMetrics = {top: 0, left: 0, width: 0, height: 0};
|
const mockContentMetrics = {top: 0, left: 0, width: 0, height: 0};
|
||||||
|
|
||||||
let contentMetrics =
|
const contentMetrics =
|
||||||
metricsManager.getScrollMetrics(false, mockViewMetrics, mockContentMetrics);
|
metricsManager.getScrollMetrics(false, mockViewMetrics, mockContentMetrics);
|
||||||
|
|
||||||
// Should add half the view width to all sides.
|
// Should add half the view width to all sides.
|
||||||
assertDimensionsMatch(contentMetrics, -200, -200, 400, 400);
|
assertDimensionsMatch(contentMetrics, -200, -200, 400, 400);
|
||||||
});
|
});
|
||||||
test('Empty workspace zoom-out in pixel coordinates', function() {
|
test('Empty workspace zoom-out in pixel coordinates', function() {
|
||||||
let ws = makeMockWs(0.5, 0, 0, 0, 0);
|
const ws = makeMockWs(0.5, 0, 0, 0, 0);
|
||||||
let metricsManager = new Blockly.MetricsManager(ws);
|
const metricsManager = new Blockly.MetricsManager(ws);
|
||||||
// The location of the viewport.
|
// The location of the viewport.
|
||||||
let mockViewMetrics = {top: 0, left: 0, width: 200, height: 200};
|
const mockViewMetrics = {top: 0, left: 0, width: 200, height: 200};
|
||||||
// The bounding box around the blocks on the screen.
|
// The bounding box around the blocks on the screen.
|
||||||
let mockContentMetrics = {top: 0, left: 0, width: 0, height: 0};
|
const mockContentMetrics = {top: 0, left: 0, width: 0, height: 0};
|
||||||
|
|
||||||
let contentMetrics =
|
const contentMetrics =
|
||||||
metricsManager.getScrollMetrics(false, mockViewMetrics, mockContentMetrics);
|
metricsManager.getScrollMetrics(false, mockViewMetrics, mockContentMetrics);
|
||||||
|
|
||||||
// Should add half the view width to all sides.
|
// Should add half the view width to all sides.
|
||||||
assertDimensionsMatch(contentMetrics, -200, -200, 400, 400);
|
assertDimensionsMatch(contentMetrics, -200, -200, 400, 400);
|
||||||
});
|
});
|
||||||
test('Non empty workspace in pixel coordinates', function() {
|
test('Non empty workspace in pixel coordinates', function() {
|
||||||
let ws = makeMockWs(1, 0, 0, 0, 0);
|
const ws = makeMockWs(1, 0, 0, 0, 0);
|
||||||
let metricsManager = new Blockly.MetricsManager(ws);
|
const metricsManager = new Blockly.MetricsManager(ws);
|
||||||
// The location of the viewport.
|
// The location of the viewport.
|
||||||
let mockViewMetrics = {top: 0, left: 0, width: 200, height: 200};
|
const mockViewMetrics = {top: 0, left: 0, width: 200, height: 200};
|
||||||
// The bounding box around the blocks on the screen.
|
// The bounding box around the blocks on the screen.
|
||||||
let mockContentMetrics = {top: 100, left: 100, width: 50, height: 50};
|
const mockContentMetrics = {top: 100, left: 100, width: 50, height: 50};
|
||||||
|
|
||||||
let contentMetrics =
|
const contentMetrics =
|
||||||
metricsManager.getScrollMetrics(false, mockViewMetrics, mockContentMetrics);
|
metricsManager.getScrollMetrics(false, mockViewMetrics, mockContentMetrics);
|
||||||
|
|
||||||
// Should add half of the view width to all sides.
|
// Should add half of the view width to all sides.
|
||||||
assertDimensionsMatch(contentMetrics, -50, -50, 350, 350);
|
assertDimensionsMatch(contentMetrics, -50, -50, 350, 350);
|
||||||
});
|
});
|
||||||
test('Non empty workspace zoom-in in pixel coordinates', function() {
|
test('Non empty workspace zoom-in in pixel coordinates', function() {
|
||||||
let ws = makeMockWs(2, 0, 0, 0, 0);
|
const ws = makeMockWs(2, 0, 0, 0, 0);
|
||||||
let metricsManager = new Blockly.MetricsManager(ws);
|
const metricsManager = new Blockly.MetricsManager(ws);
|
||||||
// The location of the viewport.
|
// The location of the viewport.
|
||||||
let mockViewMetrics = {top: 0, left: 0, width: 200, height: 200};
|
const mockViewMetrics = {top: 0, left: 0, width: 200, height: 200};
|
||||||
// The bounding box around the blocks on the screen.
|
// The bounding box around the blocks on the screen.
|
||||||
let mockContentMetrics = {top: 100, left: 100, width: 50, height: 50};
|
const mockContentMetrics = {top: 100, left: 100, width: 50, height: 50};
|
||||||
|
|
||||||
let contentMetrics =
|
const contentMetrics =
|
||||||
metricsManager.getScrollMetrics(false, mockViewMetrics, mockContentMetrics);
|
metricsManager.getScrollMetrics(false, mockViewMetrics, mockContentMetrics);
|
||||||
|
|
||||||
// Should add half of the view width to all sides.
|
// Should add half of the view width to all sides.
|
||||||
assertDimensionsMatch(contentMetrics, -50, -50, 350, 350);
|
assertDimensionsMatch(contentMetrics, -50, -50, 350, 350);
|
||||||
});
|
});
|
||||||
test('Non empty workspace zoom-out in pixel coordinates', function() {
|
test('Non empty workspace zoom-out in pixel coordinates', function() {
|
||||||
let ws = makeMockWs(0.5, 0, 0, 0, 0);
|
const ws = makeMockWs(0.5, 0, 0, 0, 0);
|
||||||
let metricsManager = new Blockly.MetricsManager(ws);
|
const metricsManager = new Blockly.MetricsManager(ws);
|
||||||
// The location of the viewport.
|
// The location of the viewport.
|
||||||
let mockViewMetrics = {top: 0, left: 0, width: 200, height: 200};
|
const mockViewMetrics = {top: 0, left: 0, width: 200, height: 200};
|
||||||
// The bounding box around the blocks on the screen.
|
// The bounding box around the blocks on the screen.
|
||||||
let mockContentMetrics = {top: 100, left: 100, width: 50, height: 50};
|
const mockContentMetrics = {top: 100, left: 100, width: 50, height: 50};
|
||||||
|
|
||||||
let contentMetrics =
|
const contentMetrics =
|
||||||
metricsManager.getScrollMetrics(false, mockViewMetrics, mockContentMetrics);
|
metricsManager.getScrollMetrics(false, mockViewMetrics, mockContentMetrics);
|
||||||
|
|
||||||
// Should add half of the view width to all sides.
|
// Should add half of the view width to all sides.
|
||||||
|
|||||||
@@ -28,9 +28,9 @@ suite('Mutator', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
test('No change', function() {
|
test('No change', function() {
|
||||||
let block = createRenderedBlock(this.workspace, 'xml_block');
|
const block = createRenderedBlock(this.workspace, 'xml_block');
|
||||||
block.mutator.setVisible(true);
|
block.mutator.setVisible(true);
|
||||||
let mutatorWorkspace = block.mutator.getWorkspace();
|
const mutatorWorkspace = block.mutator.getWorkspace();
|
||||||
// Trigger mutator change listener.
|
// Trigger mutator change listener.
|
||||||
createRenderedBlock(mutatorWorkspace, 'checkbox_block');
|
createRenderedBlock(mutatorWorkspace, 'checkbox_block');
|
||||||
chai.assert.isTrue(
|
chai.assert.isTrue(
|
||||||
@@ -41,9 +41,9 @@ suite('Mutator', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
test('XML', function() {
|
test('XML', function() {
|
||||||
let block = createRenderedBlock(this.workspace, 'xml_block');
|
const block = createRenderedBlock(this.workspace, 'xml_block');
|
||||||
block.mutator.setVisible(true);
|
block.mutator.setVisible(true);
|
||||||
let mutatorWorkspace = block.mutator.getWorkspace();
|
const mutatorWorkspace = block.mutator.getWorkspace();
|
||||||
mutatorWorkspace.getBlockById('check_block')
|
mutatorWorkspace.getBlockById('check_block')
|
||||||
.setFieldValue('TRUE', 'CHECK');
|
.setFieldValue('TRUE', 'CHECK');
|
||||||
chai.assert.isTrue(
|
chai.assert.isTrue(
|
||||||
@@ -55,9 +55,9 @@ suite('Mutator', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
test('JSO', function() {
|
test('JSO', function() {
|
||||||
let block = createRenderedBlock(this.workspace, 'jso_block');
|
const block = createRenderedBlock(this.workspace, 'jso_block');
|
||||||
block.mutator.setVisible(true);
|
block.mutator.setVisible(true);
|
||||||
let mutatorWorkspace = block.mutator.getWorkspace();
|
const mutatorWorkspace = block.mutator.getWorkspace();
|
||||||
mutatorWorkspace.getBlockById('check_block')
|
mutatorWorkspace.getBlockById('check_block')
|
||||||
.setFieldValue('TRUE', 'CHECK');
|
.setFieldValue('TRUE', 'CHECK');
|
||||||
chai.assert.isTrue(
|
chai.assert.isTrue(
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ suite('Names', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
test('Safe name', function() {
|
test('Safe name', function() {
|
||||||
let varDB = new Blockly.Names('window,door');
|
const varDB = new Blockly.Names('window,door');
|
||||||
chai.assert.equal(varDB.safeName_(''), 'unnamed', 'SafeName empty.');
|
chai.assert.equal(varDB.safeName_(''), 'unnamed', 'SafeName empty.');
|
||||||
chai.assert.equal(varDB.safeName_('foobar'), 'foobar', 'SafeName ok.');
|
chai.assert.equal(varDB.safeName_('foobar'), 'foobar', 'SafeName ok.');
|
||||||
chai.assert.equal(varDB.safeName_('9lives'), 'my_9lives', 'SafeName number start.');
|
chai.assert.equal(varDB.safeName_('9lives'), 'my_9lives', 'SafeName number start.');
|
||||||
@@ -28,7 +28,7 @@ suite('Names', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
test('Get name', function() {
|
test('Get name', function() {
|
||||||
let varDB = new Blockly.Names('window,door');
|
const varDB = new Blockly.Names('window,door');
|
||||||
chai.assert.equal(varDB.getName('Foo.bar', 'var'), 'Foo_bar', 'Name add #1.');
|
chai.assert.equal(varDB.getName('Foo.bar', 'var'), 'Foo_bar', 'Name add #1.');
|
||||||
chai.assert.equal(varDB.getName('Foo.bar', 'var'), 'Foo_bar', 'Name get #1.');
|
chai.assert.equal(varDB.getName('Foo.bar', 'var'), 'Foo_bar', 'Name get #1.');
|
||||||
chai.assert.equal(varDB.getName('Foo bar', 'var'), 'Foo_bar2', 'Name add #2.');
|
chai.assert.equal(varDB.getName('Foo bar', 'var'), 'Foo_bar2', 'Name add #2.');
|
||||||
@@ -43,7 +43,7 @@ suite('Names', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
test('Get distinct name', function() {
|
test('Get distinct name', function() {
|
||||||
let varDB = new Blockly.Names('window,door');
|
const varDB = new Blockly.Names('window,door');
|
||||||
chai.assert.equal(varDB.getDistinctName('Foo.bar', 'var'), 'Foo_bar',
|
chai.assert.equal(varDB.getDistinctName('Foo.bar', 'var'), 'Foo_bar',
|
||||||
'Name distinct #1.');
|
'Name distinct #1.');
|
||||||
chai.assert.equal(varDB.getDistinctName('Foo.bar', 'var'), 'Foo_bar2',
|
chai.assert.equal(varDB.getDistinctName('Foo.bar', 'var'), 'Foo_bar2',
|
||||||
|
|||||||
@@ -26,12 +26,12 @@ suite('Procedures', function() {
|
|||||||
|
|
||||||
suite('allProcedures', function() {
|
suite('allProcedures', function() {
|
||||||
test('Only Procedures', function() {
|
test('Only Procedures', function() {
|
||||||
let noReturnBlock = new Blockly.Block(this.workspace, 'procedures_defnoreturn');
|
const noReturnBlock = new Blockly.Block(this.workspace, 'procedures_defnoreturn');
|
||||||
noReturnBlock.setFieldValue('no return', 'NAME');
|
noReturnBlock.setFieldValue('no return', 'NAME');
|
||||||
let returnBlock = new Blockly.Block(this.workspace, 'procedures_defreturn');
|
const returnBlock = new Blockly.Block(this.workspace, 'procedures_defreturn');
|
||||||
returnBlock.setFieldValue('return', 'NAME');
|
returnBlock.setFieldValue('return', 'NAME');
|
||||||
|
|
||||||
let allProcedures = Blockly.Procedures.allProcedures(this.workspace);
|
const allProcedures = Blockly.Procedures.allProcedures(this.workspace);
|
||||||
chai.assert.lengthOf(allProcedures, 2);
|
chai.assert.lengthOf(allProcedures, 2);
|
||||||
|
|
||||||
chai.assert.lengthOf(allProcedures[0], 1);
|
chai.assert.lengthOf(allProcedures[0], 1);
|
||||||
@@ -41,15 +41,15 @@ suite('Procedures', function() {
|
|||||||
chai.assert.equal(allProcedures[1][0][0], 'return');
|
chai.assert.equal(allProcedures[1][0][0], 'return');
|
||||||
});
|
});
|
||||||
test('Multiple Blocks', function() {
|
test('Multiple Blocks', function() {
|
||||||
let noReturnBlock = new Blockly.Block(this.workspace, 'procedures_defnoreturn');
|
const noReturnBlock = new Blockly.Block(this.workspace, 'procedures_defnoreturn');
|
||||||
noReturnBlock.setFieldValue('no return', 'NAME');
|
noReturnBlock.setFieldValue('no return', 'NAME');
|
||||||
let returnBlock = new Blockly.Block(this.workspace, 'procedures_defreturn');
|
const returnBlock = new Blockly.Block(this.workspace, 'procedures_defreturn');
|
||||||
returnBlock.setFieldValue('return', 'NAME');
|
returnBlock.setFieldValue('return', 'NAME');
|
||||||
let returnBlock2 = new Blockly.Block(this.workspace, 'procedures_defreturn');
|
const returnBlock2 = new Blockly.Block(this.workspace, 'procedures_defreturn');
|
||||||
returnBlock2.setFieldValue('return2', 'NAME');
|
returnBlock2.setFieldValue('return2', 'NAME');
|
||||||
let _ = new Blockly.Block(this.workspace, 'controls_if');
|
const _ = new Blockly.Block(this.workspace, 'controls_if');
|
||||||
|
|
||||||
let allProcedures = Blockly.Procedures.allProcedures(this.workspace);
|
const allProcedures = Blockly.Procedures.allProcedures(this.workspace);
|
||||||
chai.assert.lengthOf(allProcedures, 2);
|
chai.assert.lengthOf(allProcedures, 2);
|
||||||
|
|
||||||
chai.assert.lengthOf(allProcedures[0], 1);
|
chai.assert.lengthOf(allProcedures[0], 1);
|
||||||
@@ -60,8 +60,8 @@ suite('Procedures', function() {
|
|||||||
chai.assert.equal(allProcedures[1][1][0], 'return2');
|
chai.assert.equal(allProcedures[1][1][0], 'return2');
|
||||||
});
|
});
|
||||||
test('No Procedures', function() {
|
test('No Procedures', function() {
|
||||||
let _ = new Blockly.Block(this.workspace, 'controls_if');
|
const _ = new Blockly.Block(this.workspace, 'controls_if');
|
||||||
let allProcedures = Blockly.Procedures.allProcedures(this.workspace);
|
const allProcedures = Blockly.Procedures.allProcedures(this.workspace);
|
||||||
chai.assert.lengthOf(allProcedures, 2);
|
chai.assert.lengthOf(allProcedures, 2);
|
||||||
chai.assert.lengthOf(allProcedures[0], 0, 'No procedures_defnoreturn blocks expected');
|
chai.assert.lengthOf(allProcedures[0], 0, 'No procedures_defnoreturn blocks expected');
|
||||||
chai.assert.lengthOf(allProcedures[1], 0, 'No procedures_defreturn blocks expected');
|
chai.assert.lengthOf(allProcedures[1], 0, 'No procedures_defreturn blocks expected');
|
||||||
@@ -78,7 +78,7 @@ suite('Procedures', function() {
|
|||||||
|
|
||||||
suite('Enable/Disable', function() {
|
suite('Enable/Disable', function() {
|
||||||
setup(function() {
|
setup(function() {
|
||||||
let toolbox = document.getElementById('toolbox-categories');
|
const toolbox = document.getElementById('toolbox-categories');
|
||||||
this.workspaceSvg = Blockly.inject('blocklyDiv', {toolbox: toolbox});
|
this.workspaceSvg = Blockly.inject('blocklyDiv', {toolbox: toolbox});
|
||||||
});
|
});
|
||||||
teardown(function() {
|
teardown(function() {
|
||||||
@@ -87,7 +87,7 @@ suite('Procedures', function() {
|
|||||||
});
|
});
|
||||||
suite('Inherited disabled', function() {
|
suite('Inherited disabled', function() {
|
||||||
setup(function() {
|
setup(function() {
|
||||||
let dom = Blockly.Xml.textToDom(
|
const dom = Blockly.Xml.textToDom(
|
||||||
'<xml xmlns="https://developers.google.com/blockly/xml">' +
|
'<xml xmlns="https://developers.google.com/blockly/xml">' +
|
||||||
'<block type="procedures_defreturn" id="bar-def">' +
|
'<block type="procedures_defreturn" id="bar-def">' +
|
||||||
'<field name="NAME">bar</field>' +
|
'<field name="NAME">bar</field>' +
|
||||||
@@ -234,7 +234,7 @@ suite('Procedures', function() {
|
|||||||
}
|
}
|
||||||
suite('no name renamed to unnamed', function() {
|
suite('no name renamed to unnamed', function() {
|
||||||
test('defnoreturn and defreturn', function() {
|
test('defnoreturn and defreturn', function() {
|
||||||
let xml = Blockly.Xml.textToDom(`
|
const xml = Blockly.Xml.textToDom(`
|
||||||
<xml xmlns="https://developers.google.com/blockly/xml">
|
<xml xmlns="https://developers.google.com/blockly/xml">
|
||||||
<block type="procedures_defnoreturn"/>
|
<block type="procedures_defnoreturn"/>
|
||||||
<block type="procedures_defreturn"/>
|
<block type="procedures_defreturn"/>
|
||||||
@@ -244,7 +244,7 @@ suite('Procedures', function() {
|
|||||||
this.workspace, ['unnamed'], ['unnamed2'], false);
|
this.workspace, ['unnamed'], ['unnamed2'], false);
|
||||||
});
|
});
|
||||||
test('defreturn and defnoreturn', function() {
|
test('defreturn and defnoreturn', function() {
|
||||||
let xml = Blockly.Xml.textToDom(`
|
const xml = Blockly.Xml.textToDom(`
|
||||||
<xml xmlns="https://developers.google.com/blockly/xml">
|
<xml xmlns="https://developers.google.com/blockly/xml">
|
||||||
<block type="procedures_defreturn"/>
|
<block type="procedures_defreturn"/>
|
||||||
<block type="procedures_defnoreturn"/>
|
<block type="procedures_defnoreturn"/>
|
||||||
@@ -254,7 +254,7 @@ suite('Procedures', function() {
|
|||||||
this.workspace, ['unnamed2'], ['unnamed'], false);
|
this.workspace, ['unnamed2'], ['unnamed'], false);
|
||||||
});
|
});
|
||||||
test('callnoreturn (no def in xml)', function() {
|
test('callnoreturn (no def in xml)', function() {
|
||||||
let xml = Blockly.Xml.textToDom(`
|
const xml = Blockly.Xml.textToDom(`
|
||||||
<xml xmlns="https://developers.google.com/blockly/xml">
|
<xml xmlns="https://developers.google.com/blockly/xml">
|
||||||
<block type="procedures_callnoreturn"/>
|
<block type="procedures_callnoreturn"/>
|
||||||
</xml>`);
|
</xml>`);
|
||||||
@@ -263,7 +263,7 @@ suite('Procedures', function() {
|
|||||||
this.workspace, ['unnamed'], [], true);
|
this.workspace, ['unnamed'], [], true);
|
||||||
});
|
});
|
||||||
test('callreturn (no def in xml)', function() {
|
test('callreturn (no def in xml)', function() {
|
||||||
let xml = Blockly.Xml.textToDom(`
|
const xml = Blockly.Xml.textToDom(`
|
||||||
<xml xmlns="https://developers.google.com/blockly/xml">
|
<xml xmlns="https://developers.google.com/blockly/xml">
|
||||||
<block type="procedures_callreturn"/>
|
<block type="procedures_callreturn"/>
|
||||||
</xml>`);
|
</xml>`);
|
||||||
@@ -272,7 +272,7 @@ suite('Procedures', function() {
|
|||||||
this.workspace, [], ['unnamed'], true);
|
this.workspace, [], ['unnamed'], true);
|
||||||
});
|
});
|
||||||
test('callnoreturn and callreturn (no def in xml)', function() {
|
test('callnoreturn and callreturn (no def in xml)', function() {
|
||||||
let xml = Blockly.Xml.textToDom(`
|
const xml = Blockly.Xml.textToDom(`
|
||||||
<xml xmlns="https://developers.google.com/blockly/xml">
|
<xml xmlns="https://developers.google.com/blockly/xml">
|
||||||
<block type="procedures_callnoreturn"/>
|
<block type="procedures_callnoreturn"/>
|
||||||
<block type="procedures_callreturn"/>
|
<block type="procedures_callreturn"/>
|
||||||
@@ -282,7 +282,7 @@ suite('Procedures', function() {
|
|||||||
this.workspace, ['unnamed'], ['unnamed2'], true);
|
this.workspace, ['unnamed'], ['unnamed2'], true);
|
||||||
});
|
});
|
||||||
test('callreturn and callnoreturn (no def in xml)', function() {
|
test('callreturn and callnoreturn (no def in xml)', function() {
|
||||||
let xml = Blockly.Xml.textToDom(`
|
const xml = Blockly.Xml.textToDom(`
|
||||||
<xml xmlns="https://developers.google.com/blockly/xml">
|
<xml xmlns="https://developers.google.com/blockly/xml">
|
||||||
<block type="procedures_callreturn"/>
|
<block type="procedures_callreturn"/>
|
||||||
<block type="procedures_callnoreturn"/>
|
<block type="procedures_callnoreturn"/>
|
||||||
@@ -295,7 +295,7 @@ suite('Procedures', function() {
|
|||||||
suite('caller param mismatch', function() {
|
suite('caller param mismatch', function() {
|
||||||
test.skip('callreturn with missing args', function() {
|
test.skip('callreturn with missing args', function() {
|
||||||
// TODO: How do we want it to behave in this situation?
|
// TODO: How do we want it to behave in this situation?
|
||||||
let defBlock = Blockly.Xml.domToBlock(Blockly.Xml.textToDom(`
|
const defBlock = Blockly.Xml.domToBlock(Blockly.Xml.textToDom(`
|
||||||
<block type="procedures_defreturn">
|
<block type="procedures_defreturn">
|
||||||
<field name="NAME">do something</field>
|
<field name="NAME">do something</field>
|
||||||
<mutation>
|
<mutation>
|
||||||
@@ -303,7 +303,7 @@ suite('Procedures', function() {
|
|||||||
</mutation>
|
</mutation>
|
||||||
</block>
|
</block>
|
||||||
`), this.workspace);
|
`), this.workspace);
|
||||||
let callBlock = Blockly.Xml.domToBlock(Blockly.Xml.textToDom(
|
const callBlock = Blockly.Xml.domToBlock(Blockly.Xml.textToDom(
|
||||||
'<block type="procedures_callreturn">' +
|
'<block type="procedures_callreturn">' +
|
||||||
' <mutation name="do something"/>' +
|
' <mutation name="do something"/>' +
|
||||||
'</block>'
|
'</block>'
|
||||||
@@ -313,7 +313,7 @@ suite('Procedures', function() {
|
|||||||
});
|
});
|
||||||
test.skip('callreturn with bad args', function() {
|
test.skip('callreturn with bad args', function() {
|
||||||
// TODO: How do we want it to behave in this situation?
|
// TODO: How do we want it to behave in this situation?
|
||||||
let defBlock = Blockly.Xml.domToBlock(Blockly.Xml.textToDom(`
|
const defBlock = Blockly.Xml.domToBlock(Blockly.Xml.textToDom(`
|
||||||
<block type="procedures_defreturn">
|
<block type="procedures_defreturn">
|
||||||
<field name="NAME">do something</field>
|
<field name="NAME">do something</field>
|
||||||
<mutation>
|
<mutation>
|
||||||
@@ -321,7 +321,7 @@ suite('Procedures', function() {
|
|||||||
</mutation>
|
</mutation>
|
||||||
</block>
|
</block>
|
||||||
`), this.workspace);
|
`), this.workspace);
|
||||||
let callBlock = Blockly.Xml.domToBlock(Blockly.Xml.textToDom(`
|
const callBlock = Blockly.Xml.domToBlock(Blockly.Xml.textToDom(`
|
||||||
<block type="procedures_callreturn">
|
<block type="procedures_callreturn">
|
||||||
<mutation name="do something">
|
<mutation name="do something">
|
||||||
<arg name="y"></arg>
|
<arg name="y"></arg>
|
||||||
@@ -333,7 +333,7 @@ suite('Procedures', function() {
|
|||||||
});
|
});
|
||||||
test.skip('callnoreturn with missing args', function() {
|
test.skip('callnoreturn with missing args', function() {
|
||||||
// TODO: How do we want it to behave in this situation?
|
// TODO: How do we want it to behave in this situation?
|
||||||
let defBlock = Blockly.Xml.domToBlock(Blockly.Xml.textToDom(`
|
const defBlock = Blockly.Xml.domToBlock(Blockly.Xml.textToDom(`
|
||||||
<block type="procedures_defnoreturn">
|
<block type="procedures_defnoreturn">
|
||||||
<field name="NAME">do something</field>
|
<field name="NAME">do something</field>
|
||||||
<mutation>
|
<mutation>
|
||||||
@@ -341,7 +341,7 @@ suite('Procedures', function() {
|
|||||||
</mutation>
|
</mutation>
|
||||||
</block>
|
</block>
|
||||||
`), this.workspace);
|
`), this.workspace);
|
||||||
let callBlock = Blockly.Xml.domToBlock(Blockly.Xml.textToDom(
|
const callBlock = Blockly.Xml.domToBlock(Blockly.Xml.textToDom(
|
||||||
'<block type="procedures_callnoreturn">' +
|
'<block type="procedures_callnoreturn">' +
|
||||||
' <mutation name="do something"/>' +
|
' <mutation name="do something"/>' +
|
||||||
'</block>'
|
'</block>'
|
||||||
@@ -351,7 +351,7 @@ suite('Procedures', function() {
|
|||||||
});
|
});
|
||||||
test.skip('callnoreturn with bad args', function() {
|
test.skip('callnoreturn with bad args', function() {
|
||||||
// TODO: How do we want it to behave in this situation?
|
// TODO: How do we want it to behave in this situation?
|
||||||
let defBlock = Blockly.Xml.domToBlock(Blockly.Xml.textToDom(`
|
const defBlock = Blockly.Xml.domToBlock(Blockly.Xml.textToDom(`
|
||||||
<block type="procedures_defnoreturn">
|
<block type="procedures_defnoreturn">
|
||||||
<field name="NAME">do something</field>
|
<field name="NAME">do something</field>
|
||||||
<mutation>
|
<mutation>
|
||||||
@@ -359,7 +359,7 @@ suite('Procedures', function() {
|
|||||||
</mutation>
|
</mutation>
|
||||||
</block>
|
</block>
|
||||||
`), this.workspace);
|
`), this.workspace);
|
||||||
let callBlock = Blockly.Xml.domToBlock(Blockly.Xml.textToDom(`
|
const callBlock = Blockly.Xml.domToBlock(Blockly.Xml.textToDom(`
|
||||||
<block type="procedures_callnoreturn">
|
<block type="procedures_callnoreturn">
|
||||||
<mutation name="do something">
|
<mutation name="do something">
|
||||||
<arg name="y"></arg>
|
<arg name="y"></arg>
|
||||||
@@ -401,18 +401,18 @@ suite('Procedures', function() {
|
|||||||
|
|
||||||
test('Custom procedure block', function() {
|
test('Custom procedure block', function() {
|
||||||
// Do not require procedures to be the built-in procedures.
|
// Do not require procedures to be the built-in procedures.
|
||||||
let defBlock = new Blockly.Block(this.workspace, 'new_proc');
|
const defBlock = new Blockly.Block(this.workspace, 'new_proc');
|
||||||
let def = Blockly.Procedures.getDefinition('test', this.workspace);
|
const def = Blockly.Procedures.getDefinition('test', this.workspace);
|
||||||
chai.assert.equal(def, defBlock);
|
chai.assert.equal(def, defBlock);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('Stacked procedures', function() {
|
test('Stacked procedures', function() {
|
||||||
let blockA = new Blockly.Block(this.workspace, 'nested_proc');
|
const blockA = new Blockly.Block(this.workspace, 'nested_proc');
|
||||||
let blockB = new Blockly.Block(this.workspace, 'nested_proc');
|
const blockB = new Blockly.Block(this.workspace, 'nested_proc');
|
||||||
blockA.name = 'a';
|
blockA.name = 'a';
|
||||||
blockB.name = 'b';
|
blockB.name = 'b';
|
||||||
blockA.nextConnection.connect(blockB.previousConnection);
|
blockA.nextConnection.connect(blockB.previousConnection);
|
||||||
let def = Blockly.Procedures.getDefinition('b', this.workspace);
|
const def = Blockly.Procedures.getDefinition('b', this.workspace);
|
||||||
chai.assert.equal(def, blockB);
|
chai.assert.equal(def, blockB);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@@ -479,7 +479,7 @@ suite('Procedures', function() {
|
|||||||
this.callBlock.getFieldValue('NAME'), 'proc name2');
|
this.callBlock.getFieldValue('NAME'), 'proc name2');
|
||||||
});
|
});
|
||||||
test('Simple, Input', function() {
|
test('Simple, Input', function() {
|
||||||
let defInput = this.defBlock.getField('NAME');
|
const defInput = this.defBlock.getField('NAME');
|
||||||
defInput.htmlInput_ = Object.create(null);
|
defInput.htmlInput_ = Object.create(null);
|
||||||
defInput.htmlInput_.oldValue_ = 'proc name';
|
defInput.htmlInput_.oldValue_ = 'proc name';
|
||||||
defInput.htmlInput_.untypedDefaultValue_ = 'proc name';
|
defInput.htmlInput_.untypedDefaultValue_ = 'proc name';
|
||||||
@@ -492,7 +492,7 @@ suite('Procedures', function() {
|
|||||||
this.callBlock.getFieldValue('NAME'), 'proc name2');
|
this.callBlock.getFieldValue('NAME'), 'proc name2');
|
||||||
});
|
});
|
||||||
test('lower -> CAPS', function() {
|
test('lower -> CAPS', function() {
|
||||||
let defInput = this.defBlock.getField('NAME');
|
const defInput = this.defBlock.getField('NAME');
|
||||||
defInput.htmlInput_ = Object.create(null);
|
defInput.htmlInput_ = Object.create(null);
|
||||||
defInput.htmlInput_.oldValue_ = 'proc name';
|
defInput.htmlInput_.oldValue_ = 'proc name';
|
||||||
defInput.htmlInput_.untypedDefaultValue_ = 'proc name';
|
defInput.htmlInput_.untypedDefaultValue_ = 'proc name';
|
||||||
@@ -507,7 +507,7 @@ suite('Procedures', function() {
|
|||||||
test('CAPS -> lower', function() {
|
test('CAPS -> lower', function() {
|
||||||
this.defBlock.setFieldValue('PROC NAME', 'NAME');
|
this.defBlock.setFieldValue('PROC NAME', 'NAME');
|
||||||
this.callBlock.setFieldValue('PROC NAME', 'NAME');
|
this.callBlock.setFieldValue('PROC NAME', 'NAME');
|
||||||
let defInput = this.defBlock.getField('NAME');
|
const defInput = this.defBlock.getField('NAME');
|
||||||
defInput.htmlInput_ = Object.create(null);
|
defInput.htmlInput_ = Object.create(null);
|
||||||
defInput.htmlInput_.oldValue_ = 'PROC NAME';
|
defInput.htmlInput_.oldValue_ = 'PROC NAME';
|
||||||
defInput.htmlInput_.untypedDefaultValue_ = 'PROC NAME';
|
defInput.htmlInput_.untypedDefaultValue_ = 'PROC NAME';
|
||||||
@@ -520,7 +520,7 @@ suite('Procedures', function() {
|
|||||||
this.callBlock.getFieldValue('NAME'), 'proc name');
|
this.callBlock.getFieldValue('NAME'), 'proc name');
|
||||||
});
|
});
|
||||||
test('Whitespace', function() {
|
test('Whitespace', function() {
|
||||||
let defInput = this.defBlock.getField('NAME');
|
const defInput = this.defBlock.getField('NAME');
|
||||||
defInput.htmlInput_ = Object.create(null);
|
defInput.htmlInput_ = Object.create(null);
|
||||||
defInput.htmlInput_.oldValue_ = 'proc name';
|
defInput.htmlInput_.oldValue_ = 'proc name';
|
||||||
defInput.htmlInput_.untypedDefaultValue_ = 'proc name';
|
defInput.htmlInput_.untypedDefaultValue_ = 'proc name';
|
||||||
@@ -533,7 +533,7 @@ suite('Procedures', function() {
|
|||||||
this.callBlock.getFieldValue('NAME'), 'proc name');
|
this.callBlock.getFieldValue('NAME'), 'proc name');
|
||||||
});
|
});
|
||||||
test('Whitespace then Text', function() {
|
test('Whitespace then Text', function() {
|
||||||
let defInput = this.defBlock.getField('NAME');
|
const defInput = this.defBlock.getField('NAME');
|
||||||
defInput.htmlInput_ = Object.create(null);
|
defInput.htmlInput_ = Object.create(null);
|
||||||
defInput.htmlInput_.oldValue_ = 'proc name';
|
defInput.htmlInput_.oldValue_ = 'proc name';
|
||||||
defInput.htmlInput_.untypedDefaultValue_ = 'proc name';
|
defInput.htmlInput_.untypedDefaultValue_ = 'proc name';
|
||||||
@@ -548,7 +548,7 @@ suite('Procedures', function() {
|
|||||||
this.callBlock.getFieldValue('NAME'), 'proc name 2');
|
this.callBlock.getFieldValue('NAME'), 'proc name 2');
|
||||||
});
|
});
|
||||||
test('Set Empty', function() {
|
test('Set Empty', function() {
|
||||||
let defInput = this.defBlock.getField('NAME');
|
const defInput = this.defBlock.getField('NAME');
|
||||||
defInput.htmlInput_ = Object.create(null);
|
defInput.htmlInput_ = Object.create(null);
|
||||||
defInput.htmlInput_.oldValue_ = 'proc name';
|
defInput.htmlInput_.oldValue_ = 'proc name';
|
||||||
defInput.htmlInput_.untypedDefaultValue_ = 'proc name';
|
defInput.htmlInput_.untypedDefaultValue_ = 'proc name';
|
||||||
@@ -563,14 +563,14 @@ suite('Procedures', function() {
|
|||||||
Blockly.Msg['UNNAMED_KEY']);
|
Blockly.Msg['UNNAMED_KEY']);
|
||||||
});
|
});
|
||||||
test('Set Empty, and Create New', function() {
|
test('Set Empty, and Create New', function() {
|
||||||
let defInput = this.defBlock.getField('NAME');
|
const defInput = this.defBlock.getField('NAME');
|
||||||
defInput.htmlInput_ = Object.create(null);
|
defInput.htmlInput_ = Object.create(null);
|
||||||
defInput.htmlInput_.oldValue_ = 'proc name';
|
defInput.htmlInput_.oldValue_ = 'proc name';
|
||||||
defInput.htmlInput_.untypedDefaultValue_ = 'proc name';
|
defInput.htmlInput_.untypedDefaultValue_ = 'proc name';
|
||||||
|
|
||||||
defInput.htmlInput_.value = '';
|
defInput.htmlInput_.value = '';
|
||||||
defInput.onHtmlInputChange_(null);
|
defInput.onHtmlInputChange_(null);
|
||||||
let newDefBlock = new Blockly.Block(this.workspace, testSuite.defType);
|
const newDefBlock = new Blockly.Block(this.workspace, testSuite.defType);
|
||||||
newDefBlock.setFieldValue('new name', 'NAME');
|
newDefBlock.setFieldValue('new name', 'NAME');
|
||||||
chai.assert.equal(
|
chai.assert.equal(
|
||||||
this.defBlock.getFieldValue('NAME'),
|
this.defBlock.getFieldValue('NAME'),
|
||||||
@@ -589,18 +589,18 @@ suite('Procedures', function() {
|
|||||||
this.callBlock.setFieldValue('proc name', 'NAME');
|
this.callBlock.setFieldValue('proc name', 'NAME');
|
||||||
});
|
});
|
||||||
test('Simple', function() {
|
test('Simple', function() {
|
||||||
let callers =
|
const callers =
|
||||||
Blockly.Procedures.getCallers('proc name', this.workspace);
|
Blockly.Procedures.getCallers('proc name', this.workspace);
|
||||||
chai.assert.equal(callers.length, 1);
|
chai.assert.equal(callers.length, 1);
|
||||||
chai.assert.equal(callers[0], this.callBlock);
|
chai.assert.equal(callers[0], this.callBlock);
|
||||||
});
|
});
|
||||||
test('Multiple Callers', function() {
|
test('Multiple Callers', function() {
|
||||||
let caller2 = new Blockly.Block(this.workspace, testSuite.callType);
|
const caller2 = new Blockly.Block(this.workspace, testSuite.callType);
|
||||||
caller2.setFieldValue('proc name', 'NAME');
|
caller2.setFieldValue('proc name', 'NAME');
|
||||||
let caller3 = new Blockly.Block(this.workspace, testSuite.callType);
|
const caller3 = new Blockly.Block(this.workspace, testSuite.callType);
|
||||||
caller3.setFieldValue('proc name', 'NAME');
|
caller3.setFieldValue('proc name', 'NAME');
|
||||||
|
|
||||||
let callers =
|
const callers =
|
||||||
Blockly.Procedures.getCallers('proc name', this.workspace);
|
Blockly.Procedures.getCallers('proc name', this.workspace);
|
||||||
chai.assert.equal(callers.length, 3);
|
chai.assert.equal(callers.length, 3);
|
||||||
chai.assert.equal(callers[0], this.callBlock);
|
chai.assert.equal(callers[0], this.callBlock);
|
||||||
@@ -608,12 +608,12 @@ suite('Procedures', function() {
|
|||||||
chai.assert.equal(callers[2], caller3);
|
chai.assert.equal(callers[2], caller3);
|
||||||
});
|
});
|
||||||
test('Multiple Procedures', function() {
|
test('Multiple Procedures', function() {
|
||||||
let def2 = new Blockly.Block(this.workspace, testSuite.defType);
|
const def2 = new Blockly.Block(this.workspace, testSuite.defType);
|
||||||
def2.setFieldValue('proc name2', 'NAME');
|
def2.setFieldValue('proc name2', 'NAME');
|
||||||
let caller2 = new Blockly.Block(this.workspace, testSuite.callType);
|
const caller2 = new Blockly.Block(this.workspace, testSuite.callType);
|
||||||
caller2.setFieldValue('proc name2', 'NAME');
|
caller2.setFieldValue('proc name2', 'NAME');
|
||||||
|
|
||||||
let callers =
|
const callers =
|
||||||
Blockly.Procedures.getCallers('proc name', this.workspace);
|
Blockly.Procedures.getCallers('proc name', this.workspace);
|
||||||
chai.assert.equal(callers.length, 1);
|
chai.assert.equal(callers.length, 1);
|
||||||
chai.assert.equal(callers[0], this.callBlock);
|
chai.assert.equal(callers[0], this.callBlock);
|
||||||
@@ -628,17 +628,17 @@ suite('Procedures', function() {
|
|||||||
// caller should still be returned for a differently-cased procedure.
|
// caller should still be returned for a differently-cased procedure.
|
||||||
test('Call Different Case', function() {
|
test('Call Different Case', function() {
|
||||||
this.callBlock.setFieldValue('PROC NAME', 'NAME');
|
this.callBlock.setFieldValue('PROC NAME', 'NAME');
|
||||||
let callers =
|
const callers =
|
||||||
Blockly.Procedures.getCallers('proc name', this.workspace);
|
Blockly.Procedures.getCallers('proc name', this.workspace);
|
||||||
chai.assert.equal(callers.length, 1);
|
chai.assert.equal(callers.length, 1);
|
||||||
chai.assert.equal(callers[0], this.callBlock);
|
chai.assert.equal(callers[0], this.callBlock);
|
||||||
});
|
});
|
||||||
test('Multiple Workspaces', function() {
|
test('Multiple Workspaces', function() {
|
||||||
let workspace = new Blockly.Workspace();
|
const workspace = new Blockly.Workspace();
|
||||||
try {
|
try {
|
||||||
let def2 = new Blockly.Block(workspace, testSuite.defType);
|
const def2 = new Blockly.Block(workspace, testSuite.defType);
|
||||||
def2.setFieldValue('proc name', 'NAME');
|
def2.setFieldValue('proc name', 'NAME');
|
||||||
let caller2 = new Blockly.Block(workspace, testSuite.callType);
|
const caller2 = new Blockly.Block(workspace, testSuite.callType);
|
||||||
caller2.setFieldValue('proc name', 'NAME');
|
caller2.setFieldValue('proc name', 'NAME');
|
||||||
|
|
||||||
let callers =
|
let callers =
|
||||||
@@ -663,26 +663,26 @@ suite('Procedures', function() {
|
|||||||
this.callBlock.setFieldValue('proc name', 'NAME');
|
this.callBlock.setFieldValue('proc name', 'NAME');
|
||||||
});
|
});
|
||||||
test('Simple', function() {
|
test('Simple', function() {
|
||||||
let def =
|
const def =
|
||||||
Blockly.Procedures.getDefinition('proc name', this.workspace);
|
Blockly.Procedures.getDefinition('proc name', this.workspace);
|
||||||
chai.assert.equal(def, this.defBlock);
|
chai.assert.equal(def, this.defBlock);
|
||||||
});
|
});
|
||||||
test('Multiple Procedures', function() {
|
test('Multiple Procedures', function() {
|
||||||
let def2 = new Blockly.Block(this.workspace, testSuite.defType);
|
const def2 = new Blockly.Block(this.workspace, testSuite.defType);
|
||||||
def2.setFieldValue('proc name2', 'NAME');
|
def2.setFieldValue('proc name2', 'NAME');
|
||||||
let caller2 = new Blockly.Block(this.workspace, testSuite.callType);
|
const caller2 = new Blockly.Block(this.workspace, testSuite.callType);
|
||||||
caller2.setFieldValue('proc name2', 'NAME');
|
caller2.setFieldValue('proc name2', 'NAME');
|
||||||
|
|
||||||
let def =
|
const def =
|
||||||
Blockly.Procedures.getDefinition('proc name', this.workspace);
|
Blockly.Procedures.getDefinition('proc name', this.workspace);
|
||||||
chai.assert.equal(def, this.defBlock);
|
chai.assert.equal(def, this.defBlock);
|
||||||
});
|
});
|
||||||
test('Multiple Workspaces', function() {
|
test('Multiple Workspaces', function() {
|
||||||
let workspace = new Blockly.Workspace();
|
const workspace = new Blockly.Workspace();
|
||||||
try {
|
try {
|
||||||
let def2 = new Blockly.Block(workspace, testSuite.defType);
|
const def2 = new Blockly.Block(workspace, testSuite.defType);
|
||||||
def2.setFieldValue('proc name', 'NAME');
|
def2.setFieldValue('proc name', 'NAME');
|
||||||
let caller2 = new Blockly.Block(workspace, testSuite.callType);
|
const caller2 = new Blockly.Block(workspace, testSuite.callType);
|
||||||
caller2.setFieldValue('proc name', 'NAME');
|
caller2.setFieldValue('proc name', 'NAME');
|
||||||
|
|
||||||
let def =
|
let def =
|
||||||
@@ -699,7 +699,7 @@ suite('Procedures', function() {
|
|||||||
|
|
||||||
suite('Enable/Disable', function() {
|
suite('Enable/Disable', function() {
|
||||||
setup(function() {
|
setup(function() {
|
||||||
let toolbox = document.getElementById('toolbox-categories');
|
const toolbox = document.getElementById('toolbox-categories');
|
||||||
this.workspaceSvg = Blockly.inject('blocklyDiv', {toolbox: toolbox});
|
this.workspaceSvg = Blockly.inject('blocklyDiv', {toolbox: toolbox});
|
||||||
});
|
});
|
||||||
teardown(function() {
|
teardown(function() {
|
||||||
@@ -731,7 +731,7 @@ suite('Procedures', function() {
|
|||||||
'</block>' +
|
'</block>' +
|
||||||
'</xml>');
|
'</xml>');
|
||||||
setup(function() {
|
setup(function() {
|
||||||
let dom = Blockly.Xml.textToDom(domText);
|
const dom = Blockly.Xml.textToDom(domText);
|
||||||
|
|
||||||
Blockly.Xml.appendDomToWorkspace(dom, this.workspaceSvg);
|
Blockly.Xml.appendDomToWorkspace(dom, this.workspaceSvg);
|
||||||
this.barDef = this.workspaceSvg.getBlockById('bar-def');
|
this.barDef = this.workspaceSvg.getBlockById('bar-def');
|
||||||
@@ -752,7 +752,7 @@ suite('Procedures', function() {
|
|||||||
'Callers are disabled when their definition is disabled (call ' +
|
'Callers are disabled when their definition is disabled (call ' +
|
||||||
i + ')');
|
i + ')');
|
||||||
}
|
}
|
||||||
let firedEvents = this.workspaceSvg.undoStack_;
|
const firedEvents = this.workspaceSvg.undoStack_;
|
||||||
chai.assert.equal(firedEvents.length, 3,
|
chai.assert.equal(firedEvents.length, 3,
|
||||||
'An event was fired for the definition and each caller');
|
'An event was fired for the definition and each caller');
|
||||||
for (let i = 0; i < 3; i++) {
|
for (let i = 0; i < 3; i++) {
|
||||||
@@ -789,7 +789,7 @@ suite('Procedures', function() {
|
|||||||
'Callers are disabled when their definition is disabled (call ' +
|
'Callers are disabled when their definition is disabled (call ' +
|
||||||
i + ')');
|
i + ')');
|
||||||
}
|
}
|
||||||
let firedEvents = this.workspaceSvg.undoStack_;
|
const firedEvents = this.workspaceSvg.undoStack_;
|
||||||
chai.assert.equal(firedEvents.length, 2,
|
chai.assert.equal(firedEvents.length, 2,
|
||||||
'An event was fired for the definition and the enabled caller');
|
'An event was fired for the definition and the enabled caller');
|
||||||
for (let i = 0; i < 2; i++) {
|
for (let i = 0; i < 2; i++) {
|
||||||
@@ -830,13 +830,13 @@ suite('Procedures', function() {
|
|||||||
suite('Composition', function() {
|
suite('Composition', function() {
|
||||||
suite('Statements', function() {
|
suite('Statements', function() {
|
||||||
function setStatementValue(mainWorkspace, defBlock, value) {
|
function setStatementValue(mainWorkspace, defBlock, value) {
|
||||||
let mutatorWorkspace = new Blockly.Workspace(
|
const mutatorWorkspace = new Blockly.Workspace(
|
||||||
new Blockly.Options({
|
new Blockly.Options({
|
||||||
parentWorkspace: mainWorkspace
|
parentWorkspace: mainWorkspace
|
||||||
}));
|
}));
|
||||||
defBlock.decompose(mutatorWorkspace);
|
defBlock.decompose(mutatorWorkspace);
|
||||||
let containerBlock = mutatorWorkspace.getTopBlocks()[0];
|
const containerBlock = mutatorWorkspace.getTopBlocks()[0];
|
||||||
let statementField = containerBlock.getField('STATEMENTS');
|
const statementField = containerBlock.getField('STATEMENTS');
|
||||||
statementField.setValue(value);
|
statementField.setValue(value);
|
||||||
defBlock.compose(containerBlock);
|
defBlock.compose(containerBlock);
|
||||||
}
|
}
|
||||||
@@ -850,21 +850,21 @@ suite('Procedures', function() {
|
|||||||
chai.assert.isFalse(this.defBlock.hasStatements_);
|
chai.assert.isFalse(this.defBlock.hasStatements_);
|
||||||
});
|
});
|
||||||
test('Saving Statements', function() {
|
test('Saving Statements', function() {
|
||||||
let blockXml = Blockly.Xml.textToDom(
|
const blockXml = Blockly.Xml.textToDom(
|
||||||
'<block type="procedures_defreturn">' +
|
'<block type="procedures_defreturn">' +
|
||||||
' <statement name="STACK">' +
|
' <statement name="STACK">' +
|
||||||
' <block type="procedures_ifreturn" id="test"></block>' +
|
' <block type="procedures_ifreturn" id="test"></block>' +
|
||||||
' </statement> ' +
|
' </statement> ' +
|
||||||
'</block>'
|
'</block>'
|
||||||
);
|
);
|
||||||
let defBlock = Blockly.Xml.domToBlock(blockXml, this.workspace);
|
const defBlock = Blockly.Xml.domToBlock(blockXml, this.workspace);
|
||||||
setStatementValue(this.workspace, defBlock, false);
|
setStatementValue(this.workspace, defBlock, false);
|
||||||
chai.assert.isNull(defBlock.getInput('STACK'));
|
chai.assert.isNull(defBlock.getInput('STACK'));
|
||||||
setStatementValue(this.workspace, defBlock, true);
|
setStatementValue(this.workspace, defBlock, true);
|
||||||
chai.assert.isNotNull(defBlock.getInput('STACK'));
|
chai.assert.isNotNull(defBlock.getInput('STACK'));
|
||||||
let statementBlocks = defBlock.getChildren();
|
const statementBlocks = defBlock.getChildren();
|
||||||
chai.assert.equal(statementBlocks.length, 1);
|
chai.assert.equal(statementBlocks.length, 1);
|
||||||
let block = statementBlocks[0];
|
const block = statementBlocks[0];
|
||||||
chai.assert.equal(block.type, 'procedures_ifreturn');
|
chai.assert.equal(block.type, 'procedures_ifreturn');
|
||||||
chai.assert.equal(block.id, 'test');
|
chai.assert.equal(block.id, 'test');
|
||||||
});
|
});
|
||||||
@@ -898,12 +898,12 @@ suite('Procedures', function() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
test('Simple Add Arg', function() {
|
test('Simple Add Arg', function() {
|
||||||
let args = ['arg1'];
|
const args = ['arg1'];
|
||||||
createMutator.call(this, args);
|
createMutator.call(this, args);
|
||||||
assertArgs.call(this, args);
|
assertArgs.call(this, args);
|
||||||
});
|
});
|
||||||
test('Multiple Args', function() {
|
test('Multiple Args', function() {
|
||||||
let args = ['arg1', 'arg2', 'arg3'];
|
const args = ['arg1', 'arg2', 'arg3'];
|
||||||
createMutator.call(this, args);
|
createMutator.call(this, args);
|
||||||
assertArgs.call(this, args);
|
assertArgs.call(this, args);
|
||||||
});
|
});
|
||||||
@@ -927,14 +927,14 @@ suite('Procedures', function() {
|
|||||||
});
|
});
|
||||||
// Test case for #1958
|
// Test case for #1958
|
||||||
test('Set Arg Empty', function() {
|
test('Set Arg Empty', function() {
|
||||||
let args = ['arg1'];
|
const args = ['arg1'];
|
||||||
createMutator.call(this, args);
|
createMutator.call(this, args);
|
||||||
this.argBlock.setFieldValue('', 'NAME');
|
this.argBlock.setFieldValue('', 'NAME');
|
||||||
this.defBlock.compose(this.containerBlock);
|
this.defBlock.compose(this.containerBlock);
|
||||||
assertArgs.call(this, args);
|
assertArgs.call(this, args);
|
||||||
});
|
});
|
||||||
test('Whitespace', function() {
|
test('Whitespace', function() {
|
||||||
let args = ['arg1'];
|
const args = ['arg1'];
|
||||||
createMutator.call(this, args);
|
createMutator.call(this, args);
|
||||||
this.argBlock.setFieldValue(' ', 'NAME');
|
this.argBlock.setFieldValue(' ', 'NAME');
|
||||||
this.defBlock.compose(this.containerBlock);
|
this.defBlock.compose(this.containerBlock);
|
||||||
@@ -947,7 +947,7 @@ suite('Procedures', function() {
|
|||||||
assertArgs.call(this, ['text']);
|
assertArgs.call(this, ['text']);
|
||||||
});
|
});
|
||||||
test('<>', function() {
|
test('<>', function() {
|
||||||
let args = ['<>'];
|
const args = ['<>'];
|
||||||
createMutator.call(this, args);
|
createMutator.call(this, args);
|
||||||
assertArgs.call(this, args);
|
assertArgs.call(this, args);
|
||||||
});
|
});
|
||||||
@@ -957,45 +957,45 @@ suite('Procedures', function() {
|
|||||||
suite('Statements', function() {
|
suite('Statements', function() {
|
||||||
if (testSuite.defType === 'procedures_defreturn') {
|
if (testSuite.defType === 'procedures_defreturn') {
|
||||||
test('Has Statement Input', function() {
|
test('Has Statement Input', function() {
|
||||||
let mutatorWorkspace = new Blockly.Workspace(
|
const mutatorWorkspace = new Blockly.Workspace(
|
||||||
new Blockly.Options({
|
new Blockly.Options({
|
||||||
parentWorkspace: this.workspace
|
parentWorkspace: this.workspace
|
||||||
}));
|
}));
|
||||||
this.defBlock.decompose(mutatorWorkspace);
|
this.defBlock.decompose(mutatorWorkspace);
|
||||||
let statementInput = mutatorWorkspace.getTopBlocks()[0]
|
const statementInput = mutatorWorkspace.getTopBlocks()[0]
|
||||||
.getInput('STATEMENT_INPUT');
|
.getInput('STATEMENT_INPUT');
|
||||||
chai.assert.isNotNull(statementInput);
|
chai.assert.isNotNull(statementInput);
|
||||||
});
|
});
|
||||||
test('Has Statements', function() {
|
test('Has Statements', function() {
|
||||||
this.defBlock.hasStatements_ = true;
|
this.defBlock.hasStatements_ = true;
|
||||||
let mutatorWorkspace = new Blockly.Workspace(
|
const mutatorWorkspace = new Blockly.Workspace(
|
||||||
new Blockly.Options({
|
new Blockly.Options({
|
||||||
parentWorkspace: this.workspace
|
parentWorkspace: this.workspace
|
||||||
}));
|
}));
|
||||||
this.defBlock.decompose(mutatorWorkspace);
|
this.defBlock.decompose(mutatorWorkspace);
|
||||||
let statementValue = mutatorWorkspace.getTopBlocks()[0]
|
const statementValue = mutatorWorkspace.getTopBlocks()[0]
|
||||||
.getField('STATEMENTS').getValueBoolean();
|
.getField('STATEMENTS').getValueBoolean();
|
||||||
chai.assert.isTrue(statementValue);
|
chai.assert.isTrue(statementValue);
|
||||||
});
|
});
|
||||||
test('No Has Statements', function() {
|
test('No Has Statements', function() {
|
||||||
this.defBlock.hasStatements_ = false;
|
this.defBlock.hasStatements_ = false;
|
||||||
let mutatorWorkspace = new Blockly.Workspace(
|
const mutatorWorkspace = new Blockly.Workspace(
|
||||||
new Blockly.Options({
|
new Blockly.Options({
|
||||||
parentWorkspace: this.workspace
|
parentWorkspace: this.workspace
|
||||||
}));
|
}));
|
||||||
this.defBlock.decompose(mutatorWorkspace);
|
this.defBlock.decompose(mutatorWorkspace);
|
||||||
let statementValue = mutatorWorkspace.getTopBlocks()[0]
|
const statementValue = mutatorWorkspace.getTopBlocks()[0]
|
||||||
.getField('STATEMENTS').getValueBoolean();
|
.getField('STATEMENTS').getValueBoolean();
|
||||||
chai.assert.isFalse(statementValue);
|
chai.assert.isFalse(statementValue);
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
test('Has no Statement Input', function() {
|
test('Has no Statement Input', function() {
|
||||||
let mutatorWorkspace = new Blockly.Workspace(
|
const mutatorWorkspace = new Blockly.Workspace(
|
||||||
new Blockly.Options({
|
new Blockly.Options({
|
||||||
parentWorkspace: this.workspace
|
parentWorkspace: this.workspace
|
||||||
}));
|
}));
|
||||||
this.defBlock.decompose(mutatorWorkspace);
|
this.defBlock.decompose(mutatorWorkspace);
|
||||||
let statementInput = mutatorWorkspace.getTopBlocks()[0]
|
const statementInput = mutatorWorkspace.getTopBlocks()[0]
|
||||||
.getInput('STATEMENT_INPUT');
|
.getInput('STATEMENT_INPUT');
|
||||||
chai.assert.isNull(statementInput);
|
chai.assert.isNull(statementInput);
|
||||||
});
|
});
|
||||||
@@ -1004,17 +1004,17 @@ suite('Procedures', function() {
|
|||||||
suite('Untyped Arguments', function() {
|
suite('Untyped Arguments', function() {
|
||||||
function assertArguments(argumentsArray) {
|
function assertArguments(argumentsArray) {
|
||||||
this.defBlock.arguments_ = argumentsArray;
|
this.defBlock.arguments_ = argumentsArray;
|
||||||
let mutatorWorkspace = new Blockly.Workspace(
|
const mutatorWorkspace = new Blockly.Workspace(
|
||||||
new Blockly.Options({
|
new Blockly.Options({
|
||||||
parentWorkspace: this.workspace
|
parentWorkspace: this.workspace
|
||||||
}));
|
}));
|
||||||
this.defBlock.decompose(mutatorWorkspace);
|
this.defBlock.decompose(mutatorWorkspace);
|
||||||
let argBlocks = mutatorWorkspace.getBlocksByType('procedures_mutatorarg');
|
const argBlocks = mutatorWorkspace.getBlocksByType('procedures_mutatorarg');
|
||||||
chai.assert.equal(argBlocks.length, argumentsArray.length);
|
chai.assert.equal(argBlocks.length, argumentsArray.length);
|
||||||
|
|
||||||
for (let i = 0; i < argumentsArray.length; i++) {
|
for (let i = 0; i < argumentsArray.length; i++) {
|
||||||
let argString = argumentsArray[i];
|
const argString = argumentsArray[i];
|
||||||
let argBlockValue = argBlocks[i].getFieldValue('NAME');
|
const argBlockValue = argBlocks[i].getFieldValue('NAME');
|
||||||
chai.assert.equal(argBlockValue, argString);
|
chai.assert.equal(argBlockValue, argString);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ const {assertWarnings, sharedTestSetup, sharedTestTeardown} = goog.require('Bloc
|
|||||||
|
|
||||||
|
|
||||||
suite('Registry', function() {
|
suite('Registry', function() {
|
||||||
let TestClass = function() {};
|
const TestClass = function() {};
|
||||||
TestClass.prototype.testMethod = function() {
|
TestClass.prototype.testMethod = function() {
|
||||||
return 'something';
|
return 'something';
|
||||||
};
|
};
|
||||||
@@ -238,19 +238,19 @@ suite('Registry', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
test('Simple - Plugin name given', function() {
|
test('Simple - Plugin name given', function() {
|
||||||
let testClass = Blockly.registry.getClassFromOptions('test', this.options);
|
const testClass = Blockly.registry.getClassFromOptions('test', this.options);
|
||||||
chai.assert.instanceOf(new testClass(), TestClass);
|
chai.assert.instanceOf(new testClass(), TestClass);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('Simple - Plugin class given', function() {
|
test('Simple - Plugin class given', function() {
|
||||||
this.options.plugins['test'] = TestClass;
|
this.options.plugins['test'] = TestClass;
|
||||||
let testClass = Blockly.registry.getClassFromOptions('test', this.options);
|
const testClass = Blockly.registry.getClassFromOptions('test', this.options);
|
||||||
chai.assert.instanceOf(new testClass(), TestClass);
|
chai.assert.instanceOf(new testClass(), TestClass);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('No Plugin Name Given', function() {
|
test('No Plugin Name Given', function() {
|
||||||
delete this.options['plugins']['test'];
|
delete this.options['plugins']['test'];
|
||||||
let testClass = Blockly.registry.getClassFromOptions('test', this.options);
|
const testClass = Blockly.registry.getClassFromOptions('test', this.options);
|
||||||
chai.assert.instanceOf(new testClass(), this.defaultClass);
|
chai.assert.instanceOf(new testClass(), this.defaultClass);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -41,7 +41,7 @@ function SerializerTestSuite(title) {
|
|||||||
}
|
}
|
||||||
SerializerTestSuite.prototype = new testHelpers.TestSuite();
|
SerializerTestSuite.prototype = new testHelpers.TestSuite();
|
||||||
|
|
||||||
let Serializer = new SerializerTestSuite('Serializer');
|
const Serializer = new SerializerTestSuite('Serializer');
|
||||||
|
|
||||||
// TODO: Make sure all of these properties are documented ad exported properly.
|
// TODO: Make sure all of these properties are documented ad exported properly.
|
||||||
Serializer.Empty = new SerializerTestCase('Empty',
|
Serializer.Empty = new SerializerTestCase('Empty',
|
||||||
@@ -1776,7 +1776,7 @@ Serializer.testSuites = [
|
|||||||
Serializer.Mutations,
|
Serializer.Mutations,
|
||||||
];
|
];
|
||||||
|
|
||||||
let runSerializerTestSuite = (serializer, deserializer, testSuite) => {
|
const runSerializerTestSuite = (serializer, deserializer, testSuite) => {
|
||||||
const workspaces = Blockly.serialization.workspaces;
|
const workspaces = Blockly.serialization.workspaces;
|
||||||
|
|
||||||
const createTestFunction = function(test) {
|
const createTestFunction = function(test) {
|
||||||
@@ -1788,7 +1788,7 @@ let runSerializerTestSuite = (serializer, deserializer, testSuite) => {
|
|||||||
this.workspace.clear();
|
this.workspace.clear();
|
||||||
workspaces.load(deserializer(save), this.workspace);
|
workspaces.load(deserializer(save), this.workspace);
|
||||||
}
|
}
|
||||||
let newXml = Blockly.Xml.workspaceToDom(this.workspace);
|
const newXml = Blockly.Xml.workspaceToDom(this.workspace);
|
||||||
chai.assert.equal(Blockly.Xml.domToText(newXml), test.xml);
|
chai.assert.equal(Blockly.Xml.domToText(newXml), test.xml);
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -21,18 +21,18 @@ suite('Keyboard Shortcut Registry Test', function() {
|
|||||||
|
|
||||||
suite('Registering', function() {
|
suite('Registering', function() {
|
||||||
test('Registering a shortcut', function() {
|
test('Registering a shortcut', function() {
|
||||||
let testShortcut = {'name': 'test_shortcut'};
|
const testShortcut = {'name': 'test_shortcut'};
|
||||||
this.registry.register(testShortcut, true);
|
this.registry.register(testShortcut, true);
|
||||||
let shortcut = this.registry.registry_['test_shortcut'];
|
const shortcut = this.registry.registry_['test_shortcut'];
|
||||||
chai.assert.equal(shortcut.name, 'test_shortcut');
|
chai.assert.equal(shortcut.name, 'test_shortcut');
|
||||||
});
|
});
|
||||||
test('Registers shortcut with same name', function() {
|
test('Registers shortcut with same name', function() {
|
||||||
let registry = this.registry;
|
const registry = this.registry;
|
||||||
let testShortcut = {'name': 'test_shortcut'};
|
const testShortcut = {'name': 'test_shortcut'};
|
||||||
|
|
||||||
registry.registry_['test_shortcut'] = [testShortcut];
|
registry.registry_['test_shortcut'] = [testShortcut];
|
||||||
|
|
||||||
let shouldThrow = function() {
|
const shouldThrow = function() {
|
||||||
registry.register(testShortcut);
|
registry.register(testShortcut);
|
||||||
};
|
};
|
||||||
chai.assert.throws(
|
chai.assert.throws(
|
||||||
@@ -42,16 +42,16 @@ suite('Keyboard Shortcut Registry Test', function() {
|
|||||||
test(
|
test(
|
||||||
'Registers shortcut with same name opt_allowOverrides=true',
|
'Registers shortcut with same name opt_allowOverrides=true',
|
||||||
function() {
|
function() {
|
||||||
let registry = this.registry;
|
const registry = this.registry;
|
||||||
let testShortcut = {'name': 'test_shortcut'};
|
const testShortcut = {'name': 'test_shortcut'};
|
||||||
let otherShortcut = {
|
const otherShortcut = {
|
||||||
'name': 'test_shortcut',
|
'name': 'test_shortcut',
|
||||||
'callback': function() {}
|
'callback': function() {}
|
||||||
};
|
};
|
||||||
|
|
||||||
registry.registry_['test_shortcut'] = [testShortcut];
|
registry.registry_['test_shortcut'] = [testShortcut];
|
||||||
|
|
||||||
let shouldNotThrow = function() {
|
const shouldNotThrow = function() {
|
||||||
registry.register(otherShortcut, true);
|
registry.register(otherShortcut, true);
|
||||||
};
|
};
|
||||||
chai.assert.doesNotThrow(shouldNotThrow);
|
chai.assert.doesNotThrow(shouldNotThrow);
|
||||||
@@ -61,41 +61,41 @@ suite('Keyboard Shortcut Registry Test', function() {
|
|||||||
|
|
||||||
suite('Unregistering', function() {
|
suite('Unregistering', function() {
|
||||||
test('Unregistering a shortcut', function() {
|
test('Unregistering a shortcut', function() {
|
||||||
let testShortcut = {'name': 'test_shortcut'};
|
const testShortcut = {'name': 'test_shortcut'};
|
||||||
this.registry.registry_['test'] = [testShortcut];
|
this.registry.registry_['test'] = [testShortcut];
|
||||||
chai.assert.isOk(this.registry.registry_['test']);
|
chai.assert.isOk(this.registry.registry_['test']);
|
||||||
this.registry.unregister('test', 'test_shortcut');
|
this.registry.unregister('test', 'test_shortcut');
|
||||||
chai.assert.isUndefined(this.registry.registry_['test']);
|
chai.assert.isUndefined(this.registry.registry_['test']);
|
||||||
});
|
});
|
||||||
test('Unregistering a nonexistent shortcut', function() {
|
test('Unregistering a nonexistent shortcut', function() {
|
||||||
let consoleStub = sinon.stub(console, 'warn');
|
const consoleStub = sinon.stub(console, 'warn');
|
||||||
chai.assert.isUndefined(this.registry.registry_['test']);
|
chai.assert.isUndefined(this.registry.registry_['test']);
|
||||||
|
|
||||||
let registry = this.registry;
|
const registry = this.registry;
|
||||||
chai.assert.isFalse(registry.unregister('test', 'test_shortcut'));
|
chai.assert.isFalse(registry.unregister('test', 'test_shortcut'));
|
||||||
sinon.assert.calledOnceWithExactly(consoleStub, 'Keyboard shortcut with name "test" not found.');
|
sinon.assert.calledOnceWithExactly(consoleStub, 'Keyboard shortcut with name "test" not found.');
|
||||||
});
|
});
|
||||||
test('Unregistering a shortcut with key mappings', function() {
|
test('Unregistering a shortcut with key mappings', function() {
|
||||||
let testShortcut = {'name': 'test_shortcut'};
|
const testShortcut = {'name': 'test_shortcut'};
|
||||||
this.registry.keyMap_['keyCode'] = ['test_shortcut'];
|
this.registry.keyMap_['keyCode'] = ['test_shortcut'];
|
||||||
this.registry.registry_['test_shortcut'] = testShortcut;
|
this.registry.registry_['test_shortcut'] = testShortcut;
|
||||||
|
|
||||||
this.registry.unregister('test_shortcut');
|
this.registry.unregister('test_shortcut');
|
||||||
|
|
||||||
let shortcut = this.registry.registry_['test'];
|
const shortcut = this.registry.registry_['test'];
|
||||||
let keyMappings = this.registry.keyMap_['keyCode'];
|
const keyMappings = this.registry.keyMap_['keyCode'];
|
||||||
chai.assert.isUndefined(shortcut);
|
chai.assert.isUndefined(shortcut);
|
||||||
chai.assert.isUndefined(keyMappings);
|
chai.assert.isUndefined(keyMappings);
|
||||||
});
|
});
|
||||||
test('Unregistering a shortcut with colliding key mappings', function() {
|
test('Unregistering a shortcut with colliding key mappings', function() {
|
||||||
let testShortcut = {'name': 'test_shortcut'};
|
const testShortcut = {'name': 'test_shortcut'};
|
||||||
this.registry.keyMap_['keyCode'] = ['test_shortcut', 'other_shortcutt'];
|
this.registry.keyMap_['keyCode'] = ['test_shortcut', 'other_shortcutt'];
|
||||||
this.registry.registry_['test_shortcut'] = testShortcut;
|
this.registry.registry_['test_shortcut'] = testShortcut;
|
||||||
|
|
||||||
this.registry.unregister('test_shortcut');
|
this.registry.unregister('test_shortcut');
|
||||||
|
|
||||||
let shortcut = this.registry.registry_['test'];
|
const shortcut = this.registry.registry_['test'];
|
||||||
let keyMappings = this.registry.keyMap_['keyCode'];
|
const keyMappings = this.registry.keyMap_['keyCode'];
|
||||||
chai.assert.lengthOf(keyMappings, 1);
|
chai.assert.lengthOf(keyMappings, 1);
|
||||||
chai.assert.isUndefined(shortcut);
|
chai.assert.isUndefined(shortcut);
|
||||||
});
|
});
|
||||||
@@ -107,7 +107,7 @@ suite('Keyboard Shortcut Registry Test', function() {
|
|||||||
|
|
||||||
this.registry.addKeyMapping('keyCode', 'test_shortcut');
|
this.registry.addKeyMapping('keyCode', 'test_shortcut');
|
||||||
|
|
||||||
let shortcutNames = this.registry.keyMap_['keyCode'];
|
const shortcutNames = this.registry.keyMap_['keyCode'];
|
||||||
chai.assert.lengthOf(shortcutNames, 1);
|
chai.assert.lengthOf(shortcutNames, 1);
|
||||||
chai.assert.equal(shortcutNames[0], 'test_shortcut');
|
chai.assert.equal(shortcutNames[0], 'test_shortcut');
|
||||||
});
|
});
|
||||||
@@ -117,7 +117,7 @@ suite('Keyboard Shortcut Registry Test', function() {
|
|||||||
|
|
||||||
this.registry.addKeyMapping('keyCode', 'test_shortcut', true);
|
this.registry.addKeyMapping('keyCode', 'test_shortcut', true);
|
||||||
|
|
||||||
let shortcutNames = this.registry.keyMap_['keyCode'];
|
const shortcutNames = this.registry.keyMap_['keyCode'];
|
||||||
chai.assert.lengthOf(shortcutNames, 2);
|
chai.assert.lengthOf(shortcutNames, 2);
|
||||||
chai.assert.equal(shortcutNames[0], 'test_shortcut');
|
chai.assert.equal(shortcutNames[0], 'test_shortcut');
|
||||||
chai.assert.equal(shortcutNames[1], 'test_shortcut_2');
|
chai.assert.equal(shortcutNames[1], 'test_shortcut_2');
|
||||||
@@ -126,8 +126,8 @@ suite('Keyboard Shortcut Registry Test', function() {
|
|||||||
this.registry.registry_['test_shortcut'] = {'name': 'test_shortcut'};
|
this.registry.registry_['test_shortcut'] = {'name': 'test_shortcut'};
|
||||||
this.registry.keyMap_['keyCode'] = ['test_shortcut_2'];
|
this.registry.keyMap_['keyCode'] = ['test_shortcut_2'];
|
||||||
|
|
||||||
let registry = this.registry;
|
const registry = this.registry;
|
||||||
let shouldThrow = function() {
|
const shouldThrow = function() {
|
||||||
registry.addKeyMapping('keyCode', 'test_shortcut');
|
registry.addKeyMapping('keyCode', 'test_shortcut');
|
||||||
};
|
};
|
||||||
chai.assert.throws(
|
chai.assert.throws(
|
||||||
@@ -141,10 +141,10 @@ suite('Keyboard Shortcut Registry Test', function() {
|
|||||||
this.registry.registry_['test_shortcut'] = {'name': 'test_shortcut'};
|
this.registry.registry_['test_shortcut'] = {'name': 'test_shortcut'};
|
||||||
this.registry.keyMap_['keyCode'] = ['test_shortcut', 'test_shortcut_2'];
|
this.registry.keyMap_['keyCode'] = ['test_shortcut', 'test_shortcut_2'];
|
||||||
|
|
||||||
let isRemoved =
|
const isRemoved =
|
||||||
this.registry.removeKeyMapping('keyCode', 'test_shortcut');
|
this.registry.removeKeyMapping('keyCode', 'test_shortcut');
|
||||||
|
|
||||||
let shortcutNames = this.registry.keyMap_['keyCode'];
|
const shortcutNames = this.registry.keyMap_['keyCode'];
|
||||||
chai.assert.lengthOf(shortcutNames, 1);
|
chai.assert.lengthOf(shortcutNames, 1);
|
||||||
chai.assert.equal(shortcutNames[0], 'test_shortcut_2');
|
chai.assert.equal(shortcutNames[0], 'test_shortcut_2');
|
||||||
chai.assert.isTrue(isRemoved);
|
chai.assert.isTrue(isRemoved);
|
||||||
@@ -155,14 +155,14 @@ suite('Keyboard Shortcut Registry Test', function() {
|
|||||||
|
|
||||||
this.registry.removeKeyMapping('keyCode', 'test_shortcut');
|
this.registry.removeKeyMapping('keyCode', 'test_shortcut');
|
||||||
|
|
||||||
let shortcutNames = this.registry.keyMap_['keyCode'];
|
const shortcutNames = this.registry.keyMap_['keyCode'];
|
||||||
chai.assert.isUndefined(shortcutNames);
|
chai.assert.isUndefined(shortcutNames);
|
||||||
});
|
});
|
||||||
test('Removes a key map that does not exist opt_quiet=false', function() {
|
test('Removes a key map that does not exist opt_quiet=false', function() {
|
||||||
let consoleStub = sinon.stub(console, 'warn');
|
const consoleStub = sinon.stub(console, 'warn');
|
||||||
this.registry.keyMap_['keyCode'] = ['test_shortcut_2'];
|
this.registry.keyMap_['keyCode'] = ['test_shortcut_2'];
|
||||||
|
|
||||||
let isRemoved =
|
const isRemoved =
|
||||||
this.registry.removeKeyMapping('keyCode', 'test_shortcut');
|
this.registry.removeKeyMapping('keyCode', 'test_shortcut');
|
||||||
|
|
||||||
chai.assert.isFalse(isRemoved);
|
chai.assert.isFalse(isRemoved);
|
||||||
@@ -173,9 +173,9 @@ suite('Keyboard Shortcut Registry Test', function() {
|
|||||||
test(
|
test(
|
||||||
'Removes a key map that does not exist from empty key mapping opt_quiet=false',
|
'Removes a key map that does not exist from empty key mapping opt_quiet=false',
|
||||||
function() {
|
function() {
|
||||||
let consoleStub = sinon.stub(console, 'warn');
|
const consoleStub = sinon.stub(console, 'warn');
|
||||||
|
|
||||||
let isRemoved =
|
const isRemoved =
|
||||||
this.registry.removeKeyMapping('keyCode', 'test_shortcut');
|
this.registry.removeKeyMapping('keyCode', 'test_shortcut');
|
||||||
|
|
||||||
chai.assert.isFalse(isRemoved);
|
chai.assert.isFalse(isRemoved);
|
||||||
@@ -193,26 +193,26 @@ suite('Keyboard Shortcut Registry Test', function() {
|
|||||||
});
|
});
|
||||||
test('Gets a copy of the key map', function() {
|
test('Gets a copy of the key map', function() {
|
||||||
this.registry.keyMap_['keyCode'] = ['a'];
|
this.registry.keyMap_['keyCode'] = ['a'];
|
||||||
let keyMapCopy = this.registry.getKeyMap();
|
const keyMapCopy = this.registry.getKeyMap();
|
||||||
keyMapCopy['keyCode'] = ['b'];
|
keyMapCopy['keyCode'] = ['b'];
|
||||||
chai.assert.equal(this.registry.keyMap_['keyCode'][0], 'a');
|
chai.assert.equal(this.registry.keyMap_['keyCode'][0], 'a');
|
||||||
});
|
});
|
||||||
test('Gets a copy of the registry', function() {
|
test('Gets a copy of the registry', function() {
|
||||||
this.registry.registry_['shortcutName'] = {'name': 'shortcutName'};
|
this.registry.registry_['shortcutName'] = {'name': 'shortcutName'};
|
||||||
let registrycopy = this.registry.getRegistry();
|
const registrycopy = this.registry.getRegistry();
|
||||||
registrycopy['shortcutName']['name'] = 'shortcutName1';
|
registrycopy['shortcutName']['name'] = 'shortcutName1';
|
||||||
chai.assert.equal(
|
chai.assert.equal(
|
||||||
this.registry.registry_['shortcutName']['name'], 'shortcutName');
|
this.registry.registry_['shortcutName']['name'], 'shortcutName');
|
||||||
});
|
});
|
||||||
test('Gets keyboard shortcuts from a key code', function() {
|
test('Gets keyboard shortcuts from a key code', function() {
|
||||||
this.registry.keyMap_['keyCode'] = ['shortcutName'];
|
this.registry.keyMap_['keyCode'] = ['shortcutName'];
|
||||||
let shortcutNames = this.registry.getShortcutNamesByKeyCode('keyCode');
|
const shortcutNames = this.registry.getShortcutNamesByKeyCode('keyCode');
|
||||||
chai.assert.equal(shortcutNames[0], 'shortcutName');
|
chai.assert.equal(shortcutNames[0], 'shortcutName');
|
||||||
});
|
});
|
||||||
test('Gets keycodes by shortcut name', function() {
|
test('Gets keycodes by shortcut name', function() {
|
||||||
this.registry.keyMap_['keyCode'] = ['shortcutName'];
|
this.registry.keyMap_['keyCode'] = ['shortcutName'];
|
||||||
this.registry.keyMap_['keyCode1'] = ['shortcutName'];
|
this.registry.keyMap_['keyCode1'] = ['shortcutName'];
|
||||||
let shortcutNames =
|
const shortcutNames =
|
||||||
this.registry.getKeyCodesByShortcutName('shortcutName');
|
this.registry.getKeyCodesByShortcutName('shortcutName');
|
||||||
chai.assert.lengthOf(shortcutNames, 2);
|
chai.assert.lengthOf(shortcutNames, 2);
|
||||||
chai.assert.equal(shortcutNames[0], 'keyCode');
|
chai.assert.equal(shortcutNames[0], 'keyCode');
|
||||||
@@ -241,23 +241,23 @@ suite('Keyboard Shortcut Registry Test', function() {
|
|||||||
addShortcut(this.registry, this.testShortcut, Blockly.utils.KeyCodes.C, true);
|
addShortcut(this.registry, this.testShortcut, Blockly.utils.KeyCodes.C, true);
|
||||||
});
|
});
|
||||||
test('Execute a shortcut from event', function() {
|
test('Execute a shortcut from event', function() {
|
||||||
let event = createKeyDownEvent(Blockly.utils.KeyCodes.C);
|
const event = createKeyDownEvent(Blockly.utils.KeyCodes.C);
|
||||||
chai.assert.isTrue(this.registry.onKeyDown(this.workspace, event));
|
chai.assert.isTrue(this.registry.onKeyDown(this.workspace, event));
|
||||||
sinon.assert.calledOnce(this.callBackStub);
|
sinon.assert.calledOnce(this.callBackStub);
|
||||||
});
|
});
|
||||||
test('No shortcut executed from event', function() {
|
test('No shortcut executed from event', function() {
|
||||||
let event = createKeyDownEvent(Blockly.utils.KeyCodes.D);
|
const event = createKeyDownEvent(Blockly.utils.KeyCodes.D);
|
||||||
chai.assert.isFalse(this.registry.onKeyDown(this.workspace, event));
|
chai.assert.isFalse(this.registry.onKeyDown(this.workspace, event));
|
||||||
});
|
});
|
||||||
test('No precondition available - execute callback', function() {
|
test('No precondition available - execute callback', function() {
|
||||||
delete this.testShortcut['precondition'];
|
delete this.testShortcut['precondition'];
|
||||||
let event = createKeyDownEvent(Blockly.utils.KeyCodes.C);
|
const event = createKeyDownEvent(Blockly.utils.KeyCodes.C);
|
||||||
chai.assert.isTrue(this.registry.onKeyDown(this.workspace, event));
|
chai.assert.isTrue(this.registry.onKeyDown(this.workspace, event));
|
||||||
sinon.assert.calledOnce(this.callBackStub);
|
sinon.assert.calledOnce(this.callBackStub);
|
||||||
});
|
});
|
||||||
test('Execute all shortcuts in list', function() {
|
test('Execute all shortcuts in list', function() {
|
||||||
let event = createKeyDownEvent(Blockly.utils.KeyCodes.C);
|
const event = createKeyDownEvent(Blockly.utils.KeyCodes.C);
|
||||||
let testShortcut2 = {
|
const testShortcut2 = {
|
||||||
'name': 'test_shortcut_2',
|
'name': 'test_shortcut_2',
|
||||||
'callback': function() {
|
'callback': function() {
|
||||||
return false;
|
return false;
|
||||||
@@ -266,15 +266,15 @@ suite('Keyboard Shortcut Registry Test', function() {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
let testShortcut2Stub =
|
const testShortcut2Stub =
|
||||||
addShortcut(this.registry, testShortcut2, Blockly.utils.KeyCodes.C, false);
|
addShortcut(this.registry, testShortcut2, Blockly.utils.KeyCodes.C, false);
|
||||||
chai.assert.isTrue(this.registry.onKeyDown(this.workspace, event));
|
chai.assert.isTrue(this.registry.onKeyDown(this.workspace, event));
|
||||||
sinon.assert.calledOnce(testShortcut2Stub);
|
sinon.assert.calledOnce(testShortcut2Stub);
|
||||||
sinon.assert.calledOnce(this.callBackStub);
|
sinon.assert.calledOnce(this.callBackStub);
|
||||||
});
|
});
|
||||||
test('Stop executing shortcut when event is handled', function() {
|
test('Stop executing shortcut when event is handled', function() {
|
||||||
let event = createKeyDownEvent(Blockly.utils.KeyCodes.C);
|
const event = createKeyDownEvent(Blockly.utils.KeyCodes.C);
|
||||||
let testShortcut2 = {
|
const testShortcut2 = {
|
||||||
'name': 'test_shortcut_2',
|
'name': 'test_shortcut_2',
|
||||||
'callback': function() {
|
'callback': function() {
|
||||||
return false;
|
return false;
|
||||||
@@ -283,7 +283,7 @@ suite('Keyboard Shortcut Registry Test', function() {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
let testShortcut2Stub =
|
const testShortcut2Stub =
|
||||||
addShortcut(this.registry, testShortcut2, Blockly.utils.KeyCodes.C, true);
|
addShortcut(this.registry, testShortcut2, Blockly.utils.KeyCodes.C, true);
|
||||||
chai.assert.isTrue(this.registry.onKeyDown(this.workspace, event));
|
chai.assert.isTrue(this.registry.onKeyDown(this.workspace, event));
|
||||||
sinon.assert.calledOnce(testShortcut2Stub);
|
sinon.assert.calledOnce(testShortcut2Stub);
|
||||||
@@ -293,31 +293,31 @@ suite('Keyboard Shortcut Registry Test', function() {
|
|||||||
|
|
||||||
suite('createSerializedKey', function() {
|
suite('createSerializedKey', function() {
|
||||||
test('Serialize key', function() {
|
test('Serialize key', function() {
|
||||||
let serializedKey =
|
const serializedKey =
|
||||||
this.registry.createSerializedKey(Blockly.utils.KeyCodes.A);
|
this.registry.createSerializedKey(Blockly.utils.KeyCodes.A);
|
||||||
chai.assert.equal(serializedKey, '65');
|
chai.assert.equal(serializedKey, '65');
|
||||||
});
|
});
|
||||||
|
|
||||||
test('Serialize key code and modifier', function() {
|
test('Serialize key code and modifier', function() {
|
||||||
let serializedKey = this.registry.createSerializedKey(
|
const serializedKey = this.registry.createSerializedKey(
|
||||||
Blockly.utils.KeyCodes.A, [Blockly.utils.KeyCodes.CTRL]);
|
Blockly.utils.KeyCodes.A, [Blockly.utils.KeyCodes.CTRL]);
|
||||||
chai.assert.equal(serializedKey, 'Control+65');
|
chai.assert.equal(serializedKey, 'Control+65');
|
||||||
});
|
});
|
||||||
test('Serialize only a modifier', function() {
|
test('Serialize only a modifier', function() {
|
||||||
let serializedKey = this.registry.createSerializedKey(
|
const serializedKey = this.registry.createSerializedKey(
|
||||||
null, [Blockly.utils.KeyCodes.CTRL]);
|
null, [Blockly.utils.KeyCodes.CTRL]);
|
||||||
chai.assert.equal(serializedKey, 'Control');
|
chai.assert.equal(serializedKey, 'Control');
|
||||||
});
|
});
|
||||||
test('Serialize multiple modifiers', function() {
|
test('Serialize multiple modifiers', function() {
|
||||||
let serializedKey = this.registry.createSerializedKey(
|
const serializedKey = this.registry.createSerializedKey(
|
||||||
null, [Blockly.utils.KeyCodes.CTRL, Blockly.utils.KeyCodes.SHIFT]);
|
null, [Blockly.utils.KeyCodes.CTRL, Blockly.utils.KeyCodes.SHIFT]);
|
||||||
chai.assert.equal(serializedKey, 'Shift+Control');
|
chai.assert.equal(serializedKey, 'Shift+Control');
|
||||||
});
|
});
|
||||||
test('Order of modifiers should result in same serialized key', function() {
|
test('Order of modifiers should result in same serialized key', function() {
|
||||||
let serializedKey = this.registry.createSerializedKey(
|
const serializedKey = this.registry.createSerializedKey(
|
||||||
null, [Blockly.utils.KeyCodes.CTRL, Blockly.utils.KeyCodes.SHIFT]);
|
null, [Blockly.utils.KeyCodes.CTRL, Blockly.utils.KeyCodes.SHIFT]);
|
||||||
chai.assert.equal(serializedKey, 'Shift+Control');
|
chai.assert.equal(serializedKey, 'Shift+Control');
|
||||||
let serializedKeyNewOrder = this.registry.createSerializedKey(
|
const serializedKeyNewOrder = this.registry.createSerializedKey(
|
||||||
null, [Blockly.utils.KeyCodes.SHIFT, Blockly.utils.KeyCodes.CTRL]);
|
null, [Blockly.utils.KeyCodes.SHIFT, Blockly.utils.KeyCodes.CTRL]);
|
||||||
chai.assert.equal(serializedKeyNewOrder, 'Shift+Control');
|
chai.assert.equal(serializedKeyNewOrder, 'Shift+Control');
|
||||||
});
|
});
|
||||||
@@ -325,32 +325,32 @@ suite('Keyboard Shortcut Registry Test', function() {
|
|||||||
|
|
||||||
suite('serializeKeyEvent', function() {
|
suite('serializeKeyEvent', function() {
|
||||||
test('Serialize key', function() {
|
test('Serialize key', function() {
|
||||||
let mockEvent = createKeyDownEvent(Blockly.utils.KeyCodes.A);
|
const mockEvent = createKeyDownEvent(Blockly.utils.KeyCodes.A);
|
||||||
let serializedKey = this.registry.serializeKeyEvent_(mockEvent);
|
const serializedKey = this.registry.serializeKeyEvent_(mockEvent);
|
||||||
chai.assert.equal(serializedKey, '65');
|
chai.assert.equal(serializedKey, '65');
|
||||||
});
|
});
|
||||||
test('Serialize key code and modifier', function() {
|
test('Serialize key code and modifier', function() {
|
||||||
let mockEvent = createKeyDownEvent(
|
const mockEvent = createKeyDownEvent(
|
||||||
Blockly.utils.KeyCodes.A, [Blockly.utils.KeyCodes.CTRL]);
|
Blockly.utils.KeyCodes.A, [Blockly.utils.KeyCodes.CTRL]);
|
||||||
let serializedKey = this.registry.serializeKeyEvent_(mockEvent);
|
const serializedKey = this.registry.serializeKeyEvent_(mockEvent);
|
||||||
chai.assert.equal(serializedKey, 'Control+65');
|
chai.assert.equal(serializedKey, 'Control+65');
|
||||||
});
|
});
|
||||||
test('Serialize only a modifier', function() {
|
test('Serialize only a modifier', function() {
|
||||||
let mockEvent =
|
const mockEvent =
|
||||||
createKeyDownEvent(null, [Blockly.utils.KeyCodes.CTRL]);
|
createKeyDownEvent(null, [Blockly.utils.KeyCodes.CTRL]);
|
||||||
let serializedKey = this.registry.serializeKeyEvent_(mockEvent);
|
const serializedKey = this.registry.serializeKeyEvent_(mockEvent);
|
||||||
chai.assert.equal(serializedKey, 'Control');
|
chai.assert.equal(serializedKey, 'Control');
|
||||||
});
|
});
|
||||||
test('Serialize multiple modifiers', function() {
|
test('Serialize multiple modifiers', function() {
|
||||||
let mockEvent = createKeyDownEvent(
|
const mockEvent = createKeyDownEvent(
|
||||||
null,
|
null,
|
||||||
[Blockly.utils.KeyCodes.CTRL, Blockly.utils.KeyCodes.SHIFT]);
|
[Blockly.utils.KeyCodes.CTRL, Blockly.utils.KeyCodes.SHIFT]);
|
||||||
let serializedKey = this.registry.serializeKeyEvent_(mockEvent);
|
const serializedKey = this.registry.serializeKeyEvent_(mockEvent);
|
||||||
chai.assert.equal(serializedKey, 'Shift+Control');
|
chai.assert.equal(serializedKey, 'Shift+Control');
|
||||||
});
|
});
|
||||||
test('Throw error when incorrect modifier', function() {
|
test('Throw error when incorrect modifier', function() {
|
||||||
let registry = this.registry;
|
const registry = this.registry;
|
||||||
let shouldThrow = function() {
|
const shouldThrow = function() {
|
||||||
registry.createSerializedKey(Blockly.utils.KeyCodes.K, ['s']);
|
registry.createSerializedKey(Blockly.utils.KeyCodes.K, ['s']);
|
||||||
};
|
};
|
||||||
chai.assert.throws(shouldThrow, Error, 's is not a valid modifier key.');
|
chai.assert.throws(shouldThrow, Error, 's is not a valid modifier key.');
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ const {Blocks} = goog.require('Blockly.blocks');
|
|||||||
* @param {!string} id The expected id of the variable.
|
* @param {!string} id The expected id of the variable.
|
||||||
*/
|
*/
|
||||||
function assertVariableValues(container, name, type, id) {
|
function assertVariableValues(container, name, type, id) {
|
||||||
let variable = container.getVariableById(id);
|
const variable = container.getVariableById(id);
|
||||||
chai.assert.isDefined(variable);
|
chai.assert.isDefined(variable);
|
||||||
chai.assert.equal(variable.name, name);
|
chai.assert.equal(variable.name, name);
|
||||||
chai.assert.equal(variable.type, type);
|
chai.assert.equal(variable.type, type);
|
||||||
@@ -38,7 +38,7 @@ function assertWarnings(innerFunc, messages) {
|
|||||||
if (!Array.isArray(messages)) {
|
if (!Array.isArray(messages)) {
|
||||||
messages = [messages];
|
messages = [messages];
|
||||||
}
|
}
|
||||||
let warnings = testHelpers.captureWarnings(innerFunc);
|
const warnings = testHelpers.captureWarnings(innerFunc);
|
||||||
chai.assert.lengthOf(warnings, messages.length);
|
chai.assert.lengthOf(warnings, messages.length);
|
||||||
messages.forEach((message, i) => {
|
messages.forEach((message, i) => {
|
||||||
chai.assert.match(warnings[i], message);
|
chai.assert.match(warnings[i], message);
|
||||||
@@ -101,7 +101,7 @@ function workspaceTeardown(workspace) {
|
|||||||
workspace.dispose();
|
workspace.dispose();
|
||||||
this.clock.runAll(); // Run all remaining queued setTimeout calls.
|
this.clock.runAll(); // Run all remaining queued setTimeout calls.
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
let testRef = this.currentTest || this.test;
|
const testRef = this.currentTest || this.test;
|
||||||
console.error(testRef.fullTitle() + '\n', e);
|
console.error(testRef.fullTitle() + '\n', e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -115,7 +115,7 @@ exports.workspaceTeardown = workspaceTeardown;
|
|||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
function createEventsFireStubFireImmediately_(clock) {
|
function createEventsFireStubFireImmediately_(clock) {
|
||||||
let stub = sinon.stub(eventUtils, 'fire');
|
const stub = sinon.stub(eventUtils, 'fire');
|
||||||
stub.callsFake(function(event) {
|
stub.callsFake(function(event) {
|
||||||
// Call original method.
|
// Call original method.
|
||||||
stub.wrappedMethod.call(this, ...arguments);
|
stub.wrappedMethod.call(this, ...arguments);
|
||||||
@@ -158,7 +158,7 @@ exports.addBlockTypeToCleanup = addBlockTypeToCleanup;
|
|||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
function wrapDefineBlocksWithJsonArrayWithCleanup_(sharedCleanupObj) {
|
function wrapDefineBlocksWithJsonArrayWithCleanup_(sharedCleanupObj) {
|
||||||
let stub = sinon.stub(Blockly, 'defineBlocksWithJsonArray');
|
const stub = sinon.stub(Blockly, 'defineBlocksWithJsonArray');
|
||||||
stub.callsFake(function(jsonArray) {
|
stub.callsFake(function(jsonArray) {
|
||||||
if (jsonArray) {
|
if (jsonArray) {
|
||||||
jsonArray.forEach((jsonBlock) => {
|
jsonArray.forEach((jsonBlock) => {
|
||||||
@@ -215,7 +215,7 @@ exports.sharedTestSetup = sharedTestSetup;
|
|||||||
* outermost suite using sharedTestTeardown.call(this).
|
* outermost suite using sharedTestTeardown.call(this).
|
||||||
*/
|
*/
|
||||||
function sharedTestTeardown() {
|
function sharedTestTeardown() {
|
||||||
let testRef = this.currentTest || this.test;
|
const testRef = this.currentTest || this.test;
|
||||||
if (!this.sharedSetupCalled_) {
|
if (!this.sharedSetupCalled_) {
|
||||||
console.error('"' + testRef.fullTitle() + '" did not call sharedTestSetup');
|
console.error('"' + testRef.fullTitle() + '" did not call sharedTestSetup');
|
||||||
}
|
}
|
||||||
@@ -250,11 +250,11 @@ function sharedTestTeardown() {
|
|||||||
this.sharedSetupSandbox_.restore();
|
this.sharedSetupSandbox_.restore();
|
||||||
sinon.restore();
|
sinon.restore();
|
||||||
|
|
||||||
let blockTypes = this.sharedCleanup.blockTypesCleanup_;
|
const blockTypes = this.sharedCleanup.blockTypesCleanup_;
|
||||||
for (let i = 0; i < blockTypes.length; i++) {
|
for (let i = 0; i < blockTypes.length; i++) {
|
||||||
delete Blocks[blockTypes[i]];
|
delete Blocks[blockTypes[i]];
|
||||||
}
|
}
|
||||||
let messages = this.sharedCleanup.messagesCleanup_;
|
const messages = this.sharedCleanup.messagesCleanup_;
|
||||||
for (let i = 0; i < messages.length; i++) {
|
for (let i = 0; i < messages.length; i++) {
|
||||||
delete Blockly.Msg[messages[i]];
|
delete Blockly.Msg[messages[i]];
|
||||||
}
|
}
|
||||||
@@ -274,7 +274,7 @@ exports.sharedTestTeardown = sharedTestTeardown;
|
|||||||
* @return {!SinonStub} The created stub.
|
* @return {!SinonStub} The created stub.
|
||||||
*/
|
*/
|
||||||
function createGenUidStubWithReturns(returnIds) {
|
function createGenUidStubWithReturns(returnIds) {
|
||||||
let stub = sinon.stub(Blockly.utils.idGenerator.TEST_ONLY, "genUid");
|
const stub = sinon.stub(Blockly.utils.idGenerator.TEST_ONLY, "genUid");
|
||||||
if (Array.isArray(returnIds)) {
|
if (Array.isArray(returnIds)) {
|
||||||
for (let i = 0; i < returnIds.length; i++) {
|
for (let i = 0; i < returnIds.length; i++) {
|
||||||
stub.onCall(i).returns(returnIds[i]);
|
stub.onCall(i).returns(returnIds[i]);
|
||||||
@@ -305,7 +305,7 @@ exports.createFireChangeListenerSpy = createFireChangeListenerSpy;
|
|||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
function assertXmlPropertyEqual_(xmlValue, expectedValue, message) {
|
function assertXmlPropertyEqual_(xmlValue, expectedValue, message) {
|
||||||
let value = Blockly.Xml.domToText(xmlValue);
|
const value = Blockly.Xml.domToText(xmlValue);
|
||||||
if (expectedValue instanceof Node) {
|
if (expectedValue instanceof Node) {
|
||||||
expectedValue = Blockly.Xml.domToText(expectedValue);
|
expectedValue = Blockly.Xml.domToText(expectedValue);
|
||||||
}
|
}
|
||||||
@@ -321,8 +321,8 @@ function assertXmlPropertyEqual_(xmlValue, expectedValue, message) {
|
|||||||
*/
|
*/
|
||||||
function assertXmlProperties_(obj, expectedXmlProperties) {
|
function assertXmlProperties_(obj, expectedXmlProperties) {
|
||||||
Object.keys(expectedXmlProperties).map((key) => {
|
Object.keys(expectedXmlProperties).map((key) => {
|
||||||
let value = obj[key];
|
const value = obj[key];
|
||||||
let expectedValue = expectedXmlProperties[key];
|
const expectedValue = expectedXmlProperties[key];
|
||||||
if (expectedValue === undefined) {
|
if (expectedValue === undefined) {
|
||||||
chai.assert.isUndefined(value,
|
chai.assert.isUndefined(value,
|
||||||
'Expected ' + key + ' property to be undefined');
|
'Expected ' + key + ' property to be undefined');
|
||||||
@@ -365,8 +365,8 @@ function assertEventEquals(event, expectedType,
|
|||||||
chai.assert.equal(event.blockId, expectedBlockId,
|
chai.assert.equal(event.blockId, expectedBlockId,
|
||||||
prependMessage + 'block id');
|
prependMessage + 'block id');
|
||||||
Object.keys(expectedProperties).map((key) => {
|
Object.keys(expectedProperties).map((key) => {
|
||||||
let value = event[key];
|
const value = event[key];
|
||||||
let expectedValue = expectedProperties[key];
|
const expectedValue = expectedProperties[key];
|
||||||
if (expectedValue === undefined) {
|
if (expectedValue === undefined) {
|
||||||
chai.assert.isUndefined(value, prependMessage + key);
|
chai.assert.isUndefined(value, prependMessage + key);
|
||||||
return;
|
return;
|
||||||
@@ -405,7 +405,7 @@ function assertEventFired(spy, instanceType, expectedProperties,
|
|||||||
workspaceId: expectedWorkspaceId,
|
workspaceId: expectedWorkspaceId,
|
||||||
blockId: expectedBlockId,
|
blockId: expectedBlockId,
|
||||||
}, expectedProperties);
|
}, expectedProperties);
|
||||||
let expectedEvent =
|
const expectedEvent =
|
||||||
sinon.match.instanceOf(instanceType).and(sinon.match(expectedProperties));
|
sinon.match.instanceOf(instanceType).and(sinon.match(expectedProperties));
|
||||||
sinon.assert.calledWith(spy, expectedEvent);
|
sinon.assert.calledWith(spy, expectedEvent);
|
||||||
}
|
}
|
||||||
@@ -430,7 +430,7 @@ function assertEventNotFired(spy, instanceType, expectedProperties,
|
|||||||
if (expectedBlockId !== undefined) {
|
if (expectedBlockId !== undefined) {
|
||||||
expectedProperties.blockId = expectedBlockId;
|
expectedProperties.blockId = expectedBlockId;
|
||||||
}
|
}
|
||||||
let expectedEvent =
|
const expectedEvent =
|
||||||
sinon.match.instanceOf(instanceType).and(sinon.match(expectedProperties));
|
sinon.match.instanceOf(instanceType).and(sinon.match(expectedProperties));
|
||||||
sinon.assert.neverCalledWith(spy, expectedEvent);
|
sinon.assert.neverCalledWith(spy, expectedEvent);
|
||||||
}
|
}
|
||||||
@@ -444,8 +444,8 @@ exports.assertEventNotFired = assertEventNotFired;
|
|||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
function splitByXmlProperties_(properties) {
|
function splitByXmlProperties_(properties) {
|
||||||
let xmlProperties = {};
|
const xmlProperties = {};
|
||||||
let nonXmlProperties = {};
|
const nonXmlProperties = {};
|
||||||
Object.keys(properties).forEach((key) => {
|
Object.keys(properties).forEach((key) => {
|
||||||
if (isXmlProperty_(key)) {
|
if (isXmlProperty_(key)) {
|
||||||
xmlProperties[key] = properties[key];
|
xmlProperties[key] = properties[key];
|
||||||
@@ -471,14 +471,14 @@ function splitByXmlProperties_(properties) {
|
|||||||
*/
|
*/
|
||||||
function assertNthCallEventArgEquals(spy, n, instanceType, expectedProperties,
|
function assertNthCallEventArgEquals(spy, n, instanceType, expectedProperties,
|
||||||
expectedWorkspaceId, expectedBlockId) {
|
expectedWorkspaceId, expectedBlockId) {
|
||||||
let nthCall = spy.getCall(n);
|
const nthCall = spy.getCall(n);
|
||||||
let splitProperties = splitByXmlProperties_(expectedProperties);
|
const splitProperties = splitByXmlProperties_(expectedProperties);
|
||||||
let nonXmlProperties = splitProperties[0];
|
const nonXmlProperties = splitProperties[0];
|
||||||
let xmlProperties = splitProperties[1];
|
const xmlProperties = splitProperties[1];
|
||||||
|
|
||||||
assertEventFired(nthCall, instanceType, nonXmlProperties, expectedWorkspaceId,
|
assertEventFired(nthCall, instanceType, nonXmlProperties, expectedWorkspaceId,
|
||||||
expectedBlockId);
|
expectedBlockId);
|
||||||
let eventArg = nthCall.firstArg;
|
const eventArg = nthCall.firstArg;
|
||||||
assertXmlProperties_(eventArg, xmlProperties);
|
assertXmlProperties_(eventArg, xmlProperties);
|
||||||
}
|
}
|
||||||
exports.assertNthCallEventArgEquals = assertNthCallEventArgEquals;
|
exports.assertNthCallEventArgEquals = assertNthCallEventArgEquals;
|
||||||
@@ -568,7 +568,7 @@ function defineMutatorBlocks() {
|
|||||||
hasInput: false,
|
hasInput: false,
|
||||||
|
|
||||||
mutationToDom: function() {
|
mutationToDom: function() {
|
||||||
let mutation = Blockly.utils.xml.createElement('mutation');
|
const mutation = Blockly.utils.xml.createElement('mutation');
|
||||||
mutation.setAttribute('hasInput', this.hasInput);
|
mutation.setAttribute('hasInput', this.hasInput);
|
||||||
return mutation;
|
return mutation;
|
||||||
},
|
},
|
||||||
@@ -579,7 +579,7 @@ function defineMutatorBlocks() {
|
|||||||
},
|
},
|
||||||
|
|
||||||
decompose: function(workspace) {
|
decompose: function(workspace) {
|
||||||
let topBlock = workspace.newBlock('checkbox_block', 'check_block');
|
const topBlock = workspace.newBlock('checkbox_block', 'check_block');
|
||||||
topBlock.initSvg();
|
topBlock.initSvg();
|
||||||
topBlock.render();
|
topBlock.render();
|
||||||
return topBlock;
|
return topBlock;
|
||||||
@@ -613,7 +613,7 @@ function defineMutatorBlocks() {
|
|||||||
},
|
},
|
||||||
|
|
||||||
decompose: function(workspace) {
|
decompose: function(workspace) {
|
||||||
let topBlock = workspace.newBlock('checkbox_block', 'check_block');
|
const topBlock = workspace.newBlock('checkbox_block', 'check_block');
|
||||||
topBlock.initSvg();
|
topBlock.initSvg();
|
||||||
topBlock.render();
|
topBlock.render();
|
||||||
return topBlock;
|
return topBlock;
|
||||||
@@ -653,7 +653,7 @@ function createTestBlock() {
|
|||||||
exports.createTestBlock = createTestBlock;
|
exports.createTestBlock = createTestBlock;
|
||||||
|
|
||||||
function createRenderedBlock(workspaceSvg, type) {
|
function createRenderedBlock(workspaceSvg, type) {
|
||||||
let block = workspaceSvg.newBlock(type);
|
const block = workspaceSvg.newBlock(type);
|
||||||
block.initSvg();
|
block.initSvg();
|
||||||
block.render();
|
block.render();
|
||||||
return block;
|
return block;
|
||||||
@@ -692,7 +692,7 @@ exports.dispatchPointerEvent = dispatchPointerEvent;
|
|||||||
* @return {!KeyboardEvent} The mocked keydown event.
|
* @return {!KeyboardEvent} The mocked keydown event.
|
||||||
*/
|
*/
|
||||||
function createKeyDownEvent(keyCode, modifiers) {
|
function createKeyDownEvent(keyCode, modifiers) {
|
||||||
let event = {
|
const event = {
|
||||||
keyCode: keyCode,
|
keyCode: keyCode,
|
||||||
};
|
};
|
||||||
if (modifiers && modifiers.length > 0) {
|
if (modifiers && modifiers.length > 0) {
|
||||||
|
|||||||
@@ -68,37 +68,37 @@ suite('Theme', function() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function stringifyAndCompare(val1, val2) {
|
function stringifyAndCompare(val1, val2) {
|
||||||
let stringVal1 = JSON.stringify(val1);
|
const stringVal1 = JSON.stringify(val1);
|
||||||
let stringVal2 = JSON.stringify(val2);
|
const stringVal2 = JSON.stringify(val2);
|
||||||
chai.assert.equal(stringVal1, stringVal2);
|
chai.assert.equal(stringVal1, stringVal2);
|
||||||
}
|
}
|
||||||
|
|
||||||
test('Set All BlockStyles', function() {
|
test('Set All BlockStyles', function() {
|
||||||
let theme = new Blockly.Theme('test', createBlockStyles());
|
const theme = new Blockly.Theme('test', createBlockStyles());
|
||||||
stringifyAndCompare(createBlockStyles(), theme.blockStyles);
|
stringifyAndCompare(createBlockStyles(), theme.blockStyles);
|
||||||
let blockStyles = createMultipleBlockStyles();
|
const blockStyles = createMultipleBlockStyles();
|
||||||
for (let key in blockStyles) {
|
for (const key in blockStyles) {
|
||||||
theme.blockStyles[key] = blockStyles[key];
|
theme.blockStyles[key] = blockStyles[key];
|
||||||
}
|
}
|
||||||
stringifyAndCompare(createMultipleBlockStyles(), theme.blockStyles);
|
stringifyAndCompare(createMultipleBlockStyles(), theme.blockStyles);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('Get All BlockStyles', function() {
|
test('Get All BlockStyles', function() {
|
||||||
let theme = new Blockly.Theme('test', createMultipleBlockStyles());
|
const theme = new Blockly.Theme('test', createMultipleBlockStyles());
|
||||||
let allBlocks = theme.blockStyles;
|
const allBlocks = theme.blockStyles;
|
||||||
stringifyAndCompare(createMultipleBlockStyles(), allBlocks);
|
stringifyAndCompare(createMultipleBlockStyles(), allBlocks);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('Get BlockStyles', function() {
|
test('Get BlockStyles', function() {
|
||||||
let theme = new Blockly.Theme('test', createBlockStyles());
|
const theme = new Blockly.Theme('test', createBlockStyles());
|
||||||
let blockStyle = theme.blockStyles['styleOne'];
|
const blockStyle = theme.blockStyles['styleOne'];
|
||||||
|
|
||||||
stringifyAndCompare(blockStyle, createBlockStyles().styleOne);
|
stringifyAndCompare(blockStyle, createBlockStyles().styleOne);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('Set BlockStyle Update', function() {
|
test('Set BlockStyle Update', function() {
|
||||||
let theme = new Blockly.Theme('test', createBlockStyles());
|
const theme = new Blockly.Theme('test', createBlockStyles());
|
||||||
let blockStyle = createBlockStyles();
|
const blockStyle = createBlockStyles();
|
||||||
blockStyle.styleOne.colourPrimary = '#00ff00';
|
blockStyle.styleOne.colourPrimary = '#00ff00';
|
||||||
|
|
||||||
theme.blockStyles['styleOne'] = blockStyle.styleOne;
|
theme.blockStyles['styleOne'] = blockStyle.styleOne;
|
||||||
@@ -107,8 +107,8 @@ suite('Theme', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
test('Set BlockStyle Add', function() {
|
test('Set BlockStyle Add', function() {
|
||||||
let theme = new Blockly.Theme('test', createBlockStyles());
|
const theme = new Blockly.Theme('test', createBlockStyles());
|
||||||
let blockStyle = createMultipleBlockStyles();
|
const blockStyle = createMultipleBlockStyles();
|
||||||
|
|
||||||
theme.blockStyles['styleTwo'] = blockStyle.styleTwo;
|
theme.blockStyles['styleTwo'] = blockStyle.styleTwo;
|
||||||
|
|
||||||
@@ -119,13 +119,13 @@ suite('Theme', function() {
|
|||||||
defineThemeTestBlocks();
|
defineThemeTestBlocks();
|
||||||
let workspace;
|
let workspace;
|
||||||
try {
|
try {
|
||||||
let blockStyles = createBlockStyles();
|
const blockStyles = createBlockStyles();
|
||||||
let theme = new Blockly.Theme('themeName', blockStyles);
|
const theme = new Blockly.Theme('themeName', blockStyles);
|
||||||
workspace = new Blockly.WorkspaceSvg(new Blockly.Options({}));
|
workspace = new Blockly.WorkspaceSvg(new Blockly.Options({}));
|
||||||
let blockA = workspace.newBlock('stack_block');
|
const blockA = workspace.newBlock('stack_block');
|
||||||
|
|
||||||
blockA.setStyle = function() {this.styleName_ = 'styleTwo';};
|
blockA.setStyle = function() {this.styleName_ = 'styleTwo';};
|
||||||
let refreshToolboxSelectionStub =
|
const refreshToolboxSelectionStub =
|
||||||
sinon.stub(workspace, 'refreshToolboxSelection');
|
sinon.stub(workspace, 'refreshToolboxSelection');
|
||||||
blockA.styleName_ = 'styleOne';
|
blockA.styleName_ = 'styleOne';
|
||||||
|
|
||||||
@@ -158,8 +158,8 @@ suite('Theme', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
test('Null', function() {
|
test('Null', function() {
|
||||||
let inputStyle = null;
|
const inputStyle = null;
|
||||||
let expectedOutput = {
|
const expectedOutput = {
|
||||||
"colourPrimary": "#000000",
|
"colourPrimary": "#000000",
|
||||||
"colourSecondary": "#999999",
|
"colourSecondary": "#999999",
|
||||||
"colourTertiary": "#4d4d4d",
|
"colourTertiary": "#4d4d4d",
|
||||||
@@ -170,8 +170,8 @@ suite('Theme', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
test('Empty', function() {
|
test('Empty', function() {
|
||||||
let inputStyle = {};
|
const inputStyle = {};
|
||||||
let expectedOutput = {
|
const expectedOutput = {
|
||||||
"colourPrimary": "#000000",
|
"colourPrimary": "#000000",
|
||||||
"colourSecondary": "#999999",
|
"colourSecondary": "#999999",
|
||||||
"colourTertiary": "#4d4d4d",
|
"colourTertiary": "#4d4d4d",
|
||||||
@@ -182,10 +182,10 @@ suite('Theme', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
test('Incomplete hex', function() {
|
test('Incomplete hex', function() {
|
||||||
let inputStyle = {
|
const inputStyle = {
|
||||||
"colourPrimary": "#012345"
|
"colourPrimary": "#012345"
|
||||||
};
|
};
|
||||||
let expectedOutput = {
|
const expectedOutput = {
|
||||||
"colourPrimary": "#012345",
|
"colourPrimary": "#012345",
|
||||||
"colourSecondary": "#99a7b5",
|
"colourSecondary": "#99a7b5",
|
||||||
"colourTertiary": "#4d657d",
|
"colourTertiary": "#4d657d",
|
||||||
@@ -196,13 +196,13 @@ suite('Theme', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
test('Complete hex', function() {
|
test('Complete hex', function() {
|
||||||
let inputStyle = {
|
const inputStyle = {
|
||||||
"colourPrimary": "#aaaaaa",
|
"colourPrimary": "#aaaaaa",
|
||||||
"colourSecondary": "#bbbbbb",
|
"colourSecondary": "#bbbbbb",
|
||||||
"colourTertiary": "#cccccc",
|
"colourTertiary": "#cccccc",
|
||||||
"hat": 'cap'
|
"hat": 'cap'
|
||||||
};
|
};
|
||||||
let expectedOutput = {
|
const expectedOutput = {
|
||||||
"colourPrimary": "#aaaaaa",
|
"colourPrimary": "#aaaaaa",
|
||||||
"colourSecondary": "#bbbbbb",
|
"colourSecondary": "#bbbbbb",
|
||||||
"colourTertiary": "#cccccc",
|
"colourTertiary": "#cccccc",
|
||||||
@@ -213,12 +213,12 @@ suite('Theme', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
test('Complete hue', function() {
|
test('Complete hue', function() {
|
||||||
let inputStyle = {
|
const inputStyle = {
|
||||||
"colourPrimary": "20",
|
"colourPrimary": "20",
|
||||||
"colourSecondary": "40",
|
"colourSecondary": "40",
|
||||||
"colourTertiary": "60",
|
"colourTertiary": "60",
|
||||||
};
|
};
|
||||||
let expectedOutput = {
|
const expectedOutput = {
|
||||||
"colourPrimary": "#a5745b",
|
"colourPrimary": "#a5745b",
|
||||||
"colourSecondary": "#a58c5b",
|
"colourSecondary": "#a58c5b",
|
||||||
"colourTertiary": "#a5a55b",
|
"colourTertiary": "#a5a55b",
|
||||||
@@ -229,10 +229,10 @@ suite('Theme', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
test('Incomplete hue', function() {
|
test('Incomplete hue', function() {
|
||||||
let inputStyle = {
|
const inputStyle = {
|
||||||
"colourPrimary": "20",
|
"colourPrimary": "20",
|
||||||
};
|
};
|
||||||
let expectedOutput = {
|
const expectedOutput = {
|
||||||
"colourPrimary": "#a5745b",
|
"colourPrimary": "#a5745b",
|
||||||
"colourSecondary": "#dbc7bd",
|
"colourSecondary": "#dbc7bd",
|
||||||
"colourTertiary": "#c09e8c",
|
"colourTertiary": "#c09e8c",
|
||||||
@@ -243,12 +243,12 @@ suite('Theme', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
test('Complete css colour name', function() {
|
test('Complete css colour name', function() {
|
||||||
let inputStyle = {
|
const inputStyle = {
|
||||||
"colourPrimary": "red",
|
"colourPrimary": "red",
|
||||||
"colourSecondary": "white",
|
"colourSecondary": "white",
|
||||||
"colourTertiary": "blue"
|
"colourTertiary": "blue"
|
||||||
};
|
};
|
||||||
let expectedOutput = {
|
const expectedOutput = {
|
||||||
"colourPrimary": "#ff0000",
|
"colourPrimary": "#ff0000",
|
||||||
"colourSecondary": "#ffffff",
|
"colourSecondary": "#ffffff",
|
||||||
"colourTertiary": "#0000ff",
|
"colourTertiary": "#0000ff",
|
||||||
@@ -259,10 +259,10 @@ suite('Theme', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
test('Incomplete css colour name', function() {
|
test('Incomplete css colour name', function() {
|
||||||
let inputStyle = {
|
const inputStyle = {
|
||||||
"colourPrimary": "black",
|
"colourPrimary": "black",
|
||||||
};
|
};
|
||||||
let expectedOutput = {
|
const expectedOutput = {
|
||||||
"colourPrimary": "#000000",
|
"colourPrimary": "#000000",
|
||||||
"colourSecondary": "#999999",
|
"colourSecondary": "#999999",
|
||||||
"colourTertiary": "#4d4d4d",
|
"colourTertiary": "#4d4d4d",
|
||||||
|
|||||||
@@ -180,7 +180,7 @@ exports.getDeeplyNestedJSON = getDeeplyNestedJSON;
|
|||||||
* @return {Array<Node>} Array holding xml elements for a toolbox.
|
* @return {Array<Node>} Array holding xml elements for a toolbox.
|
||||||
*/
|
*/
|
||||||
function getXmlArray() {
|
function getXmlArray() {
|
||||||
let block = Blockly.Xml.textToDom(
|
const block = Blockly.Xml.textToDom(
|
||||||
`<block type="logic_compare">
|
`<block type="logic_compare">
|
||||||
<field name="OP">NEQ</field>
|
<field name="OP">NEQ</field>
|
||||||
<value name="A">
|
<value name="A">
|
||||||
@@ -194,9 +194,9 @@ function getXmlArray() {
|
|||||||
</block>
|
</block>
|
||||||
</value>
|
</value>
|
||||||
</block>`);
|
</block>`);
|
||||||
let separator = Blockly.Xml.textToDom('<sep gap="20"></sep>');
|
const separator = Blockly.Xml.textToDom('<sep gap="20"></sep>');
|
||||||
let button = Blockly.Xml.textToDom('<button text="insert" callbackkey="insertConnectionRows"></button>');
|
const button = Blockly.Xml.textToDom('<button text="insert" callbackkey="insertConnectionRows"></button>');
|
||||||
let label = Blockly.Xml.textToDom('<label text="tooltips"></label>');
|
const label = Blockly.Xml.textToDom('<label text="tooltips"></label>');
|
||||||
return [block, separator, button, label];
|
return [block, separator, button, label];
|
||||||
}
|
}
|
||||||
exports.getXmlArray = getXmlArray;
|
exports.getXmlArray = getXmlArray;
|
||||||
@@ -214,8 +214,8 @@ function getInjectedToolbox() {
|
|||||||
* Category: NestedCategory
|
* Category: NestedCategory
|
||||||
* Category: NestedItemOne
|
* Category: NestedItemOne
|
||||||
*/
|
*/
|
||||||
let toolboxXml = document.getElementById('toolbox-test');
|
const toolboxXml = document.getElementById('toolbox-test');
|
||||||
let workspace = Blockly.inject('blocklyDiv',
|
const workspace = Blockly.inject('blocklyDiv',
|
||||||
{
|
{
|
||||||
toolbox: toolboxXml
|
toolbox: toolboxXml
|
||||||
});
|
});
|
||||||
@@ -224,8 +224,8 @@ function getInjectedToolbox() {
|
|||||||
exports.getInjectedToolbox = getInjectedToolbox;
|
exports.getInjectedToolbox = getInjectedToolbox;
|
||||||
|
|
||||||
function getBasicToolbox() {
|
function getBasicToolbox() {
|
||||||
let workspace = new Blockly.WorkspaceSvg(new Blockly.Options({}));
|
const workspace = new Blockly.WorkspaceSvg(new Blockly.Options({}));
|
||||||
let toolbox = new Blockly.Toolbox(workspace);
|
const toolbox = new Blockly.Toolbox(workspace);
|
||||||
toolbox.HtmlDiv = document.createElement('div');
|
toolbox.HtmlDiv = document.createElement('div');
|
||||||
toolbox.flyout_ = sinon.createStubInstance(Blockly.VerticalFlyout);
|
toolbox.flyout_ = sinon.createStubInstance(Blockly.VerticalFlyout);
|
||||||
return toolbox;
|
return toolbox;
|
||||||
@@ -233,9 +233,9 @@ function getBasicToolbox() {
|
|||||||
exports.getBasicToolbox = getBasicToolbox;
|
exports.getBasicToolbox = getBasicToolbox;
|
||||||
|
|
||||||
function getCollapsibleItem(toolbox) {
|
function getCollapsibleItem(toolbox) {
|
||||||
let contents = toolbox.contents_;
|
const contents = toolbox.contents_;
|
||||||
for (let i = 0; i < contents.length; i++) {
|
for (let i = 0; i < contents.length; i++) {
|
||||||
let item = contents[i];
|
const item = contents[i];
|
||||||
if (item.isCollapsible()) {
|
if (item.isCollapsible()) {
|
||||||
return item;
|
return item;
|
||||||
}
|
}
|
||||||
@@ -244,9 +244,9 @@ function getCollapsibleItem(toolbox) {
|
|||||||
exports.getCollapsibleItem = getCollapsibleItem;
|
exports.getCollapsibleItem = getCollapsibleItem;
|
||||||
|
|
||||||
function getNonCollapsibleItem(toolbox) {
|
function getNonCollapsibleItem(toolbox) {
|
||||||
let contents = toolbox.contents_;
|
const contents = toolbox.contents_;
|
||||||
for (let i = 0; i < contents.length; i++) {
|
for (let i = 0; i < contents.length; i++) {
|
||||||
let item = contents[i];
|
const item = contents[i];
|
||||||
if (!item.isCollapsible()) {
|
if (!item.isCollapsible()) {
|
||||||
return item;
|
return item;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -33,14 +33,14 @@ suite('Toolbox', function() {
|
|||||||
chai.assert.isDefined(this.toolbox.HtmlDiv);
|
chai.assert.isDefined(this.toolbox.HtmlDiv);
|
||||||
});
|
});
|
||||||
test('Init called -> HtmlDiv is inserted before parent node', function() {
|
test('Init called -> HtmlDiv is inserted before parent node', function() {
|
||||||
let toolboxDiv = Blockly.getMainWorkspace().getInjectionDiv().childNodes[0];
|
const toolboxDiv = Blockly.getMainWorkspace().getInjectionDiv().childNodes[0];
|
||||||
chai.assert.equal(toolboxDiv.className,
|
chai.assert.equal(toolboxDiv.className,
|
||||||
'blocklyToolboxDiv blocklyNonSelectable');
|
'blocklyToolboxDiv blocklyNonSelectable');
|
||||||
});
|
});
|
||||||
test('Init called -> Toolbox is subscribed to background and foreground colour', function() {
|
test('Init called -> Toolbox is subscribed to background and foreground colour', function() {
|
||||||
let themeManager = this.toolbox.workspace_.getThemeManager();
|
const themeManager = this.toolbox.workspace_.getThemeManager();
|
||||||
let themeManagerSpy = sinon.spy(themeManager, 'subscribe');
|
const themeManagerSpy = sinon.spy(themeManager, 'subscribe');
|
||||||
let componentManager = this.toolbox.workspace_.getComponentManager();
|
const componentManager = this.toolbox.workspace_.getComponentManager();
|
||||||
sinon.stub(componentManager, 'addComponent');
|
sinon.stub(componentManager, 'addComponent');
|
||||||
this.toolbox.init();
|
this.toolbox.init();
|
||||||
sinon.assert.calledWith(themeManagerSpy, this.toolbox.HtmlDiv,
|
sinon.assert.calledWith(themeManagerSpy, this.toolbox.HtmlDiv,
|
||||||
@@ -49,14 +49,14 @@ suite('Toolbox', function() {
|
|||||||
'toolboxForegroundColour', 'color');
|
'toolboxForegroundColour', 'color');
|
||||||
});
|
});
|
||||||
test('Init called -> Render is called', function() {
|
test('Init called -> Render is called', function() {
|
||||||
let renderSpy = sinon.spy(this.toolbox, 'render');
|
const renderSpy = sinon.spy(this.toolbox, 'render');
|
||||||
let componentManager = this.toolbox.workspace_.getComponentManager();
|
const componentManager = this.toolbox.workspace_.getComponentManager();
|
||||||
sinon.stub(componentManager, 'addComponent');
|
sinon.stub(componentManager, 'addComponent');
|
||||||
this.toolbox.init();
|
this.toolbox.init();
|
||||||
sinon.assert.calledOnce(renderSpy);
|
sinon.assert.calledOnce(renderSpy);
|
||||||
});
|
});
|
||||||
test('Init called -> Flyout is initialized', function() {
|
test('Init called -> Flyout is initialized', function() {
|
||||||
let componentManager = this.toolbox.workspace_.getComponentManager();
|
const componentManager = this.toolbox.workspace_.getComponentManager();
|
||||||
sinon.stub(componentManager, 'addComponent');
|
sinon.stub(componentManager, 'addComponent');
|
||||||
this.toolbox.init();
|
this.toolbox.init();
|
||||||
chai.assert.isDefined(this.toolbox.flyout_);
|
chai.assert.isDefined(this.toolbox.flyout_);
|
||||||
@@ -71,7 +71,7 @@ suite('Toolbox', function() {
|
|||||||
this.toolbox.dispose();
|
this.toolbox.dispose();
|
||||||
});
|
});
|
||||||
test('Render called with valid toolboxDef -> Contents are created', function() {
|
test('Render called with valid toolboxDef -> Contents are created', function() {
|
||||||
let positionStub = sinon.stub(this.toolbox, 'position');
|
const positionStub = sinon.stub(this.toolbox, 'position');
|
||||||
this.toolbox.render({'contents': [
|
this.toolbox.render({'contents': [
|
||||||
{'kind': 'category', 'contents': []},
|
{'kind': 'category', 'contents': []},
|
||||||
{'kind': 'category', 'contents': []}
|
{'kind': 'category', 'contents': []}
|
||||||
@@ -81,8 +81,8 @@ suite('Toolbox', function() {
|
|||||||
});
|
});
|
||||||
// TODO: Uncomment once implemented.
|
// TODO: Uncomment once implemented.
|
||||||
test.skip('Toolbox definition with both blocks and categories -> Should throw an error', function() {
|
test.skip('Toolbox definition with both blocks and categories -> Should throw an error', function() {
|
||||||
let toolbox = this.toolbox;
|
const toolbox = this.toolbox;
|
||||||
let badToolboxDef = [
|
const badToolboxDef = [
|
||||||
{
|
{
|
||||||
"kind": "block"
|
"kind": "block"
|
||||||
},
|
},
|
||||||
@@ -97,11 +97,11 @@ suite('Toolbox', function() {
|
|||||||
// TODO: Uncomment once implemented.
|
// TODO: Uncomment once implemented.
|
||||||
test.skip('Expanded set to true for a non collapsible toolbox item -> Should open flyout', function() {
|
test.skip('Expanded set to true for a non collapsible toolbox item -> Should open flyout', function() {
|
||||||
this.toolbox.render(this.toolboxXml);
|
this.toolbox.render(this.toolboxXml);
|
||||||
let selectedNode = this.toolbox.tree_.children_[0];
|
const selectedNode = this.toolbox.tree_.children_[0];
|
||||||
chai.assert.isTrue(selectedNode.selected_);
|
chai.assert.isTrue(selectedNode.selected_);
|
||||||
});
|
});
|
||||||
test('JSON toolbox definition -> Should create toolbox with contents', function() {
|
test('JSON toolbox definition -> Should create toolbox with contents', function() {
|
||||||
let jsonDef = {'contents' : [
|
const jsonDef = {'contents' : [
|
||||||
{
|
{
|
||||||
"kind": "category",
|
"kind": "category",
|
||||||
"contents": [
|
"contents": [
|
||||||
@@ -141,20 +141,20 @@ suite('Toolbox', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
test('Toolbox clicked -> Should close flyout', function() {
|
test('Toolbox clicked -> Should close flyout', function() {
|
||||||
let hideChaffStub = sinon.stub(
|
const hideChaffStub = sinon.stub(
|
||||||
Blockly.WorkspaceSvg.prototype, "hideChaff");
|
Blockly.WorkspaceSvg.prototype, "hideChaff");
|
||||||
let evt = new MouseEvent('click', {});
|
const evt = new MouseEvent('click', {});
|
||||||
this.toolbox.HtmlDiv.dispatchEvent(evt);
|
this.toolbox.HtmlDiv.dispatchEvent(evt);
|
||||||
sinon.assert.calledOnce(hideChaffStub);
|
sinon.assert.calledOnce(hideChaffStub);
|
||||||
});
|
});
|
||||||
test('Category clicked -> Should select category', function() {
|
test('Category clicked -> Should select category', function() {
|
||||||
let categoryXml = document.getElementsByClassName('blocklyTreeRow')[0];
|
const categoryXml = document.getElementsByClassName('blocklyTreeRow')[0];
|
||||||
let evt = {
|
const evt = {
|
||||||
'target': categoryXml
|
'target': categoryXml
|
||||||
};
|
};
|
||||||
let item = this.toolbox.contentMap_[categoryXml.getAttribute('id')];
|
const item = this.toolbox.contentMap_[categoryXml.getAttribute('id')];
|
||||||
let setSelectedSpy = sinon.spy(this.toolbox, 'setSelectedItem');
|
const setSelectedSpy = sinon.spy(this.toolbox, 'setSelectedItem');
|
||||||
let onClickSpy = sinon.spy(item, 'onClick');
|
const onClickSpy = sinon.spy(item, 'onClick');
|
||||||
this.toolbox.onClick_(evt);
|
this.toolbox.onClick_(evt);
|
||||||
sinon.assert.calledOnce(setSelectedSpy);
|
sinon.assert.calledOnce(setSelectedSpy);
|
||||||
sinon.assert.calledOnce(onClickSpy);
|
sinon.assert.calledOnce(onClickSpy);
|
||||||
@@ -177,9 +177,9 @@ suite('Toolbox', function() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function testCorrectFunctionCalled(toolbox, keyCode, funcName) {
|
function testCorrectFunctionCalled(toolbox, keyCode, funcName) {
|
||||||
let event = createKeyDownMock(keyCode);
|
const event = createKeyDownMock(keyCode);
|
||||||
let preventDefaultEvent = sinon.stub(event, 'preventDefault');
|
const preventDefaultEvent = sinon.stub(event, 'preventDefault');
|
||||||
let selectMethodStub = sinon.stub(toolbox, funcName);
|
const selectMethodStub = sinon.stub(toolbox, funcName);
|
||||||
selectMethodStub.returns(true);
|
selectMethodStub.returns(true);
|
||||||
toolbox.onKeyDown_(event);
|
toolbox.onKeyDown_(event);
|
||||||
sinon.assert.called(selectMethodStub);
|
sinon.assert.called(selectMethodStub);
|
||||||
@@ -200,17 +200,17 @@ suite('Toolbox', function() {
|
|||||||
});
|
});
|
||||||
test('Enter button is pushed -> Should toggle expandedd', function() {
|
test('Enter button is pushed -> Should toggle expandedd', function() {
|
||||||
this.toolbox.selectedItem_ = getCollapsibleItem(this.toolbox);
|
this.toolbox.selectedItem_ = getCollapsibleItem(this.toolbox);
|
||||||
let toggleExpandedStub = sinon.stub(this.toolbox.selectedItem_, 'toggleExpanded');
|
const toggleExpandedStub = sinon.stub(this.toolbox.selectedItem_, 'toggleExpanded');
|
||||||
let event = createKeyDownMock(Blockly.utils.KeyCodes.ENTER);
|
const event = createKeyDownMock(Blockly.utils.KeyCodes.ENTER);
|
||||||
let preventDefaultEvent = sinon.stub(event, 'preventDefault');
|
const preventDefaultEvent = sinon.stub(event, 'preventDefault');
|
||||||
this.toolbox.onKeyDown_(event);
|
this.toolbox.onKeyDown_(event);
|
||||||
sinon.assert.called(toggleExpandedStub);
|
sinon.assert.called(toggleExpandedStub);
|
||||||
sinon.assert.called(preventDefaultEvent);
|
sinon.assert.called(preventDefaultEvent);
|
||||||
});
|
});
|
||||||
test('Enter button is pushed when no item is selected -> Should not call prevent default', function() {
|
test('Enter button is pushed when no item is selected -> Should not call prevent default', function() {
|
||||||
this.toolbox.selectedItem_ = null;
|
this.toolbox.selectedItem_ = null;
|
||||||
let event = createKeyDownMock(Blockly.utils.KeyCodes.ENTER);
|
const event = createKeyDownMock(Blockly.utils.KeyCodes.ENTER);
|
||||||
let preventDefaultEvent = sinon.stub(event, 'preventDefault');
|
const preventDefaultEvent = sinon.stub(event, 'preventDefault');
|
||||||
this.toolbox.onKeyDown_(event);
|
this.toolbox.onKeyDown_(event);
|
||||||
sinon.assert.notCalled(preventDefaultEvent);
|
sinon.assert.notCalled(preventDefaultEvent);
|
||||||
});
|
});
|
||||||
@@ -227,29 +227,29 @@ suite('Toolbox', function() {
|
|||||||
suite('selectChild_', function() {
|
suite('selectChild_', function() {
|
||||||
test('No item is selected -> Should not handle event', function() {
|
test('No item is selected -> Should not handle event', function() {
|
||||||
this.toolbox.selectedItem_ = null;
|
this.toolbox.selectedItem_ = null;
|
||||||
let handled = this.toolbox.selectChild_();
|
const handled = this.toolbox.selectChild_();
|
||||||
chai.assert.isFalse(handled);
|
chai.assert.isFalse(handled);
|
||||||
});
|
});
|
||||||
test('Selected item is not collapsible -> Should not handle event', function() {
|
test('Selected item is not collapsible -> Should not handle event', function() {
|
||||||
this.toolbox.selectedItem_ = getNonCollapsibleItem(this.toolbox);
|
this.toolbox.selectedItem_ = getNonCollapsibleItem(this.toolbox);
|
||||||
let handled = this.toolbox.selectChild_();
|
const handled = this.toolbox.selectChild_();
|
||||||
chai.assert.isFalse(handled);
|
chai.assert.isFalse(handled);
|
||||||
});
|
});
|
||||||
test('Selected item is collapsible -> Should expand', function() {
|
test('Selected item is collapsible -> Should expand', function() {
|
||||||
let collapsibleItem = getCollapsibleItem(this.toolbox);
|
const collapsibleItem = getCollapsibleItem(this.toolbox);
|
||||||
this.toolbox.selectedItem_ = collapsibleItem;
|
this.toolbox.selectedItem_ = collapsibleItem;
|
||||||
let handled = this.toolbox.selectChild_();
|
const handled = this.toolbox.selectChild_();
|
||||||
chai.assert.isTrue(handled);
|
chai.assert.isTrue(handled);
|
||||||
chai.assert.isTrue(collapsibleItem.isExpanded());
|
chai.assert.isTrue(collapsibleItem.isExpanded());
|
||||||
chai.assert.equal(this.toolbox.selectedItem_, collapsibleItem);
|
chai.assert.equal(this.toolbox.selectedItem_, collapsibleItem);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('Selected item is expanded -> Should select child', function() {
|
test('Selected item is expanded -> Should select child', function() {
|
||||||
let collapsibleItem = getCollapsibleItem(this.toolbox);
|
const collapsibleItem = getCollapsibleItem(this.toolbox);
|
||||||
collapsibleItem.expanded_ = true;
|
collapsibleItem.expanded_ = true;
|
||||||
let selectNextStub = sinon.stub(this.toolbox, 'selectNext_');
|
const selectNextStub = sinon.stub(this.toolbox, 'selectNext_');
|
||||||
this.toolbox.selectedItem_ = collapsibleItem;
|
this.toolbox.selectedItem_ = collapsibleItem;
|
||||||
let handled = this.toolbox.selectChild_();
|
const handled = this.toolbox.selectChild_();
|
||||||
chai.assert.isTrue(handled);
|
chai.assert.isTrue(handled);
|
||||||
sinon.assert.called(selectNextStub);
|
sinon.assert.called(selectNextStub);
|
||||||
});
|
});
|
||||||
@@ -258,22 +258,22 @@ suite('Toolbox', function() {
|
|||||||
suite('selectParent_', function() {
|
suite('selectParent_', function() {
|
||||||
test('No item selected -> Should not handle event', function() {
|
test('No item selected -> Should not handle event', function() {
|
||||||
this.toolbox.selectedItem_ = null;
|
this.toolbox.selectedItem_ = null;
|
||||||
let handled = this.toolbox.selectParent_();
|
const handled = this.toolbox.selectParent_();
|
||||||
chai.assert.isFalse(handled);
|
chai.assert.isFalse(handled);
|
||||||
});
|
});
|
||||||
test('Selected item is expanded -> Should collapse', function() {
|
test('Selected item is expanded -> Should collapse', function() {
|
||||||
let collapsibleItem = getCollapsibleItem(this.toolbox);
|
const collapsibleItem = getCollapsibleItem(this.toolbox);
|
||||||
collapsibleItem.expanded_ = true;
|
collapsibleItem.expanded_ = true;
|
||||||
this.toolbox.selectedItem_ = collapsibleItem;
|
this.toolbox.selectedItem_ = collapsibleItem;
|
||||||
let handled = this.toolbox.selectParent_();
|
const handled = this.toolbox.selectParent_();
|
||||||
chai.assert.isTrue(handled);
|
chai.assert.isTrue(handled);
|
||||||
chai.assert.isFalse(collapsibleItem.isExpanded());
|
chai.assert.isFalse(collapsibleItem.isExpanded());
|
||||||
chai.assert.equal(this.toolbox.selectedItem_, collapsibleItem);
|
chai.assert.equal(this.toolbox.selectedItem_, collapsibleItem);
|
||||||
});
|
});
|
||||||
test('Selected item is not expanded -> Should get parent', function() {
|
test('Selected item is not expanded -> Should get parent', function() {
|
||||||
let childItem = getChildItem(this.toolbox);
|
const childItem = getChildItem(this.toolbox);
|
||||||
this.toolbox.selectedItem_ = childItem;
|
this.toolbox.selectedItem_ = childItem;
|
||||||
let handled = this.toolbox.selectParent_();
|
const handled = this.toolbox.selectParent_();
|
||||||
chai.assert.isTrue(handled);
|
chai.assert.isTrue(handled);
|
||||||
chai.assert.equal(this.toolbox.selectedItem_, childItem.getParent());
|
chai.assert.equal(this.toolbox.selectedItem_, childItem.getParent());
|
||||||
});
|
});
|
||||||
@@ -282,29 +282,29 @@ suite('Toolbox', function() {
|
|||||||
suite('selectNext_', function() {
|
suite('selectNext_', function() {
|
||||||
test('No item is selected -> Should not handle event', function() {
|
test('No item is selected -> Should not handle event', function() {
|
||||||
this.toolbox.selectedItem_ = null;
|
this.toolbox.selectedItem_ = null;
|
||||||
let handled = this.toolbox.selectNext_();
|
const handled = this.toolbox.selectNext_();
|
||||||
chai.assert.isFalse(handled);
|
chai.assert.isFalse(handled);
|
||||||
});
|
});
|
||||||
test('Next item is selectable -> Should select next item', function() {
|
test('Next item is selectable -> Should select next item', function() {
|
||||||
let item = this.toolbox.contents_[0];
|
const item = this.toolbox.contents_[0];
|
||||||
this.toolbox.selectedItem_ = item;
|
this.toolbox.selectedItem_ = item;
|
||||||
let handled = this.toolbox.selectNext_();
|
const handled = this.toolbox.selectNext_();
|
||||||
chai.assert.isTrue(handled);
|
chai.assert.isTrue(handled);
|
||||||
chai.assert.equal(this.toolbox.selectedItem_, this.toolbox.contents_[1]);
|
chai.assert.equal(this.toolbox.selectedItem_, this.toolbox.contents_[1]);
|
||||||
});
|
});
|
||||||
test('Selected item is last item -> Should not handle event', function() {
|
test('Selected item is last item -> Should not handle event', function() {
|
||||||
let item = this.toolbox.contents_[this.toolbox.contents_.length - 1];
|
const item = this.toolbox.contents_[this.toolbox.contents_.length - 1];
|
||||||
this.toolbox.selectedItem_ = item;
|
this.toolbox.selectedItem_ = item;
|
||||||
let handled = this.toolbox.selectNext_();
|
const handled = this.toolbox.selectNext_();
|
||||||
chai.assert.isFalse(handled);
|
chai.assert.isFalse(handled);
|
||||||
chai.assert.equal(this.toolbox.selectedItem_, item);
|
chai.assert.equal(this.toolbox.selectedItem_, item);
|
||||||
});
|
});
|
||||||
test('Selected item is collapsed -> Should skip over its children', function() {
|
test('Selected item is collapsed -> Should skip over its children', function() {
|
||||||
let item = getCollapsibleItem(this.toolbox);
|
const item = getCollapsibleItem(this.toolbox);
|
||||||
let childItem = item.flyoutItems_[0];
|
const childItem = item.flyoutItems_[0];
|
||||||
item.expanded_ = false;
|
item.expanded_ = false;
|
||||||
this.toolbox.selectedItem_ = item;
|
this.toolbox.selectedItem_ = item;
|
||||||
let handled = this.toolbox.selectNext_();
|
const handled = this.toolbox.selectNext_();
|
||||||
chai.assert.isTrue(handled);
|
chai.assert.isTrue(handled);
|
||||||
chai.assert.notEqual(this.toolbox.selectedItem_, childItem);
|
chai.assert.notEqual(this.toolbox.selectedItem_, childItem);
|
||||||
});
|
});
|
||||||
@@ -313,32 +313,32 @@ suite('Toolbox', function() {
|
|||||||
suite('selectPrevious', function() {
|
suite('selectPrevious', function() {
|
||||||
test('No item is selected -> Should not handle event', function() {
|
test('No item is selected -> Should not handle event', function() {
|
||||||
this.toolbox.selectedItem_ = null;
|
this.toolbox.selectedItem_ = null;
|
||||||
let handled = this.toolbox.selectPrevious_();
|
const handled = this.toolbox.selectPrevious_();
|
||||||
chai.assert.isFalse(handled);
|
chai.assert.isFalse(handled);
|
||||||
});
|
});
|
||||||
test('Selected item is first item -> Should not handle event', function() {
|
test('Selected item is first item -> Should not handle event', function() {
|
||||||
let item = this.toolbox.contents_[0];
|
const item = this.toolbox.contents_[0];
|
||||||
this.toolbox.selectedItem_ = item;
|
this.toolbox.selectedItem_ = item;
|
||||||
let handled = this.toolbox.selectPrevious_();
|
const handled = this.toolbox.selectPrevious_();
|
||||||
chai.assert.isFalse(handled);
|
chai.assert.isFalse(handled);
|
||||||
chai.assert.equal(this.toolbox.selectedItem_, item);
|
chai.assert.equal(this.toolbox.selectedItem_, item);
|
||||||
});
|
});
|
||||||
test('Previous item is selectable -> Should select previous item', function() {
|
test('Previous item is selectable -> Should select previous item', function() {
|
||||||
let item = this.toolbox.contents_[1];
|
const item = this.toolbox.contents_[1];
|
||||||
let prevItem = this.toolbox.contents_[0];
|
const prevItem = this.toolbox.contents_[0];
|
||||||
this.toolbox.selectedItem_ = item;
|
this.toolbox.selectedItem_ = item;
|
||||||
let handled = this.toolbox.selectPrevious_();
|
const handled = this.toolbox.selectPrevious_();
|
||||||
chai.assert.isTrue(handled);
|
chai.assert.isTrue(handled);
|
||||||
chai.assert.equal(this.toolbox.selectedItem_, prevItem);
|
chai.assert.equal(this.toolbox.selectedItem_, prevItem);
|
||||||
});
|
});
|
||||||
test('Previous item is collapsed -> Should skip over children of the previous item', function() {
|
test('Previous item is collapsed -> Should skip over children of the previous item', function() {
|
||||||
let childItem = getChildItem(this.toolbox);
|
const childItem = getChildItem(this.toolbox);
|
||||||
let parentItem = childItem.getParent();
|
const parentItem = childItem.getParent();
|
||||||
let parentIdx = this.toolbox.contents_.indexOf(parentItem);
|
const parentIdx = this.toolbox.contents_.indexOf(parentItem);
|
||||||
// Gets the item after the parent.
|
// Gets the item after the parent.
|
||||||
let item = this.toolbox.contents_[parentIdx + 1];
|
const item = this.toolbox.contents_[parentIdx + 1];
|
||||||
this.toolbox.selectedItem_ = item;
|
this.toolbox.selectedItem_ = item;
|
||||||
let handled = this.toolbox.selectPrevious_();
|
const handled = this.toolbox.selectPrevious_();
|
||||||
chai.assert.isTrue(handled);
|
chai.assert.isTrue(handled);
|
||||||
chai.assert.notEqual(this.toolbox.selectedItem_, childItem);
|
chai.assert.notEqual(this.toolbox.selectedItem_, childItem);
|
||||||
});
|
});
|
||||||
@@ -355,7 +355,7 @@ suite('Toolbox', function() {
|
|||||||
|
|
||||||
function setupSetSelected(toolbox, oldItem, newItem) {
|
function setupSetSelected(toolbox, oldItem, newItem) {
|
||||||
toolbox.selectedItem_ = oldItem;
|
toolbox.selectedItem_ = oldItem;
|
||||||
let newItemStub = sinon.stub(newItem, 'setSelected');
|
const newItemStub = sinon.stub(newItem, 'setSelected');
|
||||||
toolbox.setSelectedItem(newItem);
|
toolbox.setSelectedItem(newItem);
|
||||||
return newItemStub;
|
return newItemStub;
|
||||||
}
|
}
|
||||||
@@ -363,36 +363,36 @@ suite('Toolbox', function() {
|
|||||||
test('Selected item and new item are null -> Should not update the flyout', function() {
|
test('Selected item and new item are null -> Should not update the flyout', function() {
|
||||||
this.selectedItem_ = null;
|
this.selectedItem_ = null;
|
||||||
this.toolbox.setSelectedItem(null);
|
this.toolbox.setSelectedItem(null);
|
||||||
let updateFlyoutStub = sinon.stub(this.toolbox, 'updateFlyout_');
|
const updateFlyoutStub = sinon.stub(this.toolbox, 'updateFlyout_');
|
||||||
sinon.assert.notCalled(updateFlyoutStub);
|
sinon.assert.notCalled(updateFlyoutStub);
|
||||||
});
|
});
|
||||||
test('New item is not selectable -> Should not update the flyout', function() {
|
test('New item is not selectable -> Should not update the flyout', function() {
|
||||||
let separator = getSeparator(this.toolbox);
|
const separator = getSeparator(this.toolbox);
|
||||||
this.toolbox.setSelectedItem(separator);
|
this.toolbox.setSelectedItem(separator);
|
||||||
let updateFlyoutStub = sinon.stub(this.toolbox, 'updateFlyout_');
|
const updateFlyoutStub = sinon.stub(this.toolbox, 'updateFlyout_');
|
||||||
sinon.assert.notCalled(updateFlyoutStub);
|
sinon.assert.notCalled(updateFlyoutStub);
|
||||||
});
|
});
|
||||||
test('Select an item with no children -> Should select item', function() {
|
test('Select an item with no children -> Should select item', function() {
|
||||||
let oldItem = getCollapsibleItem(this.toolbox);
|
const oldItem = getCollapsibleItem(this.toolbox);
|
||||||
let oldItemStub = sinon.stub(oldItem, 'setSelected');
|
const oldItemStub = sinon.stub(oldItem, 'setSelected');
|
||||||
let newItem = getNonCollapsibleItem(this.toolbox);
|
const newItem = getNonCollapsibleItem(this.toolbox);
|
||||||
let newItemStub = setupSetSelected(this.toolbox, oldItem, newItem);
|
const newItemStub = setupSetSelected(this.toolbox, oldItem, newItem);
|
||||||
sinon.assert.calledWith(oldItemStub, false);
|
sinon.assert.calledWith(oldItemStub, false);
|
||||||
sinon.assert.calledWith(newItemStub, true);
|
sinon.assert.calledWith(newItemStub, true);
|
||||||
});
|
});
|
||||||
test('Select previously selected item with no children -> Should deselect', function() {
|
test('Select previously selected item with no children -> Should deselect', function() {
|
||||||
let newItem = getNonCollapsibleItem(this.toolbox);
|
const newItem = getNonCollapsibleItem(this.toolbox);
|
||||||
let newItemStub = setupSetSelected(this.toolbox, newItem, newItem);
|
const newItemStub = setupSetSelected(this.toolbox, newItem, newItem);
|
||||||
sinon.assert.calledWith(newItemStub, false);
|
sinon.assert.calledWith(newItemStub, false);
|
||||||
});
|
});
|
||||||
test('Select collapsible item -> Should select item', function() {
|
test('Select collapsible item -> Should select item', function() {
|
||||||
let newItem = getCollapsibleItem(this.toolbox);
|
const newItem = getCollapsibleItem(this.toolbox);
|
||||||
let newItemStub = setupSetSelected(this.toolbox, null, newItem);
|
const newItemStub = setupSetSelected(this.toolbox, null, newItem);
|
||||||
sinon.assert.calledWith(newItemStub, true);
|
sinon.assert.calledWith(newItemStub, true);
|
||||||
});
|
});
|
||||||
test('Select previously selected collapsible item -> Should not deselect', function() {
|
test('Select previously selected collapsible item -> Should not deselect', function() {
|
||||||
let newItem = getCollapsibleItem(this.toolbox);
|
const newItem = getCollapsibleItem(this.toolbox);
|
||||||
let newItemStub = setupSetSelected(this.toolbox, newItem, newItem);
|
const newItemStub = setupSetSelected(this.toolbox, newItem, newItem);
|
||||||
sinon.assert.notCalled(newItemStub);
|
sinon.assert.notCalled(newItemStub);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@@ -406,30 +406,30 @@ suite('Toolbox', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
function testHideFlyout(toolbox, oldItem, newItem) {
|
function testHideFlyout(toolbox, oldItem, newItem) {
|
||||||
let updateFlyoutStub = sinon.stub(toolbox.flyout_, 'hide');
|
const updateFlyoutStub = sinon.stub(toolbox.flyout_, 'hide');
|
||||||
toolbox.updateFlyout_(oldItem, newItem);
|
toolbox.updateFlyout_(oldItem, newItem);
|
||||||
sinon.assert.called(updateFlyoutStub);
|
sinon.assert.called(updateFlyoutStub);
|
||||||
}
|
}
|
||||||
|
|
||||||
test('Select previously selected item -> Should close flyout', function() {
|
test('Select previously selected item -> Should close flyout', function() {
|
||||||
let newItem = getNonCollapsibleItem(this.toolbox);
|
const newItem = getNonCollapsibleItem(this.toolbox);
|
||||||
testHideFlyout(this.toolbox, newItem, newItem);
|
testHideFlyout(this.toolbox, newItem, newItem);
|
||||||
});
|
});
|
||||||
test('No new item -> Should close flyout', function() {
|
test('No new item -> Should close flyout', function() {
|
||||||
testHideFlyout(this.toolbox, null, null);
|
testHideFlyout(this.toolbox, null, null);
|
||||||
});
|
});
|
||||||
test('Old item but no new item -> Should close flyout', function() {
|
test('Old item but no new item -> Should close flyout', function() {
|
||||||
let oldItem = getNonCollapsibleItem(this.toolbox);
|
const oldItem = getNonCollapsibleItem(this.toolbox);
|
||||||
testHideFlyout(this.toolbox, oldItem, null);
|
testHideFlyout(this.toolbox, oldItem, null);
|
||||||
});
|
});
|
||||||
test('Select collapsible item -> Should close flyout', function() {
|
test('Select collapsible item -> Should close flyout', function() {
|
||||||
let newItem = getCollapsibleItem(this.toolbox);
|
const newItem = getCollapsibleItem(this.toolbox);
|
||||||
testHideFlyout(this.toolbox, null, newItem);
|
testHideFlyout(this.toolbox, null, newItem);
|
||||||
});
|
});
|
||||||
test('Select selectable item -> Should open flyout', function() {
|
test('Select selectable item -> Should open flyout', function() {
|
||||||
let showFlyoutstub = sinon.stub(this.toolbox.flyout_, 'show');
|
const showFlyoutstub = sinon.stub(this.toolbox.flyout_, 'show');
|
||||||
let scrollToStartFlyout = sinon.stub(this.toolbox.flyout_, 'scrollToStart');
|
const scrollToStartFlyout = sinon.stub(this.toolbox.flyout_, 'scrollToStart');
|
||||||
let newItem = getNonCollapsibleItem(this.toolbox);
|
const newItem = getNonCollapsibleItem(this.toolbox);
|
||||||
this.toolbox.updateFlyout_(null, newItem);
|
this.toolbox.updateFlyout_(null, newItem);
|
||||||
sinon.assert.called(showFlyoutstub);
|
sinon.assert.called(showFlyoutstub);
|
||||||
sinon.assert.called(scrollToStartFlyout);
|
sinon.assert.called(scrollToStartFlyout);
|
||||||
@@ -439,7 +439,7 @@ suite('Toolbox', function() {
|
|||||||
suite('position', function() {
|
suite('position', function() {
|
||||||
setup(function() {
|
setup(function() {
|
||||||
this.toolbox = getBasicToolbox();
|
this.toolbox = getBasicToolbox();
|
||||||
let metricsStub = sinon.stub(this.toolbox.workspace_, 'getMetrics');
|
const metricsStub = sinon.stub(this.toolbox.workspace_, 'getMetrics');
|
||||||
metricsStub.returns({});
|
metricsStub.returns({});
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -454,14 +454,14 @@ suite('Toolbox', function() {
|
|||||||
chai.assert.equal(toolbox.width_, toolbox.HtmlDiv.offsetWidth, 'Check width');
|
chai.assert.equal(toolbox.width_, toolbox.HtmlDiv.offsetWidth, 'Check width');
|
||||||
}
|
}
|
||||||
test('HtmlDiv is not created -> Should not resize', function() {
|
test('HtmlDiv is not created -> Should not resize', function() {
|
||||||
let toolbox = this.toolbox;
|
const toolbox = this.toolbox;
|
||||||
toolbox.HtmlDiv = null;
|
toolbox.HtmlDiv = null;
|
||||||
toolbox.horizontalLayout_ = true;
|
toolbox.horizontalLayout_ = true;
|
||||||
toolbox.position();
|
toolbox.position();
|
||||||
chai.assert.equal(toolbox.height_, 0);
|
chai.assert.equal(toolbox.height_, 0);
|
||||||
});
|
});
|
||||||
test('Horizontal toolbox at top -> Should anchor horizontal toolbox to top', function() {
|
test('Horizontal toolbox at top -> Should anchor horizontal toolbox to top', function() {
|
||||||
let toolbox = this.toolbox;
|
const toolbox = this.toolbox;
|
||||||
toolbox.toolboxPosition = Blockly.utils.toolbox.Position.TOP;
|
toolbox.toolboxPosition = Blockly.utils.toolbox.Position.TOP;
|
||||||
toolbox.horizontalLayout_ = true;
|
toolbox.horizontalLayout_ = true;
|
||||||
toolbox.position();
|
toolbox.position();
|
||||||
@@ -469,7 +469,7 @@ suite('Toolbox', function() {
|
|||||||
chai.assert.equal(toolbox.HtmlDiv.style.top, '0px', 'Check top');
|
chai.assert.equal(toolbox.HtmlDiv.style.top, '0px', 'Check top');
|
||||||
});
|
});
|
||||||
test('Horizontal toolbox at bottom -> Should anchor horizontal toolbox to bottom', function() {
|
test('Horizontal toolbox at bottom -> Should anchor horizontal toolbox to bottom', function() {
|
||||||
let toolbox = this.toolbox;
|
const toolbox = this.toolbox;
|
||||||
toolbox.toolboxPosition = Blockly.utils.toolbox.Position.BOTTOM;
|
toolbox.toolboxPosition = Blockly.utils.toolbox.Position.BOTTOM;
|
||||||
toolbox.horizontalLayout_ = true;
|
toolbox.horizontalLayout_ = true;
|
||||||
toolbox.position();
|
toolbox.position();
|
||||||
@@ -477,7 +477,7 @@ suite('Toolbox', function() {
|
|||||||
chai.assert.equal(toolbox.HtmlDiv.style.bottom, '0px', 'Check bottom');
|
chai.assert.equal(toolbox.HtmlDiv.style.bottom, '0px', 'Check bottom');
|
||||||
});
|
});
|
||||||
test('Vertical toolbox at right -> Should anchor to right', function() {
|
test('Vertical toolbox at right -> Should anchor to right', function() {
|
||||||
let toolbox = this.toolbox;
|
const toolbox = this.toolbox;
|
||||||
toolbox.toolboxPosition = Blockly.utils.toolbox.Position.RIGHT;
|
toolbox.toolboxPosition = Blockly.utils.toolbox.Position.RIGHT;
|
||||||
toolbox.horizontalLayout_ = false;
|
toolbox.horizontalLayout_ = false;
|
||||||
toolbox.position();
|
toolbox.position();
|
||||||
@@ -485,7 +485,7 @@ suite('Toolbox', function() {
|
|||||||
checkVerticalToolbox(toolbox);
|
checkVerticalToolbox(toolbox);
|
||||||
});
|
});
|
||||||
test('Vertical toolbox at left -> Should anchor to left', function() {
|
test('Vertical toolbox at left -> Should anchor to left', function() {
|
||||||
let toolbox = this.toolbox;
|
const toolbox = this.toolbox;
|
||||||
toolbox.toolboxPosition = Blockly.utils.toolbox.Position.LEFT;
|
toolbox.toolboxPosition = Blockly.utils.toolbox.Position.LEFT;
|
||||||
toolbox.horizontalLayout_ = false;
|
toolbox.horizontalLayout_ = false;
|
||||||
toolbox.position();
|
toolbox.position();
|
||||||
@@ -501,8 +501,8 @@ suite('Toolbox', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
function checkValue(actual, expected, value) {
|
function checkValue(actual, expected, value) {
|
||||||
let actualVal = actual[value];
|
const actualVal = actual[value];
|
||||||
let expectedVal = expected[value];
|
const expectedVal = expected[value];
|
||||||
chai.assert.equal(actualVal.toUpperCase(), expectedVal.toUpperCase(), 'Checking value for: ' + value);
|
chai.assert.equal(actualVal.toUpperCase(), expectedVal.toUpperCase(), 'Checking value for: ' + value);
|
||||||
}
|
}
|
||||||
function checkContents(actualContents, expectedContents) {
|
function checkContents(actualContents, expectedContents) {
|
||||||
@@ -519,8 +519,8 @@ suite('Toolbox', function() {
|
|||||||
checkContents(actual.contents, expected.contents);
|
checkContents(actual.contents, expected.contents);
|
||||||
}
|
}
|
||||||
function checkCategoryToolbox(actual, expected) {
|
function checkCategoryToolbox(actual, expected) {
|
||||||
let actualContents = actual['contents'];
|
const actualContents = actual['contents'];
|
||||||
let expectedContents = expected['contents'];
|
const expectedContents = expected['contents'];
|
||||||
chai.assert.equal(actualContents.length, expectedContents.length);
|
chai.assert.equal(actualContents.length, expectedContents.length);
|
||||||
for (let i = 0; i < expected.length; i++) {
|
for (let i = 0; i < expected.length; i++) {
|
||||||
checkCategory(actualContents[i], expected[i]);
|
checkCategory(actualContents[i], expected[i]);
|
||||||
@@ -532,24 +532,24 @@ suite('Toolbox', function() {
|
|||||||
|
|
||||||
suite('parseToolbox', function() {
|
suite('parseToolbox', function() {
|
||||||
test('Category Toolbox: JSON', function() {
|
test('Category Toolbox: JSON', function() {
|
||||||
let toolboxDef = Blockly.utils.toolbox.convertToolboxDefToJson(this.categoryToolboxJSON);
|
const toolboxDef = Blockly.utils.toolbox.convertToolboxDefToJson(this.categoryToolboxJSON);
|
||||||
chai.assert.isNotNull(toolboxDef);
|
chai.assert.isNotNull(toolboxDef);
|
||||||
checkCategoryToolbox(toolboxDef, this.categoryToolboxJSON);
|
checkCategoryToolbox(toolboxDef, this.categoryToolboxJSON);
|
||||||
});
|
});
|
||||||
test('Simple Toolbox: JSON', function() {
|
test('Simple Toolbox: JSON', function() {
|
||||||
let toolboxDef = Blockly.utils.toolbox.convertToolboxDefToJson(this.simpleToolboxJSON);
|
const toolboxDef = Blockly.utils.toolbox.convertToolboxDefToJson(this.simpleToolboxJSON);
|
||||||
chai.assert.isNotNull(toolboxDef);
|
chai.assert.isNotNull(toolboxDef);
|
||||||
checkSimpleToolbox(toolboxDef, this.simpleToolboxJSON);
|
checkSimpleToolbox(toolboxDef, this.simpleToolboxJSON);
|
||||||
});
|
});
|
||||||
test('Category Toolbox: xml', function() {
|
test('Category Toolbox: xml', function() {
|
||||||
let toolboxXml = document.getElementById('toolbox-categories');
|
const toolboxXml = document.getElementById('toolbox-categories');
|
||||||
let toolboxDef = Blockly.utils.toolbox.convertToolboxDefToJson(toolboxXml);
|
const toolboxDef = Blockly.utils.toolbox.convertToolboxDefToJson(toolboxXml);
|
||||||
chai.assert.isNotNull(toolboxDef);
|
chai.assert.isNotNull(toolboxDef);
|
||||||
checkCategoryToolbox(toolboxDef, this.categoryToolboxJSON);
|
checkCategoryToolbox(toolboxDef, this.categoryToolboxJSON);
|
||||||
});
|
});
|
||||||
test('Simple Toolbox: xml', function() {
|
test('Simple Toolbox: xml', function() {
|
||||||
let toolboxXml = document.getElementById('toolbox-simple');
|
const toolboxXml = document.getElementById('toolbox-simple');
|
||||||
let toolboxDef = Blockly.utils.toolbox.convertToolboxDefToJson(toolboxXml);
|
const toolboxDef = Blockly.utils.toolbox.convertToolboxDefToJson(toolboxXml);
|
||||||
chai.assert.isNotNull(toolboxDef);
|
chai.assert.isNotNull(toolboxDef);
|
||||||
checkSimpleToolbox(toolboxDef, this.simpleToolboxJSON);
|
checkSimpleToolbox(toolboxDef, this.simpleToolboxJSON);
|
||||||
});
|
});
|
||||||
@@ -559,7 +559,7 @@ suite('Toolbox', function() {
|
|||||||
toolbox += ' <block type="controls_whileUntil"></block>';
|
toolbox += ' <block type="controls_whileUntil"></block>';
|
||||||
toolbox += '</xml>';
|
toolbox += '</xml>';
|
||||||
|
|
||||||
let toolboxJson = {
|
const toolboxJson = {
|
||||||
'contents': [
|
'contents': [
|
||||||
{
|
{
|
||||||
'kind': 'block',
|
'kind': 'block',
|
||||||
@@ -572,7 +572,7 @@ suite('Toolbox', function() {
|
|||||||
]
|
]
|
||||||
};
|
};
|
||||||
|
|
||||||
let toolboxDef = Blockly.utils.toolbox.convertToolboxDefToJson(toolbox);
|
const toolboxDef = Blockly.utils.toolbox.convertToolboxDefToJson(toolbox);
|
||||||
chai.assert.isNotNull(toolboxDef);
|
chai.assert.isNotNull(toolboxDef);
|
||||||
checkSimpleToolbox(toolboxDef, toolboxJson);
|
checkSimpleToolbox(toolboxDef, toolboxJson);
|
||||||
});
|
});
|
||||||
@@ -582,7 +582,7 @@ suite('Toolbox', function() {
|
|||||||
toolbox += ' <category name="b"></category>';
|
toolbox += ' <category name="b"></category>';
|
||||||
toolbox += '</xml>';
|
toolbox += '</xml>';
|
||||||
|
|
||||||
let toolboxJson = {
|
const toolboxJson = {
|
||||||
'contents': [
|
'contents': [
|
||||||
{
|
{
|
||||||
'kind': 'category',
|
'kind': 'category',
|
||||||
@@ -595,29 +595,29 @@ suite('Toolbox', function() {
|
|||||||
]
|
]
|
||||||
};
|
};
|
||||||
|
|
||||||
let toolboxDef = Blockly.utils.toolbox.convertToolboxDefToJson(toolbox);
|
const toolboxDef = Blockly.utils.toolbox.convertToolboxDefToJson(toolbox);
|
||||||
chai.assert.isNotNull(toolboxDef);
|
chai.assert.isNotNull(toolboxDef);
|
||||||
checkSimpleToolbox(toolboxDef, toolboxJson);
|
checkSimpleToolbox(toolboxDef, toolboxJson);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
suite('parseFlyout', function() {
|
suite('parseFlyout', function() {
|
||||||
test('Array of Nodes', function() {
|
test('Array of Nodes', function() {
|
||||||
let xmlList = getXmlArray();
|
const xmlList = getXmlArray();
|
||||||
let flyoutDef = Blockly.utils.toolbox.convertFlyoutDefToJsonArray(xmlList);
|
const flyoutDef = Blockly.utils.toolbox.convertFlyoutDefToJsonArray(xmlList);
|
||||||
checkContents(flyoutDef, this.simpleToolboxJSON['contents']);
|
checkContents(flyoutDef, this.simpleToolboxJSON['contents']);
|
||||||
});
|
});
|
||||||
test('NodeList', function() {
|
test('NodeList', function() {
|
||||||
let nodeList = document.getElementById('toolbox-simple').childNodes;
|
const nodeList = document.getElementById('toolbox-simple').childNodes;
|
||||||
let flyoutDef = Blockly.utils.toolbox.convertFlyoutDefToJsonArray(nodeList);
|
const flyoutDef = Blockly.utils.toolbox.convertFlyoutDefToJsonArray(nodeList);
|
||||||
checkContents(flyoutDef, this.simpleToolboxJSON['contents']);
|
checkContents(flyoutDef, this.simpleToolboxJSON['contents']);
|
||||||
});
|
});
|
||||||
test('List of json', function() {
|
test('List of json', function() {
|
||||||
let jsonList = this.simpleToolboxJSON['contents'];
|
const jsonList = this.simpleToolboxJSON['contents'];
|
||||||
let flyoutDef = Blockly.utils.toolbox.convertFlyoutDefToJsonArray(jsonList);
|
const flyoutDef = Blockly.utils.toolbox.convertFlyoutDefToJsonArray(jsonList);
|
||||||
checkContents(flyoutDef, this.simpleToolboxJSON['contents']);
|
checkContents(flyoutDef, this.simpleToolboxJSON['contents']);
|
||||||
});
|
});
|
||||||
test('Json', function() {
|
test('Json', function() {
|
||||||
let flyoutDef = Blockly.utils.toolbox.convertFlyoutDefToJsonArray(this.simpleToolboxJSON);
|
const flyoutDef = Blockly.utils.toolbox.convertFlyoutDefToJsonArray(this.simpleToolboxJSON);
|
||||||
checkContents(flyoutDef, this.simpleToolboxJSON['contents']);
|
checkContents(flyoutDef, this.simpleToolboxJSON['contents']);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@@ -631,9 +631,9 @@ suite('Toolbox', function() {
|
|||||||
});
|
});
|
||||||
test('Child categories visible if all ancestors expanded', function() {
|
test('Child categories visible if all ancestors expanded', function() {
|
||||||
this.toolbox.render(getDeeplyNestedJSON());
|
this.toolbox.render(getDeeplyNestedJSON());
|
||||||
let outerCategory = this.toolbox.contents_[0];
|
const outerCategory = this.toolbox.contents_[0];
|
||||||
let middleCategory = this.toolbox.contents_[1];
|
const middleCategory = this.toolbox.contents_[1];
|
||||||
let innerCategory = this.toolbox.contents_[2];
|
const innerCategory = this.toolbox.contents_[2];
|
||||||
|
|
||||||
outerCategory.toggleExpanded();
|
outerCategory.toggleExpanded();
|
||||||
middleCategory.toggleExpanded();
|
middleCategory.toggleExpanded();
|
||||||
@@ -644,8 +644,8 @@ suite('Toolbox', function() {
|
|||||||
});
|
});
|
||||||
test('Child categories not visible if any ancestor not expanded', function() {
|
test('Child categories not visible if any ancestor not expanded', function() {
|
||||||
this.toolbox.render(getDeeplyNestedJSON());
|
this.toolbox.render(getDeeplyNestedJSON());
|
||||||
let middleCategory = this.toolbox.contents_[1];
|
const middleCategory = this.toolbox.contents_[1];
|
||||||
let innerCategory = this.toolbox.contents_[2];
|
const innerCategory = this.toolbox.contents_[2];
|
||||||
|
|
||||||
// Don't expand the outermost category
|
// Don't expand the outermost category
|
||||||
// Even though the direct parent of inner is expanded, it shouldn't be visible
|
// Even though the direct parent of inner is expanded, it shouldn't be visible
|
||||||
|
|||||||
@@ -40,7 +40,7 @@ suite('Tooltip', function() {
|
|||||||
delete Blockly.Blocks["test_block"];
|
delete Blockly.Blocks["test_block"];
|
||||||
});
|
});
|
||||||
|
|
||||||
let tooltipText = 'testTooltip';
|
const tooltipText = 'testTooltip';
|
||||||
|
|
||||||
function assertTooltip(obj) {
|
function assertTooltip(obj) {
|
||||||
chai.assert.equal(obj.getTooltip(), tooltipText);
|
chai.assert.equal(obj.getTooltip(), tooltipText);
|
||||||
|
|||||||
@@ -16,12 +16,12 @@ suite("Trashcan", function() {
|
|||||||
'<xml xmlns="https://developers.google.com/blockly/xml">' +
|
'<xml xmlns="https://developers.google.com/blockly/xml">' +
|
||||||
xmlString + '</xml>');
|
xmlString + '</xml>');
|
||||||
xml = xml.children[0];
|
xml = xml.children[0];
|
||||||
let block = Blockly.Xml.domToBlock(xml, workspace);
|
const block = Blockly.Xml.domToBlock(xml, workspace);
|
||||||
let event = new Blockly.Events.BlockDelete(block);
|
const event = new Blockly.Events.BlockDelete(block);
|
||||||
eventUtils.fire(event);
|
eventUtils.fire(event);
|
||||||
}
|
}
|
||||||
function fireNonDeleteEvent(workspace, oldXml) {
|
function fireNonDeleteEvent(workspace, oldXml) {
|
||||||
let event = new Blockly.Events.Abstract();
|
const event = new Blockly.Events.Abstract();
|
||||||
event.type = 'test_field_block';
|
event.type = 'test_field_block';
|
||||||
event.workspaceId = workspace.id;
|
event.workspaceId = workspace.id;
|
||||||
if (oldXml) {
|
if (oldXml) {
|
||||||
@@ -86,7 +86,7 @@ suite("Trashcan", function() {
|
|||||||
fireDeleteEvent(this.workspace, '<block type="test_field_block"/>');
|
fireDeleteEvent(this.workspace, '<block type="test_field_block"/>');
|
||||||
chai.assert.equal(this.trashcan.contents_.length, 1);
|
chai.assert.equal(this.trashcan.contents_.length, 1);
|
||||||
// Stub flyout interaction.
|
// Stub flyout interaction.
|
||||||
let showFlyoutStub = sinon.stub(this.trashcan.flyout, "show");
|
const showFlyoutStub = sinon.stub(this.trashcan.flyout, "show");
|
||||||
|
|
||||||
simulateClick(this.trashcan.svgGroup_);
|
simulateClick(this.trashcan.svgGroup_);
|
||||||
|
|
||||||
@@ -101,7 +101,7 @@ suite("Trashcan", function() {
|
|||||||
test("Click outside trashcan - fires trashcanClose", function() {
|
test("Click outside trashcan - fires trashcanClose", function() {
|
||||||
sinon.stub(this.trashcan.flyout, 'isVisible').returns(true);
|
sinon.stub(this.trashcan.flyout, 'isVisible').returns(true);
|
||||||
// Stub flyout interaction.
|
// Stub flyout interaction.
|
||||||
let hideFlyoutStub = sinon.stub(this.trashcan.flyout, "hide");
|
const hideFlyoutStub = sinon.stub(this.trashcan.flyout, "hide");
|
||||||
|
|
||||||
simulateClick(this.workspace.svgGroup_);
|
simulateClick(this.workspace.svgGroup_);
|
||||||
|
|
||||||
|
|||||||
@@ -18,10 +18,10 @@ suite('Utils', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
test('genUid', function() {
|
test('genUid', function() {
|
||||||
let uuids = {};
|
const uuids = {};
|
||||||
chai.assert.equal([1, 2, 3].indexOf(4), -1);
|
chai.assert.equal([1, 2, 3].indexOf(4), -1);
|
||||||
for (let i = 0; i < 1000; i++) {
|
for (let i = 0; i < 1000; i++) {
|
||||||
let uuid = Blockly.utils.idGenerator.genUid();
|
const uuid = Blockly.utils.idGenerator.genUid();
|
||||||
chai.assert.isFalse(uuid in uuids, 'UUID different: ' + uuid);
|
chai.assert.isFalse(uuid in uuids, 'UUID different: ' + uuid);
|
||||||
uuids[uuid] = true;
|
uuids[uuid] = true;
|
||||||
}
|
}
|
||||||
@@ -229,7 +229,7 @@ suite('Utils', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
test('arrayRemove', function() {
|
test('arrayRemove', function() {
|
||||||
let arr = [1, 2, 3, 2];
|
const arr = [1, 2, 3, 2];
|
||||||
chai.assert.isFalse(Blockly.utils.arrayRemove(arr, 0), 'Remove Not found');
|
chai.assert.isFalse(Blockly.utils.arrayRemove(arr, 0), 'Remove Not found');
|
||||||
chai.assert.equal(arr.join(','), '1,2,3,2', 'Remove Not found result');
|
chai.assert.equal(arr.join(','), '1,2,3,2', 'Remove Not found result');
|
||||||
chai.assert.isTrue(Blockly.utils.arrayRemove(arr, 2), 'Remove item');
|
chai.assert.isTrue(Blockly.utils.arrayRemove(arr, 2), 'Remove item');
|
||||||
@@ -239,7 +239,7 @@ suite('Utils', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
test('XY_REGEX_', function() {
|
test('XY_REGEX_', function() {
|
||||||
let regex = Blockly.utils.getRelativeXY.XY_REGEX_;
|
const regex = Blockly.utils.getRelativeXY.XY_REGEX_;
|
||||||
let m;
|
let m;
|
||||||
m = 'INVALID'.match(regex);
|
m = 'INVALID'.match(regex);
|
||||||
chai.assert.isNull(m);
|
chai.assert.isNull(m);
|
||||||
@@ -266,7 +266,7 @@ suite('Utils', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
test('XY_STYLE_REGEX_', function() {
|
test('XY_STYLE_REGEX_', function() {
|
||||||
let regex = Blockly.utils.getRelativeXY.XY_STYLE_REGEX_;
|
const regex = Blockly.utils.getRelativeXY.XY_STYLE_REGEX_;
|
||||||
let m;
|
let m;
|
||||||
m = 'INVALID'.match(regex);
|
m = 'INVALID'.match(regex);
|
||||||
chai.assert.isNull(m);
|
chai.assert.isNull(m);
|
||||||
@@ -314,7 +314,7 @@ suite('Utils', function() {
|
|||||||
|
|
||||||
suite('DOM', function() {
|
suite('DOM', function() {
|
||||||
test('addClass', function() {
|
test('addClass', function() {
|
||||||
let p = document.createElement('p');
|
const p = document.createElement('p');
|
||||||
Blockly.utils.dom.addClass(p, 'one');
|
Blockly.utils.dom.addClass(p, 'one');
|
||||||
chai.assert.equal(p.className, 'one', 'Adding "one"');
|
chai.assert.equal(p.className, 'one', 'Adding "one"');
|
||||||
Blockly.utils.dom.addClass(p, 'one');
|
Blockly.utils.dom.addClass(p, 'one');
|
||||||
@@ -328,7 +328,7 @@ suite('Utils', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
test('hasClass', function() {
|
test('hasClass', function() {
|
||||||
let p = document.createElement('p');
|
const p = document.createElement('p');
|
||||||
p.className = ' one three two three ';
|
p.className = ' one three two three ';
|
||||||
chai.assert.isTrue(Blockly.utils.dom.hasClass(p, 'one'), 'Has "one"');
|
chai.assert.isTrue(Blockly.utils.dom.hasClass(p, 'one'), 'Has "one"');
|
||||||
chai.assert.isTrue(Blockly.utils.dom.hasClass(p, 'two'), 'Has "two"');
|
chai.assert.isTrue(Blockly.utils.dom.hasClass(p, 'two'), 'Has "two"');
|
||||||
@@ -338,7 +338,7 @@ suite('Utils', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
test('removeClass', function() {
|
test('removeClass', function() {
|
||||||
let p = document.createElement('p');
|
const p = document.createElement('p');
|
||||||
p.className = ' one three two three ';
|
p.className = ' one three two three ';
|
||||||
Blockly.utils.dom.removeClass(p, 'two');
|
Blockly.utils.dom.removeClass(p, 'two');
|
||||||
chai.assert.equal(p.className, 'one three three', 'Removing "two"');
|
chai.assert.equal(p.className, 'one three three', 'Removing "two"');
|
||||||
@@ -419,7 +419,7 @@ suite('Utils', function() {
|
|||||||
|
|
||||||
suite('Math', function() {
|
suite('Math', function() {
|
||||||
test('toRadians', function() {
|
test('toRadians', function() {
|
||||||
let quarter = Math.PI / 2;
|
const quarter = Math.PI / 2;
|
||||||
chai.assert.equal(Blockly.utils.math.toRadians(-90), -quarter, '-90');
|
chai.assert.equal(Blockly.utils.math.toRadians(-90), -quarter, '-90');
|
||||||
chai.assert.equal(Blockly.utils.math.toRadians(0), 0, '0');
|
chai.assert.equal(Blockly.utils.math.toRadians(0), 0, '0');
|
||||||
chai.assert.equal(Blockly.utils.math.toRadians(90), quarter, '90');
|
chai.assert.equal(Blockly.utils.math.toRadians(90), quarter, '90');
|
||||||
@@ -430,7 +430,7 @@ suite('Utils', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
test('toDegrees', function() {
|
test('toDegrees', function() {
|
||||||
let quarter = Math.PI / 2;
|
const quarter = Math.PI / 2;
|
||||||
chai.assert.equal(Blockly.utils.math.toDegrees(-quarter), -90, '-90');
|
chai.assert.equal(Blockly.utils.math.toDegrees(-quarter), -90, '-90');
|
||||||
chai.assert.equal(Blockly.utils.math.toDegrees(0), 0, '0');
|
chai.assert.equal(Blockly.utils.math.toDegrees(0), 0, '0');
|
||||||
chai.assert.equal(Blockly.utils.math.toDegrees(quarter), 90, '90');
|
chai.assert.equal(Blockly.utils.math.toDegrees(quarter), 90, '90');
|
||||||
|
|||||||
@@ -53,7 +53,7 @@ suite('Variable Map', function() {
|
|||||||
// Assert there is only one variable in the this.variableMap.
|
// Assert there is only one variable in the this.variableMap.
|
||||||
let keys = Object.keys(this.variableMap.variableMap_);
|
let keys = Object.keys(this.variableMap.variableMap_);
|
||||||
chai.assert.equal(keys.length, 1);
|
chai.assert.equal(keys.length, 1);
|
||||||
let varMapLength = this.variableMap.variableMap_[keys[0]].length;
|
const varMapLength = this.variableMap.variableMap_[keys[0]].length;
|
||||||
chai.assert.equal(varMapLength, 1);
|
chai.assert.equal(varMapLength, 1);
|
||||||
|
|
||||||
this.variableMap.createVariable('name1', 'type2', 'id2');
|
this.variableMap.createVariable('name1', 'type2', 'id2');
|
||||||
@@ -105,7 +105,7 @@ suite('Variable Map', function() {
|
|||||||
suite('Error cases', function() {
|
suite('Error cases', function() {
|
||||||
test('Id already exists', function() {
|
test('Id already exists', function() {
|
||||||
this.variableMap.createVariable('name1', 'type1', 'id1');
|
this.variableMap.createVariable('name1', 'type1', 'id1');
|
||||||
let variableMap = this.variableMap;
|
const variableMap = this.variableMap;
|
||||||
chai.assert.throws(function() {
|
chai.assert.throws(function() {
|
||||||
variableMap.createVariable('name2', 'type2', 'id1');
|
variableMap.createVariable('name2', 'type2', 'id1');
|
||||||
}, /"id1".*in use/);
|
}, /"id1".*in use/);
|
||||||
@@ -114,7 +114,7 @@ suite('Variable Map', function() {
|
|||||||
|
|
||||||
test('Mismatched id', function() {
|
test('Mismatched id', function() {
|
||||||
this.variableMap.createVariable('name1', 'type1', 'id1');
|
this.variableMap.createVariable('name1', 'type1', 'id1');
|
||||||
let variableMap = this.variableMap;
|
const variableMap = this.variableMap;
|
||||||
chai.assert.throws(function() {
|
chai.assert.throws(function() {
|
||||||
variableMap.createVariable('name1', 'type1', 'id2');
|
variableMap.createVariable('name1', 'type1', 'id2');
|
||||||
}, /"name1".*in use/);
|
}, /"name1".*in use/);
|
||||||
@@ -123,7 +123,7 @@ suite('Variable Map', function() {
|
|||||||
|
|
||||||
test('Mismatched type', function() {
|
test('Mismatched type', function() {
|
||||||
this.variableMap.createVariable('name1', 'type1', 'id1');
|
this.variableMap.createVariable('name1', 'type1', 'id1');
|
||||||
let variableMap = this.variableMap;
|
const variableMap = this.variableMap;
|
||||||
chai.assert.throws(function() {
|
chai.assert.throws(function() {
|
||||||
variableMap.createVariable('name1', 'type2', 'id1');
|
variableMap.createVariable('name1', 'type2', 'id1');
|
||||||
});
|
});
|
||||||
@@ -135,12 +135,12 @@ suite('Variable Map', function() {
|
|||||||
|
|
||||||
suite('getVariable', function() {
|
suite('getVariable', function() {
|
||||||
test('By name and type', function() {
|
test('By name and type', function() {
|
||||||
let var1 = this.variableMap.createVariable('name1', 'type1', 'id1');
|
const var1 = this.variableMap.createVariable('name1', 'type1', 'id1');
|
||||||
let var2 = this.variableMap.createVariable('name2', 'type1', 'id2');
|
const var2 = this.variableMap.createVariable('name2', 'type1', 'id2');
|
||||||
let var3 = this.variableMap.createVariable('name3', 'type2', 'id3');
|
const var3 = this.variableMap.createVariable('name3', 'type2', 'id3');
|
||||||
let result1 = this.variableMap.getVariable('name1', 'type1');
|
const result1 = this.variableMap.getVariable('name1', 'type1');
|
||||||
let result2 = this.variableMap.getVariable('name2', 'type1');
|
const result2 = this.variableMap.getVariable('name2', 'type1');
|
||||||
let result3 = this.variableMap.getVariable('name3', 'type2');
|
const result3 = this.variableMap.getVariable('name3', 'type2');
|
||||||
|
|
||||||
// Searching by name + type is correct.
|
// Searching by name + type is correct.
|
||||||
chai.assert.equal(result1, var1);
|
chai.assert.equal(result1, var1);
|
||||||
@@ -154,19 +154,19 @@ suite('Variable Map', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
test('Not found', function() {
|
test('Not found', function() {
|
||||||
let result = this.variableMap.getVariable('name1');
|
const result = this.variableMap.getVariable('name1');
|
||||||
chai.assert.isNull(result);
|
chai.assert.isNull(result);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
suite('getVariableById', function() {
|
suite('getVariableById', function() {
|
||||||
test('Trivial', function() {
|
test('Trivial', function() {
|
||||||
let var1 = this.variableMap.createVariable('name1', 'type1', 'id1');
|
const var1 = this.variableMap.createVariable('name1', 'type1', 'id1');
|
||||||
let var2 = this.variableMap.createVariable('name2', 'type1', 'id2');
|
const var2 = this.variableMap.createVariable('name2', 'type1', 'id2');
|
||||||
let var3 = this.variableMap.createVariable('name3', 'type2', 'id3');
|
const var3 = this.variableMap.createVariable('name3', 'type2', 'id3');
|
||||||
let result1 = this.variableMap.getVariableById('id1');
|
const result1 = this.variableMap.getVariableById('id1');
|
||||||
let result2 = this.variableMap.getVariableById('id2');
|
const result2 = this.variableMap.getVariableById('id2');
|
||||||
let result3 = this.variableMap.getVariableById('id3');
|
const result3 = this.variableMap.getVariableById('id3');
|
||||||
|
|
||||||
chai.assert.equal(result1, var1);
|
chai.assert.equal(result1, var1);
|
||||||
chai.assert.equal(result2, var2);
|
chai.assert.equal(result2, var2);
|
||||||
@@ -174,7 +174,7 @@ suite('Variable Map', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
test('Not found', function() {
|
test('Not found', function() {
|
||||||
let result = this.variableMap.getVariableById('id1');
|
const result = this.variableMap.getVariableById('id1');
|
||||||
chai.assert.isNull(result);
|
chai.assert.isNull(result);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@@ -185,70 +185,70 @@ suite('Variable Map', function() {
|
|||||||
this.variableMap.createVariable('name2', 'type1', 'id2');
|
this.variableMap.createVariable('name2', 'type1', 'id2');
|
||||||
this.variableMap.createVariable('name3', 'type2', 'id3');
|
this.variableMap.createVariable('name3', 'type2', 'id3');
|
||||||
this.variableMap.createVariable('name4', 'type3', 'id4');
|
this.variableMap.createVariable('name4', 'type3', 'id4');
|
||||||
let resultArray = this.variableMap.getVariableTypes();
|
const resultArray = this.variableMap.getVariableTypes();
|
||||||
// The empty string is always an option.
|
// The empty string is always an option.
|
||||||
chai.assert.deepEqual(resultArray, ['type1', 'type2', 'type3', '']);
|
chai.assert.deepEqual(resultArray, ['type1', 'type2', 'type3', '']);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('None', function() {
|
test('None', function() {
|
||||||
// The empty string is always an option.
|
// The empty string is always an option.
|
||||||
let resultArray = this.variableMap.getVariableTypes();
|
const resultArray = this.variableMap.getVariableTypes();
|
||||||
chai.assert.deepEqual(resultArray, ['']);
|
chai.assert.deepEqual(resultArray, ['']);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
suite('getVariablesOfType', function() {
|
suite('getVariablesOfType', function() {
|
||||||
test('Trivial', function() {
|
test('Trivial', function() {
|
||||||
let var1 = this.variableMap.createVariable('name1', 'type1', 'id1');
|
const var1 = this.variableMap.createVariable('name1', 'type1', 'id1');
|
||||||
let var2 = this.variableMap.createVariable('name2', 'type1', 'id2');
|
const var2 = this.variableMap.createVariable('name2', 'type1', 'id2');
|
||||||
this.variableMap.createVariable('name3', 'type2', 'id3');
|
this.variableMap.createVariable('name3', 'type2', 'id3');
|
||||||
this.variableMap.createVariable('name4', 'type3', 'id4');
|
this.variableMap.createVariable('name4', 'type3', 'id4');
|
||||||
let resultArray1 = this.variableMap.getVariablesOfType('type1');
|
const resultArray1 = this.variableMap.getVariablesOfType('type1');
|
||||||
let resultArray2 = this.variableMap.getVariablesOfType('type5');
|
const resultArray2 = this.variableMap.getVariablesOfType('type5');
|
||||||
chai.assert.deepEqual(resultArray1, [var1, var2]);
|
chai.assert.deepEqual(resultArray1, [var1, var2]);
|
||||||
chai.assert.deepEqual(resultArray2, []);
|
chai.assert.deepEqual(resultArray2, []);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('Null', function() {
|
test('Null', function() {
|
||||||
let var1 = this.variableMap.createVariable('name1', '', 'id1');
|
const var1 = this.variableMap.createVariable('name1', '', 'id1');
|
||||||
let var2 = this.variableMap.createVariable('name2', '', 'id2');
|
const var2 = this.variableMap.createVariable('name2', '', 'id2');
|
||||||
let var3 = this.variableMap.createVariable('name3', '', 'id3');
|
const var3 = this.variableMap.createVariable('name3', '', 'id3');
|
||||||
this.variableMap.createVariable('name4', 'type1', 'id4');
|
this.variableMap.createVariable('name4', 'type1', 'id4');
|
||||||
let resultArray = this.variableMap.getVariablesOfType(null);
|
const resultArray = this.variableMap.getVariablesOfType(null);
|
||||||
chai.assert.deepEqual(resultArray, [var1, var2, var3]);
|
chai.assert.deepEqual(resultArray, [var1, var2, var3]);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('Empty string', function() {
|
test('Empty string', function() {
|
||||||
let var1 = this.variableMap.createVariable('name1', null, 'id1');
|
const var1 = this.variableMap.createVariable('name1', null, 'id1');
|
||||||
let var2 = this.variableMap.createVariable('name2', null, 'id2');
|
const var2 = this.variableMap.createVariable('name2', null, 'id2');
|
||||||
let resultArray = this.variableMap.getVariablesOfType('');
|
const resultArray = this.variableMap.getVariablesOfType('');
|
||||||
chai.assert.deepEqual(resultArray, [var1, var2]);
|
chai.assert.deepEqual(resultArray, [var1, var2]);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('Deleted', function() {
|
test('Deleted', function() {
|
||||||
let variable = this.variableMap.createVariable('name1', null, 'id1');
|
const variable = this.variableMap.createVariable('name1', null, 'id1');
|
||||||
this.variableMap.deleteVariable(variable);
|
this.variableMap.deleteVariable(variable);
|
||||||
let resultArray = this.variableMap.getVariablesOfType('');
|
const resultArray = this.variableMap.getVariablesOfType('');
|
||||||
chai.assert.deepEqual(resultArray, []);
|
chai.assert.deepEqual(resultArray, []);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('Does not exist', function() {
|
test('Does not exist', function() {
|
||||||
let resultArray = this.variableMap.getVariablesOfType('type1');
|
const resultArray = this.variableMap.getVariablesOfType('type1');
|
||||||
chai.assert.deepEqual(resultArray, []);
|
chai.assert.deepEqual(resultArray, []);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
suite('getAllVariables', function() {
|
suite('getAllVariables', function() {
|
||||||
test('Trivial', function() {
|
test('Trivial', function() {
|
||||||
let var1 = this.variableMap.createVariable('name1', 'type1', 'id1');
|
const var1 = this.variableMap.createVariable('name1', 'type1', 'id1');
|
||||||
let var2 = this.variableMap.createVariable('name2', 'type1', 'id2');
|
const var2 = this.variableMap.createVariable('name2', 'type1', 'id2');
|
||||||
let var3 = this.variableMap.createVariable('name3', 'type2', 'id3');
|
const var3 = this.variableMap.createVariable('name3', 'type2', 'id3');
|
||||||
let resultArray = this.variableMap.getAllVariables();
|
const resultArray = this.variableMap.getAllVariables();
|
||||||
chai.assert.deepEqual(resultArray, [var1, var2, var3]);
|
chai.assert.deepEqual(resultArray, [var1, var2, var3]);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('None', function() {
|
test('None', function() {
|
||||||
let resultArray = this.variableMap.getAllVariables();
|
const resultArray = this.variableMap.getAllVariables();
|
||||||
chai.assert.deepEqual(resultArray, []);
|
chai.assert.deepEqual(resultArray, []);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ suite('Variable Model', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
test('Trivial', function() {
|
test('Trivial', function() {
|
||||||
let variable = new Blockly.VariableModel(
|
const variable = new Blockly.VariableModel(
|
||||||
this.workspace, 'test', 'test_type', 'test_id');
|
this.workspace, 'test', 'test_type', 'test_id');
|
||||||
chai.assert.equal(variable.name, 'test');
|
chai.assert.equal(variable.name, 'test');
|
||||||
chai.assert.equal(variable.type, 'test_type');
|
chai.assert.equal(variable.type, 'test_type');
|
||||||
@@ -28,19 +28,19 @@ suite('Variable Model', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
test('Null type', function() {
|
test('Null type', function() {
|
||||||
let variable = new Blockly.VariableModel(
|
const variable = new Blockly.VariableModel(
|
||||||
this.workspace, 'test', null, 'test_id');
|
this.workspace, 'test', null, 'test_id');
|
||||||
chai.assert.equal(variable.type, '');
|
chai.assert.equal(variable.type, '');
|
||||||
});
|
});
|
||||||
|
|
||||||
test('Undefined type', function() {
|
test('Undefined type', function() {
|
||||||
let variable = new Blockly.VariableModel(
|
const variable = new Blockly.VariableModel(
|
||||||
this.workspace, 'test', undefined, 'test_id');
|
this.workspace, 'test', undefined, 'test_id');
|
||||||
chai.assert.equal(variable.type, '');
|
chai.assert.equal(variable.type, '');
|
||||||
});
|
});
|
||||||
|
|
||||||
test('Null id', function() {
|
test('Null id', function() {
|
||||||
let variable = new Blockly.VariableModel(
|
const variable = new Blockly.VariableModel(
|
||||||
this.workspace, 'test', 'test_type', null);
|
this.workspace, 'test', 'test_type', null);
|
||||||
chai.assert.equal(variable.name, 'test');
|
chai.assert.equal(variable.name, 'test');
|
||||||
chai.assert.equal(variable.type, 'test_type');
|
chai.assert.equal(variable.type, 'test_type');
|
||||||
@@ -48,7 +48,7 @@ suite('Variable Model', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
test('Undefined id', function() {
|
test('Undefined id', function() {
|
||||||
let variable = new Blockly.VariableModel(
|
const variable = new Blockly.VariableModel(
|
||||||
this.workspace, 'test', 'test_type', undefined);
|
this.workspace, 'test', 'test_type', undefined);
|
||||||
chai.assert.equal(variable.name, 'test');
|
chai.assert.equal(variable.name, 'test');
|
||||||
chai.assert.equal(variable.type, 'test_type');
|
chai.assert.equal(variable.type, 'test_type');
|
||||||
@@ -56,7 +56,7 @@ suite('Variable Model', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
test('Only name provided', function() {
|
test('Only name provided', function() {
|
||||||
let variable = new Blockly.VariableModel(this.workspace, 'test');
|
const variable = new Blockly.VariableModel(this.workspace, 'test');
|
||||||
chai.assert.equal(variable.name, 'test');
|
chai.assert.equal(variable.name, 'test');
|
||||||
chai.assert.equal(variable.type, '');
|
chai.assert.equal(variable.type, '');
|
||||||
chai.assert.exists(variable.id_);
|
chai.assert.exists(variable.id_);
|
||||||
|
|||||||
@@ -44,7 +44,7 @@ suite('Variables', function() {
|
|||||||
function createTestVarBlock(workspace, variable_id) {
|
function createTestVarBlock(workspace, variable_id) {
|
||||||
// Turn off events to avoid testing XML at the same time.
|
// Turn off events to avoid testing XML at the same time.
|
||||||
Blockly.Events.disable();
|
Blockly.Events.disable();
|
||||||
let block = new Blockly.Block(workspace, 'get_var_block');
|
const block = new Blockly.Block(workspace, 'get_var_block');
|
||||||
block.inputList[0].fieldRow[0].setValue(variable_id);
|
block.inputList[0].fieldRow[0].setValue(variable_id);
|
||||||
Blockly.Events.enable();
|
Blockly.Events.enable();
|
||||||
return block;
|
return block;
|
||||||
@@ -56,7 +56,7 @@ suite('Variables', function() {
|
|||||||
createTestVarBlock(this.workspace, '2');
|
createTestVarBlock(this.workspace, '2');
|
||||||
createTestVarBlock(this.workspace, '3');
|
createTestVarBlock(this.workspace, '3');
|
||||||
|
|
||||||
let result = Blockly.Variables.allUsedVarModels(this.workspace);
|
const result = Blockly.Variables.allUsedVarModels(this.workspace);
|
||||||
chai.assert.equal(result.length, 3,
|
chai.assert.equal(result.length, 3,
|
||||||
'Expected three variables in the list of used variables');
|
'Expected three variables in the list of used variables');
|
||||||
});
|
});
|
||||||
@@ -64,7 +64,7 @@ suite('Variables', function() {
|
|||||||
test('Some unused', function() {
|
test('Some unused', function() {
|
||||||
createTestVarBlock(this.workspace, '2');
|
createTestVarBlock(this.workspace, '2');
|
||||||
|
|
||||||
let result = Blockly.Variables.allUsedVarModels(this.workspace);
|
const result = Blockly.Variables.allUsedVarModels(this.workspace);
|
||||||
chai.assert.equal(result.length, 1,
|
chai.assert.equal(result.length, 1,
|
||||||
'Expected one variable in the list of used variables');
|
'Expected one variable in the list of used variables');
|
||||||
chai.assert.equal(result[0].getId(), '2',
|
chai.assert.equal(result[0].getId(), '2',
|
||||||
@@ -75,7 +75,7 @@ suite('Variables', function() {
|
|||||||
createTestVarBlock(this.workspace, '2');
|
createTestVarBlock(this.workspace, '2');
|
||||||
createTestVarBlock(this.workspace, '2');
|
createTestVarBlock(this.workspace, '2');
|
||||||
|
|
||||||
let result = Blockly.Variables.allUsedVarModels(this.workspace);
|
const result = Blockly.Variables.allUsedVarModels(this.workspace);
|
||||||
// Using the same variable multiple times should not change the number of
|
// Using the same variable multiple times should not change the number of
|
||||||
// elements in the list.
|
// elements in the list.
|
||||||
chai.assert.equal(result.length, 1,
|
chai.assert.equal(result.length, 1,
|
||||||
@@ -85,7 +85,7 @@ suite('Variables', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
test('All unused', function() {
|
test('All unused', function() {
|
||||||
let result = Blockly.Variables.allUsedVarModels(this.workspace);
|
const result = Blockly.Variables.allUsedVarModels(this.workspace);
|
||||||
chai.assert.equal(result.length, 0,
|
chai.assert.equal(result.length, 0,
|
||||||
'Expected no variables in the list of used variables');
|
'Expected no variables in the list of used variables');
|
||||||
});
|
});
|
||||||
@@ -93,12 +93,12 @@ suite('Variables', function() {
|
|||||||
|
|
||||||
suite('getVariable', function() {
|
suite('getVariable', function() {
|
||||||
test('By id', function() {
|
test('By id', function() {
|
||||||
let var1 = this.workspace.createVariable('name1', 'type1', 'id1');
|
const var1 = this.workspace.createVariable('name1', 'type1', 'id1');
|
||||||
let var2 = this.workspace.createVariable('name2', 'type1', 'id2');
|
const var2 = this.workspace.createVariable('name2', 'type1', 'id2');
|
||||||
let var3 = this.workspace.createVariable('name3', 'type2', 'id3');
|
const var3 = this.workspace.createVariable('name3', 'type2', 'id3');
|
||||||
let result1 = Blockly.Variables.getVariable(this.workspace, 'id1');
|
const result1 = Blockly.Variables.getVariable(this.workspace, 'id1');
|
||||||
let result2 = Blockly.Variables.getVariable(this.workspace, 'id2');
|
const result2 = Blockly.Variables.getVariable(this.workspace, 'id2');
|
||||||
let result3 = Blockly.Variables.getVariable(this.workspace, 'id3');
|
const result3 = Blockly.Variables.getVariable(this.workspace, 'id3');
|
||||||
|
|
||||||
chai.assert.equal(var1, result1);
|
chai.assert.equal(var1, result1);
|
||||||
chai.assert.equal(var2, result2);
|
chai.assert.equal(var2, result2);
|
||||||
@@ -106,14 +106,14 @@ suite('Variables', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
test('By name and type', function() {
|
test('By name and type', function() {
|
||||||
let var1 = this.workspace.createVariable('name1', 'type1', 'id1');
|
const var1 = this.workspace.createVariable('name1', 'type1', 'id1');
|
||||||
let var2 = this.workspace.createVariable('name2', 'type1', 'id2');
|
const var2 = this.workspace.createVariable('name2', 'type1', 'id2');
|
||||||
let var3 = this.workspace.createVariable('name3', 'type2', 'id3');
|
const var3 = this.workspace.createVariable('name3', 'type2', 'id3');
|
||||||
let result1 =
|
const result1 =
|
||||||
Blockly.Variables.getVariable(this.workspace, null, 'name1', 'type1');
|
Blockly.Variables.getVariable(this.workspace, null, 'name1', 'type1');
|
||||||
let result2 =
|
const result2 =
|
||||||
Blockly.Variables.getVariable(this.workspace, null, 'name2', 'type1');
|
Blockly.Variables.getVariable(this.workspace, null, 'name2', 'type1');
|
||||||
let result3 =
|
const result3 =
|
||||||
Blockly.Variables.getVariable(this.workspace, null, 'name3', 'type2');
|
Blockly.Variables.getVariable(this.workspace, null, 'name3', 'type2');
|
||||||
|
|
||||||
// Searching by name + type is correct.
|
// Searching by name + type is correct.
|
||||||
@@ -123,14 +123,14 @@ suite('Variables', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
test('Bad id with name and type fallback', function() {
|
test('Bad id with name and type fallback', function() {
|
||||||
let var1 = this.workspace.createVariable('name1', 'type1', 'id1');
|
const var1 = this.workspace.createVariable('name1', 'type1', 'id1');
|
||||||
let var2 = this.workspace.createVariable('name2', 'type1', 'id2');
|
const var2 = this.workspace.createVariable('name2', 'type1', 'id2');
|
||||||
let var3 = this.workspace.createVariable('name3', 'type2', 'id3');
|
const var3 = this.workspace.createVariable('name3', 'type2', 'id3');
|
||||||
let result1 =
|
const result1 =
|
||||||
Blockly.Variables.getVariable(this.workspace, 'badId', 'name1', 'type1');
|
Blockly.Variables.getVariable(this.workspace, 'badId', 'name1', 'type1');
|
||||||
let result2 =
|
const result2 =
|
||||||
Blockly.Variables.getVariable(this.workspace, 'badId', 'name2', 'type1');
|
Blockly.Variables.getVariable(this.workspace, 'badId', 'name2', 'type1');
|
||||||
let result3 =
|
const result3 =
|
||||||
Blockly.Variables.getVariable(this.workspace, 'badId', 'name3', 'type2');
|
Blockly.Variables.getVariable(this.workspace, 'badId', 'name3', 'type2');
|
||||||
|
|
||||||
// Searching by ID failed, but falling back onto name + type is correct.
|
// Searching by ID failed, but falling back onto name + type is correct.
|
||||||
|
|||||||
@@ -45,7 +45,7 @@ suite('WidgetDiv', function() {
|
|||||||
anchorBBox, rtl, expectedX, expectedY, expectedHeight) {
|
anchorBBox, rtl, expectedX, expectedY, expectedHeight) {
|
||||||
Blockly.WidgetDiv.positionWithAnchor(
|
Blockly.WidgetDiv.positionWithAnchor(
|
||||||
this.viewportBBox, anchorBBox, this.widgetSize, rtl);
|
this.viewportBBox, anchorBBox, this.widgetSize, rtl);
|
||||||
let style = Blockly.WidgetDiv.getDiv().style;
|
const style = Blockly.WidgetDiv.getDiv().style;
|
||||||
chai.assert.equal(style.left, expectedX + 'px', 'Left');
|
chai.assert.equal(style.left, expectedX + 'px', 'Left');
|
||||||
chai.assert.equal(style.top, expectedY + 'px', 'Top');
|
chai.assert.equal(style.top, expectedY + 'px', 'Top');
|
||||||
chai.assert.equal(style.height, expectedHeight + 'px', 'Height');
|
chai.assert.equal(style.height, expectedHeight + 'px', 'Height');
|
||||||
@@ -55,57 +55,57 @@ suite('WidgetDiv', function() {
|
|||||||
suite('LTR', function() {
|
suite('LTR', function() {
|
||||||
test('noConflict', function() {
|
test('noConflict', function() {
|
||||||
// Anchor placed in the middle.
|
// Anchor placed in the middle.
|
||||||
let anchorBBox =
|
const anchorBBox =
|
||||||
makeBBox(500, 500, this.anchorSize.width, this.anchorSize.height);
|
makeBBox(500, 500, this.anchorSize.width, this.anchorSize.height);
|
||||||
// The widget div should be placed just below at the left side of the
|
// The widget div should be placed just below at the left side of the
|
||||||
// anchor.
|
// anchor.
|
||||||
let expectedX = anchorBBox.left;
|
const expectedX = anchorBBox.left;
|
||||||
let expectedY = anchorBBox.top + this.anchorSize.height;
|
const expectedY = anchorBBox.top + this.anchorSize.height;
|
||||||
this.testWidgetPosition(
|
this.testWidgetPosition(
|
||||||
anchorBBox, false, expectedX, expectedY, this.widgetSize.height);
|
anchorBBox, false, expectedX, expectedY, this.widgetSize.height);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('topConflict', function() {
|
test('topConflict', function() {
|
||||||
// Anchor close to the top.
|
// Anchor close to the top.
|
||||||
let anchorBBox =
|
const anchorBBox =
|
||||||
makeBBox(500, 50, this.anchorSize.width, this.anchorSize.height);
|
makeBBox(500, 50, this.anchorSize.width, this.anchorSize.height);
|
||||||
// The widget div should be placed just below the anchor.
|
// The widget div should be placed just below the anchor.
|
||||||
let expectedX = anchorBBox.left;
|
const expectedX = anchorBBox.left;
|
||||||
let expectedY = anchorBBox.top + this.anchorSize.height;
|
const expectedY = anchorBBox.top + this.anchorSize.height;
|
||||||
this.testWidgetPosition(
|
this.testWidgetPosition(
|
||||||
anchorBBox, false, expectedX, expectedY, this.widgetSize.height);
|
anchorBBox, false, expectedX, expectedY, this.widgetSize.height);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('bottomConflict', function() {
|
test('bottomConflict', function() {
|
||||||
// Anchor placed close to the bottom.
|
// Anchor placed close to the bottom.
|
||||||
let anchorBBox =
|
const anchorBBox =
|
||||||
makeBBox(500, 900, this.anchorSize.width, this.anchorSize.height);
|
makeBBox(500, 900, this.anchorSize.width, this.anchorSize.height);
|
||||||
// The widget div should be placed just above the anchor.
|
// The widget div should be placed just above the anchor.
|
||||||
let expectedX = anchorBBox.left;
|
const expectedX = anchorBBox.left;
|
||||||
let expectedY = anchorBBox.top - this.widgetSize.height;
|
const expectedY = anchorBBox.top - this.widgetSize.height;
|
||||||
this.testWidgetPosition(
|
this.testWidgetPosition(
|
||||||
anchorBBox, false, expectedX, expectedY, this.widgetSize.height);
|
anchorBBox, false, expectedX, expectedY, this.widgetSize.height);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('leftConflict', function() {
|
test('leftConflict', function() {
|
||||||
// Anchor placed close to the left side.
|
// Anchor placed close to the left side.
|
||||||
let anchorBBox =
|
const anchorBBox =
|
||||||
makeBBox(50, 500, this.anchorSize.width, this.anchorSize.height);
|
makeBBox(50, 500, this.anchorSize.width, this.anchorSize.height);
|
||||||
// The widget div should be placed at the anchor.
|
// The widget div should be placed at the anchor.
|
||||||
let expectedX = anchorBBox.left;
|
const expectedX = anchorBBox.left;
|
||||||
let expectedY = anchorBBox.top + this.anchorSize.height;
|
const expectedY = anchorBBox.top + this.anchorSize.height;
|
||||||
this.testWidgetPosition(
|
this.testWidgetPosition(
|
||||||
anchorBBox, false, expectedX, expectedY, this.widgetSize.height);
|
anchorBBox, false, expectedX, expectedY, this.widgetSize.height);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('rightConflict', function() {
|
test('rightConflict', function() {
|
||||||
// Anchor placed close to the right side.
|
// Anchor placed close to the right side.
|
||||||
let anchorBBox =
|
const anchorBBox =
|
||||||
makeBBox(950, 500, this.anchorSize.width, this.anchorSize.height);
|
makeBBox(950, 500, this.anchorSize.width, this.anchorSize.height);
|
||||||
// The widget div should be placed as far right as possible--at the edge of
|
// The widget div should be placed as far right as possible--at the edge of
|
||||||
// the screen.
|
// the screen.
|
||||||
let expectedX = this.viewportBBox.width - this.widgetSize.width;
|
const expectedX = this.viewportBBox.width - this.widgetSize.width;
|
||||||
let expectedY = anchorBBox.top + this.anchorSize.height;
|
const expectedY = anchorBBox.top + this.anchorSize.height;
|
||||||
this.testWidgetPosition(
|
this.testWidgetPosition(
|
||||||
anchorBBox, false, expectedX, expectedY, this.widgetSize.height);
|
anchorBBox, false, expectedX, expectedY, this.widgetSize.height);
|
||||||
});
|
});
|
||||||
@@ -113,57 +113,57 @@ suite('WidgetDiv', function() {
|
|||||||
suite('RTL', function() {
|
suite('RTL', function() {
|
||||||
test('noConflict', function() {
|
test('noConflict', function() {
|
||||||
// Anchor placed in the middle
|
// Anchor placed in the middle
|
||||||
let anchorBBox =
|
const anchorBBox =
|
||||||
makeBBox(500, 500, this.anchorSize.width, this.anchorSize.height);
|
makeBBox(500, 500, this.anchorSize.width, this.anchorSize.height);
|
||||||
// The widget div should be placed at the right side of the anchor.
|
// The widget div should be placed at the right side of the anchor.
|
||||||
let expectedX = anchorBBox.right - this.widgetSize.width;
|
const expectedX = anchorBBox.right - this.widgetSize.width;
|
||||||
let expectedY = anchorBBox.top + this.anchorSize.height;
|
const expectedY = anchorBBox.top + this.anchorSize.height;
|
||||||
this.testWidgetPosition(
|
this.testWidgetPosition(
|
||||||
anchorBBox, true, expectedX, expectedY, this.widgetSize.height);
|
anchorBBox, true, expectedX, expectedY, this.widgetSize.height);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('topConflict', function() {
|
test('topConflict', function() {
|
||||||
// Anchor close to the top.
|
// Anchor close to the top.
|
||||||
let anchorBBox =
|
const anchorBBox =
|
||||||
makeBBox(500, 50, this.anchorSize.width, this.anchorSize.height);
|
makeBBox(500, 50, this.anchorSize.width, this.anchorSize.height);
|
||||||
// The widget div should be placed just below the anchor.
|
// The widget div should be placed just below the anchor.
|
||||||
let expectedX = anchorBBox.right - this.widgetSize.width;
|
const expectedX = anchorBBox.right - this.widgetSize.width;
|
||||||
let expectedY = anchorBBox.top + this.anchorSize.height;
|
const expectedY = anchorBBox.top + this.anchorSize.height;
|
||||||
this.testWidgetPosition(
|
this.testWidgetPosition(
|
||||||
anchorBBox, true, expectedX, expectedY, this.widgetSize.height);
|
anchorBBox, true, expectedX, expectedY, this.widgetSize.height);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('bottomConflict', function() {
|
test('bottomConflict', function() {
|
||||||
// Anchor placed close to the bottom.
|
// Anchor placed close to the bottom.
|
||||||
let anchorBBox =
|
const anchorBBox =
|
||||||
makeBBox(500, 900, this.anchorSize.width, this.anchorSize.height);
|
makeBBox(500, 900, this.anchorSize.width, this.anchorSize.height);
|
||||||
// The widget div should be placed just above the anchor.
|
// The widget div should be placed just above the anchor.
|
||||||
let expectedX = anchorBBox.right - this.widgetSize.width;
|
const expectedX = anchorBBox.right - this.widgetSize.width;
|
||||||
let expectedY = anchorBBox.top - this.widgetSize.height;
|
const expectedY = anchorBBox.top - this.widgetSize.height;
|
||||||
this.testWidgetPosition(
|
this.testWidgetPosition(
|
||||||
anchorBBox, true, expectedX, expectedY, this.widgetSize.height);
|
anchorBBox, true, expectedX, expectedY, this.widgetSize.height);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('leftConflict', function() {
|
test('leftConflict', function() {
|
||||||
// Anchor placed close to the left side.
|
// Anchor placed close to the left side.
|
||||||
let anchorBBox =
|
const anchorBBox =
|
||||||
makeBBox(10, 500, this.anchorSize.width, this.anchorSize.height);
|
makeBBox(10, 500, this.anchorSize.width, this.anchorSize.height);
|
||||||
// The widget div should be placed as far left as possible--at the edge of
|
// The widget div should be placed as far left as possible--at the edge of
|
||||||
// the screen.
|
// the screen.
|
||||||
let expectedX = 0;
|
const expectedX = 0;
|
||||||
let expectedY = anchorBBox.top + this.anchorSize.height;
|
const expectedY = anchorBBox.top + this.anchorSize.height;
|
||||||
this.testWidgetPosition(
|
this.testWidgetPosition(
|
||||||
anchorBBox, true, expectedX, expectedY, this.widgetSize.height);
|
anchorBBox, true, expectedX, expectedY, this.widgetSize.height);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('rightConflict', function() {
|
test('rightConflict', function() {
|
||||||
// Anchor placed close to the right side.
|
// Anchor placed close to the right side.
|
||||||
let anchorBBox =
|
const anchorBBox =
|
||||||
makeBBox(950, 500, this.anchorSize.width, this.anchorSize.height);
|
makeBBox(950, 500, this.anchorSize.width, this.anchorSize.height);
|
||||||
// The widget div should be placed as far right as possible--at the edge of
|
// The widget div should be placed as far right as possible--at the edge of
|
||||||
// the screen.
|
// the screen.
|
||||||
let expectedX = this.viewportBBox.width - this.widgetSize.width;
|
const expectedX = this.viewportBBox.width - this.widgetSize.width;
|
||||||
let expectedY = anchorBBox.top + this.anchorSize.height;
|
const expectedY = anchorBBox.top + this.anchorSize.height;
|
||||||
this.testWidgetPosition(
|
this.testWidgetPosition(
|
||||||
anchorBBox, true, expectedX, expectedY, this.widgetSize.height);
|
anchorBBox, true, expectedX, expectedY, this.widgetSize.height);
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ suite('Workspace comment', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
test('One comment', function() {
|
test('One comment', function() {
|
||||||
let comment = new Blockly.WorkspaceComment(
|
const comment = new Blockly.WorkspaceComment(
|
||||||
this.workspace, 'comment text', 0, 0, 'comment id');
|
this.workspace, 'comment text', 0, 0, 'comment id');
|
||||||
chai.assert.equal(this.workspace.getTopComments(true).length, 1);
|
chai.assert.equal(this.workspace.getTopComments(true).length, 1);
|
||||||
chai.assert.equal(this.workspace.commentDB_['comment id'], comment);
|
chai.assert.equal(this.workspace.commentDB_['comment id'], comment);
|
||||||
@@ -46,7 +46,7 @@ suite('Workspace comment', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
test('After dispose', function() {
|
test('After dispose', function() {
|
||||||
let comment = new Blockly.WorkspaceComment(
|
const comment = new Blockly.WorkspaceComment(
|
||||||
this.workspace, 'comment text', 0, 0, 'comment id');
|
this.workspace, 'comment text', 0, 0, 'comment id');
|
||||||
comment.dispose();
|
comment.dispose();
|
||||||
chai.assert.equal(this.workspace.getTopComments(true).length, 0);
|
chai.assert.equal(this.workspace.getTopComments(true).length, 0);
|
||||||
@@ -60,7 +60,7 @@ suite('Workspace comment', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
test('One comment', function() {
|
test('One comment', function() {
|
||||||
let comment = new Blockly.WorkspaceComment(
|
const comment = new Blockly.WorkspaceComment(
|
||||||
this.workspace, 'comment text', 0, 0, 'comment id');
|
this.workspace, 'comment text', 0, 0, 'comment id');
|
||||||
chai.assert.equal(this.workspace.getTopComments(false).length, 1);
|
chai.assert.equal(this.workspace.getTopComments(false).length, 1);
|
||||||
chai.assert.equal(this.workspace.commentDB_['comment id'], comment);
|
chai.assert.equal(this.workspace.commentDB_['comment id'], comment);
|
||||||
@@ -80,7 +80,7 @@ suite('Workspace comment', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
test('After dispose', function() {
|
test('After dispose', function() {
|
||||||
let comment = new Blockly.WorkspaceComment(
|
const comment = new Blockly.WorkspaceComment(
|
||||||
this.workspace, 'comment text', 0, 0, 'comment id');
|
this.workspace, 'comment text', 0, 0, 'comment id');
|
||||||
comment.dispose();
|
comment.dispose();
|
||||||
chai.assert.equal(this.workspace.getTopComments(false).length, 0);
|
chai.assert.equal(this.workspace.getTopComments(false).length, 0);
|
||||||
@@ -90,7 +90,7 @@ suite('Workspace comment', function() {
|
|||||||
|
|
||||||
suite('getCommentById', function() {
|
suite('getCommentById', function() {
|
||||||
test('Trivial', function() {
|
test('Trivial', function() {
|
||||||
let comment = new Blockly.WorkspaceComment(
|
const comment = new Blockly.WorkspaceComment(
|
||||||
this.workspace, 'comment text', 0, 0, 'comment id');
|
this.workspace, 'comment text', 0, 0, 'comment id');
|
||||||
chai.assert.equal(this.workspace.getCommentById(comment.id), comment);
|
chai.assert.equal(this.workspace.getCommentById(comment.id), comment);
|
||||||
});
|
});
|
||||||
@@ -104,7 +104,7 @@ suite('Workspace comment', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
test('After dispose', function() {
|
test('After dispose', function() {
|
||||||
let comment = new Blockly.WorkspaceComment(
|
const comment = new Blockly.WorkspaceComment(
|
||||||
this.workspace, 'comment text', 0, 0, 'comment id');
|
this.workspace, 'comment text', 0, 0, 'comment id');
|
||||||
comment.dispose();
|
comment.dispose();
|
||||||
chai.assert.isNull(this.workspace.getCommentById(comment.id));
|
chai.assert.isNull(this.workspace.getCommentById(comment.id));
|
||||||
@@ -113,7 +113,7 @@ suite('Workspace comment', function() {
|
|||||||
|
|
||||||
suite('dispose', function() {
|
suite('dispose', function() {
|
||||||
test('Called twice', function() {
|
test('Called twice', function() {
|
||||||
let comment = new Blockly.WorkspaceComment(
|
const comment = new Blockly.WorkspaceComment(
|
||||||
this.workspace, 'comment text', 0, 0, 'comment id');
|
this.workspace, 'comment text', 0, 0, 'comment id');
|
||||||
comment.dispose();
|
comment.dispose();
|
||||||
// Nothing should go wrong the second time dispose is called.
|
// Nothing should go wrong the second time dispose is called.
|
||||||
@@ -152,14 +152,14 @@ suite('Workspace comment', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
test('Initial position', function() {
|
test('Initial position', function() {
|
||||||
let xy = this.comment.getXY();
|
const xy = this.comment.getXY();
|
||||||
chai.assert.equal(xy.x, 0, 'Initial X position');
|
chai.assert.equal(xy.x, 0, 'Initial X position');
|
||||||
chai.assert.equal(xy.y, 0, 'Initial Y position');
|
chai.assert.equal(xy.y, 0, 'Initial Y position');
|
||||||
});
|
});
|
||||||
|
|
||||||
test('moveBy', function() {
|
test('moveBy', function() {
|
||||||
this.comment.moveBy(10, 100);
|
this.comment.moveBy(10, 100);
|
||||||
let xy = this.comment.getXY();
|
const xy = this.comment.getXY();
|
||||||
chai.assert.equal(xy.x, 10, 'New X position');
|
chai.assert.equal(xy.x, 10, 'New X position');
|
||||||
chai.assert.equal(xy.y, 100, 'New Y position');
|
chai.assert.equal(xy.y, 100, 'New Y position');
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -35,22 +35,22 @@ function testAWorkspace() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
function assertBlockVarModelName(workspace, blockIndex, name) {
|
function assertBlockVarModelName(workspace, blockIndex, name) {
|
||||||
let block = workspace.topBlocks_[blockIndex];
|
const block = workspace.topBlocks_[blockIndex];
|
||||||
chai.assert.exists(block, 'Block at topBlocks_[' + blockIndex + ']');
|
chai.assert.exists(block, 'Block at topBlocks_[' + blockIndex + ']');
|
||||||
let varModel = block.getVarModels()[0];
|
const varModel = block.getVarModels()[0];
|
||||||
chai.assert.exists(varModel,
|
chai.assert.exists(varModel,
|
||||||
'VariableModel for block at topBlocks_[' + blockIndex + ']');
|
'VariableModel for block at topBlocks_[' + blockIndex + ']');
|
||||||
let blockVarName = varModel.name;
|
const blockVarName = varModel.name;
|
||||||
chai.assert.equal(blockVarName, name,
|
chai.assert.equal(blockVarName, name,
|
||||||
'VariableModel name for block at topBlocks_[' + blockIndex + ']');
|
'VariableModel name for block at topBlocks_[' + blockIndex + ']');
|
||||||
}
|
}
|
||||||
|
|
||||||
function createVarBlocksNoEvents(workspace, ids) {
|
function createVarBlocksNoEvents(workspace, ids) {
|
||||||
let blocks = [];
|
const blocks = [];
|
||||||
// Turn off events to avoid testing XML at the same time.
|
// Turn off events to avoid testing XML at the same time.
|
||||||
eventUtils.disable();
|
eventUtils.disable();
|
||||||
for (let i = 0, id; (id = ids[i]); i++) {
|
for (let i = 0, id; (id = ids[i]); i++) {
|
||||||
let block = new Blockly.Block(workspace, 'get_var_block');
|
const block = new Blockly.Block(workspace, 'get_var_block');
|
||||||
block.inputList[0].fieldRow[0].setValue(id);
|
block.inputList[0].fieldRow[0].setValue(id);
|
||||||
blocks.push(block);
|
blocks.push(block);
|
||||||
}
|
}
|
||||||
@@ -67,7 +67,7 @@ function testAWorkspace() {
|
|||||||
|
|
||||||
this.workspace.clear();
|
this.workspace.clear();
|
||||||
chai.assert.equal(this.workspace.topBlocks_.length, 0);
|
chai.assert.equal(this.workspace.topBlocks_.length, 0);
|
||||||
let varMapLength =
|
const varMapLength =
|
||||||
Object.keys(this.workspace.variableMap_.variableMap_).length;
|
Object.keys(this.workspace.variableMap_.variableMap_).length;
|
||||||
chai.assert.equal(varMapLength, 0);
|
chai.assert.equal(varMapLength, 0);
|
||||||
});
|
});
|
||||||
@@ -78,7 +78,7 @@ function testAWorkspace() {
|
|||||||
|
|
||||||
this.workspace.clear();
|
this.workspace.clear();
|
||||||
chai.assert.equal(this.workspace.topBlocks_.length, 0);
|
chai.assert.equal(this.workspace.topBlocks_.length, 0);
|
||||||
let varMapLength =
|
const varMapLength =
|
||||||
Object.keys(this.workspace.variableMap_.variableMap_).length;
|
Object.keys(this.workspace.variableMap_.variableMap_).length;
|
||||||
chai.assert.equal(varMapLength, 0);
|
chai.assert.equal(varMapLength, 0);
|
||||||
});
|
});
|
||||||
@@ -95,12 +95,12 @@ function testAWorkspace() {
|
|||||||
|
|
||||||
test('deleteVariableById(id2) one usage', function() {
|
test('deleteVariableById(id2) one usage', function() {
|
||||||
// Deleting variable one usage should not trigger confirm dialog.
|
// Deleting variable one usage should not trigger confirm dialog.
|
||||||
let stub =
|
const stub =
|
||||||
sinon.stub(Blockly.dialog, "confirm").callsArgWith(1, true);
|
sinon.stub(Blockly.dialog, "confirm").callsArgWith(1, true);
|
||||||
this.workspace.deleteVariableById('id2');
|
this.workspace.deleteVariableById('id2');
|
||||||
|
|
||||||
sinon.assert.notCalled(stub);
|
sinon.assert.notCalled(stub);
|
||||||
let variable = this.workspace.getVariableById('id2');
|
const variable = this.workspace.getVariableById('id2');
|
||||||
chai.assert.isNull(variable);
|
chai.assert.isNull(variable);
|
||||||
assertVariableValues(this.workspace, 'name1', 'type1', 'id1');
|
assertVariableValues(this.workspace, 'name1', 'type1', 'id1');
|
||||||
assertBlockVarModelName(this.workspace, 0, 'name1');
|
assertBlockVarModelName(this.workspace, 0, 'name1');
|
||||||
@@ -108,12 +108,12 @@ function testAWorkspace() {
|
|||||||
|
|
||||||
test('deleteVariableById(id1) multiple usages confirm', function() {
|
test('deleteVariableById(id1) multiple usages confirm', function() {
|
||||||
// Deleting variable with multiple usages triggers confirm dialog.
|
// Deleting variable with multiple usages triggers confirm dialog.
|
||||||
let stub =
|
const stub =
|
||||||
sinon.stub(Blockly.dialog, "confirm").callsArgWith(1, true);
|
sinon.stub(Blockly.dialog, "confirm").callsArgWith(1, true);
|
||||||
this.workspace.deleteVariableById('id1');
|
this.workspace.deleteVariableById('id1');
|
||||||
|
|
||||||
sinon.assert.calledOnce(stub);
|
sinon.assert.calledOnce(stub);
|
||||||
let variable = this.workspace.getVariableById('id1');
|
const variable = this.workspace.getVariableById('id1');
|
||||||
chai.assert.isNull(variable);
|
chai.assert.isNull(variable);
|
||||||
assertVariableValues(this.workspace, 'name2', 'type2', 'id2');
|
assertVariableValues(this.workspace, 'name2', 'type2', 'id2');
|
||||||
assertBlockVarModelName(this.workspace, 0, 'name2');
|
assertBlockVarModelName(this.workspace, 0, 'name2');
|
||||||
@@ -121,7 +121,7 @@ function testAWorkspace() {
|
|||||||
|
|
||||||
test('deleteVariableById(id1) multiple usages cancel', function() {
|
test('deleteVariableById(id1) multiple usages cancel', function() {
|
||||||
// Deleting variable with multiple usages triggers confirm dialog.
|
// Deleting variable with multiple usages triggers confirm dialog.
|
||||||
let stub =
|
const stub =
|
||||||
sinon.stub(Blockly.dialog, "confirm").callsArgWith(1, false);
|
sinon.stub(Blockly.dialog, "confirm").callsArgWith(1, false);
|
||||||
this.workspace.deleteVariableById('id1');
|
this.workspace.deleteVariableById('id1');
|
||||||
|
|
||||||
@@ -176,7 +176,7 @@ function testAWorkspace() {
|
|||||||
// The second variable should remain unchanged.
|
// The second variable should remain unchanged.
|
||||||
assertVariableValues(this.workspace, 'name2', 'type1', 'id2');
|
assertVariableValues(this.workspace, 'name2', 'type1', 'id2');
|
||||||
// The first variable should have been deleted.
|
// The first variable should have been deleted.
|
||||||
let variable = this.workspace.getVariableById('id1');
|
const variable = this.workspace.getVariableById('id1');
|
||||||
chai.assert.isNull(variable);
|
chai.assert.isNull(variable);
|
||||||
// There should only be one variable left.
|
// There should only be one variable left.
|
||||||
chai.assert.equal(this.workspace.getAllVariables().length, 1);
|
chai.assert.equal(this.workspace.getAllVariables().length, 1);
|
||||||
@@ -210,7 +210,7 @@ function testAWorkspace() {
|
|||||||
// The second variable should be updated.
|
// The second variable should be updated.
|
||||||
assertVariableValues(this.workspace, 'Name2', 'type1', 'id2');
|
assertVariableValues(this.workspace, 'Name2', 'type1', 'id2');
|
||||||
// The first variable should have been deleted.
|
// The first variable should have been deleted.
|
||||||
let variable = this.workspace.getVariableById('id1');
|
const variable = this.workspace.getVariableById('id1');
|
||||||
chai.assert.isNull(variable);
|
chai.assert.isNull(variable);
|
||||||
// There should only be one variable left.
|
// There should only be one variable left.
|
||||||
chai.assert.equal(this.workspace.getAllVariables().length, 1);
|
chai.assert.equal(this.workspace.getAllVariables().length, 1);
|
||||||
@@ -249,7 +249,7 @@ function testAWorkspace() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
test('Flat workspace one block after dispose', function() {
|
test('Flat workspace one block after dispose', function() {
|
||||||
let blockA = this.workspace.newBlock('');
|
const blockA = this.workspace.newBlock('');
|
||||||
this.workspace.newBlock('');
|
this.workspace.newBlock('');
|
||||||
blockA.dispose();
|
blockA.dispose();
|
||||||
chai.assert.equal(this.workspace.getTopBlocks(true).length, 1);
|
chai.assert.equal(this.workspace.getTopBlocks(true).length, 1);
|
||||||
@@ -283,7 +283,7 @@ function testAWorkspace() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
test('Flat workspace one block after dispose', function() {
|
test('Flat workspace one block after dispose', function() {
|
||||||
let blockA = this.workspace.newBlock('');
|
const blockA = this.workspace.newBlock('');
|
||||||
this.workspace.newBlock('');
|
this.workspace.newBlock('');
|
||||||
blockA.dispose();
|
blockA.dispose();
|
||||||
chai.assert.equal(this.workspace.getTopBlocks(false).length, 1);
|
chai.assert.equal(this.workspace.getTopBlocks(false).length, 1);
|
||||||
@@ -319,7 +319,7 @@ function testAWorkspace() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
test('Flat workspace one block after dispose', function() {
|
test('Flat workspace one block after dispose', function() {
|
||||||
let blockA = this.workspace.newBlock('');
|
const blockA = this.workspace.newBlock('');
|
||||||
this.workspace.newBlock('');
|
this.workspace.newBlock('');
|
||||||
blockA.dispose();
|
blockA.dispose();
|
||||||
chai.assert.equal(this.workspace.getAllBlocks(true).length, 1);
|
chai.assert.equal(this.workspace.getAllBlocks(true).length, 1);
|
||||||
@@ -486,26 +486,26 @@ function testAWorkspace() {
|
|||||||
|
|
||||||
test('Under block limit and no instance limit', function() {
|
test('Under block limit and no instance limit', function() {
|
||||||
this.workspace.options.maxBlocks = 3;
|
this.workspace.options.maxBlocks = 3;
|
||||||
let typeCountsMap = {'get_var_block': 1};
|
const typeCountsMap = {'get_var_block': 1};
|
||||||
chai.assert.isTrue(this.workspace.isCapacityAvailable(typeCountsMap));
|
chai.assert.isTrue(this.workspace.isCapacityAvailable(typeCountsMap));
|
||||||
});
|
});
|
||||||
|
|
||||||
test('At block limit and no instance limit', function() {
|
test('At block limit and no instance limit', function() {
|
||||||
this.workspace.options.maxBlocks = 2;
|
this.workspace.options.maxBlocks = 2;
|
||||||
let typeCountsMap = {'get_var_block': 1};
|
const typeCountsMap = {'get_var_block': 1};
|
||||||
chai.assert.isFalse(this.workspace.isCapacityAvailable(typeCountsMap));
|
chai.assert.isFalse(this.workspace.isCapacityAvailable(typeCountsMap));
|
||||||
});
|
});
|
||||||
|
|
||||||
test('Over block limit of 0 and no instance limit', function() {
|
test('Over block limit of 0 and no instance limit', function() {
|
||||||
this.workspace.options.maxBlocks = 0;
|
this.workspace.options.maxBlocks = 0;
|
||||||
let typeCountsMap = {'get_var_block': 1};
|
const typeCountsMap = {'get_var_block': 1};
|
||||||
chai.assert.isFalse(this.workspace.isCapacityAvailable(typeCountsMap));
|
chai.assert.isFalse(this.workspace.isCapacityAvailable(typeCountsMap));
|
||||||
});
|
});
|
||||||
|
|
||||||
test('Over block limit but under instance limit', function() {
|
test('Over block limit but under instance limit', function() {
|
||||||
this.workspace.options.maxBlocks = 1;
|
this.workspace.options.maxBlocks = 1;
|
||||||
this.workspace.options.maxInstances['get_var_block'] = 3;
|
this.workspace.options.maxInstances['get_var_block'] = 3;
|
||||||
let typeCountsMap = {'get_var_block': 1};
|
const typeCountsMap = {'get_var_block': 1};
|
||||||
chai.assert.isFalse(this.workspace.isCapacityAvailable(typeCountsMap),
|
chai.assert.isFalse(this.workspace.isCapacityAvailable(typeCountsMap),
|
||||||
'With maxBlocks limit 1 and maxInstances limit 3');
|
'With maxBlocks limit 1 and maxInstances limit 3');
|
||||||
});
|
});
|
||||||
@@ -513,7 +513,7 @@ function testAWorkspace() {
|
|||||||
test('Over block limit of 0 but under instance limit', function() {
|
test('Over block limit of 0 but under instance limit', function() {
|
||||||
this.workspace.options.maxBlocks = 0;
|
this.workspace.options.maxBlocks = 0;
|
||||||
this.workspace.options.maxInstances['get_var_block'] = 3;
|
this.workspace.options.maxInstances['get_var_block'] = 3;
|
||||||
let typeCountsMap = {'get_var_block': 1};
|
const typeCountsMap = {'get_var_block': 1};
|
||||||
chai.assert.isFalse(this.workspace.isCapacityAvailable(typeCountsMap),
|
chai.assert.isFalse(this.workspace.isCapacityAvailable(typeCountsMap),
|
||||||
'With maxBlocks limit 0 and maxInstances limit 3');
|
'With maxBlocks limit 0 and maxInstances limit 3');
|
||||||
});
|
});
|
||||||
@@ -521,7 +521,7 @@ function testAWorkspace() {
|
|||||||
test('Over block limit but at instance limit', function() {
|
test('Over block limit but at instance limit', function() {
|
||||||
this.workspace.options.maxBlocks = 1;
|
this.workspace.options.maxBlocks = 1;
|
||||||
this.workspace.options.maxInstances['get_var_block'] = 2;
|
this.workspace.options.maxInstances['get_var_block'] = 2;
|
||||||
let typeCountsMap = {'get_var_block': 1};
|
const typeCountsMap = {'get_var_block': 1};
|
||||||
chai.assert.isFalse(this.workspace.isCapacityAvailable(typeCountsMap),
|
chai.assert.isFalse(this.workspace.isCapacityAvailable(typeCountsMap),
|
||||||
'With maxBlocks limit 1 and maxInstances limit 2');
|
'With maxBlocks limit 1 and maxInstances limit 2');
|
||||||
});
|
});
|
||||||
@@ -529,7 +529,7 @@ function testAWorkspace() {
|
|||||||
test('Over block limit and over instance limit', function() {
|
test('Over block limit and over instance limit', function() {
|
||||||
this.workspace.options.maxBlocks = 1;
|
this.workspace.options.maxBlocks = 1;
|
||||||
this.workspace.options.maxInstances['get_var_block'] = 1;
|
this.workspace.options.maxInstances['get_var_block'] = 1;
|
||||||
let typeCountsMap = {'get_var_block': 1};
|
const typeCountsMap = {'get_var_block': 1};
|
||||||
chai.assert.isFalse(this.workspace.isCapacityAvailable(typeCountsMap),
|
chai.assert.isFalse(this.workspace.isCapacityAvailable(typeCountsMap),
|
||||||
'With maxBlocks limit 1 and maxInstances limit 1');
|
'With maxBlocks limit 1 and maxInstances limit 1');
|
||||||
});
|
});
|
||||||
@@ -537,7 +537,7 @@ function testAWorkspace() {
|
|||||||
test('Over block limit of 0 and over instance limit', function() {
|
test('Over block limit of 0 and over instance limit', function() {
|
||||||
this.workspace.options.maxBlocks = 0;
|
this.workspace.options.maxBlocks = 0;
|
||||||
this.workspace.options.maxInstances['get_var_block'] = 1;
|
this.workspace.options.maxInstances['get_var_block'] = 1;
|
||||||
let typeCountsMap = {'get_var_block': 1};
|
const typeCountsMap = {'get_var_block': 1};
|
||||||
chai.assert.isFalse(this.workspace.isCapacityAvailable(typeCountsMap),
|
chai.assert.isFalse(this.workspace.isCapacityAvailable(typeCountsMap),
|
||||||
'With maxBlocks limit 0 and maxInstances limit 1');
|
'With maxBlocks limit 0 and maxInstances limit 1');
|
||||||
});
|
});
|
||||||
@@ -545,7 +545,7 @@ function testAWorkspace() {
|
|||||||
test('Over block limit and over instance limit of 0', function() {
|
test('Over block limit and over instance limit of 0', function() {
|
||||||
this.workspace.options.maxBlocks = 1;
|
this.workspace.options.maxBlocks = 1;
|
||||||
this.workspace.options.maxInstances['get_var_block'] = 0;
|
this.workspace.options.maxInstances['get_var_block'] = 0;
|
||||||
let typeCountsMap = {'get_var_block': 1};
|
const typeCountsMap = {'get_var_block': 1};
|
||||||
chai.assert.isFalse(this.workspace.isCapacityAvailable(typeCountsMap),
|
chai.assert.isFalse(this.workspace.isCapacityAvailable(typeCountsMap),
|
||||||
'With maxBlocks limit 1 and maxInstances limit 0');
|
'With maxBlocks limit 1 and maxInstances limit 0');
|
||||||
});
|
});
|
||||||
@@ -553,7 +553,7 @@ function testAWorkspace() {
|
|||||||
test('Over block limit of 0 and over instance limit of 0', function() {
|
test('Over block limit of 0 and over instance limit of 0', function() {
|
||||||
this.workspace.options.maxBlocks = 0;
|
this.workspace.options.maxBlocks = 0;
|
||||||
this.workspace.options.maxInstances['get_var_block'] = 0;
|
this.workspace.options.maxInstances['get_var_block'] = 0;
|
||||||
let typeCountsMap = {'get_var_block': 1};
|
const typeCountsMap = {'get_var_block': 1};
|
||||||
chai.assert.isFalse(this.workspace.isCapacityAvailable(typeCountsMap));
|
chai.assert.isFalse(this.workspace.isCapacityAvailable(typeCountsMap));
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@@ -640,8 +640,8 @@ function testAWorkspace() {
|
|||||||
* @param {!Element} expected the expected node.
|
* @param {!Element} expected the expected node.
|
||||||
*/
|
*/
|
||||||
function assertNodesEqual(actual, expected) {
|
function assertNodesEqual(actual, expected) {
|
||||||
let actualString = '\n' + Blockly.Xml.domToPrettyText(actual) + '\n';
|
const actualString = '\n' + Blockly.Xml.domToPrettyText(actual) + '\n';
|
||||||
let expectedString = '\n' + Blockly.Xml.domToPrettyText(expected) + '\n';
|
const expectedString = '\n' + Blockly.Xml.domToPrettyText(expected) + '\n';
|
||||||
|
|
||||||
chai.assert.equal(actual.tagName, expected.tagName);
|
chai.assert.equal(actual.tagName, expected.tagName);
|
||||||
for (let i = 0, attr; (attr = expected.attributes[i]); i++) {
|
for (let i = 0, attr; (attr = expected.attributes[i]); i++) {
|
||||||
@@ -698,11 +698,11 @@ function testAWorkspace() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
function testUndoDelete(xmlText) {
|
function testUndoDelete(xmlText) {
|
||||||
let xml = Blockly.Xml.textToDom(xmlText);
|
const xml = Blockly.Xml.textToDom(xmlText);
|
||||||
Blockly.Xml.domToBlock(xml, this.workspace);
|
Blockly.Xml.domToBlock(xml, this.workspace);
|
||||||
this.workspace.getTopBlocks()[0].dispose(false);
|
this.workspace.getTopBlocks()[0].dispose(false);
|
||||||
this.workspace.undo();
|
this.workspace.undo();
|
||||||
let newXml = Blockly.Xml.workspaceToDom(this.workspace);
|
const newXml = Blockly.Xml.workspaceToDom(this.workspace);
|
||||||
assertNodesEqual(newXml.firstChild, xml);
|
assertNodesEqual(newXml.firstChild, xml);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -821,20 +821,20 @@ function testAWorkspace() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
function testUndoConnect(xmlText, parentId, childId, func) {
|
function testUndoConnect(xmlText, parentId, childId, func) {
|
||||||
let xml = Blockly.Xml.textToDom(xmlText);
|
const xml = Blockly.Xml.textToDom(xmlText);
|
||||||
Blockly.Xml.domToWorkspace(xml, this.workspace);
|
Blockly.Xml.domToWorkspace(xml, this.workspace);
|
||||||
|
|
||||||
let parent = this.workspace.getBlockById(parentId);
|
const parent = this.workspace.getBlockById(parentId);
|
||||||
let child = this.workspace.getBlockById(childId);
|
const child = this.workspace.getBlockById(childId);
|
||||||
func.call(this, parent, child);
|
func.call(this, parent, child);
|
||||||
this.workspace.undo();
|
this.workspace.undo();
|
||||||
|
|
||||||
let newXml = Blockly.Xml.workspaceToDom(this.workspace);
|
const newXml = Blockly.Xml.workspaceToDom(this.workspace);
|
||||||
assertNodesEqual(newXml, xml);
|
assertNodesEqual(newXml, xml);
|
||||||
}
|
}
|
||||||
|
|
||||||
test('Stack', function() {
|
test('Stack', function() {
|
||||||
let xml =
|
const xml =
|
||||||
'<xml>' +
|
'<xml>' +
|
||||||
' <block type="stack_block" id="1"></block>' +
|
' <block type="stack_block" id="1"></block>' +
|
||||||
' <block type="stack_block" id="2"></block>' +
|
' <block type="stack_block" id="2"></block>' +
|
||||||
@@ -846,7 +846,7 @@ function testAWorkspace() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
test('Row', function() {
|
test('Row', function() {
|
||||||
let xml =
|
const xml =
|
||||||
'<xml>' +
|
'<xml>' +
|
||||||
' <block type="row_block" id="1"></block>' +
|
' <block type="row_block" id="1"></block>' +
|
||||||
' <block type="row_block" id="2"></block>' +
|
' <block type="row_block" id="2"></block>' +
|
||||||
@@ -858,7 +858,7 @@ function testAWorkspace() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
test('Statement', function() {
|
test('Statement', function() {
|
||||||
let xml =
|
const xml =
|
||||||
'<xml>' +
|
'<xml>' +
|
||||||
' <block type="statement_block" id="1"></block>' +
|
' <block type="statement_block" id="1"></block>' +
|
||||||
' <block type="stack_block" id="2"></block>' +
|
' <block type="stack_block" id="2"></block>' +
|
||||||
@@ -871,7 +871,7 @@ function testAWorkspace() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
test('Stack w/ child', function() {
|
test('Stack w/ child', function() {
|
||||||
let xml =
|
const xml =
|
||||||
'<xml>' +
|
'<xml>' +
|
||||||
' <block type="stack_block" id="1">' +
|
' <block type="stack_block" id="1">' +
|
||||||
' <next>' +
|
' <next>' +
|
||||||
@@ -887,7 +887,7 @@ function testAWorkspace() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
test('Row w/ child', function() {
|
test('Row w/ child', function() {
|
||||||
let xml =
|
const xml =
|
||||||
'<xml>' +
|
'<xml>' +
|
||||||
' <block type="row_block" id="1">' +
|
' <block type="row_block" id="1">' +
|
||||||
' <value name="INPUT">' +
|
' <value name="INPUT">' +
|
||||||
@@ -903,7 +903,7 @@ function testAWorkspace() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
test('Statement w/ child', function() {
|
test('Statement w/ child', function() {
|
||||||
let xml =
|
const xml =
|
||||||
'<xml>' +
|
'<xml>' +
|
||||||
' <block type="statement_block" id="1">' +
|
' <block type="statement_block" id="1">' +
|
||||||
' <statement name="STATEMENT">' +
|
' <statement name="STATEMENT">' +
|
||||||
@@ -920,7 +920,7 @@ function testAWorkspace() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
test('Stack w/ shadow', function() {
|
test('Stack w/ shadow', function() {
|
||||||
let xml =
|
const xml =
|
||||||
'<xml>' +
|
'<xml>' +
|
||||||
' <block type="stack_block" id="1">' +
|
' <block type="stack_block" id="1">' +
|
||||||
' <next>' +
|
' <next>' +
|
||||||
@@ -936,7 +936,7 @@ function testAWorkspace() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
test('Row w/ shadow', function() {
|
test('Row w/ shadow', function() {
|
||||||
let xml =
|
const xml =
|
||||||
'<xml>' +
|
'<xml>' +
|
||||||
' <block type="row_block" id="1">' +
|
' <block type="row_block" id="1">' +
|
||||||
' <value name="INPUT">' +
|
' <value name="INPUT">' +
|
||||||
@@ -952,7 +952,7 @@ function testAWorkspace() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
test('Statement w/ shadow', function() {
|
test('Statement w/ shadow', function() {
|
||||||
let xml =
|
const xml =
|
||||||
'<xml>' +
|
'<xml>' +
|
||||||
' <block type="statement_block" id="1">' +
|
' <block type="statement_block" id="1">' +
|
||||||
' <statement name="STATEMENT">' +
|
' <statement name="STATEMENT">' +
|
||||||
@@ -1011,10 +1011,10 @@ function testAWorkspace() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
function testUndoDisconnect(xmlText, childId) {
|
function testUndoDisconnect(xmlText, childId) {
|
||||||
let xml = Blockly.Xml.textToDom(xmlText);
|
const xml = Blockly.Xml.textToDom(xmlText);
|
||||||
Blockly.Xml.domToWorkspace(xml, this.workspace);
|
Blockly.Xml.domToWorkspace(xml, this.workspace);
|
||||||
|
|
||||||
let child = this.workspace.getBlockById(childId);
|
const child = this.workspace.getBlockById(childId);
|
||||||
if (child.outputConnection) {
|
if (child.outputConnection) {
|
||||||
child.outputConnection.disconnect();
|
child.outputConnection.disconnect();
|
||||||
} else {
|
} else {
|
||||||
@@ -1022,12 +1022,12 @@ function testAWorkspace() {
|
|||||||
}
|
}
|
||||||
this.workspace.undo();
|
this.workspace.undo();
|
||||||
|
|
||||||
let newXml = Blockly.Xml.workspaceToDom(this.workspace);
|
const newXml = Blockly.Xml.workspaceToDom(this.workspace);
|
||||||
assertNodesEqual(newXml, xml);
|
assertNodesEqual(newXml, xml);
|
||||||
}
|
}
|
||||||
|
|
||||||
test('Stack', function() {
|
test('Stack', function() {
|
||||||
let xml =
|
const xml =
|
||||||
'<xml>' +
|
'<xml>' +
|
||||||
' <block type="stack_block" id="1">' +
|
' <block type="stack_block" id="1">' +
|
||||||
' <next>' +
|
' <next>' +
|
||||||
@@ -1039,7 +1039,7 @@ function testAWorkspace() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
test('Row', function() {
|
test('Row', function() {
|
||||||
let xml =
|
const xml =
|
||||||
'<xml>' +
|
'<xml>' +
|
||||||
' <block type="row_block" id="1">' +
|
' <block type="row_block" id="1">' +
|
||||||
' <value name="INPUT">' +
|
' <value name="INPUT">' +
|
||||||
@@ -1051,7 +1051,7 @@ function testAWorkspace() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
test('Statement', function() {
|
test('Statement', function() {
|
||||||
let xml =
|
const xml =
|
||||||
'<xml>' +
|
'<xml>' +
|
||||||
' <block type="statement_block" id="1">' +
|
' <block type="statement_block" id="1">' +
|
||||||
' <statement name="STATEMENT">' +
|
' <statement name="STATEMENT">' +
|
||||||
@@ -1063,7 +1063,7 @@ function testAWorkspace() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
test('Stack w/ child', function() {
|
test('Stack w/ child', function() {
|
||||||
let xml =
|
const xml =
|
||||||
'<xml>' +
|
'<xml>' +
|
||||||
' <block type="stack_block" id="1">' +
|
' <block type="stack_block" id="1">' +
|
||||||
' <next>' +
|
' <next>' +
|
||||||
@@ -1079,7 +1079,7 @@ function testAWorkspace() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
test('Row w/ child', function() {
|
test('Row w/ child', function() {
|
||||||
let xml =
|
const xml =
|
||||||
'<xml>' +
|
'<xml>' +
|
||||||
' <block type="row_block" id="1">' +
|
' <block type="row_block" id="1">' +
|
||||||
' <value name="INPUT">' +
|
' <value name="INPUT">' +
|
||||||
@@ -1095,7 +1095,7 @@ function testAWorkspace() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
test('Statement w/ child', function() {
|
test('Statement w/ child', function() {
|
||||||
let xml =
|
const xml =
|
||||||
'<xml>' +
|
'<xml>' +
|
||||||
' <block type="statement_block" id="1">' +
|
' <block type="statement_block" id="1">' +
|
||||||
' <statement name="STATEMENT">' +
|
' <statement name="STATEMENT">' +
|
||||||
@@ -1113,7 +1113,7 @@ function testAWorkspace() {
|
|||||||
test('Stack w/ shadow', function() {
|
test('Stack w/ shadow', function() {
|
||||||
// TODO: For some reason on next connections shadows are
|
// TODO: For some reason on next connections shadows are
|
||||||
// serialized second.
|
// serialized second.
|
||||||
let xml =
|
const xml =
|
||||||
'<xml>' +
|
'<xml>' +
|
||||||
' <block type="stack_block" id="1">' +
|
' <block type="stack_block" id="1">' +
|
||||||
' <next>' +
|
' <next>' +
|
||||||
@@ -1129,7 +1129,7 @@ function testAWorkspace() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
test('Row w/ shadow', function() {
|
test('Row w/ shadow', function() {
|
||||||
let xml =
|
const xml =
|
||||||
'<xml>' +
|
'<xml>' +
|
||||||
' <block type="row_block" id="1">' +
|
' <block type="row_block" id="1">' +
|
||||||
' <value name="INPUT">' +
|
' <value name="INPUT">' +
|
||||||
@@ -1145,7 +1145,7 @@ function testAWorkspace() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
test('Statement w/ shadow', function() {
|
test('Statement w/ shadow', function() {
|
||||||
let xml =
|
const xml =
|
||||||
'<xml>' +
|
'<xml>' +
|
||||||
' <block type="statement_block" id="1">' +
|
' <block type="statement_block" id="1">' +
|
||||||
' <statement name="STATEMENT">' +
|
' <statement name="STATEMENT">' +
|
||||||
@@ -1296,13 +1296,13 @@ function testAWorkspace() {
|
|||||||
test('Delete same variable twice no usages', function() {
|
test('Delete same variable twice no usages', function() {
|
||||||
this.workspace.createVariable('name1', 'type1', 'id1');
|
this.workspace.createVariable('name1', 'type1', 'id1');
|
||||||
this.workspace.deleteVariableById('id1');
|
this.workspace.deleteVariableById('id1');
|
||||||
let workspace = this.workspace;
|
const workspace = this.workspace;
|
||||||
assertWarnings(() => {
|
assertWarnings(() => {
|
||||||
workspace.deleteVariableById('id1');
|
workspace.deleteVariableById('id1');
|
||||||
}, /Can't delete/);
|
}, /Can't delete/);
|
||||||
|
|
||||||
// Check the undoStack only recorded one delete event.
|
// Check the undoStack only recorded one delete event.
|
||||||
let undoStack = this.workspace.undoStack_;
|
const undoStack = this.workspace.undoStack_;
|
||||||
chai.assert.equal(undoStack[undoStack.length - 1].type, 'var_delete');
|
chai.assert.equal(undoStack[undoStack.length - 1].type, 'var_delete');
|
||||||
chai.assert.notEqual(undoStack[undoStack.length - 2].type, 'var_delete');
|
chai.assert.notEqual(undoStack[undoStack.length - 2].type, 'var_delete');
|
||||||
|
|
||||||
@@ -1323,13 +1323,13 @@ function testAWorkspace() {
|
|||||||
this.workspace.createVariable('name1', 'type1', 'id1');
|
this.workspace.createVariable('name1', 'type1', 'id1');
|
||||||
createVarBlocksNoEvents(this.workspace, ['id1']);
|
createVarBlocksNoEvents(this.workspace, ['id1']);
|
||||||
this.workspace.deleteVariableById('id1');
|
this.workspace.deleteVariableById('id1');
|
||||||
let workspace = this.workspace;
|
const workspace = this.workspace;
|
||||||
assertWarnings(() => {
|
assertWarnings(() => {
|
||||||
workspace.deleteVariableById('id1');
|
workspace.deleteVariableById('id1');
|
||||||
}, /Can't delete/);
|
}, /Can't delete/);
|
||||||
|
|
||||||
// Check the undoStack only recorded one delete event.
|
// Check the undoStack only recorded one delete event.
|
||||||
let undoStack = this.workspace.undoStack_;
|
const undoStack = this.workspace.undoStack_;
|
||||||
chai.assert.equal(undoStack[undoStack.length - 1].type, 'var_delete');
|
chai.assert.equal(undoStack[undoStack.length - 1].type, 'var_delete');
|
||||||
chai.assert.equal(undoStack[undoStack.length - 2].type, 'delete');
|
chai.assert.equal(undoStack[undoStack.length - 2].type, 'delete');
|
||||||
chai.assert.notEqual(undoStack[undoStack.length - 3].type, 'var_delete');
|
chai.assert.notEqual(undoStack[undoStack.length - 3].type, 'var_delete');
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ const {testAWorkspace} = goog.require('Blockly.test.workspaceHelpers');
|
|||||||
suite('WorkspaceSvg', function() {
|
suite('WorkspaceSvg', function() {
|
||||||
setup(function() {
|
setup(function() {
|
||||||
sharedTestSetup.call(this);
|
sharedTestSetup.call(this);
|
||||||
let toolbox = document.getElementById('toolbox-categories');
|
const toolbox = document.getElementById('toolbox-categories');
|
||||||
this.workspace = Blockly.inject('blocklyDiv', {toolbox: toolbox});
|
this.workspace = Blockly.inject('blocklyDiv', {toolbox: toolbox});
|
||||||
Blockly.defineBlocksWithJsonArray([{
|
Blockly.defineBlocksWithJsonArray([{
|
||||||
'type': 'simple_test_block',
|
'type': 'simple_test_block',
|
||||||
@@ -37,12 +37,12 @@ suite('WorkspaceSvg', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
test('dispose of WorkspaceSvg without dom throws no error', function() {
|
test('dispose of WorkspaceSvg without dom throws no error', function() {
|
||||||
let ws = new Blockly.WorkspaceSvg(new Blockly.Options({}));
|
const ws = new Blockly.WorkspaceSvg(new Blockly.Options({}));
|
||||||
ws.dispose();
|
ws.dispose();
|
||||||
});
|
});
|
||||||
|
|
||||||
test('appendDomToWorkspace alignment', function() {
|
test('appendDomToWorkspace alignment', function() {
|
||||||
let dom = Blockly.Xml.textToDom(
|
const dom = Blockly.Xml.textToDom(
|
||||||
'<xml xmlns="https://developers.google.com/blockly/xml">' +
|
'<xml xmlns="https://developers.google.com/blockly/xml">' +
|
||||||
' <block type="math_random_float" inline="true" x="21" y="23">' +
|
' <block type="math_random_float" inline="true" x="21" y="23">' +
|
||||||
' </block>' +
|
' </block>' +
|
||||||
@@ -53,7 +53,7 @@ suite('WorkspaceSvg', function() {
|
|||||||
Blockly.Xml.appendDomToWorkspace(dom, this.workspace);
|
Blockly.Xml.appendDomToWorkspace(dom, this.workspace);
|
||||||
chai.assert.equal(this.workspace.getAllBlocks(false).length, 2,
|
chai.assert.equal(this.workspace.getAllBlocks(false).length, 2,
|
||||||
'Block count');
|
'Block count');
|
||||||
let blocks = this.workspace.getAllBlocks(false);
|
const blocks = this.workspace.getAllBlocks(false);
|
||||||
chai.assert.equal(blocks[0].getRelativeToSurfaceXY().x, 21,
|
chai.assert.equal(blocks[0].getRelativeToSurfaceXY().x, 21,
|
||||||
'Block 1 position x');
|
'Block 1 position x');
|
||||||
chai.assert.equal(blocks[0].getRelativeToSurfaceXY().y, 23,
|
chai.assert.equal(blocks[0].getRelativeToSurfaceXY().y, 23,
|
||||||
@@ -67,7 +67,7 @@ suite('WorkspaceSvg', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
test('Replacing shadow disposes svg', function() {
|
test('Replacing shadow disposes svg', function() {
|
||||||
let dom = Blockly.Xml.textToDom(
|
const dom = Blockly.Xml.textToDom(
|
||||||
'<xml xmlns="https://developers.google.com/blockly/xml">' +
|
'<xml xmlns="https://developers.google.com/blockly/xml">' +
|
||||||
'<block type="test_val_in">' +
|
'<block type="test_val_in">' +
|
||||||
'<value name="NAME">' +
|
'<value name="NAME">' +
|
||||||
@@ -77,15 +77,15 @@ suite('WorkspaceSvg', function() {
|
|||||||
'</xml>');
|
'</xml>');
|
||||||
|
|
||||||
Blockly.Xml.appendDomToWorkspace(dom, this.workspace);
|
Blockly.Xml.appendDomToWorkspace(dom, this.workspace);
|
||||||
let blocks = this.workspace.getAllBlocks(false);
|
const blocks = this.workspace.getAllBlocks(false);
|
||||||
chai.assert.equal(blocks.length, 2, 'Block count');
|
chai.assert.equal(blocks.length, 2, 'Block count');
|
||||||
let shadowBlock = blocks[1];
|
const shadowBlock = blocks[1];
|
||||||
chai.assert.exists(shadowBlock.getSvgRoot());
|
chai.assert.exists(shadowBlock.getSvgRoot());
|
||||||
|
|
||||||
let block = this.workspace.newBlock('simple_test_block');
|
const block = this.workspace.newBlock('simple_test_block');
|
||||||
block.initSvg();
|
block.initSvg();
|
||||||
|
|
||||||
let inputConnection =
|
const inputConnection =
|
||||||
this.workspace.getTopBlocks()[0].getInput('NAME').connection;
|
this.workspace.getTopBlocks()[0].getInput('NAME').connection;
|
||||||
inputConnection.connect(block.outputConnection);
|
inputConnection.connect(block.outputConnection);
|
||||||
chai.assert.exists(block.getSvgRoot());
|
chai.assert.exists(block.getSvgRoot());
|
||||||
@@ -152,7 +152,7 @@ suite('WorkspaceSvg', function() {
|
|||||||
this.workspace.variableMap_ = this.targetWorkspace.getVariableMap();
|
this.workspace.variableMap_ = this.targetWorkspace.getVariableMap();
|
||||||
|
|
||||||
Blockly.Events.disable();
|
Blockly.Events.disable();
|
||||||
let block = new Blockly.Block(this.workspace, 'get_var_block');
|
const block = new Blockly.Block(this.workspace, 'get_var_block');
|
||||||
block.inputList[0].fieldRow[0].setValue('1');
|
block.inputList[0].fieldRow[0].setValue('1');
|
||||||
Blockly.Events.enable();
|
Blockly.Events.enable();
|
||||||
|
|
||||||
@@ -176,8 +176,8 @@ suite('WorkspaceSvg', function() {
|
|||||||
}
|
}
|
||||||
function assertViewportEventFired(eventsFireStub, changeListenerSpy,
|
function assertViewportEventFired(eventsFireStub, changeListenerSpy,
|
||||||
workspace, expectedEventCount = 1) {
|
workspace, expectedEventCount = 1) {
|
||||||
let metrics = workspace.getMetrics();
|
const metrics = workspace.getMetrics();
|
||||||
let expectedProperties = {
|
const expectedProperties = {
|
||||||
scale: workspace.scale,
|
scale: workspace.scale,
|
||||||
oldScale: 1,
|
oldScale: 1,
|
||||||
viewTop: metrics.viewTop,
|
viewTop: metrics.viewTop,
|
||||||
@@ -233,7 +233,7 @@ suite('WorkspaceSvg', function() {
|
|||||||
this.clock);
|
this.clock);
|
||||||
});
|
});
|
||||||
test('zoomToFit', function() {
|
test('zoomToFit', function() {
|
||||||
let block = this.workspace.newBlock('stack_block');
|
const block = this.workspace.newBlock('stack_block');
|
||||||
block.initSvg();
|
block.initSvg();
|
||||||
block.render();
|
block.render();
|
||||||
runViewportEventTest(() => this.workspace.zoomToFit(),
|
runViewportEventTest(() => this.workspace.zoomToFit(),
|
||||||
@@ -243,7 +243,7 @@ suite('WorkspaceSvg', function() {
|
|||||||
});
|
});
|
||||||
suite('scroll', function() {
|
suite('scroll', function() {
|
||||||
test('centerOnBlock', function() {
|
test('centerOnBlock', function() {
|
||||||
let block = this.workspace.newBlock('stack_block');
|
const block = this.workspace.newBlock('stack_block');
|
||||||
block.initSvg();
|
block.initSvg();
|
||||||
block.render();
|
block.render();
|
||||||
runViewportEventTest(() => this.workspace.zoomToFit(block.id),
|
runViewportEventTest(() => this.workspace.zoomToFit(block.id),
|
||||||
@@ -263,7 +263,7 @@ suite('WorkspaceSvg', function() {
|
|||||||
});
|
});
|
||||||
suite('Blocks triggering viewport changes', function() {
|
suite('Blocks triggering viewport changes', function() {
|
||||||
test('block move that triggers scroll', function() {
|
test('block move that triggers scroll', function() {
|
||||||
let block = this.workspace.newBlock('stack_block');
|
const block = this.workspace.newBlock('stack_block');
|
||||||
block.initSvg();
|
block.initSvg();
|
||||||
block.render();
|
block.render();
|
||||||
this.clock.runAll();
|
this.clock.runAll();
|
||||||
@@ -285,7 +285,7 @@ suite('WorkspaceSvg', function() {
|
|||||||
'<block type="controls_if" x="288" y="238"></block>' +
|
'<block type="controls_if" x="288" y="238"></block>' +
|
||||||
'</xml>'),
|
'</xml>'),
|
||||||
this.workspace);
|
this.workspace);
|
||||||
let xmlDom = Blockly.Xml.textToDom(
|
const xmlDom = Blockly.Xml.textToDom(
|
||||||
'<block type="controls_if" x="188" y="163"></block>');
|
'<block type="controls_if" x="188" y="163"></block>');
|
||||||
this.clock.runAll();
|
this.clock.runAll();
|
||||||
resetEventHistory(this.eventsFireStub, this.changeListenerSpy);
|
resetEventHistory(this.eventsFireStub, this.changeListenerSpy);
|
||||||
@@ -309,7 +309,7 @@ suite('WorkspaceSvg', function() {
|
|||||||
'<block type="controls_if" x="75" y="75"></block>' +
|
'<block type="controls_if" x="75" y="75"></block>' +
|
||||||
'</xml>'),
|
'</xml>'),
|
||||||
this.workspace);
|
this.workspace);
|
||||||
let xmlDom = Blockly.Xml.textToDom(
|
const xmlDom = Blockly.Xml.textToDom(
|
||||||
'<block type="controls_if" x="0" y="0"></block>');
|
'<block type="controls_if" x="0" y="0"></block>');
|
||||||
this.clock.runAll();
|
this.clock.runAll();
|
||||||
resetEventHistory(this.eventsFireStub, this.changeListenerSpy);
|
resetEventHistory(this.eventsFireStub, this.changeListenerSpy);
|
||||||
@@ -323,7 +323,7 @@ suite('WorkspaceSvg', function() {
|
|||||||
});
|
});
|
||||||
test.skip('domToWorkspace multiple blocks triggers one viewport event', function() {
|
test.skip('domToWorkspace multiple blocks triggers one viewport event', function() {
|
||||||
// TODO: Un-skip after adding filtering for consecutive viewport events.
|
// TODO: Un-skip after adding filtering for consecutive viewport events.
|
||||||
let addingMultipleBlocks = () => {
|
const addingMultipleBlocks = () => {
|
||||||
Blockly.Xml.domToWorkspace(
|
Blockly.Xml.domToWorkspace(
|
||||||
Blockly.Xml.textToDom(
|
Blockly.Xml.textToDom(
|
||||||
'<xml xmlns="https://developers.google.com/blockly/xml">' +
|
'<xml xmlns="https://developers.google.com/blockly/xml">' +
|
||||||
|
|||||||
@@ -10,24 +10,24 @@ const {addBlockTypeToCleanup, assertVariableValues, createGenUidStubWithReturns,
|
|||||||
|
|
||||||
|
|
||||||
suite('XML', function() {
|
suite('XML', function() {
|
||||||
let assertSimpleFieldDom = function(fieldDom, name, text) {
|
const assertSimpleFieldDom = function(fieldDom, name, text) {
|
||||||
chai.assert.equal(text, fieldDom.textContent);
|
chai.assert.equal(text, fieldDom.textContent);
|
||||||
chai.assert.equal(name, fieldDom.getAttribute('name'));
|
chai.assert.equal(name, fieldDom.getAttribute('name'));
|
||||||
};
|
};
|
||||||
let assertNonSerializingFieldDom = function(fieldDom) {
|
const assertNonSerializingFieldDom = function(fieldDom) {
|
||||||
chai.assert.isUndefined(fieldDom.childNodes[0]);
|
chai.assert.isUndefined(fieldDom.childNodes[0]);
|
||||||
};
|
};
|
||||||
let assertNonVariableField = function(fieldDom, name, text) {
|
const assertNonVariableField = function(fieldDom, name, text) {
|
||||||
assertSimpleFieldDom(fieldDom, name, text);
|
assertSimpleFieldDom(fieldDom, name, text);
|
||||||
chai.assert.isNull(fieldDom.getAttribute('id'), 'id');
|
chai.assert.isNull(fieldDom.getAttribute('id'), 'id');
|
||||||
chai.assert.isNull(fieldDom.getAttribute('variabletype'), 'variabletype');
|
chai.assert.isNull(fieldDom.getAttribute('variabletype'), 'variabletype');
|
||||||
};
|
};
|
||||||
let assertVariableDomField = function(fieldDom, name, type, id, text) {
|
const assertVariableDomField = function(fieldDom, name, type, id, text) {
|
||||||
assertSimpleFieldDom(fieldDom, name, text);
|
assertSimpleFieldDom(fieldDom, name, text);
|
||||||
chai.assert.equal(fieldDom.getAttribute('variabletype'), type);
|
chai.assert.equal(fieldDom.getAttribute('variabletype'), type);
|
||||||
chai.assert.equal(fieldDom.getAttribute('id'), id);
|
chai.assert.equal(fieldDom.getAttribute('id'), id);
|
||||||
};
|
};
|
||||||
let assertVariableDom = function(fieldDom, type, id, text) {
|
const assertVariableDom = function(fieldDom, type, id, text) {
|
||||||
chai.assert.equal(fieldDom.getAttribute('type'), type);
|
chai.assert.equal(fieldDom.getAttribute('type'), type);
|
||||||
chai.assert.equal(fieldDom.getAttribute('id'), id);
|
chai.assert.equal(fieldDom.getAttribute('id'), id);
|
||||||
chai.assert.equal(fieldDom.textContent, text);
|
chai.assert.equal(fieldDom.textContent, text);
|
||||||
@@ -74,7 +74,7 @@ suite('XML', function() {
|
|||||||
});
|
});
|
||||||
suite('textToDom', function() {
|
suite('textToDom', function() {
|
||||||
test('Basic', function() {
|
test('Basic', function() {
|
||||||
let dom = Blockly.Xml.textToDom(this.complexXmlText);
|
const dom = Blockly.Xml.textToDom(this.complexXmlText);
|
||||||
chai.assert.equal(dom.nodeName, 'xml', 'XML tag');
|
chai.assert.equal(dom.nodeName, 'xml', 'XML tag');
|
||||||
chai.assert.equal(dom.getElementsByTagName('block').length, 6, 'Block tags');
|
chai.assert.equal(dom.getElementsByTagName('block').length, 6, 'Block tags');
|
||||||
});
|
});
|
||||||
@@ -99,9 +99,9 @@ suite('XML', function() {
|
|||||||
}
|
}
|
||||||
],
|
],
|
||||||
}]);
|
}]);
|
||||||
let block = new Blockly.Block(this.workspace,
|
const block = new Blockly.Block(this.workspace,
|
||||||
'field_angle_test_block');
|
'field_angle_test_block');
|
||||||
let resultFieldDom = Blockly.Xml.blockToDom(block).childNodes[0];
|
const resultFieldDom = Blockly.Xml.blockToDom(block).childNodes[0];
|
||||||
assertNonVariableField(resultFieldDom, 'ANGLE', '90');
|
assertNonVariableField(resultFieldDom, 'ANGLE', '90');
|
||||||
});
|
});
|
||||||
test('Checkbox', function() {
|
test('Checkbox', function() {
|
||||||
@@ -116,9 +116,9 @@ suite('XML', function() {
|
|||||||
}
|
}
|
||||||
],
|
],
|
||||||
}]);
|
}]);
|
||||||
let block = new Blockly.Block(this.workspace,
|
const block = new Blockly.Block(this.workspace,
|
||||||
'field_checkbox_test_block');
|
'field_checkbox_test_block');
|
||||||
let resultFieldDom = Blockly.Xml.blockToDom(block).childNodes[0];
|
const resultFieldDom = Blockly.Xml.blockToDom(block).childNodes[0];
|
||||||
assertNonVariableField(resultFieldDom, 'CHECKBOX', 'TRUE');
|
assertNonVariableField(resultFieldDom, 'CHECKBOX', 'TRUE');
|
||||||
});
|
});
|
||||||
test('Colour', function() {
|
test('Colour', function() {
|
||||||
@@ -133,9 +133,9 @@ suite('XML', function() {
|
|||||||
}
|
}
|
||||||
],
|
],
|
||||||
}]);
|
}]);
|
||||||
let block = new Blockly.Block(this.workspace,
|
const block = new Blockly.Block(this.workspace,
|
||||||
'field_colour_test_block');
|
'field_colour_test_block');
|
||||||
let resultFieldDom = Blockly.Xml.blockToDom(block).childNodes[0];
|
const resultFieldDom = Blockly.Xml.blockToDom(block).childNodes[0];
|
||||||
assertNonVariableField(resultFieldDom, 'COLOUR', '#000099');
|
assertNonVariableField(resultFieldDom, 'COLOUR', '#000099');
|
||||||
});
|
});
|
||||||
test('Dropdown', function() {
|
test('Dropdown', function() {
|
||||||
@@ -163,9 +163,9 @@ suite('XML', function() {
|
|||||||
}
|
}
|
||||||
],
|
],
|
||||||
}]);
|
}]);
|
||||||
let block = new Blockly.Block(this.workspace,
|
const block = new Blockly.Block(this.workspace,
|
||||||
'field_dropdown_test_block');
|
'field_dropdown_test_block');
|
||||||
let resultFieldDom = Blockly.Xml.blockToDom(block).childNodes[0];
|
const resultFieldDom = Blockly.Xml.blockToDom(block).childNodes[0];
|
||||||
assertNonVariableField(resultFieldDom, 'DROPDOWN', 'A');
|
assertNonVariableField(resultFieldDom, 'DROPDOWN', 'A');
|
||||||
});
|
});
|
||||||
test('Image', function() {
|
test('Image', function() {
|
||||||
@@ -183,9 +183,9 @@ suite('XML', function() {
|
|||||||
}
|
}
|
||||||
],
|
],
|
||||||
}]);
|
}]);
|
||||||
let block = new Blockly.Block(this.workspace,
|
const block = new Blockly.Block(this.workspace,
|
||||||
'field_image_test_block');
|
'field_image_test_block');
|
||||||
let resultFieldDom = Blockly.Xml.blockToDom(block);
|
const resultFieldDom = Blockly.Xml.blockToDom(block);
|
||||||
assertNonSerializingFieldDom(resultFieldDom);
|
assertNonSerializingFieldDom(resultFieldDom);
|
||||||
});
|
});
|
||||||
test('Label', function() {
|
test('Label', function() {
|
||||||
@@ -200,9 +200,9 @@ suite('XML', function() {
|
|||||||
}
|
}
|
||||||
],
|
],
|
||||||
}]);
|
}]);
|
||||||
let block = new Blockly.Block(this.workspace,
|
const block = new Blockly.Block(this.workspace,
|
||||||
'field_label_test_block');
|
'field_label_test_block');
|
||||||
let resultFieldDom = Blockly.Xml.blockToDom(block);
|
const resultFieldDom = Blockly.Xml.blockToDom(block);
|
||||||
assertNonSerializingFieldDom(resultFieldDom);
|
assertNonSerializingFieldDom(resultFieldDom);
|
||||||
});
|
});
|
||||||
test('Label Serializable', function() {
|
test('Label Serializable', function() {
|
||||||
@@ -217,9 +217,9 @@ suite('XML', function() {
|
|||||||
}
|
}
|
||||||
],
|
],
|
||||||
}]);
|
}]);
|
||||||
let block = new Blockly.Block(this.workspace,
|
const block = new Blockly.Block(this.workspace,
|
||||||
'field_label_serializable_test_block');
|
'field_label_serializable_test_block');
|
||||||
let resultFieldDom = Blockly.Xml.blockToDom(block).childNodes[0];
|
const resultFieldDom = Blockly.Xml.blockToDom(block).childNodes[0];
|
||||||
assertNonVariableField(resultFieldDom, 'LABEL', 'default');
|
assertNonVariableField(resultFieldDom, 'LABEL', 'default');
|
||||||
});
|
});
|
||||||
test('Number', function() {
|
test('Number', function() {
|
||||||
@@ -234,9 +234,9 @@ suite('XML', function() {
|
|||||||
}
|
}
|
||||||
],
|
],
|
||||||
}]);
|
}]);
|
||||||
let block = new Blockly.Block(this.workspace,
|
const block = new Blockly.Block(this.workspace,
|
||||||
'field_number_test_block');
|
'field_number_test_block');
|
||||||
let resultFieldDom = Blockly.Xml.blockToDom(block).childNodes[0];
|
const resultFieldDom = Blockly.Xml.blockToDom(block).childNodes[0];
|
||||||
assertNonVariableField(resultFieldDom, 'NUMBER', '97');
|
assertNonVariableField(resultFieldDom, 'NUMBER', '97');
|
||||||
});
|
});
|
||||||
test('Text Input', function() {
|
test('Text Input', function() {
|
||||||
@@ -251,9 +251,9 @@ suite('XML', function() {
|
|||||||
}
|
}
|
||||||
],
|
],
|
||||||
}]);
|
}]);
|
||||||
let block = new Blockly.Block(this.workspace,
|
const block = new Blockly.Block(this.workspace,
|
||||||
'field_text_input_test_block');
|
'field_text_input_test_block');
|
||||||
let resultFieldDom = Blockly.Xml.blockToDom(block).childNodes[0];
|
const resultFieldDom = Blockly.Xml.blockToDom(block).childNodes[0];
|
||||||
assertNonVariableField(resultFieldDom, 'TEXT', 'default');
|
assertNonVariableField(resultFieldDom, 'TEXT', 'default');
|
||||||
});
|
});
|
||||||
suite('Variable Fields', function() {
|
suite('Variable Fields', function() {
|
||||||
@@ -272,18 +272,18 @@ suite('XML', function() {
|
|||||||
});
|
});
|
||||||
test('Variable Trivial', function() {
|
test('Variable Trivial', function() {
|
||||||
this.workspace.createVariable('name1', '', 'id1');
|
this.workspace.createVariable('name1', '', 'id1');
|
||||||
let block = new Blockly.Block(this.workspace,
|
const block = new Blockly.Block(this.workspace,
|
||||||
'field_variable_test_block');
|
'field_variable_test_block');
|
||||||
block.inputList[0].fieldRow[0].setValue('id1');
|
block.inputList[0].fieldRow[0].setValue('id1');
|
||||||
let resultFieldDom = Blockly.Xml.blockToDom(block).childNodes[0];
|
const resultFieldDom = Blockly.Xml.blockToDom(block).childNodes[0];
|
||||||
assertVariableDomField(resultFieldDom, 'VAR', null, 'id1', 'name1');
|
assertVariableDomField(resultFieldDom, 'VAR', null, 'id1', 'name1');
|
||||||
});
|
});
|
||||||
test('Variable Typed', function() {
|
test('Variable Typed', function() {
|
||||||
this.workspace.createVariable('name1', 'string', 'id1');
|
this.workspace.createVariable('name1', 'string', 'id1');
|
||||||
let block = new Blockly.Block(this.workspace,
|
const block = new Blockly.Block(this.workspace,
|
||||||
'field_variable_test_block');
|
'field_variable_test_block');
|
||||||
block.inputList[0].fieldRow[0].setValue('id1');
|
block.inputList[0].fieldRow[0].setValue('id1');
|
||||||
let resultFieldDom = Blockly.Xml.blockToDom(block).childNodes[0];
|
const resultFieldDom = Blockly.Xml.blockToDom(block).childNodes[0];
|
||||||
assertVariableDomField(resultFieldDom, 'VAR', 'string', 'id1', 'name1');
|
assertVariableDomField(resultFieldDom, 'VAR', 'string', 'id1', 'name1');
|
||||||
});
|
});
|
||||||
test('Variable Default Case', function() {
|
test('Variable Default Case', function() {
|
||||||
@@ -291,12 +291,12 @@ suite('XML', function() {
|
|||||||
this.workspace.createVariable('name1');
|
this.workspace.createVariable('name1');
|
||||||
|
|
||||||
Blockly.Events.disable();
|
Blockly.Events.disable();
|
||||||
let block = new Blockly.Block(this.workspace,
|
const block = new Blockly.Block(this.workspace,
|
||||||
'field_variable_test_block');
|
'field_variable_test_block');
|
||||||
block.inputList[0].fieldRow[0].setValue('1');
|
block.inputList[0].fieldRow[0].setValue('1');
|
||||||
Blockly.Events.enable();
|
Blockly.Events.enable();
|
||||||
|
|
||||||
let resultFieldDom = Blockly.Xml.blockToDom(block).childNodes[0];
|
const resultFieldDom = Blockly.Xml.blockToDom(block).childNodes[0];
|
||||||
// Expect type is null and ID is '1' since we don't specify type and ID.
|
// Expect type is null and ID is '1' since we don't specify type and ID.
|
||||||
assertVariableDomField(resultFieldDom, 'VAR', null, '1', 'name1');
|
assertVariableDomField(resultFieldDom, 'VAR', null, '1', 'name1');
|
||||||
});
|
});
|
||||||
@@ -311,18 +311,18 @@ suite('XML', function() {
|
|||||||
});
|
});
|
||||||
test('Text', function() {
|
test('Text', function() {
|
||||||
this.block.setCommentText('test text');
|
this.block.setCommentText('test text');
|
||||||
let xml = Blockly.Xml.blockToDom(this.block);
|
const xml = Blockly.Xml.blockToDom(this.block);
|
||||||
let commentXml = xml.firstChild;
|
const commentXml = xml.firstChild;
|
||||||
chai.assert.equal(commentXml.tagName, 'comment');
|
chai.assert.equal(commentXml.tagName, 'comment');
|
||||||
chai.assert.equal(commentXml.innerHTML, 'test text');
|
chai.assert.equal(commentXml.innerHTML, 'test text');
|
||||||
});
|
});
|
||||||
test('No Text', function() {
|
test('No Text', function() {
|
||||||
let xml = Blockly.Xml.blockToDom(this.block);
|
const xml = Blockly.Xml.blockToDom(this.block);
|
||||||
chai.assert.isNull(xml.firstChild);
|
chai.assert.isNull(xml.firstChild);
|
||||||
});
|
});
|
||||||
test('Empty Text', function() {
|
test('Empty Text', function() {
|
||||||
this.block.setCommentText('');
|
this.block.setCommentText('');
|
||||||
let xml = Blockly.Xml.blockToDom(this.block);
|
const xml = Blockly.Xml.blockToDom(this.block);
|
||||||
chai.assert.isNull(xml.firstChild);
|
chai.assert.isNull(xml.firstChild);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@@ -339,25 +339,25 @@ suite('XML', function() {
|
|||||||
});
|
});
|
||||||
test('Text', function() {
|
test('Text', function() {
|
||||||
this.block.setCommentText('test text');
|
this.block.setCommentText('test text');
|
||||||
let xml = Blockly.Xml.blockToDom(this.block);
|
const xml = Blockly.Xml.blockToDom(this.block);
|
||||||
let commentXml = xml.firstChild;
|
const commentXml = xml.firstChild;
|
||||||
chai.assert.equal(commentXml.tagName, 'comment');
|
chai.assert.equal(commentXml.tagName, 'comment');
|
||||||
chai.assert.equal(commentXml.innerHTML, 'test text');
|
chai.assert.equal(commentXml.innerHTML, 'test text');
|
||||||
});
|
});
|
||||||
test('No Text', function() {
|
test('No Text', function() {
|
||||||
let xml = Blockly.Xml.blockToDom(this.block);
|
const xml = Blockly.Xml.blockToDom(this.block);
|
||||||
chai.assert.isNull(xml.firstChild);
|
chai.assert.isNull(xml.firstChild);
|
||||||
});
|
});
|
||||||
test('Empty Text', function() {
|
test('Empty Text', function() {
|
||||||
this.block.setCommentText('');
|
this.block.setCommentText('');
|
||||||
let xml = Blockly.Xml.blockToDom(this.block);
|
const xml = Blockly.Xml.blockToDom(this.block);
|
||||||
chai.assert.isNull(xml.firstChild);
|
chai.assert.isNull(xml.firstChild);
|
||||||
});
|
});
|
||||||
test('Size', function() {
|
test('Size', function() {
|
||||||
this.block.setCommentText('test text');
|
this.block.setCommentText('test text');
|
||||||
this.block.getCommentIcon().setBubbleSize(100, 200);
|
this.block.getCommentIcon().setBubbleSize(100, 200);
|
||||||
let xml = Blockly.Xml.blockToDom(this.block);
|
const xml = Blockly.Xml.blockToDom(this.block);
|
||||||
let commentXml = xml.firstChild;
|
const commentXml = xml.firstChild;
|
||||||
chai.assert.equal(commentXml.tagName, 'comment');
|
chai.assert.equal(commentXml.tagName, 'comment');
|
||||||
chai.assert.equal(commentXml.getAttribute('w'), 100);
|
chai.assert.equal(commentXml.getAttribute('w'), 100);
|
||||||
chai.assert.equal(commentXml.getAttribute('h'), 200);
|
chai.assert.equal(commentXml.getAttribute('h'), 200);
|
||||||
@@ -365,15 +365,15 @@ suite('XML', function() {
|
|||||||
test('Pinned True', function() {
|
test('Pinned True', function() {
|
||||||
this.block.setCommentText('test text');
|
this.block.setCommentText('test text');
|
||||||
this.block.getCommentIcon().setVisible(true);
|
this.block.getCommentIcon().setVisible(true);
|
||||||
let xml = Blockly.Xml.blockToDom(this.block);
|
const xml = Blockly.Xml.blockToDom(this.block);
|
||||||
let commentXml = xml.firstChild;
|
const commentXml = xml.firstChild;
|
||||||
chai.assert.equal(commentXml.tagName, 'comment');
|
chai.assert.equal(commentXml.tagName, 'comment');
|
||||||
chai.assert.equal(commentXml.getAttribute('pinned'), 'true');
|
chai.assert.equal(commentXml.getAttribute('pinned'), 'true');
|
||||||
});
|
});
|
||||||
test('Pinned False', function() {
|
test('Pinned False', function() {
|
||||||
this.block.setCommentText('test text');
|
this.block.setCommentText('test text');
|
||||||
let xml = Blockly.Xml.blockToDom(this.block);
|
const xml = Blockly.Xml.blockToDom(this.block);
|
||||||
let commentXml = xml.firstChild;
|
const commentXml = xml.firstChild;
|
||||||
chai.assert.equal(commentXml.tagName, 'comment');
|
chai.assert.equal(commentXml.tagName, 'comment');
|
||||||
chai.assert.equal(commentXml.getAttribute('pinned'), 'false');
|
chai.assert.equal(commentXml.getAttribute('pinned'), 'false');
|
||||||
});
|
});
|
||||||
@@ -401,10 +401,10 @@ suite('XML', function() {
|
|||||||
test('One Variable', function() {
|
test('One Variable', function() {
|
||||||
createGenUidStubWithReturns('1');
|
createGenUidStubWithReturns('1');
|
||||||
this.workspace.createVariable('name1');
|
this.workspace.createVariable('name1');
|
||||||
let resultDom =
|
const resultDom =
|
||||||
Blockly.Xml.variablesToDom(this.workspace.getAllVariables());
|
Blockly.Xml.variablesToDom(this.workspace.getAllVariables());
|
||||||
chai.assert.equal(resultDom.children.length, 1);
|
chai.assert.equal(resultDom.children.length, 1);
|
||||||
let resultVariableDom = resultDom.children[0];
|
const resultVariableDom = resultDom.children[0];
|
||||||
chai.assert.equal(resultVariableDom.textContent, 'name1');
|
chai.assert.equal(resultVariableDom.textContent, 'name1');
|
||||||
chai.assert.isNull(resultVariableDom.getAttribute('type'));
|
chai.assert.isNull(resultVariableDom.getAttribute('type'));
|
||||||
chai.assert.equal(resultVariableDom.getAttribute('id'), '1');
|
chai.assert.equal(resultVariableDom.getAttribute('id'), '1');
|
||||||
@@ -415,11 +415,11 @@ suite('XML', function() {
|
|||||||
// If events are enabled during block construction, it will create a
|
// If events are enabled during block construction, it will create a
|
||||||
// default variable.
|
// default variable.
|
||||||
Blockly.Events.disable();
|
Blockly.Events.disable();
|
||||||
let block = new Blockly.Block(this.workspace, 'field_variable_test_block');
|
const block = new Blockly.Block(this.workspace, 'field_variable_test_block');
|
||||||
block.inputList[0].fieldRow[0].setValue('id1');
|
block.inputList[0].fieldRow[0].setValue('id1');
|
||||||
Blockly.Events.enable();
|
Blockly.Events.enable();
|
||||||
|
|
||||||
let resultDom = Blockly.Xml.variablesToDom(this.workspace.getAllVariables());
|
const resultDom = Blockly.Xml.variablesToDom(this.workspace.getAllVariables());
|
||||||
chai.assert.equal(resultDom.children.length, 2);
|
chai.assert.equal(resultDom.children.length, 2);
|
||||||
assertVariableDom(resultDom.children[0], null, 'id1',
|
assertVariableDom(resultDom.children[0], null, 'id1',
|
||||||
'name1');
|
'name1');
|
||||||
@@ -427,23 +427,23 @@ suite('XML', function() {
|
|||||||
'name2');
|
'name2');
|
||||||
});
|
});
|
||||||
test('No variables', function() {
|
test('No variables', function() {
|
||||||
let resultDom =
|
const resultDom =
|
||||||
Blockly.Xml.variablesToDom(this.workspace.getAllVariables());
|
Blockly.Xml.variablesToDom(this.workspace.getAllVariables());
|
||||||
chai.assert.equal(resultDom.children.length, 0);
|
chai.assert.equal(resultDom.children.length, 0);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
suite('domToText', function() {
|
suite('domToText', function() {
|
||||||
test('Round tripping', function() {
|
test('Round tripping', function() {
|
||||||
let dom = Blockly.Xml.textToDom(this.complexXmlText);
|
const dom = Blockly.Xml.textToDom(this.complexXmlText);
|
||||||
let text = Blockly.Xml.domToText(dom);
|
const text = Blockly.Xml.domToText(dom);
|
||||||
chai.assert.equal(text.replace(/\s+/g, ''),
|
chai.assert.equal(text.replace(/\s+/g, ''),
|
||||||
this.complexXmlText.replace(/\s+/g, ''), 'Round trip');
|
this.complexXmlText.replace(/\s+/g, ''), 'Round trip');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
suite('domToPrettyText', function() {
|
suite('domToPrettyText', function() {
|
||||||
test('Round tripping', function() {
|
test('Round tripping', function() {
|
||||||
let dom = Blockly.Xml.textToDom(this.complexXmlText);
|
const dom = Blockly.Xml.textToDom(this.complexXmlText);
|
||||||
let text = Blockly.Xml.domToPrettyText(dom);
|
const text = Blockly.Xml.domToPrettyText(dom);
|
||||||
chai.assert.equal(text.replace(/\s+/g, ''),
|
chai.assert.equal(text.replace(/\s+/g, ''),
|
||||||
this.complexXmlText.replace(/\s+/g, ''), 'Round trip');
|
this.complexXmlText.replace(/\s+/g, ''), 'Round trip');
|
||||||
});
|
});
|
||||||
@@ -458,7 +458,7 @@ suite('XML', function() {
|
|||||||
suite('Dynamic Category Blocks', function() {
|
suite('Dynamic Category Blocks', function() {
|
||||||
test('Untyped Variables', function() {
|
test('Untyped Variables', function() {
|
||||||
this.workspace.createVariable('name1', '', 'id1');
|
this.workspace.createVariable('name1', '', 'id1');
|
||||||
let blocksArray =
|
const blocksArray =
|
||||||
Blockly.Variables.flyoutCategoryBlocks(this.workspace);
|
Blockly.Variables.flyoutCategoryBlocks(this.workspace);
|
||||||
for (let i = 0, xml; (xml = blocksArray[i]); i++) {
|
for (let i = 0, xml; (xml = blocksArray[i]); i++) {
|
||||||
Blockly.Xml.domToBlock(xml, this.workspace);
|
Blockly.Xml.domToBlock(xml, this.workspace);
|
||||||
@@ -468,7 +468,7 @@ suite('XML', function() {
|
|||||||
this.workspace.createVariable('name1', 'String', 'id1');
|
this.workspace.createVariable('name1', 'String', 'id1');
|
||||||
this.workspace.createVariable('name2', 'Number', 'id2');
|
this.workspace.createVariable('name2', 'Number', 'id2');
|
||||||
this.workspace.createVariable('name3', 'Colour', 'id3');
|
this.workspace.createVariable('name3', 'Colour', 'id3');
|
||||||
let blocksArray =
|
const blocksArray =
|
||||||
Blockly.VariablesDynamic.flyoutCategoryBlocks(this.workspace);
|
Blockly.VariablesDynamic.flyoutCategoryBlocks(this.workspace);
|
||||||
for (let i = 0, xml; (xml = blocksArray[i]); i++) {
|
for (let i = 0, xml; (xml = blocksArray[i]); i++) {
|
||||||
Blockly.Xml.domToBlock(xml, this.workspace);
|
Blockly.Xml.domToBlock(xml, this.workspace);
|
||||||
@@ -478,7 +478,7 @@ suite('XML', function() {
|
|||||||
suite('Comments', function() {
|
suite('Comments', function() {
|
||||||
suite('Headless', function() {
|
suite('Headless', function() {
|
||||||
test('Text', function() {
|
test('Text', function() {
|
||||||
let block = Blockly.Xml.domToBlock(Blockly.Xml.textToDom(
|
const block = Blockly.Xml.domToBlock(Blockly.Xml.textToDom(
|
||||||
'<block type="empty_block">' +
|
'<block type="empty_block">' +
|
||||||
' <comment>test text</comment>' +
|
' <comment>test text</comment>' +
|
||||||
'</block>'
|
'</block>'
|
||||||
@@ -486,7 +486,7 @@ suite('XML', function() {
|
|||||||
chai.assert.equal(block.getCommentText(), 'test text');
|
chai.assert.equal(block.getCommentText(), 'test text');
|
||||||
});
|
});
|
||||||
test('No Text', function() {
|
test('No Text', function() {
|
||||||
let block = Blockly.Xml.domToBlock(Blockly.Xml.textToDom(
|
const block = Blockly.Xml.domToBlock(Blockly.Xml.textToDom(
|
||||||
'<block type="empty_block">' +
|
'<block type="empty_block">' +
|
||||||
' <comment></comment>' +
|
' <comment></comment>' +
|
||||||
'</block>'
|
'</block>'
|
||||||
@@ -494,7 +494,7 @@ suite('XML', function() {
|
|||||||
chai.assert.equal(block.getCommentText(), '');
|
chai.assert.equal(block.getCommentText(), '');
|
||||||
});
|
});
|
||||||
test('Size', function() {
|
test('Size', function() {
|
||||||
let block = Blockly.Xml.domToBlock(Blockly.Xml.textToDom(
|
const block = Blockly.Xml.domToBlock(Blockly.Xml.textToDom(
|
||||||
'<block type="empty_block">' +
|
'<block type="empty_block">' +
|
||||||
' <comment w="100" h="200">test text</comment>' +
|
' <comment w="100" h="200">test text</comment>' +
|
||||||
'</block>'
|
'</block>'
|
||||||
@@ -503,7 +503,7 @@ suite('XML', function() {
|
|||||||
{width: 100, height: 200});
|
{width: 100, height: 200});
|
||||||
});
|
});
|
||||||
test('Pinned True', function() {
|
test('Pinned True', function() {
|
||||||
let block = Blockly.Xml.domToBlock(Blockly.Xml.textToDom(
|
const block = Blockly.Xml.domToBlock(Blockly.Xml.textToDom(
|
||||||
'<block type="empty_block">' +
|
'<block type="empty_block">' +
|
||||||
' <comment pinned="true">test text</comment>' +
|
' <comment pinned="true">test text</comment>' +
|
||||||
'</block>'
|
'</block>'
|
||||||
@@ -511,7 +511,7 @@ suite('XML', function() {
|
|||||||
chai.assert.isTrue(block.commentModel.pinned);
|
chai.assert.isTrue(block.commentModel.pinned);
|
||||||
});
|
});
|
||||||
test('Pinned False', function() {
|
test('Pinned False', function() {
|
||||||
let block = Blockly.Xml.domToBlock(Blockly.Xml.textToDom(
|
const block = Blockly.Xml.domToBlock(Blockly.Xml.textToDom(
|
||||||
'<block type="empty_block">' +
|
'<block type="empty_block">' +
|
||||||
' <comment pinned="false">test text</comment>' +
|
' <comment pinned="false">test text</comment>' +
|
||||||
'</block>'
|
'</block>'
|
||||||
@@ -519,7 +519,7 @@ suite('XML', function() {
|
|||||||
chai.assert.isFalse(block.commentModel.pinned);
|
chai.assert.isFalse(block.commentModel.pinned);
|
||||||
});
|
});
|
||||||
test('Pinned Undefined', function() {
|
test('Pinned Undefined', function() {
|
||||||
let block = Blockly.Xml.domToBlock(Blockly.Xml.textToDom(
|
const block = Blockly.Xml.domToBlock(Blockly.Xml.textToDom(
|
||||||
'<block type="empty_block">' +
|
'<block type="empty_block">' +
|
||||||
' <comment>test text</comment>' +
|
' <comment>test text</comment>' +
|
||||||
'</block>'
|
'</block>'
|
||||||
@@ -536,7 +536,7 @@ suite('XML', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
test('Text', function() {
|
test('Text', function() {
|
||||||
let block = Blockly.Xml.domToBlock(Blockly.Xml.textToDom(
|
const block = Blockly.Xml.domToBlock(Blockly.Xml.textToDom(
|
||||||
'<block type="empty_block">' +
|
'<block type="empty_block">' +
|
||||||
' <comment>test text</comment>' +
|
' <comment>test text</comment>' +
|
||||||
'</block>'
|
'</block>'
|
||||||
@@ -545,7 +545,7 @@ suite('XML', function() {
|
|||||||
chai.assert.isNotNull(block.getCommentIcon());
|
chai.assert.isNotNull(block.getCommentIcon());
|
||||||
});
|
});
|
||||||
test('No Text', function() {
|
test('No Text', function() {
|
||||||
let block = Blockly.Xml.domToBlock(Blockly.Xml.textToDom(
|
const block = Blockly.Xml.domToBlock(Blockly.Xml.textToDom(
|
||||||
'<block type="empty_block">' +
|
'<block type="empty_block">' +
|
||||||
' <comment></comment>' +
|
' <comment></comment>' +
|
||||||
'</block>'
|
'</block>'
|
||||||
@@ -554,7 +554,7 @@ suite('XML', function() {
|
|||||||
chai.assert.isNotNull(block.getCommentIcon());
|
chai.assert.isNotNull(block.getCommentIcon());
|
||||||
});
|
});
|
||||||
test('Size', function() {
|
test('Size', function() {
|
||||||
let block = Blockly.Xml.domToBlock(Blockly.Xml.textToDom(
|
const block = Blockly.Xml.domToBlock(Blockly.Xml.textToDom(
|
||||||
'<block type="empty_block">' +
|
'<block type="empty_block">' +
|
||||||
' <comment w="100" h="200">test text</comment>' +
|
' <comment w="100" h="200">test text</comment>' +
|
||||||
'</block>'
|
'</block>'
|
||||||
@@ -567,7 +567,7 @@ suite('XML', function() {
|
|||||||
});
|
});
|
||||||
suite('Pinned', function() {
|
suite('Pinned', function() {
|
||||||
test('Pinned True', function() {
|
test('Pinned True', function() {
|
||||||
let block = Blockly.Xml.domToBlock(Blockly.Xml.textToDom(
|
const block = Blockly.Xml.domToBlock(Blockly.Xml.textToDom(
|
||||||
'<block type="empty_block">' +
|
'<block type="empty_block">' +
|
||||||
' <comment pinned="true">test text</comment>' +
|
' <comment pinned="true">test text</comment>' +
|
||||||
'</block>'
|
'</block>'
|
||||||
@@ -578,7 +578,7 @@ suite('XML', function() {
|
|||||||
chai.assert.isTrue(block.getCommentIcon().isVisible());
|
chai.assert.isTrue(block.getCommentIcon().isVisible());
|
||||||
});
|
});
|
||||||
test('Pinned False', function() {
|
test('Pinned False', function() {
|
||||||
let block = Blockly.Xml.domToBlock(Blockly.Xml.textToDom(
|
const block = Blockly.Xml.domToBlock(Blockly.Xml.textToDom(
|
||||||
'<block type="empty_block">' +
|
'<block type="empty_block">' +
|
||||||
' <comment pinned="false">test text</comment>' +
|
' <comment pinned="false">test text</comment>' +
|
||||||
'</block>'
|
'</block>'
|
||||||
@@ -589,7 +589,7 @@ suite('XML', function() {
|
|||||||
chai.assert.isFalse(block.getCommentIcon().isVisible());
|
chai.assert.isFalse(block.getCommentIcon().isVisible());
|
||||||
});
|
});
|
||||||
test('Pinned Undefined', function() {
|
test('Pinned Undefined', function() {
|
||||||
let block = Blockly.Xml.domToBlock(Blockly.Xml.textToDom(
|
const block = Blockly.Xml.domToBlock(Blockly.Xml.textToDom(
|
||||||
'<block type="empty_block">' +
|
'<block type="empty_block">' +
|
||||||
' <comment>test text</comment>' +
|
' <comment>test text</comment>' +
|
||||||
'</block>'
|
'</block>'
|
||||||
@@ -623,7 +623,7 @@ suite('XML', function() {
|
|||||||
});
|
});
|
||||||
test('Backwards compatibility', function() {
|
test('Backwards compatibility', function() {
|
||||||
createGenUidStubWithReturns('1');
|
createGenUidStubWithReturns('1');
|
||||||
let dom = Blockly.Xml.textToDom(
|
const dom = Blockly.Xml.textToDom(
|
||||||
'<xml xmlns="https://developers.google.com/blockly/xml">' +
|
'<xml xmlns="https://developers.google.com/blockly/xml">' +
|
||||||
' <block type="field_variable_test_block" id="block_id">' +
|
' <block type="field_variable_test_block" id="block_id">' +
|
||||||
' <field name="VAR">name1</field>' +
|
' <field name="VAR">name1</field>' +
|
||||||
@@ -634,7 +634,7 @@ suite('XML', function() {
|
|||||||
assertVariableValues(this.workspace, 'name1', '', '1');
|
assertVariableValues(this.workspace, 'name1', '', '1');
|
||||||
});
|
});
|
||||||
test('Variables at top', function() {
|
test('Variables at top', function() {
|
||||||
let dom = Blockly.Xml.textToDom(
|
const dom = Blockly.Xml.textToDom(
|
||||||
'<xml xmlns="https://developers.google.com/blockly/xml">' +
|
'<xml xmlns="https://developers.google.com/blockly/xml">' +
|
||||||
' <variables>' +
|
' <variables>' +
|
||||||
' <variable type="type1" id="id1">name1</variable>' +
|
' <variable type="type1" id="id1">name1</variable>' +
|
||||||
@@ -652,7 +652,7 @@ suite('XML', function() {
|
|||||||
assertVariableValues(this.workspace, 'name3', '', 'id3');
|
assertVariableValues(this.workspace, 'name3', '', 'id3');
|
||||||
});
|
});
|
||||||
test('Variables at top duplicated variables tag', function() {
|
test('Variables at top duplicated variables tag', function() {
|
||||||
let dom = Blockly.Xml.textToDom(
|
const dom = Blockly.Xml.textToDom(
|
||||||
'<xml xmlns="https://developers.google.com/blockly/xml">' +
|
'<xml xmlns="https://developers.google.com/blockly/xml">' +
|
||||||
' <variables>' +
|
' <variables>' +
|
||||||
' </variables>' +
|
' </variables>' +
|
||||||
@@ -664,7 +664,7 @@ suite('XML', function() {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
test('Variables at top missing type', function() {
|
test('Variables at top missing type', function() {
|
||||||
let dom = Blockly.Xml.textToDom(
|
const dom = Blockly.Xml.textToDom(
|
||||||
'<xml xmlns="https://developers.google.com/blockly/xml">' +
|
'<xml xmlns="https://developers.google.com/blockly/xml">' +
|
||||||
' <variables>' +
|
' <variables>' +
|
||||||
' <variable id="id1">name1</variable>' +
|
' <variable id="id1">name1</variable>' +
|
||||||
@@ -678,7 +678,7 @@ suite('XML', function() {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
test('Variables at top mismatch block type', function() {
|
test('Variables at top mismatch block type', function() {
|
||||||
let dom = Blockly.Xml.textToDom(
|
const dom = Blockly.Xml.textToDom(
|
||||||
'<xml xmlns="https://developers.google.com/blockly/xml">' +
|
'<xml xmlns="https://developers.google.com/blockly/xml">' +
|
||||||
' <variables>' +
|
' <variables>' +
|
||||||
' <variable type="type1" id="id1">name1</variable>' +
|
' <variable type="type1" id="id1">name1</variable>' +
|
||||||
@@ -708,21 +708,21 @@ suite('XML', function() {
|
|||||||
workspaceTeardown.call(this, this.workspace);
|
workspaceTeardown.call(this, this.workspace);
|
||||||
});
|
});
|
||||||
test('Headless', function() {
|
test('Headless', function() {
|
||||||
let dom = Blockly.Xml.textToDom(
|
const dom = Blockly.Xml.textToDom(
|
||||||
'<xml xmlns="https://developers.google.com/blockly/xml">' +
|
'<xml xmlns="https://developers.google.com/blockly/xml">' +
|
||||||
' <block type="test_block" inline="true" x="21" y="23">' +
|
' <block type="test_block" inline="true" x="21" y="23">' +
|
||||||
' </block>' +
|
' </block>' +
|
||||||
'</xml>');
|
'</xml>');
|
||||||
Blockly.Xml.appendDomToWorkspace(dom, this.workspace);
|
Blockly.Xml.appendDomToWorkspace(dom, this.workspace);
|
||||||
chai.assert.equal(this.workspace.getAllBlocks(false).length, 1, 'Block count');
|
chai.assert.equal(this.workspace.getAllBlocks(false).length, 1, 'Block count');
|
||||||
let newBlockIds = Blockly.Xml.appendDomToWorkspace(dom, this.workspace);
|
const newBlockIds = Blockly.Xml.appendDomToWorkspace(dom, this.workspace);
|
||||||
chai.assert.equal(this.workspace.getAllBlocks(false).length, 2, 'Block count');
|
chai.assert.equal(this.workspace.getAllBlocks(false).length, 2, 'Block count');
|
||||||
chai.assert.equal(newBlockIds.length, 1, 'Number of new block ids');
|
chai.assert.equal(newBlockIds.length, 1, 'Number of new block ids');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
suite('workspaceToDom -> domToWorkspace -> workspaceToDom', function() {
|
suite('workspaceToDom -> domToWorkspace -> workspaceToDom', function() {
|
||||||
setup(function() {
|
setup(function() {
|
||||||
let options = {
|
const options = {
|
||||||
comments: true
|
comments: true
|
||||||
};
|
};
|
||||||
this.renderedWorkspace = Blockly.inject('blocklyDiv', options);
|
this.renderedWorkspace = Blockly.inject('blocklyDiv', options);
|
||||||
@@ -733,19 +733,19 @@ suite('XML', function() {
|
|||||||
workspaceTeardown.call(this, this.renderedWorkspace);
|
workspaceTeardown.call(this, this.renderedWorkspace);
|
||||||
workspaceTeardown.call(this, this.headlessWorkspace);
|
workspaceTeardown.call(this, this.headlessWorkspace);
|
||||||
});
|
});
|
||||||
let assertRoundTrip = function(originWs, targetWs) {
|
const assertRoundTrip = function(originWs, targetWs) {
|
||||||
let originXml = Blockly.Xml.workspaceToDom(originWs);
|
const originXml = Blockly.Xml.workspaceToDom(originWs);
|
||||||
Blockly.Xml.domToWorkspace(originXml, targetWs);
|
Blockly.Xml.domToWorkspace(originXml, targetWs);
|
||||||
let targetXml = Blockly.Xml.workspaceToDom(targetWs);
|
const targetXml = Blockly.Xml.workspaceToDom(targetWs);
|
||||||
|
|
||||||
let expectedXmlText = Blockly.Xml.domToText(originXml);
|
const expectedXmlText = Blockly.Xml.domToText(originXml);
|
||||||
let actualXmlText = Blockly.Xml.domToText(targetXml);
|
const actualXmlText = Blockly.Xml.domToText(targetXml);
|
||||||
|
|
||||||
chai.assert.equal(actualXmlText, expectedXmlText);
|
chai.assert.equal(actualXmlText, expectedXmlText);
|
||||||
};
|
};
|
||||||
suite('Rendered -> XML -> Headless -> XML', function() {
|
suite('Rendered -> XML -> Headless -> XML', function() {
|
||||||
test('Comment', function() {
|
test('Comment', function() {
|
||||||
let block = Blockly.Xml.domToBlock(Blockly.Xml.textToDom(
|
const block = Blockly.Xml.domToBlock(Blockly.Xml.textToDom(
|
||||||
'<block type="empty_block"/>'
|
'<block type="empty_block"/>'
|
||||||
), this.renderedWorkspace);
|
), this.renderedWorkspace);
|
||||||
block.setCommentText('test text');
|
block.setCommentText('test text');
|
||||||
@@ -756,7 +756,7 @@ suite('XML', function() {
|
|||||||
});
|
});
|
||||||
suite('Headless -> XML -> Rendered -> XML', function() {
|
suite('Headless -> XML -> Rendered -> XML', function() {
|
||||||
test('Comment', function() {
|
test('Comment', function() {
|
||||||
let block = Blockly.Xml.domToBlock(Blockly.Xml.textToDom(
|
const block = Blockly.Xml.domToBlock(Blockly.Xml.textToDom(
|
||||||
'<block type="empty_block"/>'
|
'<block type="empty_block"/>'
|
||||||
), this.headlessWorkspace);
|
), this.headlessWorkspace);
|
||||||
block.setCommentText('test text');
|
block.setCommentText('test text');
|
||||||
@@ -771,11 +771,11 @@ suite('XML', function() {
|
|||||||
});
|
});
|
||||||
suite('generateVariableFieldDom', function() {
|
suite('generateVariableFieldDom', function() {
|
||||||
test('Case Sensitive', function() {
|
test('Case Sensitive', function() {
|
||||||
let varId = 'testId';
|
const varId = 'testId';
|
||||||
let type = 'testType';
|
const type = 'testType';
|
||||||
let name = 'testName';
|
const name = 'testName';
|
||||||
|
|
||||||
let mockVariableModel = {
|
const mockVariableModel = {
|
||||||
type: type,
|
type: type,
|
||||||
name: name,
|
name: name,
|
||||||
getId: function() {
|
getId: function() {
|
||||||
@@ -783,9 +783,9 @@ suite('XML', function() {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
let generatedXml = Blockly.Xml.domToText(
|
const generatedXml = Blockly.Xml.domToText(
|
||||||
Blockly.Variables.generateVariableFieldDom(mockVariableModel));
|
Blockly.Variables.generateVariableFieldDom(mockVariableModel));
|
||||||
let expectedXml =
|
const expectedXml =
|
||||||
'<field xmlns="https://developers.google.com/blockly/xml"' +
|
'<field xmlns="https://developers.google.com/blockly/xml"' +
|
||||||
' name="VAR"' +
|
' name="VAR"' +
|
||||||
' id="' + varId + '"' +
|
' id="' + varId + '"' +
|
||||||
|
|||||||
Reference in New Issue
Block a user