topical media & game development

talk show tell print

mobile-query-three-www-vendor-bootstrap-js-tests-unit-bootstrap-dropdown.js / js



  $(function () {
  
      module("bootstrap-dropdowns")
  
        test("should be defined on jquery object", function () {
          ok($(document.body).dropdown, 'dropdown method is defined')
        })
  
        test("should return element", function () {
          ok($(document.body).dropdown()[0] == document.body, 'document.body returned')
        })
  
        test("should add class open to menu if clicked", function () {
          var dropdownHTML = '<ul class="tabs">'
            + '<li class="dropdown">'
            + '<a href="#" class="dropdown-toggle" data-toggle="dropdown">Dropdown</a>'
            + '<ul class="dropdown-menu">'
            + '<li><a href="#">Secondary link</a></li>'
            + '<li><a href="#">Something else here</a></li>'
            + '<li class="divider"></li>'
            + '<li><a href="#">Another link</a></li>'
            + '</ul>'
            + '</li>'
            + '</ul>'
            , dropdown = dropdownHTML.find('[data-toggle="dropdown"]').dropdown().click()
  
          ok(dropdown.parent('.dropdown').hasClass('open'), 'open class added on click')
        })
  
        test("should remove open class if body clicked", function () {
          var dropdownHTML = '<ul class="tabs">'
            + '<li class="dropdown">'
            + '<a href="#" class="dropdown-toggle" data-toggle="dropdown">Dropdown</a>'
            + '<ul class="dropdown-menu">'
            + '<li><a href="#">Secondary link</a></li>'
            + '<li><a href="#">Something else here</a></li>'
            + '<li class="divider"></li>'
            + '<li><a href="#">Another link</a></li>'
            + '</ul>'
            + '</li>'
            + '</ul>'
            , dropdown = dropdownHTML
              .appendTo('#qunit-fixture')
              .find('[data-toggle="dropdown"]')
              .dropdown()
              .click()
          ok(dropdown.parent('.dropdown').hasClass('open'), 'open class added on click')
          $('body').click()
          ok(!dropdown.parent('.dropdown').hasClass('open'), 'open class removed')
          dropdown.remove()
        })
  
  })


(C) Æliens 04/09/2009

You may not copy or print any of this material without explicit permission of the author or the publisher. In case of other copyright issues, contact the author.