flex-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mih...@apache.org
Subject [03/10] git commit: [flex-sdk] [refs/heads/develop] - FLEX-34852 Added another test class to test the basic functionality of sorting (using simple fields). That's because we have to make sure that we don't break existing functionality when adding the fea
Date Fri, 22 May 2015 17:02:15 GMT
FLEX-34852 Added another test class to test the basic functionality of sorting (using simple
fields). That's because we have to make sure that we don't break existing functionality when
adding the feature of sorting by complex fields. Currently all functions 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/cae5f406
Tree: http://git-wip-us.apache.org/repos/asf/flex-sdk/tree/cae5f406
Diff: http://git-wip-us.apache.org/repos/asf/flex-sdk/diff/cae5f406

Branch: refs/heads/develop
Commit: cae5f406e03038adda172b405ac91ffedf5d70fb
Parents: 19cdb39
Author: Mihai Chira <mihaic@apache.org>
Authored: Fri May 22 13:12:43 2015 +0200
Committer: Mihai Chira <mihaic@apache.org>
Committed: Fri May 22 18:17:50 2015 +0200

----------------------------------------------------------------------
 .../tests/ListCollectionView_Sort_Tests.as      | 389 +++++++++++++++++++
 1 file changed, 389 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/flex-sdk/blob/cae5f406/frameworks/projects/framework/tests/ListCollectionView_Sort_Tests.as
