forked from google/blockly
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: insertion markers and change events to work with JSO hooks (goog…
…le#5378) * fix: add tests for fixing change events * fix: change events and insertion markers * fix: build: * fix: remove duplicate code * fix: requires
- Loading branch information
1 parent
1d4cbd1
commit 486123e
Showing
10 changed files
with
287 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
|
||
/** | ||
* @license | ||
* Copyright 2021 Google LLC | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
goog.module('Blockly.test.blockChangeEvent'); | ||
|
||
const {defineMutatorBlocks, sharedTestSetup, sharedTestTeardown} = goog.require('Blockly.test.helpers'); | ||
|
||
|
||
suite('Block Change Event', function() { | ||
setup(function() { | ||
sharedTestSetup.call(this); | ||
this.workspace = new Blockly.Workspace(); | ||
}); | ||
|
||
teardown(function() { | ||
sharedTestTeardown.call(this); | ||
}); | ||
|
||
suite('Undo and Redo', function() { | ||
suite('Mutation', function() { | ||
setup(function() { | ||
defineMutatorBlocks(); | ||
}); | ||
|
||
teardown(function() { | ||
Blockly.Extensions.unregister('xml_mutator'); | ||
Blockly.Extensions.unregister('jso_mutator'); | ||
}); | ||
|
||
suite('XML', function() { | ||
test('Undo', function() { | ||
const block = this.workspace.newBlock('xml_block', 'block_id'); | ||
block.domToMutation( | ||
Blockly.Xml.textToDom('<mutation hasInput="true"/>')); | ||
const blockChange = new Blockly.Events.BlockChange( | ||
block, 'mutation', null, '', '<mutation hasInput="true"/>'); | ||
blockChange.run(false); | ||
chai.assert.isFalse(block.hasInput); | ||
}); | ||
|
||
test('Redo', function() { | ||
const block = this.workspace.newBlock('xml_block', 'block_id'); | ||
const blockChange = new Blockly.Events.BlockChange( | ||
block, 'mutation', null, '', '<mutation hasInput="true"/>'); | ||
blockChange.run(true); | ||
chai.assert.isTrue(block.hasInput); | ||
}); | ||
}); | ||
|
||
suite('JSO', function() { | ||
test('Undo', function() { | ||
const block = this.workspace.newBlock('jso_block', 'block_id'); | ||
block.loadExtraState({hasInput: true}); | ||
const blockChange = new Blockly.Events.BlockChange( | ||
block, 'mutation', null, '', '{"hasInput":true}'); | ||
blockChange.run(false); | ||
chai.assert.isFalse(block.hasInput); | ||
}); | ||
|
||
test('Redo', function() { | ||
const block = this.workspace.newBlock('jso_block', 'block_id'); | ||
const blockChange = new Blockly.Events.BlockChange( | ||
block, 'mutation', null, '', '{"hasInput":true}'); | ||
blockChange.run(true); | ||
chai.assert.isTrue(block.hasInput); | ||
}); | ||
}); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
|
||
/** | ||
* @license | ||
* Copyright 2021 Google LLC | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
goog.module('Blockly.test.mutator'); | ||
|
||
const {createRenderedBlock, defineMutatorBlocks, sharedTestSetup, sharedTestTeardown} = goog.require('Blockly.test.helpers'); | ||
|
||
|
||
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() { | ||
var block = createRenderedBlock(this.workspace, 'xml_block'); | ||
block.mutator.setVisible(true); | ||
var 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() { | ||
var block = createRenderedBlock(this.workspace, 'xml_block'); | ||
block.mutator.setVisible(true); | ||
var 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() { | ||
var block = createRenderedBlock(this.workspace, 'jso_block'); | ||
block.mutator.setVisible(true); | ||
var 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}')); | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.