Revert r6710: The new popup coe is going to need to change tests, so this
needs to wait. git-svn-id: http://svn.openlayers.org/trunk/openlayers@6711 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
122
tests/Control/test_Panel.html
Normal file
122
tests/Control/test_Panel.html
Normal file
@@ -0,0 +1,122 @@
|
||||
<html>
|
||||
<head>
|
||||
<script src="../../lib/OpenLayers.js"></script>
|
||||
<script type="text/javascript">
|
||||
function test_Control_Panel_constructor (t) {
|
||||
t.plan( 2 );
|
||||
|
||||
control = new OpenLayers.Control.Panel();
|
||||
t.ok( control instanceof OpenLayers.Control.Panel, "new OpenLayers.Control returns object" );
|
||||
t.eq( control.displayClass, "olControlPanel", "displayClass is correct" );
|
||||
}
|
||||
function test_01_Control_Panel_constructor (t) {
|
||||
t.plan(5);
|
||||
var map = new OpenLayers.Map('map');
|
||||
var panel = new OpenLayers.Control.Panel();
|
||||
var toolControl = new OpenLayers.Control.ZoomBox();
|
||||
var AnotherToolControl = OpenLayers.Class(OpenLayers.Control, {
|
||||
CLASS_NAME: 'mbControl.TestTool',
|
||||
type: OpenLayers.Control.TYPE_TOOL
|
||||
});
|
||||
var anotherToolControl = new AnotherToolControl();
|
||||
var ToggleControl = OpenLayers.Class(OpenLayers.Control, {
|
||||
CLASS_NAME: 'mbControl.TestToggle',
|
||||
type: OpenLayers.Control.TYPE_TOGGLE
|
||||
});
|
||||
var toggleControl = new ToggleControl();
|
||||
|
||||
t.ok(panel instanceof OpenLayers.Control.Panel,
|
||||
"new OpenLayers.Control.Panel returns object");
|
||||
|
||||
panel.addControls([toolControl, anotherToolControl, toggleControl]);
|
||||
|
||||
t.eq(panel.controls.length, 3,
|
||||
"added three controls to the panel");
|
||||
map.addControl(panel);
|
||||
|
||||
panel.activateControl(toolControl);
|
||||
t.ok(toolControl.active && !anotherToolControl.active && !toggleControl.active,
|
||||
"activated one tool control, the other one is inactive and the toggle control also.");
|
||||
|
||||
panel.activateControl(toggleControl);
|
||||
t.ok(toolControl.active && !anotherToolControl.active && toggleControl.active,
|
||||
"activated the toggle control, which has no influence on the tool controls.");
|
||||
|
||||
panel.activateControl(anotherToolControl);
|
||||
t.ok(!toolControl.active && anotherToolControl.active && toggleControl.active,
|
||||
"activated the other tool control, the first one is inactive and the toggle control still active.");
|
||||
}
|
||||
function test_02_Control_Panel_titles (t) {
|
||||
t.plan(2);
|
||||
var panel = new OpenLayers.Control.Panel();
|
||||
var toolControl = new OpenLayers.Control.ZoomBox({
|
||||
title:"Zoom box: Selecting it you can zoom on an area by clicking and dragging."
|
||||
});
|
||||
panel.addControls([toolControl]);
|
||||
t.eq(panel.controls.length, 1, "added a control to the panel");
|
||||
t.eq(panel.controls[0].title, toolControl.panel_div.title, "the title is correctly set");
|
||||
}
|
||||
|
||||
function test_Control_Panel_getBy(t) {
|
||||
|
||||
var panel = {
|
||||
getBy: OpenLayers.Control.Panel.prototype.getBy,
|
||||
getControlsBy: OpenLayers.Control.Panel.prototype.getControlsBy,
|
||||
controls: [
|
||||
{foo: "foo", id: Math.random()},
|
||||
{foo: "bar", id: Math.random()},
|
||||
{foo: "foobar", id: Math.random()},
|
||||
{foo: "foo bar", id: Math.random()},
|
||||
{foo: "foo", id: Math.random()}
|
||||
]
|
||||
};
|
||||
|
||||
var cases = [
|
||||
{
|
||||
got: panel.getControlsBy("foo", "foo"),
|
||||
expected: [panel.controls[0], panel.controls[4]],
|
||||
message: "(string literal) got two controls matching foo"
|
||||
}, {
|
||||
got: panel.getControlsBy("foo", "bar"),
|
||||
expected: [panel.controls[1]],
|
||||
message: "(string literal) got one control matching foo"
|
||||
}, {
|
||||
got: panel.getControlsBy("foo", "barfoo"),
|
||||
expected: [],
|
||||
message: "(string literal) got empty array for no foo match"
|
||||
}, {
|
||||
got: panel.getControlsBy("foo", /foo/),
|
||||
expected: [panel.controls[0], panel.controls[2], panel.controls[3], panel.controls[4]],
|
||||
message: "(regexp literal) got three controls containing string"
|
||||
}, {
|
||||
got: panel.getControlsBy("foo", /foo$/),
|
||||
expected: [panel.controls[0], panel.controls[4]],
|
||||
message: "(regexp literal) got three controls ending with string"
|
||||
}, {
|
||||
got: panel.getControlsBy("foo", /\s/),
|
||||
expected: [panel.controls[3]],
|
||||
message: "(regexp literal) got control containing space"
|
||||
}, {
|
||||
got: panel.getControlsBy("foo", new RegExp("BAR", "i")),
|
||||
expected: [panel.controls[1], panel.controls[2], panel.controls[3]],
|
||||
message: "(regexp object) got layers ignoring case"
|
||||
}, {
|
||||
got: panel.getControlsBy("foo", {test: function(str) {return str.length > 3;}}),
|
||||
expected: [panel.controls[2], panel.controls[3]],
|
||||
message: "(custom object) got controls with foo length greater than 3"
|
||||
}
|
||||
];
|
||||
t.plan(cases.length);
|
||||
for(var i=0; i<cases.length; ++i) {
|
||||
t.eq(cases[i].got, cases[i].expected, cases[i].message);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
</script>
|
||||
</head>
|
||||
<body>
|
||||
<div id="map" style="width: 1024px; height: 512px;"/>
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user