Skip to content

Instantly share code, notes, and snippets.

@swiz
Created May 19, 2010 01:42
Show Gist options
  • Save swiz/405843 to your computer and use it in GitHub Desktop.
Save swiz/405843 to your computer and use it in GitHub Desktop.
10 minutes + Swiz Chaining API = Rudimentary functional tester
package chains
{
import org.swizframework.utils.chain.AbstractChain;
import org.swizframework.utils.chain.IAutonomousChainStep;
import org.swizframework.utils.chain.IChain;
public class CompositeChain extends AbstractChain implements IChain
{
public function doProceed():void
{
IAutonomousChainStep( steps[ position ] ).doProceed();
}
}
}
package steps
{
import flash.events.Event;
import flash.events.IEventDispatcher;
import org.swizframework.utils.chain.BaseChainStep;
import org.swizframework.utils.chain.IAutonomousChainStep;
public class DispatchEventStep extends BaseChainStep implements IAutonomousChainStep
{
public var dispatcher:IEventDispatcher;
public var event:Event;
public function DispatchEventStep( dispatcher:IEventDispatcher, event:Event )
{
this.dispatcher = dispatcher;
this.event = event;
}
public function doProceed():void
{
dispatcher.dispatchEvent( event );
complete();
}
}
}
<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx"
creationComplete="application1_creationCompleteHandler(event)">
<s:layout>
<s:VerticalLayout horizontalAlign="center" gap="10" paddingTop="20" />
</s:layout>
<fx:Script>
<![CDATA[
import chains.CompositeChain;
import mx.collections.ArrayCollection;
import mx.events.FlexEvent;
import org.swizframework.utils.chain.EventChain;
import steps.DispatchEventStep;
import steps.PropertySetterStep;
protected function application1_creationCompleteHandler(event:FlexEvent):void
{
var cc:CompositeChain = new CompositeChain();
cc.addStep( new PropertySetterStep( lbl, { "text": "some text from the label" } ) );
cc.addStep( new PropertySetterStep( ddl, { "selectedIndex": 1 } ) );
cc.addStep( new DispatchEventStep( btn, new MouseEvent( "click" ) ) );
cc.start();
}
]]>
</fx:Script>
<s:Label id="lbl" />
<s:DropDownList id="ddl" dataProvider="{ new ArrayCollection( [ 'one', 'two', 'three' ] ) }" />
<s:Button id="btn" label="Fill Text" click="ta.text = lbl.text + '\n\n' + ddl.selectedItem" />
<s:TextArea id="ta" />
</s:Application>
package steps
{
import org.swizframework.utils.chain.BaseChainStep;
import org.swizframework.utils.chain.IAutonomousChainStep;
public class PropertySetterStep extends BaseChainStep implements IAutonomousChainStep
{
public var target:Object;
public var props:Object;
public function PropertySetterStep( target:Object, props:Object )
{
this.target = target;
this.props = props;
}
public function doProceed():void
{
for( var prop:String in props )
{
target[ prop ] = props[ prop ];
}
complete();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment