Initial commit of 001code-html Scratch frontend project.
Includes scratch-gui, scratch-vm, scratch-blocks, scratch-render, scratch-l10n, and deployment config. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
75
scratch-blocks/tests/workspace_svg/index.html
Normal file
75
scratch-blocks/tests/workspace_svg/index.html
Normal file
@@ -0,0 +1,75 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>Blockly Workspace SVG testing</title>
|
||||
<script src="../../blockly_uncompressed_vertical.js"></script>
|
||||
<script src="../../blocks_vertical/vertical_extensions.js"></script>
|
||||
<script src="../../blocks_vertical/looks.js"></script>
|
||||
<script>goog.require('goog.testing.jsunit');</script>
|
||||
<script src="../../msg/messages.js"></script>
|
||||
|
||||
<script>
|
||||
'use strict';
|
||||
</script>
|
||||
|
||||
<style>
|
||||
html, body {
|
||||
height: 100%;
|
||||
}
|
||||
body {
|
||||
background-color: #fff;
|
||||
font-family: sans-serif;
|
||||
overflow: hidden;
|
||||
}
|
||||
h1 {
|
||||
font-weight: normal;
|
||||
font-size: 140%;
|
||||
}
|
||||
#blocklyDiv {
|
||||
float: right;
|
||||
height: 95%;
|
||||
width: 70%;
|
||||
}
|
||||
#importExport {
|
||||
font-family: monospace;
|
||||
}
|
||||
|
||||
.ioLabel>.blocklyFlyoutLabelText {
|
||||
font-style: italic;
|
||||
}
|
||||
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<div id="blocklyDiv"></div>
|
||||
|
||||
<h1>Blockly Workspace testing</h1>
|
||||
<script src="../jsunit/test_utilities.js"></script>
|
||||
<script src="workspace_svg_test.js"></script>
|
||||
|
||||
|
||||
<xml id="toolbox-categories" style="display: none">
|
||||
<category name="Looks" colour="#9966FF" secondaryColour="#774DCB">
|
||||
<block type="looks_show" id="lABCD"></block>
|
||||
<block type="looks_hide" id="looks_hide"></block>
|
||||
<block type="looks_switchcostumeto" id="looks_switchcostumeto">
|
||||
<value name="COSTUME">
|
||||
<shadow type="looks_costume"></shadow>
|
||||
</value>
|
||||
</block>
|
||||
<block type="looks_nextcostume" id="looks_nextcostume"></block>
|
||||
<block type="looks_nextbackdrop" id="looks_nextbackdrop"></block>
|
||||
<block type="looks_switchbackdropto" id="looks_switchbackdropto">
|
||||
<value name="BACKDROP">
|
||||
<shadow type="looks_backdrops"></shadow>
|
||||
</value>
|
||||
</block>
|
||||
|
||||
<sep></sep>
|
||||
<category name="Variables" colour="330" custom="VARIABLE"></category>
|
||||
<category name="Functions" colour="290" custom="PROCEDURE"></category>
|
||||
</xml>
|
||||
</body>
|
||||
</html>
|
||||
135
scratch-blocks/tests/workspace_svg/workspace_svg_test.js
Normal file
135
scratch-blocks/tests/workspace_svg/workspace_svg_test.js
Normal file
@@ -0,0 +1,135 @@
|
||||
/**
|
||||
* @license
|
||||
* Blockly Tests
|
||||
*
|
||||
* Copyright 2017 Google Inc.
|
||||
* https://developers.google.com/blockly/
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
'use strict';
|
||||
|
||||
goog.require('goog.testing');
|
||||
goog.require('goog.testing.MockControl');
|
||||
|
||||
function helper_createWorkspaceWithToolbox() {
|
||||
var toolbox = document.getElementById('toolbox-categories');
|
||||
return Blockly.inject('blocklyDiv', {toolbox: toolbox});
|
||||
}
|
||||
|
||||
function test_createWorkspace() {
|
||||
var workspace = helper_createWorkspaceWithToolbox();
|
||||
workspace.dispose();
|
||||
}
|
||||
|
||||
function test_emptyWorkspace() {
|
||||
var workspace = helper_createWorkspaceWithToolbox();
|
||||
try {
|
||||
assertEquals('Empty workspace (1).', 0, workspace.getTopBlocks(true).length);
|
||||
assertEquals('Empty workspace (2).', 0, workspace.getTopBlocks(false).length);
|
||||
assertEquals('Empty workspace (3).', 0, workspace.getAllBlocks().length);
|
||||
workspace.clear();
|
||||
assertEquals('Empty workspace (4).', 0, workspace.getTopBlocks(true).length);
|
||||
assertEquals('Empty workspace (5).', 0, workspace.getTopBlocks(false).length);
|
||||
assertEquals('Empty workspace (6).', 0, workspace.getAllBlocks().length);
|
||||
} finally {
|
||||
workspace.dispose();
|
||||
}
|
||||
}
|
||||
|
||||
function test_flatWorkspace() {
|
||||
var workspace = helper_createWorkspaceWithToolbox();
|
||||
var blockA, blockB;
|
||||
try {
|
||||
blockA = workspace.newBlock('');
|
||||
assertEquals('One block workspace (1).', 1, workspace.getTopBlocks(true).length);
|
||||
assertEquals('One block workspace (2).', 1, workspace.getTopBlocks(false).length);
|
||||
assertEquals('One block workspace (3).', 1, workspace.getAllBlocks().length);
|
||||
blockB = workspace.newBlock('');
|
||||
assertEquals('Two block workspace (1).', 2, workspace.getTopBlocks(true).length);
|
||||
assertEquals('Two block workspace (2).', 2, workspace.getTopBlocks(false).length);
|
||||
assertEquals('Two block workspace (3).', 2, workspace.getAllBlocks().length);
|
||||
blockA.dispose();
|
||||
assertEquals('One block workspace (4).', 1, workspace.getTopBlocks(true).length);
|
||||
assertEquals('One block workspace (5).', 1, workspace.getTopBlocks(false).length);
|
||||
assertEquals('One block workspace (6).', 1, workspace.getAllBlocks().length);
|
||||
workspace.clear();
|
||||
assertEquals('Cleared workspace (1).', 0, workspace.getTopBlocks(true).length);
|
||||
assertEquals('Cleared workspace (2).', 0, workspace.getTopBlocks(false).length);
|
||||
assertEquals('Cleared workspace (3).', 0, workspace.getAllBlocks().length);
|
||||
} finally {
|
||||
blockB && blockB.dispose();
|
||||
blockA && blockA.dispose();
|
||||
workspace.dispose();
|
||||
}
|
||||
}
|
||||
|
||||
/** Tests the alignment of appendDomToWorkspace with WorkspaceSvg. */
|
||||
function test_appendDomToWorkspace() {
|
||||
var workspace = helper_createWorkspaceWithToolbox();
|
||||
try {
|
||||
var dom = Blockly.Xml.textToDom(
|
||||
'<xml xmlns="http://www.w3.org/1999/xhtml">' +
|
||||
' <block type="looks_show" inline="true" x="21" y="23">' +
|
||||
' </block>' +
|
||||
'</xml>');
|
||||
Blockly.Xml.appendDomToWorkspace(dom, workspace);
|
||||
assertEquals('Block count', 1, workspace.getAllBlocks().length);
|
||||
Blockly.Xml.appendDomToWorkspace(dom, workspace);
|
||||
assertEquals('Block count', 2, workspace.getAllBlocks().length);
|
||||
var blocks = workspace.getAllBlocks();
|
||||
assertEquals('Block 1 position x',21,blocks[0].getRelativeToSurfaceXY().x);
|
||||
assertEquals('Block 1 position y',23,blocks[0].getRelativeToSurfaceXY().y);
|
||||
assertEquals('Block 2 position x',21,blocks[1].getRelativeToSurfaceXY().x);
|
||||
assertEquals('Block 2 position y',23 + blocks[0].getHeightWidth().height + Blockly.BlockSvg.SEP_SPACE_Y,blocks[1].getRelativeToSurfaceXY().y);
|
||||
} finally {
|
||||
workspace.dispose();
|
||||
}
|
||||
}
|
||||
|
||||
function test_addNewVariableRefreshToolbox() {
|
||||
var workspace = helper_createWorkspaceWithToolbox();
|
||||
|
||||
var mockControl = new goog.testing.MockControl();
|
||||
var mockMethod = mockControl.createMethodMock(Blockly.WorkspaceSvg.prototype,
|
||||
'refreshToolboxSelection_');
|
||||
try {
|
||||
mockMethod().$once();
|
||||
mockControl.$replayAll();
|
||||
|
||||
workspace.createVariable('name1', 'type1', 'id1');
|
||||
mockControl.$verifyAll();
|
||||
} finally {
|
||||
workspace.dispose();
|
||||
}
|
||||
}
|
||||
|
||||
function test_addDuplicateVariableDoNotRefreshToolbox() {
|
||||
var workspace = helper_createWorkspaceWithToolbox();
|
||||
|
||||
var mockControl = new goog.testing.MockControl();
|
||||
var mockMethod = mockControl.createMethodMock(Blockly.WorkspaceSvg.prototype,
|
||||
'refreshToolboxSelection_');
|
||||
try {
|
||||
mockMethod().$once();
|
||||
mockControl.$replayAll();
|
||||
// Create same variable twice. The first should refresh the toolbox,
|
||||
// the second should not.
|
||||
workspace.createVariable('name1', 'type1', 'id1');
|
||||
workspace.createVariable('name1', 'type1', 'id1');
|
||||
|
||||
mockControl.$verifyAll();
|
||||
} finally {
|
||||
workspace.dispose();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user