1
0

bootstrap-tab.js 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. $(function () {
  2. module("bootstrap-tabs")
  3. test("should provide no conflict", function () {
  4. var tab = $.fn.tab.noConflict()
  5. ok(!$.fn.tab, 'tab was set back to undefined (org value)')
  6. $.fn.tab = tab
  7. })
  8. test("should be defined on jquery object", function () {
  9. ok($(document.body).tab, 'tabs method is defined')
  10. })
  11. test("should return element", function () {
  12. ok($(document.body).tab()[0] == document.body, 'document.body returned')
  13. })
  14. test("should activate element by tab id", function () {
  15. var tabsHTML =
  16. '<ul class="tabs">'
  17. + '<li><a href="#home">Home</a></li>'
  18. + '<li><a href="#profile">Profile</a></li>'
  19. + '</ul>'
  20. $('<ul><li id="home"></li><li id="profile"></li></ul>').appendTo("#qunit-fixture")
  21. $(tabsHTML).find('li:last a').tab('show')
  22. equals($("#qunit-fixture").find('.active').attr('id'), "profile")
  23. $(tabsHTML).find('li:first a').tab('show')
  24. equals($("#qunit-fixture").find('.active').attr('id'), "home")
  25. })
  26. test("should activate element by tab id", function () {
  27. var pillsHTML =
  28. '<ul class="pills">'
  29. + '<li><a href="#home">Home</a></li>'
  30. + '<li><a href="#profile">Profile</a></li>'
  31. + '</ul>'
  32. $('<ul><li id="home"></li><li id="profile"></li></ul>').appendTo("#qunit-fixture")
  33. $(pillsHTML).find('li:last a').tab('show')
  34. equals($("#qunit-fixture").find('.active').attr('id'), "profile")
  35. $(pillsHTML).find('li:first a').tab('show')
  36. equals($("#qunit-fixture").find('.active').attr('id'), "home")
  37. })
  38. test("should not fire closed when close is prevented", function () {
  39. $.support.transition = false
  40. stop();
  41. $('<div class="tab"/>')
  42. .bind('show', function (e) {
  43. e.preventDefault();
  44. ok(true);
  45. start();
  46. })
  47. .bind('shown', function () {
  48. ok(false);
  49. })
  50. .tab('show')
  51. })
  52. test("show and shown events should reference correct relatedTarget", function () {
  53. var dropHTML =
  54. '<ul class="drop">'
  55. + '<li class="dropdown"><a data-toggle="dropdown" href="#">1</a>'
  56. + '<ul class="dropdown-menu">'
  57. + '<li><a href="#1-1" data-toggle="tab">1-1</a></li>'
  58. + '<li><a href="#1-2" data-toggle="tab">1-2</a></li>'
  59. + '</ul>'
  60. + '</li>'
  61. + '</ul>'
  62. $(dropHTML).find('ul>li:first a').tab('show').end()
  63. .find('ul>li:last a').on('show', function(event){
  64. equals(event.relatedTarget.hash, "#1-1")
  65. }).on('shown', function(event){
  66. equals(event.relatedTarget.hash, "#1-1")
  67. }).tab('show')
  68. })
  69. })