Repository: flex-sdk Updated Branches: refs/heads/develop 11489c6e7 -> 94dd74615
FLEX-34852 Added unit test (actually moved the first function from ListCollectionView_FLEX_34837_Tests, as it's better suited for this ticket). Because the feature is not implemented, it currently fails. Project: http://git-wip-us.apache.org/repos/asf/flex-sdk/repo Commit: http://git-wip-us.apache.org/repos/asf/flex-sdk/commit/7cd1b3bc Tree: http://git-wip-us.apache.org/repos/asf/flex-sdk/tree/7cd1b3bc Diff: http://git-wip-us.apache.org/repos/asf/flex-sdk/diff/7cd1b3bc Branch: refs/heads/develop Commit: 7cd1b3bc69f11c6c9d88a65e0df9eae39a17afa3 Parents: 11489c6 Author: Mihai Chira <[email protected]> Authored: Sun Jun 7 12:53:06 2015 +0200 Committer: Mihai Chira <[email protected]> Committed: Sun Jun 7 12:53:06 2015 +0200 ---------------------------------------------------------------------- .../framework/tests/FLEX_34852_Tests.as | 129 +++++++++++++++++++ .../ListCollectionView_FLEX_34837_Tests.as | 18 --- 2 files changed, 129 insertions(+), 18 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/flex-sdk/blob/7cd1b3bc/frameworks/projects/framework/tests/FLEX_34852_Tests.as ---------------------------------------------------------------------- diff --git a/frameworks/projects/framework/tests/FLEX_34852_Tests.as b/frameworks/projects/framework/tests/FLEX_34852_Tests.as new file mode 100644 index 0000000..3a66221 --- /dev/null +++ b/frameworks/projects/framework/tests/FLEX_34852_Tests.as @@ -0,0 +1,129 @@ +//////////////////////////////////////////////////////////////////////////////// +// +// 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 mx.collections.Sort; + import mx.collections.SortField; + + import org.flexunit.asserts.assertEquals; + + public class FLEX_34852_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_simple_ascending_sort_by_complex_fields():void + { + //given + 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]); + } + + + + private function assertIndexesAre(indexes:Array):void + { + assertEquals(indexes.length, _sut.length); + + for(var i:int = 0; i < _sut.length; i++) + { + assertEquals(FLEX_34852_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.push(generator(i)); + } + + if(reverse) + result.reverse(); + + return new ArrayList(result); + } + + private static function generateOneObject(i:Number):FLEX_34852_VO + { + return new FLEX_34852_VO(i, "Object"+i, "Street"+i); + } + } +} + +class FLEX_34852_VO +{ + [Bindable] + public var name:String; + + [Bindable] + public var address:FLEX_34852_AddressVO; + + [Bindable] + public var index:Number; + + public function FLEX_34852_VO(index:Number, namePrefix:String, streetPrefix:String) + { + this.index = index; + this.name = namePrefix + index; + this.address = new FLEX_34852_AddressVO(streetPrefix + index); + } +} + +class FLEX_34852_AddressVO +{ + [Bindable] + public var street:String; + + public function FLEX_34852_AddressVO(street:String) + { + this.street = street; + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/flex-sdk/blob/7cd1b3bc/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 f11e906..ae8f746 100644 --- a/frameworks/projects/framework/tests/ListCollectionView_FLEX_34837_Tests.as +++ b/frameworks/projects/framework/tests/ListCollectionView_FLEX_34837_Tests.as @@ -43,24 +43,6 @@ package { } [Test] - public function test_simple_ascending_sort_by_complex_fields():void - { - //given - 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_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