----------------------------------------------------------------------
diff --git a/frameworks/projects/framework/tests/ListCollectionView_Sort_Tests.as b/frameworks/projects/framework/tests/ListCollectionView_Sort_Tests.as
new file mode 100644
index 0000000..49da81a
--- /dev/null
+++ b/frameworks/projects/framework/tests/ListCollectionView_Sort_Tests.as
@@ -0,0 +1,389 @@
+////////////////////////////////////////////////////////////////////////////////
+//
+//  Licensed to the Apache Software Foundation (ASF) under one or more
+//  contributor license agreements.  See the NOTICE file distributed with
+//  this work for additional information regarding copyright ownership.
+//  The ASF licenses this file to You under the Apache License, Version 2.0
+//  (the "License"); you may not use this file except in compliance with
+//  the License.  You may obtain a copy of the License at
+//
+//      http://www.apache.org/licenses/LICENSE-2.0
+//
+//  Unless required by applicable law or agreed to in writing, software
+//  distributed under the License is distributed on an "AS IS" BASIS,
+//  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+//  See the License for the specific language governing permissions and
+//  limitations under the License.
+//
+////////////////////////////////////////////////////////////////////////////////
+
+package {
+    import mx.collections.ArrayList;
+    import mx.collections.IList;
+    import mx.collections.ListCollectionView;
+
+    import org.flexunit.asserts.assertEquals;
+
+    import mx.collections.Sort;
+    import mx.collections.SortField;
+
+    public class ListCollectionView_Sort_Tests {
+        private var _sut:ListCollectionView;
+
+        [Before]
+        public function setUp():void
+        {
+            _sut = new ListCollectionView(new ArrayList());
+        }
+
+        [After]
+        public function tearDown():void
+        {
+            _sut = null;
+        }
+
+        [Test]
+        public function test_numeric_descending_sort_on_simple_objects():void
+        {
+            //given
+            var from0To4:IList = generateNumbers(5);
+            _sut.addAll(from0To4); //values: 0, 1, 2, 3, 4
+
+            const sortByIndexDescending:Sort = new Sort();
+            sortByIndexDescending.fields = [new SortField(null, false, true, true)];
+            _sut.sort = sortByIndexDescending;
+
+            //when
+            _sut.refresh(); //should be: 4, 3, 2, 1, 0
+
+            //then
+            assertItemsAre([4, 3, 2, 1, 0]);
+        }
+
+        [Test]
+        public function test_numeric_descending_sort_on_simple_objects_adds_new_object_in_right_place():void
+        {
+            //given
+            var from0To4:IList = generateNumbers(5);
+            _sut.addAll(from0To4); //values: 0, 1, 2, 3, 4
+
+            const sortByIndexDescending:Sort = new Sort();
+            sortByIndexDescending.fields = [new SortField(null, false, true, true)];
+            _sut.sort = sortByIndexDescending;
+            _sut.refresh(); //values: 4, 3, 2, 1, 0
+
+            //when
+            _sut.addItem(5); //should be: 5, 4, 3, 2, 1, 0
+
+            //then
+            assertItemsAre([5, 4, 3, 2, 1, 0]);
+        }
+
+        [Test]
+        public function test_numeric_descending_sort_on_simple_objects_removes_object_correctly():void
+        {
+            //given
+            var from0To4:IList = generateNumbers(5);
+            _sut.addAll(from0To4); //values: 0, 1, 2, 3, 4
+
+            const sortByIndexDescending:Sort = new Sort();
+            sortByIndexDescending.fields = [new SortField(null, false, true, true)];
+            _sut.sort = sortByIndexDescending;
+            _sut.refresh(); //values: 4, 3, 2, 1, 0
+
+            //when
+            _sut.removeItem(3); //should be: 4, 2, 1, 0
+
+            //then
+            assertItemsAre([4, 2, 1, 0]);
+        }
+
+        [Test]
+        public function test_numeric_descending_sort_on_simple_objects_removes_object_at_index_correctly():void
+        {
+            //given
+            var from0To4:IList = generateNumbers(5);
+            _sut.addAll(from0To4); //values: 0, 1, 2, 3, 4
+
+            const sortByIndexDescending:Sort = new Sort();
+            sortByIndexDescending.fields = [new SortField(null, false, true, true)];
+            _sut.sort = sortByIndexDescending;
+            _sut.refresh(); //values: 4, 3, 2, 1, 0
+
+            //when
+            _sut.removeItemAt(3); //should be: 4, 3, 2, 0
+
+            //then
+            assertItemsAre([4, 3, 2, 0]);
+        }
+
+        [Test]
+        public function test_numeric_descending_sort_on_simple_objects_moves_replaced_object_in_right_place():void
+        {
+            //given
+            var from0To4:IList = generateNumbers(5);
+            _sut.addAll(from0To4); //values: 0, 1, 2, 3, 4
+
+            const sortByIndexDescending:Sort = new Sort();
+            sortByIndexDescending.fields = [new SortField(null, false, true, true)];
+            _sut.sort = sortByIndexDescending;
+            _sut.refresh(); //values: 4, 3, 2, 1, 0
+
+            //when
+            _sut.setItemAt(100, 3); //before re-sort: 4, 3, 2, 100, 0
+
+            //then
+            assertItemsAre([100, 4, 3, 2, 0]);
+        }
+
+        [Test]
+        public function test_numeric_descending_sort_on_simple_objects_adds_new_identical_object_in_right_place():void
+        {
+            //given
+            var from0To4:IList = generateNumbers(5);
+            _sut.addAll(from0To4); //values: 0, 1, 2, 3, 4
+
+            const sortByIndexDescending:Sort = new Sort();
+            sortByIndexDescending.fields = [new SortField(null, false, true, true)];
+            _sut.sort = sortByIndexDescending;
+            _sut.refresh(); //values: 4, 3, 2, 1, 0
+
+            //when
+            _sut.addItem(3); //should be: 5, 4, 3, 2, 1, 0
+
+            //then
+            assertItemsAre([4, 3, 3, 2, 1, 0]);
+        }
+
+        [Test]
+        public function test_numeric_descending_sort_on_simple_objects_adds_new_identical_object_in_right_place_even_with_addItemAt():void
+        {
+            //given
+            var from0To4:IList = generateNumbers(5);
+            _sut.addAll(from0To4); //values: 0, 1, 2, 3, 4
+
+            const sortByIndexDescending:Sort = new Sort();
+            sortByIndexDescending.fields = [new SortField(null, false, true, true)];
+            _sut.sort = sortByIndexDescending;
+            _sut.refresh(); //values: 4, 3, 2, 1, 0
+
+            //when
+            _sut.addItemAt(3, 0); //should be: 5, 4, 3, 2, 1, 0
+
+            //then
+            assertItemsAre([4, 3, 3, 2, 1, 0]);
+        }
+
+
+        [Test]
+        public function test_numeric_descending_sort_on_complex_objects():void
+        {
+            //given
+            var from0To4:IList = generateVOs(5);
+            _sut.addAll(from0To4); //values["name"]: Object0, Object1, Object2, Object3,
Object4
+
+            const sortByIndexDescending:Sort = new Sort();
+            sortByIndexDescending.fields = [new SortField("index", false, true, true)];
+            _sut.sort = sortByIndexDescending;
+
+            //when
+            _sut.refresh(); //should be: Object4, Object3, Object2, Object1, Object0
+
+            //then
+            assertIndexesAre([4, 3, 2, 1, 0]);
+        }
+
+        [Test]
+        public function test_multiple_sort_fields_on_complex_objects():void
+        {
+            //given
+            var from0To4:IList = generateVOs(5);
+            _sut.addAll(from0To4); //values["name"]: Object0, Object1, Object2, Object3,
Object4
+            _sut.addItem(generateOneObject(2, "ABC")); //values["name"]: Object0, Object1,
Object2, Object3, Object4, ABC2
+
+            const sortByIndexDescending:Sort = new Sort();
+            sortByIndexDescending.fields = [new SortField("index", false, true, true), new
SortField("name", false, false, false)];
+            _sut.sort = sortByIndexDescending;
+
+            //when
+            _sut.refresh(); //should be: Object0, Object1, ABC2, Object2, Object3, Object4
+
+            //then
+            assertIndexesAre([4, 3, 2, 2, 1, 0]);
+            assertNamesAre(["Object4", "Object3", "ABC2", "Object2", "Object1", "Object0"]);
+        }
+
+        [Test]
+        public function test_numeric_descending_sort_on_complex_objects_adds_new_objects_in_right_place():void
+        {
+            //given
+            var from0To4:IList = generateVOs(5);
+            _sut.addAll(from0To4); //values["name"]: Object0, Object1, Object2, Object3,
Object4
+
+            const sortByIndexDescending:Sort = new Sort();
+            sortByIndexDescending.fields = [new SortField("index", false, true, true)];
+            _sut.sort = sortByIndexDescending;
+            _sut.refresh(); //values["name"]: Object4, Object3, Object2, Object1, Object0
+
+            //when
+            _sut.addItem(generateOneObject(6));
+            _sut.addItem(generateOneObject(3.5));
+
+            //then
+            assertIndexesAre([6, 4, 3.5, 3, 2, 1, 0]);
+        }
+
+        [Test]
+        public function test_numeric_descending_sort_on_complex_objects_moves_replaced_object_in_right_place():void
+        {
+            //given
+            var from0To4:IList = generateVOs(5);
+            _sut.addAll(from0To4); //values["name"]: Object0, Object1, Object2, Object3,
Object4
+
+            const sortByIndexDescending:Sort = new Sort();
+            sortByIndexDescending.fields = [new SortField("index", false, true, true)];
+            _sut.sort = sortByIndexDescending;
+            _sut.refresh(); //values["name"]: Object4, Object3, Object2, Object1, Object0
+
+            //when
+            _sut.setItemAt(generateOneObject(6), 1);
+
+            //then
+            assertIndexesAre([6, 4, 2, 1, 0]);
+        }
+
+        [Test]
+        public function test_simple_numeric_ascending_sort_on_complex_objects():void
+        {
+            //given
+            var from4To0:IList = generateVOs(5, true);
+            _sut.addAll(from4To0); //values["name"]: Object4, Object3, Object2, Object1,
Object0
+
+            const sortByIndexAscending:Sort = new Sort();
+            sortByIndexAscending.fields = [new SortField("index", false, false, true)];
+            _sut.sort = sortByIndexAscending;
+
+            //when
+            _sut.refresh(); //should be: Object0, Object1, Object2, Object3, Object4
+
+            //then
+            assertIndexesAre([0, 1, 2, 3, 4]);
+        }
+
+        [Test(description="Testing that changing the properties of the Sort doesn't impact
the actual sort order")]
+        public function test_sort_fields_on_complex_objects_dont_change_unless_sort_reapplied():void
+        {
+            //given
+            var from4To0:IList = generateVOs(5, true);
+            _sut.addAll(from4To0); //values["name"]: Object4, Object3, Object2, Object1,
Object0
+
+            const sortByIndexAscending:Sort = new Sort();
+            sortByIndexAscending.fields = [new SortField("index", false, false, true)];
+            _sut.sort = sortByIndexAscending;
+            _sut.refresh(); //should be: Object0, Object1, Object2, Object3, Object4
+
+            //when
+            sortByIndexAscending.fields = [new SortField("name", false, true, false)]; //should
have no effect
+
+            //then
+            assertIndexesAre([0, 1, 2, 3, 4]);
+        }
+
+        private function assertIndexesAre(indexes:Array):void
+        {
+            assertFieldValuesAre("index", indexes);
+        }
+
+        private function assertNamesAre(names:Array):void
+        {
+            assertFieldValuesAre("name", names);
+        }
+
+        private function assertFieldValuesAre(field:String, values:Array):void
+        {
+            assertEquals(values.length, _sut.length);
+
+            for(var i:int = 0; i < _sut.length; i++)
+            {
+                assertEquals(ListCollectionView_Sort_VO(_sut.getItemAt(i))[field], values[i]);
+            }
+        }
+
+
+
+        private function assertItemsAre(indexes:Array):void
+        {
+            assertEquals(indexes.length, _sut.length);
+
+            for(var i:int = 0; i < _sut.length; i++)
+            {
+                assertEquals(indexes[i], _sut.getItemAt(i));
+            }
+        }
+
+
+        private static function generateVOs(no:int, reverse:Boolean = false):IList
+        {
+            return generateObjects(no, reverse, generateOneObject);
+        }
+
+        private static function generateNumbers(no:int, reverse:Boolean = false):IList
+        {
+            return generateObjects(no, reverse, generateOneNumber);
+        }
+
+        private static function generateObjects(no:int, reverse:Boolean = false, generator:Function
= null):IList
+        {
+            var result:Array = [];
+            for(var i:int = 0; i < no; i++)
+            {
+                result.push(generator(i));
+            }
+
+            if(reverse)
+                result.reverse();
+
+            return new ArrayList(result);
+        }
+
+        private static function generateOneObject(index:Number, name:String = "Object"):ListCollectionView_Sort_VO
+        {
+            return new ListCollectionView_Sort_VO(index, name, "Street");
+        }
+
+        private static function generateOneNumber(value:Number):Number
+        {
+            return value;
+        }
+    }
+}
+
+class ListCollectionView_Sort_VO
+{
+    [Bindable]
+    public var name:String;
+
+    [Bindable]
+    public var address:ListCollectionView_Sort_AddressVO;
+
+    [Bindable]
+    public var index:Number;
+
+    public function ListCollectionView_Sort_VO(index:Number, namePrefix:String, streetPrefix:String)
+    {
+        this.index = index;
+        this.name = namePrefix + index;
+        this.address = new ListCollectionView_Sort_AddressVO(streetPrefix + index);
+    }
+}
+
+class ListCollectionView_Sort_AddressVO
+{
+    [Bindable]
+    public var street:String;
+
+    public function ListCollectionView_Sort_AddressVO(street:String)
+    {
+        this.street = street;
+    }
+}
\ No newline at end of file


Mime
View raw message