Files
openlayers/tests/test_Popup.html
2006-11-08 19:03:30 +00:00

116 lines
4.4 KiB
HTML

<html>
<head>
<script src="../lib/OpenLayers.js"></script>
<script type="text/javascript"><!--
var popup;
function test_01_Popup_default_constructor(t) {
t.plan( 8 );
var size = new OpenLayers.Size(OpenLayers.Popup.WIDTH,
OpenLayers.Popup.HEIGHT);
popup = new OpenLayers.Popup();
t.ok( popup instanceof OpenLayers.Popup, "new OpenLayers.Popup returns Popup object" );
t.ok(popup.id.startsWith("OpenLayers.Popup"), "valid default popupid");
var firstID = popup.id;
t.ok(popup.size.equals(size), "good default popup.size");
t.eq(popup.contentHTML, "", "good default popup.contentHTML");
t.eq(popup.backgroundColor, OpenLayers.Popup.COLOR, "good default popup.backgroundColor");
t.eq(popup.opacity, OpenLayers.Popup.OPACITY, "good default popup.opacity");
t.eq(popup.border, OpenLayers.Popup.BORDER, "good default popup.border");
popup = new OpenLayers.Popup();
var newID = popup.id;
t.ok(newID != firstID, "default id generator creating unique ids");
}
function test_02_Popup_constructor (t) {
t.plan( 5 );
var id = "chicken";
var w = 500;
var h = 400;
var sz = new OpenLayers.Size(w,h);
var lon = 5;
var lat = 40;
var ll = new OpenLayers.LonLat(lon, lat);
var content = "foo";
popup = new OpenLayers.Popup(id,
ll,
sz,
content);
t.ok( popup instanceof OpenLayers.Popup, "new OpenLayers.Popup returns Popup object" );
t.eq(popup.id, id, "popup.id set correctly");
t.ok(popup.lonlat.equals(ll), "popup.lonlat set correctly");
t.ok(popup.size.equals(sz), "popup.size set correctly");
t.eq(popup.contentHTML, content, "contentHTML porpoerty of set correctly");
}
function test_03_Popup_draw(t) {
t.plan( 17 );
var id = "chicken";
var x = 50;
var y = 100;
var w = 500;
var h = 400;
var content = "charlie";
var color = "red";
var opacity = 0.5;
var border = "1px solid";
popup = new OpenLayers.Popup(id);
popup.setSize(new OpenLayers.Size(w, h));
popup.setContentHTML(content);
popup.setBackgroundColor(color);
popup.setOpacity(opacity);
popup.setBorder(border);
popup.draw(new OpenLayers.Pixel(x, y));
t.eq(popup.div.id, id, "popup.div.id set correctly");
t.eq(popup.div.style.left, x + "px", "left position of popup.div set correctly");
t.eq(popup.div.style.top, y + "px", "top position of popup.div set correctly");
t.eq(popup.div.style.width, w + "px", "width position of popup.div set correctly");
t.eq(popup.div.style.height, h + "px", "heightposition of popup.div set correctly");
var contentDiv = popup.div.childNodes[0];
t.eq(contentDiv.className, "olPopupContent", "correct content div className");
t.eq(contentDiv.id, "chicken_contentDiv", "correct content div id");
t.eq(contentDiv.style.width, "200px", "correct content div width");
t.eq(contentDiv.style.height, "200px", "correct content div height");
t.eq(contentDiv.style.position, "relative", "correct content div position");
t.eq(contentDiv.style.overflow, "hidden", "correct content div overflow");
t.eq(contentDiv.innerHTML, content, "correct content div content");
t.eq(popup.div.style.backgroundColor, color, "good default popup.backgroundColor");
if (navigator.appName.indexOf("Microsoft") == -1) {
t.eq(parseFloat(popup.div.style.opacity), opacity, "good default popup.opacity");
} else {
t.eq(popup.div.style.filter, "alpha(opacity=" + opacity*100 + ")", "good default popup.opacity");
}
t.ok(popup.div.style.border.indexOf(border) != -1, "good default popup.border");
x += 50;
popup.moveTo(new OpenLayers.Pixel(x, y));
t.eq(popup.div.style.left, x + "px", "moveTo updates left position of popup.div correctly");
t.eq(popup.div.style.top, y + "px", "moveTo updates top position of popup.div correctly");
}
// -->
</script>
</head>
<body>
</body>
</html>