flex-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mih...@apache.org
Subject [1/3] 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.
Date Wed, 12 Apr 2017 11:35:43 GMT
Repository: flex-sdk
Updated Branches:
  refs/heads/develop 56abc7db2 -> 60ccf24cb


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/a1c61c5c
Tree: http://git-wip-us.apache.org/repos/asf/flex-sdk/tree/a1c61c5c
Diff: http://git-wip-us.apache.org/repos/asf/flex-sdk/diff/a1c61c5c

Branch: refs/heads/develop
Commit: a1c61c5cfd452cb0a150788e498865763890d112
Parents: 56abc7d
Author: Mihai Chira <mihaic@apache.org>
Authored: Wed Mar 29 14:26:51 2017 +0200
Committer: Mihai Chira <mihaic@apache.org>
Committed: Wed Mar 29 14:26:51 2017 +0200

----------------------------------------------------------------------
 .../GridHeaderViewLayout_FLEX_35260_Tests.as    | 84 ++++++++++++++------
 1 file changed, 61 insertions(+), 23 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/flex-sdk/blob/a1c61c5c/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 1ac5a17..5bc24b4 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
@@ -88,6 +88,7 @@ package spark.components.gridClasses {
         private static const directions:Array = [ITSELF, N, NE, E, SE, S, SW, W, NW];
 
         private static const COLUMN_HEADER_RECTANGLES:String = "columnHeaderRectangles";
+        private static const COLUMN_RECTANGLES:String = "columnRectangles";
         private static const ENTIRE_HEADER_RECTANGLE:String = "headerRectangle"; //includes
padding
         private static const MAIN_HEADER_VIEW_RECTANGLE:String = "mainHeaderViewRectangle";
         private static const FIXED_HEADER_VIEW_RECTANGLE:String = "fixedHeaderViewRectangle";
@@ -98,11 +99,11 @@ package spark.components.gridClasses {
         private var _keyPoints:Array;
 
         //@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] */
-            [[10, 0, 300, 5, 0, 5, [25, 150]]],
-            [[0, 0, 300, 5, 0, 0, [25, 150]]]
+            [[/*x=*/    0, /*y=*/   0, /*width=*/   300, /*paddingLeft=*/   5, /*paddingTop=*/
 0, /*paddingBottom=*/   0, /*columnWidths=*/[25, 150]]],
+            [[/*x=*/   10, /*y=*/   0, /*width=*/   300, /*paddingLeft=*/   5, /*paddingTop=*/
 0, /*paddingBottom=*/   5, /*columnWidths=*/[25, 150]]],
+            [[/*x=*/   -5, /*y=*/-100, /*width=*/   200, /*paddingLeft=*/  25, /*paddingTop=*/
12, /*paddingBottom=*/   5, /*columnWidths=*/[100, 150]]] //horizontal scroll
         ];
 
 
@@ -135,22 +136,6 @@ package spark.components.gridClasses {
             _keyPoints = null;
         }
 
-        /*
-        [Ignore]
-        [Test]
-        public function test_column_index(globalPoint:Array, expectedColumnIndex:int):void
-        {
-            //given
-            var localPoint:Point = _dataGrid.grid.globalToLocal(new Point(globalPoint[0],
globalPoint[1]));
-
-            //when
-            var columnIndex:int = _dataGrid.grid.getColumnIndexAt(localPoint.x, 0);
-
-            //then
-            assertEquals(expectedColumnIndex, columnIndex);
-        }
-*/
-
 
         [Test(dataProvider="dimensions")]
         public function test_with_no_scroll(dimensions:Array):void
@@ -189,6 +174,7 @@ package spark.components.gridClasses {
             {
             assertThatHeaderContainsPointOrNot(point, pointName, currentTransformation);
             assertThatHeaderIndexIsCorrect(point, pointName, currentTransformation);
+            assertThatColumnIndexIsCorrect(point, pointName, currentTransformation);
             assertThatCoordinatesOverHeaderViewOrNot(point, pointName, currentTransformation);
         }
 
@@ -227,6 +213,17 @@ package spark.components.gridClasses {
             assertEquals(errorMessageHeaderIndex, expectedHeaderIndex, actualHeaderIndex);
         }
 
+        private function assertThatColumnIndexIsCorrect(point:Point, pointName:String, currentTransformation:Matrix):void
+        {
+            //when
+            var expectedColumnIndex:int = getColumnIndexAssumption(point);
+            var actualColumnIndex:int = getColumnIndexAtGlobalPoint(point);
+            const errorMessageColumnIndex:String = getColumnIndexErrorMessage(pointName,
currentTransformation, point, expectedColumnIndex, actualColumnIndex);
+
+            //then
+            assertEquals(errorMessageColumnIndex, expectedColumnIndex, actualColumnIndex);
+        }
+
         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 "
@@ -236,6 +233,15 @@ package spark.components.gridClasses {
                     + "\n DEBUG INFO: headerRectangles=" + columnHeaderRectangles);
         }
 
+        private function getColumnIndexErrorMessage(pointName:String, direction:Matrix, transformedPoint:Point,
expectedColumnHeaderIndex:int, actualColumnHeaderIndex:int):String
+        {
+            return "The point " + pointName + " transformed with Matrix " + direction + "
(resulting in " + transformedPoint + ") should have its x value "
+                    + (expectedColumnHeaderIndex == -1 ? "outside any column bounds" : "within
the column with index " + expectedColumnHeaderIndex)
+                    + " but was mistakenly found to be "
+                    + (actualColumnHeaderIndex == -1 ? "outside any column bounds" : "inside
the column with index " + actualColumnHeaderIndex
+                    + "\n DEBUG INFO: columnRectangles=" + columnRectangles);
+        }
+
         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 "
@@ -260,6 +266,12 @@ package spark.components.gridClasses {
             return _sut.getHeaderIndexAt(localPoint.x, localPoint.y);
         }
 
+        private function getColumnIndexAtGlobalPoint(globalPoint:Point):int
+        {
+            var localPoint:Point = _dataGrid.grid.globalToLocal(globalPoint);
+            return _dataGrid.grid.getColumnIndexAt(localPoint.x, localPoint.y);
+        }
+
         private function getHeaderShouldContainPointAssumption(point:Point):Boolean
         {
             return rectangleContainsPoint(entireHeaderRectangle, point);
@@ -277,15 +289,15 @@ package spark.components.gridClasses {
 
         private function getHeaderIndexAssumption(point:Point):int
         {
-            return getIndexOfHeaderRectangleWhichContainsPoint(point, columnHeaderRectangles);
+            return getIndexOfRectangleWhichContainsPoint(point, columnHeaderRectangles);
         }
 
-        private function getAdjacentPoint(point:Point, direction:Matrix):Point
+        private function getColumnIndexAssumption(point:Point):int
         {
-            return direction.transformPoint(point);
+            return getIndexOfRectangleWhichContainsPoint(point, columnRectangles);
         }
 
-        private function getIndexOfHeaderRectangleWhichContainsPoint(point:Point, rectangles:Array):int
+        private function getIndexOfRectangleWhichContainsPoint(point:Point, rectangles:Array):int
         {
             for (var i:int = 0; i < rectangles.length; i++)
             {
@@ -301,6 +313,11 @@ package spark.components.gridClasses {
             return rectangle.containsPoint(point);
         }
 
+        private function getAdjacentPoint(point:Point, direction:Matrix):Point
+        {
+            return direction.transformPoint(point);
+        }
+
         private function generateKeyPoints(dimensions:Array, grid:DataGrid):Array
         {
             var keyPoints:Array = [];
@@ -338,6 +355,7 @@ package spark.components.gridClasses {
             var keyRectangles:Array = [];
 
             keyRectangles[COLUMN_HEADER_RECTANGLES] = generateHeaderColumnRectangles(keyPoints,
dimensions);
+            keyRectangles[COLUMN_RECTANGLES] = generateColumnRectangles(keyPoints, dimensions);
             keyRectangles[ENTIRE_HEADER_RECTANGLE] = generateVisibleHeaderRectangle(keyPoints,
dimensions);
             keyRectangles[MAIN_HEADER_VIEW_RECTANGLE] = generateMainHeaderViewRectangle(keyPoints,
dimensions);
             keyRectangles[FIXED_HEADER_VIEW_RECTANGLE] = generateFixedHeaderViewRectangle(keyPoints,
dimensions);
@@ -390,6 +408,21 @@ package spark.components.gridClasses {
             return headerRectangles;
         }
 
+        //Note that the height and y of the rectangles doesn't matter until FLEX-35280 is
fixed
+        private function generateColumnRectangles(keyPoints:Array, dimensions:Array):Array
+        {
+            var columnRectangles:Array = [];
+
+            for (var i:int = 0; i < getColumnWidths(dimensions).length; i++)
+            {
+                var topLeft:Point = keyPoints["g" + i];
+                var topRight:Point = keyPoints["g" + (i+1)];
+                columnRectangles.push(new Rectangle(topLeft.x, -10000, topRight.x - topLeft.x,
Number.MAX_VALUE));
+            }
+
+            return columnRectangles;
+        }
+
         private function forEachPoint(assertThat_:Function):void
         {
             for (var pointName:String in _keyPoints)
@@ -415,6 +448,11 @@ package spark.components.gridClasses {
             return _keyRectangles[COLUMN_HEADER_RECTANGLES];
         }
 
+        private function get columnRectangles():Array
+        {
+            return _keyRectangles[COLUMN_RECTANGLES];
+        }
+
         private function get entireHeaderRectangle():Rectangle //includes padding
         {
             return _keyRectangles[ENTIRE_HEADER_RECTANGLE] as Rectangle;


Mime
View raw message