bootstrap-twipsy.js 2.25 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
$(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>')
32
          .appendTo('#qunit-fixture')
Jacob Thornton's avatar
Jacob Thornton committed
33
          .twipsy({placement: 'bottom'})
Jacob Thornton's avatar
Jacob Thornton committed
34
          .twipsy('show')
Jacob Thornton's avatar
Jacob Thornton committed
35

Jacob Thornton's avatar
Jacob Thornton committed
36
        ok($(".twipsy").hasClass('fade bottom 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
      test("should always allow html entities", function () {
Jacob Thornton's avatar
Jacob Thornton committed
41
42
        $.support.transition = false
        var twipsy = $('<a href="#" rel="twipsy" title="<b>@fat</b>"></a>')
43
          .appendTo('#qunit-fixture')
Jacob Thornton's avatar
Jacob Thornton committed
44
          .twipsy('show')
Jacob Thornton's avatar
Jacob Thornton committed
45
46

        ok($('.twipsy b').length, 'b tag was inserted')
Jacob Thornton's avatar
Jacob Thornton committed
47
        twipsy.twipsy('hide')
Jacob Thornton's avatar
Jacob Thornton committed
48
49
50
        ok(!$(".twipsy").length, 'twipsy removed')
      })

51
52
53
54
55
56
57
58
59
60
61
      test("should respect custom classes", function () {
        var twipsy = $('<a href="#" rel="twipsy" title="Another twipsy"></a>')
          .appendTo('#qunit-fixture')
          .twipsy({ template: '<div class="twipsy some-class"><div class="twipsy-arrow"/><div class="twipsy-inner"/></div>'})
          .twipsy('show')

        ok($('.twipsy').hasClass('some-class'), 'custom class is present')
        twipsy.twipsy('hide')
        ok(!$(".twipsy").length, 'twipsy removed')
      })

Jacob Thornton's avatar
Jacob Thornton committed
62
})