You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@flex.apache.org by mi...@apache.org on 2017/03/29 11:17:34 UTC

[5/5] git commit: [flex-sdk] [refs/heads/develop] - FLEX-35267 Updated unit test - made it easier to read, and now we're also testing GridColumnHeaderGroup.containsGlobalCoordinates(). For the test to pass I've improved the logic in GridHeaderViewLayout.

FLEX-35267 Updated unit test - made it easier to read, and now we're also testing GridColumnHeaderGroup.containsGlobalCoordinates(). For the test to pass I've improved the logic in GridHeaderViewLayout.getHeaderIndexAt() which, in turn, made a few functions redundant in GridColumnHeaderGroup. All tests currently pass.


Project: http://git-wip-us.apache.org/repos/asf/flex-sdk/repo
Commit: http://git-wip-us.apache.org/repos/asf/flex-sdk/commit/56abc7db
Tree: http://git-wip-us.apache.org/repos/asf/flex-sdk/tree/56abc7db
Diff: http://git-wip-us.apache.org/repos/asf/flex-sdk/diff/56abc7db

Branch: refs/heads/develop
Commit: 56abc7db27bc79bc313db3f6ab4ab2c14f536a4e
Parents: 5787e9b
Author: Mihai Chira <mi...@apache.org>
Authored: Wed Mar 29 13:16:54 2017 +0200
Committer: Mihai Chira <mi...@apache.org>
Committed: Wed Mar 29 13:16:54 2017 +0200

----------------------------------------------------------------------
 .../spark/components/GridColumnHeaderGroup.as   |  37 +-----
 .../gridClasses/GridHeaderViewLayout.as         |  21 ++-
 .../GridHeaderViewLayout_FLEX_35260_Tests.as    | 132 ++++++++++++-------
 3 files changed, 99 insertions(+), 91 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/flex-sdk/blob/56abc7db/frameworks/projects/spark/src/spark/components/GridColumnHeaderGroup.as
----------------------------------------------------------------------
diff --git a/frameworks/projects/spark/src/spark/components/GridColumnHeaderGroup.as b/frameworks/projects/spark/src/spark/components/GridColumnHeaderGroup.as
index 0b202b7..02f3aac 100644
--- a/frameworks/projects/spark/src/spark/components/GridColumnHeaderGroup.as
+++ b/frameworks/projects/spark/src/spark/components/GridColumnHeaderGroup.as
@@ -794,7 +794,10 @@ public class GridColumnHeaderGroup extends Group implements IDataGridElement
 
     public function containsGlobalCoordinates(coordinates:Point):Boolean
     {
-        return areCoordinatesOverAHeaderView(coordinates) || areCoordinatesOverPadding(coordinates);
+        var globalPosition:Point = localToGlobal(new Point(getLayoutBoundsX(), getLayoutBoundsY()));
+        var bounds:Rectangle = new Rectangle(globalPosition.x, globalPosition.y, getLayoutBoundsWidth(), getLayoutBoundsHeight());
+
+        return bounds.containsPoint(coordinates);
     }
 
     public function areCoordinatesOverAHeaderView(coordinates:Point):Boolean
@@ -802,38 +805,6 @@ public class GridColumnHeaderGroup extends Group implements IDataGridElement
         return getHeaderViewUnderGlobalCoordinates(coordinates) != null;
     }
 
