bootstrap-source/bootstrap-3.0.3/js/tests/unit/collapse.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("collapse")
info@54
     4
info@54
     5
      test("should provide no conflict", function () {
info@54
     6
        var collapse = $.fn.collapse.noConflict()
info@54
     7
        ok(!$.fn.collapse, 'collapse was set back to undefined (org value)')
info@54
     8
        $.fn.collapse = collapse
info@54
     9
      })
info@54
    10
info@54
    11
      test("should be defined on jquery object", function () {
info@54
    12
        ok($(document.body).collapse, 'collapse method is defined')
info@54
    13
      })
info@54
    14
info@54
    15
      test("should return element", function () {
info@54
    16
        ok($(document.body).collapse()[0] == document.body, 'document.body returned')
info@54
    17
      })
info@54
    18
info@54
    19
      test("should show a collapsed element", function () {
info@54
    20
        var el = $('<div class="collapse"></div>').collapse('show')
info@54
    21
        ok(el.hasClass('in'), 'has class in')
info@54
    22
        ok(/height/.test(el.attr('style')), 'has height set')
info@54
    23
      })
info@54
    24
info@54
    25
      test("should hide a collapsed element", function () {
info@54
    26
        var el = $('<div class="collapse"></div>').collapse('hide')
info@54
    27
        ok(!el.hasClass('in'), 'does not have class in')
info@54
    28
        ok(/height/.test(el.attr('style')), 'has height set')
info@54
    29
      })
info@54
    30
info@54
    31
      test("should not fire shown when show is prevented", function () {
info@54
    32
        $.support.transition = false
info@54
    33
        stop()
info@54
    34
        $('<div class="collapse"/>')
info@54
    35
          .on('show.bs.collapse', function (e) {
info@54
    36
            e.preventDefault();
info@54
    37
            ok(true);
info@54
    38
            start();
info@54
    39
          })
info@54
    40
          .on('shown.bs.collapse', function () {
info@54
    41
            ok(false);
info@54
    42
          })
info@54
    43
          .collapse('show')
info@54
    44
      })
info@54
    45
info@54
    46
      test("should reset style to auto after finishing opening collapse", function () {
info@54
    47
        $.support.transition = false
info@54
    48
        stop()
info@54
    49
        $('<div class="collapse" style="height: 0px"/>')
info@54
    50
          .on('show.bs.collapse', function () {
info@54
    51
            ok(this.style.height == '0px')
info@54
    52
          })
info@54
    53
          .on('shown.bs.collapse', function () {
info@54
    54
            ok(this.style.height == 'auto')
info@54
    55
            start()
info@54
    56
          })
info@54
    57
          .collapse('show')
info@54
    58
      })
info@54
    59
info@54
    60
      test("should add active class to target when collapse shown", function () {
info@54
    61
        $.support.transition = false
info@54
    62
        stop()
info@54
    63
info@54
    64
        var target = $('<a data-toggle="collapse" href="#test1"></a>')
info@54
    65
          .appendTo($('#qunit-fixture'))
info@54
    66
info@54
    67
        var collapsible = $('<div id="test1"></div>')
info@54
    68
          .appendTo($('#qunit-fixture'))
info@54
    69
          .on('show.bs.collapse', function () {
info@54
    70
            ok(!target.hasClass('collapsed'))
info@54
    71
            start()
info@54
    72
          })
info@54
    73
info@54
    74
        target.click()
info@54
    75
      })
info@54
    76
info@54
    77
      test("should remove active class to target when collapse hidden", function () {
info@54
    78
        $.support.transition = false
info@54
    79
        stop()
info@54
    80
info@54
    81
        var target = $('<a data-toggle="collapse" href="#test1"></a>')
info@54
    82
          .appendTo($('#qunit-fixture'))
info@54
    83
info@54
    84
        var collapsible = $('<div id="test1" class="in"></div>')
info@54
    85
          .appendTo($('#qunit-fixture'))
info@54
    86
          .on('hide.bs.collapse', function () {
info@54
    87
            ok(target.hasClass('collapsed'))
info@54
    88
            start()
info@54
    89
          })
info@54
    90
info@54
    91
        target.click()
info@54
    92
      })
