Files
blockly/tests/mocha/mutator_test.js
Beka Westberg 96758fedd4 chore: convert mocha tests and test helpers to esmodules (#6333)
* chore: change goog.module to goog.declareModuleId

* chore: change test helper exports to esmod exports

* chore: change test helpers to use esmodule imports

* chore: convert imports of test helpers to esmodule imports

* chore: convert other imports in tests to esm imports

* fix: make imports use built files

* chore: add blockly imports to a bunch of tests

* fix: reference Blockly.Blocks instead of Blocks'

* fix: properly import generators

* chore: fix lint

* chore: cleanup from rebase

* chore: cleanup from rebase

* chore: fix blocks tests
2022-08-10 14:54:02 -07:00

73 lines
2.4 KiB
JavaScript

/**
* @license
* Copyright 2021 Google LLC
* SPDX-License-Identifier: Apache-2.0
*/
goog.declareModuleId('Blockly.test.mutator');
import {sharedTestSetup, sharedTestTeardown} from './test_helpers/setup_teardown.js';
import {createRenderedBlock, defineMutatorBlocks} from './test_helpers/block_definitions.js';
suite('Mutator', function() {
setup(function() {
sharedTestSetup.call(this);
});
suite('Firing change event', function() {
setup(function() {
this.workspace = Blockly.inject('blocklyDiv', {});
defineMutatorBlocks();
});
teardown(function() {
Blockly.Extensions.unregister('xml_mutator');
Blockly.Extensions.unregister('jso_mutator');
sharedTestTeardown.call(this);
});
test('No change', function() {
const block = createRenderedBlock(this.workspace, 'xml_block');
block.mutator.setVisible(true);
const mutatorWorkspace = block.mutator.getWorkspace();
// Trigger mutator change listener.
createRenderedBlock(mutatorWorkspace, 'checkbox_block');
chai.assert.isTrue(
this.eventsFireStub.getCalls().every(
({args}) =>
args[0].type !== Blockly.Events.BLOCK_CHANGE ||
args[0].element !== 'mutation'));
});
test('XML', function() {
const block = createRenderedBlock(this.workspace, 'xml_block');
block.mutator.setVisible(true);
const mutatorWorkspace = block.mutator.getWorkspace();
mutatorWorkspace.getBlockById('check_block')
.setFieldValue('TRUE', 'CHECK');
chai.assert.isTrue(
this.eventsFireStub.getCalls().some(
({args}) =>
args[0].type === Blockly.Events.BLOCK_CHANGE &&
args[0].element === 'mutation' &&
/<mutation.*><\/mutation>/.test(args[0].newValue)));
});
test('JSO', function() {
const block = createRenderedBlock(this.workspace, 'jso_block');
block.mutator.setVisible(true);
const mutatorWorkspace = block.mutator.getWorkspace();
mutatorWorkspace.getBlockById('check_block')
.setFieldValue('TRUE', 'CHECK');
chai.assert.isTrue(
this.eventsFireStub.getCalls().some(
({args}) =>
args[0].type === Blockly.Events.BLOCK_CHANGE &&
args[0].element === 'mutation' &&
args[0].newValue === '{"hasInput":true}'));
});
});
});