tab.js 2.55 KB
Newer Older
1
2
$(function () {

XhmikosR's avatar
XhmikosR committed
3
  module('tabs')
4

XhmikosR's avatar
XhmikosR committed
5
6
7
8
9
  test('should provide no conflict', function () {
    var tab = $.fn.tab.noConflict()
    ok(!$.fn.tab, 'tab was set back to undefined (org value)')
    $.fn.tab = tab
  })
10

XhmikosR's avatar
XhmikosR committed
11
12
13
  test('should be defined on jquery object', function () {
    ok($(document.body).tab, 'tabs method is defined')
  })
14

XhmikosR's avatar
XhmikosR committed
15
16
17
  test('should return element', function () {
    ok($(document.body).tab()[0] == document.body, 'document.body returned')
  })
18

XhmikosR's avatar
XhmikosR committed
19
20
21
22
23
  test('should activate element by tab id', function () {
    var tabsHTML = '<ul class="tabs">' +
        '<li><a href="#home">Home</a></li>' +
        '<li><a href="#profile">Profile</a></li>' +
        '</ul>'
24

XhmikosR's avatar
XhmikosR committed
25
    $('<ul><li id="home"></li><li id="profile"></li></ul>').appendTo('#qunit-fixture')
26

XhmikosR's avatar
XhmikosR committed
27
28
    $(tabsHTML).find('li:last a').tab('show')
    equal($('#qunit-fixture').find('.active').attr('id'), 'profile')
29

XhmikosR's avatar
XhmikosR committed
30
31
32
    $(tabsHTML).find('li:first a').tab('show')
    equal($('#qunit-fixture').find('.active').attr('id'), 'home')
  })
33

XhmikosR's avatar
XhmikosR committed
34
35
36
37
38
  test('should activate element by tab id', function () {
    var pillsHTML = '<ul class="pills">' +
        '<li><a href="#home">Home</a></li>' +
        '<li><a href="#profile">Profile</a></li>' +
        '</ul>'
39

XhmikosR's avatar
XhmikosR committed
40
    $('<ul><li id="home"></li><li id="profile"></li></ul>').appendTo('#qunit-fixture')
41

XhmikosR's avatar
XhmikosR committed
42
43
    $(pillsHTML).find('li:last a').tab('show')
    equal($('#qunit-fixture').find('.active').attr('id'), 'profile')
44

XhmikosR's avatar
XhmikosR committed
45
46
47
    $(pillsHTML).find('li:first a').tab('show')
    equal($('#qunit-fixture').find('.active').attr('id'), 'home')
  })
48

49

XhmikosR's avatar
XhmikosR committed
50
51
  test('should not fire closed when close is prevented', function () {
    $.support.transition = false
52
    stop()
XhmikosR's avatar
XhmikosR committed
53
54
    $('<div class="tab"/>')
      .on('show.bs.tab', function (e) {
55
56
57
        e.preventDefault()
        ok(true)
        start()
58
      })
XhmikosR's avatar
XhmikosR committed
59
      .on('shown.bs.tab', function () {
60
        ok(false)
XhmikosR's avatar
XhmikosR committed
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
      })
      .tab('show')
  })

  test('show and shown events should reference correct relatedTarget', function () {
    var dropHTML = '<ul class="drop">' +
        '<li class="dropdown"><a data-toggle="dropdown" href="#">1</a>' +
        '<ul class="dropdown-menu">' +
        '<li><a href="#1-1" data-toggle="tab">1-1</a></li>' +
        '<li><a href="#1-2" data-toggle="tab">1-2</a></li>' +
        '</ul>' +
        '</li>' +
        '</ul>'

    $(dropHTML).find('ul>li:first a').tab('show').end()
      .find('ul>li:last a')
      .on('show.bs.tab', function (event) {
        equal(event.relatedTarget.hash, '#1-1')
      })
      .on('show.bs.tab', function (event) {
        equal(event.relatedTarget.hash, '#1-1')
Kevin Attfield's avatar
Kevin Attfield committed
82
      })
XhmikosR's avatar
XhmikosR committed
83
84
      .tab('show')
  })
Kevin Attfield's avatar
Kevin Attfield committed
85

86
})