Files
blockly/tests/mocha/event_block_field_intermediate_change_test.js
truongductri01 96a354b46b feat: added intermediate event change (#7671)
* feat: added intermediate event change

* fix: update prettier format for the code

* fix: update comment style

* fix: update test statements
2023-12-04 13:10:09 -08:00

73 lines
1.8 KiB
JavaScript

/**
* @license
* Copyright 2023 Google LLC
* SPDX-License-Identifier: Apache-2.0
*/
import {
sharedTestSetup,
sharedTestTeardown,
} from './test_helpers/setup_teardown.js';
suite('Field Intermediate Change Event', function () {
setup(function () {
sharedTestSetup.call(this);
this.workspace = new Blockly.Workspace();
});
teardown(function () {
sharedTestTeardown.call(this);
});
suite('Serialization', function () {
test('events round-trip through JSON', function () {
const block = this.workspace.newBlock('text', 'block_id');
const origEvent = new Blockly.Events.BlockFieldIntermediateChange(
block,
'TEXT',
'old value',
'new value',
);
const json = origEvent.toJson();
const newEvent = new Blockly.Events.fromJson(json, this.workspace);
chai.assert.deepEqual(newEvent, origEvent);
});
});
suite('Change Value', function () {
test("running forward changes the block's value to new value", function () {
const block = this.workspace.newBlock('text', 'block_id');
const origEvent = new Blockly.Events.BlockFieldIntermediateChange(
block,
'TEXT',
'old value',
'new value',
);
origEvent.run(true);
chai.assert.deepEqual(
block.getField(origEvent.name).getValue(),
'new value',
);
});
test("running backward changes the block's value to old value", function () {
const block = this.workspace.newBlock('text', 'block_id');
const origEvent = new Blockly.Events.BlockFieldIntermediateChange(
block,
'TEXT',
'old value',
'new value',
);
origEvent.run(false);
chai.assert.deepEqual(
block.getField(origEvent.name).getValue(),
'old value',
);
});
});
});