-    public function areCoordinatesOverPadding(coordinates:Point):Boolean
-    {
-        return areCoordinatesOverLeftPadding(coordinates) || areCoordinatesOverTopPadding(coordinates) || areCoordinatesOverBottomPadding(coordinates);
-    }
-
-    public function areCoordinatesOverLeftPadding(coordinates:Point):Boolean
-    {
-        var paddingLeftStyle:Number = getStyle("paddingLeft");
-        var paddingLeft:Number = isNaN(paddingLeftStyle) ? 0 : paddingLeftStyle;
-
-        return getHeaderViewUnderGlobalCoordinates(new Point(coordinates.x, coordinates.y)) == null &&
-                getHeaderViewUnderGlobalCoordinates(new Point(coordinates.x + paddingLeft, coordinates.y)) != null;
-    }
-    
-    public function areCoordinatesOverTopPadding(coordinates:Point):Boolean
-    {
-        var paddingTopStyle:Number = getStyle("paddingTop");
-        var paddingTop:Number = isNaN(paddingTopStyle) ? 0 : paddingTopStyle;
-
-        return getHeaderViewUnderGlobalCoordinates(new Point(coordinates.x, coordinates.y)) == null &&
-        getHeaderViewUnderGlobalCoordinates(new Point(coordinates.x, coordinates.y + paddingTop)) != null;
-    }
-
-    public function areCoordinatesOverBottomPadding(coordinates:Point):Boolean
-    {
-        var paddingBottomStyle:Number = getStyle("paddingBottom");
-        var paddingBottom:Number = isNaN(paddingBottomStyle) ? 0 : paddingBottomStyle;
-
-        return getHeaderViewUnderGlobalCoordinates(new Point(coordinates.x, coordinates.y)) == null &&
-        getHeaderViewUnderGlobalCoordinates(new Point(coordinates.x, coordinates.y - paddingBottom)) != null;
-    }
-
     //--------------------------------------------------------------------------
     //
     //  Methods 

http://git-wip-us.apache.org/repos/asf/flex-sdk/blob/56abc7db/frameworks/projects/spark/src/spark/components/gridClasses/GridHeaderViewLayout.as
----------------------------------------------------------------------
diff --git a/frameworks/projects/spark/src/spark/components/gridClasses/GridHeaderViewLayout.as b/frameworks/projects/spark/src/spark/components/gridClasses/GridHeaderViewLayout.as
index 4eac8c7..cbdf3eb 100644
--- a/frameworks/projects/spark/src/spark/components/gridClasses/GridHeaderViewLayout.as
+++ b/frameworks/projects/spark/src/spark/components/gridClasses/GridHeaderViewLayout.as
@@ -503,21 +503,18 @@ public class GridHeaderViewLayout extends LayoutBase
         var headerIndex:int = -1;
         var globalPoint:Point = gridColumnHeaderGroup.localToGlobal(new Point(x, y));
 
