flex-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mih...@apache.org
Subject [2/8] git commit: [flex-sdk] [refs/heads/FLEX-34119] - FLEX-34440 Added unit test to reproduce FLEX-34440. This also required a few changes in HierarchicalCollectionViewTestUtils.
Date Mon, 28 Jul 2014 17:21:52 GMT
FLEX-34440 Added unit test to reproduce FLEX-34440. This also required a few changes in HierarchicalCollectionViewTestUtils.


Project: http://git-wip-us.apache.org/repos/asf/flex-sdk/repo
Commit: http://git-wip-us.apache.org/repos/asf/flex-sdk/commit/3336f2ec
Tree: http://git-wip-us.apache.org/repos/asf/flex-sdk/tree/3336f2ec
Diff: http://git-wip-us.apache.org/repos/asf/flex-sdk/diff/3336f2ec

Branch: refs/heads/FLEX-34119
Commit: 3336f2ecb058b9184b070c1fc910e15ecfaeb2e6
Parents: 90c9136
Author: Mihai Chira <mihaic@apache.org>
Authored: Mon Jul 28 11:51:10 2014 +0100
Committer: Mihai Chira <mihaic@apache.org>
Committed: Mon Jul 28 11:51:10 2014 +0100

----------------------------------------------------------------------
 ...hicalCollectionViewCursor_FLEX_34440_Test.as | 125 +++++++++++++++++++
 .../HierarchicalCollectionViewTestUtils.as      |  20 ++-
 2 files changed, 141 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/flex-sdk/blob/3336f2ec/frameworks/tests/unitTests/mx/collections/HierarchicalCollectionViewCursor_FLEX_34440_Test.as
----------------------------------------------------------------------
diff --git a/frameworks/tests/unitTests/mx/collections/HierarchicalCollectionViewCursor_FLEX_34440_Test.as
b/frameworks/tests/unitTests/mx/collections/HierarchicalCollectionViewCursor_FLEX_34440_Test.as
new file mode 100644
index 0000000..c6fb4ca
--- /dev/null
+++ b/frameworks/tests/unitTests/mx/collections/HierarchicalCollectionViewCursor_FLEX_34440_Test.as
@@ -0,0 +1,125 @@
+package
+{
+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_34440_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_34440():void
+        {
+			//GIVEN
+			var selectedItemIndex:int = 10, operationIndex:int = 5;
+			
+			//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));
+		    performReplacement(_operationCursor);
+
+            //THEN
+            assertTrue(_noErrorsThrown);
+        }
+		
+        private static function performReplacement(where:HierarchicalCollectionViewCursor):void
+        {
+            var itemToBeReplaced:DataNode = where.current as DataNode;
+            assertNotNull(itemToBeReplaced);
+
+            var parentOfReplacementLocation:DataNode = _currentHierarchy.getParentItem(itemToBeReplaced)
as DataNode;
+            var collectionToChange:ArrayCollection = parentOfReplacementLocation ? parentOfReplacementLocation.children
: _utils.getRoot(_currentHierarchy) as ArrayCollection;
+            var replacedItemIndex:int = collectionToChange.getItemIndex(itemToBeReplaced);
+
+            collectionToChange.setItemAt(_utils.createSimpleNode(itemToBeReplaced.label +
" [REPLACED NODE]"), replacedItemIndex);
+        }
+
+
+
+		
+		
+		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)TBR
+         Region(2)->City(1)->Company(2)TBR->Department(1)
+         Region(2)->City(1)->Company(2)TBR->Department(2)
+         Region(2)->City(1)->Company(2)TBR->Department(2)->Employee(1)
+         Region(2)->City(1)->Company(2)TBR->Department(2)->Employee(2)
+         Region(2)->City(1)->Company(2)TBR->Department(2)->Employee(3)SEL
+         Region(2)->City(1)->Company(2)TBR->Department(3)
+         Region(2)->City(1)->Company(2)TBR->Department(3)->Employee(1)
+         Region(2)->City(1)->Company(2)TBR->Department(3)->Employee(2)
+         Region(2)->City(1)->Company(2)TBR->Department(3)->Employee(3)
+         Region(2)->City(1)->Company(2)TBR->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

http://git-wip-us.apache.org/repos/asf/flex-sdk/blob/3336f2ec/frameworks/tests/unitTests/mx/collections/HierarchicalCollectionViewTestUtils.as
----------------------------------------------------------------------
diff --git a/frameworks/tests/unitTests/mx/collections/HierarchicalCollectionViewTestUtils.as
b/frameworks/tests/unitTests/mx/collections/HierarchicalCollectionViewTestUtils.as
index 82d00c7..f89e10c 100644
--- a/frameworks/tests/unitTests/mx/collections/HierarchicalCollectionViewTestUtils.as
+++ b/frameworks/tests/unitTests/mx/collections/HierarchicalCollectionViewTestUtils.as
@@ -3,14 +3,18 @@ package
 	import com.adobe.utils.StringUtil;
 	
 	import mx.collections.ArrayCollection;
+	import mx.collections.CursorBookmark;
 	import mx.collections.HierarchicalCollectionView;
 	import mx.collections.HierarchicalCollectionViewCursor;
 	import mx.collections.HierarchicalData;
 	import mx.collections.IViewCursor;
+	import mx.utils.UIDUtil;
 
 	public class HierarchicalCollectionViewTestUtils
 	{
 		//assumes the root is an ArrayCollection of DataNodes
+		private var _allNodes:Object = {};
+		
 		public function clone(hcv:HierarchicalCollectionView):HierarchicalCollectionView
 		{
 			var oldRoot:ArrayCollection = ArrayCollection(getRoot(hcv));
@@ -37,14 +41,20 @@ package
 		
 		public function generateOpenHierarchyFromRootList(root:ArrayCollection):HierarchicalCollectionView
 		{
-			var hcv:HierarchicalCollectionView = generateHCV(root);
+			var hcv:HierarchicalCollectionView = generateHCV(root, false);
 			openAllNodes(hcv);
 			return hcv;
 		}
+
+        public function generateOpenHierarchyFromRootListWithAllNodesMethod(root:ArrayCollection):HierarchicalCollectionView
+        {
+            var hcv:HierarchicalCollectionView = generateHCV(root, true);
+            return hcv;
+        }
 		
-		public function generateHCV(rootCollection:ArrayCollection):HierarchicalCollectionView
+		public function generateHCV(rootCollection:ArrayCollection, useAllNodes:Boolean = false):HierarchicalCollectionView
 		{
-			return new HierarchicalCollectionView(new HierarchicalData(rootCollection));
+			return new HierarchicalCollectionView(new HierarchicalData(rootCollection), useAllNodes
? _allNodes : null);
 		}
 		
 		public function openAllNodes(hcv:HierarchicalCollectionView):void
@@ -75,7 +85,9 @@ package
 
         public function createSimpleNode(label:String):DataNode
 		{
-            return new DataNode(label);
+			var node:DataNode = new DataNode(label);
+			_allNodes[UIDUtil.getUID(node)] = node;
+            return node;
         }
 
         public function isAncestor(node:DataNode, forNode:DataNode, hcv:HierarchicalCollectionView):Boolean


Mime
View raw message