Move createRenderedBlock to test helpers, fix setup, use helper in more places

This commit is contained in:
Rachel Fenichel
2020-08-05 20:33:34 -07:00
parent 6dd5428e5b
commit 3a7a636d28
2 changed files with 71 additions and 77 deletions

View File

@@ -424,14 +424,14 @@ suite('Blocks', function() {
});
suite('Deserialization', function() {
setup() {
setup(function() {
this.deserializationHelper = function(text) {
let dom = Blockly.Xml.textToDom(text);
Blockly.Xml.appendDomToWorkspace(dom, this.workspace);
this.assertConnectionsEmpty();
this.clock.runAll();
}
}
};
});
test('Stack', function() {
this.deserializationHelper(
'<xml>' +
@@ -898,16 +898,8 @@ suite('Blocks', function() {
});
});
suite('Remove Connections Programmatically', function() {
setup() {
this.makeBlock = function(type) {
var block = this.workspace.newBlock(type);
block.initSvg();
block.render();
return block;
}
}
test('Output', function() {
var block = this.makeBlock('row_block');
var block = createRenderedBlock(this.workspace, 'row_block');
block.setOutput(false);
@@ -915,7 +907,7 @@ suite('Blocks', function() {
chai.assert.equal(this.getInputs().length, 1);
});
test('Value', function() {
var block = this.makeBlock('row_block');
var block = createRenderedBlock(this.workspace, 'row_block');
block.removeInput('INPUT');
@@ -923,7 +915,7 @@ suite('Blocks', function() {
chai.assert.equal(this.getInputs().length, 0);
});
test('Previous', function() {
var block = this.makeBlock('stack_block');
var block = createRenderedBlock(this.workspace, 'stack_block');
block.setPreviousStatement(false);
@@ -931,7 +923,7 @@ suite('Blocks', function() {
chai.assert.equal(this.getNext().length, 1);
});
test('Next', function() {
var block = this.makeBlock('stack_block');
var block = createRenderedBlock(this.workspace, 'stack_block');
block.setNextStatement(false);
@@ -939,7 +931,7 @@ suite('Blocks', function() {
chai.assert.equal(this.getNext().length, 0);
});
test('Statement', function() {
var block = this.makeBlock('statement_block');
var block = createRenderedBlock(this.workspace, 'statement_block');
block.removeInput('STATEMENT');
@@ -949,9 +941,10 @@ suite('Blocks', function() {
});
suite('Add Connections Programmatically', function() {
test('Output', function() {
var block = this.workspace.newBlock('empty_block');
block.initSvg();
block.render();
var block = createRenderedBlock(this.workspace, 'empty_block');
// this.workspace.newBlock('empty_block');
// block.initSvg();
// block.render();
block.setOutput(true);
@@ -1238,12 +1231,6 @@ suite('Blocks', function() {
],
}
]);
this.createBlock = function(type) {
var block = this.workspace.newBlock(type);
block.initSvg();
block.render();
return block;
};
});
teardown(function() {
Blockly.Events.enable();
@@ -1251,8 +1238,8 @@ suite('Blocks', function() {
});
suite('Connecting and Disconnecting', function() {
test('Connect Block to Next', function() {
var blockA = this.createBlock('stack_block');
var blockB = this.createBlock('stack_block');
var blockA = createRenderedBlock(this.workspace,'stack_block');
var blockB = createRenderedBlock(this.workspace,'stack_block');
blockA.setCollapsed(true);
assertCollapsed(blockA);
@@ -1260,8 +1247,8 @@ suite('Blocks', function() {
assertNotCollapsed(blockB);
});
test('Connect Block to Value Input', function() {
var blockA = this.createBlock('row_block');
var blockB = this.createBlock('row_block');
var blockA = createRenderedBlock(this.workspace,'row_block');
var blockB = createRenderedBlock(this.workspace,'row_block');
blockA.setCollapsed(true);
assertCollapsed(blockA);
@@ -1272,8 +1259,8 @@ suite('Blocks', function() {
chai.assert.isFalse(isBlockHidden(blockB));
});
test('Connect Block to Statement Input', function() {
var blockA = this.createBlock('statement_block');
var blockB = this.createBlock('stack_block');
var blockA = createRenderedBlock(this.workspace,'statement_block');
var blockB = createRenderedBlock(this.workspace,'stack_block');
blockA.setCollapsed(true);
assertCollapsed(blockA);
@@ -1285,9 +1272,9 @@ suite('Blocks', function() {
chai.assert.isFalse(isBlockHidden(blockB));
});
test('Connect Block to Child of Collapsed - Input', function() {
var blockA = this.createBlock('row_block');
var blockB = this.createBlock('row_block');
var blockC = this.createBlock('row_block');
var blockA = createRenderedBlock(this.workspace,'row_block');
var blockB = createRenderedBlock(this.workspace,'row_block');
var blockC = createRenderedBlock(this.workspace,'row_block');
blockA.getInput('INPUT').connection.connect(blockB.outputConnection);
blockA.setCollapsed(true);
@@ -1302,9 +1289,9 @@ suite('Blocks', function() {
chai.assert.isFalse(isBlockHidden(blockC));
});
test('Connect Block to Child of Collapsed - Next', function() {
var blockA = this.createBlock('statement_block');
var blockB = this.createBlock('stack_block');
var blockC = this.createBlock('stack_block');
var blockA = createRenderedBlock(this.workspace,'statement_block');
var blockB = createRenderedBlock(this.workspace,'stack_block');
var blockC = createRenderedBlock(this.workspace,'stack_block');
blockA.getInput('STATEMENT').connection
.connect(blockB.previousConnection);
@@ -1320,9 +1307,9 @@ suite('Blocks', function() {
chai.assert.isFalse(isBlockHidden(blockC));
});
test('Connect Block to Value Input Already Taken', function() {
var blockA = this.createBlock('row_block');
var blockB = this.createBlock('row_block');
var blockC = this.createBlock('row_block');
var blockA = createRenderedBlock(this.workspace,'row_block');
var blockB = createRenderedBlock(this.workspace,'row_block');
var blockC = createRenderedBlock(this.workspace,'row_block');
blockA.getInput('INPUT').connection.connect(blockB.outputConnection);
blockA.setCollapsed(true);
@@ -1339,9 +1326,9 @@ suite('Blocks', function() {
chai.assert.isFalse(isBlockHidden(blockC));
});
test('Connect Block to Statement Input Already Taken', function() {
var blockA = this.createBlock('statement_block');
var blockB = this.createBlock('stack_block');
var blockC = this.createBlock('stack_block');
var blockA = createRenderedBlock(this.workspace,'statement_block');
var blockB = createRenderedBlock(this.workspace,'stack_block');
var blockC = createRenderedBlock(this.workspace,'stack_block');
blockA.getInput('STATEMENT').connection
.connect(blockB.previousConnection);
@@ -1360,9 +1347,9 @@ suite('Blocks', function() {
chai.assert.isFalse(isBlockHidden(blockC));
});
test('Connect Block with Child - Input', function() {
var blockA = this.createBlock('row_block');
var blockB = this.createBlock('row_block');
var blockC = this.createBlock('row_block');
var blockA = createRenderedBlock(this.workspace,'row_block');
var blockB = createRenderedBlock(this.workspace,'row_block');
var blockC = createRenderedBlock(this.workspace,'row_block');
blockB.getInput('INPUT').connection.connect(blockC.outputConnection);
blockA.setCollapsed(true);
@@ -1377,9 +1364,9 @@ suite('Blocks', function() {
chai.assert.isFalse(isBlockHidden(blockC));
});
test('Connect Block with Child - Statement', function() {
var blockA = this.createBlock('statement_block');
var blockB = this.createBlock('stack_block');
var blockC = this.createBlock('stack_block');
var blockA = createRenderedBlock(this.workspace,'statement_block');
var blockB = createRenderedBlock(this.workspace,'stack_block');
var blockC = createRenderedBlock(this.workspace,'stack_block');
blockB.nextConnection.connect(blockC.previousConnection);
blockA.setCollapsed(true);
@@ -1395,8 +1382,8 @@ suite('Blocks', function() {
chai.assert.isFalse(isBlockHidden(blockC));
});
test('Disconnect Block from Value Input', function() {
var blockA = this.createBlock('row_block');
var blockB = this.createBlock('row_block');
var blockA = createRenderedBlock(this.workspace,'row_block');
var blockB = createRenderedBlock(this.workspace,'row_block');
blockA.getInput('INPUT').connection.connect(blockB.outputConnection);
blockA.setCollapsed(true);
@@ -1406,8 +1393,8 @@ suite('Blocks', function() {
chai.assert.isFalse(isBlockHidden(blockB));
});
test('Disconnect Block from Statement Input', function() {
var blockA = this.createBlock('statement_block');
var blockB = this.createBlock('stack_block');
var blockA = createRenderedBlock(this.workspace,'statement_block');
var blockB = createRenderedBlock(this.workspace,'stack_block');
blockA.getInput('STATEMENT').connection
.connect(blockB.previousConnection);
@@ -1418,9 +1405,9 @@ suite('Blocks', function() {
chai.assert.isFalse(isBlockHidden(blockB));
});
test('Disconnect Block from Child of Collapsed - Input', function() {
var blockA = this.createBlock('row_block');
var blockB = this.createBlock('row_block');
var blockC = this.createBlock('row_block');
var blockA = createRenderedBlock(this.workspace,'row_block');
var blockB = createRenderedBlock(this.workspace,'row_block');
var blockC = createRenderedBlock(this.workspace,'row_block');
blockA.getInput('INPUT').connection.connect(blockB.outputConnection);
blockB.getInput('INPUT').connection.connect(blockC.outputConnection);
@@ -1433,9 +1420,9 @@ suite('Blocks', function() {
chai.assert.isFalse(isBlockHidden(blockC));
});
test('Disconnect Block from Child of Collapsed - Next', function() {
var blockA = this.createBlock('statement_block');
var blockB = this.createBlock('stack_block');
var blockC = this.createBlock('stack_block');
var blockA = createRenderedBlock(this.workspace,'statement_block');
var blockB = createRenderedBlock(this.workspace,'stack_block');
var blockC = createRenderedBlock(this.workspace,'stack_block');
blockA.getInput('STATEMENT').connection
.connect(blockB.previousConnection);
@@ -1449,9 +1436,9 @@ suite('Blocks', function() {
chai.assert.isFalse(isBlockHidden(blockC));
});
test('Disconnect Block with Child - Input', function() {
var blockA = this.createBlock('row_block');
var blockB = this.createBlock('row_block');
var blockC = this.createBlock('row_block');
var blockA = createRenderedBlock(this.workspace,'row_block');
var blockB = createRenderedBlock(this.workspace,'row_block');
var blockC = createRenderedBlock(this.workspace,'row_block');
blockB.getInput('INPUT').connection.connect(blockC.outputConnection);
blockA.getInput('INPUT').connection.connect(blockB.outputConnection);
@@ -1465,9 +1452,9 @@ suite('Blocks', function() {
chai.assert.isFalse(isBlockHidden(blockC));
});
test('Disconnect Block with Child - Statement', function() {
var blockA = this.createBlock('statement_block');
var blockB = this.createBlock('stack_block');
var blockC = this.createBlock('stack_block');
var blockA = createRenderedBlock(this.workspace,'statement_block');
var blockB = createRenderedBlock(this.workspace,'stack_block');
var blockC = createRenderedBlock(this.workspace,'stack_block');
blockB.nextConnection.connect(blockC.previousConnection);
blockA.getInput('STATEMENT').connection
@@ -1484,7 +1471,7 @@ suite('Blocks', function() {
});
suite('Adding and Removing Block Parts', function() {
test('Add Previous Connection', function() {
var blockA = this.createBlock('empty_block');
var blockA = createRenderedBlock(this.workspace,'empty_block');
blockA.setCollapsed(true);
assertCollapsed(blockA);
blockA.setPreviousStatement(true);
@@ -1492,7 +1479,7 @@ suite('Blocks', function() {
chai.assert.isNotNull(blockA.previousConnection);
});
test('Add Next Connection', function() {
var blockA = this.createBlock('empty_block');
var blockA = createRenderedBlock(this.workspace,'empty_block');
blockA.setCollapsed(true);
assertCollapsed(blockA);
blockA.setNextStatement(true);
@@ -1500,7 +1487,7 @@ suite('Blocks', function() {
chai.assert.isNotNull(blockA.nextConnection);
});
test('Add Input', function() {
var blockA = this.createBlock('empty_block');
var blockA = createRenderedBlock(this.workspace,'empty_block');
blockA.setCollapsed(true);
assertCollapsed(blockA);
blockA.appendDummyInput('NAME');
@@ -1508,7 +1495,7 @@ suite('Blocks', function() {
chai.assert.isNotNull(blockA.getInput('NAME'));
});
test('Add Field', function() {
var blockA = this.createBlock('empty_block');
var blockA = createRenderedBlock(this.workspace,'empty_block');
var input = blockA.appendDummyInput('NAME');
blockA.setCollapsed(true);
assertCollapsed(blockA);
@@ -1519,14 +1506,14 @@ suite('Blocks', function() {
chai.assert.equal(field.getText(), 'test');
});
test('Add Icon', function() {
var blockA = this.createBlock('empty_block');
var blockA = createRenderedBlock(this.workspace,'empty_block');
blockA.setCollapsed(true);
assertCollapsed(blockA);
blockA.setCommentText('test');
assertCollapsed(blockA);
});
test('Remove Previous Connection', function() {
var blockA = this.createBlock('empty_block');
var blockA = createRenderedBlock(this.workspace,'empty_block');
blockA.setPreviousStatement(true);
blockA.setCollapsed(true);
assertCollapsed(blockA);
@@ -1535,7 +1522,7 @@ suite('Blocks', function() {
chai.assert.isNull(blockA.previousConnection);
});
test('Remove Next Connection', function() {
var blockA = this.createBlock('empty_block');
var blockA = createRenderedBlock(this.workspace,'empty_block');
blockA.setNextStatement(true);
blockA.setCollapsed(true);
assertCollapsed(blockA);
@@ -1544,7 +1531,7 @@ suite('Blocks', function() {
chai.assert.isNull(blockA.nextConnection);
});
test('Remove Input', function() {
var blockA = this.createBlock('empty_block');
var blockA = createRenderedBlock(this.workspace,'empty_block');
blockA.appendDummyInput('NAME');
blockA.setCollapsed(true);
assertCollapsed(blockA);
@@ -1553,7 +1540,7 @@ suite('Blocks', function() {
chai.assert.isNull(blockA.getInput('NAME'));
});
test('Remove Field', function() {
var blockA = this.createBlock('empty_block');
var blockA = createRenderedBlock(this.workspace,'empty_block');
var input = blockA.appendDummyInput('NAME');
input.appendField(new Blockly.FieldLabel('test'), 'FIELD');
blockA.setCollapsed(true);
@@ -1564,7 +1551,7 @@ suite('Blocks', function() {
chai.assert.isNull(field);
});
test('Remove Icon', function() {
var blockA = this.createBlock('empty_block');
var blockA = createRenderedBlock(this.workspace,'empty_block');
blockA.setCommentText('test');
blockA.setCollapsed(true);
assertCollapsed(blockA);
@@ -1574,7 +1561,7 @@ suite('Blocks', function() {
});
suite('Renaming Vars', function() {
test('Simple Rename', function() {
var blockA = this.createBlock('variable_block');
var blockA = createRenderedBlock(this.workspace,'variable_block');
blockA.setCollapsed(true);
assertCollapsed(blockA, 'x');
@@ -1584,7 +1571,7 @@ suite('Blocks', function() {
assertCollapsed(blockA, 'y');
});
test('Coalesce, Different Case', function() {
var blockA = this.createBlock('variable_block');
var blockA = createRenderedBlock(this.workspace,'variable_block');
blockA.setCollapsed(true);
assertCollapsed(blockA, 'x');

View File

@@ -291,3 +291,10 @@ function createTestBlock() {
}
};
}
function createRenderedBlock(workspaceSvg, type) {
var block = workspaceSvg.newBlock(type);
block.initSvg();
block.render();
return block;
}