mirror of
https://github.com/google/blockly.git
synced 2026-01-07 09:00:11 +01:00
chore: run eslint--fix for no-var rule in tests/mocha (#5637)
This commit is contained in:
@@ -56,7 +56,7 @@ suite('Events', function() {
|
||||
|
||||
suite('Constructors', function() {
|
||||
test('Abstract', function() {
|
||||
var event = new Blockly.Events.Abstract();
|
||||
let event = new Blockly.Events.Abstract();
|
||||
assertEventEquals(event, undefined, undefined, undefined, {
|
||||
'recordUndo': true,
|
||||
'group': ''
|
||||
@@ -64,7 +64,7 @@ suite('Events', function() {
|
||||
});
|
||||
|
||||
test('UI event without block', function() {
|
||||
var event = new Blockly.Events.UiBase(this.workspace.id);
|
||||
let event = new Blockly.Events.UiBase(this.workspace.id);
|
||||
assertEventEquals(event, undefined, this.workspace.id, undefined, {
|
||||
'recordUndo': false,
|
||||
'group': '',
|
||||
@@ -72,7 +72,7 @@ suite('Events', function() {
|
||||
});
|
||||
|
||||
test('Click without block', function() {
|
||||
var event = new Blockly.Events.Click(null, this.workspace.id, 'workspace');
|
||||
let event = new Blockly.Events.Click(null, this.workspace.id, 'workspace');
|
||||
assertEventEquals(event, Blockly.Events.CLICK, this.workspace.id, null, {
|
||||
'targetType': 'workspace',
|
||||
'recordUndo': false,
|
||||
@@ -81,9 +81,9 @@ suite('Events', function() {
|
||||
});
|
||||
|
||||
test('Old UI event without block', function() {
|
||||
var TEST_GROUP_ID = 'testGroup';
|
||||
let TEST_GROUP_ID = 'testGroup';
|
||||
eventUtils.setGroup(TEST_GROUP_ID);
|
||||
var event = new Blockly.Events.Ui(null, 'foo', 'bar', 'baz');
|
||||
let event = new Blockly.Events.Ui(null, 'foo', 'bar', 'baz');
|
||||
assertEventEquals(event, Blockly.Events.UI, '', null, {
|
||||
'element': 'foo',
|
||||
'oldValue': 'bar',
|
||||
@@ -104,7 +104,7 @@ suite('Events', function() {
|
||||
});
|
||||
|
||||
test('Block base', function() {
|
||||
var event = new Blockly.Events.BlockBase(this.block);
|
||||
let event = new Blockly.Events.BlockBase(this.block);
|
||||
sinon.assert.calledOnce(this.genUidStub);
|
||||
assertEventEquals(event, undefined,
|
||||
this.workspace.id, this.TEST_BLOCK_ID,
|
||||
@@ -116,7 +116,7 @@ suite('Events', function() {
|
||||
});
|
||||
|
||||
test('Block create', function() {
|
||||
var event = new Blockly.Events.BlockCreate(this.block);
|
||||
let event = new Blockly.Events.BlockCreate(this.block);
|
||||
sinon.assert.calledOnce(this.genUidStub);
|
||||
assertEventEquals(event, Blockly.Events.BLOCK_CREATE,
|
||||
this.workspace.id, this.TEST_BLOCK_ID,
|
||||
@@ -127,7 +127,7 @@ suite('Events', function() {
|
||||
});
|
||||
|
||||
test('Block delete', function() {
|
||||
var event = new Blockly.Events.BlockDelete(this.block);
|
||||
let event = new Blockly.Events.BlockDelete(this.block);
|
||||
sinon.assert.calledOnce(this.genUidStub);
|
||||
assertEventEquals(event, Blockly.Events.BLOCK_DELETE,
|
||||
this.workspace.id, this.TEST_BLOCK_ID,
|
||||
@@ -138,9 +138,9 @@ suite('Events', function() {
|
||||
});
|
||||
|
||||
test('Old UI event with block', function() {
|
||||
var TEST_GROUP_ID = 'testGroup';
|
||||
let TEST_GROUP_ID = 'testGroup';
|
||||
eventUtils.setGroup(TEST_GROUP_ID);
|
||||
var event = new Blockly.Events.Ui(this.block, 'foo', 'bar', 'baz');
|
||||
let event = new Blockly.Events.Ui(this.block, 'foo', 'bar', 'baz');
|
||||
sinon.assert.calledOnce(this.genUidStub);
|
||||
assertEventEquals(event, Blockly.Events.UI, this.workspace.id,
|
||||
this.TEST_BLOCK_ID,
|
||||
@@ -154,9 +154,9 @@ suite('Events', function() {
|
||||
});
|
||||
|
||||
test('Click with block', function() {
|
||||
var TEST_GROUP_ID = 'testGroup';
|
||||
let TEST_GROUP_ID = 'testGroup';
|
||||
eventUtils.setGroup(TEST_GROUP_ID);
|
||||
var event = new Blockly.Events.Click(this.block, null, 'block');
|
||||
let event = new Blockly.Events.Click(this.block, null, 'block');
|
||||
assertEventEquals(event, Blockly.Events.CLICK, this.workspace.id,
|
||||
this.TEST_BLOCK_ID, {
|
||||
'targetType': 'block',
|
||||
@@ -167,10 +167,10 @@ suite('Events', function() {
|
||||
|
||||
suite('Block Move', function() {
|
||||
test('by coordinate', function() {
|
||||
var coordinate = new Blockly.utils.Coordinate(3, 4);
|
||||
let coordinate = new Blockly.utils.Coordinate(3, 4);
|
||||
this.block.xy_ = coordinate;
|
||||
|
||||
var event = new Blockly.Events.BlockMove(this.block);
|
||||
let event = new Blockly.Events.BlockMove(this.block);
|
||||
sinon.assert.calledOnce(this.genUidStub);
|
||||
assertEventEquals(event, Blockly.Events.BLOCK_MOVE, this.workspace.id,
|
||||
this.TEST_BLOCK_ID, {
|
||||
@@ -187,7 +187,7 @@ suite('Events', function() {
|
||||
this.parentBlock = createSimpleTestBlock(this.workspace);
|
||||
this.block.parentBlock_ = this.parentBlock;
|
||||
this.block.xy_ = new Blockly.utils.Coordinate(3, 4);
|
||||
var event = new Blockly.Events.BlockMove(this.block);
|
||||
let event = new Blockly.Events.BlockMove(this.block);
|
||||
sinon.assert.calledTwice(this.genUidStub);
|
||||
assertEventEquals(event, Blockly.Events.BLOCK_MOVE, this.workspace.id,
|
||||
this.TEST_BLOCK_ID, {
|
||||
@@ -217,7 +217,7 @@ suite('Events', function() {
|
||||
});
|
||||
|
||||
test('Block base', function() {
|
||||
var event = new Blockly.Events.BlockBase(this.block);
|
||||
let event = new Blockly.Events.BlockBase(this.block);
|
||||
sinon.assert.calledOnce(this.genUidStub);
|
||||
assertEventEquals(event, undefined,
|
||||
this.workspace.id, this.TEST_BLOCK_ID,
|
||||
@@ -229,7 +229,7 @@ suite('Events', function() {
|
||||
});
|
||||
|
||||
test('Block change', function() {
|
||||
var event = new Blockly.Events.BlockChange(
|
||||
let event = new Blockly.Events.BlockChange(
|
||||
this.block, 'field', 'FIELD_NAME', 'old', 'new');
|
||||
sinon.assert.calledOnce(this.genUidStub);
|
||||
assertEventEquals(event, Blockly.Events.BLOCK_CHANGE,
|
||||
@@ -246,7 +246,7 @@ suite('Events', function() {
|
||||
});
|
||||
|
||||
test('Block create', function() {
|
||||
var event = new Blockly.Events.BlockCreate(this.block);
|
||||
let event = new Blockly.Events.BlockCreate(this.block);
|
||||
sinon.assert.calledOnce(this.genUidStub);
|
||||
assertEventEquals(event, Blockly.Events.BLOCK_CREATE,
|
||||
this.workspace.id, this.TEST_BLOCK_ID,
|
||||
@@ -257,7 +257,7 @@ suite('Events', function() {
|
||||
});
|
||||
|
||||
test('Block delete', function() {
|
||||
var event = new Blockly.Events.BlockDelete(this.block);
|
||||
let event = new Blockly.Events.BlockDelete(this.block);
|
||||
sinon.assert.calledOnce(this.genUidStub);
|
||||
assertEventEquals(event, Blockly.Events.BLOCK_DELETE,
|
||||
this.workspace.id, this.TEST_BLOCK_ID,
|
||||
@@ -272,7 +272,7 @@ suite('Events', function() {
|
||||
this.parentBlock = createSimpleTestBlock(this.workspace);
|
||||
this.block.parentBlock_ = this.parentBlock;
|
||||
this.block.xy_ = new Blockly.utils.Coordinate(3, 4);
|
||||
var event = new Blockly.Events.BlockMove(this.block);
|
||||
let event = new Blockly.Events.BlockMove(this.block);
|
||||
sinon.assert.calledTwice(this.genUidStub);
|
||||
assertEventEquals(event, Blockly.Events.BLOCK_MOVE, this.workspace.id,
|
||||
this.TEST_BLOCK_ID,
|
||||
@@ -301,7 +301,7 @@ suite('Events', function() {
|
||||
});
|
||||
|
||||
test('Block change', function() {
|
||||
var event = new Blockly.Events.BlockChange(
|
||||
let event = new Blockly.Events.BlockChange(
|
||||
this.block, 'field', 'VAR', 'id1', 'id2');
|
||||
assertEventEquals(event, Blockly.Events.BLOCK_CHANGE, this.workspace.id,
|
||||
this.TEST_BLOCK_ID,
|
||||
@@ -318,7 +318,7 @@ suite('Events', function() {
|
||||
});
|
||||
|
||||
suite('Serialization', function() {
|
||||
var safeStringify = (json) => {
|
||||
let safeStringify = (json) => {
|
||||
let cache = [];
|
||||
return JSON.stringify(json, (key, value) => {
|
||||
if (typeof value == 'object' && value != null) {
|
||||
@@ -332,7 +332,7 @@ suite('Events', function() {
|
||||
return value;
|
||||
});
|
||||
};
|
||||
var variableEventTestCases = [
|
||||
let variableEventTestCases = [
|
||||
{title: 'Var create', class: Blockly.Events.VarCreate,
|
||||
getArgs: (thisObj) => [thisObj.variable],
|
||||
getExpectedJson: () => ({type: 'var_create', varId: 'id1',
|
||||
@@ -346,7 +346,7 @@ suite('Events', function() {
|
||||
getExpectedJson: () => ({type: 'var_rename', varId: 'id1',
|
||||
oldName: 'name1', newName: 'name2'})},
|
||||
];
|
||||
var uiEventTestCases = [
|
||||
let uiEventTestCases = [
|
||||
{title: 'Bubble open', class: Blockly.Events.BubbleOpen,
|
||||
getArgs: (thisObj) => [thisObj.block, true, 'mutator'],
|
||||
getExpectedJson: (thisObj) => ({type: 'bubble_open', isOpen: true,
|
||||
@@ -438,7 +438,7 @@ suite('Events', function() {
|
||||
getExpectedJson: () => ({type: 'viewport_change', viewTop: 0,
|
||||
viewLeft: 0, scale: 1.2, oldScale: 1})},
|
||||
];
|
||||
var blockEventTestCases = [
|
||||
let blockEventTestCases = [
|
||||
{
|
||||
title: 'Block change',
|
||||
class: Blockly.Events.BlockChange,
|
||||
@@ -552,13 +552,13 @@ suite('Events', function() {
|
||||
})
|
||||
},
|
||||
];
|
||||
var workspaceEventTestCases = [
|
||||
let workspaceEventTestCases = [
|
||||
{title: 'Finished Loading', class: Blockly.Events.FinishedLoading,
|
||||
getArgs: (thisObj) => [thisObj.workspace],
|
||||
getExpectedJson: (thisObj) => ({type: 'finished_loading',
|
||||
workspaceId: thisObj.workspace.id})},
|
||||
];
|
||||
var workspaceCommentEventTestCases = [
|
||||
let workspaceCommentEventTestCases = [
|
||||
{title: 'Comment change', class: Blockly.Events.CommentChange,
|
||||
getArgs: (thisObj) => [thisObj.comment, 'bar', 'foo'],
|
||||
getExpectedJson: (thisObj) => ({type: 'comment_change',
|
||||
@@ -579,7 +579,7 @@ suite('Events', function() {
|
||||
getExpectedJson: (thisObj) => ({type: 'comment_move',
|
||||
commentId: thisObj.comment.id, oldCoordinate: '0,0'})},
|
||||
];
|
||||
var testSuites = [
|
||||
let testSuites = [
|
||||
{title: 'Variable events', testCases: variableEventTestCases,
|
||||
setup: (thisObj) => {
|
||||
thisObj.variable =
|
||||
@@ -614,9 +614,9 @@ suite('Events', function() {
|
||||
suite('fromJson', function() {
|
||||
testSuite.testCases.forEach((testCase) => {
|
||||
test(testCase.title, function() {
|
||||
var event = new testCase.class(...testCase.getArgs(this));
|
||||
var event2 = new testCase.class();
|
||||
var json = event.toJson();
|
||||
let event = new testCase.class(...testCase.getArgs(this));
|
||||
let event2 = new testCase.class();
|
||||
let json = event.toJson();
|
||||
event2.fromJson(json);
|
||||
|
||||
chai.assert.equal(
|
||||
@@ -628,9 +628,9 @@ suite('Events', function() {
|
||||
testSuite.testCases.forEach((testCase) => {
|
||||
if (testCase.getExpectedJson) {
|
||||
test(testCase.title, function() {
|
||||
var event = new testCase.class(...testCase.getArgs(this));
|
||||
var json = event.toJson();
|
||||
var expectedJson = testCase.getExpectedJson(this);
|
||||
let event = new testCase.class(...testCase.getArgs(this));
|
||||
let json = event.toJson();
|
||||
let expectedJson = testCase.getExpectedJson(this);
|
||||
|
||||
chai.assert.equal(
|
||||
safeStringify(json), safeStringify(expectedJson));
|
||||
@@ -656,7 +656,7 @@ suite('Events', function() {
|
||||
* @param {!string} id The expected id of the variable.
|
||||
*/
|
||||
function checkVariableValues(container, name, type, id) {
|
||||
var variable = container.getVariableById(id);
|
||||
let variable = container.getVariableById(id);
|
||||
chai.assert.isDefined(variable);
|
||||
chai.assert.equal(name, variable.name);
|
||||
chai.assert.equal(type, variable.type);
|
||||
@@ -665,7 +665,7 @@ suite('Events', function() {
|
||||
|
||||
suite('Constructors', function() {
|
||||
test('Var base', function() {
|
||||
var event = new Blockly.Events.VarBase(this.variable);
|
||||
let event = new Blockly.Events.VarBase(this.variable);
|
||||
assertEventEquals(event, undefined, this.workspace.id, undefined, {
|
||||
'varId': 'id1',
|
||||
'recordUndo': true,
|
||||
@@ -674,7 +674,7 @@ suite('Events', function() {
|
||||
});
|
||||
|
||||
test('Var create', function() {
|
||||
var event = new Blockly.Events.VarCreate(this.variable);
|
||||
let event = new Blockly.Events.VarCreate(this.variable);
|
||||
assertEventEquals(event, Blockly.Events.VAR_CREATE, this.workspace.id,
|
||||
undefined,
|
||||
{
|
||||
@@ -687,7 +687,7 @@ suite('Events', function() {
|
||||
});
|
||||
|
||||
test('Var delete', function() {
|
||||
var event = new Blockly.Events.VarDelete(this.variable);
|
||||
let event = new Blockly.Events.VarDelete(this.variable);
|
||||
assertEventEquals(event, Blockly.Events.VAR_DELETE, this.workspace.id,
|
||||
undefined,
|
||||
{
|
||||
@@ -700,7 +700,7 @@ suite('Events', function() {
|
||||
});
|
||||
|
||||
test('Var rename', function() {
|
||||
var event = new Blockly.Events.VarRename(this.variable, 'name2');
|
||||
let event = new Blockly.Events.VarRename(this.variable, 'name2');
|
||||
assertEventEquals(event, Blockly.Events.VAR_RENAME, this.workspace.id,
|
||||
undefined,
|
||||
{
|
||||
@@ -715,24 +715,24 @@ suite('Events', function() {
|
||||
|
||||
suite('Run Forward', function() {
|
||||
test('Var create', function() {
|
||||
var json = {type: "var_create", varId: "id2", varType: "type2",
|
||||
let json = {type: "var_create", varId: "id2", varType: "type2",
|
||||
varName: "name2"};
|
||||
var event = eventUtils.fromJson(json, this.workspace);
|
||||
var x = this.workspace.getVariableById('id2');
|
||||
let event = eventUtils.fromJson(json, this.workspace);
|
||||
let x = this.workspace.getVariableById('id2');
|
||||
chai.assert.isNull(x);
|
||||
event.run(true);
|
||||
assertVariableValues(this.workspace, 'name2', 'type2', 'id2');
|
||||
});
|
||||
|
||||
test('Var delete', function() {
|
||||
var event = new Blockly.Events.VarDelete(this.variable);
|
||||
let event = new Blockly.Events.VarDelete(this.variable);
|
||||
chai.assert.isNotNull(this.workspace.getVariableById('id1'));
|
||||
event.run(true);
|
||||
chai.assert.isNull(this.workspace.getVariableById('id1'));
|
||||
});
|
||||
|
||||
test('Var rename', function() {
|
||||
var event = new Blockly.Events.VarRename(this.variable, 'name2');
|
||||
let event = new Blockly.Events.VarRename(this.variable, 'name2');
|
||||
event.run(true);
|
||||
chai.assert.isNull(this.workspace.getVariable('name1'));
|
||||
checkVariableValues(this.workspace, 'name2', 'type1', 'id1');
|
||||
@@ -740,22 +740,22 @@ suite('Events', function() {
|
||||
});
|
||||
suite('Run Backward', function() {
|
||||
test('Var create', function() {
|
||||
var event = new Blockly.Events.VarCreate(this.variable);
|
||||
let event = new Blockly.Events.VarCreate(this.variable);
|
||||
chai.assert.isNotNull(this.workspace.getVariableById('id1'));
|
||||
event.run(false);
|
||||
});
|
||||
|
||||
test('Var delete', function() {
|
||||
var json = {type: "var_delete", varId: "id2", varType: "type2",
|
||||
let json = {type: "var_delete", varId: "id2", varType: "type2",
|
||||
varName: "name2"};
|
||||
var event = eventUtils.fromJson(json, this.workspace);
|
||||
let event = eventUtils.fromJson(json, this.workspace);
|
||||
chai.assert.isNull(this.workspace.getVariableById('id2'));
|
||||
event.run(false);
|
||||
assertVariableValues(this.workspace, 'name2', 'type2', 'id2');
|
||||
});
|
||||
|
||||
test('Var rename', function() {
|
||||
var event = new Blockly.Events.VarRename(this.variable, 'name2');
|
||||
let event = new Blockly.Events.VarRename(this.variable, 'name2');
|
||||
event.run(false);
|
||||
chai.assert.isNull(this.workspace.getVariable('name2'));
|
||||
checkVariableValues(this.workspace, 'name1', 'type1', 'id1');
|
||||
@@ -777,14 +777,14 @@ suite('Events', function() {
|
||||
}
|
||||
|
||||
test('No removed, order unchanged', function() {
|
||||
var block = this.workspace.newBlock('field_variable_test_block', '1');
|
||||
var events = [
|
||||
let block = this.workspace.newBlock('field_variable_test_block', '1');
|
||||
let events = [
|
||||
new Blockly.Events.BlockCreate(block),
|
||||
new Blockly.Events.BlockMove(block),
|
||||
new Blockly.Events.BlockChange(block, 'field', 'VAR', 'id1', 'id2'),
|
||||
new Blockly.Events.Click(block)
|
||||
];
|
||||
var filteredEvents = eventUtils.filter(events, true);
|
||||
let filteredEvents = eventUtils.filter(events, true);
|
||||
chai.assert.equal(filteredEvents.length, 4); // no event should have been removed.
|
||||
// test that the order hasn't changed
|
||||
chai.assert.isTrue(filteredEvents[0] instanceof Blockly.Events.BlockCreate);
|
||||
@@ -794,25 +794,25 @@ suite('Events', function() {
|
||||
});
|
||||
|
||||
test('Different blocks no removed', function() {
|
||||
var block1 = this.workspace.newBlock('field_variable_test_block', '1');
|
||||
var block2 = this.workspace.newBlock('field_variable_test_block', '2');
|
||||
var events = [
|
||||
let block1 = this.workspace.newBlock('field_variable_test_block', '1');
|
||||
let block2 = this.workspace.newBlock('field_variable_test_block', '2');
|
||||
let events = [
|
||||
new Blockly.Events.BlockCreate(block1),
|
||||
new Blockly.Events.BlockMove(block1),
|
||||
new Blockly.Events.BlockCreate(block2),
|
||||
new Blockly.Events.BlockMove(block2)
|
||||
];
|
||||
var filteredEvents = eventUtils.filter(events, true);
|
||||
let filteredEvents = eventUtils.filter(events, true);
|
||||
chai.assert.equal(filteredEvents.length, 4); // no event should have been removed.
|
||||
});
|
||||
|
||||
test('Forward', function() {
|
||||
var block = this.workspace.newBlock('field_variable_test_block', '1');
|
||||
var events = [ new Blockly.Events.BlockCreate(block) ];
|
||||
let block = this.workspace.newBlock('field_variable_test_block', '1');
|
||||
let events = [ new Blockly.Events.BlockCreate(block) ];
|
||||
addMoveEvent(events, block, 1, 1);
|
||||
addMoveEvent(events, block, 2, 2);
|
||||
addMoveEvent(events, block, 3, 3);
|
||||
var filteredEvents = eventUtils.filter(events, true);
|
||||
let filteredEvents = eventUtils.filter(events, true);
|
||||
chai.assert.equal(filteredEvents.length, 2); // duplicate moves should have been removed.
|
||||
// test that the order hasn't changed
|
||||
chai.assert.isTrue(filteredEvents[0] instanceof Blockly.Events.BlockCreate);
|
||||
@@ -822,12 +822,12 @@ suite('Events', function() {
|
||||
});
|
||||
|
||||
test('Backward', function() {
|
||||
var block = this.workspace.newBlock('field_variable_test_block', '1');
|
||||
var events = [ new Blockly.Events.BlockCreate(block) ];
|
||||
let block = this.workspace.newBlock('field_variable_test_block', '1');
|
||||
let events = [ new Blockly.Events.BlockCreate(block) ];
|
||||
addMoveEvent(events, block, 1, 1);
|
||||
addMoveEvent(events, block, 2, 2);
|
||||
addMoveEvent(events, block, 3, 3);
|
||||
var filteredEvents = eventUtils.filter(events, false);
|
||||
let filteredEvents = eventUtils.filter(events, false);
|
||||
chai.assert.equal(filteredEvents.length, 2); // duplicate event should have been removed.
|
||||
// test that the order hasn't changed
|
||||
chai.assert.isTrue(filteredEvents[0] instanceof Blockly.Events.BlockCreate);
|
||||
@@ -837,34 +837,34 @@ suite('Events', function() {
|
||||
});
|
||||
|
||||
test('Merge block move events', function() {
|
||||
var block = this.workspace.newBlock('field_variable_test_block', '1');
|
||||
var events = [];
|
||||
let block = this.workspace.newBlock('field_variable_test_block', '1');
|
||||
let events = [];
|
||||
addMoveEvent(events, block, 0, 0);
|
||||
addMoveEvent(events, block, 1, 1);
|
||||
var filteredEvents = eventUtils.filter(events, true);
|
||||
let filteredEvents = eventUtils.filter(events, true);
|
||||
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.y, 1);
|
||||
});
|
||||
|
||||
test('Merge block change events', function() {
|
||||
var block1 = this.workspace.newBlock('field_variable_test_block', '1');
|
||||
var events = [
|
||||
let block1 = this.workspace.newBlock('field_variable_test_block', '1');
|
||||
let events = [
|
||||
new Blockly.Events.BlockChange(block1, 'field', 'VAR', 'item', 'item1'),
|
||||
new Blockly.Events.BlockChange(block1, 'field', 'VAR', 'item1', 'item2')
|
||||
];
|
||||
var filteredEvents = eventUtils.filter(events, true);
|
||||
let filteredEvents = eventUtils.filter(events, true);
|
||||
chai.assert.equal(filteredEvents.length, 1); // second change event merged into first
|
||||
chai.assert.equal(filteredEvents[0].oldValue, 'item');
|
||||
chai.assert.equal(filteredEvents[0].newValue, 'item2');
|
||||
});
|
||||
|
||||
test('Merge viewport change events', function() {
|
||||
var events = [
|
||||
let events = [
|
||||
new Blockly.Events.ViewportChange(1, 2, 3, this.workspace, 4),
|
||||
new Blockly.Events.ViewportChange(5, 6, 7, this.workspace, 8)
|
||||
];
|
||||
var filteredEvents = eventUtils.filter(events, true);
|
||||
let filteredEvents = eventUtils.filter(events, true);
|
||||
chai.assert.equal(filteredEvents.length, 1); // second change event merged into first
|
||||
chai.assert.equal(filteredEvents[0].viewTop, 5);
|
||||
chai.assert.equal(filteredEvents[0].viewLeft, 6);
|
||||
@@ -873,10 +873,10 @@ suite('Events', function() {
|
||||
});
|
||||
|
||||
test('Merge ui events', function() {
|
||||
var block1 = this.workspace.newBlock('field_variable_test_block', '1');
|
||||
var block2 = this.workspace.newBlock('field_variable_test_block', '2');
|
||||
var block3 = this.workspace.newBlock('field_variable_test_block', '3');
|
||||
var events = [
|
||||
let block1 = this.workspace.newBlock('field_variable_test_block', '1');
|
||||
let block2 = this.workspace.newBlock('field_variable_test_block', '2');
|
||||
let block3 = this.workspace.newBlock('field_variable_test_block', '3');
|
||||
let events = [
|
||||
new Blockly.Events.BubbleOpen(block1, true, 'comment'),
|
||||
new Blockly.Events.Click(block1),
|
||||
new Blockly.Events.BubbleOpen(block2, true, 'mutator'),
|
||||
@@ -884,7 +884,7 @@ suite('Events', function() {
|
||||
new Blockly.Events.BubbleOpen(block3, true, 'warning'),
|
||||
new Blockly.Events.Click(block3)
|
||||
];
|
||||
var filteredEvents = eventUtils.filter(events, true);
|
||||
let filteredEvents = eventUtils.filter(events, true);
|
||||
// click event merged into corresponding *Open event
|
||||
chai.assert.equal(filteredEvents.length, 3);
|
||||
chai.assert.isTrue(filteredEvents[0] instanceof Blockly.Events.BubbleOpen);
|
||||
@@ -898,12 +898,12 @@ suite('Events', function() {
|
||||
test('Colliding events not dropped', function() {
|
||||
// Tests that events that collide on a (event, block, workspace) tuple
|
||||
// but cannot be merged do not get dropped during filtering.
|
||||
var block = this.workspace.newBlock('field_variable_test_block', '1');
|
||||
var events = [
|
||||
let block = this.workspace.newBlock('field_variable_test_block', '1');
|
||||
let events = [
|
||||
new Blockly.Events.Click(block),
|
||||
new Blockly.Events.Ui(block, 'stackclick', undefined, undefined)
|
||||
];
|
||||
var filteredEvents = eventUtils.filter(events, true);
|
||||
let filteredEvents = eventUtils.filter(events, true);
|
||||
// click and stackclick should both exist
|
||||
chai.assert.equal(filteredEvents.length, 2);
|
||||
chai.assert.isTrue(filteredEvents[0] instanceof Blockly.Events.Click);
|
||||
@@ -918,12 +918,12 @@ suite('Events', function() {
|
||||
// that two move events that do get merged (disconnecting and
|
||||
// reconnecting a block in response to a mutator change) are filtered
|
||||
// from the queue.
|
||||
var block = this.workspace.newBlock('field_variable_test_block', '1');
|
||||
let block = this.workspace.newBlock('field_variable_test_block', '1');
|
||||
block.setParent(null);
|
||||
var events = [];
|
||||
let events = [];
|
||||
addMoveEventParent(events, block, null);
|
||||
addMoveEventParent(events, block, null);
|
||||
var filteredEvents = eventUtils.filter(events, true);
|
||||
let filteredEvents = eventUtils.filter(events, true);
|
||||
// The two events should be merged, but because nothing has changed
|
||||
// they will be filtered out.
|
||||
chai.assert.equal(filteredEvents.length, 0);
|
||||
@@ -935,16 +935,16 @@ suite('Events', function() {
|
||||
// See github.com/google/blockly/pull/1892 for a worked example showing
|
||||
// how merging non-consecutive events can fail when replacing a shadow
|
||||
// block.
|
||||
var block1 = createSimpleTestBlock(this.workspace);
|
||||
var block2 = createSimpleTestBlock(this.workspace);
|
||||
let block1 = createSimpleTestBlock(this.workspace);
|
||||
let block2 = createSimpleTestBlock(this.workspace);
|
||||
|
||||
var events = [];
|
||||
let events = [];
|
||||
addMoveEvent(events, block1, 1, 1);
|
||||
addMoveEvent(events, block2, 1, 1);
|
||||
events.push(new Blockly.Events.BlockDelete(block2));
|
||||
addMoveEvent(events, block1, 2, 2);
|
||||
|
||||
var filteredEvents = eventUtils.filter(events, true);
|
||||
let filteredEvents = eventUtils.filter(events, true);
|
||||
// Nothing should have merged.
|
||||
chai.assert.equal(filteredEvents.length, 4);
|
||||
// test that the order hasn't changed
|
||||
@@ -962,23 +962,23 @@ suite('Events', function() {
|
||||
|
||||
test('Block dispose triggers Delete', function() {
|
||||
try {
|
||||
var toolbox = document.getElementById('toolbox-categories');
|
||||
let toolbox = document.getElementById('toolbox-categories');
|
||||
var workspaceSvg = Blockly.inject('blocklyDiv', {toolbox: toolbox});
|
||||
var TEST_BLOCK_ID = 'test_block_id';
|
||||
var genUidStub = createGenUidStubWithReturns(
|
||||
let TEST_BLOCK_ID = 'test_block_id';
|
||||
let genUidStub = createGenUidStubWithReturns(
|
||||
[TEST_BLOCK_ID, 'test_group_id']);
|
||||
|
||||
var block = workspaceSvg.newBlock('');
|
||||
let block = workspaceSvg.newBlock('');
|
||||
block.initSvg();
|
||||
block.setCommentText('test comment');
|
||||
var expectedOldXml = Blockly.Xml.blockToDomWithXY(block);
|
||||
var expectedId = block.id;
|
||||
let expectedOldXml = Blockly.Xml.blockToDomWithXY(block);
|
||||
let expectedId = block.id;
|
||||
|
||||
// Run all queued events.
|
||||
this.clock.runAll();
|
||||
|
||||
this.eventsFireSpy.resetHistory();
|
||||
var changeListenerSpy = createFireChangeListenerSpy(workspaceSvg);
|
||||
let changeListenerSpy = createFireChangeListenerSpy(workspaceSvg);
|
||||
block.dispose();
|
||||
|
||||
// Run all queued events.
|
||||
@@ -1005,13 +1005,13 @@ suite('Events', function() {
|
||||
});
|
||||
|
||||
test('New block new var', function() {
|
||||
var TEST_BLOCK_ID = 'test_block_id';
|
||||
var TEST_GROUP_ID = 'test_group_id';
|
||||
var TEST_VAR_ID = 'test_var_id';
|
||||
var genUidStub = createGenUidStubWithReturns(
|
||||
let TEST_BLOCK_ID = 'test_block_id';
|
||||
let TEST_GROUP_ID = 'test_group_id';
|
||||
let TEST_VAR_ID = 'test_var_id';
|
||||
let genUidStub = createGenUidStubWithReturns(
|
||||
[TEST_BLOCK_ID, TEST_GROUP_ID, TEST_VAR_ID]);
|
||||
var _ = this.workspace.newBlock('field_variable_test_block');
|
||||
var TEST_VAR_NAME = 'item'; // As defined in block's json.
|
||||
let _ = this.workspace.newBlock('field_variable_test_block');
|
||||
let TEST_VAR_NAME = 'item'; // As defined in block's json.
|
||||
|
||||
// Run all queued events.
|
||||
this.clock.runAll();
|
||||
@@ -1041,18 +1041,18 @@ suite('Events', function() {
|
||||
});
|
||||
|
||||
test('New block new var xml', function() {
|
||||
var TEST_GROUP_ID = 'test_group_id';
|
||||
var genUidStub = createGenUidStubWithReturns(TEST_GROUP_ID);
|
||||
var dom = Blockly.Xml.textToDom(
|
||||
let TEST_GROUP_ID = 'test_group_id';
|
||||
let genUidStub = createGenUidStubWithReturns(TEST_GROUP_ID);
|
||||
let dom = Blockly.Xml.textToDom(
|
||||
'<xml xmlns="https://developers.google.com/blockly/xml">' +
|
||||
' <block type="field_variable_test_block" id="test_block_id">' +
|
||||
' <field name="VAR" id="test_var_id">name1</field>' +
|
||||
' </block>' +
|
||||
'</xml>');
|
||||
Blockly.Xml.domToWorkspace(dom, this.workspace);
|
||||
var TEST_BLOCK_ID = 'test_block_id';
|
||||
var TEST_VAR_ID = 'test_var_id';
|
||||
var TEST_VAR_NAME = 'name1';
|
||||
let TEST_BLOCK_ID = 'test_block_id';
|
||||
let TEST_VAR_ID = 'test_var_id';
|
||||
let TEST_VAR_NAME = 'name1';
|
||||
|
||||
// Run all queued events.
|
||||
this.clock.runAll();
|
||||
@@ -1093,7 +1093,7 @@ suite('Events', function() {
|
||||
suite('Disable orphans', function() {
|
||||
setup(function() {
|
||||
// disableOrphans needs a WorkspaceSVG
|
||||
var toolbox = document.getElementById('toolbox-categories');
|
||||
let toolbox = document.getElementById('toolbox-categories');
|
||||
this.workspace = Blockly.inject('blocklyDiv', {toolbox: toolbox});
|
||||
});
|
||||
teardown(function() {
|
||||
@@ -1101,7 +1101,7 @@ suite('Events', function() {
|
||||
});
|
||||
test('Created orphan block is disabled', function() {
|
||||
this.workspace.addChangeListener(eventUtils.disableOrphans);
|
||||
var block = this.workspace.newBlock('controls_for');
|
||||
let block = this.workspace.newBlock('controls_for');
|
||||
block.initSvg();
|
||||
block.render();
|
||||
|
||||
@@ -1115,7 +1115,7 @@ suite('Events', function() {
|
||||
this.workspace.addChangeListener(eventUtils.disableOrphans);
|
||||
|
||||
// Procedure block is never an orphan
|
||||
var functionBlock = this.workspace.newBlock('procedures_defnoreturn');
|
||||
let functionBlock = this.workspace.newBlock('procedures_defnoreturn');
|
||||
functionBlock.initSvg();
|
||||
functionBlock.render();
|
||||
|
||||
@@ -1127,11 +1127,11 @@ suite('Events', function() {
|
||||
});
|
||||
test('Moving a block to top-level disables it', function() {
|
||||
this.workspace.addChangeListener(eventUtils.disableOrphans);
|
||||
var functionBlock = this.workspace.newBlock('procedures_defnoreturn');
|
||||
let functionBlock = this.workspace.newBlock('procedures_defnoreturn');
|
||||
functionBlock.initSvg();
|
||||
functionBlock.render();
|
||||
|
||||
var block = this.workspace.newBlock('controls_for');
|
||||
let block = this.workspace.newBlock('controls_for');
|
||||
block.initSvg();
|
||||
block.render();
|
||||
|
||||
@@ -1149,11 +1149,11 @@ suite('Events', function() {
|
||||
});
|
||||
test('Giving block a parent enables it', function() {
|
||||
this.workspace.addChangeListener(eventUtils.disableOrphans);
|
||||
var functionBlock = this.workspace.newBlock('procedures_defnoreturn');
|
||||
let functionBlock = this.workspace.newBlock('procedures_defnoreturn');
|
||||
functionBlock.initSvg();
|
||||
functionBlock.render();
|
||||
|
||||
var block = this.workspace.newBlock('controls_for');
|
||||
let block = this.workspace.newBlock('controls_for');
|
||||
block.initSvg();
|
||||
block.render();
|
||||
|
||||
@@ -1168,11 +1168,11 @@ suite('Events', function() {
|
||||
});
|
||||
test('disableOrphans events are not undoable', function() {
|
||||
this.workspace.addChangeListener(eventUtils.disableOrphans);
|
||||
var functionBlock = this.workspace.newBlock('procedures_defnoreturn');
|
||||
let functionBlock = this.workspace.newBlock('procedures_defnoreturn');
|
||||
functionBlock.initSvg();
|
||||
functionBlock.render();
|
||||
|
||||
var block = this.workspace.newBlock('controls_for');
|
||||
let block = this.workspace.newBlock('controls_for');
|
||||
block.initSvg();
|
||||
block.render();
|
||||
|
||||
@@ -1185,7 +1185,7 @@ suite('Events', function() {
|
||||
// Fire all events
|
||||
this.clock.runAll();
|
||||
|
||||
var disabledEvents = this.workspace.getUndoStack().filter(function(e) {
|
||||
let disabledEvents = this.workspace.getUndoStack().filter(function(e) {
|
||||
return e.element === 'disabled';
|
||||
});
|
||||
chai.assert.isEmpty(disabledEvents,
|
||||
|
||||
Reference in New Issue
Block a user