| 1 | <!DOCTYPE html> |
| 2 | <html lang="en"> |
| 3 | <head> |
| 4 | <meta http-equiv="Content-type" content="text/html; charset=utf-8"> |
| 5 | <title>TabContainer DOH Test</title> |
| 6 | |
| 7 | <script type="text/javascript" src="../boilerplate.js"></script> |
| 8 | |
| 9 | <script type="text/javascript"> |
| 10 | require([ |
| 11 | "doh/runner", |
| 12 | "dojo/_base/array", |
| 13 | "dojo/aspect", |
| 14 | "dojo/dom", |
| 15 | "dojo/dom-class", |
| 16 | "dojo/dom-geometry", |
| 17 | "dojo/json", |
| 18 | "dojo/_base/lang", |
| 19 | "dojo/parser", |
| 20 | "dojo/query", |
| 21 | "dijit/focus", |
| 22 | "dijit/registry", |
| 23 | "dijit/layout/TabContainer", |
| 24 | "dijit/layout/ContentPane", |
| 25 | "dijit/tests/helpers", |
| 26 | "dojo/domReady!" |
| 27 | ], function(doh, array, aspect, dom, domClass, domGeom, json, lang, parser, query, |
| 28 | focus, registry, TabContainer, ContentPane, helpers){ |
| 29 | |
| 30 | |
| 31 | doh.register("parse", function(){ |
| 32 | return parser.parse(); |
| 33 | }); |
| 34 | |
| 35 | doh.register("creationAndDestruction", [ |
| 36 | |
| 37 | // Test that destroyRecursive removes all supporting widgets, including the list-of-tabs menu |
| 38 | // and the close menu. Also test that the second tab doesn't get selected |
| 39 | // for a split second as the TabContainer is being destroyed. |
| 40 | { |
| 41 | name: 'destroyRecursive', |
| 42 | runTest: function(t){ |
| 43 | var num = registry.length; |
| 44 | |
| 45 | var cp1 = new ContentPane({title: "test pane 1", closable: true}), |
| 46 | cp2 = new ContentPane({title: "test pane 2", href: "doc0.html"}), |
| 47 | tc = new TabContainer({ |
| 48 | id:"creationAndDestruction", |
| 49 | useMenu:true |
| 50 | }).placeAt(document.body); |
| 51 | |
| 52 | var cp2selected = false; |
| 53 | cp2.watch("selected", function(){ |
| 54 | cp2selected = true; |
| 55 | }); |
| 56 | |
| 57 | tc.addChild(cp1); |
| 58 | tc.addChild(cp2); |
| 59 | tc.startup(); |
| 60 | |
| 61 | tc.destroyRecursive(); |
| 62 | |
| 63 | t.is(registry.length, num, "registry length"); |
| 64 | t.f(cp2selected, "second pane wasn't temporarily selected"); |
| 65 | } |
| 66 | }, |
| 67 | |
| 68 | // Test that on destroyDescendants(), the second tab doesn't get selected |
| 69 | // for a split second as the TabContainer is being destroyed. |
| 70 | { |
| 71 | name: 'destroyDescendants', |
| 72 | runTest: function(t){ |
| 73 | var cp1 = new ContentPane({ |
| 74 | id: "destroyDescendants_pane1", |
| 75 | title: "test pane 1", |
| 76 | closable: true |
| 77 | }), |
| 78 | cp2 = new ContentPane({ |
| 79 | id: "destroyDescendants_pane2", |
| 80 | title: "test pane 2", |
| 81 | href: "doc0.html" |
| 82 | }), |
| 83 | tc = new TabContainer({ |
| 84 | id:"destroyDescendants", |
| 85 | useMenu:true |
| 86 | }).placeAt(document.body); |
| 87 | |
| 88 | var cp2selected = false; |
| 89 | cp2.watch("selected", function(){ |
| 90 | cp2selected = true; |
| 91 | }); |
| 92 | var downloadStarted = false; |
| 93 | cp2.on("downloadstart", function(){ |
| 94 | downloadStarted = true; |
| 95 | }); |
| 96 | |
| 97 | tc.addChild(cp1); |
| 98 | tc.addChild(cp2); |
| 99 | tc.startup(); |
| 100 | |
| 101 | tc.destroyDescendants(); |
| 102 | |
| 103 | t.f(cp2selected, "second pane wasn't temporarily selected"); |
| 104 | t.f(downloadStarted, "second pane never started downloading"); |
| 105 | t.is(undefined, tc._selectedChildWidget, "no selected child widget"); |
| 106 | } |
| 107 | }, |
| 108 | |
| 109 | // Check that tab labels for initial tabs are created. |
| 110 | { |
| 111 | name: 'checkTabLabels', |
| 112 | runTest: function(t){ |
| 113 | var tabLabels = query("#tc1 .tabLabel"); |
| 114 | t.is(4, tabLabels.length); |
| 115 | } |
| 116 | } |
| 117 | ]); |
| 118 | |
| 119 | doh.register("addingTabs", [ |
| 120 | |
| 121 | // Test that adding a pane creates new tab button. |
| 122 | { |
| 123 | name: 'add new tab', |
| 124 | runTest: function(t){ |
| 125 | var tc = registry.byId("tc1"); |
| 126 | var cp1 = new ContentPane({ |
| 127 | id: "newTab1", |
| 128 | title: "newTab1", |
| 129 | content: "newTab1 content" |
| 130 | }); |
| 131 | tc.addChild(cp1); |
| 132 | |
| 133 | var tabLabels = registry.byId("tc1").getChildren(); |
| 134 | |
| 135 | t.is(5, tabLabels.length, "there are 5 tabs"); |
| 136 | } |
| 137 | }, |
| 138 | |
| 139 | // Test that scroll buttons show up when tab buttons overflow. |
| 140 | { |
| 141 | name: 'addTabsOverflowMenu', |
| 142 | runTest: function(t){ |
| 143 | var tc = registry.byId("tc1"); |
| 144 | |
| 145 | var cp2 = new ContentPane({ |
| 146 | id: "newTab2", |
| 147 | title: "newTab2", |
| 148 | content: "newTab2 content" |
| 149 | }); |
| 150 | tc.addChild(cp2); |
| 151 | |
| 152 | var left = dom.byId("tc1_tablist_leftBtn"); |
| 153 | var right = dom.byId("tc1_tablist_rightBtn"); |
| 154 | var menu = dom.byId("tc1_tablist_menuBtn"); |
| 155 | |
| 156 | t.t(left, "verify left scroll button exists"); |
| 157 | t.t(right, "verify right scroll button exists"); |
| 158 | t.t(menu, "verify dropdown menu button exists"); |
| 159 | |
| 160 | t.t(helpers.isVisible(left), "left scroll button is displayed"); |
| 161 | t.t(helpers.isVisible(right), "right scroll button is displayed"); |
| 162 | t.t(helpers.isVisible(menu), "menu button is displayed"); |
| 163 | } |
| 164 | } |
| 165 | ]); |
| 166 | |
| 167 | doh.register("selectingTabs", [ |
| 168 | |
| 169 | // Check that tab button is scrolled into view when tab is selected, |
| 170 | // but that focus isn't changed because it's outside the tab container. |
| 171 | // Also, check that left/right scroll buttons are enabled/disabled correctly. |
| 172 | { |
| 173 | name: 'focus outside', |
| 174 | timeout: 10000, |
| 175 | runTest: function(){ |
| 176 | var d = new doh.Deferred(); |
| 177 | |
| 178 | dom.byId("inputBeforeTc1").focus(); |
| 179 | doh.is("inputBeforeTc1", focus.curNode.id, "initial focus"); |
| 180 | |
| 181 | var tc = registry.byId("tc1"); |
| 182 | |
| 183 | var cp = registry.byId("newTab2"); |
| 184 | tc.selectChild(cp); |
| 185 | |
| 186 | setTimeout(d.getTestErrback(function(){ |
| 187 | doh.is("inputBeforeTc1", focus.curNode.id, "focus after selectChild()"); |
| 188 | |
| 189 | var cpLeft = registry.byId("tc1_tablist_leftBtn"); |
| 190 | var left = domGeom.position(cpLeft.domNode).x + domGeom.position(cpLeft.domNode).w; |
| 191 | |
| 192 | var cpRight = registry.byId("tc1_tablist_rightBtn"); |
| 193 | var right = domGeom.position(cpRight.domNode).x; |
| 194 | |
| 195 | var tab = registry.byId("tc1_tablist_newTab1"); |
| 196 | var tabLeft = domGeom.position(tab.domNode).x; |
| 197 | var tabRight = domGeom.position(tab.domNode).x + domGeom.position(tab.domNode).w; |
| 198 | |
| 199 | doh.t(tabLeft > left && tabRight < right, "chosen tab visible"); |
| 200 | |
| 201 | doh.f(cpLeft.get("disabled"), "left scroll button enabled"); |
| 202 | doh.t(cpRight.get("disabled"), "right scroll button disabled"); |
| 203 | |
| 204 | tc.selectChild("cpTitle"); |
| 205 | |
| 206 | setTimeout(d.getTestCallback(function(){ |
| 207 | doh.t(cpLeft.get("disabled"), "left scroll button disabled"); |
| 208 | doh.f(cpRight.get("disabled"), "right scroll button enabled"); |
| 209 | doh.is("inputBeforeTc1", focus.curNode.id); |
| 210 | }), 1000); |
| 211 | }), 1000); |
| 212 | |
| 213 | return d; |
| 214 | } |
| 215 | }, |
| 216 | |
| 217 | // Test what happens when focus is inside tab1 and you call selectChild() to select tab2. |
| 218 | // In this case focus should be put on the tab2's label, so that it isn't in a hidden pane. |
| 219 | { |
| 220 | name: 'focus inside', |
| 221 | timeout: 10000, |
| 222 | runTest: function(){ |
| 223 | var d = new doh.Deferred(); |
| 224 | |
| 225 | // ... if previous test was successful, cpTitle tab is selected ... |
| 226 | |
| 227 | dom.byId("inputInsideCpTitle").focus(); |
| 228 | doh.is("inputInsideCpTitle", focus.curNode.id, "initial focus"); |
| 229 | |
| 230 | var tc = registry.byId("tc1"); |
| 231 | |
| 232 | // First select a child where the tab label is already visible. |
| 233 | // The specified pane should be selected and the associated tab label should be focused. |
| 234 | tc.selectChild("t2"); |
| 235 | doh.is("tc1_tablist_t2", focus.curNode.id, "focus after selectChild(t2)"); |
| 236 | |
| 237 | // Next, select a pane that requires scrolling the tab labels. |
| 238 | var cp = registry.byId("newTab2"); |
| 239 | tc.selectChild(cp); |
| 240 | |
| 241 | setTimeout(d.getTestErrback(function(){ |
| 242 | doh.is("tc1_tablist_newTab2", focus.curNode.id, "focus after selectChild(newTab2)"); |
| 243 | |
| 244 | var cpLeft = registry.byId("tc1_tablist_leftBtn"); |
| 245 | var left = domGeom.position(cpLeft.domNode).x + domGeom.position(cpLeft.domNode).w; |
| 246 | |
| 247 | var cpRight = registry.byId("tc1_tablist_rightBtn"); |
| 248 | var right = domGeom.position(cpRight.domNode).x; |
| 249 | |
| 250 | var tab = registry.byId("tc1_tablist_newTab1"); |
| 251 | var tabLeft = domGeom.position(tab.domNode).x; |
| 252 | var tabRight = domGeom.position(tab.domNode).x + domGeom.position(tab.domNode).w; |
| 253 | |
| 254 | doh.t(tabLeft > left && tabRight < right, "chosen tab visible"); |
| 255 | |
| 256 | doh.f(cpLeft.get("disabled"), "left scroll button enabled"); |
| 257 | doh.t(cpRight.get("disabled"), "right scroll button disabled"); |
| 258 | |
| 259 | tc.selectChild("cpTitle"); |
| 260 | |
| 261 | setTimeout(d.getTestCallback(function(){ |
| 262 | doh.t(cpLeft.get("disabled"), "left scroll button disabled"); |
| 263 | doh.f(cpRight.get("disabled"), "right scroll button enabled"); |
| 264 | doh.is("tc1_tablist_cpTitle", focus.curNode.id, "focus after selectChild(cpTitle)"); |
| 265 | }), 1000); |
| 266 | }), 1000); |
| 267 | |
| 268 | return d; |
| 269 | } |
| 270 | }, |
| 271 | |
| 272 | // Test that scroll position is preserved when returning to a tab. |
| 273 | { |
| 274 | name: 'panel scroll', |
| 275 | timeout: 10000, |
| 276 | runTest: function(){ |
| 277 | var d = new doh.Deferred(); |
| 278 | |
| 279 | var tc = registry.byId("tc1"); |
| 280 | var cp = registry.byId("t4"); |
| 281 | tc.selectChild(cp); |
| 282 | |
| 283 | setTimeout(d.getTestErrback(function(){ |
| 284 | cp.domNode.scrollTop = 10000; // scroll to the bottom |
| 285 | |
| 286 | tc.selectChild("t3"); // switch to another tab |
| 287 | |
| 288 | setTimeout(d.getTestErrback(function(){ |
| 289 | tc.selectChild(cp); // and then switch back |
| 290 | |
| 291 | setTimeout(d.getTestCallback(function(){ |
| 292 | doh.t(cp.domNode.scrollTop > 0, "still scrolled"); |
| 293 | }), 1000); |
| 294 | }), 1000); |
| 295 | }), 1000); |
| 296 | |
| 297 | return d; |
| 298 | } |
| 299 | } |
| 300 | ]); |
| 301 | |
| 302 | doh.register("icons", [ |
| 303 | { |
| 304 | name: "initialIcon", |
| 305 | runTest: function(t){ |
| 306 | var cp = registry.byId("cp4"); |
| 307 | |
| 308 | t.is('tab1', innerText(cp.controlButton.containerNode), "tab label"); |
| 309 | t.is('plusIcon', cp.controlButton.iconClass, "tab icon"); |
| 310 | } |
| 311 | }, |
| 312 | { |
| 313 | name: "changeIcon", |
| 314 | runTest: function(t){ |
| 315 | var cp = registry.byId("cp4"); |
| 316 | |
| 317 | cp.set({ |
| 318 | "title": "note", |
| 319 | "iconClass": "noteIcon" |
| 320 | }); |
| 321 | |
| 322 | t.is('note', innerText(cp.controlButton.containerNode), "the tab's label has changed"); |
| 323 | t.is('noteIcon', cp.controlButton.iconClass, "new icon is displayed in tab"); |
| 324 | } |
| 325 | }, |
| 326 | { |
| 327 | name: "noTitle", |
| 328 | runTest: function(t){ |
| 329 | var cp = registry.byId("cp7"); |
| 330 | t.f(cp.controlButton.showLabel, "an icon exists, but there is no text label"); |
| 331 | } |
| 332 | } |
| 333 | ]); |
| 334 | |
| 335 | doh.register("changeTabName", [ |
| 336 | { |
| 337 | name: 'changeName', |
| 338 | runTest: function(t){ |
| 339 | var cp = registry.byId('cpTitle'); |
| 340 | cp.set('title', 'newTitle'); |
| 341 | |
| 342 | var title = query("#tc1_tablist_cpTitle")[0]; |
| 343 | |
| 344 | t.is('newTitle', innerText(title), "the tab's text label has changed"); |
| 345 | } |
| 346 | } |
| 347 | ]); |
| 348 | |
| 349 | doh.register("deletingTabs", [ |
| 350 | |
| 351 | // Check that deleting a pane removes the tab button. |
| 352 | { |
| 353 | name: 'deleteTab', |
| 354 | runTest: function(t){ |
| 355 | var tc1 = registry.byId("tc1"); |
| 356 | var cp = registry.byId("cpTitle"); |
| 357 | |
| 358 | |
| 359 | // track resizes to cp, removing it from tc1 shouldn't cause a resize call |
| 360 | var cpResizes = 0; |
| 361 | aspect.after(cp, "resize", function(){ |
| 362 | cpResizes++; |
| 363 | }, true); |
| 364 | |
| 365 | t.t(domClass.contains(cp.domNode, 'dijitTabPane'), 'children have correct CSS class'); |
| 366 | |
| 367 | tc1.removeChild(cp); |
| 368 | |
| 369 | t.f(domClass.contains(cp.domNode, 'dijitTabPane'), 'children have CSS class removed upon removal'); |
| 370 | |
| 371 | var childPanes = tc1.getChildren(); |
| 372 | |
| 373 | t.is(5, childPanes.length, "verify there are now only 4 tabs instead of 5"); |
| 374 | t.t(cp.domNode, "verify that the deleted tab's content pane still exists on the page"); |
| 375 | |
| 376 | var label = dom.byId("#tc1_tablist_cpTitle"); |
| 377 | t.f(label, "verify that deleted tab's label does not exist"); |
| 378 | |
| 379 | t.is(0, cpResizes, "no resize"); |
| 380 | } |
| 381 | }, |
| 382 | |
| 383 | // Check that scroll buttons disappear when no longer needed. |
| 384 | { |
| 385 | name: 'removedOverflowMenu', |
| 386 | runTest: function(t){ |
| 387 | var tc = registry.byId("tc3"); |
| 388 | |
| 389 | var cp = registry.byId('cp10'); |
| 390 | tc.removeChild(cp); |
| 391 | cp = registry.byId('cp9'); |
| 392 | tc.removeChild(cp); |
| 393 | cp = registry.byId('cp8'); |
| 394 | tc.removeChild(cp); |
| 395 | cp = registry.byId('cp7'); |
| 396 | tc.removeChild(cp); |
| 397 | |
| 398 | var left = registry.byId("tc3_tablist_leftBtn").domNode; |
| 399 | var right = registry.byId("tc3_tablist_rightBtn").domNode; |
| 400 | var menu = registry.byId("tc3_tablist_menuBtn").domNode; |
| 401 | |
| 402 | t.t(helpers.isHidden(left), "left scroll is hidden"); |
| 403 | t.t(helpers.isHidden(right), "right scroll is hidden"); |
| 404 | t.t(helpers.isHidden(menu), "menu is hidden"); |
| 405 | } |
| 406 | } |
| 407 | ]); |
| 408 | |
| 409 | doh.register("closableTabs", [ |
| 410 | { |
| 411 | name: "closeTab", |
| 412 | runTest: function(t){ |
| 413 | var cp = registry.byId("cp6"); |
| 414 | var cp2 = registry.byId("cp5"); |
| 415 | |
| 416 | t.t(cp.controlButton.closeButton, "close button is displayed"); |
| 417 | t.f(cp2.controlButton.closeButton, "close button is not displayed"); |
| 418 | } |
| 419 | } |
| 420 | ]); |
| 421 | |
| 422 | doh.register("menu", { |
| 423 | name: "menu", |
| 424 | runTest: function(){ |
| 425 | var tc1 = registry.byId("tc1"), |
| 426 | children = tc1.getChildren(); |
| 427 | |
| 428 | // add an icon and change the title just for testing that the icon and label appear in the menu |
| 429 | children[0].set({ |
| 430 | title: "new title", |
| 431 | iconClass: "noteIcon" |
| 432 | }); |
| 433 | |
| 434 | var menuBtn = registry.byId("tc1_tablist_menuBtn"); |
| 435 | menuBtn.toggleDropDown(); |
| 436 | |
| 437 | var menu = registry.byId("tc1_menu"); |
| 438 | doh.t(helpers.isVisible(menu), "menu exists and is visible"); |
| 439 | doh.is(menu.getChildren().length, children.length, "# of menu children"); |
| 440 | doh.is("new title", innerText(menu.getChildren()[0].containerNode)); |
| 441 | doh.is("noteIcon", menu.getChildren()[0].iconClass); |
| 442 | }, |
| 443 | tearDown: function(){ |
| 444 | var tc1 = registry.byId("tc1"), |
| 445 | children = tc1.getChildren(); |
| 446 | |
| 447 | children[0].set({ |
| 448 | title: "old title", |
| 449 | iconClass: "" |
| 450 | }); |
| 451 | |
| 452 | var menuBtn = registry.byId("tc1_tablist_menuBtn"); |
| 453 | menuBtn.closeDropDown(); |
| 454 | } |
| 455 | }); |
| 456 | |
| 457 | doh.register("layoutTests", [ |
| 458 | { |
| 459 | name: "tabPosition", |
| 460 | runTest: function(t){ |
| 461 | // top tabs above content |
| 462 | var topTabs = dom.byId("tc1_tablist"), |
| 463 | topContent = query(".dijitTabPaneWrapper", "tc1")[0], |
| 464 | topTabsPos = domGeom.position(topTabs), |
| 465 | topContentPos = domGeom.position(topContent); |
| 466 | t.t(topTabsPos.y + topTabsPos.h <= topContentPos.y, "top tabs above content " + |
| 467 | json.stringify(topTabsPos) + json.stringify(topContentPos)); |
| 468 | |
| 469 | // left tabs to left of content |
| 470 | var leftTabs = dom.byId("leftTabs_tablist"), |
| 471 | leftContent = query(".dijitTabPaneWrapper", "leftTabs")[0], |
| 472 | leftTabsPos = domGeom.position(leftTabs), |
| 473 | leftContentPos = domGeom.position(leftContent); |
| 474 | t.t(leftTabsPos.x + Math.floor(leftTabsPos.w) <= leftContentPos.x, "left tabs before content " + |
| 475 | json.stringify(leftTabsPos) + json.stringify(leftContentPos)); |
| 476 | |
| 477 | // right tabs to right of content |
| 478 | var rightTabs = dom.byId("rightTabs_tablist"), |
| 479 | rightContent = query(".dijitTabPaneWrapper", "rightTabs")[0], |
| 480 | rightTabsPos = domGeom.position(rightTabs), |
| 481 | rightContentPos = domGeom.position(rightContent); |
| 482 | t.t(rightTabsPos.x >= rightContentPos.x + rightContentPos.w, "right tabs after content " + |
| 483 | json.stringify(rightTabsPos) + json.stringify(rightContentPos)); |
| 484 | |
| 485 | // bottom tabs below content |
| 486 | var bottomTabs = dom.byId("bottomTabs_tablist"), |
| 487 | bottomContent = query(".dijitTabPaneWrapper", "bottomTabs")[0], |
| 488 | bottomTabsPos = domGeom.position(bottomTabs), |
| 489 | bottomContentPos = domGeom.position(bottomContent); |
| 490 | t.t(bottomTabsPos.y >= bottomContentPos.y + bottomContentPos.h, "bottom tabs below content " + |
| 491 | json.stringify(bottomTabsPos) + json.stringify(bottomContentPos)); |
| 492 | } |
| 493 | }, |
| 494 | { |
| 495 | name: "nested", |
| 496 | runTest: function(t){ |
| 497 | var parent = registry.byId("tcNestedParent"), |
| 498 | child = registry.byId("tcNestedChild"); |
| 499 | |
| 500 | t.f(parent.nested, "parent TabContainer is not nested"); |
| 501 | |
| 502 | var children = parent.getChildren(); |
| 503 | t.is(2, children.length, "parent TabContainer has multiple children"); |
| 504 | |
| 505 | t.t(children[1].nested, "second child of parent TabContainer has nested tabs"); |
| 506 | t.t(domClass.contains("tcNestedChild_tablist", "dijitTabContainerTabListNested"), "nested CSS applied"); |
| 507 | |
| 508 | // test that when TabButtons overflow to 2 rows, the content area is reduced |
| 509 | parent.selectChild(registry.byId("tcNestedChild")); |
| 510 | var content = query(".dijitTabPaneWrapper", "tcNestedChild")[0], |
| 511 | height0 = domGeom.position(content).h; |
| 512 | |
| 513 | var newGrandchildren = []; |
| 514 | for(var i=0; i<10; i++){ |
| 515 | var gc = new ContentPane({ |
| 516 | title: "additional child #" + i, |
| 517 | content: "hello world " + i |
| 518 | }); |
| 519 | newGrandchildren.push(gc); |
| 520 | child.addChild(gc); |
| 521 | } |
| 522 | var height1 = domGeom.position(content).h; |
| 523 | doh.t(height1 < height0, "content area size reduced ", height1, height0); |
| 524 | |
| 525 | // and that size increases back when children are removed |
| 526 | array.forEach(newGrandchildren, lang.hitch(child, "removeChild")); |
| 527 | var height2 = domGeom.position(content).h; |
| 528 | doh.is(height0, height2, "after deleting extra children height restored to original"); |
| 529 | |
| 530 | // Setting the title of nested TabContainer shouldn't make a tooltip over it |
| 531 | doh.f(child.domNode.hasAttribute && child.domNode.hasAttribute("title"), "child.hasAttribute(title) before"); |
| 532 | child.set("title", "Nested new title"); |
| 533 | doh.f(child.domNode.hasAttribute && child.domNode.hasAttribute("title"), "child.hasAttribute(title) after"); |
| 534 | } |
| 535 | }, |
| 536 | { |
| 537 | name: "doLayoutFalse", |
| 538 | runTest: function(t){ |
| 539 | var tc = registry.byId("tcNoLayout"); |
| 540 | var cps = tc.getChildren(); |
| 541 | |
| 542 | tc.selectChild(cps[0]); |
| 543 | var height1 = tc.domNode.offsetHeight; |
| 544 | tc.selectChild(cps[1]); |
| 545 | var height2 = tc.domNode.offsetHeight; |
| 546 | tc.selectChild(cps[2]); |
| 547 | var height3 = tc.domNode.offsetHeight; |
| 548 | |
| 549 | t.t(height1 < height2, "height 1 < height 2" + height1 + " < " + height2); |
| 550 | t.t(height2 < height3, "height 2 < height 3" + height2 + " < " + height3); |
| 551 | } |
| 552 | }, |
| 553 | { |
| 554 | name: "doLayoutTrue", |
| 555 | runTest: function(t){ |
| 556 | var tc = registry.byId("tc3"); |
| 557 | var cps = tc.getChildren(); |
| 558 | |
| 559 | tc.selectChild(cps[0]); |
| 560 | var height1 = tc.domNode.offsetHeight; |
| 561 | tc.selectChild(cps[1]); |
| 562 | var height2 = tc.domNode.offsetHeight; |
| 563 | tc.selectChild(cps[2]); |
| 564 | var height3 = tc.domNode.offsetHeight; |
| 565 | |
| 566 | t.is(height1, height2); |
| 567 | t.is(height2, height3); |
| 568 | t.t(height1 > 10, "make sure height measurement is giving something reasonable"); |
| 569 | } |
| 570 | } |
| 571 | |
| 572 | ]); |
| 573 | |
| 574 | var tabId = 1; |
| 575 | function addTab(tc){ |
| 576 | // summary: |
| 577 | // Add a tab to specified TabContainer. |
| 578 | var cp = new ContentPane({ |
| 579 | title: 'Tab' + tabId, |
| 580 | content: "Contents of Tab " + tabId++ |
| 581 | }); |
| 582 | tc.addChild(cp); |
| 583 | } |
| 584 | |
| 585 | doh.register("empty tab container",[ |
| 586 | function createEmptyTabContainer(){ |
| 587 | var emptyTC = new TabContainer({id:"emptyTC", style:'height:200px;width:500px;'}); |
| 588 | document.body.appendChild(emptyTC.domNode); |
| 589 | emptyTC.startup(); |
| 590 | |
| 591 | var children = emptyTC.getChildren(); |
| 592 | doh.is(0, children.length); |
| 593 | doh.t(helpers.isVisible(emptyTC)); |
| 594 | |
| 595 | var pos = domGeom.position(emptyTC.domNode); |
| 596 | var heightDiff = 200 - pos.h; |
| 597 | var widthDiff = 500 - pos.w; |
| 598 | doh.t(-0.01 < heightDiff && heightDiff < 0.01); |
| 599 | doh.t(-0.01 < widthDiff && widthDiff < 0.01); |
| 600 | }, |
| 601 | function addTabToEmptyTabContainer(){ |
| 602 | var tc = registry.byId("emptyTC"); |
| 603 | addTab(tc); |
| 604 | |
| 605 | var children = tc.getChildren(); |
| 606 | doh.is(1, children.length); |
| 607 | doh.is("Tab1", children[0].title); |
| 608 | doh.is("Contents of Tab 1", tc.selectedChildWidget.domNode.innerHTML); |
| 609 | |
| 610 | doh.t(helpers.isVisible(tc.tablist.containerNode.childNodes[0])); |
| 611 | }, |
| 612 | function add2ndTabToEmptyTabContainer(){ |
| 613 | var tc = registry.byId("emptyTC"); |
| 614 | addTab(tc); |
| 615 | tc.selectChild(tc.getChildren()[1]); |
| 616 | |
| 617 | var children = tc.getChildren(); |
| 618 | doh.is(2, children.length); |
| 619 | doh.is("Tab2", children[1].title); |
| 620 | doh.is("Contents of Tab 2", tc.selectedChildWidget.domNode.innerHTML); |
| 621 | |
| 622 | doh.t(helpers.isVisible(tc.tablist.containerNode.childNodes[1])); |
| 623 | }, |
| 624 | function remove2ndTabToEmptyTabContainer(){ |
| 625 | var tc = registry.byId("emptyTC"); |
| 626 | tc.removeChild(tc.getChildren()[1]); |
| 627 | |
| 628 | var children = tc.getChildren(); |
| 629 | doh.is(1, children.length); |
| 630 | doh.is("Tab1", children[0].title); |
| 631 | doh.is("Contents of Tab 1", tc.selectedChildWidget.domNode.innerHTML); |
| 632 | } |
| 633 | ]); |
| 634 | |
| 635 | // Further testing for tab label scrolling. Also tested in "selectingTabs" section. |
| 636 | doh.register("tab label scrolling", [ |
| 637 | function initialScroll(){ |
| 638 | // Make sure that tab labels are scrolled so that selected tab visible. |
| 639 | var tcPos = domGeom.position("scroll"), |
| 640 | labelPos = domGeom.position("scroll_tablist_nine"); |
| 641 | doh.t(tcPos.x < labelPos.x, "tcPos.x (" + tcPos.x + ") < labelPos.x (" + labelPos.x + ")"); |
| 642 | doh.t(tcPos.x + tcPos.w > labelPos.x + labelPos.w, |
| 643 | "tcPos.x (" + tcPos.x + ") + tcPos.w (" + tcPos.w + |
| 644 | ") < labelPos.x " + labelPos.x + " + labelPos.w + (" + labelPos.w + ")"); |
| 645 | }, |
| 646 | function selectATab(){ |
| 647 | // Make sure that tab labels are scrolled so that selected tab visible |
| 648 | var d = new doh.Deferred(); |
| 649 | var tc = registry.byId("scroll"); |
| 650 | tc.selectChild(registry.byId("one")); |
| 651 | setTimeout(d.getTestCallback(function(){ |
| 652 | var tcPos = domGeom.position("scroll"), |
| 653 | labelPos = domGeom.position("scroll_tablist_one"); |
| 654 | doh.t(tcPos.x < labelPos.x, "tcPos.x (" + tcPos.x + ") < labelPos.x (" + labelPos.x + ")"); |
| 655 | doh.t(tcPos.x + tcPos.w > labelPos.x + labelPos.w, |
| 656 | "tcPos.x (" + tcPos.x + ") + tcPos.w (" + tcPos.w + |
| 657 | ") < labelPos.x " + labelPos.x + " + labelPos.w + (" + labelPos.w + ")"); |
| 658 | }), 500); |
| 659 | |
| 660 | return d; |
| 661 | } |
| 662 | ]); |
| 663 | |
| 664 | doh.run(); |
| 665 | }); |
| 666 | </script> |
| 667 | |
| 668 | </head> |
| 669 | <body class="claro" role="main"> |
| 670 | |
| 671 | <h1 class="testTitle">Dijit layout.TabContainer DOH tests</h1> |
| 672 | |
| 673 | <input id="inputBeforeTc1" value="for focus testing"> |
| 674 | <div id="tc1" data-dojo-type="dijit/layout/TabContainer" data-dojo-props='style:"width: 300px; height: 100px;","aria-label":"my super label" '> |
| 675 | <div id="cpTitle" data-dojo-type="dijit/layout/ContentPane" data-dojo-props='title:"tab1", selected:true'> |
| 676 | Lorem ipsum and all around... |
| 677 | <input id="inputInsideCpTitle" value="for focus testing"> |
| 678 | </div> |
| 679 | <div id="t2" data-dojo-type="dijit/layout/ContentPane" data-dojo-props='title:"tab2"'> |
| 680 | Lorem ipsum and all around - second... |
| 681 | </div> |
| 682 | <div id="t3" data-dojo-type="dijit/layout/ContentPane" data-dojo-props='title:"tab3", closable:true'> |
| 683 | Lorem ipsum and all around - third... |
| 684 | </div> |
| 685 | <div id="t4" data-dojo-type="dijit/layout/ContentPane" data-dojo-props='title:"tab4", closable:true'> |
| 686 | <p> |
| 687 | Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean |
| 688 | semper sagittis velit. Cras in mi. Duis porta mauris ut ligula. Proin |
| 689 | porta rutrum lacus. Etiam consequat scelerisque quam. Nulla facilisi. |
| 690 | Maecenas luctus venenatis nulla. In sit amet dui non mi semper iaculis. |
| 691 | Sed molestie tortor at ipsum. Morbi dictum rutrum magna. Sed vitae |
| 692 | risus. |
| 693 | </p> |
| 694 | <p> |
| 695 | Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean |
| 696 | semper sagittis velit. Cras in mi. Duis porta mauris ut ligula. Proin |
| 697 | porta rutrum lacus. Etiam consequat scelerisque quam. Nulla facilisi. |
| 698 | Maecenas luctus venenatis nulla. In sit amet dui non mi semper iaculis. |
| 699 | Sed molestie tortor at ipsum. Morbi dictum rutrum magna. Sed vitae |
| 700 | risus. |
| 701 | </p> |
| 702 | <p> |
| 703 | Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean |
| 704 | semper sagittis velit. Cras in mi. Duis porta mauris ut ligula. Proin |
| 705 | porta rutrum lacus. Etiam consequat scelerisque quam. Nulla facilisi. |
| 706 | Maecenas luctus venenatis nulla. In sit amet dui non mi semper iaculis. |
| 707 | Sed molestie tortor at ipsum. Morbi dictum rutrum magna. Sed vitae |
| 708 | risus. |
| 709 | </p> |
| 710 | <p> |
| 711 | Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean |
| 712 | semper sagittis velit. Cras in mi. Duis porta mauris ut ligula. Proin |
| 713 | porta rutrum lacus. Etiam consequat scelerisque quam. Nulla facilisi. |
| 714 | Maecenas luctus venenatis nulla. In sit amet dui non mi semper iaculis. |
| 715 | Sed molestie tortor at ipsum. Morbi dictum rutrum magna. Sed vitae |
| 716 | risus. |
| 717 | </p> |
| 718 | </div> |
| 719 | </div> |
| 720 | |
| 721 | <div id="tc3" data-dojo-type="dijit/layout/TabContainer" data-dojo-props='style:"width: 300px; height: 100px;" '> |
| 722 | <div id="cp4" data-dojo-type="dijit/layout/ContentPane" data-dojo-props='title:"tab1", selected:true, iconClass:"plusIcon"'> |
| 723 | Lorem ipsum and all around... |
| 724 | </div> |
| 725 | <div id="cp5" data-dojo-type="dijit/layout/ContentPane" data-dojo-props='title:"tab2"'> |
| 726 | Lorem ipsum and all around - last... |
| 727 | <br /> |
| 728 | <br /> |
| 729 | <br /> |
| 730 | Hmmm even more expanding tabs...... |
| 731 | </div> |
| 732 | <div id="cp6" data-dojo-type="dijit/layout/ContentPane" data-dojo-props='title:"tab3", closable:true'> |
| 733 | Lorem ipsum and all around - last... |
| 734 | </div> |
| 735 | <div id="cp7" data-dojo-type="dijit/layout/ContentPane" data-dojo-props='title:"plus", closable:true, iconClass:"plusIcon", showTitle:false'> |
| 736 | Lorem ipsum and all around - last... |
| 737 | </div> |
| 738 | <div id="cp8" data-dojo-type="dijit/layout/ContentPane" data-dojo-props='title:"tab4", closable:true'> |
| 739 | Lorem ipsum and all around - last... |
| 740 | </div> |
| 741 | <div id="cp9" data-dojo-type="dijit/layout/ContentPane" data-dojo-props='title:"tab5", closable:true'> |
| 742 | Lorem ipsum and all around - last... |
| 743 | </div> |
| 744 | <div id="cp10" data-dojo-type="dijit/layout/ContentPane" data-dojo-props='title:"tab6", closable:true'> |
| 745 | Lorem ipsum and all around - last... |
| 746 | </div> |
| 747 | </div> |
| 748 | |
| 749 | <div id="tcNestedParent" data-dojo-type="dijit/layout/TabContainer" data-dojo-props='style:"width: 400px; height: 300px;" '> |
| 750 | <div id="tcNestedChild" data-dojo-type="dijit/layout/TabContainer" data-dojo-props='title:"Tab 1", nested:true '> |
| 751 | <div data-dojo-type="dijit/layout/ContentPane" data-dojo-props='title:"My first inner tab", selected:true'> |
| 752 | Lorem ipsum and all around... |
| 753 | </div> |
| 754 | <div data-dojo-type="dijit/layout/ContentPane" data-dojo-props='title:"My second inner tab"'> |
| 755 | Lorem ipsum and all around - second... |
| 756 | </div> |
| 757 | <div data-dojo-type="dijit/layout/ContentPane" data-dojo-props='title:"My last inner tab"'> |
| 758 | Lorem ipsum and all around - last... |
| 759 | </div> |
| 760 | </div> |
| 761 | <div data-dojo-type="dijit/layout/TabContainer" data-dojo-props='title:"Tab 2", nested:true'> |
| 762 | <div data-dojo-type="dijit/layout/ContentPane" data-dojo-props='title:"My first inner tab", selected:true'> |
| 763 | Lorem ipsum and all around... |
| 764 | </div> |
| 765 | <div data-dojo-type="dijit/layout/ContentPane" data-dojo-props='title:"My second inner tab"'> |
| 766 | Lorem ipsum and all around - second... |
| 767 | </div> |
| 768 | <div data-dojo-type="dijit/layout/ContentPane" data-dojo-props='title:"My last inner tab"'> |
| 769 | Lorem ipsum and all around - last... |
| 770 | </div> |
| 771 | </div> |
| 772 | </div> |
| 773 | |
| 774 | <div id="tcNoLayout" data-dojo-type="dijit/layout/TabContainer" data-dojo-props='style:"width: 100%;", doLayout:false'> |
| 775 | <div data-dojo-type="dijit/layout/ContentPane" data-dojo-props='title:"My first tab", selected:true'> |
| 776 | Lorem ipsum and all around... |
| 777 | </div> |
| 778 | <div data-dojo-type="dijit/layout/ContentPane" data-dojo-props='title:"My second tab", closable:true'> |
| 779 | Lorem ipsum and all around - second... |
| 780 | <br /> |
| 781 | Hmmm expanding tabs...... |
| 782 | </div> |
| 783 | <div data-dojo-type="dijit/layout/ContentPane" data-dojo-props='title:"My last tab"'> |
| 784 | Lorem ipsum and all around - last... |
| 785 | <br /> |
| 786 | <br /> |
| 787 | <br /> |
| 788 | Hmmm even more expanding tabs...... |
| 789 | </div> |
| 790 | </div> |
| 791 | <br /> |
| 792 | |
| 793 | <div id="leftTabs" data-dojo-type="dijit/layout/TabContainer" data-dojo-props='style:"width: 500px; height: 200px;", tabPosition:"left-h"'> |
| 794 | <div data-dojo-type="dijit/layout/ContentPane" data-dojo-props='title:"My first tab", selected:true'> |
| 795 | Left tabs |
| 796 | </div> |
| 797 | <div data-dojo-type="dijit/layout/ContentPane" data-dojo-props='title:"My second tab", closable:true'> |
| 798 | Lorem ipsum and all around - second... |
| 799 | </div> |
| 800 | <div data-dojo-type="dijit/layout/ContentPane" data-dojo-props='title:"My last tab"'> |
| 801 | Lorem ipsum and all around - last... |
| 802 | </div> |
| 803 | </div> |
| 804 | <br /> |
| 805 | |
| 806 | <div id="rightTabs" data-dojo-type="dijit/layout/TabContainer" data-dojo-props='style:"width: 500px; height: 200px;", tabPosition:"right-h"'> |
| 807 | <div data-dojo-type="dijit/layout/ContentPane" data-dojo-props='title:"My first tab", selected:true'> |
| 808 | Right tabs |
| 809 | </div> |
| 810 | <div data-dojo-type="dijit/layout/ContentPane" data-dojo-props='title:"My second tab", closable:true'> |
| 811 | Lorem ipsum and all around - second... |
| 812 | </div> |
| 813 | <div data-dojo-type="dijit/layout/ContentPane" data-dojo-props='title:"My last tab"'> |
| 814 | Lorem ipsum and all around - last... |
| 815 | </div> |
| 816 | </div> |
| 817 | <br /> |
| 818 | |
| 819 | <div id="bottomTabs" data-dojo-type="dijit/layout/TabContainer" data-dojo-props='style:"width: 500px; height: 200px;", tabPosition:"bottom"'> |
| 820 | <div data-dojo-type="dijit/layout/ContentPane" data-dojo-props='title:"My first tab", selected:true'> |
| 821 | Bottom tabs |
| 822 | </div> |
| 823 | <div data-dojo-type="dijit/layout/ContentPane" data-dojo-props='title:"My second tab", closable:true'> |
| 824 | Lorem ipsum and all around - second... |
| 825 | </div> |
| 826 | <div data-dojo-type="dijit/layout/ContentPane" data-dojo-props='title:"My last tab"'> |
| 827 | Lorem ipsum and all around - last... |
| 828 | </div> |
| 829 | </div> |
| 830 | |
| 831 | <div id="scroll" data-dojo-type="dijit/layout/TabContainer" data-dojo-id="scroll" style="width: 300px; height:200px;"> |
| 832 | <div data-dojo-type="dijit/layout/ContentPane" title="One" data-dojo-id="one" id="one">One</div> |
| 833 | <div data-dojo-type="dijit/layout/ContentPane" title="Two" data-dojo-id="two" id="two">Two</div> |
| 834 | <div data-dojo-type="dijit/layout/ContentPane" title="Three" data-dojo-id="three" id="three">Three</div> |
| 835 | <div data-dojo-type="dijit/layout/ContentPane" title="Four" data-dojo-id="four" id="four">Four</div> |
| 836 | <div data-dojo-type="dijit/layout/ContentPane" title="Five" data-dojo-id="five" id="five">Five</div> |
| 837 | <div data-dojo-type="dijit/layout/ContentPane" title="Six" data-dojo-id="six" id="six">Six</div> |
| 838 | <div data-dojo-type="dijit/layout/ContentPane" title="Seven" data-dojo-id="seven" id="seven">Seven</div> |
| 839 | <div data-dojo-type="dijit/layout/ContentPane" title="Eight" data-dojo-id="eight" id="eight">Eight</div> |
| 840 | <div data-dojo-type="dijit/layout/ContentPane" selected="true" title="Nine" data-dojo-id="nine" id="nine">Nine</div> |
| 841 | </div> |
| 842 | |
| 843 | </body> |
| 844 | </html> |