You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@flex.apache.org by mi...@apache.org on 2014/08/11 13:41:54 UTC
[12/19] git commit: [flex-sdk] [refs/heads/develop] - FLEX-34424
Added a unit test to reproduce FLEX-34424. As expected,
it is currently failing. Also added a few more tests to
HierarchicalCollectionViewCursor_Basics_Test to do with the deletion of nodes
FLEX-34424 Added a unit test to reproduce FLEX-34424. As expected, it is currently failing.
Also added a few more tests to HierarchicalCollectionViewCursor_Basics_Test to do with the deletion of nodes. These are currently passing.
Project: http://git-wip-us.apache.org/repos/asf/flex-sdk/repo
Commit: http://git-wip-us.apache.org/repos/asf/flex-sdk/commit/4970df88
Tree: http://git-wip-us.apache.org/repos/asf/flex-sdk/tree/4970df88
Diff: http://git-wip-us.apache.org/repos/asf/flex-sdk/diff/4970df88
Branch: refs/heads/develop
Commit: 4970df88bea72d134a53c4a5ceddf236db7dde84
Parents: c2e68dc
Author: Mihai Chira <mi...@apache.org>
Authored: Mon Jul 28 15:57:26 2014 +0100
Committer: Mihai Chira <mi...@apache.org>
Committed: Mon Jul 28 16:03:01 2014 +0100
----------------------------------------------------------------------
...rarchicalCollectionViewCursor_Basics_Test.as | 81 +++++++++++-
...hicalCollectionViewCursor_FLEX_34424_Test.as | 126 +++++++++++++++++++
2 files changed, 205 insertions(+), 2 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/flex-sdk/blob/4970df88/frameworks/tests/unitTests/mx/collections/HierarchicalCollectionViewCursor_Basics_Test.as
----------------------------------------------------------------------
diff --git a/frameworks/tests/unitTests/mx/collections/HierarchicalCollectionViewCursor_Basics_Test.as b/frameworks/tests/unitTests/mx/collections/HierarchicalCollectionViewCursor_Basics_Test.as
index 2990a80..6e3e34a 100644
--- a/frameworks/tests/unitTests/mx/collections/HierarchicalCollectionViewCursor_Basics_Test.as
+++ b/frameworks/tests/unitTests/mx/collections/HierarchicalCollectionViewCursor_Basics_Test.as
@@ -1,8 +1,10 @@
package mx.collections
{
import flash.events.UncaughtErrorEvent;
-
- import mx.collections.ArrayCollection;
+
+import flashx.textLayout.debug.assert;
+
+import mx.collections.ArrayCollection;
import mx.collections.CursorBookmark;
import mx.collections.HierarchicalCollectionView;
import mx.collections.HierarchicalCollectionViewCursor;
@@ -125,6 +127,81 @@ package mx.collections
//then
assertEquals(newLastCompany, _sut.current);
}
+
+ [Test]
+ public function testRemovingCurrentMiddleItemChangesCurrentToNextItem():void
+ {
+ //given
+ var firstCompany:DataNode = _level0.getItemAt(0) as DataNode;
+ var secondLocation:DataNode = firstCompany.children.getItemAt(1) as DataNode;
+ var thirdDepartmentOfSecondLocation:DataNode = secondLocation.children.getItemAt(2) as DataNode;
+
+ _sut.seek(new CursorBookmark(6)); //Company(1)->Location(2)->Department(2)
+
+ //when
+ secondLocation.children.removeItemAt(1);
+
+ //then
+ assertEquals(thirdDepartmentOfSecondLocation, _sut.current);
+ }
+
+ [Test]
+ public function testRemovingPreviousSiblingOfCurrentMiddleItemDoesNotChangeCurrent():void
+ {
+ //given
+ var firstCompany:DataNode = _level0.getItemAt(0) as DataNode;
+ var secondLocation:DataNode = firstCompany.children.getItemAt(1) as DataNode;
+ var secondDepartmentOfSecondLocation:DataNode = secondLocation.children.getItemAt(1) as DataNode;
+
+ //when
+ _sut.seek(new CursorBookmark(6)); //Company(1)->Location(2)->Department(2)
+
+ //then
+ assertEquals(secondDepartmentOfSecondLocation, _sut.current);
+
+ //when
+ secondLocation.children.removeItemAt(0);
+
+ //then
+ assertEquals(secondDepartmentOfSecondLocation, _sut.current);
+ }
+
+ [Test]
+ public function testRemovingCurrentFirstItemChangesCurrentToNextItem():void
+ {
+ //given
+ var firstCompany:DataNode = _level0.getItemAt(0) as DataNode;
+ var secondCompany:DataNode = _level0.getItemAt(1) as DataNode;
+
+ //initial assumption
+ assertEquals(firstCompany, _sut.current);
+
+ //when
+ _level0.removeItemAt(0);
+
+ //then
+ assertEquals(secondCompany, _sut.current);
+ }
+
+ [Test]
+ public function testRemovingSiblingOfCurrentFirstItemDoesNotChangeCurrent():void
+ {
+ //given
+ var firstCompany:DataNode = _level0.getItemAt(0) as DataNode;
+ var firstLocation:DataNode = firstCompany.children.getItemAt(0) as DataNode;
+
+ //when
+ _sut.seek(new CursorBookmark(1)); //Company(1)->Location(1)
+
+ //then
+ assertEquals(firstLocation, _sut.current);
+
+ //when
+ firstCompany.children.removeItemAt(1);
+
+ //then
+ assertEquals(firstLocation, _sut.current);
+ }
private static function handleUncaughtClientError(event:UncaughtErrorEvent):void
http://git-wip-us.apache.org/repos/asf/flex-sdk/blob/4970df88/frameworks/tests/unitTests/mx/collections/HierarchicalCollectionViewCursor_FLEX_34424_Test.as
----------------------------------------------------------------------
diff --git a/frameworks/tests/unitTests/mx/collections/HierarchicalCollectionViewCursor_FLEX_34424_Test.as b/frameworks/tests/unitTests/mx/collections/HierarchicalCollectionViewCursor_FLEX_34424_Test.as
new file mode 100644
index 0000000..2927c16
--- /dev/null
+++ b/frameworks/tests/unitTests/mx/collections/HierarchicalCollectionViewCursor_FLEX_34424_Test.as
@@ -0,0 +1,126 @@
+package mx.collections
+{
+import flash.events.UncaughtErrorEvent;
+
+import mx.collections.ArrayCollection;
+import mx.collections.CursorBookmark;
+import mx.collections.HierarchicalCollectionView;
+import mx.collections.HierarchicalCollectionViewCursor;
+import mx.core.FlexGlobals;
+
+import org.flexunit.asserts.assertNotNull;
+import org.flexunit.asserts.assertTrue;
+import org.flexunit.runners.Parameterized;
+
+import spark.components.WindowedApplication;
+
+public class HierarchicalCollectionViewCursor_FLEX_34424_Test
+ {
+ private static var _utils:HierarchicalCollectionViewTestUtils = new HierarchicalCollectionViewTestUtils();
+ private static var _noErrorsThrown:Boolean = true;
+ private static var _currentHierarchy:HierarchicalCollectionView;
+ private static var _sut:HierarchicalCollectionViewCursor;
+ private static var _operationCursor:HierarchicalCollectionViewCursor;
+
+ [BeforeClass]
+ public static function setUpBeforeClass():void
+ {
+ (FlexGlobals.topLevelApplication as WindowedApplication).loaderInfo.uncaughtErrorEvents.addEventListener(UncaughtErrorEvent.UNCAUGHT_ERROR, onUncaughtClientError);
+ }
+
+ [AfterClass]
+ public static function tearDownAfterClass():void
+ {
+ (FlexGlobals.topLevelApplication as WindowedApplication).loaderInfo.uncaughtErrorEvents.removeEventListener(UncaughtErrorEvent.UNCAUGHT_ERROR, onUncaughtClientError);
+ }
+
+ [Before]
+ public function setUp():void
+ {
+ _currentHierarchy = _utils.generateOpenHierarchyFromRootListWithAllNodesMethod(_utils.generateHierarchySourceFromString(HIERARCHY_STRING));
+ _sut = _currentHierarchy.createCursor() as HierarchicalCollectionViewCursor;
+ }
+
+ [After]
+ public function tearDown():void
+ {
+ _sut = null;
+ _currentHierarchy = null;
+ _operationCursor = null;
+ }
+
+ [Test]
+ public function testReproduce_FLEX_34424():void
+ {
+ //GIVEN
+ var selectedItemIndex:int = 10, operationIndex:int = 8;
+
+ //WHEN
+ //1. Select a specific node
+ _sut.seek(new CursorBookmark(selectedItemIndex));
+
+ var selectedNode:DataNode = DataNode(_sut.current);
+ assertNotNull(selectedNode);
+ selectedNode.isSelected = true;
+
+ //2. Perform setItemAt operation
+ _operationCursor = _currentHierarchy.createCursor() as HierarchicalCollectionViewCursor;
+ _operationCursor.seek(new CursorBookmark(operationIndex));
+ performRemoval(_operationCursor);
+
+ //THEN
+ assertTrue(_noErrorsThrown);
+ assertNotNull(_sut.current);
+ }
+
+ private static function performRemoval(where:HierarchicalCollectionViewCursor):void
+ {
+ var itemToBeRemoved:DataNode = where.current as DataNode;
+ assertNotNull(itemToBeRemoved);
+
+ var parentOfReplacementLocation:DataNode = _currentHierarchy.getParentItem(itemToBeRemoved) as DataNode;
+ var collectionToChange:ArrayCollection = parentOfReplacementLocation ? parentOfReplacementLocation.children : _utils.getRoot(_currentHierarchy) as ArrayCollection;
+ var removedItemIndex:int = collectionToChange.getItemIndex(itemToBeRemoved);
+
+ collectionToChange.removeItemAt(removedItemIndex);
+ }
+
+
+
+
+
+ private static function onUncaughtClientError(event:UncaughtErrorEvent):void
+ {
+ event.preventDefault();
+ event.stopImmediatePropagation();
+ _noErrorsThrown = false;
+
+ trace("\n FAIL: " + event.error);
+ _utils.printHCollectionView(_currentHierarchy);
+ }
+
+
+ private static const HIERARCHY_STRING:String = (<![CDATA[
+ Region(1)
+ Region(2)
+ Region(2)->City(0)
+ Region(2)->City(1)
+ Region(2)->City(1)->Company(1)
+ Region(2)->City(1)->Company(2)
+ Region(2)->City(1)->Company(2)->Department(1)
+ Region(2)->City(1)->Company(2)->Department(2)
+ Region(2)->City(1)->Company(2)->Department(2)->Employee(1)TBR
+ Region(2)->City(1)->Company(2)->Department(2)->Employee(2)
+ Region(2)->City(1)->Company(2)->Department(2)->Employee(3)SEL
+ Region(2)->City(1)->Company(2)->Department(3)
+ Region(2)->City(1)->Company(2)->Department(3)->Employee(1)
+ Region(2)->City(1)->Company(2)->Department(3)->Employee(2)
+ Region(2)->City(1)->Company(2)->Department(3)->Employee(3)
+ Region(2)->City(1)->Company(2)->Department(3)->Employee(4)
+ Region(2)->City(1)->Company(3)
+ Region(2)->City(1)->Company(3)->Department(1)
+ Region(2)->City(1)->Company(3)->Department(1)->Employee(1)
+ Region(2)->City(1)->Company(3)->Department(2)
+ ]]>).toString();
+ }
+}
\ No newline at end of file