[Commits] r814 - sandbox/elemoine/playground/geoext/tests/lib/GeoExt/widgets
commits at geoext.org
commits at geoext.org
Tue May 19 17:15:18 CEST 2009
Author: elemoine
Date: 2009-05-19 17:15:18 +0200 (Tue, 19 May 2009)
New Revision: 814
Modified:
sandbox/elemoine/playground/geoext/tests/lib/GeoExt/widgets/Action.html
Log:
complete tests
Modified: sandbox/elemoine/playground/geoext/tests/lib/GeoExt/widgets/Action.html
===================================================================
--- sandbox/elemoine/playground/geoext/tests/lib/GeoExt/widgets/Action.html 2009-05-19 14:52:42 UTC (rev 813)
+++ sandbox/elemoine/playground/geoext/tests/lib/GeoExt/widgets/Action.html 2009-05-19 15:15:18 UTC (rev 814)
@@ -256,6 +256,121 @@
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");
}
+
+ function test_toggle_group(t) {
+ t.plan(8);
+
+ var menu, menuBtn, tb, ctrl1, ctrl2;
+
+ var activateCtrl1Cnt, deactivateCtrl1Cnt;
+ var activateCtrl2Cnt, deactivateCtrl2Cnt;
+
+ var action1, action2, btn1, btn2, item1, item2;
+
+ 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 controls
+ ctrl1 = new OpenLayers.Control({
+ activate: function() {
+ activateCtrl1Cnt++;
+ return OpenLayers.Control.prototype.activate.call(this, arguments);
+ },
+ deactivate: function() {
+ deactivateCtrl1Cnt++;
+ return OpenLayers.Control.prototype.deactivate.call(this, arguments);
+ }
+ });
+ ctrl1.deactivate();
+ ctrl2 = new OpenLayers.Control({
+ activate: function() {
+ activateCtrl2Cnt++;
+ return OpenLayers.Control.prototype.activate.call(this, arguments);
+ },
+ deactivate: function() {
+ deactivateCtrl2Cnt++;
+ return OpenLayers.Control.prototype.deactivate.call(this, arguments);
+ }
+ });
+ ctrl2.activate();
+
+ // the actions
+ action1 = GeoExt.Action.fromControl(ctrl1, {
+ toggleGroup: "ctrl",
+ pressed: false
+ });
+ action2 = GeoExt.Action.fromControl(ctrl2, {
+ toggleGroup: "ctrl",
+ pressed: true
+ });
+
+ // create buttons from actions and add them to toolbar
+ btn1 = new Ext.Button(action1);
+ tb.add(btn1);
+ btn2 = new Ext.Button(action2);
+ tb.add(btn2);
+
+ // simulate click on btn1
+ // 2 tests
+ // test that ctrl1 gets activated once
+ // test that ctrl2 gets deactivated once
+ activateCtrl1Cnt = 0;
+ deactivateCtrl2Cnt = 0;
+ btn1.onClick(evt);
+ t.eq(activateCtrl1Cnt, 1, "click on btn1 activates ctrl1 once");
+ t.eq(deactivateCtrl2Cnt, 1, "click on btn1 deactivates ctrl2 once");
+
+ // simulate click on btn2
+ // 2 tests
+ // test that ctrl1 gets deactivated once
+ // test that ctrl2 gets activated once
+ deactivateCtrl1Cnt = 0;
+ activateCtrl2Cnt = 0;
+ btn2.onClick(evt);
+ t.eq(deactivateCtrl1Cnt, 1, "click on btn2 deactivates ctrl1 once");
+ t.eq(activateCtrl2Cnt, 1, "click on btn2 activates ctrl2 once");
+
+ // create menu items from actions and them to menu
+ item1 = new Ext.menu.CheckItem(action1);
+ menu.add(item1);
+ item2 = new Ext.menu.CheckItem(action2);
+ menu.add(item2);
+
+ // simulate click on item1
+ // 2 tests
+ // test that ctrl1 gets activated once
+ // test that ctrl2 gets deactivated once
+ activateCtrl1Cnt = 0;
+ deactivateCtrl2Cnt = 0;
+ menuBtn.showMenu();
+ item1.onClick(evt);
+ menuBtn.hideMenu();
+ t.eq(activateCtrl1Cnt, 1, "click on item1 activates ctrl1 once");
+ t.eq(deactivateCtrl2Cnt, 1, "click on item1 deactivates ctrl2 once");
+
+ // simulate click on item2
+ // 2 tests
+ // test that ctrl1 gets deactivated once
+ // test that ctrl2 gets activated once
+ deactivateCtrl1Cnt = 0;
+ activateCtrl2Cnt = 0;
+ menuBtn.showMenu();
+ item2.onClick(evt);
+ menuBtn.hideMenu();
+ t.eq(deactivateCtrl1Cnt, 1, "click on item2 deactivates ctrl1 once");
+ t.eq(activateCtrl2Cnt, 1, "click on item2 activates ctrl2 once");
+ }
</script>
<body>
<div id="toolbar"></div>
More information about the Commits
mailing list