Files
blockly/tests/mocha/block_create_event_test.js
Beka Westberg 2edd228117 fix: move test helpers from samples into core (#5969)
* fix: move core test helpers into new directory

* fix: add test helpers to core and convert to goog modules

* fix: change tests to use local helpers

* fix: change local tests to use chai asserts

* fix: skip field tests in serializer b/c test blocks are unavailable

* fix: rename some helper files

* fix: rename some helper modules

* fix: split block helpers into code gen and serialization

* fix: split block defs into new helper file

* fix: split warning helpers into new file

* fix: split user input helpers into new file

* fix: split event helpers into a new file

* fix: split variable helper into new file

* fix: move remaining test helpers to new setup-teardown file

* fix: rename setup and teardown module

* fix: cleanup from rebase

* fix: undo accidental rename

* fix: lint?

* fix: bad toolbox definitions namespace

* fix: fixup warning helpers

* fix: remove inclusion of dev-tools in mocha tests

* move to modules, but break mocha

* fix: run mocha as a module

* fix: lint
2022-03-04 13:10:03 -08:00

61 lines
1.6 KiB
JavaScript

/**
* @license
* Copyright 2021 Google LLC
* SPDX-License-Identifier: Apache-2.0
*/
goog.module('Blockly.test.blockCreateEvent');
const {assertEventFired} = goog.require('Blockly.test.helpers.events');
const eventUtils = goog.require('Blockly.Events.utils');
const {sharedTestSetup, sharedTestTeardown} = goog.require('Blockly.test.helpers.setupTeardown');
suite('Block Create Event', function() {
setup(function() {
sharedTestSetup.call(this);
this.workspace = new Blockly.Workspace();
});
teardown(function() {
sharedTestTeardown.call(this);
});
test('Create shadow on disconnect', function() {
Blockly.Events.disable();
const block = Blockly.serialization.blocks.append(
{
"type": "text_print",
"inputs": {
"TEXT": {
"shadow": {
"type": "text",
"id": "shadowId",
"fields": {
"TEXT": "abc",
},
},
"block": {
"type": "text",
"fields": {
"TEXT": "",
},
},
},
},
},
this.workspace);
Blockly.Events.enable();
block.getInput('TEXT').connection.disconnect();
assertEventFired(
this.eventsFireStub,
Blockly.Events.BlockCreate,
{'recordUndo': false, 'type': eventUtils.BLOCK_CREATE},
this.workspace.id,
'shadowId');
const calls = this.eventsFireStub.getCalls();
const event = calls[calls.length - 1].args[0];
chai.assert.equal(event.xml.tagName, 'shadow');
});
});