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

    module("bootstrap-modal")

      test("should be defined on jquery object", function () {
Jacob Thornton's avatar
Jacob Thornton committed
6
7
        var div = $("<div id='modal-test'></div>")
        ok(div.modal, 'modal method is defined')
8
9
      })

Jacob Thornton's avatar
Jacob Thornton committed
10
11
12
      test("should return element", function () {
        var div = $("<div id='modal-test'></div>")
        ok(div.modal() == div, 'document.body returned')
13
        $('#modal-test').remove()
14
15
      })

Jacob Thornton's avatar
Jacob Thornton committed
16
17
      test("should expose defaults var for settings", function () {
        ok($.fn.modal.defaults, 'default object exposed')
18
19
      })

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

32
33
34
35
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
      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
61
      test("should hide modal when hide is called", function () {
Jacob Thornton's avatar
Jacob Thornton committed
62
        stop()
Jacob Thornton's avatar
Jacob Thornton committed
63
        $.support.transition = false
64
65

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

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

97
      test("should remove from dom when click [data-dismiss=modal]", function () {
Jacob Thornton's avatar
Jacob Thornton committed
98
        stop()
Jacob Thornton's avatar
Jacob Thornton committed
99
        $.support.transition = false
100
        var div = $("<div id='modal-test'><span class='close' data-dismiss='modal'></span></div>")
Jacob Thornton's avatar
Jacob Thornton committed
101
        div
Jacob Thornton's avatar
Jacob Thornton committed
102
103
          .bind("shown", function () {
            ok($('#modal-test').is(":visible"), 'modal visible')
Jacob Thornton's avatar
Jacob Thornton committed
104
105
106
            ok($('#modal-test').length, 'modal insterted into dom')
            div.find('.close').click()
          })
Jacob Thornton's avatar
Jacob Thornton committed
107
108
          .bind("hidden", function() {
            ok(!$('#modal-test').is(":visible"), 'modal hidden')
Jacob Thornton's avatar
Jacob Thornton committed
109
            div.remove()
110
            start()
Jacob Thornton's avatar
Jacob Thornton committed
111
          })
Jacob Thornton's avatar
Jacob Thornton committed
112
          .modal("toggle")
Jacob Thornton's avatar
Jacob Thornton committed
113
      })
114
})