-        if(gridColumnHeaderGroup.containsGlobalCoordinates(globalPoint))
+        if(gridColumnHeaderGroup.areCoordinatesOverAHeaderView(globalPoint))
         {
-            if (!gridColumnHeaderGroup.areCoordinatesOverPadding(globalPoint))
-            {
-                var paddingLeftStyle:Number = gridColumnHeaderGroup.getStyle("paddingLeft");
-                var paddingLeft:Number = isNaN(paddingLeftStyle) ? 0 : paddingLeftStyle;
+            var paddingLeftStyle:Number = gridColumnHeaderGroup.getStyle("paddingLeft");
+            var paddingLeft:Number = isNaN(paddingLeftStyle) ? 0 : paddingLeftStyle;
 
-                headerIndex = gridView.gridViewLayout.gridDimensionsView.getColumnIndexAt(x - paddingLeft + horizontalScrollPosition, y);
+            headerIndex = gridView.gridViewLayout.gridDimensionsView.getColumnIndexAt(x - paddingLeft + horizontalScrollPosition, y);
 
-                if(headerIndex == -1)
-                {
-                    //then the point is either over the right padding, over the width of the vertical
-                    //scroll bar, or over the space between the last separator and the width of the grid
-                    headerIndex = grid.getPreviousVisibleColumnIndex(columnsView.length);
-                }
+            if(headerIndex == -1)
+            {
+                //then the point is either over the right padding, over the width of the vertical
+                //scroll bar, or over the space between the last separator and the width of the grid
+                headerIndex = grid.getPreviousVisibleColumnIndex(columnsView.length);
             }
         }
 

http://git-wip-us.apache.org/repos/asf/flex-sdk/blob/56abc7db/frameworks/projects/spark/tests/spark/components/gridClasses/GridHeaderViewLayout_FLEX_35260_Tests.as
----------------------------------------------------------------------
diff --git a/frameworks/projects/spark/tests/spark/components/gridClasses/GridHeaderViewLayout_FLEX_35260_Tests.as b/frameworks/projects/spark/tests/spark/components/gridClasses/GridHeaderViewLayout_FLEX_35260_Tests.as
index 9c7bd51..1ac5a17 100644
--- a/frameworks/projects/spark/tests/spark/components/gridClasses/GridHeaderViewLayout_FLEX_35260_Tests.as
+++ b/frameworks/projects/spark/tests/spark/components/gridClasses/GridHeaderViewLayout_FLEX_35260_Tests.as
@@ -99,7 +99,8 @@ package spark.components.gridClasses {
 
         //@TODO add cases with horizontal scroll, and also with fixed columns
         //@TODO we probably have to account for paddingTop and paddingBottom as well
-        public static var dimensions:Array = [/*x, y, width, header padding left, header padding top, header padding bottom, [column widths] */
+        public static var dimensions:Array = [
+            /*x, y, width, header padding left, header padding top, header padding bottom, [column widths] */
             [[10, 0, 300, 5, 0, 5, [25, 150]]],
             [[0, 0, 300, 5, 0, 0, [25, 150]]]
         ];
@@ -148,17 +149,8 @@ package spark.components.gridClasses {
             //then
             assertEquals(expectedColumnIndex, columnIndex);
         }
+*/
 
-        [Ignore]
-        [Test]
-        public function test_header_contains_global_coordinates(globalPoint:Array, headerShouldContainThisPoint:Boolean):void
-        {
-            //when
-            var doesHeaderContainThisPoint:Boolean = _sut.containsGlobalCoordinates(new Point(globalPoint[0], globalPoint[1]));
-
-            //then
-            assertEquals(headerShouldContainThisPoint, doesHeaderContainThisPoint);
-        }*/
 
         [Test(dataProvider="dimensions")]
         public function test_with_no_scroll(dimensions:Array):void
@@ -190,46 +182,75 @@ package spark.components.gridClasses {
             //first, make sure that the dataGrid was rendered correctly
             assertThat("The dataGrid has not yet been correctly rendered on stage", getActualHeaderHeight(_dataGrid) > 0);
 
-            for (var pointName:String in _keyPoints)
+            forEachPoint(assertAssumptionsAboutPoint);
+        }
+
+        private function assertAssumptionsAboutPoint(point:Point, pointName:String, currentTransformation:Matrix):void
             {
-                for (var i:int = 0; i < directions.length; i++)
-                {
-                    //given
-                    var pointToTest:Point = getAdjacentPoint(_keyPoints[pointName], directions[i]);
+            assertThatHeaderContainsPointOrNot(point, pointName, currentTransformation);
+            assertThatHeaderIndexIsCorrect(point, pointName, currentTransformation);
+            assertThatCoordinatesOverHeaderViewOrNot(point, pointName, currentTransformation);
+        }
 
+        private function assertThatHeaderContainsPointOrNot(point:Point, pointName:String, currentTransformation:Matrix):void
+        {
                     //when
-                    var expectedHeaderIndex:int = getHeaderIndexAssumption(pointToTest);
-                    var actualHeaderIndex:int = getHeaderIndexAtGlobalPoint(pointToTest);
-                    const errorMessageHeaderIndex:String = getHeaderIndexErrorMessage(pointName, directions[i], pointToTest, expectedHeaderIndex, actualHeaderIndex);
+            var headerShouldContainThisPoint:Boolean = getHeaderShouldContainPointAssumption(point);
+            var doesHeaderContainThisPoint:Boolean = _sut.containsGlobalCoordinates(point);
+            const errorMessageHeaderContainsPoint:String = getHeaderContainsPointErrorMessage(pointName, currentTransformation, point, headerShouldContainThisPoint, doesHeaderContainThisPoint);
 
-                    var shouldBeContainedInMainHeaderView:Boolean = getMainHeaderViewContainsPointAssumption(pointToTest);
-                    var shouldBeContainedInFixedHeaderView:Boolean = getFixedHeaderViewContainsPointAssumption(pointToTest);
+            //then
+            assertEquals(errorMessageHeaderContainsPoint, headerShouldContainThisPoint, doesHeaderContainThisPoint);
+        }
+
+        private function assertThatCoordinatesOverHeaderViewOrNot(point:Point, pointName:String, currentTransformation:Matrix):void
+        {
+            //when
+            var shouldBeContainedInMainHeaderView:Boolean = getMainHeaderViewContainsPointAssumption(point);
+            var shouldBeContainedInFixedHeaderView:Boolean = getFixedHeaderViewContainsPointAssumption(point);
                     const shouldBeContainedInAHeaderView:Boolean = shouldBeContainedInMainHeaderView || shouldBeContainedInFixedHeaderView;
-                    var actuallyContainedInAHeaderView:Boolean = _sut.areCoordinatesOverAHeaderView(pointToTest);
-                    const errorMessageHeaderViewContainsPoint:String = getHeaderContainsPointErrorMessage(pointName, directions[i], pointToTest, shouldBeContainedInAHeaderView, actuallyContainedInAHeaderView);
+            var actuallyContainedInAHeaderView:Boolean = _sut.areCoordinatesOverAHeaderView(point);
+            const errorMessageHeaderViewContainsPoint:String = getHeaderViewContainsPointErrorMessage(pointName, currentTransformation, point, shouldBeContainedInAHeaderView, actuallyContainedInAHeaderView);
 
                     //then
-                    assertEquals(errorMessageHeaderIndex, expectedHeaderIndex, actualHeaderIndex);
                     assertEquals(errorMessageHeaderViewContainsPoint, shouldBeContainedInAHeaderView, actuallyContainedInAHeaderView);
                 }
-            }
+
+        private function assertThatHeaderIndexIsCorrect(point:Point, pointName:String, currentTransformation:Matrix):void
+        {
+            //when
+            var expectedHeaderIndex:int = getHeaderIndexAssumption(point);
+            var actualHeaderIndex:int = getHeaderIndexAtGlobalPoint(point);
+            const errorMessageHeaderIndex:String = getHeaderIndexErrorMessage(pointName, currentTransformation, point, expectedHeaderIndex, actualHeaderIndex);
+
+            //then
+            assertEquals(errorMessageHeaderIndex, expectedHeaderIndex, actualHeaderIndex);
         }
 
         private function getHeaderIndexErrorMessage(pointName:String, direction:Matrix, transformedPoint:Point, expectedColumnHeaderIndex:int, actualColumnHeaderIndex:int):String
         {
             return "The point " + pointName + " transformed with Matrix " + direction + " (resulting in " + transformedPoint + ") should be "
-                    + (expectedColumnHeaderIndex == -1 ? "outside any header bounds" : "inside the column header with index " + expectedColumnHeaderIndex)
+                    + (expectedColumnHeaderIndex == -1 ? "outside any column header bounds" : "inside the column header with index " + expectedColumnHeaderIndex)
                     + " but was mistakenly found to be "
-                    + (actualColumnHeaderIndex == -1 ? "outside any header bounds" : "inside the column header with index " + actualColumnHeaderIndex
+                    + (actualColumnHeaderIndex == -1 ? "outside any column header bounds" : "inside the column header with index " + actualColumnHeaderIndex
                     + "\n DEBUG INFO: headerRectangles=" + columnHeaderRectangles);
         }
 
         private function getHeaderContainsPointErrorMessage(pointName:String, direction:Matrix, transformedPoint:Point, shouldBeContainedInHeader:Boolean, isActuallyContainedInHeader:Boolean):String
         {
             return "The point " + pointName + " transformed with Matrix " + direction + " (resulting in " + transformedPoint + ") should be "
-                    + (shouldBeContainedInHeader ? "within " : "outside ") + "a header view"
+                    + (shouldBeContainedInHeader ? "within " : "outside ") + "the header bounds"
                     + " but was mistakenly found to be "
                     + (isActuallyContainedInHeader ? "within" : "outside")
+                    + "\n DEBUG INFO: header rectangle=" + entireHeaderRectangle;
+        }
+
+        private function getHeaderViewContainsPointErrorMessage(pointName:String, direction:Matrix, transformedPoint:Point, shouldBeContainedInAHeaderView:Boolean, isActuallyContainedByAHeaderView:Boolean):String
+        {
+            return "The point " + pointName + " transformed with Matrix " + direction + " (resulting in " + transformedPoint + ") should be "
+                    + (shouldBeContainedInAHeaderView ? "within " : "outside ") + "a header view"
+                    + " but was mistakenly found to be "
+                    + (isActuallyContainedByAHeaderView ? "within" : "outside")
                     + "\n DEBUG INFO: header views=" + fixedHeaderViewRectangle + "; " + mainHeaderViewRectangle;
         }
 
@@ -239,7 +260,7 @@ package spark.components.gridClasses {
             return _sut.getHeaderIndexAt(localPoint.x, localPoint.y);
         }
 
-        private function getHeaderContainsPointAssumption(point:Point):Boolean
+        private function getHeaderShouldContainPointAssumption(point:Point):Boolean
         {
             return rectangleContainsPoint(entireHeaderRectangle, point);
         }
@@ -343,7 +364,8 @@ package spark.components.gridClasses {
         private function generateVisibleHeaderRectangle(keyPoints:Array, dimensions:Array):Rectangle
         {
             const topLeftCorner:Point = keyPoints["b0"];
-            return new Rectangle(topLeftCorner.x, topLeftCorner.y, getHeaderWidthFromKeyPoints(keyPoints), getHeaderHeightFromKeyPoints(keyPoints));
+            const bottomRightCorner:Point = keyPoints["i"];
+            return new Rectangle(topLeftCorner.x, topLeftCorner.y, bottomRightCorner.x - topLeftCorner.x, bottomRightCorner.y - topLeftCorner.y);
         }
 
         private function generateHeaderColumnRectangles(keyPoints:Array, dimensions:Array):Array
@@ -368,6 +390,26 @@ package spark.components.gridClasses {
             return headerRectangles;
         }
 
+        private function forEachPoint(assertThat_:Function):void
+        {
+            for (var pointName:String in _keyPoints)
+            {
+                for (var i:int = 0; i < directions.length; i++)
+                {
+                    assertThat_(getAdjacentPoint(_keyPoints[pointName], directions[i]), pointName, directions[i]);
+                }
+            }
+        }
+
+
+        private function getActualHeaderHeight(grid:DataGrid):Number
+        {
+            //Note that we're assuming the grid is on stage and validated by this point!
+            return grid.columnHeaderGroup.height;
+        }
+
+        /* key rectangles getters */
+
         private function get columnHeaderRectangles():Array
         {
             return _keyRectangles[COLUMN_HEADER_RECTANGLES];
@@ -388,12 +430,26 @@ package spark.components.gridClasses {
             return _keyRectangles[FIXED_HEADER_VIEW_RECTANGLE] as Rectangle;
         }
 
+        /* key points getters */
+
         private function getColumnWidthFromKeyPoints(keyPoints:Array, columnIndex:int):Number
         {
             //we're assuming columnIndex has a valid value
             return Point(keyPoints["c" + (columnIndex + 1)]).x - Point(keyPoints["c" + columnIndex]).x;
         }
 
+        private function getHeaderHeightFromKeyPoints(keyPoints:Array):Number
+        {
+            return Point(keyPoints["i"]).y - Point(keyPoints["d"]).y;
+        }
+
+        private function getHeaderWidthFromKeyPoints(keyPoints:Array):Number
+        {
+            return Point(keyPoints["d"]).x - Point(keyPoints["b0"]).x;
+        }
+
+        /* dimensions getters */
+
         private function getX(dimensions:Array):Number
         {
             return dimensions[0];
@@ -424,22 +480,6 @@ package spark.components.gridClasses {
             return dimensions[5];
         }
 
-        private function getActualHeaderHeight(grid:DataGrid):Number
-        {
-            //Note that we're assuming the grid is on stage and validated by this point!
-            return grid.columnHeaderGroup.height;
-        }
-
-        private function getHeaderHeightFromKeyPoints(keyPoints:Array):Number
-        {
-            return Point(keyPoints["i"]).y - Point(keyPoints["d"]).y;
-        }
-
-        private function getHeaderWidthFromKeyPoints(keyPoints:Array):Number
-        {
-            return Point(keyPoints["d"]).x - Point(keyPoints["b0"]).x;
-        }
-
         private function getColumnWidths(dimensions:Array):Array
         {
             return dimensions[6];