[Commits] r794 - sandbox/elemoine/playground/geoext/tests/lib/GeoExt/widgets

commits at geoext.org commits at geoext.org
Mon May 18 06:33:09 CEST 2009


Author: elemoine
Date: 2009-05-18 06:33:09 +0200 (Mon, 18 May 2009)
New Revision: 794

Modified:
   sandbox/elemoine/playground/geoext/tests/lib/GeoExt/widgets/Action.html
Log:
more tests


Modified: sandbox/elemoine/playground/geoext/tests/lib/GeoExt/widgets/Action.html
===================================================================
--- sandbox/elemoine/playground/geoext/tests/lib/GeoExt/widgets/Action.html	2009-05-15 23:08:48 UTC (rev 793)
+++ sandbox/elemoine/playground/geoext/tests/lib/GeoExt/widgets/Action.html	2009-05-18 04:33:09 UTC (rev 794)
@@ -23,19 +23,241 @@
 
             // 1 test
             cfg = {text: "foo"};
-            action = new GeoExt.Action.fromControl(ctrl, cfg);
+            action = GeoExt.Action.fromControl(ctrl, cfg);
             t.ok(action.initialConfig == cfg,
                  "fromControl sets the config in the instance's initial config");
             
             // 1 test
             var a = new Ext.Action({text: "foo"});
-            action = new GeoExt.Action.fromControl(ctrl, a);
+            action = GeoExt.Action.fromControl(ctrl, a);
             t.ok(action.initialConfig == a.initialConfig,
                  "fromControl sets the passed action's initial config in the " +
                  "instance's initial config");
         }
