-
Notifications
You must be signed in to change notification settings - Fork 3.7k
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 (#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
Showing
9 changed files
with
273 additions
and
19 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
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,69 @@ | ||
|
||
/** | ||
* @license | ||
* Copyright 2021 Google LLC | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
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,66 @@ | ||
|
||
/** | ||
* @license | ||
* Copyright 2021 Google LLC | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
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}')); | ||
}); | ||
}); | ||
}); |
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