widget.html revision 81ed0aaa8456bd5c6a54e7797258b1f182eb1f5b
290N/A<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
290N/A<html>
290N/A<head>
290N/A <title>Widget Test Suite</title>
290N/A
290N/A <script src="/build/yui/yui.js"></script>
290N/A
290N/A <style type="text/css">
290N/A #console .yui3-console-entry {
290N/A padding:2px;
290N/A margin:0px;
290N/A min-height:0;
290N/A }
290N/A
290N/A #console .yui3-console-entry-fail .yui3-console-entry-cat {
290N/A background-color:red;
290N/A }
290N/A
290N/A #console .yui3-console-entry-pass .yui3-console-entry-cat {
290N/A background-color:green;
2339N/A }
2690N/A
2339N/A #console .yui3-console-entry-perf .yui3-console-entry-cat {
290N/A background-color:blue;
290N/A }
290N/A
290N/A #console {
290N/A position:static;
290N/A }
290N/A
290N/A html, body {
290N/A height:100%;
290N/A }
290N/A </style>
290N/A</head>
290N/A<body class="yui3-skin-sam">
290N/A<div id="testbed" class="yui3-skin-foo"></div>
290N/A<script>
290N/AYUI({useBrowserConsole:false}).use('test', 'widget', 'console', function (Y) {
290N/A
290N/A var suite = new Y.Test.Suite("Widget Tests");
290N/A
290N/A suite.add(new Y.Test.Case({
290N/A
290N/A name : "getSkinName",
290N/A
290N/A "getSkinName should return null if not rendered" : function () {
290N/A var w = new Y.Widget();
290N/A
290N/A Y.Assert.isNull( w.getSkinName() );
290N/A },
2690N/A
2690N/A "getSkinName should return name from BB if available": function () {
2690N/A var bb = Y.Node.create( '<div class="yui3-skin-foo"><div></div></div>' ),
2690N/A cb = bb.one( 'div' ),
2690N/A w = new Y.Widget( {
2690N/A boundingBox: bb,
2690N/A contentBox: cb
2690N/A } );
2690N/A
2690N/A Y.Assert.areEqual( "foo", w.getSkinName() );
2690N/A },
2690N/A
2690N/A "getSkinName should return name from body or null": function () {
2828N/A var w = new Y.Widget().render(),
2828N/A body = Y.one( 'body' );
290N/A
290N/A Y.Assert.areEqual( "sam", w.getSkinName() );
290N/A
290N/A body.removeClass( "yui3-skin-sam" );
290N/A
290N/A Y.Assert.isNull( w.getSkinName() );
290N/A
290N/A body.addClass( "yui3-skin-sam" );
290N/A },
290N/A
290N/A "getSkinName should return name from ancestor if both ancestor and body are classed": function () {
290N/A var w = new Y.Widget().render( '#testbed' ),
290N/A body = Y.one( 'body' );
290N/A
290N/A body.addClass( "yui3-skin-sam" );
290N/A
290N/A Y.Assert.areEqual( "foo", w.getSkinName() );
290N/A }
290N/A }));
290N/A
290N/A suite.add(new Y.Test.Case({
290N/A
290N/A name:"destroy",
290N/A
290N/A testRenderedDestroy: function() {
290N/A var w = new Y.Widget({id:"foo"}).render();
290N/A try {
290N/A w.destroy();
290N/A Y.Assert.isNull(Y.Node.one("#foo"), "Bounding box still in DOM");
290N/A } catch(e) {
290N/A Y.Assert.fail("w.destroy() on a rendered widget threw an exception" + e);
290N/A }
290N/A },
290N/A
290N/A testUnrenderedDestroy: function() {
290N/A var w = new Y.Widget();
290N/A try {
2690N/A w.destroy();
290N/A } catch(e) {
290N/A Y.Assert.fail("w.destroy() on an unrendered widget threw an exception" + e);
290N/A }
290N/A },
290N/A
290N/A testSingleBoxDestroy: function() {
290N/A
290N/A function MyWidget() {
290N/A MyWidget.superclass.constructor.apply(this, arguments);
290N/A };
290N/A MyWidget.NAME = "myWidget";
290N/A
290N/A Y.extend(MyWidget, Y.Widget, {
290N/A CONTENT_TEMPLATE:null
290N/A });
290N/A
290N/A var w = new MyWidget({
290N/A id:"foo"
290N/A });
290N/A
290N/A try {
290N/A w.destroy();
290N/A Y.Assert.isNull(Y.Node.one("#foo"), "Bounding box still in DOM");
290N/A } catch(e) {
290N/A Y.Assert.fail("w.destroy() on a single box widget threw an exception" + e);
290N/A }
290N/A },
290N/A
290N/A testWidgetClone : function() {
290N/A var a = new Y.Widget();
290N/A var b = new Y.Widget();
290N/A var c = new Y.Widget();
290N/A
290N/A var a1 = Y.clone(a);
290N/A var a2 = Y.clone(a1);
290N/A var a3 = Y.clone(a2);
290N/A
290N/A Y.Assert.isTrue(a instanceof Y.Widget);
290N/A Y.Assert.isTrue(a1 instanceof Y.Widget);
290N/A Y.Assert.isTrue(a2 instanceof Y.Widget);
290N/A Y.Assert.isTrue(a3 instanceof Y.Widget);
290N/A
290N/A var b1 = Y.clone(b);
290N/A var b2 = Y.clone(b1);
290N/A var b3 = Y.clone(b2);
290N/A
290N/A Y.Assert.isTrue(b instanceof Y.Widget);
290N/A Y.Assert.isTrue(b1 instanceof Y.Widget);
2690N/A Y.Assert.isTrue(b2 instanceof Y.Widget);
290N/A Y.Assert.isTrue(b3 instanceof Y.Widget);
290N/A
290N/A var c1 = Y.clone(c);
290N/A var c2 = Y.clone(c1);
290N/A var c3 = Y.clone(c2);
290N/A
290N/A Y.Assert.isTrue(c instanceof Y.Widget);
290N/A Y.Assert.isTrue(c1 instanceof Y.Widget);
290N/A Y.Assert.isTrue(c2 instanceof Y.Widget);
290N/A Y.Assert.isTrue(c3 instanceof Y.Widget);
290N/A },
290N/A
290N/A testWidgetHashClone : function() {
290N/A // When Widget's are properties of an object it seems to break apart
290N/A // something not passed to the recursive call maybe?
290N/A
290N/A var a = new Y.Widget();
290N/A var b = new Y.Widget();
290N/A var c = new Y.Widget();
290N/A
2690N/A var o = {
290N/A a : a,
290N/A b : b,
290N/A c : c
2690N/A };
290N/A
290N/A var o1 = Y.clone(o);
290N/A var o2 = Y.clone(o1);
290N/A var o3 = Y.clone(o2);
290N/A
290N/A Y.Assert.isTrue(o3.a instanceof Y.Widget);
290N/A Y.Assert.isTrue(o3.b instanceof Y.Widget);
290N/A Y.Assert.isTrue(o3.c instanceof Y.Widget);
290N/A },
290N/A
290N/A testBaseClone : function() {
290N/A var a = new Y.Base();
290N/A var b = new Y.Base();
290N/A var c = new Y.Base();
290N/A
290N/A // Base works fine
290N/A
290N/A var a1 = Y.clone(a);
290N/A var a2 = Y.clone(a1);
2690N/A var a3 = Y.clone(a2);
290N/A
290N/A Y.Assert.isTrue(a instanceof Y.Base);
290N/A Y.Assert.isTrue(a1 instanceof Y.Base);
290N/A Y.Assert.isTrue(a2 instanceof Y.Base);
290N/A Y.Assert.isTrue(a3 instanceof Y.Base);
290N/A
290N/A var b1 = Y.clone(b);
290N/A var b2 = Y.clone(b1);
290N/A var b3 = Y.clone(b2);
290N/A
290N/A Y.Assert.isTrue(b instanceof Y.Base);
290N/A Y.Assert.isTrue(b1 instanceof Y.Base);
290N/A Y.Assert.isTrue(b2 instanceof Y.Base);
2690N/A Y.Assert.isTrue(b3 instanceof Y.Base);
290N/A
290N/A var c1 = Y.clone(c);
290N/A var c2 = Y.clone(c1);
290N/A var c3 = Y.clone(c2);
290N/A
290N/A Y.Assert.isTrue(c instanceof Y.Base);
290N/A Y.Assert.isTrue(c1 instanceof Y.Base);
290N/A Y.Assert.isTrue(c2 instanceof Y.Base);
290N/A Y.Assert.isTrue(c3 instanceof Y.Base);
290N/A },
290N/A
290N/A testBaseHashClone : function() {
290N/A var a = new Y.Base();
290N/A var b = new Y.Base();
290N/A var c = new Y.Base();
290N/A
290N/A var o = {
290N/A a : a,
290N/A b : b,
290N/A c : c
290N/A };
290N/A
290N/A var o1 = Y.clone(o);
290N/A var o2 = Y.clone(o1);
290N/A var o3 = Y.clone(o2);
290N/A
290N/A Y.Assert.isTrue(o3.a instanceof Y.Base);
290N/A Y.Assert.isTrue(o3.b instanceof Y.Base);
290N/A Y.Assert.isTrue(o3.c instanceof Y.Base);
290N/A }
290N/A }));
290N/A
290N/A Y.Test.Runner.setName("Widget Tests");
290N/A Y.Test.Runner.add(suite);
290N/A Y.Test.Runner.disableLogging();
2690N/A Y.Test.Runner.run();
290N/A
290N/A var console;
290N/A
290N/A Y.one("#btnRun").set("disabled", false).on("click", function() {
290N/A if (!console) {
290N/A console = new Y.Console({
290N/A id:"console",
290N/A width:"100%",
290N/A height:"90%",
290N/A verbose : false,
290N/A printTimeout: 0,
290N/A newestOnTop : false,
290N/A entryTemplate: '<pre class="{entry_class} {cat_class} {src_class}">'+
290N/A '<span class="{entry_cat_class}">{label}</span>'+
290N/A '<span class="{entry_content_class}">{message}</span>'+
290N/A '</pre>'
290N/A }).render();
290N/A }
290N/A
290N/A Y.Test.Runner.enableLogging();
290N/A Y.Test.Runner.run();
290N/A });
290N/A});
2690N/A</script>
290N/A<p><input type="button" value="Run Tests" id="btnRun" disabled=true></p>
290N/A</body>
290N/A</html>
1933N/A