Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Modify test structure. #2

Merged
merged 1 commit into from
Mar 19, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion tests/deps.mocha.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

117 changes: 117 additions & 0 deletions tests/mocha/comment_deserialization_test.js
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');
});
});
});
80 changes: 0 additions & 80 deletions tests/mocha/comment_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ goog.module('Blockly.test.comments');
const {assertEventFired} = goog.require('Blockly.test.helpers.events');
const eventUtils = goog.require('Blockly.Events.utils');
const {sharedTestSetup, sharedTestTeardown} = goog.require('Blockly.test.helpers.setupTeardown');
const {simulateClick} = goog.require('Blockly.test.helpers.userInput');


suite('Comments', function() {
Expand All @@ -22,21 +21,9 @@ suite('Comments', function() {
"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),
});
this.block = Blockly.Xml.domToBlock(Blockly.Xml.textToDom(
'<block type="empty_block"/>'
Expand Down Expand Up @@ -146,71 +133,4 @@ suite('Comments', function() {
assertBubbleSize(this.comment, 100, 100);
});
});
suite('Restore Comment', function() {
setup(function() {
this.blockCount = this.workspace.getAllBlocks().length;
this.tempBlock = Blockly.Xml.domToBlock(Blockly.Xml.textToDom(
'<block type="empty_block"/>'
), this.workspace);
this.tempBlock.setCommentText('test temp text');
});
function assertComment(workspace, text) {
const count = workspace.getAllBlocks().length;
// Show comment.
const tempBlock = workspace.getAllBlocks()[count - 1];
tempBlock.comment.setVisible(true);
// Check comment bubble size.
const comment = tempBlock.getCommentIcon();
const bubbleSize = comment.getBubbleSize();
chai.assert.isNotNaN(bubbleSize.width);
chai.assert.isNotNaN(bubbleSize.height);
chai.assert.equal(comment.textarea_.value, text);
}
test('Trashcan', function() {
// Delete block.
this.tempBlock.checkAndDelete();
chai.assert.equal(this.workspace.getAllBlocks().length, this.blockCount);
// 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, this.blockCount + 1);
// Check comment.
assertComment(this.workspace, 'test temp text');
});
test('Undo', function() {
// Delete block.
this.tempBlock.checkAndDelete();
chai.assert.equal(this.workspace.getAllBlocks().length, this.blockCount);
// Undo.
this.workspace.undo(false);
chai.assert.equal(this.workspace.getAllBlocks().length, this.blockCount + 1);
// Check comment.
assertComment(this.workspace, 'test temp text');
});
test('Redo', function() {
// Undo & undo.
this.workspace.undo(false);
this.workspace.undo(false);
chai.assert.equal(this.workspace.getAllBlocks().length, this.blockCount);
// Redo & redo.
this.workspace.undo(true);
this.workspace.undo(true);
chai.assert.equal(this.workspace.getAllBlocks().length, this.blockCount + 1);
// Check comment.
assertComment(this.workspace, 'test temp text');
});
test('Toolbox', function() {
// Delete temp block.
this.tempBlock.checkAndDelete();
chai.assert.equal(this.workspace.getAllBlocks().length, this.blockCount);
// 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, this.blockCount + 1);
// Check comment.
assertComment(this.workspace, 'test toolbox text');
});
});
});
1 change: 1 addition & 0 deletions tests/mocha/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
goog.require('Blockly.test.blockJson');
goog.require('Blockly.test.blocks');
goog.require('Blockly.test.comments');
goog.require('Blockly.test.commentDeserialization');
goog.require('Blockly.test.connectionChecker');
goog.require('Blockly.test.connectionDb');
goog.require('Blockly.test.connection');
Expand Down