bootstrap-source/bootstrap-3.0.3/js/tests/unit/modal.js
author stetrabby <info@trabucchi.de>
Fri, 20 Dec 2013 22:49:16 +0100
changeset 54 0ded9d7748b7
permissions -rwxr-xr-x
initial less based on the pymove3d.css
info@54
     1
$(function () {
info@54
     2
info@54
     3
  module("modal")
info@54
     4
info@54
     5
    test("should provide no conflict", function () {
info@54
     6
      var modal = $.fn.modal.noConflict()
info@54
     7
      ok(!$.fn.modal, 'modal was set back to undefined (org value)')
info@54
     8
      $.fn.modal = modal
info@54
     9
    })
info@54
    10
info@54
    11
    test("should be defined on jquery object", function () {
info@54
    12
      var div = $("<div id='modal-test'></div>")
info@54
    13
      ok(div.modal, 'modal method is defined')
info@54
    14
    })
info@54
    15
info@54
    16
    test("should return element", function () {
info@54
    17
      var div = $("<div id='modal-test'></div>")
info@54
    18
      ok(div.modal() == div, 'document.body returned')
info@54
    19
      $('#modal-test').remove()
info@54
    20
    })
info@54
    21
info@54
    22
    test("should expose defaults var for settings", function () {
info@54
    23
      ok($.fn.modal.Constructor.DEFAULTS, 'default object exposed')
info@54
    24
    })
info@54
    25
info@54
    26
    test("should insert into dom when show method is called", function () {
info@54
    27
      stop()
info@54
    28
      $.support.transition = false
info@54
    29
      $("<div id='modal-test'></div>")
info@54
    30
        .on("shown.bs.modal", function () {
info@54
    31
          ok($('#modal-test').length, 'modal inserted into dom')
info@54
    32
          $(this).remove()
info@54
    33
          start()
info@54
    34
        })
info@54
    35
        .modal("show")
info@54
    36
    })
info@54
    37
info@54
    38
    test("should fire show event", function () {
info@54
    39
      stop()
info@54
    40
      $.support.transition = false
info@54
    41
      $("<div id='modal-test'></div>")
info@54
    42
        .on("show.bs.modal", function () {
info@54
    43
          ok(true, "show was called")
info@54
    44
        })
info@54
    45
        .on("shown.bs.modal", function () {
info@54
    46
          $(this).remove()
info@54
    47
          start()
info@54
    48
        })
info@54
    49
        .modal("show")
info@54
    50
    })
info@54
    51
info@54
    52
    test("should not fire shown when default prevented", function () {
info@54
    53
      stop()
info@54
    54
      $.support.transition = false
info@54
    55
      $("<div id='modal-test'></div>")
info@54
    56
        .on("show.bs.modal", function (e) {
info@54
    57
          e.preventDefault()
info@54
    58
          ok(true, "show was called")
info@54
    59
          start()
info@54
    60
        })
info@54
    61
        .on("shown.bs.modal", function () {
info@54
    62
          ok(false, "shown was called")
info@54
    63
        })
info@54
    64
        .modal("show")
info@54
    65
    })
info@54
    66
info@54
    67
    test("should hide modal when hide is called", function () {
info@54
    68
      stop()
info@54
    69
      $.support.transition = false
info@54
    70
info@54
    71
      $("<div id='modal-test'></div>")
info@54
    72
        .on("shown.bs.modal", function () {
info@54
    73
          ok($('#modal-test').is(":visible"), 'modal visible')
info@54
    74
          ok($('#modal-test').length, 'modal inserted into dom')
info@54
    75
          $(this).modal("hide")
info@54
    76
        })
info@54
    77
        .on("hidden.bs.modal", function() {
info@54
    78
          ok(!$('#modal-test').is(":visible"), 'modal hidden')
info@54
    79
          $('#modal-test').remove()
info@54
    80
          start()
info@54
    81
        })
info@54
    82
        .modal("show")
info@54
    83
    })
info@54
    84
info@54
    85
    test("should toggle when toggle is called", function () {
info@54
    86
      stop()
info@54
    87
      $.support.transition = false
info@54
    88
      var div = $("<div id='modal-test'></div>")
info@54
    89
      div
info@54
    90
        .on("shown.bs.modal", function () {
info@54
    91
          ok($('#modal-test').is(":visible"), 'modal visible')
info@54
    92
          ok($('#modal-test').length, 'modal inserted into dom')
info@54
    93
          div.modal("toggle")
info@54
    94
        })
info@54
    95
        .on("hidden.bs.modal", function() {
info@54
    96
          ok(!$('#modal-test').is(":visible"), 'modal hidden')
info@54
    97
          div.remove()
info@54
    98
          start()
info@54
    99
        })
info@54
   100
        .modal("toggle")
info@54
   101
    })
info@54
   102
info@54
   103
    test("should remove from dom when click [data-dismiss=modal]", function () {
info@54
   104
      stop()
info@54
   105
      $.support.transition = false
info@54
   106
      var div = $("<div id='modal-test'><span class='close' data-dismiss='modal'></span></div>")
info@54
   107
      div
info@54
   108
        .on("shown.bs.modal", function () {
info@54
   109
          ok($('#modal-test').is(":visible"), 'modal visible')
info@54
   110
          ok($('#modal-test').length, 'modal inserted into dom')
info@54
   111
          div.find('.close').click()
info@54
   112
        })
info@54
   113
        .on("hidden.bs.modal", function() {
info@54
   114
          ok(!$('#modal-test').is(":visible"), 'modal hidden')
info@54
   115
          div.remove()
info@54
   116
          start()
info@54
   117
        })
info@54
   118
        .modal("toggle")
info@54
   119
    })
info@54
   120
info@54
   121
    test("should allow modal close with 'backdrop:false'", function () {
info@54
   122
      stop()
info@54
   123
      $.support.transition = false
info@54
   124
      var div = $("<div>", { id: 'modal-test', "data-backdrop": false })
info@54
   125
      div
info@54
   126
        .on("shown.bs.modal", function () {
info@54
   127
          ok($('#modal-test').is(":visible"), 'modal visible')
info@54
   128
          div.modal("hide")
info@54
   129
        })
info@54
   130
        .on("hidden.bs.modal", function() {
info@54
   131
          ok(!$('#modal-test').is(":visible"), 'modal hidden')
info@54
   132
          div.remove()
info@54
   133
          start()
info@54
   134
        })
info@54
   135
        .modal("show")
info@54
   136
    })
info@54
   137
info@54
   138
    test("should close modal when clicking outside of modal-content", function () {
info@54
   139
      stop()
info@54
   140
      $.support.transition = false
info@54
   141
      var div = $("<div id='modal-test'><div class='contents'></div></div>")
info@54
   142
      div
info@54
   143
        .bind("shown.bs.modal", function () {
info@54
   144
          ok($('#modal-test').length, 'modal insterted into dom')
info@54
   145
          $('.contents').click()
info@54
   146
          ok($('#modal-test').is(":visible"), 'modal visible')
info@54
   147
          $('#modal-test').click()
info@54
   148
        })
info@54
   149
        .bind("hidden.bs.modal", function() {
info@54
   150
          ok(!$('#modal-test').is(":visible"), 'modal hidden')
info@54
   151
          div.remove()
info@54
   152
          start()
info@54
   153
        })
info@54
   154
        .modal("show")
info@54
   155
    })
info@54
   156
info@54
   157
    test("should trigger hide event once when clicking outside of modal-content", function () {
info@54
   158
      stop()
info@54
   159
      $.support.transition = false
info@54
   160
      var div = $("<div id='modal-test'><div class='contents'></div></div>")
info@54
   161
      var triggered
info@54
   162
      div
info@54
   163
        .bind("shown.bs.modal", function () {
info@54
   164
          triggered = 0
info@54
   165
          $('#modal-test').click()
info@54
   166
        })
info@54
   167
        .one("hidden.bs.modal", function() {
info@54
   168
          div.modal("show")
info@54
   169
        })
info@54
   170
        .bind("hide.bs.modal", function () {
info@54
   171
          triggered += 1
info@54
   172
          ok(triggered === 1, 'modal hide triggered once')
info@54
   173
          start()
info@54
   174
        })
info@54
   175
        .modal("show")
info@54
   176
    })
info@54
   177
info@54
   178
    test("should close reopened modal with [data-dismiss=modal] click", function () {
info@54
   179
      stop()
info@54
   180
      $.support.transition = false
info@54
   181
      var div = $("<div id='modal-test'><div class='contents'><div id='close' data-dismiss='modal'></div></div></div>")
info@54
   182
      div
info@54
   183
        .bind("shown.bs.modal", function () {
info@54
   184
          $('#close').click()
info@54
   185
          ok(!$('#modal-test').is(":visible"), 'modal hidden')
info@54
   186
        })
info@54
   187
        .one("hidden.bs.modal", function() {
info@54
   188
          div.one('hidden.bs.modal', function () {
info@54
   189
            start()
info@54
   190
          }).modal("show")
info@54
   191
        })
info@54
   192
        .modal("show")
info@54
   193
info@54
   194
      div.remove()
info@54
   195
    })
info@54
   196
})
Impressum Datenschutzerklärung