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