dojo.provide("tests.webmap.widget.EditMenu");

dojo.require("doh.runner");
dojo.require("webmap.widget.EditMenu");
dojo.require("tests.Util");

var div;
function doEditMenuSetup(){
	div = document.createElement("div");
	document.body.appendChild(div);
}
doh.register("tests.webmap.widget.EditMenu", 
	[
		{
			name: "newLabel",
			widget: null,
			setUp: function(){
				doEditMenuSetup();
				this.widget = new webmap.widget.EditMenu({_x:20,_y:40,toolbar:"toolbar"}, div);
			},
			runTest: function(){
				var i = 0;
				var _this = this;
				var widgets = dijit.registry.byClass("webmap.widget.LabelWindow");
				widgets.forEach(function(){i++;});
				this.widget.newLabel();
				widgets = dijit.registry.byClass("webmap.widget.LabelWindow");
				var _this = this;
				widgets.forEach(function(w){
					i++;
					tests.assertEqual(_this.widget._x, dojo.style(w.domNode, "left"));
					tests.assertEqual(_this.widget._y, dojo.style(w.domNode, "top"));
					tests.assertEqual(_this.widget.toolbar, w.toolbar);
				});
				tests.assertEqual(1, i);
			},
			tearDown: function(){
				this.widget.destroy();
			}
		},
		{
			name: "newCalloutBox",
			widget: null,
			setUp: function(){
				doEditMenuSetup();
				this.widget = new webmap.widget.EditMenu({_x:20,_y:40,toolbar:"toolbar"}, div);
			},
			runTest: function(){
				var i = 0;
				var _this = this;
				var widgets = dijit.registry.byClass("webmap.widget.LabelCalloutBox");
				widgets.forEach(function(){i++;});
				this.widget.newCalloutBox();
				widgets = dijit.registry.byClass("webmap.widget.LabelCalloutBox");
				var _this = this;
				widgets.forEach(function(w){
					i++;
					tests.assertEqual(_this.widget._x, w.x);
					tests.assertEqual(_this.widget._y, w.y);
					tests.assertEqual(_this.widget.toolbar, w.toolbar);
				});
				tests.assertEqual(1, i);
			},
			tearDown: function(){
				this.widget.destroy();
			}
		},
		{
			name: "onItemClick",
			widget: null,
			item: {id:"newLabel"},
			apply: webmap.widget.EditMenu.superclass.onItemClick.apply,
			applyArgs: [],
			labels: 0,
			callouts: 0,
			setUp: function(){
				doEditMenuSetup();
				var _this = this;
				this.widget = new webmap.widget.EditMenu({
					_x:20,_y:40, toolbar:"toolbar",
					newLabel:function(){_this.labels++;},
					newCalloutBox:function(){_this.callouts++;}
				}, div);
				webmap.widget.EditMenu.superclass.onItemClick.apply = function(a0,a1){
					_this.applyArgs.push([a0,a1]);
				}
			},
			runTest: function(){
				this.widget.onItemClick(this.item);
				tests.assertEqual([[this.widget, [this.item]]], this.applyArgs);
				tests.assertEqual(1, this.labels);
				tests.assertEqual(0, this.callouts);
				this.item.id = "newCalloutBox";
				this.widget.onItemClick(this.item);
				tests.assertEqual([
					[this.widget, [this.item]],
					[this.widget, [this.item]]
					], this.applyArgs);
				tests.assertEqual(1, this.labels);
				tests.assertEqual(1, this.callouts);
			},
			tearDown: function(){
				webmap.widget.EditMenu.superclass.onItemClick.apply = this.apply;
				this.widget.destroy();
			}
		},
		{
			name: "onOpen",
			widget: null,
			evt: {x:20,y:40},
			onOpen: webmap.widget.EditMenu.superclass.onOpen.apply,
			applyArgs: [],
			setUp: function(){
				doEditMenuSetup();
				this.widget = new webmap.widget.EditMenu({}, div);
				var _this = this;
				webmap.widget.EditMenu.superclass.onOpen.apply = function(a0,a1){
					_this.applyArgs.push([a0,a1]);
				}
			},
			runTest: function(){
				this.widget.onOpen(this.evt);
				tests.assertEqual([[this.widget, [this.evt]]], this.applyArgs);
				tests.assertEqual(this.evt.x, this.widget._x);
				tests.assertEqual(this.evt.y, this.widget._y);
			},
			tearDown: function(){
				webmap.widget.EditMenu.superclass.onOpen.apply = this.apply;
				this.widget.destroy();
			}
		}
	]
);