Revamping mostly gesture tests.

This commit is contained in:
marisaleung
2017-06-22 12:08:21 -07:00
parent 5d91051ec7
commit 4a2c95fd1b
3 changed files with 96 additions and 0 deletions

View File

@@ -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();
}

View File

@@ -18,6 +18,7 @@
<script src="field_number_test.js"></script>
<script src="field_variable_test.js"></script>
<script src="generator_test.js"></script>
<script src="gesture_test.js"></script>
<script src="input_test.js"></script>
<script src="names_test.js"></script>
<script src="workspace_test.js"></script>

View File

@@ -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');