diff --git a/tests/jsunit/gesture_test.js b/tests/jsunit/gesture_test.js new file mode 100644 index 000000000..19ba1864e --- /dev/null +++ b/tests/jsunit/gesture_test.js @@ -0,0 +1,90 @@ +/** + * @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 gesture. + * @author marisaleung@google.com (Marisa Leung) + */ +'use strict'; + +var e; +var workspace; + + +function gestureTest_setUp() { + workspace = new Blockly.Workspace(); + e = {}; +} + +function gestureTest_tearDown() { + e = null; + workspace.dispose(); +} + +function test_gestureConstructor() { + var gesture = new Blockly.Gesture(e, workspace); + assertEquals(gesture.mostRecentEvent_, e); + assertEquals(gesture.creatorWorkspace_, workspace); +} + +function test_gestureIsField_ClickInWorkspace() { + gestureTest_setUp(); + var block = new Blockly.Block(workspace); + var field = new Blockly.Field(); + field.setSourceBlock(block); + var gesture = new Blockly.Gesture(e, workspace); + gesture.setStartField(field); + + var isFieldClick = gesture.isFieldClick_(); + assertEquals(isFieldClick, true); + gestureTest_tearDown(); +} + +function gestureIsFieldClick_InFlyoutHelper(flyout, expectedResult){ + // Assign workspace flyout + workspace.flyout_ = flyout; + // Create a Field inside of a Block + var block = new Blockly.Block(workspace); + var field = new Blockly.Field(); + field.setSourceBlock(block); + // Create gesture from the flyout + var gesture = new Blockly.Gesture(e, workspace.flyout_); + // Populate gesture with click start information + gesture.setStartField(field); + gesture.setStartFlyout_(workspace.flyout_); + + var isFieldClick = gesture.isFieldClick_(); + assertEquals(isFieldClick, expectedResult); +} + +function test_gestureIsFieldClick_AutoCloseFlyout() { + gestureTest_setUp(); + var flyout = new Blockly.VerticalFlyout({}); + gestureIsFieldClick_InFlyoutHelper(flyout, false); + gestureTest_tearDown(); +} + +function test_gestureIsFieldClick_AlwaysOpenFlyout() { + gestureTest_setUp(); + var flyout = new Blockly.VerticalFlyout({}); + flyout.autoClose = false; + gestureIsFieldClick_InFlyoutHelper(flyout, true); + gestureTest_tearDown(); +} diff --git a/tests/jsunit/index.html b/tests/jsunit/index.html index d2fa6f479..dd62a536a 100644 --- a/tests/jsunit/index.html +++ b/tests/jsunit/index.html @@ -18,6 +18,7 @@ + diff --git a/tests/jsunit/variable_map_test.js b/tests/jsunit/variable_map_test.js index 51141cffc..023377b14 100644 --- a/tests/jsunit/variable_map_test.js +++ b/tests/jsunit/variable_map_test.js @@ -17,6 +17,11 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + + /** + * @fileoverview Tests for variable map. + * @author marisaleung@google.com (Marisa Leung) + */ 'use strict'; goog.require('goog.testing');