+
+        function test_constructor(t) {
+            t.plan(10)
+
+            var ctrl, scope, handler, toggleHandler, checkHandler, cfg, action;
+
+            ctrl = new OpenLayers.Control();
+
+            scope = {}, handler = function() {};
+            toggleHandler = function() {}, checkHandler = function() {};
+
+            cfg = {
+                control: ctrl,
+                scope: scope,
+                handler: handler,
+                toggleHandler: toggleHandler,
+                checkHandler: checkHandler
+            };
+
+            action = new GeoExt.Action(cfg);
+
+            t.ok(action.control == ctrl,
+                 "constructor sets control in the instance");
+            t.ok(action.uScope == scope,
+                 "constructor sets this.uScope to user-provided scope");
+            t.ok(action.uHandler == handler,
+                 "constructor sets this.uHandler to user-provided handler");
+            t.ok(action.uToggleHandler == toggleHandler,
+                 "constructor sets this.uToggleHandler to user-provided toggleHandler");
+            t.ok(action.uCheckHandler == checkHandler,
+                 "constructor sets this.uCheckHandler to user-provided checkHandler");
+
+            t.eq(action.initialConfig.control, undefined,
+                 "constructor does not set control in the initial config");
+            t.ok(action.initialConfig.scope == action,
+                 "constructor sets scope to this in the initial config");
+            t.ok(action.initialConfig.handler == action.pHandler,
+                 "constructor sets handler to this.pHandler in the initial config");
+            t.ok(action.initialConfig.toggleHandler == action.pToggleHandler,
+                 "constructor sets toggleHandler to this.ptoggleHandler in the initial config");
+            t.ok(action.initialConfig.checkHandler == action.pCheckHandler,
+                 "constructor sets checkHandler to this.pCheckHandler in the initial config");
+        }
+
+        function test_button(t) {
+            t.plan(6);
+
+            var menu, menuBtn, tb, ctrl, triggerCnt, handlerCnt;
+            var action, btn, item;
+
+            var evt = {
+                preventDefault: function() {},
+                stopEvent: function() {},
+                button: 0
+            };
+
+            menu = new Ext.menu.Menu();
+            menuBtn = new Ext.Button({menu: menu});
+
+            tb = new Ext.Toolbar({
+                renderTo: "toolbar",
+                buttons: [menuBtn]
+            });
+
+            // the "button" control
+            ctrl = new OpenLayers.Control({
+                type: OpenLayers.Control.TYPE_BUTTON,
+                trigger: function() {
+                    triggerCnt++;
+                }
+            });
+            ctrl.activate();
+
+            action = GeoExt.Action.fromControl(ctrl, {
+                handler: function() {
+                    handlerCnt++;
+                }
+            });
+            
+            // create button from action and it to toolbar
+            btn = new Ext.Button(action);
+            tb.add(btn);
+
+            // simulate click on button
+            // 2 tests
+            // test that the control's trigger is called exactly once
+            // test that the action handler is called exactly once
+            triggerCnt = 0;
+            handlerCnt = 0;
+            btn.onClick(evt);
+            t.eq(triggerCnt, 1, "click on button calls control trigger once");
+            t.eq(handlerCnt, 1, "click on button calls action handler once");
+
+            // create menu item from action and it to menu
+            item = new Ext.menu.Item(action);
+            menu.add(item);
+
+            // simulate click on menu item
+            // 2 tests
+            // test that the control's trigger is called exactly once
+            // test that the action handler is called exactly once
+            triggerCnt = 0;
+            handlerCnt = 0;
+            menuBtn.showMenu();
+            item.onClick(evt);
+            menuBtn.hideMenu();
+            t.eq(triggerCnt, 1, "click on menu item calls control trigger once");
+            t.eq(handlerCnt, 1, "click on menu item calls action handler once");
+
+            // deactivate control
+            // 2 tests
+            // test that button is disabled
+            // test that menu item is disabled
+            ctrl.deactivate();
+            t.eq(btn.disabled, true, "deactivating control disables button");
+            t.eq(btn.disabled, true, "deactivating control disables menu item");
+        }
+
+        function test_toggle(t) {
+            t.plan(12);
+
+            var menu, menuBtn, tb, ctrl;
+            var activateCnt, deactivateCnt, toggleHandlerCnt, checkHandlerCnt;
+            var action, btn, item;
+
+            var evt = {
+                preventDefault: function() {},
+                stopEvent: function() {},
+                button: 0
+            };
+
+            menu = new Ext.menu.Menu();
+            menuBtn = new Ext.Button({menu: menu});
+
+            tb = new Ext.Toolbar({
+                renderTo: "toolbar",
+                buttons: [menuBtn]
+            });
+
+            // the control
+            ctrl = new OpenLayers.Control({
+                activate: function() {
+                    activateCnt++;
+                    return OpenLayers.Control.prototype.activate.call(this, arguments);
+                },
+                deactivate: function() {
+                    deactivateCnt++;
+                    return OpenLayers.Control.prototype.deactivate.call(this, arguments);
+                }
+            });
+            ctrl.activate();
+
+            action = GeoExt.Action.fromControl(ctrl, {
+                enableToggle: true,
+                toggleHandler: function() {
+                    toggleHandlerCnt++;
+                },
+                checkHandler: function() {
+                    checkHandlerCnt++;
+                }
+            });
+            
+            // create button from action and it to toolbar
+            btn = new Ext.Button(action);
+            tb.add(btn);
+
+            // simulate click on button
+            // 2 tests
+            // test that the control gets activated once
+            // test that the toggle handler is called exactly once
+            activateCnt = 0;
+            deactivateCnt = 0;
+            toggleHandlerCnt = 0;
+            btn.onClick(evt);
+            t.eq(activateCnt, 1, "click on button activates control once");
+            t.eq(deactivateCnt, 0, "click on button does not deactivate control");
+            t.eq(toggleHandlerCnt, 1, "click on button calls toggle handler once");
+
+            // simulate click on button
+            // 2 tests
+            // test that the control gets deactivated once
+            // test that the toggle handler is called exactly once
+            activateCnt = 0;
+            deactivateCnt = 0;
+            toggleHandlerCnt = 0;
+            btn.onClick(evt);
+            t.eq(activateCnt, 0, "click again on button does not activate control");
+            t.eq(deactivateCnt, 1, "click again on button deactivates control once");
+            t.eq(toggleHandlerCnt, 1, "click again on button calls toggle handler once");
+
+            // create menu item from action and it to menu
+            item = new Ext.menu.CheckItem(action);
+            menu.add(item);
+
+            // simulate click on menu item
+            // 2 tests
+            // test that the control gets activated once
+            // test that the toggle handler is called exactly once
+            activateCnt = 0;
+            deactivateCnt = 0;
+            checkHandlerCnt = 0;
+            menuBtn.showMenu();
+            item.onClick(evt);
+            menuBtn.hideMenu();
+            t.eq(activateCnt, 1, "click on menu item activates control once");
+            t.eq(deactivateCnt, 0, "click on menu item does not deactivate control");
+            t.eq(checkHandlerCnt, 1, "click on menu item calls check handler once");
+
+            // simulate click on menu item
+            // 2 tests
+            // test that the control gets deactivated once
+            // test that the toggle handler is called exactly once
+            activateCnt = 0;
+            deactivateCnt = 0;
+            checkHandlerCnt = 0;
+            menuBtn.showMenu();
+            item.onClick(evt);
+            menuBtn.hideMenu();
+            t.eq(activateCnt, 0, "click again on menu item does not activate control");
+            t.eq(deactivateCnt, 1, "click again on menu item deactivates control once");
+            t.eq(checkHandlerCnt, 1, "click again on menu item calls check handler once");
+        }
     </script>
   <body>
-    <div id="mappanel"></div>
+    <div id="toolbar"></div>
   </body>
 </html>



More information about the Commits mailing list