Skip to content

Instantly share code, notes, and snippets.

@Stray
Created May 28, 2010 15:35
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Stray/417298 to your computer and use it in GitHub Desktop.
Save Stray/417298 to your computer and use it in GitHub Desktop.
package app.restricted.view.overlays {
import asunit.framework.TestCase;
import org.robotlegs.mvcs.Mediator;
import mockolate.prepare;
import mockolate.nice;
import mockolate.stub;
import mockolate.verify;
import org.hamcrest.object.equalTo;
import flash.events.IEventDispatcher;
import flash.events.Event;
import app.restricted.view.overlays.DefinitionView;
import flash.events.EventDispatcher;
import app.api.LessonDefinitionEvent;
import flash.utils.Dictionary;
import app.api.DefinitionDictionaryVO;
import app.api.LessonNavBarEvent;
public class DefinitionViewMediatorTest extends TestCase {
private var instanceMediator:DefinitionViewMediator;
public function DefinitionViewMediatorTest(methodName:String=null) {
super(methodName)
}
override public function run():void{
var mockolateMaker:IEventDispatcher = prepare(DefinitionView);
mockolateMaker.addEventListener(Event.COMPLETE, prepareCompleteHandler);
}
private function prepareCompleteHandler(e:Event):void{
super.run();
}
override protected function setUp():void {
super.setUp();
instanceMediator = new DefinitionViewMediator();
instanceMediator.view = nice(DefinitionView);
instanceMediator.eventDispatcher = new EventDispatcher();
var vector1:Vector.<String> = new Vector.<String>();
var vector2:Vector.<String> = new Vector.<String>();
var vector3:Vector.<String> = new Vector.<String>();
vector1.push("test title");
vector1.push("test body");
vector2.push("blah");
vector2.push("blah");
vector3.push("blah");
vector3.push("blah");
var dictionary:Dictionary = new Dictionary();
dictionary['test button'] = vector1;
dictionary['key2'] = vector2;
dictionary['key3'] = vector3;
var definitionDictionaryVO:DefinitionDictionaryVO = new DefinitionDictionaryVO(dictionary, 'defaultAnswer');
instanceMediator.definitionDictionaryVO = definitionDictionaryVO;
instanceMediator.onRegister();
}
override protected function tearDown():void {
super.tearDown();
instanceMediator = null;
}
public function testInstantiated():void {
assertTrue("instanceMediator is DefinitionViewMediator", instanceMediator is DefinitionViewMediator);
}
public function testIsMediator():void{
assertTrue("instanceMediator is robotlegs Mediator", instanceMediator is Mediator);
}
public function testFailure():void {
assertTrue("Failing test", true);
}
public function testRegisterDefinitionEventTriggersShowDefinitionButtonOnView():void{
addAsync(null, 50, checkAddButtonCalledOnView);
var definitionEvent:LessonDefinitionEvent = new LessonDefinitionEvent(LessonDefinitionEvent.REGISTER_DEFINITION, 100, 200, 'tr_test_button_name');
instanceMediator.eventDispatcher.dispatchEvent(definitionEvent);
}
public function checkAddButtonCalledOnView(e:Event):void{
verify(instanceMediator.view).method("addDefinitionButton").args(equalTo('tr_test_button_name'), equalTo(100), equalTo(200), equalTo('test title'), equalTo('test body'), equalTo(false));
}
public function testRegisterFootnoteEventTriggersShowDefinitionButtonOnView():void{
addAsync(null, 50, checkAddButtonCalledOnViewForFootnote);
var definitionEvent:LessonDefinitionEvent = new LessonDefinitionEvent(LessonDefinitionEvent.REGISTER_FOOTNOTE, 100, 200, 'tr_test_button_name');
instanceMediator.eventDispatcher.dispatchEvent(definitionEvent);
}
public function checkAddButtonCalledOnViewForFootnote(e:Event):void{
verify(instanceMediator.view).method("addDefinitionButton").args(equalTo('tr_test_button_name'), equalTo(100), equalTo(200), equalTo('test title'), equalTo('test body'), equalTo(true));
}
public function testRemoveButtonEventRemovesDefinitionButtonFromView():void{
addAsync(null, 50, checkRemoveButtonCalledOnView);
var definitionEvent:LessonDefinitionEvent = new LessonDefinitionEvent(LessonDefinitionEvent.REMOVE_BUTTON, 100, 200, 'tr_test_button_name');
instanceMediator.eventDispatcher.dispatchEvent(definitionEvent);
}
public function checkRemoveButtonCalledOnView(e:Event):void{
verify(instanceMediator.view).method("removeDefinitionButton").args(equalTo('tr_test_button_name'));
}
public function testRemoveDefinitionEventRemovesDefinitionButtonFromView():void{
addAsync(null, 50, checkRemoveDefinitionCalledOnView);
var definitionEvent:LessonDefinitionEvent = new LessonDefinitionEvent(LessonDefinitionEvent.REMOVE_DEFINITION, 100, 200, 'tr_test_button_name');
instanceMediator.eventDispatcher.dispatchEvent(definitionEvent);
}
public function checkRemoveDefinitionCalledOnView(e:Event):void{
verify(instanceMediator.view).method("removeDefinitionPopup").noArgs();
}
public function testNavBarEventRemovesDefinitionButtonAndPopupFromView():void{
addAsync(null, 50, checkRemoveDefinitionCalledOnView);
addAsync(null, 50, checkRemoveAllDefinitionButtonsCalledOnView);
var navBarEvent:LessonNavBarEvent = new LessonNavBarEvent(LessonNavBarEvent.GO_TO_MARKER, 0, 0);
instanceMediator.eventDispatcher.dispatchEvent(navBarEvent);
}
public function checkRemoveAllDefinitionButtonsCalledOnView(e:Event):void{
verify(instanceMediator.view).method("removeAllDefinitionButtons").noArgs();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment