bootstrap-modal.js 4.26 KB
Newer Older
1
2
3
4
$(function () {

    module("bootstrap-modal")

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

11
      test("should be defined on jquery object", function () {
Jacob Thornton's avatar
Jacob Thornton committed
12
13
        var div = $("<div id='modal-test'></div>")
        ok(div.modal, 'modal method is defined')
14
15
      })

Jacob Thornton's avatar
Jacob Thornton committed
16
17
18
      test("should return element", function () {
        var div = $("<div id='modal-test'></div>")
        ok(div.modal() == div, 'document.body returned')
19
        $('#modal-test').remove()
20
21
      })

Jacob Thornton's avatar
Jacob Thornton committed
22
23
      test("should expose defaults var for settings", function () {
        ok($.fn.modal.defaults, 'default object exposed')
24
25
      })

Jacob Thornton's avatar
Jacob Thornton committed
26
      test("should insert into dom when show method is called", function () {
Jacob Thornton's avatar
Jacob Thornton committed
27
        stop()
Jacob Thornton's avatar
Jacob Thornton committed
28
        $.support.transition = false
29
        $("<div id='modal-test'></div>")
Jacob Thornton's avatar
Jacob Thornton committed
30
          .bind("shown", function () {
Jacob Thornton's avatar
Jacob Thornton committed
31
            ok($('#modal-test').length, 'modal insterted into dom')
32
            $(this).remove()
Jacob Thornton's avatar
Jacob Thornton committed
33
34
            start()
          })
35
          .modal("show")
36
37
      })

38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
      test("should fire show event", function () {
        stop()
        $.support.transition = false
        $("<div id='modal-test'></div>")
          .bind("show", function () {
            ok(true, "show was called")
          })
          .bind("shown", function () {
            $(this).remove()
            start()
          })
          .modal("show")
      })

      test("should not fire shown when default prevented", function () {
        stop()
        $.support.transition = false
        $("<div id='modal-test'></div>")
          .bind("show", function (e) {
            e.preventDefault()
            ok(true, "show was called")
            start()
          })
          .bind("shown", function () {
            ok(false, "shown was called")
          })
          .modal("show")
      })

Jacob Thornton's avatar
Jacob Thornton committed
67
      test("should hide modal when hide is called", function () {
Jacob Thornton's avatar
Jacob Thornton committed
68
        stop()
Jacob Thornton's avatar
Jacob Thornton committed
69
        $.support.transition = false
70
71

        $("<div id='modal-test'></div>")
Jacob Thornton's avatar
Jacob Thornton committed
72
73
          .bind("shown", function () {
            ok($('#modal-test').is(":visible"), 'modal visible')
Jacob Thornton's avatar
Jacob Thornton committed
74
            ok($('#modal-test').length, 'modal insterted into dom')
75
            $(this).modal("hide")
Jacob Thornton's avatar
Jacob Thornton committed
76
          })
Jacob Thornton's avatar
Jacob Thornton committed
77
78
          .bind("hidden", function() {
            ok(!$('#modal-test').is(":visible"), 'modal hidden')
79
            $('#modal-test').remove()
Jacob Thornton's avatar
Jacob Thornton committed
80
81
            start()
          })
Jacob Thornton's avatar
Jacob Thornton committed
82
          .modal("show")
83
84
      })

Jacob Thornton's avatar
Jacob Thornton committed
85
      test("should toggle when toggle is called", function () {
Jacob Thornton's avatar
Jacob Thornton committed
86
        stop()
87
        $.support.transition = false
Jacob Thornton's avatar
Jacob Thornton committed
88
        var div = $("<div id='modal-test'></div>")
Jacob Thornton's avatar
Jacob Thornton committed
89
        div
Jacob Thornton's avatar
Jacob Thornton committed
90
91
          .bind("shown", function () {
            ok($('#modal-test').is(":visible"), 'modal visible')
Jacob Thornton's avatar
Jacob Thornton committed
92
            ok($('#modal-test').length, 'modal insterted into dom')
Jacob Thornton's avatar
Jacob Thornton committed
93
            div.modal("toggle")
Jacob Thornton's avatar
Jacob Thornton committed
94
          })
Jacob Thornton's avatar
Jacob Thornton committed
95
96
          .bind("hidden", function() {
            ok(!$('#modal-test').is(":visible"), 'modal hidden')
Jacob Thornton's avatar
Jacob Thornton committed
97
            div.remove()
98
            start()
Jacob Thornton's avatar
Jacob Thornton committed
99
          })
Jacob Thornton's avatar
Jacob Thornton committed
100
          .modal("toggle")
101
102
      })

103
      test("should remove from dom when click [data-dismiss=modal]", function () {
Jacob Thornton's avatar
Jacob Thornton committed
104
        stop()
Jacob Thornton's avatar
Jacob Thornton committed
105
        $.support.transition = false
106
        var div = $("<div id='modal-test'><span class='close' data-dismiss='modal'></span></div>")
Jacob Thornton's avatar
Jacob Thornton committed
107
        div
Jacob Thornton's avatar
Jacob Thornton committed
108
109
          .bind("shown", function () {
            ok($('#modal-test').is(":visible"), 'modal visible')
Jacob Thornton's avatar
Jacob Thornton committed
110
111
112
            ok($('#modal-test').length, 'modal insterted into dom')
            div.find('.close').click()
          })
Jacob Thornton's avatar
Jacob Thornton committed
113
114
          .bind("hidden", function() {
            ok(!$('#modal-test').is(":visible"), 'modal hidden')
Jacob Thornton's avatar
Jacob Thornton committed
115
            div.remove()
116
            start()
Jacob Thornton's avatar
Jacob Thornton committed
117
          })
Jacob Thornton's avatar
Jacob Thornton committed
118
          .modal("toggle")
Jacob Thornton's avatar
Jacob Thornton committed
119
      })
fat's avatar
shiiiit    
fat committed
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136

      test("should allow modal close with 'backdrop:false'", function () {
        stop()
        $.support.transition = false
        var div = $("<div>", { id: 'modal-test', "data-backdrop": false })
        div
          .bind("shown", function () {
            ok($('#modal-test').is(":visible"), 'modal visible')
            div.modal("hide")
          })
          .bind("hidden", function() {
            ok(!$('#modal-test').is(":visible"), 'modal hidden')
            div.remove()
            start()
          })
          .modal("show")
      })
137
})