5d6602ccab9b5300134be9f9c206a815d1df3eccSatyen Desai<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
5d6602ccab9b5300134be9f9c206a815d1df3eccSatyen Desai #console .yui3-console-entry {
5d6602ccab9b5300134be9f9c206a815d1df3eccSatyen Desai padding:2px;
5d6602ccab9b5300134be9f9c206a815d1df3eccSatyen Desai min-height:0;
5d6602ccab9b5300134be9f9c206a815d1df3eccSatyen Desai #console .yui3-console-entry-fail .yui3-console-entry-cat {
5d6602ccab9b5300134be9f9c206a815d1df3eccSatyen Desai background-color:red;
5d6602ccab9b5300134be9f9c206a815d1df3eccSatyen Desai #console .yui3-console-entry-pass .yui3-console-entry-cat {
5d6602ccab9b5300134be9f9c206a815d1df3eccSatyen Desai background-color:green;
5d6602ccab9b5300134be9f9c206a815d1df3eccSatyen Desai #console .yui3-console-entry-perf .yui3-console-entry-cat {
5d6602ccab9b5300134be9f9c206a815d1df3eccSatyen Desai background-color:blue;
5d6602ccab9b5300134be9f9c206a815d1df3eccSatyen Desai position:static;
5d6602ccab9b5300134be9f9c206a815d1df3eccSatyen Desai html, body {
5d6602ccab9b5300134be9f9c206a815d1df3eccSatyen Desai height:100%;
1bb9ba7f0e700971d0c04fca23820699348cfd49Satyen Desai useBrowserConsole:false,
1bb9ba7f0e700971d0c04fca23820699348cfd49Satyen Desai filter: (window.location.search.match(/[?&]filter=([^&]+)/) || [])[1] || 'min'
df315088426ba61b1911bca0c888843588e552e9Satyen Desai }).use("node-event-simulate", "async-queue", "widget", "widget-parent", "widget-child", "test", "console", function (Y) {
df315088426ba61b1911bca0c888843588e552e9Satyen Desai var RootWidget = Y.RootWidget = Y.Base.create("rootwidget", Y.Widget, [Y.WidgetParent]);
df315088426ba61b1911bca0c888843588e552e9Satyen Desai var ParentWidget = Y.ParentWidget = Y.Base.create("parentwidget", Y.Widget, [Y.WidgetParent, Y.WidgetChild], {
cf8ec1f7a476d02f1a43bda999dc075e8546ee27Todd Kloots renderUI: function () {
cf8ec1f7a476d02f1a43bda999dc075e8546ee27Todd Kloots ParentWidget.superclass.renderUI.apply(this, arguments);
cf8ec1f7a476d02f1a43bda999dc075e8546ee27Todd Kloots if (this.get("depth") > -1) {
df315088426ba61b1911bca0c888843588e552e9Satyen Desai this.get("contentBox").insert("<em>" + this.get("label") + "</em>");
df315088426ba61b1911bca0c888843588e552e9Satyen Desai var ChildWidget = Y.ChildWidget = Y.Base.create("childwidget", Y.Widget, [Y.WidgetChild], {
cf8ec1f7a476d02f1a43bda999dc075e8546ee27Todd Kloots renderUI: function () {
cf8ec1f7a476d02f1a43bda999dc075e8546ee27Todd Kloots this.get("contentBox").setContent(this.get("label"));
5d6602ccab9b5300134be9f9c206a815d1df3eccSatyen Desai var suite = new Y.Test.Suite("Widget ParentChild Tests");
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");
df315088426ba61b1911bca0c888843588e552e9Satyen Desai } catch (e) {
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");
df315088426ba61b1911bca0c888843588e552e9Satyen Desai } catch (e) {
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");
df315088426ba61b1911bca0c888843588e552e9Satyen Desai } catch (e) {
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.");
5d6602ccab9b5300134be9f9c206a815d1df3eccSatyen Desai Y.Assert.areEqual(widget.item(4).get("id"), "child-2", "The child with the id of \"child-2\" should now be the parent's fith child.");
cf8ec1f7a476d02f1a43bda999dc075e8546ee27Todd Kloots Y.Assert.areEqual(widget.size(), 7, "The widget should have seven children.");
1df84ffb9aca4272e816ec9205c44b42161d9252Satyen Desai testPreRenderedChildWithEmptyParent : function() {
1df84ffb9aca4272e816ec9205c44b42161d9252Satyen Desai // Based on pull request from andreas-karlsson
1df84ffb9aca4272e816ec9205c44b42161d9252Satyen Desai // https://github.com/yui/yui3/pull/25#issuecomment-2103536
1df84ffb9aca4272e816ec9205c44b42161d9252Satyen Desai var widget = new Y.ParentWidget({
1df84ffb9aca4272e816ec9205c44b42161d9252Satyen Desai id:"widget-1"
1df84ffb9aca4272e816ec9205c44b42161d9252Satyen Desai var child = new Y.ChildWidget({
1df84ffb9aca4272e816ec9205c44b42161d9252Satyen Desai id:"child-1"
1df84ffb9aca4272e816ec9205c44b42161d9252Satyen Desai Y.Assert.areEqual(1, widget.size(1), "expected one child");
1df84ffb9aca4272e816ec9205c44b42161d9252Satyen Desai var renderedChildren = widget.get("contentBox").get("children");
1df84ffb9aca4272e816ec9205c44b42161d9252Satyen Desai Y.Assert.areEqual(1, renderedChildren.size(), "expected one child node");
df315088426ba61b1911bca0c888843588e552e9Satyen Desai testAddOutOfOrderPreRender : function() {
df315088426ba61b1911bca0c888843588e552e9Satyen Desai var widget = new Y.ParentWidget({
df315088426ba61b1911bca0c888843588e552e9Satyen Desai id:"widget-1"
df315088426ba61b1911bca0c888843588e552e9Satyen Desai widget.add({type: Y.ChildWidget, label: "Child Two", id: "child-2" }, 1);
df315088426ba61b1911bca0c888843588e552e9Satyen Desai widget.add({type: Y.ChildWidget, label: "Child One", id: "child-1" }, 0);
df315088426ba61b1911bca0c888843588e552e9Satyen Desai widget.add({type: Y.ChildWidget, label: "Child Three", id: "child-3" }, 2);
df315088426ba61b1911bca0c888843588e552e9Satyen Desai var children = widget.get("children");
df315088426ba61b1911bca0c888843588e552e9Satyen Desai Y.Assert.areEqual(widget.item(0).get("id"), "child-1", "child-1 is out of order");
df315088426ba61b1911bca0c888843588e552e9Satyen Desai Y.Assert.areEqual(widget.item(1).get("id"), "child-2", "child-2 is out of order");
df315088426ba61b1911bca0c888843588e552e9Satyen Desai Y.Assert.areEqual(widget.item(2).get("id"), "child-3", "child-3 is out of order");
df315088426ba61b1911bca0c888843588e552e9Satyen Desai var renderedChildren = widget.get("contentBox").get("children");
df315088426ba61b1911bca0c888843588e552e9Satyen Desai Y.Assert.areEqual(renderedChildren.item(0).get("id"), "child-1", "child-1 is out of order");
df315088426ba61b1911bca0c888843588e552e9Satyen Desai Y.Assert.areEqual(renderedChildren.item(1).get("id"), "child-2", "child-2 is out of order");
df315088426ba61b1911bca0c888843588e552e9Satyen Desai Y.Assert.areEqual(renderedChildren.item(2).get("id"), "child-3", "child-3 is out of order");
df315088426ba61b1911bca0c888843588e552e9Satyen Desai testAddOutOfOrderPostRender : function() {
df315088426ba61b1911bca0c888843588e552e9Satyen Desai var widget = new Y.ParentWidget({
df315088426ba61b1911bca0c888843588e552e9Satyen Desai id:"widget-1"
df315088426ba61b1911bca0c888843588e552e9Satyen Desai widget.add({type: Y.ChildWidget, label: "Child Two", id: "child-2" }, 1);
df315088426ba61b1911bca0c888843588e552e9Satyen Desai widget.add({type: Y.ChildWidget, label: "Child One", id: "child-1" }, 0);
df315088426ba61b1911bca0c888843588e552e9Satyen Desai widget.add({type: Y.ChildWidget, label: "Child Three", id: "child-3" }, 2);
df315088426ba61b1911bca0c888843588e552e9Satyen Desai Y.Assert.areEqual(widget.item(0).get("id"), "child-1", "child-1 is out of order");
df315088426ba61b1911bca0c888843588e552e9Satyen Desai Y.Assert.areEqual(widget.item(1).get("id"), "child-2", "child-2 is out of order");
df315088426ba61b1911bca0c888843588e552e9Satyen Desai Y.Assert.areEqual(widget.item(2).get("id"), "child-3", "child-3 is out of order");
df315088426ba61b1911bca0c888843588e552e9Satyen Desai var renderedChildren = widget.get("contentBox").get("children");
df315088426ba61b1911bca0c888843588e552e9Satyen Desai Y.Assert.areEqual(renderedChildren.item(0).get("id"), "child-1", "child-1 is out of order");
df315088426ba61b1911bca0c888843588e552e9Satyen Desai Y.Assert.areEqual(renderedChildren.item(1).get("id"), "child-2", "child-2 is out of order");
df315088426ba61b1911bca0c888843588e552e9Satyen Desai Y.Assert.areEqual(renderedChildren.item(2).get("id"), "child-3", "child-3 is out of order");
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.");
dffbe2d4e60ed4db1cecdea6cec2041eed9ff555Satyen Desai testRemoveSelectedChild : function() {
dffbe2d4e60ed4db1cecdea6cec2041eed9ff555Satyen Desai var widget = new Y.ParentWidget({
dffbe2d4e60ed4db1cecdea6cec2041eed9ff555Satyen Desai id: "widget-1",
dffbe2d4e60ed4db1cecdea6cec2041eed9ff555Satyen Desai { type: Y.ChildWidget, label: "Child One", id: "child-1" },
dffbe2d4e60ed4db1cecdea6cec2041eed9ff555Satyen Desai { type: Y.ChildWidget, label: "Child Two", id: "child-2" },
dffbe2d4e60ed4db1cecdea6cec2041eed9ff555Satyen Desai { type: Y.ChildWidget, label: "Child Three", id: "child-3" },
dffbe2d4e60ed4db1cecdea6cec2041eed9ff555Satyen Desai { type: Y.ChildWidget, label: "Child Four", id: "child-4" }
dffbe2d4e60ed4db1cecdea6cec2041eed9ff555Satyen Desai var childSelector = "." + widget.item(0).getClassName(),
dffbe2d4e60ed4db1cecdea6cec2041eed9ff555Satyen Desai parentBB = widget.get("boundingBox");
dffbe2d4e60ed4db1cecdea6cec2041eed9ff555Satyen Desai Y.Assert.areSame(widget.item(1), widget.get("selection"));
dffbe2d4e60ed4db1cecdea6cec2041eed9ff555Satyen Desai Y.Assert.areEqual(widget.remove(1).get("id"), "child-2", "The parent's \"remove\" method should return a reference to the child removed.");
dffbe2d4e60ed4db1cecdea6cec2041eed9ff555Satyen Desai Y.Assert.areEqual(parentBB.one("#child-2"), null, "child-2's bounding box should have been removed");
dffbe2d4e60ed4db1cecdea6cec2041eed9ff555Satyen Desai Y.Assert.areEqual(parentBB.all(childSelector).size(), 3, "The widget should now have three children bounding boxes.");
dffbe2d4e60ed4db1cecdea6cec2041eed9ff555Satyen Desai Y.Assert.areEqual(widget.size(), 3, "The widget should now have three children.");
dffbe2d4e60ed4db1cecdea6cec2041eed9ff555Satyen Desai testRemoveFocusedChild : function() {
dffbe2d4e60ed4db1cecdea6cec2041eed9ff555Satyen Desai var widget = new Y.ParentWidget({
dffbe2d4e60ed4db1cecdea6cec2041eed9ff555Satyen Desai id: "widget-1",
dffbe2d4e60ed4db1cecdea6cec2041eed9ff555Satyen Desai { type: Y.ChildWidget, label: "Child One", id: "child-1" },
dffbe2d4e60ed4db1cecdea6cec2041eed9ff555Satyen Desai { type: Y.ChildWidget, label: "Child Two", id: "child-2" },
dffbe2d4e60ed4db1cecdea6cec2041eed9ff555Satyen Desai { type: Y.ChildWidget, label: "Child Three", id: "child-3" },
dffbe2d4e60ed4db1cecdea6cec2041eed9ff555Satyen Desai { type: Y.ChildWidget, label: "Child Four", id: "child-4" }
dffbe2d4e60ed4db1cecdea6cec2041eed9ff555Satyen Desai var childSelector = "." + widget.item(0).getClassName(),
dffbe2d4e60ed4db1cecdea6cec2041eed9ff555Satyen Desai parentBB = widget.get("boundingBox");
dffbe2d4e60ed4db1cecdea6cec2041eed9ff555Satyen Desai Y.Assert.areSame(widget.item(1), widget.get("activeDescendant"));
dffbe2d4e60ed4db1cecdea6cec2041eed9ff555Satyen Desai var removedChild = widget.remove(1);
dffbe2d4e60ed4db1cecdea6cec2041eed9ff555Satyen Desai Y.Assert.areEqual(removedChild.get("id"), "child-2", "The parent's \"remove\" method should return a reference to the child removed.");
dffbe2d4e60ed4db1cecdea6cec2041eed9ff555Satyen Desai Y.Assert.areEqual(parentBB.one("#child-2"), null, "child-2's bounding box should have been removed");
dffbe2d4e60ed4db1cecdea6cec2041eed9ff555Satyen Desai Y.Assert.areEqual(parentBB.all(childSelector).size(), 3, "The widget should now have three children bounding boxes.");
dffbe2d4e60ed4db1cecdea6cec2041eed9ff555Satyen Desai Y.Assert.areEqual(widget.size(), 3, "The widget should now have three children.");
dffbe2d4e60ed4db1cecdea6cec2041eed9ff555Satyen Desai Y.Assert.isNull(widget.get("activeDescendant"));
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
ca4cb3af5af57ff62359482f6b9106dde7091717Satyen Desai tree.item(2).selectChild(0);
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.");
ca4cb3af5af57ff62359482f6b9106dde7091717Satyen Desai // Confirm that we can't do a multiple selection
ca4cb3af5af57ff62359482f6b9106dde7091717Satyen Desai var evts = [];
ca4cb3af5af57ff62359482f6b9106dde7091717Satyen Desai tree.on("selectedChange", function() {
ca4cb3af5af57ff62359482f6b9106dde7091717Satyen Desai evts.push("root:onSelectedChange");
ca4cb3af5af57ff62359482f6b9106dde7091717Satyen Desai tree.after("selectedChange", function() {
ca4cb3af5af57ff62359482f6b9106dde7091717Satyen Desai evts.push("root:afterSelectedChange");
ca4cb3af5af57ff62359482f6b9106dde7091717Satyen Desai tree.set("selected", 1);
ca4cb3af5af57ff62359482f6b9106dde7091717Satyen Desai Y.ArrayAssert.itemsAreEqual(["root:onSelectedChange"], evts);
ca4cb3af5af57ff62359482f6b9106dde7091717Satyen Desai tree.item(2).on("selectedChange", function() {
ca4cb3af5af57ff62359482f6b9106dde7091717Satyen Desai evts.push("subTree:onSelectedChange");
ca4cb3af5af57ff62359482f6b9106dde7091717Satyen Desai tree.item(2).after("selectedChange", function() {
ca4cb3af5af57ff62359482f6b9106dde7091717Satyen Desai evts.push("subTree:afterSelectedChange");
ca4cb3af5af57ff62359482f6b9106dde7091717Satyen Desai tree.item(2).set("selected", 1);
ca4cb3af5af57ff62359482f6b9106dde7091717Satyen Desai Y.ArrayAssert.itemsAreEqual(["subTree:onSelectedChange", "root:onSelectedChange"], evts);
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
5d6602ccab9b5300134be9f9c206a815d1df3eccSatyen Desai // So tests can be rerun
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\"");
153a5c4700cc6ab14ac1898ab461a13f738f4d1eSatyen Desai testFullDestroy: function () {
c5d69e6f30e09e2833161efb5393ecc8a8c9d8d6Satyen Desai var expected = ["leaf-1", "leaf-2", "subtree-leaf-1", "subtree-leaf-2", "subtree", "tree"];
c5d69e6f30e09e2833161efb5393ecc8a8c9d8d6Satyen Desai var destroyed = [];
c5d69e6f30e09e2833161efb5393ecc8a8c9d8d6Satyen Desai var tree = new Y.ParentWidget({
c5d69e6f30e09e2833161efb5393ecc8a8c9d8d6Satyen Desai { type: Y.ChildWidget, id: "leaf-1", label: "Leaf One" },
c5d69e6f30e09e2833161efb5393ecc8a8c9d8d6Satyen Desai { type: Y.ChildWidget, id: "leaf-2", label: "Leaf Two" },
c5d69e6f30e09e2833161efb5393ecc8a8c9d8d6Satyen Desai { type: Y.ParentWidget, id: "subtree", label: "Subtree", children: [
c5d69e6f30e09e2833161efb5393ecc8a8c9d8d6Satyen Desai { type: Y.ChildWidget, id: "subtree-leaf-1", label: "Subtree - Leaf One" },
c5d69e6f30e09e2833161efb5393ecc8a8c9d8d6Satyen Desai { type: Y.ChildWidget, id: "subtree-leaf-2", label: "Subtree - Leaf Two" }
c5d69e6f30e09e2833161efb5393ecc8a8c9d8d6Satyen Desai // We're only doing this the long way, because the event bubbling doesn't
c5d69e6f30e09e2833161efb5393ecc8a8c9d8d6Satyen Desai // seem to be working (subtree is missing). Otherwise we would use tree.on("*:destroy");
c5d69e6f30e09e2833161efb5393ecc8a8c9d8d6Satyen Desai tree.each(function(child) {
c5d69e6f30e09e2833161efb5393ecc8a8c9d8d6Satyen Desai var id = child.get("id");
c5d69e6f30e09e2833161efb5393ecc8a8c9d8d6Satyen Desai child.after("destroy", function(e) {
c5d69e6f30e09e2833161efb5393ecc8a8c9d8d6Satyen Desai Y.Assert.isNull(Y.Node.one("#" + id), "Child bounding box still in DOM");
c5d69e6f30e09e2833161efb5393ecc8a8c9d8d6Satyen Desai child.each(function(subtreechild) {
c5d69e6f30e09e2833161efb5393ecc8a8c9d8d6Satyen Desai var id = subtreechild.get("id");
c5d69e6f30e09e2833161efb5393ecc8a8c9d8d6Satyen Desai subtreechild.after("destroy", function(e) {
c5d69e6f30e09e2833161efb5393ecc8a8c9d8d6Satyen Desai Y.Assert.isNull(Y.Node.one("#" + id), "Subtree child Bounding box still in DOM");
c5d69e6f30e09e2833161efb5393ecc8a8c9d8d6Satyen Desai var rootId = tree.get("id");
c5d69e6f30e09e2833161efb5393ecc8a8c9d8d6Satyen Desai tree.after("destroy", function(e) {
c5d69e6f30e09e2833161efb5393ecc8a8c9d8d6Satyen Desai Y.Assert.isNull(Y.Node.one("#" + rootId), "Root Bounding box still in DOM");
c5d69e6f30e09e2833161efb5393ecc8a8c9d8d6Satyen Desai Y.ArrayAssert.itemsAreEqual(expected, destroyed, "Unexpected destroy events");
153a5c4700cc6ab14ac1898ab461a13f738f4d1eSatyen Desai testRemoveChildOnDestroy: function () {
153a5c4700cc6ab14ac1898ab461a13f738f4d1eSatyen Desai var tree = new Y.ParentWidget({
153a5c4700cc6ab14ac1898ab461a13f738f4d1eSatyen Desai { type: Y.ChildWidget, id: "leaf-1", label: "Leaf One" },
153a5c4700cc6ab14ac1898ab461a13f738f4d1eSatyen Desai { type: Y.ChildWidget, id: "leaf-2", label: "Leaf Two" },
153a5c4700cc6ab14ac1898ab461a13f738f4d1eSatyen Desai { type: Y.ParentWidget, id: "subtree", label: "Subtree", children: [
153a5c4700cc6ab14ac1898ab461a13f738f4d1eSatyen Desai { type: Y.ChildWidget, id: "subtree-leaf-1", label: "Subtree - Leaf One" },
153a5c4700cc6ab14ac1898ab461a13f738f4d1eSatyen Desai { type: Y.ChildWidget, id: "subtree-leaf-2", label: "Subtree - Leaf Two" }
153a5c4700cc6ab14ac1898ab461a13f738f4d1eSatyen Desai var subtree = tree.item(2);
153a5c4700cc6ab14ac1898ab461a13f738f4d1eSatyen Desai Y.Assert.areEqual(3, tree.size(), "Initial tree size is incorrect");
153a5c4700cc6ab14ac1898ab461a13f738f4d1eSatyen Desai Y.Assert.areEqual(2, subtree.size(), "Initial tree size is incorrect");
153a5c4700cc6ab14ac1898ab461a13f738f4d1eSatyen Desai Y.Assert.areEqual(2, tree.size(), "Item 1 doesn't seem to have been removed. Tree size is the same");
153a5c4700cc6ab14ac1898ab461a13f738f4d1eSatyen Desai Y.Assert.areEqual("subtree", tree.item(1).get("id"), "Item 1 doesn't seem to have been removed");
153a5c4700cc6ab14ac1898ab461a13f738f4d1eSatyen Desai Y.Assert.areEqual(1, subtree.size(), "Subtree item 0 doesn't seem to have been removed. subtree size is the same");
153a5c4700cc6ab14ac1898ab461a13f738f4d1eSatyen Desai Y.Assert.areEqual("subtree-leaf-2", subtree.item(0).get("id"), "Subtree item 0 doesn't seem to have been removed");
153a5c4700cc6ab14ac1898ab461a13f738f4d1eSatyen Desai Y.Assert.areEqual(subtree.item(1), null, "Subtree item 1 should have moved up to item 0");
37c410fc73ed5acc3161813869a31de525b5aa2eSatyen Desai testUIEvents : function() {
37c410fc73ed5acc3161813869a31de525b5aa2eSatyen Desai var expectedEvents = [
37c410fc73ed5acc3161813869a31de525b5aa2eSatyen Desai "parentwidget:click",
37c410fc73ed5acc3161813869a31de525b5aa2eSatyen Desai "parentwidget:click"
37c410fc73ed5acc3161813869a31de525b5aa2eSatyen Desai actualEvents = [],
37c410fc73ed5acc3161813869a31de525b5aa2eSatyen Desai expectedChildEvents = [
37c410fc73ed5acc3161813869a31de525b5aa2eSatyen Desai "childwidget:click",
37c410fc73ed5acc3161813869a31de525b5aa2eSatyen Desai "childwidget:click"
37c410fc73ed5acc3161813869a31de525b5aa2eSatyen Desai actualChildEvents = [];
37c410fc73ed5acc3161813869a31de525b5aa2eSatyen Desai var widget = new Y.ParentWidget({
37c410fc73ed5acc3161813869a31de525b5aa2eSatyen Desai id: "widget-1",
37c410fc73ed5acc3161813869a31de525b5aa2eSatyen Desai { type: Y.ChildWidget, label: '<span class="uitarget">Child One - Click Target</span>', id: "child-1" },
37c410fc73ed5acc3161813869a31de525b5aa2eSatyen Desai { type: Y.ChildWidget, label: '<span class="uitarget">Child Two - Click Target</span>', id: "child-2" }
37c410fc73ed5acc3161813869a31de525b5aa2eSatyen Desai widget.on("click", function(e) {
37c410fc73ed5acc3161813869a31de525b5aa2eSatyen Desai widget.item(0).on("click", function(e) {
37c410fc73ed5acc3161813869a31de525b5aa2eSatyen Desai widget.item(1).on("click", function(e) {
37c410fc73ed5acc3161813869a31de525b5aa2eSatyen Desai Y.Node.one("#child-1 .uitarget").simulate("click");
37c410fc73ed5acc3161813869a31de525b5aa2eSatyen Desai Y.Node.one("#child-2 .uitarget").simulate("click");
37c410fc73ed5acc3161813869a31de525b5aa2eSatyen Desai Y.ArrayAssert.itemsAreEqual(expectedEvents, actualEvents, "Unexpected UI events");
37c410fc73ed5acc3161813869a31de525b5aa2eSatyen Desai Y.ArrayAssert.itemsAreEqual(expectedChildEvents, actualChildEvents, "Unexpected Child UI events");
df315088426ba61b1911bca0c888843588e552e9Satyen Desai testCustomAsyncRender : function() {
df315088426ba61b1911bca0c888843588e552e9Satyen Desai // NOTE: This is not a unit test for "out-of-the-box" code per-se.
df315088426ba61b1911bca0c888843588e552e9Satyen Desai // It's testing an additional check for "rendered", added to _uiAddChild, specifically
df315088426ba61b1911bca0c888843588e552e9Satyen Desai // for a customization which modified child.render() to be async.
df315088426ba61b1911bca0c888843588e552e9Satyen Desai // See http://yuilibrary.com/projects/yui3/ticket/2529863 for more details.
df315088426ba61b1911bca0c888843588e552e9Satyen Desai var test = this;
df315088426ba61b1911bca0c888843588e552e9Satyen Desai var AsyncRenderParent = Y.Base.create("asyncParent", Y.Widget, [Y.WidgetParent], {
df315088426ba61b1911bca0c888843588e552e9Satyen Desai add: function() {
df315088426ba61b1911bca0c888843588e552e9Satyen Desai var parent = this;
df315088426ba61b1911bca0c888843588e552e9Satyen Desai Y.WidgetParent.prototype.add.apply(parent, arguments);
df315088426ba61b1911bca0c888843588e552e9Satyen Desai parent.renderQ.after("complete", function() {
df315088426ba61b1911bca0c888843588e552e9Satyen Desai parent.fire("asyncAddComplete");
df315088426ba61b1911bca0c888843588e552e9Satyen Desai var AsyncRenderChild = Y.Base.create("asyncChild", Y.Widget, [Y.WidgetChild], {
df315088426ba61b1911bca0c888843588e552e9Satyen Desai render: function() {
df315088426ba61b1911bca0c888843588e552e9Satyen Desai var w = this,
df315088426ba61b1911bca0c888843588e552e9Satyen Desai args = arguments;
df315088426ba61b1911bca0c888843588e552e9Satyen Desai AsyncRenderChild.superclass.render.apply(w, args);
df315088426ba61b1911bca0c888843588e552e9Satyen Desai var widget = new AsyncRenderParent({
df315088426ba61b1911bca0c888843588e552e9Satyen Desai id:"widget-1"
df315088426ba61b1911bca0c888843588e552e9Satyen Desai widget.after("asyncAddComplete", function(e) {
df315088426ba61b1911bca0c888843588e552e9Satyen Desai Y.Assert.areEqual(widget.item(0).get("id"), "child-1", "child-1 is out of order");
df315088426ba61b1911bca0c888843588e552e9Satyen Desai Y.Assert.areEqual(widget.item(1).get("id"), "child-2", "child-2 is out of order");
df315088426ba61b1911bca0c888843588e552e9Satyen Desai Y.Assert.areEqual(widget.item(2).get("id"), "child-3", "child-3 is out of order");
df315088426ba61b1911bca0c888843588e552e9Satyen Desai var renderedChildren = widget.get("contentBox").get("children");
df315088426ba61b1911bca0c888843588e552e9Satyen Desai Y.Assert.areEqual(renderedChildren.item(0).get("id"), "child-1", "child-1 is out of order");
df315088426ba61b1911bca0c888843588e552e9Satyen Desai Y.Assert.areEqual(renderedChildren.item(1).get("id"), "child-2", "child-2 is out of order");
df315088426ba61b1911bca0c888843588e552e9Satyen Desai Y.Assert.areEqual(renderedChildren.item(2).get("id"), "child-3", "child-3 is out of order");
df315088426ba61b1911bca0c888843588e552e9Satyen Desai {type: AsyncRenderChild, label: "Child One", id: "child-1"},
df315088426ba61b1911bca0c888843588e552e9Satyen Desai {type: AsyncRenderChild, label: "Child Two", id: "child-2"},
df315088426ba61b1911bca0c888843588e552e9Satyen Desai {type: AsyncRenderChild, label: "Child Three", id: "child-3"}
5d6602ccab9b5300134be9f9c206a815d1df3eccSatyen Desai Y.Test.Runner.setName("Widget ParentChild Tests");
5d6602ccab9b5300134be9f9c206a815d1df3eccSatyen Desai var console;
5d6602ccab9b5300134be9f9c206a815d1df3eccSatyen Desai Y.one("#btnRun").set("disabled", false).on("click", function() {
5d6602ccab9b5300134be9f9c206a815d1df3eccSatyen Desai if (!console) {
5d6602ccab9b5300134be9f9c206a815d1df3eccSatyen Desai console = new Y.Console({
5d6602ccab9b5300134be9f9c206a815d1df3eccSatyen Desai id:"console",
5d6602ccab9b5300134be9f9c206a815d1df3eccSatyen Desai width:"100%",
5d6602ccab9b5300134be9f9c206a815d1df3eccSatyen Desai height:"90%",
5d6602ccab9b5300134be9f9c206a815d1df3eccSatyen Desai verbose : false,
5d6602ccab9b5300134be9f9c206a815d1df3eccSatyen Desai printTimeout: 0,
5d6602ccab9b5300134be9f9c206a815d1df3eccSatyen Desai newestOnTop : false,
5d6602ccab9b5300134be9f9c206a815d1df3eccSatyen Desai entryTemplate: '<pre class="{entry_class} {cat_class} {src_class}">'+
5d6602ccab9b5300134be9f9c206a815d1df3eccSatyen Desai '<span class="{entry_cat_class}">{label}</span>'+
5d6602ccab9b5300134be9f9c206a815d1df3eccSatyen Desai '<span class="{entry_content_class}">{message}</span>'+
5d6602ccab9b5300134be9f9c206a815d1df3eccSatyen Desai }).render();
5d6602ccab9b5300134be9f9c206a815d1df3eccSatyen Desai <p><input type="button" value="Run Tests" id="btnRun" disabled=true></p>