parent-child.html revision 1bb9ba7f0e700971d0c04fca23820699348cfd49
d5b7ba26785d7494166d48876362ba30ff30b98awrowe<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
269e0a31aa0f6aafe7292e932a182ccb535e55a9trawick #console .yui3-console-entry {
269e0a31aa0f6aafe7292e932a182ccb535e55a9trawick padding:2px;
263702cf74538e1c6d31b58baae20ac168a45712minfrin margin:0px;
263702cf74538e1c6d31b58baae20ac168a45712minfrin min-height:0;
98e28ee4e3e3972abeb1bfd509c0e79c54c871f6nd #console .yui3-console-entry-fail .yui3-console-entry-cat {
98e28ee4e3e3972abeb1bfd509c0e79c54c871f6nd background-color:red;
50e23f7dca0da305e324349792fb7c27d8e04b60minfrin #console .yui3-console-entry-pass .yui3-console-entry-cat {
50e23f7dca0da305e324349792fb7c27d8e04b60minfrin background-color:green;
217f75ac21f879b5d71892790e536cd80184db8dminfrin #console .yui3-console-entry-perf .yui3-console-entry-cat {
217f75ac21f879b5d71892790e536cd80184db8dminfrin background-color:blue;
c1ba3b0ac00c4fee2f4b950dfdb167b39611b661nd #console {
c1ba3b0ac00c4fee2f4b950dfdb167b39611b661nd position:static;
63267f5839a0a485948dd38ba607427d51a169e3madhum html, body {
63267f5839a0a485948dd38ba607427d51a169e3madhum height:100%;
03a3ed87983471816561562f957390ed935d7b3bnd useBrowserConsole:false,
03a3ed87983471816561562f957390ed935d7b3bnd filter: (window.location.search.match(/[?&]filter=([^&]+)/) || [])[1] || 'min'
c533ecac2227dc228070e686fb14dc6860f497f8nd }).use("node-event-simulate", "widget", "widget-parent", "widget-child", "test", "console", function (Y) {
33c6c050363f8b571cec0477008390a95b41523and var RootWidget = function () {
33c6c050363f8b571cec0477008390a95b41523and RootWidget.superclass.constructor.apply(this, arguments);
68ed4d659ab8f6deb93fe6d520b5d3ee65645493nd RootWidget.NAME = "rootwidget";
2bfe4d90e1d374e14fd5db16a799e6f5e0944748nd Y.RootWidget = Y.Base.build("rootwidget", RootWidget, [Y.WidgetParent], { dynamic: false });
2bfe4d90e1d374e14fd5db16a799e6f5e0944748nd var ParentWidget = function () {
97789c9dcc4cc724c9b80fb9b428d128c58e3e0and ParentWidget.superclass.constructor.apply(this, arguments);
97789c9dcc4cc724c9b80fb9b428d128c58e3e0and Y.mix(ParentWidget, {
56cefde0af6b8db6fda0f1d95d8cdca54f397cd0nd NAME: "parentwidget",
9e8c2603790f490398a0fabf97866b6815748a54ianh renderUI: function () {
a21b3b9d8ebb12fd51fa1d17e44d5644a35a9a5fnd if (this.get("depth") > -1) {
5fcef4390e6414ad7754c2f004974982bc33cac2nd var label = Y.Node.create("<em>" + this.get("label") + "</em>"),
5fcef4390e6414ad7754c2f004974982bc33cac2nd parent = this.get("boundingBox").get("parentNode");
e6c244ee56578707b20a86e0e938498299a93b6cnd Y.ParentWidget = Y.Base.build("parentwidget", ParentWidget, [Y.WidgetParent, Y.WidgetChild], { dynamic: false });
56d70402724e1872992bcac08b802681cf762d9and var ChildWidget = function () {
56d70402724e1872992bcac08b802681cf762d9and ChildWidget.superclass.constructor.apply(this, arguments);
bfbca4e24db7fef55c0ab787aca9f89594530b45geoff Y.mix(ChildWidget, {
bfbca4e24db7fef55c0ab787aca9f89594530b45geoff NAME: "childwidget",
d7c7669331357296719d67d1963d40d713ed455atrawick renderUI: function () {
d7c7669331357296719d67d1963d40d713ed455atrawick this.get("contentBox").setContent(this.get("label"));
781888a651637edc0b043a6787cb0c2acf30a187geoff Y.ChildWidget = Y.Base.build("childwidget", ChildWidget, [Y.WidgetChild], { dynamic: false });
5d3e5520c34648220ed0cd9dc01c2c203257c86fnd var suite = new Y.Test.Suite("Widget ParentChild Tests");
92d95be777d4365eb79444a7a558355a7a92081ajorton name: "Widget Parent API, Widget Child API Tests",
af8dee354a287249dd9f3f77bbe850108e5afe43trawick testAdd: function() {
af8dee354a287249dd9f3f77bbe850108e5afe43trawick var root = new Y.ParentWidget(),
fb82af0f0cd7b58eef19c54b086131b7e1e1e749madhum child = root.add({ type: "ChildWidget", label: "Child One" });
bcccfc984c481af611fa4ffc3e2732400b041cfend Y.Assert.isNotUndefined(child, "Add should return a reference to the child that was created and added.");
bcccfc984c481af611fa4ffc3e2732400b041cfend Y.assert((root.size() == 1), "The root Widget should have one child");
f78505c7d260473bf11002f5028186f27d0ed8a0geoff child = root.add({ childType: ChildWidget, label: "Child Two" });
f78505c7d260473bf11002f5028186f27d0ed8a0geoff Y.Assert.isNotUndefined(child, "Add should return a reference to the child that was created and added.");
f78505c7d260473bf11002f5028186f27d0ed8a0geoff Y.assert((root.size() == 2), "The root Widget should have two children");
ea981941b1e5ecfb1a27b9e9aff32b9c98640ed9nd child = root.add({ label: "Invalid Child" });
ea981941b1e5ecfb1a27b9e9aff32b9c98640ed9nd Y.Assert.isUndefined(child, "Add should return undefined since the type of the child is undefined.");
ea981941b1e5ecfb1a27b9e9aff32b9c98640ed9nd Y.assert((root.size() == 2), "The root Widget should have two children");
ced699ca391a4fb7d70cfeb995c58d4bf62f00a8trawick catch (e) {
ced699ca391a4fb7d70cfeb995c58d4bf62f00a8trawick 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.");
d11bf78168abbb07d8ed9f54d7ea0953d46aad83nd child = root.add({ childType: "MyChild", label: "Invalid Child" });
d11bf78168abbb07d8ed9f54d7ea0953d46aad83nd Y.Assert.isUndefined(child, "The \"add\" method should return undefined since the type of the child is invalid.");
d11bf78168abbb07d8ed9f54d7ea0953d46aad83nd Y.assert((root.size() == 2), "The root Widget should have two children");
bf28a00d8218aa76a56eddabca308e8d0e691626nd catch (e) {
bf28a00d8218aa76a56eddabca308e8d0e691626nd Y.Assert.isNotUndefined(e, "The \"add\" method should throw an error since the type of the child is invalid.");
c08f5a0cf2b8903255186ba998a4481dfac9c796nd child = root.add({ type: MyChild, label: "Invalid Child" });
c08f5a0cf2b8903255186ba998a4481dfac9c796nd Y.Assert.isUndefined(child, "Add should return undefined since the type of the child is invalid.");
eea521297270de3f9ae70d8822f8665c513de574nd Y.assert((root.size() == 2), "The root Widget should have two children");
5bcdf2cd27ab0c91a3c7eaffbff4cb8505389dc1nd catch (e) {
5bcdf2cd27ab0c91a3c7eaffbff4cb8505389dc1nd Y.Assert.isNotUndefined(e, "The \"add\" method should throw an error since the type of the child is invalid.");
02b0660d7f44ff8106bd5095653e9c19e39ec37dnd root.set("defaultChildType", "ChildWidget");
5b8e35ad88268c0210d93288dad57c2f1d3e8811nd child = root.add({ label: "Child Three" });
a9ee8e9bd3dffd23ca49be8d0bdf0e33cd0bcce2jorton Y.Assert.isNotUndefined(child, "Add should return a reference to the child that was created and added.");
a9ee8e9bd3dffd23ca49be8d0bdf0e33cd0bcce2jorton Y.assert((root.size() == 3), "The root Widget should have three children");
8d9494af6ddb7a9c998b1b622e0bcd8d17cac50ejorton root.set("defaultChildType", ChildWidget);
9026fcf39ea5fbacee72b6c4f68e6c778dbad478nd child = root.add({ label: "Child Four" });
8aad5258d3ecde3751559bc685a3185e63cbde9aianh Y.Assert.isNotUndefined(child, "Add should return a reference to the child that was created and added.");
8aad5258d3ecde3751559bc685a3185e63cbde9aianh Y.assert((root.size() == 4), "The root Widget should have four children");
71f3601de4983bc2a6aaffcf37dc1d35c8674a34coar root.set("defaultChildType", "MyChild");
49a82db11388cff9b29ff861b4241bbce69c76fdtrawick Y.Assert.areEqual(root.get("defaultChildType"), Y.ChildWidget, "Setter for \"defaultChildType\" should disallow setting the attribute to an invalid value.");
49a82db11388cff9b29ff861b4241bbce69c76fdtrawick root.set("defaultChildType", MyChild);
f23c50b3628a8571da2ff3277ae58ef1d675554ftrawick Y.Assert.areEqual(root.get("defaultChildType"), Y.ChildWidget, "Setter for \"defaultChildType\" should disallow setting the attribute to an invalid value.");
6126fad8adeca94e9813812c691747afeca164dftrawick testInsert: function () {
6126fad8adeca94e9813812c691747afeca164dftrawick var widget = new Y.ParentWidget({
7ed5992392d5babab20be4ce4029ad17ae062b5aianh id: "widget-1",
7ed5992392d5babab20be4ce4029ad17ae062b5aianh children: [
b7973a1e572a3ff7cdedb48ed1f9481ece700bf9trawick { type: Y.ChildWidget, label: "Child One", id: "child-1" },
36f2369ee230c310fed3b600e9e99cf5770804a3wrowe { type: Y.ChildWidget, label: "Child Two", id: "child-2" },
b7973a1e572a3ff7cdedb48ed1f9481ece700bf9trawick { type: Y.ChildWidget, label: "Child Three", id: "child-3" },
5c4e29c5f77fbc967d78886ab378b9500267b0fbtrawick { type: Y.ChildWidget, label: "Child Four", id: "child-4" }
679cafe33462d8c6bd0a74cc4359e561d19a0aafnd widget.add({ type: Y.ChildWidget, label: "Child One", id: "inserted-child-1" }, 0);
6c4c113ce85934b11c9e78399e1bb8ec7a568af9nd Y.Assert.areEqual(widget.item(0).get("id"), "inserted-child-1", "The newly inserted child should be the parent's first child.");
81ef3d132c8f335006465f297c42319f8734825dnd Y.Assert.areEqual(widget.size(), 5, "The widget should have five children.");
73291de2e17c97d3549f2f8aa085ca43d27e108and { type: Y.ChildWidget, label: "Child One", id: "inserted-child-2" },
73291de2e17c97d3549f2f8aa085ca43d27e108and { type: Y.ChildWidget, label: "Child One", id: "inserted-child-3" }
3caed8f01e7d67f3ad5d47cb28bb4e43131652fdjerenkrantz 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.");
3caed8f01e7d67f3ad5d47cb28bb4e43131652fdjerenkrantz 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.");
3caed8f01e7d67f3ad5d47cb28bb4e43131652fdjerenkrantz 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.");
238e707c9022eaa8332a702dd6913dd0d1fb3df8jerenkrantz Y.Assert.areEqual(widget.size(), 7, "The widget should have seven children.");
e127d82e8afc2f885fe2183b68d4a110580d21dfjwoolley testRemove: function () {
fd99717a52886f7d9f9f73be2080d3fdc2ec4bd6nd var widget = new Y.ParentWidget({
5fb2e8564729922524cd011b11e2d4f5d76f5a8dnd id: "widget-1",
5fb2e8564729922524cd011b11e2d4f5d76f5a8dnd children: [
5fb2e8564729922524cd011b11e2d4f5d76f5a8dnd { type: Y.ChildWidget, label: "Child One", id: "child-1" },
987c2c2ff2f19f306357f79d3280b347d96c470fnd { type: Y.ChildWidget, label: "Child Two", id: "child-2" },
987c2c2ff2f19f306357f79d3280b347d96c470fnd { type: Y.ChildWidget, label: "Child Three", id: "child-3" },
987c2c2ff2f19f306357f79d3280b347d96c470fnd { type: Y.ChildWidget, label: "Child Four", id: "child-4" }
f2fe083bb9fabd2af7eb39d4f154f27a451bb5a4nd var childSelector = "." + widget.item(0).getClassName(),
f2fe083bb9fabd2af7eb39d4f154f27a451bb5a4nd parentBB = widget.get("boundingBox");
7de6cb79f71a9007ba2b1e786cbad8b84f05d101nd Y.Assert.areEqual(widget.remove(1).get("id"), "child-2", "The parent's \"remove\" method should return a reference to the child removed.");
7de6cb79f71a9007ba2b1e786cbad8b84f05d101nd Y.Assert.areEqual(parentBB.one("#child-2"), null, "child-2's bounding box should have been removed");
7de6cb79f71a9007ba2b1e786cbad8b84f05d101nd Y.Assert.areEqual(parentBB.all(childSelector).size(), 3, "The widget should now have three children bounding boxes.");
7de6cb79f71a9007ba2b1e786cbad8b84f05d101nd Y.Assert.areEqual(widget.size(), 3, "The widget should now have three children.");
36f2369ee230c310fed3b600e9e99cf5770804a3wrowe 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.");
aa9b03a5f32732c0caaef03a7ed78ffb290e29e4trawick Y.Assert.areEqual(parentBB.one("#child-1"), null, "child-1's bounding box should have been removed");
ab56518227d474ee08f039e4c5540011c1b8a913trawick Y.Assert.areEqual(parentBB.all(childSelector).size(), 2, "The widget should now have two children bounding boxes.");
36f2369ee230c310fed3b600e9e99cf5770804a3wrowe Y.Assert.areEqual(widget.size(), 2, "The widget should now have two children.");
a18a308d7a942230edcde1bf00d7ae9b4b143c90trawick var removed = widget.removeAll();
a18a308d7a942230edcde1bf00d7ae9b4b143c90trawick Y.Assert.areEqual(removed.size(), 2, "The \"removeAll\" method should return a Y.ArrayList instance with a size of 2.");
3b872593fd5f61981d9dd69a4b0b5d5f5f668929trawick Y.Assert.areEqual(widget.size(), 0, "The widget should now have no children.");
3b872593fd5f61981d9dd69a4b0b5d5f5f668929trawick Y.Assert.areEqual(parentBB.all(childSelector).size(), 0, "The widget should now have no children bounding boxes.");
fcdca175a52fe517f2317ba0e2b6e6d14522b869madhum testSingleSelection: function () {
92a2439559cf1161742650ed9c50c6483bd029cemadhum var root = new Y.ParentWidget({
36f2369ee230c310fed3b600e9e99cf5770804a3wrowe id: "new-widget",
92a2439559cf1161742650ed9c50c6483bd029cemadhum children: [
ebecc16986604cce1369d5075eff65032e3dd0deianh { type: Y.ChildWidget, label: "Child One" },
0d60370bedd05f9632f54e85c417ce472d463674madhum { type: Y.ChildWidget, label: "Child Two" },
ebecc16986604cce1369d5075eff65032e3dd0deianh { type: Y.ChildWidget, label: "Child Three" },
764315969cef40e50cdc6a5e9638454e10c1c06end { type: Y.ChildWidget, label: "Child Four" }
b92cba59a0890be43b14aaf1ce30606140be9593nd root.item(0).set("selected", 1);
402d23baca89e8c4fcb4e52ad8b2d66a6904baaetrawick root.item(1).set("selected", 1);
402d23baca89e8c4fcb4e52ad8b2d66a6904baaetrawick // Confirm the selection
4caa28863a3418d26cc20a998dc368c3de3b7e19jerenkrantz Y.Assert.areEqual(root.item(1).get("selected"), 1, "The second child of the parent widget should be selected");
4caa28863a3418d26cc20a998dc368c3de3b7e19jerenkrantz Y.Assert.areEqual(root.get("selected"), 2, "The root's \"selected\" attribute should return 2");
a3f2646ef3d8a3a5234a5601de0f95f10308c2a6jerenkrantz Y.Assert.areEqual(root.get("selection"), root.item(1), "The parent's \"selection\" attribute should return a reference to its second child.");
9e398d701dd430f073ff5418fb720642e064046ajerenkrantz // Select another child and confirm the previously selected
9e398d701dd430f073ff5418fb720642e064046ajerenkrantz // child is deselected and and the parent's selection is
9e398d701dd430f073ff5418fb720642e064046ajerenkrantz // correctly updated.
1a5b9e0071f0c662036250b482d566ad87ff0b4bjerenkrantz root.item(2).set("selected", 1);
a7ac9b52c3d9f7ce937f078a0d585023db626c55jerenkrantz Y.Assert.areEqual(root.item(1).get("selected"), 0, "The parent's second child should not be selected");
a7ac9b52c3d9f7ce937f078a0d585023db626c55jerenkrantz Y.Assert.areEqual(root.item(2).get("selected"), 1, "The parent's third child should be selected");
a7ac9b52c3d9f7ce937f078a0d585023db626c55jerenkrantz Y.Assert.areEqual(root.get("selection"), root.item(2), "The parent's \"selection\" attribute should return a reference to its third child.");
ba6c07204bd224fa5d4cd0e6b8bf256d6daffb74nd // Confirm deselection
db5837bbc9bef214303e755fa52122140366cb6fianh root.item(2).set("selected", 0);
aac2b82fe4f1ac117e2a0702438d6615542642dand Y.Assert.areEqual(root.item(2).get("selected"), 0, "The parent's third child should not be selected");
aac2b82fe4f1ac117e2a0702438d6615542642dand Y.Assert.areEqual(root.get("selected"), 0, "The parent's \"selected\" attribute should return 0");
aac2b82fe4f1ac117e2a0702438d6615542642dand Y.Assert.isNull(root.get("selection"), "The parent's \"selection\" attribute should return null.");
36f2369ee230c310fed3b600e9e99cf5770804a3wrowe var tree = new Y.ParentWidget({
ab8c0315521735c73ce16c8072f91e17c406ca5bnd { type: Y.ChildWidget, id: "leaf-1", label: "Leaf One" },
ab8c0315521735c73ce16c8072f91e17c406ca5bnd { type: Y.ChildWidget, id: "leaf-2", label: "Leaf Two" },
ab8c0315521735c73ce16c8072f91e17c406ca5bnd { type: Y.ParentWidget, id: "subtree", label: "Subtree", children: [
b9e99e0d3154bbebe3e1b8d11d6c15bde79510a5nd { type: Y.ChildWidget, id: "subtree-leaf-1", label: "Subtree - Leaf One" },
b9e99e0d3154bbebe3e1b8d11d6c15bde79510a5nd { type: Y.ChildWidget, id: "subtree-leaf-2", label: "Subtree - Leaf Two" },
b9e99e0d3154bbebe3e1b8d11d6c15bde79510a5nd { type: Y.ChildWidget, id: "subtree-leaf-3", label: "Subtree - Leaf Three" },
ea5f8cfbb7ef1d19318f6994c26dd73c38ffd8ddjerenkrantz { type: Y.ChildWidget, id: "subtree-leaf-4", label: "Subtree - Leaf Four" }
2f408250e9111c4b85b2b4b9b8836e83987efdefstoddard // Select a child in the subtree to test if the selection is represented at the root level
2f408250e9111c4b85b2b4b9b8836e83987efdefstoddard tree.item(2).item(0).set("selected", 1);
47fe07199bddec6124ab7251c6be5c6c9ac00485jerenkrantz Y.Assert.areEqual(tree.get("selected"), 2, "The root's \"selected\" attribute should be 2 (indicating partially selected).");
47fe07199bddec6124ab7251c6be5c6c9ac00485jerenkrantz Y.Assert.areEqual(tree.item(2).get("selected"), 2, "The subtree's \"selected\" attribute should be 2 (indicating partially selected).");
6646a289c2d4778c8cd43d62b5a1cc966a356f85jerenkrantz Y.Assert.areEqual(tree.get("selection").get("id"), "subtree", "The root's \"selection\" attribute should return the subtree.");
6646a289c2d4778c8cd43d62b5a1cc966a356f85jerenkrantz Y.Assert.areEqual(tree.item(2).get("selection").get("id"), "subtree-leaf-1", "The subtree's \"selection\" attribute should return the first child.");
aec70520ebe1e33e0d5e83c3626649d2a41dbe68wrowe // Select a child in the root to confirm that the subtree's selection is cleared
aec70520ebe1e33e0d5e83c3626649d2a41dbe68wrowe tree.item(0).set("selected", 1);
ad451e2e428a069086d1c18c9e3372f8846ec617wrowe Y.Assert.areEqual(tree.get("selected"), 2, "The root's \"selected\" attribute should be 2 (indicating partially selected).");
ad451e2e428a069086d1c18c9e3372f8846ec617wrowe Y.Assert.areEqual(tree.get("selection").get("id"), "leaf-1", "The root's \"selection\" attribute should return a reference to its first child.");
ad451e2e428a069086d1c18c9e3372f8846ec617wrowe Y.Assert.areEqual(tree.item(2).get("selected"), 0, "The subtree should no longer be selected.");
329ce430c1ad464f1927f95f114ab16fe91e4c9bstoddard Y.Assert.areEqual(tree.item(2).get("selection"), null, "The subtree's \"selection\" attribute should return null.");
9026fcf39ea5fbacee72b6c4f68e6c778dbad478nd // Select a new child in the subtree to test if the selection is represented at the root level
9026fcf39ea5fbacee72b6c4f68e6c778dbad478nd tree.item(2).item(2).set("selected", 1);
9026fcf39ea5fbacee72b6c4f68e6c778dbad478nd Y.Assert.areEqual(tree.get("selected"), 2, "The root's \"selected\" attribute should be 2 (indicating partially selected).");
0043caa79a47e74a29c19b87bc85b2545e7209e6nd Y.Assert.areEqual(tree.item(2).get("selected"), 2, "The subtree's \"selected\" attribute should be 2 (indicating partially selected).");
0043caa79a47e74a29c19b87bc85b2545e7209e6nd Y.Assert.areEqual(tree.get("selection").get("id"), "subtree", "The root's \"selection\" attribute should return the subtree.");
0043caa79a47e74a29c19b87bc85b2545e7209e6nd Y.Assert.areEqual(tree.item(2).get("selection").get("id"), "subtree-leaf-3", "The subtree's \"selection\" attribute should return its third child.");
0043caa79a47e74a29c19b87bc85b2545e7209e6nd testMultipleSelection: function () {
0043caa79a47e74a29c19b87bc85b2545e7209e6nd var root = new Y.ParentWidget({
73e8c23f3efca94370c24e6a5908ee6e522bf4dbminfrin id: "m-s-widget",
73e8c23f3efca94370c24e6a5908ee6e522bf4dbminfrin multiple: true,
73e8c23f3efca94370c24e6a5908ee6e522bf4dbminfrin children: [
73e8c23f3efca94370c24e6a5908ee6e522bf4dbminfrin { type: Y.ChildWidget, label: "Child One" },
94e96b9af3e76ff6913fcf5306e3acb75c70168bminfrin { type: Y.ChildWidget, label: "Child Two" },
94e96b9af3e76ff6913fcf5306e3acb75c70168bminfrin { type: Y.ChildWidget, label: "Child Three" },
94e96b9af3e76ff6913fcf5306e3acb75c70168bminfrin { type: Y.ChildWidget, label: "Child Four" }
294742ca68d050582b774a02fa708926d4eba173minfrin root.item(0).set("selected", 1);
294742ca68d050582b774a02fa708926d4eba173minfrin root.item(1).set("selected", 1);
294742ca68d050582b774a02fa708926d4eba173minfrin // Confirm that both children are selected and
294742ca68d050582b774a02fa708926d4eba173minfrin // represented in the parent's selection.
294742ca68d050582b774a02fa708926d4eba173minfrin Y.Assert.areEqual(root.item(0).get("selected"), 1, "The first child of the parent widget should be selected.");
294742ca68d050582b774a02fa708926d4eba173minfrin Y.Assert.areEqual(root.item(1).get("selected"), 1, "The second child of the parent widget should be selected.");
294742ca68d050582b774a02fa708926d4eba173minfrin Y.Assert.areEqual(root.get("selection").size(), 2, "The \"selection\" attribute should return an ArrayList with a size of 2.");
294742ca68d050582b774a02fa708926d4eba173minfrin Y.Assert.areEqual(root.get("selected"), 2, "The root's \"selection\" attribute should be 2 (indicating partially selected).");
29bb843fb0833aec0d7f631a2bdbba9e9f6f3851minfrin // Select remaining children to confirm all children
29bb843fb0833aec0d7f631a2bdbba9e9f6f3851minfrin // are represented in the parent's selection and that
29bb843fb0833aec0d7f631a2bdbba9e9f6f3851minfrin // the parent's "selected" attribute returns 1.
29bb843fb0833aec0d7f631a2bdbba9e9f6f3851minfrin root.item(2).set("selected", 1);
29bb843fb0833aec0d7f631a2bdbba9e9f6f3851minfrin root.item(3).set("selected", 1);
b837ddaa27238a68194cefc842a0620dd28c75fbtrawick Y.Assert.areEqual(root.get("selection").size(), 4, "The \"selection\" attribute should return an ArrayList with a size of 4.");
b837ddaa27238a68194cefc842a0620dd28c75fbtrawick Y.Assert.areEqual(root.get("selected"), 1, "The root's \"selected\" attribute should return 1 (indicating fully selected).");
9ee730154a1f2bcd0e650ffc4df999460c2c6660bnicholes // Deselect all children and confirm the results
9ee730154a1f2bcd0e650ffc4df999460c2c6660bnicholes root.get("selection").each(function (child) {
9ee730154a1f2bcd0e650ffc4df999460c2c6660bnicholes child.set("selected", 0);
c386113d5a8d0760909f40632fa84b387405e976trawick Y.Assert.isNull(root.get("selection"), "The root's \"selection\" attribute should return null.");
c386113d5a8d0760909f40632fa84b387405e976trawick Y.Assert.areEqual(root.get("selected"), 0, "The root's \"selected\" attribute should return 0");
c386113d5a8d0760909f40632fa84b387405e976trawick // Select all children via selectAll() to confirm all
c386113d5a8d0760909f40632fa84b387405e976trawick // children are represented in the parent's selection and
c386113d5a8d0760909f40632fa84b387405e976trawick // that the parent's "selected" attribute returns 1.
408cee92f47d2d345c9fd57b17341d3dbbca4259nd Y.Assert.areEqual(root.get("selected"), 1, "The root's \"selected\" attribute should return 1");
408cee92f47d2d345c9fd57b17341d3dbbca4259nd Y.Assert.areEqual(root.get("selection").size(), 4, "The root's \"selection\" attribute should return an ArrayList with a size of 4.");
408cee92f47d2d345c9fd57b17341d3dbbca4259nd // Deselect all children via deselectAll() to confirm all
916b4a16ae45981780b372609bbaa05d45f8d9babnicholes // children are no longer selected and that the parent's
916b4a16ae45981780b372609bbaa05d45f8d9babnicholes // selection is empty.
ed3570ebd308d1e57fc42f7ccffec5ca8a6c8afdjorton Y.Assert.areEqual(root.get("selected"), 0, "The root's \"selected\" attribute should return 0");
ed3570ebd308d1e57fc42f7ccffec5ca8a6c8afdjorton Y.Assert.areEqual(root.get("selection"), null, "The root's \"selection\" attribute should return an ArrayList with a size of 4.");
7b95cbe3641be28a5b9aed8bbf749643f3c9e65cnd root.add({ type: Y.ParentWidget, id: "subtree", label: "Subtree", children: [
7b95cbe3641be28a5b9aed8bbf749643f3c9e65cnd { type: Y.ChildWidget, id: "subtree-leaf-1", label: "Subtree - Leaf One" },
250e3f54ac9cfd4d78b1180e7f75d8a16288b0f8trawick { type: Y.ChildWidget, id: "subtree-leaf-2", label: "Subtree - Leaf Two" },
250e3f54ac9cfd4d78b1180e7f75d8a16288b0f8trawick { type: Y.ChildWidget, id: "subtree-leaf-3", label: "Subtree - Leaf Three" },
250e3f54ac9cfd4d78b1180e7f75d8a16288b0f8trawick { type: Y.ChildWidget, id: "subtree-leaf-4", label: "Subtree - Leaf Four" }
ee64282e65aac20cde407210163ecbf7e104cc56stoddard Y.Assert.isTrue(root.item(4).get("multiple"), "The \"multiple\" attribute of the nested parent widget should be true.");
911591cbd699fcc3df55396b264f2b811a068fb2stoddard testAncestorNavigation: function () {
329ce430c1ad464f1927f95f114ab16fe91e4c9bstoddard var widget = new Y.ParentWidget({
329ce430c1ad464f1927f95f114ab16fe91e4c9bstoddard id: "widget-1",
329ce430c1ad464f1927f95f114ab16fe91e4c9bstoddard label: "Parent",
329ce430c1ad464f1927f95f114ab16fe91e4c9bstoddard children: [
2fe16d53f7d596938f07b0e68f65313047028a11geoff { type: Y.ChildWidget, label: "Child One", id: "child-1" },
2fe16d53f7d596938f07b0e68f65313047028a11geoff { type: Y.ChildWidget, label: "Child Two", id: "child-2" },
2fe16d53f7d596938f07b0e68f65313047028a11geoff { type: Y.ChildWidget, label: "Child Three", id: "child-3" },
2fe16d53f7d596938f07b0e68f65313047028a11geoff { type: Y.ChildWidget, label: "Child Four", id: "child-4" }
422a2e9e48a594c7d46d62410e45651a7a994430trawick var root = new Y.RootWidget({ id: "rootwidget-1" });
422a2e9e48a594c7d46d62410e45651a7a994430trawick // Confirm that the "root" attribute is
422a2e9e48a594c7d46d62410e45651a7a994430trawick // is not presently constrained by type since the ROOT_TYPE
804768c70a799483fa88678e6e3b3f0f0a2fee77trawick // property is not yet set.
804768c70a799483fa88678e6e3b3f0f0a2fee77trawick 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");
5bd2a3a3d9e7d622546f5a3a973a9b802394ecf1jerenkrantz Y.Assert.areEqual(widget.get("root").get("id"), "rootwidget-1", "The \"root\" attribute of \"widget-1\" should return a reference to rootwidget-1");
5bd2a3a3d9e7d622546f5a3a973a9b802394ecf1jerenkrantz Y.Assert.isFalse(widget.isRoot(), "\"widget-1\" should not be considered root.");
5bd2a3a3d9e7d622546f5a3a973a9b802394ecf1jerenkrantz Y.Assert.areEqual(widget.item(0).get("depth"), 1, "The \"depth\" attribute of \"child-1\" should return 1.");
5bd2a3a3d9e7d622546f5a3a973a9b802394ecf1jerenkrantz Y.Assert.areEqual(widget.item(0).ancestor(0).get("id"), "widget-1", "The ancestor of \"child-1\" at depth 0 should be \"widget-1\"");
5bd2a3a3d9e7d622546f5a3a973a9b802394ecf1jerenkrantz Y.Assert.areEqual(widget.item(0).ancestor(-1).get("id"), "rootwidget-1", "The ancestor of \"child-1\" at depth -1 should be \"rootwidget-1\"");
5bd2a3a3d9e7d622546f5a3a973a9b802394ecf1jerenkrantz // Confirm that the root attribute will be constrained to
5bd2a3a3d9e7d622546f5a3a973a9b802394ecf1jerenkrantz // a particular type when the ROOT_TYPE is defined.
5bd2a3a3d9e7d622546f5a3a973a9b802394ecf1jerenkrantz Y.ParentWidget.prototype.ROOT_TYPE = Y.ParentWidget;
5bd2a3a3d9e7d622546f5a3a973a9b802394ecf1jerenkrantz Y.ChildWidget.prototype.ROOT_TYPE = Y.ParentWidget;
5bd2a3a3d9e7d622546f5a3a973a9b802394ecf1jerenkrantz 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");
5bd2a3a3d9e7d622546f5a3a973a9b802394ecf1jerenkrantz Y.Assert.areEqual(widget.get("root").get("id"), "widget-1", "The \"root\" attribute of \"widget-1\" should return a reference to widget-1");
5bd2a3a3d9e7d622546f5a3a973a9b802394ecf1jerenkrantz Y.Assert.isTrue(widget.isRoot(), "Calling the \"isRoot\" method on \"widget-1\" should return \"widget-1\"");
5bd2a3a3d9e7d622546f5a3a973a9b802394ecf1jerenkrantz Y.Assert.areEqual(widget.item(0).get("depth"), 0, "The \"depth\" attribute of \"child-1\" should return 0");
5bd2a3a3d9e7d622546f5a3a973a9b802394ecf1jerenkrantz 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
270a4b12c5e0e51c8ffdbe8317db257a79a5f56ajorton // So tests can be rerun
270a4b12c5e0e51c8ffdbe8317db257a79a5f56ajorton testSiblingNavigation: function () {
cc0b2a935c91a33f5bc0f13115def505d4b864e3trawick var widget = new Y.ParentWidget({
2a30bb2c6d10ba7eb726e592f090fae2bc316f55nd id: "widget-1",
2a30bb2c6d10ba7eb726e592f090fae2bc316f55nd children: [
2a30bb2c6d10ba7eb726e592f090fae2bc316f55nd { type: Y.ChildWidget, label: "Child One", id: "child-1" },
2bc1c8cb65f7b7833251e6ee4c9be636762a5081trawick { type: Y.ChildWidget, label: "Child Two", id: "child-2" },
2bc1c8cb65f7b7833251e6ee4c9be636762a5081trawick { type: Y.ChildWidget, label: "Child Three", id: "child-3" },
2bc1c8cb65f7b7833251e6ee4c9be636762a5081trawick { type: Y.ChildWidget, label: "Child Four", id: "child-4" }
270a4b12c5e0e51c8ffdbe8317db257a79a5f56ajorton Y.Assert.areEqual(widget.item(3).get("index"), 3, "The \"index\" attribute of \"child-4\" should return 3.");
270a4b12c5e0e51c8ffdbe8317db257a79a5f56ajorton Y.Assert.isUndefined(widget.item(3).next(), "\"child-4\" should have no next sibling");
270a4b12c5e0e51c8ffdbe8317db257a79a5f56ajorton 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\"");
dd9feec012ad7760f0f0dd5c12cdd72aee86d243bnicholes Y.Assert.isUndefined(widget.item(0).previous(), "\"child-1\" should have no previous sibling");
dd9feec012ad7760f0f0dd5c12cdd72aee86d243bnicholes 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\"");
cbb5a63b9436fd6d32b6679812d17e95764a095dnd testActiveDescendant: function () {
cbb5a63b9436fd6d32b6679812d17e95764a095dnd var tree = new Y.ParentWidget({
432de55307c72b09db614e14e79764ac2e6caa2arederpj id: "tree",
432de55307c72b09db614e14e79764ac2e6caa2arederpj children: [
da152944fea872835df37b7c2141648926c7c22crederpj { type: Y.ChildWidget, id: "leaf-1", label: "Leaf One" },
da152944fea872835df37b7c2141648926c7c22crederpj { type: Y.ChildWidget, id: "leaf-2", label: "Leaf Two" },
da152944fea872835df37b7c2141648926c7c22crederpj { type: Y.ParentWidget, id: "subtree", label: "Subtree", children: [
6af3206a1b2ebe14ec93368e71f09258998467b4rederpj { type: Y.ChildWidget, id: "subtree-leaf-1", label: "Subtree - Leaf One" },
6af3206a1b2ebe14ec93368e71f09258998467b4rederpj { type: Y.ChildWidget, id: "subtree-leaf-2", label: "Subtree - Leaf Two" },
34e4083fa62b3a9cc49b25b1e11691e5094ad084rederpj { type: Y.ChildWidget, id: "subtree-leaf-3", label: "Subtree - Leaf Three" },
34e4083fa62b3a9cc49b25b1e11691e5094ad084rederpj { type: Y.ChildWidget, id: "subtree-leaf-4", label: "Subtree - Leaf Four" }
1b6c93a6a669e703316455afdd1c789c2c3fa3a2rederpj tree.item(2).item(0).focus();
1b6c93a6a669e703316455afdd1c789c2c3fa3a2rederpj 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\"");
1b6c93a6a669e703316455afdd1c789c2c3fa3a2rederpj 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\"");
7a706bb27e442a89a00d736fb5a6cc3ec0713cedrederpj testUIEvents : function() {
f93e3a425ac550079682c6e4d9ecccdb2c9225fdrederpj var expectedEvents = [
f93e3a425ac550079682c6e4d9ecccdb2c9225fdrederpj "parentwidget:click",
f93e3a425ac550079682c6e4d9ecccdb2c9225fdrederpj "parentwidget:click"
f93e3a425ac550079682c6e4d9ecccdb2c9225fdrederpj actualEvents = [],
f93e3a425ac550079682c6e4d9ecccdb2c9225fdrederpj expectedChildEvents = [
2666c6e15c495cdc39b00c7bd5e3f180407dae9ejorton "childwidget:click",
2666c6e15c495cdc39b00c7bd5e3f180407dae9ejorton "childwidget:click"
2666c6e15c495cdc39b00c7bd5e3f180407dae9ejorton actualChildEvents = [];
2666c6e15c495cdc39b00c7bd5e3f180407dae9ejorton var widget = new Y.ParentWidget({
2666c6e15c495cdc39b00c7bd5e3f180407dae9ejorton id: "widget-1",
2666c6e15c495cdc39b00c7bd5e3f180407dae9ejorton children: [
2666c6e15c495cdc39b00c7bd5e3f180407dae9ejorton { type: Y.ChildWidget, label: '<span class="uitarget">Child One - Click Target</span>', id: "child-1" },
2666c6e15c495cdc39b00c7bd5e3f180407dae9ejorton { type: Y.ChildWidget, label: '<span class="uitarget">Child Two - Click Target</span>', id: "child-2" }
166ee86bb7bdcf9a89ebccee59c72064ac627dc0nd widget.on("click", function(e) {
0dd9b0cc0c1dcf7f6c4dba782a0b50f0b69f519dtrawick widget.item(0).on("click", function(e) {
0c4c708dd860d02dd784da6dc5e7001044185620stoddard widget.item(1).on("click", function(e) {
0c4c708dd860d02dd784da6dc5e7001044185620stoddard Y.Node.one("#child-1 .uitarget").simulate("click");
0c4c708dd860d02dd784da6dc5e7001044185620stoddard Y.Node.one("#child-2 .uitarget").simulate("click");
84e59981d4df2f141ac6153e06fd8371406dd23cnd Y.ArrayAssert.itemsAreEqual(expectedEvents, actualEvents, "Unexpected UI events");
84e59981d4df2f141ac6153e06fd8371406dd23cnd Y.ArrayAssert.itemsAreEqual(expectedChildEvents, actualChildEvents, "Unexpected Child UI events");
d545dd10d4e60c2ae57205017550cb48311a3ac7nd Y.Test.Runner.setName("Widget ParentChild Tests");
75c180fb45396964ad10af6444077798a470b6a3jorton var console;
75c180fb45396964ad10af6444077798a470b6a3jorton Y.one("#btnRun").set("disabled", false).on("click", function() {
75c180fb45396964ad10af6444077798a470b6a3jorton if (!console) {
75c180fb45396964ad10af6444077798a470b6a3jorton console = new Y.Console({
75c180fb45396964ad10af6444077798a470b6a3jorton id:"console",
277e05eebdd1878d86c1edc2538c94c5b42102e4nd width:"100%",
277e05eebdd1878d86c1edc2538c94c5b42102e4nd height:"90%",
277e05eebdd1878d86c1edc2538c94c5b42102e4nd verbose : false,
277e05eebdd1878d86c1edc2538c94c5b42102e4nd printTimeout: 0,
277e05eebdd1878d86c1edc2538c94c5b42102e4nd newestOnTop : false,
277e05eebdd1878d86c1edc2538c94c5b42102e4nd entryTemplate: '<pre class="{entry_class} {cat_class} {src_class}">'+
277e05eebdd1878d86c1edc2538c94c5b42102e4nd }).render();
4bf5825d6c53ba24264110d7bf774709b1b2bc78trawick <p><input type="button" value="Run Tests" id="btnRun" disabled=true></p>