This is an automated email from the ASF dual-hosted git repository. joshtynjala pushed a commit to branch develop in repository https://gitbox.apache.org/repos/asf/royale-asjs.git
The following commit(s) were added to refs/heads/develop by this push: new 145687f RoyaleUnitUI: work in progress 145687f is described below commit 145687f5edd951f97c165c0e6ceb1734d910a916 Author: Josh Tynjala <joshtynj...@apache.org> AuthorDate: Thu Nov 7 14:50:28 2019 -0800 RoyaleUnitUI: work in progress --- .../apache/royale/html/test/UITestItemRenderer.as | 92 +++++++++ .../org/apache/royale/html/test/UITestRunner.mxml | 210 +++++++++++++++++++++ .../royale/html/test/models/UITestRunnerModel.as | 76 ++++++++ .../org/apache/royale/html/test/models/UITestVO.as | 48 +++++ 4 files changed, 426 insertions(+) diff --git a/frameworks/projects/RoyaleUnitUI/src/org/apache/royale/html/test/UITestItemRenderer.as b/frameworks/projects/RoyaleUnitUI/src/org/apache/royale/html/test/UITestItemRenderer.as new file mode 100644 index 0000000..1c7f733 --- /dev/null +++ b/frameworks/projects/RoyaleUnitUI/src/org/apache/royale/html/test/UITestItemRenderer.as @@ -0,0 +1,92 @@ +//////////////////////////////////////////////////////////////////////////////// +// +// Licensed to the Apache Software Foundation (ASF) under one or more +// contributor license agreements. See the NOTICE file distributed with +// this work for additional information regarding copyright ownership. +// The ASF licenses this file to You under the Apache License, Version 2.0 +// (the "License"); you may not use this file except in compliance with +// the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +//////////////////////////////////////////////////////////////////////////////// +package org.apache.royale.html.test +{ + import org.apache.royale.html.Group; + import org.apache.royale.html.Label; + import org.apache.royale.html.beads.VerticalAlignChildren; + import org.apache.royale.html.beads.layouts.HorizontalLayoutWithPaddingAndGap; + import org.apache.royale.html.supportClasses.DataItemRenderer; + import org.apache.royale.html.test.models.UITestVO; + + [ExcludeClass] + /** + * @private + */ + public class UITestItemRenderer extends DataItemRenderer + { + public function UITestItemRenderer() + { + super(); + this.typeNames = "UITestItemRenderer"; + } + + private var container:Group; + private var icon:Label; + private var label:Label; + + override public function addedToParent():void + { + super.addedToParent(); + + container = new Group(); + var layout:HorizontalLayoutWithPaddingAndGap = new HorizontalLayoutWithPaddingAndGap(); + layout.gap = 8; + layout.paddingTop = 4; + layout.paddingBottom = 4; + layout.paddingLeft = 8; + layout.paddingRight = 8; + container.addBead(layout); + var align:VerticalAlignChildren = new VerticalAlignChildren(); + align.alignment = "middle"; + container.addBead(align); + addElement(container); + + icon = new Label(); + container.addElement(icon); + + label = new Label(); + container.addElement(label); + } + + override public function set data(value:Object):void + { + super.data = value; + + var item:UITestVO = UITestVO(value); + if(item.ignored) + { + icon.text = "⚪"; + } + else if(item.failure) + { + icon.text = "🔴"; + } + else if(item.active) + { + icon.text = "🟡" + } + else + { + icon.text = "🟢"; + } + label.text = item.description; + } + } +} diff --git a/frameworks/projects/RoyaleUnitUI/src/org/apache/royale/html/test/UITestRunner.mxml b/frameworks/projects/RoyaleUnitUI/src/org/apache/royale/html/test/UITestRunner.mxml new file mode 100644 index 0000000..938e4e4 --- /dev/null +++ b/frameworks/projects/RoyaleUnitUI/src/org/apache/royale/html/test/UITestRunner.mxml @@ -0,0 +1,210 @@ +<?xml version="1.0" encoding="utf-8"?> +<!--- +// +// Licensed to the Apache Software Foundation (ASF) under one or more +// contributor license agreements. See the NOTICE file distributed with +// this work for additional information regarding copyright ownership. +// The ASF licenses this file to You under the Apache License, Version 2.0 +// (the "License"); you may not use this file except in compliance with +// the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +//////////////////////////////////////////////////////////////////////////////// +--> +<js:View xmlns:fx="http://ns.adobe.com/mxml/2009" + xmlns:js="library://ns.apache.org/royale/basic" + xmlns:models="org.apache.royale.html.test.models.*" + implements="org.apache.royale.test.runners.notification.IRunListener" + percentWidth="100" percentHeight="100" + initComplete="resultTypesList.selectedIndex = 0;"> + <js:beads> + <js:ViewDataBinding/> + <js:VerticalLayout/> + </js:beads> + <fx:Declarations> + <models:UITestRunnerModel localId="testsModel"/> + </fx:Declarations> + + <js:Panel title="RoyaleUnit Test Results" percentWidth="100" percentHeight="50"> + <js:beads> + <js:OneFlexibleChildVerticalLayout flexibleChild="resultsList"/> + </js:beads> + <js:HGroup percentWidth="100"> + <js:Label text="Filter:"/> + <js:Spacer width="10"/> + <js:DropDownList localId="resultTypesList" + dataProvider="{testsModel.resultTypes}" + change="resultTypesList_changeHandler(event)"/> + </js:HGroup> + <js:Spacer height="2"/> + <js:DynamicList localId="resultsList" + labelField="description" dataProvider="{testsModel.results}" + percentWidth="100" + itemRenderer="org.apache.royale.html.test.UITestItemRenderer" + change="resultsList_changeHandler(event)"> + <js:beads> + <!-- needed for filterFunction --> + <js:CollectionChangeUpdateForArrayListData/> + </js:beads> + </js:DynamicList> + </js:Panel> + + <js:Panel title="Test Details" percentWidth="100" percentHeight="50" + visible="{!testsModel.selectedResult}"> + <js:beads> + <js:VerticalLayout/> + </js:beads> + <js:Label text="No test selected"/> + </js:Panel> + + <js:Panel title="Test Details" percentWidth="100" percentHeight="50" + visible="{testsModel.selectedResult}"> + <js:beads> + <js:VerticalLayout/> + </js:beads> + + <js:Label text="Function:"/> + <js:Label text="{testsModel.selectedResult.functionName}"/> + + <js:Spacer height="10"/> + + <js:Label text="Test Case:"/> + <js:Label text="{testsModel.selectedResult.testCaseName}"/> + + <js:Spacer height="10"/> + + <js:Label text="Result:"/> + <js:Label text="{getResultType(testsModel.selectedResult)}"/> + + <js:Spacer height="10"/> + + <js:VGroup visible="{testsModel.selectedResult.failure}"> + <js:Label text="Stack Trace:"/> + <js:MultilineLabel text="{testsModel.selectedResult.failure.stackTrace}" + percentWidth="100" style="white-space:pre;overflow-x:scroll"/> + </js:VGroup> + </js:Panel> + + <fx:Script> + <![CDATA[ + import org.apache.royale.collections.ArrayListView; + import org.apache.royale.events.Event; + import org.apache.royale.test.runners.notification.Failure; + import org.apache.royale.test.runners.notification.Result; + import org.apache.royale.html.test.models.UITestVO; + import org.apache.royale.test.AssertionError; + + public function testRunStarted(description:String):void + { + + } + + public function testStarted(description:String):void + { + var testResults:ArrayListView = testsModel.results; + testResults.addItem(new UITestVO(description)); + } + + public function testFinished(description:String):void + { + var testResults:ArrayListView = testsModel.results; + var item:UITestVO = testResults.getItemAt(testResults.length - 1) as UITestVO; + item.active = false; + testResults.itemUpdated(item); + } + + public function testFailure(failure:Failure):void + { + var testResults:ArrayListView = testsModel.results; + var item:UITestVO = testResults.getItemAt(testResults.length - 1) as UITestVO; + item.failure = failure; + testResults.itemUpdated(item); + } + + public function testIgnored(description:String):void + { + var testResults:ArrayListView = testsModel.results; + var item:UITestVO = new UITestVO(description); + item.active = false; + item.ignored = true; + testResults.addItem(item); + } + + public function testRunFinished(result:Result):void + { + } + + private function getResultType(item:UITestVO):String + { + if(item.active) + { + return "Active"; + } + if(item.ignored) + { + return "Ignored"; + } + if(item.failure) + { + if(item.failure.exception is AssertionError) + { + return "Assertion Failed"; + } + return "Exception"; + } + return "Passed"; + } + + private function resultsList_changeHandler(event:Event):void + { + testsModel.selectedResultIndex = resultsList.selectedIndex; + } + + private function resultTypesList_changeHandler(event:Event):void + { + var selectedResult:UITestVO = testsModel.selectedResult; + + var testResults:ArrayListView = testsModel.results; + var resultType:String = resultTypesList.selectedItem as String; + testResults.filterFunction = function(test:UITestVO):Boolean + { + switch(resultType) + { + case UITestRunnerModel.RESULT_TYPE_FAILED: + { + return test.failure; + } + case UITestRunnerModel.RESULT_TYPE_PASSED: + { + return !test.failure && !test.ignored && !test.active; + } + case UITestRunnerModel.RESULT_TYPE_IGNORED: + { + return test.ignored; + } + } + return true; + }; + testResults.refresh(); + + if(selectedResult) + { + var newIndex:int = testResults.getItemIndex(selectedResult); + if(newIndex == -1 && testResults.length > 0) + { + newIndex = 0; + } + resultsList.selectedIndex = newIndex; + testsModel.selectedResultIndex = newIndex; + } + } + ]]> + </fx:Script> +</js:View> \ No newline at end of file diff --git a/frameworks/projects/RoyaleUnitUI/src/org/apache/royale/html/test/models/UITestRunnerModel.as b/frameworks/projects/RoyaleUnitUI/src/org/apache/royale/html/test/models/UITestRunnerModel.as new file mode 100644 index 0000000..8ffe730 --- /dev/null +++ b/frameworks/projects/RoyaleUnitUI/src/org/apache/royale/html/test/models/UITestRunnerModel.as @@ -0,0 +1,76 @@ +//////////////////////////////////////////////////////////////////////////////// +// +// Licensed to the Apache Software Foundation (ASF) under one or more +// contributor license agreements. See the NOTICE file distributed with +// this work for additional information regarding copyright ownership. +// The ASF licenses this file to You under the Apache License, Version 2.0 +// (the "License"); you may not use this file except in compliance with +// the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +//////////////////////////////////////////////////////////////////////////////// +package org.apache.royale.html.test.models +{ + import org.apache.royale.collections.ArrayListView; + import org.apache.royale.events.Event; + import org.apache.royale.events.EventDispatcher; + + [ExcludeClass] + /** + * @private + */ + public class UITestRunnerModel extends EventDispatcher + { + public static const RESULT_TYPE_ALL:String = "All Tests"; + public static const RESULT_TYPE_PASSED:String = "Passed"; + public static const RESULT_TYPE_FAILED:String = "Failed"; + public static const RESULT_TYPE_IGNORED:String = "Ignored"; + + public function UITestRunnerModel() + { + super(); + } + + private var _results:ArrayListView = new ArrayListView(); + + [Bindable] + public function get results():ArrayListView + { + return this._results; + } + + [Bindable("change")] + public function get selectedResult():UITestVO + { + if(this.selectedResultIndex == -1) + { + return null; + } + return this._results.getItemAt(this.selectedResultIndex) as UITestVO; + } + + private var _selectedResultIndex:int = -1; + + [Bindable("change")] + public function get selectedResultIndex():int + { + return this._selectedResultIndex; + } + + public function set selectedResultIndex(value:int):void + { + this._selectedResultIndex = value; + this.dispatchEvent(new Event("change")); + } + + [Bindable] + public var resultTypes:Array = [RESULT_TYPE_ALL, RESULT_TYPE_FAILED, RESULT_TYPE_PASSED, RESULT_TYPE_IGNORED]; + } +} \ No newline at end of file diff --git a/frameworks/projects/RoyaleUnitUI/src/org/apache/royale/html/test/models/UITestVO.as b/frameworks/projects/RoyaleUnitUI/src/org/apache/royale/html/test/models/UITestVO.as new file mode 100644 index 0000000..362262b --- /dev/null +++ b/frameworks/projects/RoyaleUnitUI/src/org/apache/royale/html/test/models/UITestVO.as @@ -0,0 +1,48 @@ +//////////////////////////////////////////////////////////////////////////////// +// +// Licensed to the Apache Software Foundation (ASF) under one or more +// contributor license agreements. See the NOTICE file distributed with +// this work for additional information regarding copyright ownership. +// The ASF licenses this file to You under the Apache License, Version 2.0 +// (the "License"); you may not use this file except in compliance with +// the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +//////////////////////////////////////////////////////////////////////////////// +package org.apache.royale.html.test.models +{ + import org.apache.royale.test.runners.notification.Failure; + + [ExcludeClass] + [Bindable] + /** + * @private + */ + public class UITestVO + { + public function UITestVO(description:String) + { + this.description = description; + + var index:int = description.lastIndexOf("."); + testCaseName = description.substr(0, index); + functionName = description.substr(index + 1); + } + + public var description:String; + + public var functionName:String; + public var testCaseName:String; + + public var active:Boolean = true; + public var ignored:Boolean = false; + public var failure:Failure; + } +} \ No newline at end of file