From 1881b0c3fa87f75e5baa670ea416d4d72c493179 Mon Sep 17 00:00:00 2001 From: Rachel Fenichel Date: Thu, 2 Feb 2017 16:08:03 -0800 Subject: [PATCH] Add skeleton for tests on rendered workspaces --- tests/workspace_svg/index.html | 399 ++++++++++++++++++++++ tests/workspace_svg/workspace_svg_test.js | 72 ++++ 2 files changed, 471 insertions(+) create mode 100644 tests/workspace_svg/index.html create mode 100644 tests/workspace_svg/workspace_svg_test.js diff --git a/tests/workspace_svg/index.html b/tests/workspace_svg/index.html new file mode 100644 index 000000000..65890169a --- /dev/null +++ b/tests/workspace_svg/index.html @@ -0,0 +1,399 @@ + + + + +Blockly Workspace SVG testing + + + + + + + + + + + + + + + + + +
+ +

Blockly Workspace testing

+ + + + + + + diff --git a/tests/workspace_svg/workspace_svg_test.js b/tests/workspace_svg/workspace_svg_test.js new file mode 100644 index 000000000..ea25eaef3 --- /dev/null +++ b/tests/workspace_svg/workspace_svg_test.js @@ -0,0 +1,72 @@ +/** + * @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'; + +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(); + } +}