mock map.pan, map.zoomIn and map.zoomOut in the Control.KeyboardDefaults tests, references #176
This commit is contained in:
@@ -47,132 +47,121 @@
|
|||||||
* http://unixpapa.com/js/key.html
|
* http://unixpapa.com/js/key.html
|
||||||
*/
|
*/
|
||||||
function test_Control_KeyboardDefaults_KeyDownEvent (t) {
|
function test_Control_KeyboardDefaults_KeyDownEvent (t) {
|
||||||
t.plan( 16 );
|
t.plan( 25 );
|
||||||
|
|
||||||
|
var evt = {which: 1}, pans = [], zoomIns = 0, zoomOuts = 0;
|
||||||
|
|
||||||
var evt = {which: 1};
|
|
||||||
map = new OpenLayers.Map('map');
|
map = new OpenLayers.Map('map');
|
||||||
|
|
||||||
|
// mock "pan", "zoomIn" and "zoomOut"
|
||||||
|
map.pan = function(dx, dy) {
|
||||||
|
pans.push({dx: dx, dy: dy});
|
||||||
|
};
|
||||||
|
map.zoomIn = function() {
|
||||||
|
zoomIns++;
|
||||||
|
};
|
||||||
|
map.zoomOut = function() {
|
||||||
|
zoomOuts++;
|
||||||
|
};
|
||||||
|
|
||||||
var layer = new OpenLayers.Layer.WMS("Test Layer",
|
var layer = new OpenLayers.Layer.WMS("Test Layer",
|
||||||
"http://octo.metacarta.com/cgi-bin/mapserv?",
|
"http://octo.metacarta.com/cgi-bin/mapserv?",
|
||||||
{map: "/mapdata/vmap_wms.map", layers: "basic"});
|
{map: "/mapdata/vmap_wms.map", layers: "basic"});
|
||||||
map.addLayer(layer);
|
map.addLayer(layer);
|
||||||
control = new OpenLayers.Control.KeyboardDefaults();
|
|
||||||
|
var control = new OpenLayers.Control.KeyboardDefaults({
|
||||||
|
slideFactor: 100
|
||||||
|
});
|
||||||
map.addControl(control);
|
map.addControl(control);
|
||||||
|
|
||||||
var STARTING_ZOOM_LEVEL = 4;
|
map.setCenter(new OpenLayers.LonLat(0, 0), 4);
|
||||||
var DELAY = 2;
|
|
||||||
|
|
||||||
var centerLL = new OpenLayers.LonLat(0,0);
|
|
||||||
map.setCenter(centerLL, STARTING_ZOOM_LEVEL);
|
|
||||||
|
|
||||||
// Start new test.
|
// Start new test.
|
||||||
evt.keyCode = OpenLayers.Event.KEY_LEFT;
|
evt.keyCode = OpenLayers.Event.KEY_LEFT;
|
||||||
control.defaultKeyPress(evt);
|
control.defaultKeyPress(evt);
|
||||||
t.delay_call(
|
t.eq(pans.length, 1, '[KEY_LEFT] pan called once');
|
||||||
DELAY, function() {
|
t.eq(pans[0], {dx: -100, dy: 0},
|
||||||
t.ok( map.getCenter().lon < centerLL.lon, "key left works correctly" );
|
'[KEY LEFT] pan called with expected args');
|
||||||
|
|
||||||
// Start new test.
|
evt.keyCode = OpenLayers.Event.KEY_RIGHT;
|
||||||
evt.keyCode = OpenLayers.Event.KEY_RIGHT;
|
control.defaultKeyPress(evt);
|
||||||
control.defaultKeyPress(evt);
|
t.eq(pans.length, 2, '[KEY_RIGHT] pan called once');
|
||||||
},
|
t.eq(pans[1], {dx: 100, dy: 0},
|
||||||
DELAY, function() {
|
'[KEY RIGHT] pan called with expected args');
|
||||||
t.eq( map.getCenter().lon, centerLL.lon, "key right works correctly" );
|
|
||||||
|
|
||||||
// Start new test.
|
evt.keyCode = OpenLayers.Event.KEY_UP;
|
||||||
evt.keyCode = OpenLayers.Event.KEY_UP;
|
control.defaultKeyPress(evt);
|
||||||
control.defaultKeyPress(evt);
|
t.eq(pans.length, 3, '[KEY_UP] pan called once');
|
||||||
},
|
t.eq(pans[2], {dx: 0, dy: -100},
|
||||||
DELAY, function() {
|
'[KEY UP] pan called with expected args');
|
||||||
t.ok( map.getCenter().lat > centerLL.lat, "key up works correctly" );
|
|
||||||
|
|
||||||
// Start new test.
|
evt.keyCode = OpenLayers.Event.KEY_DOWN;
|
||||||
evt.keyCode = OpenLayers.Event.KEY_DOWN;
|
control.defaultKeyPress(evt);
|
||||||
control.defaultKeyPress(evt);
|
t.eq(pans.length, 4, '[KEY_DOWN] pan called once');
|
||||||
},
|
t.eq(pans[3], {dx: 0, dy: 100},
|
||||||
DELAY, function() {
|
'[KEY DOWN] pan called with expected args');
|
||||||
t.ok( map.getCenter().lat == centerLL.lat, "key down works correctly" );
|
|
||||||
|
|
||||||
// Start new test.
|
evt.keyCode = 33;
|
||||||
evt.keyCode = 33; //page up
|
control.defaultKeyPress(evt);
|
||||||
control.defaultKeyPress(evt);
|
t.eq(pans.length, 5, '[33] pan called once');
|
||||||
},
|
t.eq(pans[4], {dx: 0, dy: -384},
|
||||||
DELAY, function() {
|
'[33] pan called with expected args');
|
||||||
t.ok( map.getCenter().lat > centerLL.lat, "key page up works correctly" );
|
|
||||||
|
|
||||||
// Start new test.
|
evt.keyCode = 34;
|
||||||
evt.keyCode = 34; //page down
|
control.defaultKeyPress(evt);
|
||||||
control.defaultKeyPress(evt);
|
t.eq(pans.length, 6, '[34] pan called once');
|
||||||
},
|
t.eq(pans[5], {dx: 0, dy: 384},
|
||||||
DELAY, function() {
|
'[34] pan called with expected args');
|
||||||
t.ok( map.getCenter().lat == centerLL.lat, "key page down works correctly" );
|
|
||||||
|
|
||||||
// Start new test.
|
evt.keyCode = 35;
|
||||||
evt.keyCode = 35; //end
|
control.defaultKeyPress(evt);
|
||||||
control.defaultKeyPress(evt);
|
t.eq(pans.length, 7, '[35] pan called once');
|
||||||
},
|
t.eq(pans[6], {dx: 768, dy: 0},
|
||||||
DELAY, function() {
|
'[35] pan called with expected args');
|
||||||
t.ok( map.getCenter().lon > centerLL.lon, "key end works correctly" );
|
|
||||||
|
|
||||||
// Start new test.
|
evt.keyCode = 36;
|
||||||
evt.keyCode = 36; //home
|
control.defaultKeyPress(evt);
|
||||||
control.defaultKeyPress(evt);
|
t.eq(pans.length, 8, '[36] pan called once');
|
||||||
},
|
t.eq(pans[7], {dx: -768, dy: 0},
|
||||||
DELAY, function() {
|
'[36] pan called with expected args');
|
||||||
t.ok( map.getCenter().lon == centerLL.lon, "key home works correctly");
|
|
||||||
|
|
||||||
// Start new test.
|
evt.keyCode = 43;
|
||||||
evt.keyCode = 43; //+
|
control.defaultKeyPress(evt);
|
||||||
control.defaultKeyPress(evt);
|
t.eq(zoomIns, 1, '[43] zoomIn called once');
|
||||||
t.eq( map.getZoom(), STARTING_ZOOM_LEVEL + 1, "key code 43 works correctly: +/= key (ASCII), keypad + (ASCII, Opera)" );
|
|
||||||
|
|
||||||
// Start new test.
|
evt.keyCode = 61;
|
||||||
evt.keyCode = 61;
|
control.defaultKeyPress(evt);
|
||||||
control.defaultKeyPress(evt);
|
t.eq(zoomIns, 2, '[61] zoomIn called once');
|
||||||
t.eq( map.getZoom(), STARTING_ZOOM_LEVEL + 2, "key code 61 works correctly: +/= key (Mozilla, Opera, some ASCII)");
|
|
||||||
|
|
||||||
// Start new test.
|
evt.keyCode = 187;
|
||||||
evt.keyCode = 187;
|
control.defaultKeyPress(evt);
|
||||||
control.defaultKeyPress(evt);
|
t.eq(zoomIns, 3, '[187] zoomIn called once');
|
||||||
t.eq( map.getZoom(), STARTING_ZOOM_LEVEL + 3, "key code 187 works correctly: +/= key (IE)");
|
|
||||||
|
|
||||||
// Start new test.
|
evt.keyCode = 107;
|
||||||
evt.keyCode = 107;
|
control.defaultKeyPress(evt);
|
||||||
control.defaultKeyPress(evt);
|
t.eq(zoomIns, 4, '[107] zoomIn called once');
|
||||||
t.eq( map.getZoom(), STARTING_ZOOM_LEVEL + 4, "key code 107 works correctly: keypad + (IE, Mozilla)");
|
|
||||||
|
|
||||||
// Start new test.
|
evt.keyCode = 107;
|
||||||
// set zoomanimation flag manually,
|
control.defaultKeyPress(evt);
|
||||||
// reason: loadend event in layers.js will not achieved in unittests
|
t.eq(zoomIns, 5, '[107] zoomIn called once');
|
||||||
map.zoomanimationActive = false;
|
|
||||||
evt.keyCode = 45;
|
|
||||||
control.defaultKeyPress(evt);
|
|
||||||
t.eq( map.getZoom(), STARTING_ZOOM_LEVEL + 3, "key code 45 works correctly: -/_ key (ASCII, Opera), keypad - (ASCII, Opera)");
|
|
||||||
|
|
||||||
// Start new test.
|
evt.keyCode = 45;
|
||||||
// set zoomanimation flag manually,
|
control.defaultKeyPress(evt);
|
||||||
// reason: loadend event in layers.js will not achieved in unittests
|
t.eq(zoomOuts, 1, '[45] zoomOut called once');
|
||||||
map.zoomanimationActive = false;
|
|
||||||
evt.keyCode = 109;
|
|
||||||
control.defaultKeyPress(evt);
|
|
||||||
t.eq( map.getZoom(), STARTING_ZOOM_LEVEL + 2, "key code 109 works correctly: -/_ key (Mozilla), keypad - (Mozilla, IE)");
|
|
||||||
|
|
||||||
// Start new test.
|
evt.keyCode = 109;
|
||||||
// set zoomanimation flag manually,
|
control.defaultKeyPress(evt);
|
||||||
// reason: loadend event in layers.js will not achieved in unittests
|
t.eq(zoomOuts, 2, '[109] zoomOut called once');
|
||||||
map.zoomanimationActive = false;
|
|
||||||
evt.keyCode = 189;
|
|
||||||
control.defaultKeyPress(evt);
|
|
||||||
t.eq( map.getZoom(), STARTING_ZOOM_LEVEL + 1, "key code 189 works correctly: -/_ key (IE)");
|
|
||||||
|
|
||||||
// Start new test.
|
evt.keyCode = 189;
|
||||||
// set zoomanimation flag manually,
|
control.defaultKeyPress(evt);
|
||||||
// reason: loadend event in layers.js will not achieved in unittests
|
t.eq(zoomOuts, 3, '[189] zoomOut called once');
|
||||||
map.zoomanimationActive = false;
|
|
||||||
evt.keyCode = 95;
|
evt.keyCode = 95;
|
||||||
control.defaultKeyPress(evt);
|
control.defaultKeyPress(evt);
|
||||||
t.eq( map.getZoom(), STARTING_ZOOM_LEVEL, "key code 95 works correctly: -/_ key (some ASCII)");
|
t.eq(zoomOuts, 4, '[95] zoomOut called once');
|
||||||
}
|
|
||||||
);
|
map.destroy();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user