info@54
    93
info@54
    94
      test("should remove active class from inactive accordion targets", function () {
info@54
    95
        $.support.transition = false
info@54
    96
        stop()
info@54
    97
info@54
    98
        var accordion = $('<div id="accordion"><div class="accordion-group"></div><div class="accordion-group"></div><div class="accordion-group"></div></div>')
info@54
    99
          .appendTo($('#qunit-fixture'))
info@54
   100
info@54
   101
        var target1 = $('<a data-toggle="collapse" href="#body1" data-parent="#accordion"></a>')
info@54
   102
          .appendTo(accordion.find('.accordion-group').eq(0))
info@54
   103
info@54
   104
        var collapsible1 = $('<div id="body1" class="in"></div>')
info@54
   105
          .appendTo(accordion.find('.accordion-group').eq(0))
info@54
   106
info@54
   107
        var target2 = $('<a class="collapsed" data-toggle="collapse" href="#body2" data-parent="#accordion"></a>')
info@54
   108
          .appendTo(accordion.find('.accordion-group').eq(1))
info@54
   109
info@54
   110
        var collapsible2 = $('<div id="body2"></div>')
info@54
   111
          .appendTo(accordion.find('.accordion-group').eq(1))
info@54
   112
info@54
   113
        var target3 = $('<a class="collapsed" data-toggle="collapse" href="#body3" data-parent="#accordion"></a>')
info@54
   114
          .appendTo(accordion.find('.accordion-group').eq(2))
info@54
   115
info@54
   116
        var collapsible3 = $('<div id="body3"></div>')
info@54
   117
          .appendTo(accordion.find('.accordion-group').eq(2))
info@54
   118
          .on('show.bs.collapse', function () {
info@54
   119
            ok(target1.hasClass('collapsed'))
info@54
   120
            ok(target2.hasClass('collapsed'))
info@54
   121
            ok(!target3.hasClass('collapsed'))
info@54
   122
info@54
   123
            start()
info@54
   124
          })
info@54
   125
info@54
   126
        target3.click()
info@54
   127
      })
info@54
   128
info@54
   129
      test("should allow dots in data-parent", function () {
info@54
   130
        $.support.transition = false
info@54
   131
        stop()
info@54
   132
info@54
   133
        var accordion = $('<div class="accordion"><div class="accordion-group"></div><div class="accordion-group"></div><div class="accordion-group"></div></div>')
info@54
   134
          .appendTo($('#qunit-fixture'))
info@54
   135
info@54
   136
        var target1 = $('<a data-toggle="collapse" href="#body1" data-parent=".accordion"></a>')
info@54
   137
          .appendTo(accordion.find('.accordion-group').eq(0))
info@54
   138
info@54
   139
        var collapsible1 = $('<div id="body1" class="in"></div>')
info@54
   140
          .appendTo(accordion.find('.accordion-group').eq(0))
info@54
   141
info@54
   142
        var target2 = $('<a class="collapsed" data-toggle="collapse" href="#body2" data-parent=".accordion"></a>')
info@54
   143
          .appendTo(accordion.find('.accordion-group').eq(1))
info@54
   144
info@54
   145
        var collapsible2 = $('<div id="body2"></div>')
info@54
   146
          .appendTo(accordion.find('.accordion-group').eq(1))
info@54
   147
info@54
   148
        var target3 = $('<a class="collapsed" data-toggle="collapse" href="#body3" data-parent=".accordion"></a>')
info@54
   149
          .appendTo(accordion.find('.accordion-group').eq(2))
info@54
   150
info@54
   151
        var collapsible3 = $('<div id="body3"></div>')
info@54
   152
          .appendTo(accordion.find('.accordion-group').eq(2))
info@54
   153
          .on('show.bs.collapse', function () {
info@54
   154
            ok(target1.hasClass('collapsed'))
info@54
   155
            ok(target2.hasClass('collapsed'))
info@54
   156
            ok(!target3.hasClass('collapsed'))
info@54
   157
info@54
   158
            start()
info@54
   159
          })
info@54
   160
info@54
   161
        target3.click()
info@54
   162
      })
info@54
   163
info@54
   164
})
Impressum Datenschutzerklärung