flex-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mih...@apache.org
Subject [02/10] git commit: [flex-sdk] [refs/heads/develop] - FLEX-34837 Added another test function to test the basic functionality of sorting by complex fields. (Note that because the feature isn't yet implemented, this also fails currently.)
Date Fri, 22 May 2015 17:02:14 GMT
FLEX-34837 Added another test function to test the basic functionality of sorting by complex
fields. (Note that because the feature isn't yet implemented, this also fails currently.)


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

Branch: refs/heads/develop
Commit: 19cdb3900c5814f452c5d5687c13f497a93d6a5c
Parents: 95b3926
Author: Mihai Chira <mihaic@apache.org>
Authored: Fri May 22 13:08:44 2015 +0200
Committer: Mihai Chira <mihaic@apache.org>
Committed: Fri May 22 18:17:10 2015 +0200

----------------------------------------------------------------------
 .../ListCollectionView_FLEX_34837_Tests.as      | 72 +++++++++++++++-----
 1 file changed, 56 insertions(+), 16 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/flex-sdk/blob/19cdb390/frameworks/projects/framework/tests/ListCollectionView_FLEX_34837_Tests.as
----------------------------------------------------------------------
diff --git a/frameworks/projects/framework/tests/ListCollectionView_FLEX_34837_Tests.as b/frameworks/projects/framework/tests/ListCollectionView_FLEX_34837_Tests.as
index 5ef19fb..d069b90 100644
--- a/frameworks/projects/framework/tests/ListCollectionView_FLEX_34837_Tests.as
+++ b/frameworks/projects/framework/tests/ListCollectionView_FLEX_34837_Tests.as
@@ -21,12 +21,11 @@ package {
     import mx.collections.ArrayList;
     import mx.collections.IList;
     import mx.collections.ListCollectionView;
+    import mx.collections.Sort;
+    import mx.collections.SortField;
 
     import org.flexunit.asserts.assertEquals;
 
-    import spark.collections.Sort;
-    import spark.collections.SortField;
-
     public class ListCollectionView_FLEX_34837_Tests {
         private var _sut:ListCollectionView;
 
@@ -43,10 +42,28 @@ package {
         }
 
         [Test]
-        public function test_changing_sort_field_value_places_it_correctly_according_to_collection_sort():void
+        public function test_simple_ascending_sort_by_complex_fields():void
         {
             //given
-            var from1To4:IList = generateObjects(5);
+            var from4To0:IList = generateVOs(5, true);
+            _sut.addAll(from4To0); //values["address.street"]: Street4, Street3, Street2,
Street1, Street0
+
+            const sortByIndexAscending:Sort = new Sort();
+            sortByIndexAscending.fields = [new SortField("address.street", false, false,
false)];
+            _sut.sort = sortByIndexAscending;
+
+            //when
+            _sut.refresh(); //should be: Street0, Street1, Street2, Street3, Street4
+
+            //then
+            assertIndexesAre([0, 1, 2, 3, 4]);
+        }
+
+        [Test]
+        public function test_changing_simple_sort_field_value_places_it_correctly_according_to_collection_sort():void
+        {
+            //given
+            var from1To4:IList = generateVOs(5);
             from1To4.removeItemAt(0);
             _sut.addAll(from1To4);
 
@@ -69,7 +86,7 @@ package {
         public function test_changing_complex_sort_field_value_places_it_correctly_according_to_collection_sort():void
         {
             //given
-            var from1To4:IList = generateObjects(5);
+            var from1To4:IList = generateVOs(5);
             from1To4.removeItemAt(0);
             _sut.addAll(from1To4);
 
@@ -85,24 +102,43 @@ package {
 
             //then
             const newItemIndex:int = _sut.getItemIndex(newItem);
-            assertEquals("the new item should have been placed at the beginning of the list
as soon as its name was changed", 0, newItemIndex);
+            assertEquals("the new item should have been placed at the beginning of the list
as soon as its address's street name was changed", 0, newItemIndex);
             _sut.removeItemAt(_sut.getItemIndex(newItem)); //if the bug is present, this
will throw an RTE
         }
 
-        private function generateObjects(no:int):IList
+        private function assertIndexesAre(indexes:Array):void
         {
-            var result:ArrayList = new ArrayList();
+            assertEquals(indexes.length, _sut.length);
+
+            for(var i:int = 0; i < _sut.length; i++)
+            {
+                assertEquals(ListCollectionView_FLEX_34837_VO(_sut.getItemAt(i)).index, indexes[i]);
+            }
+        }
+
+
+        private static function generateVOs(no:int, reverse:Boolean = false):IList
+        {
+            return generateObjects(no, reverse, generateOneObject);
+        }
+
+        private static function generateObjects(no:int, reverse:Boolean, generator:Function):IList
+        {
+            var result:Array = [];
             for(var i:int = 0; i < no; i++)
             {
-                result.addItem(generateOneObject(i));
+                result.push(generator(i));
             }
 
-            return result;
+            if(reverse)
+                result.reverse();
+
+            return new ArrayList(result);
         }
 
-        private static function generateOneObject(i:int):ListCollectionView_FLEX_34837_VO
+        private static function generateOneObject(index:Number):ListCollectionView_FLEX_34837_VO
         {
-            return new ListCollectionView_FLEX_34837_VO("Object"+i, "Street"+i);
+            return new ListCollectionView_FLEX_34837_VO(index, "Object", "Street");
         }
     }
 }
@@ -115,10 +151,14 @@ class ListCollectionView_FLEX_34837_VO
     [Bindable]
     public var address:ListCollectionView_FLEX_34837_AddressVO;
 
-    public function ListCollectionView_FLEX_34837_VO(name:String, street:String)
+    [Bindable]
+    public var index:Number;
+
+    public function ListCollectionView_FLEX_34837_VO(index:Number, namePrefix:String, streetPrefix:String)
     {
-        this.name = name;
-        this.address = new ListCollectionView_FLEX_34837_AddressVO(street);
+        this.index = index;
+        this.name = namePrefix + index;
+        this.address = new ListCollectionView_FLEX_34837_AddressVO(streetPrefix + index);
     }
 }
 


Mime
View raw message