FLEX-34854 FLEX-34884 Added more unit tests, mostly about sorting with two SortFields. NOTE that getItemIndex_finds_newly_inserted_item_in_complex_multi_field_sorted_list() fails. Debugging in process.
Project: http://git-wip-us.apache.org/repos/asf/flex-sdk/repo Commit: http://git-wip-us.apache.org/repos/asf/flex-sdk/commit/9485397f Tree: http://git-wip-us.apache.org/repos/asf/flex-sdk/tree/9485397f Diff: http://git-wip-us.apache.org/repos/asf/flex-sdk/diff/9485397f Branch: refs/heads/develop Commit: 9485397fc9fe9d956df2a60b76db335274ab1390 Parents: f46e308 Author: Mihai Chira <mih...@apache.org> Authored: Thu Jul 16 21:19:35 2015 +0200 Committer: Mihai Chira <mih...@apache.org> Committed: Thu Jul 16 21:19:35 2015 +0200 ---------------------------------------------------------------------- .../framework/tests/FLEX_34884_Tests.as | 118 ++++++++++++++++++- 1 file changed, 115 insertions(+), 3 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/flex-sdk/blob/9485397f/frameworks/projects/framework/tests/FLEX_34884_Tests.as ---------------------------------------------------------------------- diff --git a/frameworks/projects/framework/tests/FLEX_34884_Tests.as b/frameworks/projects/framework/tests/FLEX_34884_Tests.as index c1bea32..d42b1df 100644 --- a/frameworks/projects/framework/tests/FLEX_34884_Tests.as +++ b/frameworks/projects/framework/tests/FLEX_34884_Tests.as @@ -111,6 +111,30 @@ package { } [Test] + public function getItemIndex_finds_item_in_descending_two_sort_fields_sorted_list_after_changing_one_field():void + { + //given + var from0To4:IList = generateVOs(5); + _sut.addAll(from0To4); //index/name: 0/Object0, 1/Object1, 2/Object2, 3/Object3, 4/Object4 + + const sortByIndexDescending:Sort = new Sort(); + sortByIndexDescending.fields = [new SortField("index", true, true), new SortField("name", false, false)]; + _sut.sort = sortByIndexDescending; + _sut.refresh(); //index/name: 4/Object4, 3/Object3, 2/Object2, 1/Object1, 0/Object0 + + //when + var item1:FLEX_34884_VO = from0To4.getItemAt(1) as FLEX_34884_VO; + item1.index = 0; //index/name: 4/Object4, 3/Object3, 2/Object2, 0/Object0, 0/Object1 + + var item2:FLEX_34884_VO = from0To4.getItemAt(2) as FLEX_34884_VO; + item2.index = 0; //index/name: 4/Object4, 3/Object3, 0/Object0, 0/Object1, 0/Object2 + + //then + assertEquals(_sut.length - 1, _sut.getItemIndex(item2)); + assertEquals(_sut.length - 2, _sut.getItemIndex(item1)); + } + + [Test] public function getItemIndex_finds_second_to_last_item_in_simple_no_fields_non_unique_sorted_list():void { //given @@ -245,6 +269,71 @@ package { } [Test] + public function getItemIndex_finds_item_in_complex_multi_field_sorted_non_filtered_list():void + { + //given + var from0To4:IList = generateVOs(5); + _sut.addAll(from0To4); //index / address.street: 0/Street0, 1/Street1, 2/Street2, 3/Street3, 4/Street4 + + const sortByStreetAndIndex:Sort = new Sort(); + sortByStreetAndIndex.fields = [new ComplexSortField("address.street", false, true, false), new SortField("index", false, true)]; + _sut.sort = sortByStreetAndIndex; + _sut.refresh(); //index / address.street: 4/Street4, 3/Street3, 2/Street2, 1/Street1, 0/Street0 + + _sut.complexFieldWatcher = new ComplexFieldChangeWatcher(); + + //when + var item0:FLEX_34884_VO = from0To4.getItemAt(0) as FLEX_34884_VO; + item0.address.street = "Street4"; //index / address.street: 0/Street4, 4/Street4, 3/Street3, 2/Street2, 1/Street1 + + var item1:FLEX_34884_VO = from0To4.getItemAt(1) as FLEX_34884_VO; + item1.address.street = "Street4"; //index / address.street: 0/Street4, 1/Street4, 4/Street4, 3/Street3, 2/Street2 + item1.index = 9; //index / address.street: 0/Street4, 4/Street4, 9/Street4, 3/Street3, 2/Street2 + + //then + assertEquals(0, _sut.getItemIndex(item0)); + assertEquals(2, _sut.getItemIndex(item1)); + } + + [Test] + public function getItemIndex_finds_item_in_complex_multi_field_sorted_filtered_list():void + { + function excludeIndexesAbove4(item:Object):Boolean + { + return FLEX_34884_VO(item).index <= 4; + } + + //given + var from0To4:IList = generateVOs(5); + _sut.addAll(from0To4); //index / address.street: 0/Street0, 1/Street1, 2/Street2, 3/Street3, 4/Street4 + + const sortByStreetAndIndex:Sort = new Sort(); + sortByStreetAndIndex.fields = [new ComplexSortField("address.street", false, true, false), new SortField("index", false, true)]; + _sut.sort = sortByStreetAndIndex; + + _sut.refresh(); //index / address.street: 4/Street4, 3/Street3, 2/Street2, 1/Street1, 0/Street0 + + _sut.complexFieldWatcher = new ComplexFieldChangeWatcher(); + + //when + var item0:FLEX_34884_VO = from0To4.getItemAt(0) as FLEX_34884_VO; + item0.address.street = "Street4"; //index / address.street: 0/Street4, 4/Street4, 3/Street3, 2/Street2, 1/Street1 + + var item1:FLEX_34884_VO = from0To4.getItemAt(1) as FLEX_34884_VO; + item1.address.street = "Street4"; //index / address.street: 0/Street4, 1/Street4, 4/Street4, 3/Street3, 2/Street2 + item1.index = 9; //index / address.street: 0/Street4, 4/Street4, 9/Street4, 3/Street3, 2/Street2 + + _sut.filterFunction = excludeIndexesAbove4; + _sut.refresh(); //index / address.street: 0/Street4, 4/Street4, 3/Street3, 2/Street2 + + //then + assertEquals(0, _sut.getItemIndex(item0)); + assertEquals(-1, _sut.getItemIndex(item1)); + var item3:FLEX_34884_VO = from0To4.getItemAt(3) as FLEX_34884_VO; + assertEquals(2, _sut.getItemIndex(item3)); + } + + [Test] public function getItemIndex_finds_item_in_complex_descending_sorted_list_after_its_repositioned_due_to_its_sort_field_changing():void { //given @@ -301,9 +390,9 @@ package { var from0To4:IList = generateVOs(5); _sut.addAll(from0To4); //values[address.street]: Street0, Street1, Street2, Street3, Street4 - const sortByIndexDescending:Sort = new Sort(); - sortByIndexDescending.fields = [new ComplexSortField("address.street", false, true, false)]; - _sut.sort = sortByIndexDescending; + const sortByStreetDescending:Sort = new Sort(); + sortByStreetDescending.fields = [new ComplexSortField("address.street", false, true, false)]; + _sut.sort = sortByStreetDescending; _sut.refresh(); //values[address.street]: Street4, Street3, Street2, Street1, Street0 _sut.complexFieldWatcher = new ComplexFieldChangeWatcher(); @@ -317,6 +406,29 @@ package { } [Test] + public function getItemIndex_finds_newly_inserted_item_in_complex_multi_field_sorted_list():void + { + //given + var from0To4:IList = generateVOs(5); + _sut.addAll(from0To4); //values[address.street/index]: Street0/0, Street1/1, Street2/2, Street3/3, Street4/4 + + const sortByStreetAndIndex:Sort = new Sort(); + sortByStreetAndIndex.fields = [new ComplexSortField("address.street", false, true, false), new SortField("index", false, true)]; + _sut.sort = sortByStreetAndIndex; + _sut.refresh(); //values[address.street/index]: Street4/4, Street3/3, Street2/2, Street1/1, Street0/0 + + _sut.complexFieldWatcher = new ComplexFieldChangeWatcher(); + + //when + var newItem:FLEX_34884_VO = generateOneObject(9); + newItem.address.street = "Street 4"; + _sut.addItemAt(newItem, _sut.length - 1); //values[address.street/index]: Street4/4, Street4/9, Street3/3, Street2/2, Street1/1, Street0/0 + + //then + assertEquals(1, _sut.getItemIndex(newItem)); + } + + [Test] public function getItemIndex_finds_newly_inserted_item_in_complex_descending_sorted_list_after_its_sort_field_changes():void { //given