parent-child.html revision 8210c45660fdfb72dd288f258040dd11b6ba71b2
a93a1f58a8763fa69172980b98e3d24720c1136egm<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
a93a1f58a8763fa69172980b98e3d24720c1136egm "http://www.w3.org/TR/html4/strict.dtd">
a93a1f58a8763fa69172980b98e3d24720c1136egm
a93a1f58a8763fa69172980b98e3d24720c1136egm<html>
a93a1f58a8763fa69172980b98e3d24720c1136egm<head>
a93a1f58a8763fa69172980b98e3d24720c1136egm <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
a93a1f58a8763fa69172980b98e3d24720c1136egm <title>Widget Parent API Tests</title>
a93a1f58a8763fa69172980b98e3d24720c1136egm
a93a1f58a8763fa69172980b98e3d24720c1136egm <link rel="stylesheet" type="text/css" href="/build/cssreset/reset-min.css">
a93a1f58a8763fa69172980b98e3d24720c1136egm <link rel="stylesheet" type="text/css" href="/build/cssfonts/fonts-min.css">
a93a1f58a8763fa69172980b98e3d24720c1136egm <link rel="stylesheet" type="text/css" href="/build_files/tablist.css">
a93a1f58a8763fa69172980b98e3d24720c1136egm
a93a1f58a8763fa69172980b98e3d24720c1136egm <script src="/build/yui/yui-min.js" type="text/javascript"></script>
a93a1f58a8763fa69172980b98e3d24720c1136egm
a93a1f58a8763fa69172980b98e3d24720c1136egm</head>
a93a1f58a8763fa69172980b98e3d24720c1136egm<body class="yui3-skin-sam">
a93a1f58a8763fa69172980b98e3d24720c1136egm
a93a1f58a8763fa69172980b98e3d24720c1136egm <script type="text/javascript">
a93a1f58a8763fa69172980b98e3d24720c1136egm
a93a1f58a8763fa69172980b98e3d24720c1136egm YUI({
a93a1f58a8763fa69172980b98e3d24720c1136egm
a93a1f58a8763fa69172980b98e3d24720c1136egm base: "/build/",
a93a1f58a8763fa69172980b98e3d24720c1136egm timeout: 10000,
a93a1f58a8763fa69172980b98e3d24720c1136egm filter: "raw"
a93a1f58a8763fa69172980b98e3d24720c1136egm
a93a1f58a8763fa69172980b98e3d24720c1136egm }).use("widget", "widget-parent", "widget-child", "test", "console", function (Y) {
a93a1f58a8763fa69172980b98e3d24720c1136egm
a93a1f58a8763fa69172980b98e3d24720c1136egm
a93a1f58a8763fa69172980b98e3d24720c1136egm var RootWidget = function () {
a93a1f58a8763fa69172980b98e3d24720c1136egm RootWidget.superclass.constructor.apply(this, arguments);
a93a1f58a8763fa69172980b98e3d24720c1136egm };
a93a1f58a8763fa69172980b98e3d24720c1136egm
a93a1f58a8763fa69172980b98e3d24720c1136egm RootWidget.NAME = "rootwidget";
a93a1f58a8763fa69172980b98e3d24720c1136egm
a93a1f58a8763fa69172980b98e3d24720c1136egm Y.extend(RootWidget, Y.Widget);
a93a1f58a8763fa69172980b98e3d24720c1136egm
a93a1f58a8763fa69172980b98e3d24720c1136egm Y.RootWidget = Y.Base.build("rootwidget", RootWidget, [Y.WidgetParent], { dynamic: false });
a93a1f58a8763fa69172980b98e3d24720c1136egm
a93a1f58a8763fa69172980b98e3d24720c1136egm
a93a1f58a8763fa69172980b98e3d24720c1136egm var ParentWidget = function () {
a93a1f58a8763fa69172980b98e3d24720c1136egm ParentWidget.superclass.constructor.apply(this, arguments);
a93a1f58a8763fa69172980b98e3d24720c1136egm };
a93a1f58a8763fa69172980b98e3d24720c1136egm
a93a1f58a8763fa69172980b98e3d24720c1136egm Y.mix(ParentWidget, {
a93a1f58a8763fa69172980b98e3d24720c1136egm
a93a1f58a8763fa69172980b98e3d24720c1136egm NAME: "parentwidget",
a93a1f58a8763fa69172980b98e3d24720c1136egm
a93a1f58a8763fa69172980b98e3d24720c1136egm ATTRS: {
a93a1f58a8763fa69172980b98e3d24720c1136egm
a93a1f58a8763fa69172980b98e3d24720c1136egm label: {
a93a1f58a8763fa69172980b98e3d24720c1136egm validator: Y.Lang.isString
a93a1f58a8763fa69172980b98e3d24720c1136egm }
a93a1f58a8763fa69172980b98e3d24720c1136egm
a93a1f58a8763fa69172980b98e3d24720c1136egm }
a93a1f58a8763fa69172980b98e3d24720c1136egm
a93a1f58a8763fa69172980b98e3d24720c1136egm });
a93a1f58a8763fa69172980b98e3d24720c1136egm
a93a1f58a8763fa69172980b98e3d24720c1136egm Y.extend(ParentWidget, Y.Widget, {
a93a1f58a8763fa69172980b98e3d24720c1136egm
a93a1f58a8763fa69172980b98e3d24720c1136egm renderUI: function () {
a93a1f58a8763fa69172980b98e3d24720c1136egm
a93a1f58a8763fa69172980b98e3d24720c1136egm ParentWidget.superclass.renderUI.apply(this, arguments);
a93a1f58a8763fa69172980b98e3d24720c1136egm
a93a1f58a8763fa69172980b98e3d24720c1136egm if (this.get("depth") > -1) {
a93a1f58a8763fa69172980b98e3d24720c1136egm
a93a1f58a8763fa69172980b98e3d24720c1136egm var label = Y.Node.create("<em>" + this.get("label") + "</em>"),
a93a1f58a8763fa69172980b98e3d24720c1136egm parent = this.get("boundingBox").get("parentNode");
a93a1f58a8763fa69172980b98e3d24720c1136egm
a93a1f58a8763fa69172980b98e3d24720c1136egm parent.appendChild(label);
a93a1f58a8763fa69172980b98e3d24720c1136egm
a93a1f58a8763fa69172980b98e3d24720c1136egm }
a93a1f58a8763fa69172980b98e3d24720c1136egm
a93a1f58a8763fa69172980b98e3d24720c1136egm }
a93a1f58a8763fa69172980b98e3d24720c1136egm
a93a1f58a8763fa69172980b98e3d24720c1136egm });
a93a1f58a8763fa69172980b98e3d24720c1136egm
a93a1f58a8763fa69172980b98e3d24720c1136egm Y.ParentWidget = Y.Base.build("parentwidget", ParentWidget, [Y.WidgetParent, Y.WidgetChild], { dynamic: false });
a93a1f58a8763fa69172980b98e3d24720c1136egm
a93a1f58a8763fa69172980b98e3d24720c1136egm
a93a1f58a8763fa69172980b98e3d24720c1136egm var ChildWidget = function () {
a93a1f58a8763fa69172980b98e3d24720c1136egm ChildWidget.superclass.constructor.apply(this, arguments);
a93a1f58a8763fa69172980b98e3d24720c1136egm };
a93a1f58a8763fa69172980b98e3d24720c1136egm
a93a1f58a8763fa69172980b98e3d24720c1136egm Y.mix(ChildWidget, {
a93a1f58a8763fa69172980b98e3d24720c1136egm
a93a1f58a8763fa69172980b98e3d24720c1136egm NAME: "childwidget",
a93a1f58a8763fa69172980b98e3d24720c1136egm
a93a1f58a8763fa69172980b98e3d24720c1136egm ATTRS: {
a93a1f58a8763fa69172980b98e3d24720c1136egm
a93a1f58a8763fa69172980b98e3d24720c1136egm label: {
a93a1f58a8763fa69172980b98e3d24720c1136egm validator: Y.Lang.isString
a93a1f58a8763fa69172980b98e3d24720c1136egm }
a93a1f58a8763fa69172980b98e3d24720c1136egm
a93a1f58a8763fa69172980b98e3d24720c1136egm }
a93a1f58a8763fa69172980b98e3d24720c1136egm
a93a1f58a8763fa69172980b98e3d24720c1136egm });
a93a1f58a8763fa69172980b98e3d24720c1136egm
a93a1f58a8763fa69172980b98e3d24720c1136egm Y.extend(ChildWidget, Y.Widget, {
a93a1f58a8763fa69172980b98e3d24720c1136egm
a93a1f58a8763fa69172980b98e3d24720c1136egm renderUI: function () {
a93a1f58a8763fa69172980b98e3d24720c1136egm this.get("contentBox").setContent(this.get("label"));
a93a1f58a8763fa69172980b98e3d24720c1136egm }
a93a1f58a8763fa69172980b98e3d24720c1136egm
a93a1f58a8763fa69172980b98e3d24720c1136egm });
a93a1f58a8763fa69172980b98e3d24720c1136egm
a93a1f58a8763fa69172980b98e3d24720c1136egm
a93a1f58a8763fa69172980b98e3d24720c1136egm Y.ChildWidget = Y.Base.build("childwidget", ChildWidget, [Y.WidgetChild], { dynamic: false });
a93a1f58a8763fa69172980b98e3d24720c1136egm
a93a1f58a8763fa69172980b98e3d24720c1136egm
a93a1f58a8763fa69172980b98e3d24720c1136egm
a93a1f58a8763fa69172980b98e3d24720c1136egm var debugConsole = new Y.Console().render();
a93a1f58a8763fa69172980b98e3d24720c1136egm
a93a1f58a8763fa69172980b98e3d24720c1136egm
a93a1f58a8763fa69172980b98e3d24720c1136egm
a93a1f58a8763fa69172980b98e3d24720c1136egm Y.Test.Runner.add( new Y.Test.Case({
a93a1f58a8763fa69172980b98e3d24720c1136egm
a93a1f58a8763fa69172980b98e3d24720c1136egm name: "Widget Parent API, Widget Child API Tests",
a93a1f58a8763fa69172980b98e3d24720c1136egm
a93a1f58a8763fa69172980b98e3d24720c1136egm testAdd: function() {
a93a1f58a8763fa69172980b98e3d24720c1136egm
a93a1f58a8763fa69172980b98e3d24720c1136egm var root = new Y.ParentWidget(),
a93a1f58a8763fa69172980b98e3d24720c1136egm child,
a93a1f58a8763fa69172980b98e3d24720c1136egm MyChild;
a93a1f58a8763fa69172980b98e3d24720c1136egm
a93a1f58a8763fa69172980b98e3d24720c1136egm
a93a1f58a8763fa69172980b98e3d24720c1136egm child = root.add({ type: "ChildWidget", label: "Child One" });
a93a1f58a8763fa69172980b98e3d24720c1136egm
a93a1f58a8763fa69172980b98e3d24720c1136egm Y.Assert.isNotUndefined(child, "Add should return a reference to the child that was created and added.");
a93a1f58a8763fa69172980b98e3d24720c1136egm Y.assert((root.size() == 1), "The root Widget should have one child");
a93a1f58a8763fa69172980b98e3d24720c1136egm
a93a1f58a8763fa69172980b98e3d24720c1136egm
a93a1f58a8763fa69172980b98e3d24720c1136egm child = root.add({ type: ChildWidget, label: "Child Two" });
a93a1f58a8763fa69172980b98e3d24720c1136egm
a93a1f58a8763fa69172980b98e3d24720c1136egm Y.Assert.isNotUndefined(child, "Add should return a reference to the child that was created and added.");
a93a1f58a8763fa69172980b98e3d24720c1136egm Y.assert((root.size() == 2), "The root Widget should have two children");
a93a1f58a8763fa69172980b98e3d24720c1136egm
a93a1f58a8763fa69172980b98e3d24720c1136egm
a93a1f58a8763fa69172980b98e3d24720c1136egm try {
a93a1f58a8763fa69172980b98e3d24720c1136egm
a93a1f58a8763fa69172980b98e3d24720c1136egm child = root.add({ label: "Invalid Child" });
a93a1f58a8763fa69172980b98e3d24720c1136egm
a93a1f58a8763fa69172980b98e3d24720c1136egm Y.Assert.isUndefined(child, "Add should return undefined since the type of the child is undefined.");
a93a1f58a8763fa69172980b98e3d24720c1136egm Y.assert((root.size() == 2), "The root Widget should have two children");
a93a1f58a8763fa69172980b98e3d24720c1136egm
a93a1f58a8763fa69172980b98e3d24720c1136egm }
a93a1f58a8763fa69172980b98e3d24720c1136egm catch (e) {
a93a1f58a8763fa69172980b98e3d24720c1136egm Y.Assert.isNotUndefined(e, "The \"add\" method should throw an error since the type of the child was not specified and the defaultChildType attribute is not defined.");
a93a1f58a8763fa69172980b98e3d24720c1136egm }
a93a1f58a8763fa69172980b98e3d24720c1136egm
a93a1f58a8763fa69172980b98e3d24720c1136egm
a93a1f58a8763fa69172980b98e3d24720c1136egm try {
a93a1f58a8763fa69172980b98e3d24720c1136egm
a93a1f58a8763fa69172980b98e3d24720c1136egm child = root.add({ type: "MyChild", label: "Invalid Child" });
a93a1f58a8763fa69172980b98e3d24720c1136egm
a93a1f58a8763fa69172980b98e3d24720c1136egm Y.Assert.isUndefined(child, "The \"add\" method should return undefined since the type of the child is invalid.");
a93a1f58a8763fa69172980b98e3d24720c1136egm Y.assert((root.size() == 2), "The root Widget should have two children");
a93a1f58a8763fa69172980b98e3d24720c1136egm
a93a1f58a8763fa69172980b98e3d24720c1136egm }
a93a1f58a8763fa69172980b98e3d24720c1136egm catch (e) {
a93a1f58a8763fa69172980b98e3d24720c1136egm Y.Assert.isNotUndefined(e, "The \"add\" method should throw an error since the type of the child is invalid.");
a93a1f58a8763fa69172980b98e3d24720c1136egm }
a93a1f58a8763fa69172980b98e3d24720c1136egm
a93a1f58a8763fa69172980b98e3d24720c1136egm
a93a1f58a8763fa69172980b98e3d24720c1136egm try {
a93a1f58a8763fa69172980b98e3d24720c1136egm
a93a1f58a8763fa69172980b98e3d24720c1136egm child = root.add({ type: MyChild, label: "Invalid Child" });
a93a1f58a8763fa69172980b98e3d24720c1136egm
a93a1f58a8763fa69172980b98e3d24720c1136egm Y.Assert.isUndefined(child, "Add should return undefined since the type of the child is invalid.");
a93a1f58a8763fa69172980b98e3d24720c1136egm Y.assert((root.size() == 2), "The root Widget should have two children");
a93a1f58a8763fa69172980b98e3d24720c1136egm
a93a1f58a8763fa69172980b98e3d24720c1136egm }
a93a1f58a8763fa69172980b98e3d24720c1136egm catch (e) {
a93a1f58a8763fa69172980b98e3d24720c1136egm Y.Assert.isNotUndefined(e, "The \"add\" method should throw an error since the type of the child is invalid.");
a93a1f58a8763fa69172980b98e3d24720c1136egm }
a93a1f58a8763fa69172980b98e3d24720c1136egm
a93a1f58a8763fa69172980b98e3d24720c1136egm
a93a1f58a8763fa69172980b98e3d24720c1136egm root.set("defaultChildType", "ChildWidget");
a93a1f58a8763fa69172980b98e3d24720c1136egm
a93a1f58a8763fa69172980b98e3d24720c1136egm child = root.add({ label: "Child Three" });
a93a1f58a8763fa69172980b98e3d24720c1136egm
a93a1f58a8763fa69172980b98e3d24720c1136egm Y.Assert.isNotUndefined(child, "Add should return a reference to the child that was created and added.");
a93a1f58a8763fa69172980b98e3d24720c1136egm Y.assert((root.size() == 3), "The root Widget should have three children");
a93a1f58a8763fa69172980b98e3d24720c1136egm
a93a1f58a8763fa69172980b98e3d24720c1136egm
a93a1f58a8763fa69172980b98e3d24720c1136egm root.set("defaultChildType", ChildWidget);
a93a1f58a8763fa69172980b98e3d24720c1136egm
a93a1f58a8763fa69172980b98e3d24720c1136egm child = root.add({ label: "Child Four" });
a93a1f58a8763fa69172980b98e3d24720c1136egm
a93a1f58a8763fa69172980b98e3d24720c1136egm Y.Assert.isNotUndefined(child, "Add should return a reference to the child that was created and added.");
a93a1f58a8763fa69172980b98e3d24720c1136egm Y.assert((root.size() == 4), "The root Widget should have four children");
a93a1f58a8763fa69172980b98e3d24720c1136egm
a93a1f58a8763fa69172980b98e3d24720c1136egm
a93a1f58a8763fa69172980b98e3d24720c1136egm root.set("defaultChildType", "MyChild");
a93a1f58a8763fa69172980b98e3d24720c1136egm
a93a1f58a8763fa69172980b98e3d24720c1136egm Y.Assert.areEqual(root.get("defaultChildType"), Y.ChildWidget, "Setter for \"defaultChildType\" should disallow setting the attribute to an invalid value.");
a93a1f58a8763fa69172980b98e3d24720c1136egm
a93a1f58a8763fa69172980b98e3d24720c1136egm
a93a1f58a8763fa69172980b98e3d24720c1136egm root.set("defaultChildType", MyChild);
a93a1f58a8763fa69172980b98e3d24720c1136egm
a93a1f58a8763fa69172980b98e3d24720c1136egm Y.Assert.areEqual(root.get("defaultChildType"), Y.ChildWidget, "Setter for \"defaultChildType\" should disallow setting the attribute to an invalid value.");
a93a1f58a8763fa69172980b98e3d24720c1136egm
a93a1f58a8763fa69172980b98e3d24720c1136egm
a93a1f58a8763fa69172980b98e3d24720c1136egm root.render();
a93a1f58a8763fa69172980b98e3d24720c1136egm
a93a1f58a8763fa69172980b98e3d24720c1136egm root.destroy();
a93a1f58a8763fa69172980b98e3d24720c1136egm
a93a1f58a8763fa69172980b98e3d24720c1136egm },
a93a1f58a8763fa69172980b98e3d24720c1136egm
a93a1f58a8763fa69172980b98e3d24720c1136egm testInsert: function () {
a93a1f58a8763fa69172980b98e3d24720c1136egm
a93a1f58a8763fa69172980b98e3d24720c1136egm var widget = new Y.ParentWidget({
a93a1f58a8763fa69172980b98e3d24720c1136egm
a93a1f58a8763fa69172980b98e3d24720c1136egm id: "widget-1",
a93a1f58a8763fa69172980b98e3d24720c1136egm children: [
a93a1f58a8763fa69172980b98e3d24720c1136egm { type: Y.ChildWidget, label: "Child One", id: "child-1" },
a93a1f58a8763fa69172980b98e3d24720c1136egm { type: Y.ChildWidget, label: "Child Two", id: "child-2" },
a93a1f58a8763fa69172980b98e3d24720c1136egm { type: Y.ChildWidget, label: "Child Three", id: "child-3" },
a93a1f58a8763fa69172980b98e3d24720c1136egm { type: Y.ChildWidget, label: "Child Four", id: "child-4" }
a93a1f58a8763fa69172980b98e3d24720c1136egm ]
a93a1f58a8763fa69172980b98e3d24720c1136egm
a93a1f58a8763fa69172980b98e3d24720c1136egm });
a93a1f58a8763fa69172980b98e3d24720c1136egm
a93a1f58a8763fa69172980b98e3d24720c1136egm widget.render();
a93a1f58a8763fa69172980b98e3d24720c1136egm
a93a1f58a8763fa69172980b98e3d24720c1136egm widget.add({ type: Y.ChildWidget, label: "Child One", id: "inserted-child-1" }, 0);
a93a1f58a8763fa69172980b98e3d24720c1136egm
a93a1f58a8763fa69172980b98e3d24720c1136egm Y.Assert.areEqual(widget.item(0).get("id"), "inserted-child-1", "The newly inserted child should be the parent's first child.");
a93a1f58a8763fa69172980b98e3d24720c1136egm Y.Assert.areEqual(widget.size(), 5, "The widget should have five children.");
a93a1f58a8763fa69172980b98e3d24720c1136egm
a93a1f58a8763fa69172980b98e3d24720c1136egm widget.add([
a93a1f58a8763fa69172980b98e3d24720c1136egm { type: Y.ChildWidget, label: "Child One", id: "inserted-child-2" },
a93a1f58a8763fa69172980b98e3d24720c1136egm { type: Y.ChildWidget, label: "Child One", id: "inserted-child-3" }
a93a1f58a8763fa69172980b98e3d24720c1136egm ], 2);
a93a1f58a8763fa69172980b98e3d24720c1136egm
a93a1f58a8763fa69172980b98e3d24720c1136egm Y.Assert.areEqual(widget.item(2).get("id"), "inserted-child-2", "The child with the id of \"inserted-child-2\" should be the parent's third child.");
a93a1f58a8763fa69172980b98e3d24720c1136egm Y.Assert.areEqual(widget.item(3).get("id"), "inserted-child-3", "The child with the id of \"inserted-child-3\" should be the parent's fourth child.");
a93a1f58a8763fa69172980b98e3d24720c1136egm Y.Assert.areEqual(widget.item(4).get("id"), "child-2", "The child with the id of \"child-2\" should now be the parent's fifth child.");
a93a1f58a8763fa69172980b98e3d24720c1136egm Y.Assert.areEqual(widget.size(), 7, "The widget should have seven children.");
a93a1f58a8763fa69172980b98e3d24720c1136egm
a93a1f58a8763fa69172980b98e3d24720c1136egm widget.destroy();
a93a1f58a8763fa69172980b98e3d24720c1136egm
a93a1f58a8763fa69172980b98e3d24720c1136egm },
a93a1f58a8763fa69172980b98e3d24720c1136egm
a93a1f58a8763fa69172980b98e3d24720c1136egm testRemove: function () {
a93a1f58a8763fa69172980b98e3d24720c1136egm
a93a1f58a8763fa69172980b98e3d24720c1136egm var widget = new Y.ParentWidget({
a93a1f58a8763fa69172980b98e3d24720c1136egm
a93a1f58a8763fa69172980b98e3d24720c1136egm id: "widget-1",
a93a1f58a8763fa69172980b98e3d24720c1136egm children: [
a93a1f58a8763fa69172980b98e3d24720c1136egm { type: Y.ChildWidget, label: "Child One", id: "child-1" },
a93a1f58a8763fa69172980b98e3d24720c1136egm { type: Y.ChildWidget, label: "Child Two", id: "child-2" },
a93a1f58a8763fa69172980b98e3d24720c1136egm { type: Y.ChildWidget, label: "Child Three", id: "child-3" },
a93a1f58a8763fa69172980b98e3d24720c1136egm { type: Y.ChildWidget, label: "Child Four", id: "child-4" }
a93a1f58a8763fa69172980b98e3d24720c1136egm ]
a93a1f58a8763fa69172980b98e3d24720c1136egm
a93a1f58a8763fa69172980b98e3d24720c1136egm });
a93a1f58a8763fa69172980b98e3d24720c1136egm
a93a1f58a8763fa69172980b98e3d24720c1136egm
a93a1f58a8763fa69172980b98e3d24720c1136egm widget.render();
a93a1f58a8763fa69172980b98e3d24720c1136egm
a93a1f58a8763fa69172980b98e3d24720c1136egm Y.Assert.areEqual(widget.remove(1).get("id"), "child-2", "The parent's \"remove\" method should return a reference to the child removed.");
a93a1f58a8763fa69172980b98e3d24720c1136egm Y.Assert.areEqual(widget.size(), 3, "The widget should now have three children.");
a93a1f58a8763fa69172980b98e3d24720c1136egm
a93a1f58a8763fa69172980b98e3d24720c1136egm
a93a1f58a8763fa69172980b98e3d24720c1136egm Y.Assert.areEqual(widget.item(0).remove().get("id"), "child-1", "If a child calls the \"remove\" method on itself, the \"remove\" method should return a reference to the child.");
a93a1f58a8763fa69172980b98e3d24720c1136egm Y.Assert.areEqual(widget.size(), 2, "The widget should now have two children.");
a93a1f58a8763fa69172980b98e3d24720c1136egm
a93a1f58a8763fa69172980b98e3d24720c1136egm
a93a1f58a8763fa69172980b98e3d24720c1136egm var removed = widget.removeAll();
a93a1f58a8763fa69172980b98e3d24720c1136egm
a93a1f58a8763fa69172980b98e3d24720c1136egm Y.Assert.areEqual(removed.size(), 2, "The \"removeAll\" method should return a Y.ArrayList instance with a size of 2.");
a93a1f58a8763fa69172980b98e3d24720c1136egm Y.Assert.areEqual(widget.size(), 0, "The widget should now have no children.");
a93a1f58a8763fa69172980b98e3d24720c1136egm
a93a1f58a8763fa69172980b98e3d24720c1136egm widget.destroy();
a93a1f58a8763fa69172980b98e3d24720c1136egm
a93a1f58a8763fa69172980b98e3d24720c1136egm },
a93a1f58a8763fa69172980b98e3d24720c1136egm
a93a1f58a8763fa69172980b98e3d24720c1136egm testSingleSelection: function () {
a93a1f58a8763fa69172980b98e3d24720c1136egm
a93a1f58a8763fa69172980b98e3d24720c1136egm var root = new Y.ParentWidget({
a93a1f58a8763fa69172980b98e3d24720c1136egm
a93a1f58a8763fa69172980b98e3d24720c1136egm id: "new-widget",
a93a1f58a8763fa69172980b98e3d24720c1136egm children: [
a93a1f58a8763fa69172980b98e3d24720c1136egm { type: Y.ChildWidget, label: "Child One" },
a93a1f58a8763fa69172980b98e3d24720c1136egm { type: Y.ChildWidget, label: "Child Two" },
a93a1f58a8763fa69172980b98e3d24720c1136egm { type: Y.ChildWidget, label: "Child Three" },
a93a1f58a8763fa69172980b98e3d24720c1136egm { type: Y.ChildWidget, label: "Child Four" }
a93a1f58a8763fa69172980b98e3d24720c1136egm ]
a93a1f58a8763fa69172980b98e3d24720c1136egm
a93a1f58a8763fa69172980b98e3d24720c1136egm });
a93a1f58a8763fa69172980b98e3d24720c1136egm
a93a1f58a8763fa69172980b98e3d24720c1136egm root.render();
a93a1f58a8763fa69172980b98e3d24720c1136egm
a93a1f58a8763fa69172980b98e3d24720c1136egm root.item(0).set("selected", 1);
a93a1f58a8763fa69172980b98e3d24720c1136egm root.item(1).set("selected", 1);
a93a1f58a8763fa69172980b98e3d24720c1136egm
a93a1f58a8763fa69172980b98e3d24720c1136egm // Confirm the selection
a93a1f58a8763fa69172980b98e3d24720c1136egm
a93a1f58a8763fa69172980b98e3d24720c1136egm Y.Assert.areEqual(root.item(1).get("selected"), 1, "The second child of the parent widget should be selected");
a93a1f58a8763fa69172980b98e3d24720c1136egm Y.Assert.areEqual(root.get("selected"), 2, "The root's \"selected\" attribute should return 2");
a93a1f58a8763fa69172980b98e3d24720c1136egm Y.Assert.areEqual(root.get("selection"), root.item(1), "The parent's \"selection\" attribute should return a reference to its second child.");
a93a1f58a8763fa69172980b98e3d24720c1136egm
a93a1f58a8763fa69172980b98e3d24720c1136egm
a93a1f58a8763fa69172980b98e3d24720c1136egm // Select another child and confirm the previously selected
a93a1f58a8763fa69172980b98e3d24720c1136egm // child is deselected and and the parent's selection is
a93a1f58a8763fa69172980b98e3d24720c1136egm // correctly updated.
a93a1f58a8763fa69172980b98e3d24720c1136egm
a93a1f58a8763fa69172980b98e3d24720c1136egm root.item(2).set("selected", 1);
a93a1f58a8763fa69172980b98e3d24720c1136egm
a93a1f58a8763fa69172980b98e3d24720c1136egm Y.Assert.areEqual(root.item(1).get("selected"), 0, "The parent's second child should not be selected");
a93a1f58a8763fa69172980b98e3d24720c1136egm Y.Assert.areEqual(root.item(2).get("selected"), 1, "The parent's third child should be selected");
a93a1f58a8763fa69172980b98e3d24720c1136egm Y.Assert.areEqual(root.get("selection"), root.item(2), "The parent's \"selection\" attribute should return a reference to its third child.");
a93a1f58a8763fa69172980b98e3d24720c1136egm
a93a1f58a8763fa69172980b98e3d24720c1136egm
a93a1f58a8763fa69172980b98e3d24720c1136egm // Confirm deselection
a93a1f58a8763fa69172980b98e3d24720c1136egm
a93a1f58a8763fa69172980b98e3d24720c1136egm root.item(2).set("selected", 0);
a93a1f58a8763fa69172980b98e3d24720c1136egm
a93a1f58a8763fa69172980b98e3d24720c1136egm Y.Assert.areEqual(root.item(2).get("selected"), 0, "The parent's third child should not be selected");
a93a1f58a8763fa69172980b98e3d24720c1136egm Y.Assert.areEqual(root.get("selected"), 0, "The parent's \"selected\" attribute should return 0");
a93a1f58a8763fa69172980b98e3d24720c1136egm Y.Assert.isNull(root.get("selection"), "The parent's \"selection\" attribute should return null.");
a93a1f58a8763fa69172980b98e3d24720c1136egm
a93a1f58a8763fa69172980b98e3d24720c1136egm root.destroy();
a93a1f58a8763fa69172980b98e3d24720c1136egm
a93a1f58a8763fa69172980b98e3d24720c1136egm
a93a1f58a8763fa69172980b98e3d24720c1136egm
a93a1f58a8763fa69172980b98e3d24720c1136egm var tree = new Y.ParentWidget({
a93a1f58a8763fa69172980b98e3d24720c1136egm
a93a1f58a8763fa69172980b98e3d24720c1136egm id: "tree",
a93a1f58a8763fa69172980b98e3d24720c1136egm children: [
a93a1f58a8763fa69172980b98e3d24720c1136egm
a93a1f58a8763fa69172980b98e3d24720c1136egm { type: Y.ChildWidget, id: "leaf-1", label: "Leaf One" },
a93a1f58a8763fa69172980b98e3d24720c1136egm { type: Y.ChildWidget, id: "leaf-2", label: "Leaf Two" },
a93a1f58a8763fa69172980b98e3d24720c1136egm { type: Y.ParentWidget, id: "subtree", label: "Subtree", children: [
a93a1f58a8763fa69172980b98e3d24720c1136egm
a93a1f58a8763fa69172980b98e3d24720c1136egm { type: Y.ChildWidget, id: "subtree-leaf-1", label: "Subtree - Leaf One" },
a93a1f58a8763fa69172980b98e3d24720c1136egm { type: Y.ChildWidget, id: "subtree-leaf-2", label: "Subtree - Leaf Two" },
a93a1f58a8763fa69172980b98e3d24720c1136egm { type: Y.ChildWidget, id: "subtree-leaf-3", label: "Subtree - Leaf Three" },
a93a1f58a8763fa69172980b98e3d24720c1136egm { type: Y.ChildWidget, id: "subtree-leaf-4", label: "Subtree - Leaf Four" }
a93a1f58a8763fa69172980b98e3d24720c1136egm
a93a1f58a8763fa69172980b98e3d24720c1136egm ]}
a93a1f58a8763fa69172980b98e3d24720c1136egm ]
a93a1f58a8763fa69172980b98e3d24720c1136egm
a93a1f58a8763fa69172980b98e3d24720c1136egm });
a93a1f58a8763fa69172980b98e3d24720c1136egm
a93a1f58a8763fa69172980b98e3d24720c1136egm tree.render();
a93a1f58a8763fa69172980b98e3d24720c1136egm
a93a1f58a8763fa69172980b98e3d24720c1136egm
a93a1f58a8763fa69172980b98e3d24720c1136egm // Select a child in the subtree to test if the selection is represented at the root level
a93a1f58a8763fa69172980b98e3d24720c1136egm
a93a1f58a8763fa69172980b98e3d24720c1136egm tree.item(2).item(0).set("selected", 1);
a93a1f58a8763fa69172980b98e3d24720c1136egm
a93a1f58a8763fa69172980b98e3d24720c1136egm Y.Assert.areEqual(tree.get("selected"), 2, "The root's \"selected\" attribute should be 2 (indicating partially selected).");
a93a1f58a8763fa69172980b98e3d24720c1136egm Y.Assert.areEqual(tree.item(2).get("selected"), 2, "The subtree's \"selected\" attribute should be 2 (indicating partially selected).");
a93a1f58a8763fa69172980b98e3d24720c1136egm Y.Assert.areEqual(tree.get("selection").get("id"), "subtree", "The root's \"selection\" attribute should return the subtree.");
a93a1f58a8763fa69172980b98e3d24720c1136egm Y.Assert.areEqual(tree.item(2).get("selection").get("id"), "subtree-leaf-1", "The subtree's \"selection\" attribute should return the first child.");
a93a1f58a8763fa69172980b98e3d24720c1136egm
a93a1f58a8763fa69172980b98e3d24720c1136egm
a93a1f58a8763fa69172980b98e3d24720c1136egm // Select a child in the root to confirm that the subtree's selection is cleared
a93a1f58a8763fa69172980b98e3d24720c1136egm
a93a1f58a8763fa69172980b98e3d24720c1136egm tree.item(0).set("selected", 1);
a93a1f58a8763fa69172980b98e3d24720c1136egm
a93a1f58a8763fa69172980b98e3d24720c1136egm Y.Assert.areEqual(tree.get("selected"), 2, "The root's \"selected\" attribute should be 2 (indicating partially selected).");
a93a1f58a8763fa69172980b98e3d24720c1136egm Y.Assert.areEqual(tree.get("selection").get("id"), "leaf-1", "The root's \"selection\" attribute should return a reference to its first child.");
a93a1f58a8763fa69172980b98e3d24720c1136egm Y.Assert.areEqual(tree.item(2).get("selected"), 0, "The subtree should no longer be selected.");
a93a1f58a8763fa69172980b98e3d24720c1136egm Y.Assert.areEqual(tree.item(2).get("selection"), null, "The subtree's \"selection\" attribute should return null.");
a93a1f58a8763fa69172980b98e3d24720c1136egm
a93a1f58a8763fa69172980b98e3d24720c1136egm
a93a1f58a8763fa69172980b98e3d24720c1136egm // Select a new child in the subtree to test if the selection is represented at the root level
a93a1f58a8763fa69172980b98e3d24720c1136egm
a93a1f58a8763fa69172980b98e3d24720c1136egm tree.item(2).item(2).set("selected", 1);
a93a1f58a8763fa69172980b98e3d24720c1136egm
a93a1f58a8763fa69172980b98e3d24720c1136egm Y.Assert.areEqual(tree.get("selected"), 2, "The root's \"selected\" attribute should be 2 (indicating partially selected).");
a93a1f58a8763fa69172980b98e3d24720c1136egm Y.Assert.areEqual(tree.item(2).get("selected"), 2, "The subtree's \"selected\" attribute should be 2 (indicating partially selected).");
a93a1f58a8763fa69172980b98e3d24720c1136egm Y.Assert.areEqual(tree.get("selection").get("id"), "subtree", "The root's \"selection\" attribute should return the subtree.");
a93a1f58a8763fa69172980b98e3d24720c1136egm Y.Assert.areEqual(tree.item(2).get("selection").get("id"), "subtree-leaf-3", "The subtree's \"selection\" attribute should return its third child.");
a93a1f58a8763fa69172980b98e3d24720c1136egm
a93a1f58a8763fa69172980b98e3d24720c1136egm
a93a1f58a8763fa69172980b98e3d24720c1136egm tree.destroy();
a93a1f58a8763fa69172980b98e3d24720c1136egm
a93a1f58a8763fa69172980b98e3d24720c1136egm },
a93a1f58a8763fa69172980b98e3d24720c1136egm
a93a1f58a8763fa69172980b98e3d24720c1136egm testMultipleSelection: function () {
a93a1f58a8763fa69172980b98e3d24720c1136egm
a93a1f58a8763fa69172980b98e3d24720c1136egm var root = new Y.ParentWidget({
a93a1f58a8763fa69172980b98e3d24720c1136egm
a93a1f58a8763fa69172980b98e3d24720c1136egm id: "m-s-widget",
a93a1f58a8763fa69172980b98e3d24720c1136egm multiple: true,
a93a1f58a8763fa69172980b98e3d24720c1136egm children: [
a93a1f58a8763fa69172980b98e3d24720c1136egm { type: Y.ChildWidget, label: "Child One" },
a93a1f58a8763fa69172980b98e3d24720c1136egm { type: Y.ChildWidget, label: "Child Two" },
a93a1f58a8763fa69172980b98e3d24720c1136egm { type: Y.ChildWidget, label: "Child Three" },
a93a1f58a8763fa69172980b98e3d24720c1136egm { type: Y.ChildWidget, label: "Child Four" }
a93a1f58a8763fa69172980b98e3d24720c1136egm ]
a93a1f58a8763fa69172980b98e3d24720c1136egm
a93a1f58a8763fa69172980b98e3d24720c1136egm });
a93a1f58a8763fa69172980b98e3d24720c1136egm
a93a1f58a8763fa69172980b98e3d24720c1136egm root.render();
a93a1f58a8763fa69172980b98e3d24720c1136egm
a93a1f58a8763fa69172980b98e3d24720c1136egm
a93a1f58a8763fa69172980b98e3d24720c1136egm root.item(0).set("selected", 1);
a93a1f58a8763fa69172980b98e3d24720c1136egm root.item(1).set("selected", 1);
a93a1f58a8763fa69172980b98e3d24720c1136egm
a93a1f58a8763fa69172980b98e3d24720c1136egm // Confirm that both children are selected and
a93a1f58a8763fa69172980b98e3d24720c1136egm // represented in the parent's selection.
a93a1f58a8763fa69172980b98e3d24720c1136egm
a93a1f58a8763fa69172980b98e3d24720c1136egm Y.Assert.areEqual(root.item(0).get("selected"), 1, "The first child of the parent widget should be selected.");
a93a1f58a8763fa69172980b98e3d24720c1136egm Y.Assert.areEqual(root.item(1).get("selected"), 1, "The second child of the parent widget should be selected.");
a93a1f58a8763fa69172980b98e3d24720c1136egm Y.Assert.areEqual(root.get("selection").size(), 2, "The \"selection\" attribute should return an ArrayList with a size of 2.");
a93a1f58a8763fa69172980b98e3d24720c1136egm Y.Assert.areEqual(root.get("selected"), 2, "The root's \"selection\" attribute should be 2 (indicating partially selected).");
a93a1f58a8763fa69172980b98e3d24720c1136egm
a93a1f58a8763fa69172980b98e3d24720c1136egm
a93a1f58a8763fa69172980b98e3d24720c1136egm // Select remaining children to confirm all children
a93a1f58a8763fa69172980b98e3d24720c1136egm // are represented in the parent's selection and that
a93a1f58a8763fa69172980b98e3d24720c1136egm // the parent's "selected" attribute returns 1.
a93a1f58a8763fa69172980b98e3d24720c1136egm
a93a1f58a8763fa69172980b98e3d24720c1136egm root.item(2).set("selected", 1);
a93a1f58a8763fa69172980b98e3d24720c1136egm root.item(3).set("selected", 1);
a93a1f58a8763fa69172980b98e3d24720c1136egm
a93a1f58a8763fa69172980b98e3d24720c1136egm Y.Assert.areEqual(root.get("selection").size(), 4, "The \"selection\" attribute should return an ArrayList with a size of 4.");
a93a1f58a8763fa69172980b98e3d24720c1136egm Y.Assert.areEqual(root.get("selected"), 1, "The root's \"selected\" attribute should return 1 (indicating fully selected).");
a93a1f58a8763fa69172980b98e3d24720c1136egm
a93a1f58a8763fa69172980b98e3d24720c1136egm
a93a1f58a8763fa69172980b98e3d24720c1136egm // Deselect all children and confirm the results
a93a1f58a8763fa69172980b98e3d24720c1136egm
a93a1f58a8763fa69172980b98e3d24720c1136egm root.get("selection").each(function (child) {
a93a1f58a8763fa69172980b98e3d24720c1136egm child.set("selected", 0);
a93a1f58a8763fa69172980b98e3d24720c1136egm });
a93a1f58a8763fa69172980b98e3d24720c1136egm
a93a1f58a8763fa69172980b98e3d24720c1136egm Y.Assert.isNull(root.get("selection"), "The root's \"selection\" attribute should return null.");
a93a1f58a8763fa69172980b98e3d24720c1136egm Y.Assert.areEqual(root.get("selected"), 0, "The root's \"selected\" attribute should return 0");
a93a1f58a8763fa69172980b98e3d24720c1136egm
a93a1f58a8763fa69172980b98e3d24720c1136egm
a93a1f58a8763fa69172980b98e3d24720c1136egm // Select all children via selectAll() to confirm all
a93a1f58a8763fa69172980b98e3d24720c1136egm // children are represented in the parent's selection and
a93a1f58a8763fa69172980b98e3d24720c1136egm // that the parent's "selected" attribute returns 1.
a93a1f58a8763fa69172980b98e3d24720c1136egm
a93a1f58a8763fa69172980b98e3d24720c1136egm root.selectAll();
a93a1f58a8763fa69172980b98e3d24720c1136egm Y.Assert.areEqual(root.get("selected"), 1, "The root's \"selected\" attribute should return 1");
a93a1f58a8763fa69172980b98e3d24720c1136egm Y.Assert.areEqual(root.get("selection").size(), 4, "The root's \"selection\" attribute should return an ArrayList with a size of 4.");
a93a1f58a8763fa69172980b98e3d24720c1136egm
a93a1f58a8763fa69172980b98e3d24720c1136egm
a93a1f58a8763fa69172980b98e3d24720c1136egm // Deselect all children via deselectAll() to confirm all
a93a1f58a8763fa69172980b98e3d24720c1136egm // children are no longer selected and that the parent's
a93a1f58a8763fa69172980b98e3d24720c1136egm // selection is empty.
a93a1f58a8763fa69172980b98e3d24720c1136egm
a93a1f58a8763fa69172980b98e3d24720c1136egm root.deselectAll();
a93a1f58a8763fa69172980b98e3d24720c1136egm
a93a1f58a8763fa69172980b98e3d24720c1136egm Y.Assert.areEqual(root.get("selected"), 0, "The root's \"selected\" attribute should return 0");
a93a1f58a8763fa69172980b98e3d24720c1136egm Y.Assert.areEqual(root.get("selection"), null, "The root's \"selection\" attribute should return an ArrayList with a size of 4.");
a93a1f58a8763fa69172980b98e3d24720c1136egm
a93a1f58a8763fa69172980b98e3d24720c1136egm
a93a1f58a8763fa69172980b98e3d24720c1136egm root.add({ type: Y.ParentWidget, id: "subtree", label: "Subtree", children: [
a93a1f58a8763fa69172980b98e3d24720c1136egm
a93a1f58a8763fa69172980b98e3d24720c1136egm { type: Y.ChildWidget, id: "subtree-leaf-1", label: "Subtree - Leaf One" },
a93a1f58a8763fa69172980b98e3d24720c1136egm { type: Y.ChildWidget, id: "subtree-leaf-2", label: "Subtree - Leaf Two" },
a93a1f58a8763fa69172980b98e3d24720c1136egm { type: Y.ChildWidget, id: "subtree-leaf-3", label: "Subtree - Leaf Three" },
a93a1f58a8763fa69172980b98e3d24720c1136egm { type: Y.ChildWidget, id: "subtree-leaf-4", label: "Subtree - Leaf Four" }
a93a1f58a8763fa69172980b98e3d24720c1136egm
a93a1f58a8763fa69172980b98e3d24720c1136egm ]});
a93a1f58a8763fa69172980b98e3d24720c1136egm
a93a1f58a8763fa69172980b98e3d24720c1136egm root.render();
a93a1f58a8763fa69172980b98e3d24720c1136egm
a93a1f58a8763fa69172980b98e3d24720c1136egm Y.Assert.isTrue(root.item(4).get("multiple"), "The \"multiple\" attribute of the nested parent widget should be true.");
a93a1f58a8763fa69172980b98e3d24720c1136egm
a93a1f58a8763fa69172980b98e3d24720c1136egm
a93a1f58a8763fa69172980b98e3d24720c1136egm root.destroy();
a93a1f58a8763fa69172980b98e3d24720c1136egm
a93a1f58a8763fa69172980b98e3d24720c1136egm },
a93a1f58a8763fa69172980b98e3d24720c1136egm
a93a1f58a8763fa69172980b98e3d24720c1136egm testAncestorNavigation: function () {
a93a1f58a8763fa69172980b98e3d24720c1136egm
a93a1f58a8763fa69172980b98e3d24720c1136egm var widget = new Y.ParentWidget({
a93a1f58a8763fa69172980b98e3d24720c1136egm
a93a1f58a8763fa69172980b98e3d24720c1136egm id: "widget-1",
a93a1f58a8763fa69172980b98e3d24720c1136egm label: "Parent",
a93a1f58a8763fa69172980b98e3d24720c1136egm children: [
a93a1f58a8763fa69172980b98e3d24720c1136egm { type: Y.ChildWidget, label: "Child One", id: "child-1" },
a93a1f58a8763fa69172980b98e3d24720c1136egm { type: Y.ChildWidget, label: "Child Two", id: "child-2" },
a93a1f58a8763fa69172980b98e3d24720c1136egm { type: Y.ChildWidget, label: "Child Three", id: "child-3" },
a93a1f58a8763fa69172980b98e3d24720c1136egm { type: Y.ChildWidget, label: "Child Four", id: "child-4" }
a93a1f58a8763fa69172980b98e3d24720c1136egm ]
a93a1f58a8763fa69172980b98e3d24720c1136egm
a93a1f58a8763fa69172980b98e3d24720c1136egm });
a93a1f58a8763fa69172980b98e3d24720c1136egm
a93a1f58a8763fa69172980b98e3d24720c1136egm var root = new Y.RootWidget({ id: "rootwidget-1" });
a93a1f58a8763fa69172980b98e3d24720c1136egm
a93a1f58a8763fa69172980b98e3d24720c1136egm root.add(widget);
a93a1f58a8763fa69172980b98e3d24720c1136egm root.render();
a93a1f58a8763fa69172980b98e3d24720c1136egm
a93a1f58a8763fa69172980b98e3d24720c1136egm
a93a1f58a8763fa69172980b98e3d24720c1136egm // Confirm that the "root" attribute is
a93a1f58a8763fa69172980b98e3d24720c1136egm // is not presently constrained by type since the ROOT_TYPE
a93a1f58a8763fa69172980b98e3d24720c1136egm // property is not yet set.
a93a1f58a8763fa69172980b98e3d24720c1136egm
a93a1f58a8763fa69172980b98e3d24720c1136egm Y.Assert.areEqual(widget.item(0).get("root").get("id"), "rootwidget-1", "The \"root\" attribute of \"child-1\" should return a reference to rootwidget-1");
a93a1f58a8763fa69172980b98e3d24720c1136egm Y.Assert.areEqual(widget.get("root").get("id"), "rootwidget-1", "The \"root\" attribute of \"widget-1\" should return a reference to rootwidget-1");
a93a1f58a8763fa69172980b98e3d24720c1136egm Y.Assert.isFalse(widget.isRoot(), "\"widget-1\" should not be considered root.");
a93a1f58a8763fa69172980b98e3d24720c1136egm Y.Assert.areEqual(widget.item(0).get("depth"), 1, "The \"depth\" attribute of \"child-1\" should return 1.");
a93a1f58a8763fa69172980b98e3d24720c1136egm
a93a1f58a8763fa69172980b98e3d24720c1136egm Y.Assert.areEqual(widget.item(0).ancestor(0).get("id"), "widget-1", "The ancestor of \"child-1\" at depth 0 should be \"widget-1\"");
a93a1f58a8763fa69172980b98e3d24720c1136egm Y.Assert.areEqual(widget.item(0).ancestor(-1).get("id"), "rootwidget-1", "The ancestor of \"child-1\" at depth -1 should be \"rootwidget-1\"");
a93a1f58a8763fa69172980b98e3d24720c1136egm
a93a1f58a8763fa69172980b98e3d24720c1136egm
a93a1f58a8763fa69172980b98e3d24720c1136egm // Confirm that the root attribute will be constrained to
a93a1f58a8763fa69172980b98e3d24720c1136egm // a particular type when the ROOT_TYPE is defined.
a93a1f58a8763fa69172980b98e3d24720c1136egm
a93a1f58a8763fa69172980b98e3d24720c1136egm Y.ParentWidget.prototype.ROOT_TYPE = Y.ParentWidget;
a93a1f58a8763fa69172980b98e3d24720c1136egm Y.ChildWidget.prototype.ROOT_TYPE = Y.ParentWidget;
a93a1f58a8763fa69172980b98e3d24720c1136egm
a93a1f58a8763fa69172980b98e3d24720c1136egm Y.Assert.areEqual(widget.item(0).get("root").get("id"), "widget-1", "The \"root\" attribute of \"child-1\" should return a reference to widget-1");
a93a1f58a8763fa69172980b98e3d24720c1136egm Y.Assert.areEqual(widget.get("root").get("id"), "widget-1", "The \"root\" attribute of \"widget-1\" should return a reference to widget-1");
a93a1f58a8763fa69172980b98e3d24720c1136egm Y.Assert.isTrue(widget.isRoot(), "Calling the \"isRoot\" method on \"widget-1\" should return \"widget-1\"");
a93a1f58a8763fa69172980b98e3d24720c1136egm Y.Assert.areEqual(widget.item(0).get("depth"), 0, "The \"depth\" attribute of \"child-1\" should return 0");
a93a1f58a8763fa69172980b98e3d24720c1136egm Y.Assert.areEqual(widget.item(0).ancestor(-1).get("id"), "widget-1", "The ancestor of \"child-1\" at depth -1 should be \"widget-1\""); // parent depth
a93a1f58a8763fa69172980b98e3d24720c1136egm
a93a1f58a8763fa69172980b98e3d24720c1136egm root.destroy();
a93a1f58a8763fa69172980b98e3d24720c1136egm
a93a1f58a8763fa69172980b98e3d24720c1136egm },
a93a1f58a8763fa69172980b98e3d24720c1136egm
a93a1f58a8763fa69172980b98e3d24720c1136egm testSiblingNavigation: function () {
a93a1f58a8763fa69172980b98e3d24720c1136egm
a93a1f58a8763fa69172980b98e3d24720c1136egm var widget = new Y.ParentWidget({
a93a1f58a8763fa69172980b98e3d24720c1136egm
a93a1f58a8763fa69172980b98e3d24720c1136egm id: "widget-1",
a93a1f58a8763fa69172980b98e3d24720c1136egm children: [
a93a1f58a8763fa69172980b98e3d24720c1136egm { type: Y.ChildWidget, label: "Child One", id: "child-1" },
a93a1f58a8763fa69172980b98e3d24720c1136egm { type: Y.ChildWidget, label: "Child Two", id: "child-2" },
a93a1f58a8763fa69172980b98e3d24720c1136egm { type: Y.ChildWidget, label: "Child Three", id: "child-3" },
a93a1f58a8763fa69172980b98e3d24720c1136egm { type: Y.ChildWidget, label: "Child Four", id: "child-4" }
a93a1f58a8763fa69172980b98e3d24720c1136egm ]
a93a1f58a8763fa69172980b98e3d24720c1136egm
a93a1f58a8763fa69172980b98e3d24720c1136egm });
a93a1f58a8763fa69172980b98e3d24720c1136egm
a93a1f58a8763fa69172980b98e3d24720c1136egm widget.render();
a93a1f58a8763fa69172980b98e3d24720c1136egm
a93a1f58a8763fa69172980b98e3d24720c1136egm Y.Assert.areEqual(widget.item(3).get("index"), 3, "The \"index\" attribute of \"child-4\" should return 3.");
a93a1f58a8763fa69172980b98e3d24720c1136egm Y.Assert.isUndefined(widget.item(3).next(), "\"child-4\" should have no next sibling");
a93a1f58a8763fa69172980b98e3d24720c1136egm Y.Assert.areEqual(widget.item(3).next(true).get("id"), "child-1", "Calling the \"next\" method with the circular flag should return a reference to \"child-1\"");
a93a1f58a8763fa69172980b98e3d24720c1136egm
a93a1f58a8763fa69172980b98e3d24720c1136egm Y.Assert.isUndefined(widget.item(0).previous(), "\"child-1\" should have no previous sibling");
a93a1f58a8763fa69172980b98e3d24720c1136egm Y.Assert.areEqual(widget.item(0).previous(true).get("id"), "child-4", "Calling the \"previous\" method with the circular flag should return a reference to \"child-4\"");
a93a1f58a8763fa69172980b98e3d24720c1136egm
a93a1f58a8763fa69172980b98e3d24720c1136egm widget.destroy();
a93a1f58a8763fa69172980b98e3d24720c1136egm
a93a1f58a8763fa69172980b98e3d24720c1136egm },
a93a1f58a8763fa69172980b98e3d24720c1136egm
a93a1f58a8763fa69172980b98e3d24720c1136egm testActiveDescendant: function () {
a93a1f58a8763fa69172980b98e3d24720c1136egm
a93a1f58a8763fa69172980b98e3d24720c1136egm var tree = new Y.ParentWidget({
a93a1f58a8763fa69172980b98e3d24720c1136egm
a93a1f58a8763fa69172980b98e3d24720c1136egm id: "tree",
a93a1f58a8763fa69172980b98e3d24720c1136egm children: [
a93a1f58a8763fa69172980b98e3d24720c1136egm
a93a1f58a8763fa69172980b98e3d24720c1136egm { type: Y.ChildWidget, id: "leaf-1", label: "Leaf One" },
a93a1f58a8763fa69172980b98e3d24720c1136egm { type: Y.ChildWidget, id: "leaf-2", label: "Leaf Two" },
a93a1f58a8763fa69172980b98e3d24720c1136egm { type: Y.ParentWidget, id: "subtree", label: "Subtree", children: [
a93a1f58a8763fa69172980b98e3d24720c1136egm
a93a1f58a8763fa69172980b98e3d24720c1136egm { type: Y.ChildWidget, id: "subtree-leaf-1", label: "Subtree - Leaf One" },
a93a1f58a8763fa69172980b98e3d24720c1136egm { type: Y.ChildWidget, id: "subtree-leaf-2", label: "Subtree - Leaf Two" },
a93a1f58a8763fa69172980b98e3d24720c1136egm { type: Y.ChildWidget, id: "subtree-leaf-3", label: "Subtree - Leaf Three" },
a93a1f58a8763fa69172980b98e3d24720c1136egm { type: Y.ChildWidget, id: "subtree-leaf-4", label: "Subtree - Leaf Four" }
a93a1f58a8763fa69172980b98e3d24720c1136egm
a93a1f58a8763fa69172980b98e3d24720c1136egm ]}
a93a1f58a8763fa69172980b98e3d24720c1136egm ]
a93a1f58a8763fa69172980b98e3d24720c1136egm
a93a1f58a8763fa69172980b98e3d24720c1136egm });
a93a1f58a8763fa69172980b98e3d24720c1136egm
a93a1f58a8763fa69172980b98e3d24720c1136egm tree.render();
a93a1f58a8763fa69172980b98e3d24720c1136egm
a93a1f58a8763fa69172980b98e3d24720c1136egm tree.item(2).item(0).focus();
a93a1f58a8763fa69172980b98e3d24720c1136egm
a93a1f58a8763fa69172980b98e3d24720c1136egm Y.Assert.areEqual(tree.item(2).get("activeDescendant"), tree.item(2).item(0), "The \"activeDescendant\" attribute of \"subtree\" should return a reference to \"subtree-leaf-1\"");
a93a1f58a8763fa69172980b98e3d24720c1136egm Y.Assert.areEqual(tree.get("activeDescendant"), tree.item(2).item(0), "The \"activeDescendant\" attribute of the root widget should return a reference to the \"subtree\"");
a93a1f58a8763fa69172980b98e3d24720c1136egm
a93a1f58a8763fa69172980b98e3d24720c1136egm tree.destroy();
a93a1f58a8763fa69172980b98e3d24720c1136egm }
a93a1f58a8763fa69172980b98e3d24720c1136egm
a93a1f58a8763fa69172980b98e3d24720c1136egm }));
a93a1f58a8763fa69172980b98e3d24720c1136egm
a93a1f58a8763fa69172980b98e3d24720c1136egm Y.Test.Runner.run();
a93a1f58a8763fa69172980b98e3d24720c1136egm
a93a1f58a8763fa69172980b98e3d24720c1136egm });
a93a1f58a8763fa69172980b98e3d24720c1136egm
a93a1f58a8763fa69172980b98e3d24720c1136egm </script>
a93a1f58a8763fa69172980b98e3d24720c1136egm
a93a1f58a8763fa69172980b98e3d24720c1136egm</body>
a93a1f58a8763fa69172980b98e3d24720c1136egm</html>
a93a1f58a8763fa69172980b98e3d24720c1136egm