Skip to content

Commit

Permalink
Merge branch 'FLEX-34837' into develop
Browse files Browse the repository at this point in the history
Conflicts:
	frameworks/projects/framework/tests/ListCollectionView_FLEX_34837_Tests.as
  • Loading branch information
evolverine committed May 22, 2015
2 parents ab0805a + 9c40493 commit e80b203
Show file tree
Hide file tree
Showing 9 changed files with 608 additions and 36 deletions.
4 changes: 4 additions & 0 deletions frameworks/build.xml
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@
<antcall target="apache-test"/>
<antcall target="spark-test"/>
<antcall target="advancedgrids-test"/>
<antcall target="framework-test"/>
</target>

<target name="flex-config" depends="playerglobal-setswfversion" description="Copy the flex/air/airmobile config templates to flex/air/airmobile-config.xml and inject version numbers">
Expand Down Expand Up @@ -526,6 +527,9 @@
<target name="advancedgrids-test" description="Tests for 'advancedgrids' project">
<ant dir="${basedir}/projects/advancedgrids" target="test"/>
</target>
<target name="framework-test" description="Tests for 'framework' project">
<ant dir="${basedir}/projects/framework" target="test"/>
</target>

<target name="experimental" description="Clean build of experimental.swc">
<ant dir="${basedir}/projects/experimental"/>
Expand Down
6 changes: 6 additions & 0 deletions frameworks/projects/framework/build.xml
Original file line number Diff line number Diff line change
Expand Up @@ -321,4 +321,10 @@
<delete dir="${FLEX_HOME}/tempDoc" failonerror="false" includeEmptyDirs="true"/>
<delete file="${basedir}/bundles/en_US/packages.dita" failonerror="false"/>
</target>

<target name="test" description="Runs the FlexUnit tests for this project">
<ant antfile="${FLEX_HOME}/flexunit-tests.xml">
<property name="project.root" value="${basedir}"/>
</ant>
</target>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@
package mx.binding.utils
{

import mx.binding.utils.ChangeWatcher;

/**
* The BindingUtils class defines utility methods
* for performing data binding from ActionScript.
Expand Down Expand Up @@ -158,7 +156,7 @@ public class BindingUtils
* The <code>host</code> maintains a list of <code>setters</code> to update
* when <code>prop</code> changes.
*
* @param name The name of the property, or property chain.
* @param chain The name of the property, or property chain.
* See the <code>bindProperty()</code> method for more information.
*
* @param commitOnly Set to <code>true</code> if the handler should be
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ public class ChangeWatcher
/**
* Lets you determine if an Object has any properties.
*
* @param Object to inspect.
* @param obj to inspect.
*
* @return <code>true</code> if Object has no properties.
*
Expand Down
2 changes: 1 addition & 1 deletion frameworks/projects/framework/src/mx/collections/ISort.as
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ public interface ISort
* The function cannot determine a definitive answer if the sort uses a
* custom comparator; it always returns <code>true</code> in this case.
*
* @param property The name of the field that to test.
* @param property The name of the field to test.
* @return Whether the property value might affect the sort outcome.
* If the sort uses the default compareFunction, returns
* <code>true</code> if the
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1450,7 +1450,7 @@ public class ListCollectionView extends Proxy
if (updatedItems[j].item == item)
{
// even if it is, if a different property changed, track that too.
var evts:Array = updatedItems[j].events;
var evts:Array = updatedItems[j].events as Array;
var l:int = evts.length;
for (var k:int = 0; k < l; k++)
{
Expand Down
21 changes: 9 additions & 12 deletions frameworks/projects/framework/src/mx/collections/SortField.as
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,15 @@
package mx.collections
{

import flash.events.Event;
import flash.events.EventDispatcher;
import mx.collections.errors.SortError;
import mx.managers.ISystemManager;
import mx.managers.SystemManager;
import mx.resources.IResourceManager;
import mx.resources.ResourceManager;
import mx.utils.ObjectUtil;
import mx.collections.SortFieldCompareTypes;

[ResourceBundle("collections")]
import flash.events.Event;
import flash.events.EventDispatcher;

import mx.collections.errors.SortError;
import mx.resources.IResourceManager;
import mx.resources.ResourceManager;
import mx.utils.ObjectUtil;

[ResourceBundle("collections")]
[Alternative(replacement="spark.collections.SortField", since="4.5")]

/**
Expand Down Expand Up @@ -659,7 +657,6 @@ public class SortField extends EventDispatcher implements ISortField

private function nullCompare(a:Object, b:Object):int
{
var value:Object;
var left:Object;
var right:Object;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@ package {
import mx.collections.ArrayList;
import mx.collections.IList;
import mx.collections.ListCollectionView;
import mx.collections.Sort;
import mx.collections.SortField;
import mx.utils.ObjectUtil;

import org.flexunit.asserts.assertEquals;

import spark.collections.Sort;
import spark.collections.SortField;

public class ListCollectionView_FLEX_34837_Tests {
private var _sut:ListCollectionView;

Expand All @@ -43,15 +43,88 @@ 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_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
var from1To4:IList = generateVOs(5);
from1To4.removeItemAt(0);
_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

Expand All @@ -69,12 +142,12 @@ 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);

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

Expand All @@ -85,24 +158,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(i:Number):ListCollectionView_FLEX_34837_VO
{
return new ListCollectionView_FLEX_34837_VO("Object"+i, "Street"+i);
return new ListCollectionView_FLEX_34837_VO(i, "Object"+i, "Street"+i);
}
}
}
Expand All @@ -115,10 +207,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);
}
}

Expand Down
Loading

0 comments on commit e80b203

Please sign in to comment.