widget.html revision 5edf890115170a08e2060f946472ba4ce0a93e26
<!doctype html>
<html>
<head>
<title>Widget Test Suite</title>
<link type="text/css" rel="stylesheet" href="/build/test/assets/test-console.css">
<style type="text/css">
h1 {
font: normal 125%/1.4 Arial, sans-serif;
}
.yui3-skin-sam .yui3-console .yui3-console-content {
font-size: 10px;
}
.yui3-skin-sam .yui3-console-entry-pass .yui3-console-entry-cat {
background: #070;
color: #fff;
}
.yui3-skin-sam .yui3-console-entry-fail .yui3-console-entry-cat {
background: #700;
color: #fff;
}
.yui3-skin-sam .yui3-console-entry-time {
display: none;
}
</style>
</head>
<body class="yui3-skin-sam">
<div id="testbed" class="yui3-skin-foo"></div>
<script src="/build/yui/yui.js"></script>
<script>
YUI({
filter : 'raw'
}).use('test','console',function (Y) {
var suite = new Y.Test.Suite("Widget Tests");
suite.add(new Y.Test.Case({
name : "getSkinName",
"getSkinName should return null if not rendered" : function () {
var w = new Y.Widget();
Y.Assert.isNull( w.getSkinName() );
},
"getSkinName should return name from BB if available": function () {
var bb = Y.Node.create( '<div class="yui3-skin-foo"><div></div></div>' ),
cb = bb.one( 'div' ),
w = new Y.Widget( {
boundingBox: bb,
contentBox: cb
} );
Y.Assert.areEqual( "foo", w.getSkinName() );
},
"getSkinName should return name from body or null": function () {
var w = new Y.Widget().render(),
body = Y.one( 'body' );
Y.Assert.areEqual( "sam", w.getSkinName() );
body.removeClass( "yui3-skin-sam" );
Y.Assert.isNull( w.getSkinName() );
body.addClass( "yui3-skin-sam" );
},
"getSkinName should return name from ancestor if both ancestor and body are classed": function () {
var w = new Y.Widget().render( '#testbed' ),
body = Y.one( 'body' );
body.addClass( "yui3-skin-sam" );
Y.Assert.areEqual( "foo", w.getSkinName() );
},
testRenderedDestroy: function() {
var w = new Y.Widget().render();
try {
w.destroy();
} catch(e) {
Y.Assert.fail("w.destroy() on a rendered widget threw an exception" + e);
}
},
testUnrenderedDestroy: function() {
var w = new Y.Widget();
try {
w.destroy();
} catch(e) {
Y.Assert.fail("w.destroy() on an unrendered widget threw an exception" + e);
}
},
testWidgetClone : function() {
var a = new Y.Widget();
var b = new Y.Widget();
var c = new Y.Widget();
var a1 = Y.clone(a);
var a2 = Y.clone(a1);
var a3 = Y.clone(a2);
Y.Assert.isTrue(a instanceof Y.Widget);
Y.Assert.isTrue(a1 instanceof Y.Widget);
Y.Assert.isTrue(a2 instanceof Y.Widget);
Y.Assert.isTrue(a3 instanceof Y.Widget);
var b1 = Y.clone(b);
var b2 = Y.clone(b1);
var b3 = Y.clone(b2);
Y.Assert.isTrue(b instanceof Y.Widget);
Y.Assert.isTrue(b1 instanceof Y.Widget);
Y.Assert.isTrue(b2 instanceof Y.Widget);
Y.Assert.isTrue(b3 instanceof Y.Widget);
var c1 = Y.clone(c);
var c2 = Y.clone(c1);
var c3 = Y.clone(c2);
Y.Assert.isTrue(c instanceof Y.Widget);
Y.Assert.isTrue(c1 instanceof Y.Widget);
Y.Assert.isTrue(c2 instanceof Y.Widget);
Y.Assert.isTrue(c3 instanceof Y.Widget);
},
testWidgetHashClone : function() {
// When Widget's are properties of an object it seems to break apart
// something not passed to the recursive call maybe?
var a = new Y.Widget();
var b = new Y.Widget();
var c = new Y.Widget();
var o = {
a : a,
b : b,
c : c
};
var o1 = Y.clone(o);
var o2 = Y.clone(o1);
var o3 = Y.clone(o2);
Y.Assert.isTrue(o3.a instanceof Y.Widget);
Y.Assert.isTrue(o3.b instanceof Y.Widget);
Y.Assert.isTrue(o3.c instanceof Y.Widget);
},
testBaseClone : function() {
var a = new Y.Base();
var b = new Y.Base();
var c = new Y.Base();
// Base works fine
var a1 = Y.clone(a);
var a2 = Y.clone(a1);
var a3 = Y.clone(a2);
Y.Assert.isTrue(a instanceof Y.Base);
Y.Assert.isTrue(a1 instanceof Y.Base);
Y.Assert.isTrue(a2 instanceof Y.Base);
Y.Assert.isTrue(a3 instanceof Y.Base);
var b1 = Y.clone(b);
var b2 = Y.clone(b1);
var b3 = Y.clone(b2);
Y.Assert.isTrue(b instanceof Y.Base);
Y.Assert.isTrue(b1 instanceof Y.Base);
Y.Assert.isTrue(b2 instanceof Y.Base);
Y.Assert.isTrue(b3 instanceof Y.Base);
var c1 = Y.clone(c);
var c2 = Y.clone(c1);
var c3 = Y.clone(c2);
Y.Assert.isTrue(c instanceof Y.Base);
Y.Assert.isTrue(c1 instanceof Y.Base);
Y.Assert.isTrue(c2 instanceof Y.Base);
Y.Assert.isTrue(c3 instanceof Y.Base);
},
testBaseHashClone : function() {
var a = new Y.Base();
var b = new Y.Base();
var c = new Y.Base();
var o = {
a : a,
b : b,
c : c
};
var o1 = Y.clone(o);
var o2 = Y.clone(o1);
var o3 = Y.clone(o2);
Y.Assert.isTrue(o3.a instanceof Y.Base);
Y.Assert.isTrue(o3.b instanceof Y.Base);
Y.Assert.isTrue(o3.c instanceof Y.Base);
}
}));
new Y.Console({
newestOnTop: false,
height: '580px'
}).render();
Y.Test.Runner.add(suite);
Y.Test.Runner.run();
});
</script>
</body>
</html>