bootstrap-modal.js 2.67 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 modal:show event 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
25
26
27
28
29
30
        div
          .modal()
          .trigger("modal:show")
          .bind("modal:shown", function () {
            ok($('#modal-test').length, 'modal insterted into dom')
            start()
            div.remove()
          })
31
32
      })

Jacob Thornton's avatar
Jacob Thornton committed
33
34
      test("should remove from dom when modal:hide is called", function () {
        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
39
40
41
42
43
44
45
46
47
48
        div
          .modal()
          .trigger("modal:show")
          .bind("modal:shown", function () {
            ok($('#modal-test').length, 'modal insterted into dom')
            div.trigger("modal:hide")
          })
          .bind("modal:hidden", function() {
            ok(!$('#modal-test').length, 'modal removed from dom')
            start()
            div.remove()
          })
49
50
      })

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

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