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