parent-child.html revision d0a16c48f3477794c63f4ff3242dc20db6a49295
f86f2dc613a22ee06add9b878197922466df641bvboxsync <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
f86f2dc613a22ee06add9b878197922466df641bvboxsync <link rel="stylesheet" type="text/css" href="/build/cssreset/reset-min.css">
f86f2dc613a22ee06add9b878197922466df641bvboxsync <link rel="stylesheet" type="text/css" href="/build/cssfonts/fonts-min.css">
f86f2dc613a22ee06add9b878197922466df641bvboxsync <link rel="stylesheet" type="text/css" href="/build_files/tablist.css">
f86f2dc613a22ee06add9b878197922466df641bvboxsync <script src="/build/yui/yui-min.js" type="text/javascript"></script>
2a047f0d7ee5964456dbc4dec9925031482588abvboxsync timeout: 10000,
2a047f0d7ee5964456dbc4dec9925031482588abvboxsync filter: "raw"
2a047f0d7ee5964456dbc4dec9925031482588abvboxsync }).use("widget", "widget-parent", "widget-child", "test", "console", function (Y) {
40c9dcdf4b9d1c60dc67fa671b7a689b3c0f84d4vboxsync var RootWidget = function () {
40c9dcdf4b9d1c60dc67fa671b7a689b3c0f84d4vboxsync RootWidget.superclass.constructor.apply(this, arguments);
f86f2dc613a22ee06add9b878197922466df641bvboxsync RootWidget.NAME = "rootwidget";
6a008ce8150c1391d9e0dda0cdf9485b3c806034vboxsync Y.RootWidget = Y.Base.build("rootwidget", RootWidget, [Y.WidgetParent], { dynamic: false });
6a008ce8150c1391d9e0dda0cdf9485b3c806034vboxsync var ParentWidget = function () {
6a008ce8150c1391d9e0dda0cdf9485b3c806034vboxsync ParentWidget.superclass.constructor.apply(this, arguments);
ccc948c886b751603889a67909fbd4a5fcaeac85vboxsync Y.mix(ParentWidget, {
2a047f0d7ee5964456dbc4dec9925031482588abvboxsync NAME: "parentwidget",
f86f2dc613a22ee06add9b878197922466df641bvboxsync renderUI: function () {
f86f2dc613a22ee06add9b878197922466df641bvboxsync ParentWidget.superclass.renderUI.apply(this, arguments);
f86f2dc613a22ee06add9b878197922466df641bvboxsync if (this.get("depth") > -1) {
2a047f0d7ee5964456dbc4dec9925031482588abvboxsync var label = Y.Node.create("<em>" + this.get("label") + "</em>"),
8300beb17e7c288655895d07bfdc58a01f618218vboxsync parent = this.get("boundingBox").get("parentNode");
8300beb17e7c288655895d07bfdc58a01f618218vboxsync Y.ParentWidget = Y.Base.build("parentwidget", ParentWidget, [Y.WidgetParent, Y.WidgetChild], { dynamic: false });
8300beb17e7c288655895d07bfdc58a01f618218vboxsync var ChildWidget = function () {
8300beb17e7c288655895d07bfdc58a01f618218vboxsync ChildWidget.superclass.constructor.apply(this, arguments);
f86f2dc613a22ee06add9b878197922466df641bvboxsync Y.mix(ChildWidget, {
f86f2dc613a22ee06add9b878197922466df641bvboxsync NAME: "childwidget",
8300beb17e7c288655895d07bfdc58a01f618218vboxsync renderUI: function () {
f86f2dc613a22ee06add9b878197922466df641bvboxsync this.get("contentBox").setContent(this.get("label"));
8300beb17e7c288655895d07bfdc58a01f618218vboxsync Y.ChildWidget = Y.Base.build("childwidget", ChildWidget, [Y.WidgetChild], { dynamic: false });
8300beb17e7c288655895d07bfdc58a01f618218vboxsync var debugConsole = new Y.Console().render();
8300beb17e7c288655895d07bfdc58a01f618218vboxsync name: "Widget Parent API, Widget Child API Tests",
8300beb17e7c288655895d07bfdc58a01f618218vboxsync testAdd: function() {
8300beb17e7c288655895d07bfdc58a01f618218vboxsync var root = new Y.ParentWidget(),
8300beb17e7c288655895d07bfdc58a01f618218vboxsync child = root.add({ type: "ChildWidget", label: "Child One" });
8300beb17e7c288655895d07bfdc58a01f618218vboxsync Y.Assert.isNotUndefined(child, "Add should return a reference to the child that was created and added.");
8300beb17e7c288655895d07bfdc58a01f618218vboxsync Y.assert((root.size() == 1), "The root Widget should have one child");
f86f2dc613a22ee06add9b878197922466df641bvboxsync child = root.add({ type: ChildWidget, label: "Child Two" });
2a047f0d7ee5964456dbc4dec9925031482588abvboxsync Y.Assert.isNotUndefined(child, "Add should return a reference to the child that was created and added.");
8300beb17e7c288655895d07bfdc58a01f618218vboxsync Y.assert((root.size() == 2), "The root Widget should have two children");
8300beb17e7c288655895d07bfdc58a01f618218vboxsync child = root.add({ label: "Invalid Child" });
8300beb17e7c288655895d07bfdc58a01f618218vboxsync Y.Assert.isUndefined(child, "Add should return undefined since the type of the child is undefined.");
8300beb17e7c288655895d07bfdc58a01f618218vboxsync Y.assert((root.size() == 2), "The root Widget should have two children");
8300beb17e7c288655895d07bfdc58a01f618218vboxsync catch (e) {
8300beb17e7c288655895d07bfdc58a01f618218vboxsync 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.");
8300beb17e7c288655895d07bfdc58a01f618218vboxsync child = root.add({ type: "MyChild", label: "Invalid Child" });
8300beb17e7c288655895d07bfdc58a01f618218vboxsync Y.Assert.isUndefined(child, "The \"add\" method should return undefined since the type of the child is invalid.");
8300beb17e7c288655895d07bfdc58a01f618218vboxsync Y.assert((root.size() == 2), "The root Widget should have two children");
8300beb17e7c288655895d07bfdc58a01f618218vboxsync catch (e) {
8300beb17e7c288655895d07bfdc58a01f618218vboxsync Y.Assert.isNotUndefined(e, "The \"add\" method should throw an error since the type of the child is invalid.");
2a047f0d7ee5964456dbc4dec9925031482588abvboxsync child = root.add({ type: MyChild, label: "Invalid Child" });
2a047f0d7ee5964456dbc4dec9925031482588abvboxsync Y.Assert.isUndefined(child, "Add should return undefined since the type of the child is invalid.");
2a047f0d7ee5964456dbc4dec9925031482588abvboxsync Y.assert((root.size() == 2), "The root Widget should have two children");
2a047f0d7ee5964456dbc4dec9925031482588abvboxsync catch (e) {
f86f2dc613a22ee06add9b878197922466df641bvboxsync Y.Assert.isNotUndefined(e, "The \"add\" method should throw an error since the type of the child is invalid.");
f86f2dc613a22ee06add9b878197922466df641bvboxsync root.set("defaultChildType", "ChildWidget");
f86f2dc613a22ee06add9b878197922466df641bvboxsync child = root.add({ label: "Child Three" });
f86f2dc613a22ee06add9b878197922466df641bvboxsync Y.Assert.isNotUndefined(child, "Add should return a reference to the child that was created and added.");
2a047f0d7ee5964456dbc4dec9925031482588abvboxsync Y.assert((root.size() == 3), "The root Widget should have three children");
f86f2dc613a22ee06add9b878197922466df641bvboxsync root.set("defaultChildType", ChildWidget);
f86f2dc613a22ee06add9b878197922466df641bvboxsync child = root.add({ label: "Child Four" });
f86f2dc613a22ee06add9b878197922466df641bvboxsync Y.Assert.isNotUndefined(child, "Add should return a reference to the child that was created and added.");
f86f2dc613a22ee06add9b878197922466df641bvboxsync Y.assert((root.size() == 4), "The root Widget should have four children");
2a047f0d7ee5964456dbc4dec9925031482588abvboxsync root.set("defaultChildType", "MyChild");
f86f2dc613a22ee06add9b878197922466df641bvboxsync Y.Assert.areEqual(root.get("defaultChildType"), Y.ChildWidget, "Setter for \"defaultChildType\" should disallow setting the attribute to an invalid value.");
f86f2dc613a22ee06add9b878197922466df641bvboxsync root.set("defaultChildType", MyChild);
f86f2dc613a22ee06add9b878197922466df641bvboxsync Y.Assert.areEqual(root.get("defaultChildType"), Y.ChildWidget, "Setter for \"defaultChildType\" should disallow setting the attribute to an invalid value.");
f86f2dc613a22ee06add9b878197922466df641bvboxsync testInsert: function () {
f86f2dc613a22ee06add9b878197922466df641bvboxsync var widget = new Y.ParentWidget({
f86f2dc613a22ee06add9b878197922466df641bvboxsync id: "widget-1",
f86f2dc613a22ee06add9b878197922466df641bvboxsync children: [
f86f2dc613a22ee06add9b878197922466df641bvboxsync { type: Y.ChildWidget, label: "Child One", id: "child-1" },
f86f2dc613a22ee06add9b878197922466df641bvboxsync { type: Y.ChildWidget, label: "Child Two", id: "child-2" },
f86f2dc613a22ee06add9b878197922466df641bvboxsync { type: Y.ChildWidget, label: "Child Three", id: "child-3" },
f86f2dc613a22ee06add9b878197922466df641bvboxsync { type: Y.ChildWidget, label: "Child Four", id: "child-4" }
f86f2dc613a22ee06add9b878197922466df641bvboxsync widget.add({ type: Y.ChildWidget, label: "Child One", id: "inserted-child-1" }, 0);
f86f2dc613a22ee06add9b878197922466df641bvboxsync Y.Assert.areEqual(widget.item(0).get("id"), "inserted-child-1", "The newly inserted child should be the parent's first child.");
f86f2dc613a22ee06add9b878197922466df641bvboxsync Y.Assert.areEqual(widget.size(), 5, "The widget should have five children.");
f86f2dc613a22ee06add9b878197922466df641bvboxsync { type: Y.ChildWidget, label: "Child One", id: "inserted-child-2" },
f86f2dc613a22ee06add9b878197922466df641bvboxsync { type: Y.ChildWidget, label: "Child One", id: "inserted-child-3" }
f86f2dc613a22ee06add9b878197922466df641bvboxsync 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.");
f86f2dc613a22ee06add9b878197922466df641bvboxsync 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.");
f86f2dc613a22ee06add9b878197922466df641bvboxsync 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.");
f86f2dc613a22ee06add9b878197922466df641bvboxsync Y.Assert.areEqual(widget.size(), 7, "The widget should have seven children.");
f86f2dc613a22ee06add9b878197922466df641bvboxsync testRemove: function () {
f86f2dc613a22ee06add9b878197922466df641bvboxsync var widget = new Y.ParentWidget({
f86f2dc613a22ee06add9b878197922466df641bvboxsync id: "widget-1",
f86f2dc613a22ee06add9b878197922466df641bvboxsync children: [
f86f2dc613a22ee06add9b878197922466df641bvboxsync { type: Y.ChildWidget, label: "Child One", id: "child-1" },
f86f2dc613a22ee06add9b878197922466df641bvboxsync { type: Y.ChildWidget, label: "Child Two", id: "child-2" },
f86f2dc613a22ee06add9b878197922466df641bvboxsync { type: Y.ChildWidget, label: "Child Three", id: "child-3" },
2a047f0d7ee5964456dbc4dec9925031482588abvboxsync { type: Y.ChildWidget, label: "Child Four", id: "child-4" }
f86f2dc613a22ee06add9b878197922466df641bvboxsync Y.Assert.areEqual(widget.remove(1).get("id"), "child-2", "The parent's \"remove\" method should return a reference to the child removed.");
f86f2dc613a22ee06add9b878197922466df641bvboxsync Y.Assert.areEqual(widget.size(), 3, "The widget should now have three children.");
f86f2dc613a22ee06add9b878197922466df641bvboxsync 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.");
f86f2dc613a22ee06add9b878197922466df641bvboxsync Y.Assert.areEqual(widget.size(), 2, "The widget should now have two children.");
f86f2dc613a22ee06add9b878197922466df641bvboxsync var removed = widget.removeAll();
f86f2dc613a22ee06add9b878197922466df641bvboxsync Y.Assert.areEqual(removed.size(), 2, "The \"removeAll\" method should return a Y.ArrayList instance with a size of 2.");
f86f2dc613a22ee06add9b878197922466df641bvboxsync Y.Assert.areEqual(widget.size(), 0, "The widget should now have no children.");
f86f2dc613a22ee06add9b878197922466df641bvboxsync testSingleSelection: function () {
f86f2dc613a22ee06add9b878197922466df641bvboxsync var root = new Y.ParentWidget({
f86f2dc613a22ee06add9b878197922466df641bvboxsync id: "new-widget",
f86f2dc613a22ee06add9b878197922466df641bvboxsync children: [
2a047f0d7ee5964456dbc4dec9925031482588abvboxsync { type: Y.ChildWidget, label: "Child One" },
f86f2dc613a22ee06add9b878197922466df641bvboxsync { type: Y.ChildWidget, label: "Child Two" },
f86f2dc613a22ee06add9b878197922466df641bvboxsync { type: Y.ChildWidget, label: "Child Three" },
f86f2dc613a22ee06add9b878197922466df641bvboxsync { type: Y.ChildWidget, label: "Child Four" }
f86f2dc613a22ee06add9b878197922466df641bvboxsync root.item(0).set("selected", 1);
f86f2dc613a22ee06add9b878197922466df641bvboxsync root.item(1).set("selected", 1);
f86f2dc613a22ee06add9b878197922466df641bvboxsync // Confirm the selection
f86f2dc613a22ee06add9b878197922466df641bvboxsync Y.Assert.areEqual(root.item(1).get("selected"), 1, "The second child of the parent widget should be selected");
8300beb17e7c288655895d07bfdc58a01f618218vboxsync Y.Assert.areEqual(root.get("selected"), 2, "The root's \"selected\" attribute should return 2");
f86f2dc613a22ee06add9b878197922466df641bvboxsync Y.Assert.areEqual(root.get("selection"), root.item(1), "The parent's \"selection\" attribute should return a reference to its second child.");
f86f2dc613a22ee06add9b878197922466df641bvboxsync // Select another child and confirm the previously selected
f86f2dc613a22ee06add9b878197922466df641bvboxsync // child is deselected and and the parent's selection is
f86f2dc613a22ee06add9b878197922466df641bvboxsync // correctly updated.
f86f2dc613a22ee06add9b878197922466df641bvboxsync root.item(2).set("selected", 1);
ccc948c886b751603889a67909fbd4a5fcaeac85vboxsync Y.Assert.areEqual(root.item(1).get("selected"), 0, "The parent's second child should not be selected");
ccc948c886b751603889a67909fbd4a5fcaeac85vboxsync Y.Assert.areEqual(root.item(2).get("selected"), 1, "The parent's third child should be selected");
ccc948c886b751603889a67909fbd4a5fcaeac85vboxsync Y.Assert.areEqual(root.get("selection"), root.item(2), "The parent's \"selection\" attribute should return a reference to its third child.");
ccc948c886b751603889a67909fbd4a5fcaeac85vboxsync // Confirm deselection
ccc948c886b751603889a67909fbd4a5fcaeac85vboxsync root.item(2).set("selected", 0);
ccc948c886b751603889a67909fbd4a5fcaeac85vboxsync Y.Assert.areEqual(root.item(2).get("selected"), 0, "The parent's third child should not be selected");
ccc948c886b751603889a67909fbd4a5fcaeac85vboxsync Y.Assert.areEqual(root.get("selected"), 0, "The parent's \"selected\" attribute should return 0");
ccc948c886b751603889a67909fbd4a5fcaeac85vboxsync Y.Assert.isNull(root.get("selection"), "The parent's \"selection\" attribute should return null.");
ccc948c886b751603889a67909fbd4a5fcaeac85vboxsync var tree = new Y.ParentWidget({
ccc948c886b751603889a67909fbd4a5fcaeac85vboxsync id: "tree",
ccc948c886b751603889a67909fbd4a5fcaeac85vboxsync children: [
ccc948c886b751603889a67909fbd4a5fcaeac85vboxsync { type: Y.ChildWidget, id: "leaf-1", label: "Leaf One" },
ccc948c886b751603889a67909fbd4a5fcaeac85vboxsync { type: Y.ChildWidget, id: "leaf-2", label: "Leaf Two" },
f86f2dc613a22ee06add9b878197922466df641bvboxsync { type: Y.ParentWidget, id: "subtree", label: "Subtree", children: [
f86f2dc613a22ee06add9b878197922466df641bvboxsync { type: Y.ChildWidget, id: "subtree-leaf-1", label: "Subtree - Leaf One" },
f86f2dc613a22ee06add9b878197922466df641bvboxsync { type: Y.ChildWidget, id: "subtree-leaf-2", label: "Subtree - Leaf Two" },
f86f2dc613a22ee06add9b878197922466df641bvboxsync { type: Y.ChildWidget, id: "subtree-leaf-3", label: "Subtree - Leaf Three" },
f86f2dc613a22ee06add9b878197922466df641bvboxsync { type: Y.ChildWidget, id: "subtree-leaf-4", label: "Subtree - Leaf Four" }
8300beb17e7c288655895d07bfdc58a01f618218vboxsync // Select a child in the subtree to test if the selection is represented at the root level
f86f2dc613a22ee06add9b878197922466df641bvboxsync tree.item(2).item(0).set("selected", 1);
f86f2dc613a22ee06add9b878197922466df641bvboxsync Y.Assert.areEqual(tree.get("selected"), 2, "The root's \"selected\" attribute should be 2 (indicating partially selected).");
f86f2dc613a22ee06add9b878197922466df641bvboxsync Y.Assert.areEqual(tree.item(2).get("selected"), 2, "The subtree's \"selected\" attribute should be 2 (indicating partially selected).");
f86f2dc613a22ee06add9b878197922466df641bvboxsync Y.Assert.areEqual(tree.get("selection").get("id"), "subtree", "The root's \"selection\" attribute should return the subtree.");
6af5a377dcdc4437fa51e183a5a8dad78abf2ec0vboxsync Y.Assert.areEqual(tree.item(2).get("selection").get("id"), "subtree-leaf-1", "The subtree's \"selection\" attribute should return the first child.");
f86f2dc613a22ee06add9b878197922466df641bvboxsync // Select a child in the root to confirm that the subtree's selection is cleared
2a047f0d7ee5964456dbc4dec9925031482588abvboxsync tree.item(0).set("selected", 1);
f86f2dc613a22ee06add9b878197922466df641bvboxsync Y.Assert.areEqual(tree.get("selected"), 2, "The root's \"selected\" attribute should be 2 (indicating partially selected).");
f86f2dc613a22ee06add9b878197922466df641bvboxsync Y.Assert.areEqual(tree.get("selection").get("id"), "leaf-1", "The root's \"selection\" attribute should return a reference to its first child.");
f86f2dc613a22ee06add9b878197922466df641bvboxsync Y.Assert.areEqual(tree.item(2).get("selected"), 0, "The subtree should no longer be selected.");
f86f2dc613a22ee06add9b878197922466df641bvboxsync Y.Assert.areEqual(tree.item(2).get("selection"), null, "The subtree's \"selection\" attribute should return null.");
f86f2dc613a22ee06add9b878197922466df641bvboxsync // Select a new child in the subtree to test if the selection is represented at the root level
f86f2dc613a22ee06add9b878197922466df641bvboxsync tree.item(2).item(2).set("selected", 1);
f86f2dc613a22ee06add9b878197922466df641bvboxsync Y.Assert.areEqual(tree.get("selected"), 2, "The root's \"selected\" attribute should be 2 (indicating partially selected).");
f86f2dc613a22ee06add9b878197922466df641bvboxsync Y.Assert.areEqual(tree.item(2).get("selected"), 2, "The subtree's \"selected\" attribute should be 2 (indicating partially selected).");
8300beb17e7c288655895d07bfdc58a01f618218vboxsync Y.Assert.areEqual(tree.get("selection").get("id"), "subtree", "The root's \"selection\" attribute should return the subtree.");
f86f2dc613a22ee06add9b878197922466df641bvboxsync Y.Assert.areEqual(tree.item(2).get("selection").get("id"), "subtree-leaf-3", "The subtree's \"selection\" attribute should return its third child.");
2a047f0d7ee5964456dbc4dec9925031482588abvboxsync testMultipleSelection: function () {
f86f2dc613a22ee06add9b878197922466df641bvboxsync var root = new Y.ParentWidget({
f86f2dc613a22ee06add9b878197922466df641bvboxsync id: "m-s-widget",
f86f2dc613a22ee06add9b878197922466df641bvboxsync multiple: true,
f86f2dc613a22ee06add9b878197922466df641bvboxsync children: [
f86f2dc613a22ee06add9b878197922466df641bvboxsync { type: Y.ChildWidget, label: "Child One" },
6af5a377dcdc4437fa51e183a5a8dad78abf2ec0vboxsync { type: Y.ChildWidget, label: "Child Two" },
f86f2dc613a22ee06add9b878197922466df641bvboxsync { type: Y.ChildWidget, label: "Child Three" },
f86f2dc613a22ee06add9b878197922466df641bvboxsync { type: Y.ChildWidget, label: "Child Four" }
f86f2dc613a22ee06add9b878197922466df641bvboxsync root.item(0).set("selected", 1);
f86f2dc613a22ee06add9b878197922466df641bvboxsync root.item(1).set("selected", 1);
f86f2dc613a22ee06add9b878197922466df641bvboxsync // Confirm that both children are selected and
f86f2dc613a22ee06add9b878197922466df641bvboxsync // represented in the parent's selection.
f86f2dc613a22ee06add9b878197922466df641bvboxsync Y.Assert.areEqual(root.item(0).get("selected"), 1, "The first child of the parent widget should be selected.");
f86f2dc613a22ee06add9b878197922466df641bvboxsync Y.Assert.areEqual(root.item(1).get("selected"), 1, "The second child of the parent widget should be selected.");
f86f2dc613a22ee06add9b878197922466df641bvboxsync Y.Assert.areEqual(root.get("selection").size(), 2, "The \"selection\" attribute should return an ArrayList with a size of 2.");
f86f2dc613a22ee06add9b878197922466df641bvboxsync Y.Assert.areEqual(root.get("selected"), 2, "The root's \"selection\" attribute should be 2 (indicating partially selected).");
6af5a377dcdc4437fa51e183a5a8dad78abf2ec0vboxsync // Select remaining children to confirm all children
6af5a377dcdc4437fa51e183a5a8dad78abf2ec0vboxsync // are represented in the parent's selection and that
f86f2dc613a22ee06add9b878197922466df641bvboxsync // the parent's "selected" attribute returns 1.
f86f2dc613a22ee06add9b878197922466df641bvboxsync root.item(2).set("selected", 1);
f86f2dc613a22ee06add9b878197922466df641bvboxsync root.item(3).set("selected", 1);
f86f2dc613a22ee06add9b878197922466df641bvboxsync Y.Assert.areEqual(root.get("selection").size(), 4, "The \"selection\" attribute should return an ArrayList with a size of 4.");
f86f2dc613a22ee06add9b878197922466df641bvboxsync Y.Assert.areEqual(root.get("selected"), 1, "The root's \"selected\" attribute should return 1 (indicating fully selected).");
f86f2dc613a22ee06add9b878197922466df641bvboxsync // Deselect all children and confirm the results
f86f2dc613a22ee06add9b878197922466df641bvboxsync root.get("selection").each(function (child) {
f86f2dc613a22ee06add9b878197922466df641bvboxsync child.set("selected", 0);
f86f2dc613a22ee06add9b878197922466df641bvboxsync Y.Assert.isNull(root.get("selection"), "The root's \"selection\" attribute should return null.");
f86f2dc613a22ee06add9b878197922466df641bvboxsync Y.Assert.areEqual(root.get("selected"), 0, "The root's \"selected\" attribute should return 0");
f86f2dc613a22ee06add9b878197922466df641bvboxsync // Select all children via selectAll() to confirm all
f86f2dc613a22ee06add9b878197922466df641bvboxsync // children are represented in the parent's selection and
f86f2dc613a22ee06add9b878197922466df641bvboxsync // that the parent's "selected" attribute returns 1.
f86f2dc613a22ee06add9b878197922466df641bvboxsync Y.Assert.areEqual(root.get("selected"), 1, "The root's \"selected\" attribute should return 1");
f86f2dc613a22ee06add9b878197922466df641bvboxsync Y.Assert.areEqual(root.get("selection").size(), 4, "The root's \"selection\" attribute should return an ArrayList with a size of 4.");
f86f2dc613a22ee06add9b878197922466df641bvboxsync // Deselect all children via deselectAll() to confirm all
f86f2dc613a22ee06add9b878197922466df641bvboxsync // children are no longer selected and that the parent's
f86f2dc613a22ee06add9b878197922466df641bvboxsync // selection is empty.
f86f2dc613a22ee06add9b878197922466df641bvboxsync Y.Assert.areEqual(root.get("selected"), 0, "The root's \"selected\" attribute should return 0");
6af5a377dcdc4437fa51e183a5a8dad78abf2ec0vboxsync Y.Assert.areEqual(root.get("selection"), null, "The root's \"selection\" attribute should return an ArrayList with a size of 4.");
f86f2dc613a22ee06add9b878197922466df641bvboxsync root.add({ type: Y.ParentWidget, id: "subtree", label: "Subtree", children: [
f86f2dc613a22ee06add9b878197922466df641bvboxsync { type: Y.ChildWidget, id: "subtree-leaf-1", label: "Subtree - Leaf One" },
f86f2dc613a22ee06add9b878197922466df641bvboxsync { type: Y.ChildWidget, id: "subtree-leaf-2", label: "Subtree - Leaf Two" },
f86f2dc613a22ee06add9b878197922466df641bvboxsync { type: Y.ChildWidget, id: "subtree-leaf-3", label: "Subtree - Leaf Three" },
f86f2dc613a22ee06add9b878197922466df641bvboxsync { type: Y.ChildWidget, id: "subtree-leaf-4", label: "Subtree - Leaf Four" }
f86f2dc613a22ee06add9b878197922466df641bvboxsync Y.Assert.isTrue(root.item(4).get("multiple"), "The \"multiple\" attribute of the nested parent widget should be true.");
f86f2dc613a22ee06add9b878197922466df641bvboxsync testAncestorNavigation: function () {
f86f2dc613a22ee06add9b878197922466df641bvboxsync var widget = new Y.ParentWidget({
f86f2dc613a22ee06add9b878197922466df641bvboxsync id: "widget-1",
f86f2dc613a22ee06add9b878197922466df641bvboxsync label: "Parent",
f86f2dc613a22ee06add9b878197922466df641bvboxsync children: [
f86f2dc613a22ee06add9b878197922466df641bvboxsync { type: Y.ChildWidget, label: "Child One", id: "child-1" },
f86f2dc613a22ee06add9b878197922466df641bvboxsync { type: Y.ChildWidget, label: "Child Two", id: "child-2" },
f86f2dc613a22ee06add9b878197922466df641bvboxsync { type: Y.ChildWidget, label: "Child Three", id: "child-3" },
f86f2dc613a22ee06add9b878197922466df641bvboxsync { type: Y.ChildWidget, label: "Child Four", id: "child-4" }
f86f2dc613a22ee06add9b878197922466df641bvboxsync var root = new Y.RootWidget({ id: "rootwidget-1" });
5a9f1d57ea268b1d88ff2492d9d59a696b1c693evboxsync // Confirm that the "root" attribute is
f86f2dc613a22ee06add9b878197922466df641bvboxsync // is not presently constrained by type since the ROOT_TYPE
f86f2dc613a22ee06add9b878197922466df641bvboxsync // property is not yet set.
f86f2dc613a22ee06add9b878197922466df641bvboxsync 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");
f86f2dc613a22ee06add9b878197922466df641bvboxsync Y.Assert.areEqual(widget.get("root").get("id"), "rootwidget-1", "The \"root\" attribute of \"widget-1\" should return a reference to rootwidget-1");
f86f2dc613a22ee06add9b878197922466df641bvboxsync Y.Assert.isFalse(widget.isRoot(), "\"widget-1\" should not be considered root.");
f86f2dc613a22ee06add9b878197922466df641bvboxsync Y.Assert.areEqual(widget.item(0).get("depth"), 1, "The \"depth\" attribute of \"child-1\" should return 1.");
f86f2dc613a22ee06add9b878197922466df641bvboxsync Y.Assert.areEqual(widget.item(0).ancestor(0).get("id"), "widget-1", "The ancestor of \"child-1\" at depth 0 should be \"widget-1\"");
f86f2dc613a22ee06add9b878197922466df641bvboxsync Y.Assert.areEqual(widget.item(0).ancestor(-1).get("id"), "rootwidget-1", "The ancestor of \"child-1\" at depth -1 should be \"rootwidget-1\"");
8300beb17e7c288655895d07bfdc58a01f618218vboxsync // Confirm that the root attribute will be constrained to
f86f2dc613a22ee06add9b878197922466df641bvboxsync // a particular type when the ROOT_TYPE is defined.
8300beb17e7c288655895d07bfdc58a01f618218vboxsync Y.ParentWidget.prototype.ROOT_TYPE = Y.ParentWidget;
8300beb17e7c288655895d07bfdc58a01f618218vboxsync Y.ChildWidget.prototype.ROOT_TYPE = Y.ParentWidget;
8300beb17e7c288655895d07bfdc58a01f618218vboxsync 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");
8300beb17e7c288655895d07bfdc58a01f618218vboxsync Y.Assert.areEqual(widget.get("root").get("id"), "widget-1", "The \"root\" attribute of \"widget-1\" should return a reference to widget-1");
8300beb17e7c288655895d07bfdc58a01f618218vboxsync Y.Assert.isTrue(widget.isRoot(), "Calling the \"isRoot\" method on \"widget-1\" should return \"widget-1\"");
8300beb17e7c288655895d07bfdc58a01f618218vboxsync Y.Assert.areEqual(widget.item(0).get("depth"), 0, "The \"depth\" attribute of \"child-1\" should return 0");
8300beb17e7c288655895d07bfdc58a01f618218vboxsync 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
8300beb17e7c288655895d07bfdc58a01f618218vboxsync testSiblingNavigation: function () {
2a047f0d7ee5964456dbc4dec9925031482588abvboxsync var widget = new Y.ParentWidget({
2a047f0d7ee5964456dbc4dec9925031482588abvboxsync id: "widget-1",
f86f2dc613a22ee06add9b878197922466df641bvboxsync children: [
f86f2dc613a22ee06add9b878197922466df641bvboxsync { type: Y.ChildWidget, label: "Child One", id: "child-1" },
f86f2dc613a22ee06add9b878197922466df641bvboxsync { type: Y.ChildWidget, label: "Child Two", id: "child-2" },
f86f2dc613a22ee06add9b878197922466df641bvboxsync { type: Y.ChildWidget, label: "Child Three", id: "child-3" },
f86f2dc613a22ee06add9b878197922466df641bvboxsync { type: Y.ChildWidget, label: "Child Four", id: "child-4" }
f86f2dc613a22ee06add9b878197922466df641bvboxsync Y.Assert.areEqual(widget.item(3).get("index"), 3, "The \"index\" attribute of \"child-4\" should return 3.");
f86f2dc613a22ee06add9b878197922466df641bvboxsync Y.Assert.isUndefined(widget.item(3).next(), "\"child-4\" should have no next sibling");
f86f2dc613a22ee06add9b878197922466df641bvboxsync 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\"");
f86f2dc613a22ee06add9b878197922466df641bvboxsync Y.Assert.isUndefined(widget.item(0).previous(), "\"child-1\" should have no previous sibling");
f86f2dc613a22ee06add9b878197922466df641bvboxsync 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\"");
f86f2dc613a22ee06add9b878197922466df641bvboxsync testActiveItem: function () {
f86f2dc613a22ee06add9b878197922466df641bvboxsync var tree = new Y.ParentWidget({
8300beb17e7c288655895d07bfdc58a01f618218vboxsync id: "tree",
8300beb17e7c288655895d07bfdc58a01f618218vboxsync children: [
f86f2dc613a22ee06add9b878197922466df641bvboxsync { type: Y.ChildWidget, id: "leaf-1", label: "Leaf One" },
f86f2dc613a22ee06add9b878197922466df641bvboxsync { type: Y.ChildWidget, id: "leaf-2", label: "Leaf Two" },
f86f2dc613a22ee06add9b878197922466df641bvboxsync { type: Y.ParentWidget, id: "subtree", label: "Subtree", children: [
f86f2dc613a22ee06add9b878197922466df641bvboxsync { type: Y.ChildWidget, id: "subtree-leaf-1", label: "Subtree - Leaf One" },
f86f2dc613a22ee06add9b878197922466df641bvboxsync { type: Y.ChildWidget, id: "subtree-leaf-2", label: "Subtree - Leaf Two" },
f86f2dc613a22ee06add9b878197922466df641bvboxsync { type: Y.ChildWidget, id: "subtree-leaf-3", label: "Subtree - Leaf Three" },
f86f2dc613a22ee06add9b878197922466df641bvboxsync { type: Y.ChildWidget, id: "subtree-leaf-4", label: "Subtree - Leaf Four" }
5a9f1d57ea268b1d88ff2492d9d59a696b1c693evboxsync tree.item(2).item(0).focus();
f86f2dc613a22ee06add9b878197922466df641bvboxsync Y.Assert.areEqual(tree.item(2).get("activeItem"), tree.item(2).item(0), "The \"activeItem\" attribute of \"subtree\" should return a reference to \"subtree-leaf-1\"");
f86f2dc613a22ee06add9b878197922466df641bvboxsync Y.Assert.areEqual(tree.get("activeItem"), tree.item(2), "The \"activeItem\" attribute of the root widget should return a reference to the \"subtree\"");