FLEX-18746 Added unit test (current fails).
Project: http://git-wip-us.apache.org/repos/asf/flex-sdk/repo Commit: http://git-wip-us.apache.org/repos/asf/flex-sdk/commit/f804380f Tree: http://git-wip-us.apache.org/repos/asf/flex-sdk/tree/f804380f Diff: http://git-wip-us.apache.org/repos/asf/flex-sdk/diff/f804380f Branch: refs/heads/master Commit: f804380f10e725aa90fee6c2ab998b3db30fe705 Parents: fea9be9 Author: Mihai Chira <mih...@apache.org> Authored: Mon Aug 14 19:56:14 2017 +0200 Committer: Mihai Chira <mih...@apache.org> Committed: Mon Aug 14 19:56:14 2017 +0200 ---------------------------------------------------------------------- .../tests/mx/controls/Tree_FLEX_18746_Tests.as | 112 +++++++++++++++++++ 1 file changed, 112 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/flex-sdk/blob/f804380f/frameworks/projects/mx/tests/mx/controls/Tree_FLEX_18746_Tests.as ---------------------------------------------------------------------- diff --git a/frameworks/projects/mx/tests/mx/controls/Tree_FLEX_18746_Tests.as b/frameworks/projects/mx/tests/mx/controls/Tree_FLEX_18746_Tests.as new file mode 100644 index 0000000..5d64b06 --- /dev/null +++ b/frameworks/projects/mx/tests/mx/controls/Tree_FLEX_18746_Tests.as @@ -0,0 +1,112 @@ +package mx.controls { + import flash.events.Event; + import flash.events.EventDispatcher; + + import mx.collections.ArrayCollection; + import mx.core.mx_internal; + + import org.flexunit.assertThat; + import org.flexunit.async.Async; + import org.fluint.uiImpersonation.UIImpersonator; + + use namespace mx_internal; + + public class Tree_FLEX_18746_Tests + { + private static var noEnterFramesToWait:int = NaN; + private static const _finishNotifier:EventDispatcher = new EventDispatcher(); + + private static var _sut:Tree; + private static var child:Object = {label: "Item"}; + private static var parent0:Object = {label: "Folder 0", children: new ArrayCollection()}; + private static var parent1:Object = {label: "Folder 1", children: new ArrayCollection([child])}; + + + [Before] + public function setUp():void + { + _sut = new Tree(); + _sut.width = 200; + _sut.height = 200; + UIImpersonator.addChild(_sut); + } + + [After] + public function tearDown():void + { + UIImpersonator.removeAllChildren(); + _sut = null; + } + + + //-------------------------------------------------------------------------- + // + // Test method + // + //-------------------------------------------------------------------------- + + [Test(async, timeout=1000)] + public function test_object_removed_from_stage_via_code_is_not_initialized():void + { + //given + const dataProvider:ArrayCollection = new ArrayCollection(); + dataProvider.addItem(parent0); + dataProvider.addItem(parent1); + + //when + _sut.dataProvider = dataProvider; + + //then wait a few frames + noEnterFramesToWait = 2; + UIImpersonator.testDisplay.addEventListener(Event.ENTER_FRAME, onEnterFrame); + Async.handleEvent(this, _finishNotifier, Event.COMPLETE, then_expand_second_folder, 200); + } + + + private function then_expand_second_folder(event:Event, passThroughData:Object):void + { + //when + _sut.expandItem(parent1, true, true, true); + + //then wait a bit + noEnterFramesToWait = 5; + UIImpersonator.testDisplay.addEventListener(Event.ENTER_FRAME, onEnterFrame); + Async.handleEvent(this, _finishNotifier, Event.COMPLETE, then_move_child_to_first_parent_and_expand_it, 500); + } + + private function then_move_child_to_first_parent_and_expand_it(event:Event, passThroughData:Object):void + { + //then + assertThat(_sut.isItemOpen(parent1)); + + //when + ArrayCollection(parent1.children).removeItemAt(0); + _sut.expandItem(parent0, true, true, true); + ArrayCollection(parent0.children).addItem(child); + + //then wait a bit + noEnterFramesToWait = 1; + UIImpersonator.testDisplay.addEventListener(Event.ENTER_FRAME, onEnterFrame); + Async.handleEvent(this, _finishNotifier, Event.COMPLETE, then_contract_second_folder, 200); + } + + private static function then_contract_second_folder(event:Event, passThroughData:Object):void + { + //when + _sut.expandItem(parent1, false, true, true); + + //then no error was thrown + assertThat(true); + } + + + private static function onEnterFrame(event:Event):void + { + if(!--noEnterFramesToWait) + { + UIImpersonator.testDisplay.removeEventListener(Event.ENTER_FRAME, onEnterFrame); + _finishNotifier.dispatchEvent(new Event(Event.COMPLETE)); + } + } + } +} \ No newline at end of file