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.
Merge pull request #2 from yamadayutaka/fix/issue_6002_test
fix: Modify test structure.
- Loading branch information
Showing
4 changed files
with
120 additions
and
81 deletions.
There are no files selected for viewing
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,117 @@ | ||
/** | ||
* @license | ||
* Copyright 2022 Google LLC | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
goog.module('Blockly.test.commentDeserialization'); | ||
|
||
const {sharedTestSetup, sharedTestTeardown} = goog.require('Blockly.test.helpers.setupTeardown'); | ||
const {simulateClick} = goog.require('Blockly.test.helpers.userInput'); | ||
|
||
|
||
suite('Comment Deserialization', function() { | ||
setup(function() { | ||
sharedTestSetup.call(this); | ||
Blockly.defineBlocksWithJsonArray([ | ||
{ | ||
"type": "empty_block", | ||
"message0": "", | ||
"args0": [], | ||
}, | ||
]); | ||
const toolboxXml = ` | ||
<xml> | ||
<category name="test"> | ||
<block type="empty_block"> | ||
<comment pinned="true" h="80" w="160">test toolbox text</comment> | ||
</block> | ||
</category> | ||
</xml> | ||
`; | ||
this.workspace = Blockly.inject('blocklyDiv', { | ||
comments: true, | ||
scrollbars: true, | ||
trashcan: true, | ||
maxTrashcanContents: Infinity, | ||
toolbox: Blockly.Xml.textToDom(toolboxXml), | ||
}); | ||
}); | ||
teardown(function() { | ||
sharedTestTeardown.call(this); | ||
}); | ||
suite('Pattern', function() { | ||
teardown(function() { | ||
// Delete all blocks. | ||
this.workspace.clear(); | ||
}); | ||
function createBlock(workspace) { | ||
const block = Blockly.Xml.domToBlock(Blockly.Xml.textToDom( | ||
'<block type="empty_block"/>' | ||
), workspace); | ||
block.setCommentText('test text'); | ||
return block; | ||
} | ||
function assertComment(workspace, text) { | ||
// Show comment. | ||
const block = workspace.getAllBlocks()[0]; | ||
block.comment.setVisible(true); | ||
// Check comment bubble size. | ||
const comment = block.getCommentIcon(); | ||
const bubbleSize = comment.getBubbleSize(); | ||
chai.assert.isNotNaN(bubbleSize.width); | ||
chai.assert.isNotNaN(bubbleSize.height); | ||
// Check comment text. | ||
chai.assert.equal(comment.textarea_.value, text); | ||
} | ||
test('Trashcan', function() { | ||
// Create block. | ||
this.block = createBlock(this.workspace); | ||
// Delete block. | ||
this.block.checkAndDelete(); | ||
chai.assert.equal(this.workspace.getAllBlocks().length, 0); | ||
// Open trashcan. | ||
simulateClick(this.workspace.trashcan.svgGroup_); | ||
// Place from trashcan. | ||
simulateClick(this.workspace.trashcan.flyout.svgGroup_.querySelector('.blocklyDraggable')); | ||
chai.assert.equal(this.workspace.getAllBlocks().length, 1); | ||
// Check comment. | ||
assertComment(this.workspace, 'test text'); | ||
}); | ||
test('Undo', function() { | ||
// Create block. | ||
this.block = createBlock(this.workspace); | ||
// Delete block. | ||
this.block.checkAndDelete(); | ||
chai.assert.equal(this.workspace.getAllBlocks().length, 0); | ||
// Undo. | ||
this.workspace.undo(false); | ||
chai.assert.equal(this.workspace.getAllBlocks().length, 1); | ||
// Check comment. | ||
assertComment(this.workspace, 'test text'); | ||
}); | ||
test('Redo', function() { | ||
// Create block. | ||
this.block = createBlock(this.workspace); | ||
// Undo & undo. | ||
this.workspace.undo(false); | ||
this.workspace.undo(false); | ||
chai.assert.equal(this.workspace.getAllBlocks().length, 0); | ||
// Redo & redo. | ||
this.workspace.undo(true); | ||
this.workspace.undo(true); | ||
chai.assert.equal(this.workspace.getAllBlocks().length, 1); | ||
// Check comment. | ||
assertComment(this.workspace, 'test text'); | ||
}); | ||
test('Toolbox', function() { | ||
// Place from toolbox. | ||
const toolbox = this.workspace.getToolbox(); | ||
simulateClick(toolbox.HtmlDiv.querySelector('.blocklyTreeRow')); | ||
simulateClick(toolbox.getFlyout().svgGroup_.querySelector('.blocklyDraggable')); | ||
chai.assert.equal(this.workspace.getAllBlocks().length, 1); | ||
// Check comment. | ||
assertComment(this.workspace, 'test toolbox text'); | ||
}); | ||
}); | ||
}); |
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