fix: blocks not receiving their own delete events (#6655)

* fix: blocks not receiving their own delete events

* chore: unskip tests
This commit is contained in:
Beka Westberg
2022-11-29 08:39:21 -08:00
committed by GitHub
parent d5de2da2de
commit 485bd4dddf
3 changed files with 22 additions and 10 deletions

View File

@@ -12,7 +12,8 @@ import {sharedTestSetup, sharedTestTeardown} from './test_helpers/setup_teardown
suite('Block Delete Event', function() {
setup(function() {
sharedTestSetup.call(this);
const {clock} = sharedTestSetup.call(this, {fireEventsNow: false});
this.clock = clock;
defineRowBlock();
this.workspace = new Blockly.Workspace();
});
@@ -22,9 +23,9 @@ suite('Block Delete Event', function() {
});
suite('Receiving', function() {
test('blocks receive their own delete events', function() {
test('blocks receive their own delete events', function(done) {
Blockly.Blocks['test'] = {
onchange: function(e) {},
onchange: function(e) { },
};
// Need to stub the definition, because the property on the definition is
// what gets registered as an event listener.
@@ -32,10 +33,13 @@ suite('Block Delete Event', function() {
const testBlock = this.workspace.newBlock('test');
testBlock.dispose();
this.clock.tick(2); // Fire events. The built-in timeout is 0.
const deleteClass = eventUtils.get(eventUtils.BLOCK_DELETE);
chai.assert.isTrue(spy.calledOnce);
chai.assert.isTrue(spy.getCall(0).args[0] instanceof deleteClass);
chai.assert.isTrue(
spy.calledWith(sinon.match.instanceOf(deleteClass)),
'Expected the block to receive its own delete event.');
done();
});
});

View File

@@ -105,6 +105,8 @@ function wrapDefineBlocksWithJsonArrayWithCleanup_(sharedCleanupObj) {
*
* @param {Object<string, boolean>} options Options to enable/disable setup
* of certain stubs.
* @return {{clock: *}} The fake clock (as part of an object to make refactoring
* easier).
*/
export function sharedTestSetup(options = {}) {
this.sharedSetupCalled_ = true;
@@ -122,6 +124,9 @@ export function sharedTestSetup(options = {}) {
this.blockTypesCleanup_ = this.sharedCleanup.blockTypesCleanup_;
this.messagesCleanup_ = this.sharedCleanup.messagesCleanup_;
wrapDefineBlocksWithJsonArrayWithCleanup_(this.sharedCleanup);
return {
clock: this.clock,
};
}
/**