mirror of
https://github.com/google/blockly.git
synced 2026-01-10 02:17:09 +01:00
Merge branch 'develop' into ensure-immovable-blocks-are-considered-during-workspace-tidying
This commit is contained in:
@@ -47,7 +47,7 @@ window['healthCheck'] = function() {
|
||||
const blockCount =
|
||||
getMainWorkspace().getFlyout().getWorkspace().getTopBlocks().length;
|
||||
return (blockCount > 5 && blockCount < 100);
|
||||
} catch (_e) {
|
||||
} catch {
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
import * as common from '../../build/src/core/common.js';
|
||||
import {ConnectionType} from '../../build/src/core/connection_type.js';
|
||||
import {EventType} from '../../build/src/core/events/type.js';
|
||||
import * as eventUtils from '../../build/src/core/events/utils.js';
|
||||
@@ -444,6 +445,39 @@ suite('Blocks', function () {
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
suite('Disposing selected shadow block', function () {
|
||||
setup(function () {
|
||||
this.workspace = Blockly.inject('blocklyDiv');
|
||||
this.parentBlock = this.workspace.newBlock('row_block');
|
||||
this.parentBlock.initSvg();
|
||||
this.parentBlock.render();
|
||||
this.parentBlock.inputList[0].connection.setShadowState({
|
||||
'type': 'row_block',
|
||||
'id': 'shadow_child',
|
||||
});
|
||||
this.shadowChild =
|
||||
this.parentBlock.inputList[0].connection.targetConnection.getSourceBlock();
|
||||
});
|
||||
|
||||
teardown(function () {
|
||||
workspaceTeardown.call(this, this.workspace);
|
||||
});
|
||||
|
||||
test('Disposing selected shadow unhighlights parent', function () {
|
||||
const parentBlock = this.parentBlock;
|
||||
common.setSelected(this.shadowChild);
|
||||
assert.isTrue(
|
||||
parentBlock.pathObject.svgRoot.classList.contains('blocklySelected'),
|
||||
'Expected parent to be highlighted after selecting shadow child',
|
||||
);
|
||||
this.shadowChild.dispose();
|
||||
assert.isFalse(
|
||||
parentBlock.pathObject.svgRoot.classList.contains('blocklySelected'),
|
||||
'Expected parent to be unhighlighted after deleting shadow child',
|
||||
);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
suite('Remove Input', function () {
|
||||
|
||||
@@ -42,6 +42,26 @@ suite('Events', function () {
|
||||
'type': 'simple_test_block',
|
||||
'message0': 'simple test block',
|
||||
},
|
||||
{
|
||||
'type': 'inputs_test_block',
|
||||
'message0': 'first %1 second %2',
|
||||
'args0': [
|
||||
{
|
||||
'type': 'input_statement',
|
||||
'name': 'STATEMENT1',
|
||||
},
|
||||
{
|
||||
'type': 'input_statement',
|
||||
'name': 'STATEMENT2',
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
'type': 'statement_test_block',
|
||||
'message0': '',
|
||||
'previousStatement': null,
|
||||
'nextStatement': null,
|
||||
},
|
||||
]);
|
||||
});
|
||||
|
||||
@@ -1102,6 +1122,165 @@ suite('Events', function () {
|
||||
});
|
||||
});
|
||||
|
||||
suite('enqueueEvent', function () {
|
||||
const {FIRE_QUEUE, enqueueEvent} = eventUtils.TEST_ONLY;
|
||||
|
||||
function newDisconnectEvent(parent, child, inputName, workspaceId) {
|
||||
const event = new Blockly.Events.BlockMove(child);
|
||||
event.workspaceId = workspaceId;
|
||||
event.oldParentId = parent.id;
|
||||
event.oldInputName = inputName;
|
||||
event.oldCoordinate = undefined;
|
||||
event.newParentId = undefined;
|
||||
event.newInputName = undefined;
|
||||
event.newCoordinate = new Blockly.utils.Coordinate(0, 0);
|
||||
return event;
|
||||
}
|
||||
|
||||
function newConnectEvent(parent, child, inputName, workspaceId) {
|
||||
const event = new Blockly.Events.BlockMove(child);
|
||||
event.workspaceId = workspaceId;
|
||||
event.oldParentId = undefined;
|
||||
event.oldInputName = undefined;
|
||||
event.oldCoordinate = new Blockly.utils.Coordinate(0, 0);
|
||||
event.newParentId = parent.id;
|
||||
event.newInputName = inputName;
|
||||
event.newCoordinate = undefined;
|
||||
return event;
|
||||
}
|
||||
|
||||
function newMutationEvent(block, workspaceId) {
|
||||
const event = new Blockly.Events.BlockChange(block);
|
||||
event.workspaceId = workspaceId;
|
||||
event.element = 'mutation';
|
||||
return event;
|
||||
}
|
||||
|
||||
test('Events are enqueued', function () {
|
||||
// Disable events during block creation to avoid firing BlockCreate
|
||||
// events.
|
||||
eventUtils.disable();
|
||||
const block = this.workspace.newBlock('simple_test_block', '1');
|
||||
eventUtils.enable();
|
||||
|
||||
try {
|
||||
assert.equal(FIRE_QUEUE.length, 0);
|
||||
const events = [
|
||||
new Blockly.Events.BlockCreate(block),
|
||||
new Blockly.Events.BlockMove(block),
|
||||
new Blockly.Events.Click(block),
|
||||
];
|
||||
events.map((e) => enqueueEvent(e));
|
||||
assert.equal(FIRE_QUEUE.length, events.length, 'FIRE_QUEUE.length');
|
||||
for (let i = 0; i < events.length; i++) {
|
||||
assert.equal(FIRE_QUEUE[i], events[i], `FIRE_QUEUE[${i}]`);
|
||||
}
|
||||
} finally {
|
||||
FIRE_QUEUE.length = 0;
|
||||
}
|
||||
});
|
||||
|
||||
test('BlockChange event reordered', function () {
|
||||
eventUtils.disable();
|
||||
const parent = this.workspace.newBlock('inputs_test_block', 'parent');
|
||||
const child1 = this.workspace.newBlock('statement_test_block', 'child1');
|
||||
const child2 = this.workspace.newBlock('statement_test_block', 'child2');
|
||||
eventUtils.enable();
|
||||
|
||||
try {
|
||||
assert.equal(FIRE_QUEUE.length, 0);
|
||||
const events = [
|
||||
newDisconnectEvent(parent, child1, 'STATEMENT1'),
|
||||
newDisconnectEvent(parent, child2, 'STATEMENT2'),
|
||||
newConnectEvent(parent, child1, 'STATEMENT1'),
|
||||
newConnectEvent(parent, child2, 'STATEMENT2'),
|
||||
newMutationEvent(parent),
|
||||
];
|
||||
events.map((e) => enqueueEvent(e));
|
||||
assert.equal(FIRE_QUEUE.length, events.length, 'FIRE_QUEUE.length');
|
||||
assert.equal(FIRE_QUEUE[0], events[0], 'FIRE_QUEUE[0]');
|
||||
assert.equal(FIRE_QUEUE[1], events[1], 'FIRE_QUEUE[1]');
|
||||
assert.equal(FIRE_QUEUE[2], events[4], 'FIRE_QUEUE[2]');
|
||||
assert.equal(FIRE_QUEUE[3], events[2], 'FIRE_QUEUE[3]');
|
||||
assert.equal(FIRE_QUEUE[4], events[3], 'FIRE_QUEUE[4]');
|
||||
} finally {
|
||||
FIRE_QUEUE.length = 0;
|
||||
}
|
||||
});
|
||||
|
||||
test('BlockChange event for other workspace not reordered', function () {
|
||||
eventUtils.disable();
|
||||
const parent = this.workspace.newBlock('inputs_test_block', 'parent');
|
||||
const child = this.workspace.newBlock('statement_test_block', 'child');
|
||||
eventUtils.enable();
|
||||
|
||||
try {
|
||||
assert.equal(FIRE_QUEUE.length, 0);
|
||||
const events = [
|
||||
newDisconnectEvent(parent, child, 'STATEMENT1', 'ws1'),
|
||||
newConnectEvent(parent, child, 'STATEMENT1', 'ws1'),
|
||||
newMutationEvent(parent, 'ws2'),
|
||||
];
|
||||
events.map((e) => enqueueEvent(e));
|
||||
assert.equal(FIRE_QUEUE.length, events.length, 'FIRE_QUEUE.length');
|
||||
for (let i = 0; i < events.length; i++) {
|
||||
assert.equal(FIRE_QUEUE[i], events[i], `FIRE_QUEUE[${i}]`);
|
||||
}
|
||||
} finally {
|
||||
FIRE_QUEUE.length = 0;
|
||||
}
|
||||
});
|
||||
|
||||
test('BlockChange event for other group not reordered', function () {
|
||||
eventUtils.disable();
|
||||
const parent = this.workspace.newBlock('inputs_test_block', 'parent');
|
||||
const child = this.workspace.newBlock('statement_test_block', 'child');
|
||||
eventUtils.enable();
|
||||
|
||||
try {
|
||||
assert.equal(FIRE_QUEUE.length, 0);
|
||||
const events = [];
|
||||
eventUtils.setGroup('group1');
|
||||
events.push(newDisconnectEvent(parent, child, 'STATEMENT1'));
|
||||
events.push(newConnectEvent(parent, child, 'STATEMENT1'));
|
||||
eventUtils.setGroup('group2');
|
||||
events.push(newMutationEvent(parent, 'ws2'));
|
||||
events.map((e) => enqueueEvent(e));
|
||||
assert.equal(FIRE_QUEUE.length, events.length, 'FIRE_QUEUE.length');
|
||||
for (let i = 0; i < events.length; i++) {
|
||||
assert.equal(FIRE_QUEUE[i], events[i], `FIRE_QUEUE[${i}]`);
|
||||
}
|
||||
} finally {
|
||||
FIRE_QUEUE.length = 0;
|
||||
eventUtils.setGroup(false);
|
||||
}
|
||||
});
|
||||
|
||||
test('BlockChange event for other parent not reordered', function () {
|
||||
eventUtils.disable();
|
||||
const parent1 = this.workspace.newBlock('inputs_test_block', 'parent1');
|
||||
const parent2 = this.workspace.newBlock('inputs_test_block', 'parent2');
|
||||
const child = this.workspace.newBlock('statement_test_block', 'child');
|
||||
eventUtils.enable();
|
||||
|
||||
try {
|
||||
assert.equal(FIRE_QUEUE.length, 0);
|
||||
const events = [
|
||||
newDisconnectEvent(parent1, child, 'STATEMENT1', 'ws1'),
|
||||
newConnectEvent(parent1, child, 'STATEMENT1', 'ws1'),
|
||||
newMutationEvent(parent2, 'ws2'),
|
||||
];
|
||||
events.map((e) => enqueueEvent(e));
|
||||
assert.equal(FIRE_QUEUE.length, events.length, 'FIRE_QUEUE.length');
|
||||
for (let i = 0; i < events.length; i++) {
|
||||
assert.equal(FIRE_QUEUE[i], events[i], `FIRE_QUEUE[${i}]`);
|
||||
}
|
||||
} finally {
|
||||
FIRE_QUEUE.length = 0;
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
suite('Filters', function () {
|
||||
function addMoveEvent(events, block, newX, newY) {
|
||||
events.push(new Blockly.Events.BlockMove(block));
|
||||
@@ -1566,9 +1745,9 @@ suite('Events', function () {
|
||||
// Fire all events
|
||||
this.clock.runAll();
|
||||
|
||||
const disabledEvents = this.workspace.getUndoStack().filter(function (e) {
|
||||
return e.element === 'disabled';
|
||||
});
|
||||
const disabledEvents = this.workspace
|
||||
.getUndoStack()
|
||||
.filter((e) => e.element === 'disabled');
|
||||
assert.isEmpty(
|
||||
disabledEvents,
|
||||
'Undo stack should not contain any disabled events',
|
||||
|
||||
Reference in New Issue
Block a user