Files
blockly/tests/jsunit/procedures_test.js
Neil Fraser 82705923cb Convert compile demo into a unit test. (#1360)
* Intentionally break Travis.

* Alphabetize tests, remove orphaned test, and add fail to test that's running.

* Unbreak test, disable OS X, move scripts, list compiler directory.

* Test Java, break test.

* Unbreak test, call compile script.

* Compile main_compressed.js

* Run test command using bash.

* Fix path.

* Exclude node modules.

* Be more specific about JS files to compile.

* Test failure.

* Restore OSX, undo Blockly failure, remove compilation demo, add compilation test.

* Delete manual test files.

* Ignore downloaded/generated files.

* Whitespace cleanup.
2017-10-12 14:54:57 -07:00

83 lines
2.2 KiB
JavaScript

/**
* @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.
*/
/**
* @fileoverview Tests for procedures.
* @author marisaleung@google.com (Marisa Leung)
*/
'use strict';
goog.require('goog.testing');
var workspace;
function proceduresTest_setUpWithMockBlocks() {
workspace = new Blockly.Workspace();
Blockly.defineBlocksWithJsonArray([{
getProcedureDef: function() {
},
'type': 'procedure_mock_block',
'message0': '%1',
'args0': [
{
'type': 'field_variable',
'name': 'NAME',
'variable': 'item'
}
],
}]);
Blockly.Blocks['procedure_mock_block'].getProcedureDef = function() {
return [this.getFieldValue('NAME'), [], false];
};
}
function proceduresTest_tearDownWithMockBlocks() {
workspace.dispose();
delete Blockly.Blocks.procedures_mock_block;
}
function test_isNameUsed_NoBlocks() {
workspace = new Blockly.Workspace();
var result = Blockly.Procedures.isNameUsed('name1', workspace);
assertFalse(result);
workspace.dispose();
}
function test_isNameUsed_False() {
proceduresTest_setUpWithMockBlocks();
var block = new Blockly.Block(workspace, 'procedure_mock_block');
block.setFieldValue('name2', 'NAME');
var result = Blockly.Procedures.isNameUsed('name1', workspace);
assertFalse(result);
proceduresTest_tearDownWithMockBlocks();
}
function test_isNameUsed_True() {
proceduresTest_setUpWithMockBlocks();
var block = new Blockly.Block(workspace, 'procedure_mock_block');
block.setFieldValue('name1', 'NAME');
var result = Blockly.Procedures.isNameUsed('name1', workspace);
assertTrue(result);
proceduresTest_tearDownWithMockBlocks();
}