flex-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mih...@apache.org
Subject [06/10] git commit: [flex-sdk] [refs/heads/develop] - FLEX-34837 Added two more test functions to make sure that sorting with a custom compare function works well despite using a SortField with a complex field for its name. They do pass, indeed.
Date Fri, 22 May 2015 17:02:18 GMT
FLEX-34837 Added two more test functions to make sure that sorting with a custom compare function
works well despite using a SortField with a complex field for its name. They do pass, indeed.


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

Branch: refs/heads/develop
Commit: 4e62c7c7db69b196f38588d7e036c9352bf0d54f
Parents: d7272f3
Author: Mihai Chira <mihaic@apache.org>
Authored: Fri May 22 13:38:54 2015 +0200
Committer: Mihai Chira <mihaic@apache.org>
Committed: Fri May 22 18:19:51 2015 +0200

----------------------------------------------------------------------
 .../ListCollectionView_FLEX_34837_Tests.as      | 60 +++++++++++++++++++-
 1 file changed, 58 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/flex-sdk/blob/4e62c7c7/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 d069b90..2ebf97f 100644
--- a/frameworks/projects/framework/tests/ListCollectionView_FLEX_34837_Tests.as
+++ b/frameworks/projects/framework/tests/ListCollectionView_FLEX_34837_Tests.as
@@ -23,6 +23,7 @@ package {
     import mx.collections.ListCollectionView;
     import mx.collections.Sort;
     import mx.collections.SortField;
+    import mx.utils.ObjectUtil;
 
     import org.flexunit.asserts.assertEquals;
 
@@ -60,6 +61,61 @@ package {
         }
 
         [Test]
+        public function test_simple_sort_by_complex_fields_with_custom_compare_function_for_sort():void
+        {
+            function compareByStreet(a:ListCollectionView_FLEX_34837_VO, b:ListCollectionView_FLEX_34837_VO,
fields:Array):int
+            {
+                var streetA:String = a.address ? a.address.street : null;
+                var streetB:String = b.address ? b.address.street : null;
+
+                return ObjectUtil.stringCompare(streetA, streetB, true);
+            }
+
+            //given
+            var from4To0:IList = generateVOs(5, true);
+            _sut.addAll(from4To0); //values["address.street"]: Street4, Street3, Street2,
Street1, Street0
+
+            const sortByStreetAscending:Sort = new Sort();
+            sortByStreetAscending.fields = [new SortField("address.street", false, false,
false)]; //should make no difference
+            sortByStreetAscending.compareFunction = compareByStreet;
+            _sut.sort = sortByStreetAscending;
+
+            //when
+            _sut.refresh(); //should be: Street0, Street1, Street2, Street3, Street4
+
+            //then
+            assertIndexesAre([0, 1, 2, 3, 4]);
+        }
+
+        [Test]
+        public function test_simple_sort_by_complex_fields_with_custom_compare_function_for_sort_field():void
+        {
+            function compareByStreet(a:ListCollectionView_FLEX_34837_VO, b:ListCollectionView_FLEX_34837_VO):int
+            {
+                var streetA:String = a.address ? a.address.street : null;
+                var streetB:String = b.address ? b.address.street : null;
+
+                return ObjectUtil.stringCompare(streetA, streetB, true);
+            }
+
+            //given
+            var from4To0:IList = generateVOs(5, true);
+            _sut.addAll(from4To0); //values["address.street"]: Street4, Street3, Street2,
Street1, Street0
+
+            const sortByStreetAscending:Sort = new Sort();
+            var sortField:SortField = new SortField("address.street", false, false, false);
+            sortField.compareFunction = compareByStreet;
+            sortByStreetAscending.fields = [sortField];
+            _sut.sort = sortByStreetAscending;
+
+            //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
@@ -68,7 +124,7 @@ package {
             _sut.addAll(from1To4);
 
             const sortByNameAscending:Sort = new Sort();
-            sortByNameAscending.fields = [new SortField("name", false, false)];
+            sortByNameAscending.fields = [new SortField("name", false, false, false)];
             _sut.sort = sortByNameAscending;
             _sut.refresh(); //values: Object1, Object2, Object3, Object4
 
@@ -91,7 +147,7 @@ package {
             _sut.addAll(from1To4);
 
             const sortByNameAscending:Sort = new Sort();
-            sortByNameAscending.fields = [new SortField("address.street", false, false)];
+            sortByNameAscending.fields = [new SortField("address.street", false, false, false)];
             _sut.sort = sortByNameAscending;
             _sut.refresh(); //values: Object1, Object2, Object3, Object4
 


Mime
View raw message