bootstrap-twipsy.js 2.84 KB
Newer Older
Jacob Thornton's avatar
Jacob Thornton committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
$(function () {

    module("bootstrap-twipsy")

      test("should be defined on jquery object", function () {
        var div = $("<div></div>")
        ok(div.twipsy, 'popover method is defined')
      })

      test("should return element", function () {
        var div = $("<div></div>")
        ok(div.twipsy() == div, 'document.body returned')
      })

      test("should expose default settings", function () {
        ok(!!$.fn.twipsy.defaults, 'defaults is defined')
      })

      test("should remove title attribute", function () {
        var twipsy = $('<a href="#" rel="twipsy" title="Another twipsy"></a>').twipsy()
        ok(!twipsy.attr('title'), 'title tag was removed')
      })

      test("should add data attribute for referencing original title", function () {
        var twipsy = $('<a href="#" rel="twipsy" title="Another twipsy"></a>').twipsy()
        equals(twipsy.attr('data-original-title'), 'Another twipsy', 'original title preserved in data attribute')
      })

      test("should place tooltips relative to placement option", function () {
        $.support.transition = false
        var twipsy = $('<a href="#" rel="twipsy" title="Another twipsy"></a>')
          .appendTo('#qunit-runoff')
          .twipsy({placement: 'below'})
Jacob Thornton's avatar
Jacob Thornton committed
34
          .twipsy('show')
Jacob Thornton's avatar
Jacob Thornton committed
35
36

        ok($(".twipsy").hasClass('fade below in'), 'has correct classes applied')
Jacob Thornton's avatar
Jacob Thornton committed
37
        twipsy.twipsy('hide')
Jacob Thornton's avatar
Jacob Thornton committed
38
39
40
41
42
43
44
45
46
        ok(!$(".twipsy").length, 'twipsy removed')
        $('#qunit-runoff').empty()
      })

      test("should add a fallback in cases where elements have no title tag", function () {
        $.support.transition = false
        var twipsy = $('<a href="#" rel="twipsy"></a>')
          .appendTo('#qunit-runoff')
          .twipsy({fallback: '@fat'})
Jacob Thornton's avatar
Jacob Thornton committed
47
          .twipsy('show')
Jacob Thornton's avatar
Jacob Thornton committed
48
49

        equals($(".twipsy").text(), "@fat", 'has correct default text')
Jacob Thornton's avatar
Jacob Thornton committed
50
        twipsy.twipsy('hide')
Jacob Thornton's avatar
Jacob Thornton committed
51
52
53
54
55
56
57
58
59
        ok(!$(".twipsy").length, 'twipsy removed')
        $('#qunit-runoff').empty()
      })

      test("should not allow html entities", function () {
        $.support.transition = false
        var twipsy = $('<a href="#" rel="twipsy" title="<b>@fat</b>"></a>')
          .appendTo('#qunit-runoff')
          .twipsy()
Jacob Thornton's avatar
Jacob Thornton committed
60
          .twipsy('show')
Jacob Thornton's avatar
Jacob Thornton committed
61
62

        ok(!$('.twipsy b').length, 'b tag was not inserted')
Jacob Thornton's avatar
Jacob Thornton committed
63
        twipsy.twipsy('hide')
Jacob Thornton's avatar
Jacob Thornton committed
64
65
66
67
68
69
70
71
72
        ok(!$(".twipsy").length, 'twipsy removed')
        $('#qunit-runoff').empty()
      })

      test("should allow html entities if html option set to true", function () {
        $.support.transition = false
        var twipsy = $('<a href="#" rel="twipsy" title="<b>@fat</b>"></a>')
          .appendTo('#qunit-runoff')
          .twipsy({html: true})
Jacob Thornton's avatar
Jacob Thornton committed
73
          .twipsy('show')
Jacob Thornton's avatar
Jacob Thornton committed
74
75

        ok($('.twipsy b').length, 'b tag was inserted')
Jacob Thornton's avatar
Jacob Thornton committed
76
        twipsy.twipsy('hide')
Jacob Thornton's avatar
Jacob Thornton committed
77
78
79
80
81
        ok(!$(".twipsy").length, 'twipsy removed')
        $('#qunit-runoff').empty()
      })

})