From 23df4765c0563ee9c63247b648cd899da7ec2c39 Mon Sep 17 00:00:00 2001 From: rachel-fenichel Date: Fri, 11 Mar 2016 11:41:02 -0800 Subject: [PATCH 1/2] fix test --- tests/jsunit/connection_test.js | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/tests/jsunit/connection_test.js b/tests/jsunit/connection_test.js index b4448b083..e0b91efee 100644 --- a/tests/jsunit/connection_test.js +++ b/tests/jsunit/connection_test.js @@ -51,6 +51,7 @@ function connectionTest_tearDown() { dummyWorkspace = null; } +var isMovableFn = function() { return true; }; /** * These tests check that the reasons for failures to connect are consistent * (internal view of error states). @@ -67,10 +68,10 @@ function testCanConnectWithReason_TargetNull() { function testCanConnectWithReason_Disconnect() { connectionTest_setUp(); - var tempConnection = new Blockly.Connection({workspace: dummyWorkspace}, + var tempConnection = new Blockly.Connection({workspace: dummyWorkspace, isMovable: isMovableFn}, Blockly.OUTPUT_VALUE); - Blockly.Connection.connectReciprocally(input, tempConnection); - assertEquals(Blockly.Connection.REASON_MUST_DISCONNECT, + Blockly.Connection.connectReciprocally_(input, tempConnection); + assertEquals(Blockly.Connection.CAN_CONNECT, input.canConnectWithReason_(output)); connectionTest_tearDown(); @@ -270,7 +271,7 @@ function test_isConnectionAllowed() { var four = helper_createConnection(0, 0, Blockly.INPUT_VALUE); four.sourceBlock_ = helper_makeSourceBlock(sharedWorkspace); - Blockly.Connection.connectReciprocally(three, four); + Blockly.Connection.connectReciprocally_(three, four); assertFalse(one.isConnectionAllowed(three, 20.0)); // Don't connect two connections on the same block. @@ -286,4 +287,4 @@ function testCheckConnection_Okay() { output.checkConnection_(input); connectionTest_tearDown(); -} \ No newline at end of file +} From 50975170d71b1e95c6b818065903f602a7bf91d8 Mon Sep 17 00:00:00 2001 From: rachel-fenichel Date: Fri, 11 Mar 2016 13:13:34 -0800 Subject: [PATCH 2/2] Fix search for closest --- core/connection.js | 8 +------- core/connection_db.js | 11 +++++++---- tests/jsunit/connection_db_test.js | 3 ++- 3 files changed, 10 insertions(+), 12 deletions(-) diff --git a/core/connection.js b/core/connection.js index 81017f21c..4db07585f 100644 --- a/core/connection.js +++ b/core/connection.js @@ -645,13 +645,7 @@ Blockly.Connection.prototype.tighten_ = function() { * and 'radius' which is the distance. */ Blockly.Connection.prototype.closest = function(maxLimit, dx, dy) { - var closestConnection = this.dbOpposite_.searchForClosest(this, maxLimit, dx, - dy); - if (closestConnection) { - return {connection: closestConnection, - radius: this.distanceFrom(closestConnection)}; - } - return {connection: null, radius: maxLimit}; + return this.dbOpposite_.searchForClosest(this, maxLimit, dx, dy); }; /** diff --git a/core/connection_db.js b/core/connection_db.js index b64c5e23a..b1c85b1b3 100644 --- a/core/connection_db.js +++ b/core/connection_db.js @@ -221,14 +221,15 @@ Blockly.ConnectionDB.prototype.isInYRange_ = function(index, baseY, maxRadius) { * in the database and the current location (as a result of dragging). * @param {number} dy Vertical offset between this connection's location * in the database and the current location (as a result of dragging). - * @return ?Blockly.Connection the closest valid connection. - * another connection or null, and 'radius' which is the distance. + * @return {!{connection: ?Blockly.Connection, radius: number}} Contains two + * properties:' connection' which is either another connection or null, + * and 'radius' which is the distance. */ Blockly.ConnectionDB.prototype.searchForClosest = function(conn, maxRadius, dx, dy) { // Don't bother. if (!this.length) { - return null; + return {connection: null, radius: maxRadius}; } // Stash the values of x and y from before the drag. @@ -273,7 +274,9 @@ Blockly.ConnectionDB.prototype.searchForClosest = function(conn, maxRadius, dx, // Reset the values of x and y. conn.x_ = baseX; conn.y_ = baseY; - return bestConnection; + + // If there were no valid connections, bestConnection will be null. + return {connection: bestConnection, radius: bestRadius}; }; /** diff --git a/tests/jsunit/connection_db_test.js b/tests/jsunit/connection_db_test.js index 0e7b33401..67f6eeb5d 100644 --- a/tests/jsunit/connection_db_test.js +++ b/tests/jsunit/connection_db_test.js @@ -260,7 +260,8 @@ function helper_searchDB(db, x, y, radius, shared_workspace) { var tempConn = helper_createConnection(x, y, Blockly.NEXT_STATEMENT, shared_workspace); tempConn.sourceBlock_ = helper_makeSourceBlock(shared_workspace); - return db.searchForClosest(tempConn, radius, 0, 0); + var closest = db.searchForClosest(tempConn, radius, 0, 0); + return closest.connection; } function helper_makeSourceBlock(sharedWorkspace) {