bootstrap-modal.js 2.75 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
14
      })

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

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

Jacob Thornton's avatar
Jacob Thornton committed
33
      test("should hide modal when hide is called", function () {
Jacob Thornton's avatar
Jacob Thornton committed
34
        stop()
Jacob Thornton's avatar
Jacob Thornton committed
35
36
        $.support.transition = false
        var div = $("<div id='modal-test'></div>")
Jacob Thornton's avatar
Jacob Thornton committed
37
38
        div
          .modal()
Jacob Thornton's avatar
Jacob Thornton committed
39
40
          .bind("shown", function () {
            ok($('#modal-test').is(":visible"), 'modal visible')
Jacob Thornton's avatar
Jacob Thornton committed
41
            ok($('#modal-test').length, 'modal insterted into dom')
Jacob Thornton's avatar
Jacob Thornton committed
42
            div.modal("hide")
Jacob Thornton's avatar
Jacob Thornton committed
43
          })
Jacob Thornton's avatar
Jacob Thornton committed
44
45
          .bind("hidden", function() {
            ok(!$('#modal-test').is(":visible"), 'modal hidden')
Jacob Thornton's avatar
Jacob Thornton committed
46
47
48
            start()
            div.remove()
          })
Jacob Thornton's avatar
Jacob Thornton committed
49
          .modal("show")
50
51
      })

Jacob Thornton's avatar
Jacob Thornton committed
52
      test("should toggle when toggle is called", function () {
Jacob Thornton's avatar
Jacob Thornton committed
53
        stop()
54
        $.support.transition = false
Jacob Thornton's avatar
Jacob Thornton committed
55
        var div = $("<div id='modal-test'></div>")
Jacob Thornton's avatar
Jacob Thornton committed
56
57
        div
          .modal()
Jacob Thornton's avatar
Jacob Thornton committed
58
59
          .bind("shown", function () {
            ok($('#modal-test').is(":visible"), 'modal visible')
Jacob Thornton's avatar
Jacob Thornton committed
60
            ok($('#modal-test').length, 'modal insterted into dom')
Jacob Thornton's avatar
Jacob Thornton committed
61
            div.modal("toggle")
Jacob Thornton's avatar
Jacob Thornton committed
62
          })
Jacob Thornton's avatar
Jacob Thornton committed
63
64
          .bind("hidden", function() {
            ok(!$('#modal-test').is(":visible"), 'modal hidden')
Jacob Thornton's avatar
Jacob Thornton committed
65
66
67
            start()
            div.remove()
          })
Jacob Thornton's avatar
Jacob Thornton committed
68
          .modal("toggle")
69
70
      })

Jacob Thornton's avatar
Jacob Thornton committed
71
      test("should remove from dom when click .close", function () {
Jacob Thornton's avatar
Jacob Thornton committed
72
        stop()
Jacob Thornton's avatar
Jacob Thornton committed
73
74
        $.support.transition = false
        var div = $("<div id='modal-test'><span class='close'></span></div>")
Jacob Thornton's avatar
Jacob Thornton committed
75
76
        div
          .modal()
Jacob Thornton's avatar
Jacob Thornton committed
77
78
          .bind("shown", function () {
            ok($('#modal-test').is(":visible"), 'modal visible')
Jacob Thornton's avatar
Jacob Thornton committed
79
80
81
            ok($('#modal-test').length, 'modal insterted into dom')
            div.find('.close').click()
          })
Jacob Thornton's avatar
Jacob Thornton committed
82
83
          .bind("hidden", function() {
            ok(!$('#modal-test').is(":visible"), 'modal hidden')
Jacob Thornton's avatar
Jacob Thornton committed
84
85
86
            start()
            div.remove()
          })
Jacob Thornton's avatar
Jacob Thornton committed
87
          .modal("toggle")
Jacob Thornton's avatar
Jacob Thornton committed
88
      })
89
})