FLEX-35031 Added more unit tests to define how findAny() and findLast() should work, for when I attempt fixes for this bug. -Making sure that they return different values when there are two objects in the collection view with the same property and value for that property (currently they do). -Made the ids unique for the EmployeeVOs, which makes it easier to index them and use them in tests.
Project: http://git-wip-us.apache.org/repos/asf/flex-sdk/repo Commit: http://git-wip-us.apache.org/repos/asf/flex-sdk/commit/6a26ebb0 Tree: http://git-wip-us.apache.org/repos/asf/flex-sdk/tree/6a26ebb0 Diff: http://git-wip-us.apache.org/repos/asf/flex-sdk/diff/6a26ebb0 Branch: refs/heads/develop Commit: 6a26ebb072bff4c808eeda359dc0f17fac386527 Parents: d072e9e Author: Mihai Chira <[email protected]> Authored: Tue Feb 16 14:00:03 2016 +0100 Committer: Mihai Chira <[email protected]> Committed: Tue Feb 16 14:00:03 2016 +0100 ---------------------------------------------------------------------- ...rchicalCollectionViewCursor_FindAny_Tests.as | 67 ++++++++++++++------ 1 file changed, 48 insertions(+), 19 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/flex-sdk/blob/6a26ebb0/frameworks/projects/advancedgrids/tests/mx/collections/HierarchicalCollectionViewCursor_FindAny_Tests.as ---------------------------------------------------------------------- diff --git a/frameworks/projects/advancedgrids/tests/mx/collections/HierarchicalCollectionViewCursor_FindAny_Tests.as b/frameworks/projects/advancedgrids/tests/mx/collections/HierarchicalCollectionViewCursor_FindAny_Tests.as index 36708d0..b5e9b90 100644 --- a/frameworks/projects/advancedgrids/tests/mx/collections/HierarchicalCollectionViewCursor_FindAny_Tests.as +++ b/frameworks/projects/advancedgrids/tests/mx/collections/HierarchicalCollectionViewCursor_FindAny_Tests.as @@ -27,11 +27,14 @@ package mx.collections { { private static const DEPARTMENT_SALES:String = "Sales"; private static const DEPARTMENT_DEVELOPMENT:String = "Development"; - private static const NO_ITEMS_PER_GRID_HEIGHT:int = 5; + private static const NO_EMPLOYEES_PER_DEPARTMENT:int = 5; + private static const NO_DEPARTMENTS:int = 2; + private static const NO_EMPLOYEES:int = NO_EMPLOYEES_PER_DEPARTMENT * NO_DEPARTMENTS; private static const _utils:HierarchicalCollectionViewTestUtils = new HierarchicalCollectionViewTestUtils(); private static var _collectionView:HierarchicalCollectionView; private static var _sut:HierarchicalCollectionViewCursor; private static var _level0:ArrayCollection; + private static var _employeesByID:Array = []; [Before] public function setUp():void @@ -241,36 +244,65 @@ package mx.collections { public function test_findAny_finds_sealed_class_instance_via_anonymous_object_with_subset_of_properties():void { //given - const ID_TO_FIND:int = 1; + const ID_TO_FIND:int = NO_EMPLOYEES_PER_DEPARTMENT; _utils.openAllNodes(_collectionView); //when - var found:Boolean = _sut.findAny({department:DEPARTMENT_SALES, idInDepartment:ID_TO_FIND}); + var found:Boolean = _sut.findAny({department:DEPARTMENT_SALES, uniqueID:ID_TO_FIND}); //then assertTrue(found); var currentEmployee:EmployeeVO = _sut.current as EmployeeVO; assertNotNull(currentEmployee); assertEquals(DEPARTMENT_SALES, currentEmployee.department); - assertEquals(ID_TO_FIND, currentEmployee.idInDepartment); + assertEquals(ID_TO_FIND, currentEmployee.uniqueID); } [Test] public function test_findLast_finds_sealed_class_instance_via_anonymous_object_with_subset_of_properties():void { //given - const ID_TO_FIND:int = 1; + const ID_TO_FIND:int = 0; _utils.openAllNodes(_collectionView); //when - var found:Boolean = _sut.findLast({department:DEPARTMENT_DEVELOPMENT, idInDepartment:ID_TO_FIND}); + var found:Boolean = _sut.findLast({department:DEPARTMENT_DEVELOPMENT, uniqueID:ID_TO_FIND}); //then assertTrue(found); var currentEmployee:EmployeeVO = _sut.current as EmployeeVO; assertNotNull(currentEmployee); assertEquals(DEPARTMENT_DEVELOPMENT, currentEmployee.department); - assertEquals(ID_TO_FIND, currentEmployee.idInDepartment); + assertEquals(ID_TO_FIND, currentEmployee.uniqueID); + } + + [Test] + public function test_findLast_finds_different_object_to_findFirst_via_anonymous_object_with_subset_of_properties():void + { + //given + _utils.openAllNodes(_collectionView); + + var secondEmployee:EmployeeVO = _employeesByID[1] as EmployeeVO; + var secondToLastEmployee:EmployeeVO = _employeesByID[NO_EMPLOYEES - 2] as EmployeeVO; + + const sameName:String = "John"; + + //when + secondEmployee.name = sameName; + secondToLastEmployee.name = sameName; + + var foundFromBeginning:Boolean = _sut.findAny({name:sameName}); + + //then + assertTrue(foundFromBeginning); + assertEquals(secondEmployee, _sut.current); + + //when + var foundFromEnd:Boolean = _sut.findLast({name:sameName}); + + //then + assertTrue(foundFromEnd); + assertEquals(secondToLastEmployee, _sut.current); } private static function createHierarchicalCollectionView(groupingCollection:GroupingCollection2):HierarchicalCollectionView @@ -281,22 +313,19 @@ package mx.collections { private static function createEmployees():ArrayCollection { var result:ArrayCollection = new ArrayCollection(); - for (var i:int = 0; i < NO_ITEMS_PER_GRID_HEIGHT - 1; i++) - { - result.addItem(createEmployee("Emp-" + DEPARTMENT_DEVELOPMENT + "-" + i, DEPARTMENT_DEVELOPMENT, i)); - } - - for (i = 0; i < NO_ITEMS_PER_GRID_HEIGHT - 1; i++) + for (var i:int = 0; i < NO_EMPLOYEES_PER_DEPARTMENT * 2; i++) { - result.addItem(createEmployee("Emp-" + DEPARTMENT_SALES + "-" + i, DEPARTMENT_SALES, i)); + result.addItem(createEmployee("Emp-" + i, (i < NO_EMPLOYEES_PER_DEPARTMENT ? DEPARTMENT_DEVELOPMENT : DEPARTMENT_SALES), i)); } return result; } - private static function createEmployee(name:String, department:String, idInDepartment:int):EmployeeVO + private static function createEmployee(name:String, department:String, uniqueID:int):EmployeeVO { - return new EmployeeVO(name, department, idInDepartment); + var employeeVO:EmployeeVO = new EmployeeVO(name, department, uniqueID); + _employeesByID[employeeVO.uniqueID] = employeeVO; + return employeeVO; } private static function createGroupingCollection(source:ArrayCollection):GroupingCollection2 @@ -318,12 +347,12 @@ class EmployeeVO { public var name:String; public var department:String; - public var idInDepartment:int; + public var uniqueID:int; - public function EmployeeVO(name:String, department:String, idInDepartment:int) + public function EmployeeVO(name:String, department:String, uniqueID:int) { this.name = name; this.department = department; - this.idInDepartment = idInDepartment; + this.uniqueID = uniqueID; } } \ No newline at end of file
