• Joe Haddad's avatar
    Upgrade webpack (#1291) · 12288836
    Joe Haddad authored
    * Upgrade webpack
    
    * Address more webpack v2 ...
    
    * Update html-webpack-plugin
    
    * Remove LoaderOptionsPlugin from dev config
    
    * ExtractTextPlugin still uses webpack 1 syntax
    ... and doesn't support complex options (yet)
    
    * Grammar nit
    
    * Update extract text webpack plugin
    
    * - Remove webpack.LoaderOptionsPlugin
    - Update deps
    
    * Lerna hoists packages
    
    * Update extract-text-webpack-plugin
    
    * Update webpack-dev-server
    
    * Remove imports for the tests
    
    * stop removing babelrc
    12288836
This project manages its dependencies using npm. Learn more
modal.js 8.76 KiB
$(function () {
  'use strict';
  module('modal plugin')
  test('should be defined on jquery object', function () {
    ok($(document.body).modal, 'modal method is defined')
  })
  module('modal', {
    setup: function () {
      // Run all tests in noConflict mode -- it's the only way to ensure that the plugin works in noConflict mode
      $.fn.bootstrapModal = $.fn.modal.noConflict()
    teardown: function () {
      $.fn.modal = $.fn.bootstrapModal
      delete $.fn.bootstrapModal
  test('should provide no conflict', function () {
    strictEqual($.fn.modal, undefined, 'modal was set back to undefined (orig value)')
  test('should return jquery collection containing the element', function () {
    var $el = $('<div id="modal-test"/>')
    var $modal = $el.bootstrapModal()
    ok($modal instanceof $, 'returns jquery collection')
    strictEqual($modal[0], $el[0], 'collection contains element')
  test('should expose defaults var for settings', function () {
    ok($.fn.bootstrapModal.Constructor.DEFAULTS, 'default object exposed')
  test('should insert into dom when show method is called', function (assert) {
    var done = assert.async()
    $('<div id="modal-test"/>')
      .on('shown.bs.modal', function () {
        notEqual($('#modal-test').length, 0, 'modal inserted into dom')
        done()
      .bootstrapModal('show')
  test('should fire show event', function (assert) {
    var done = assert.async()
    $('<div id="modal-test"/>')
      .on('show.bs.modal', function () {
        ok(true, 'show event fired')
        done()
      .bootstrapModal('show')
  test('should not fire shown when show was prevented', function (assert) {
    var done = assert.async()
    $('<div id="modal-test"/>')
      .on('show.bs.modal', function (e) {
        e.preventDefault()
        ok(true, 'show event fired')
        done()
      .on('shown.bs.modal', function () {
        ok(false, 'shown event fired')
      .bootstrapModal('show')
7172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
}) test('should hide modal when hide is called', function (assert) { var done = assert.async() $('<div id="modal-test"/>') .on('shown.bs.modal', function () { ok($('#modal-test').is(':visible'), 'modal visible') notEqual($('#modal-test').length, 0, 'modal inserted into dom') $(this).bootstrapModal('hide') }) .on('hidden.bs.modal', function () { ok(!$('#modal-test').is(':visible'), 'modal hidden') done() }) .bootstrapModal('show') }) test('should toggle when toggle is called', function (assert) { var done = assert.async() $('<div id="modal-test"/>') .on('shown.bs.modal', function () { ok($('#modal-test').is(':visible'), 'modal visible') notEqual($('#modal-test').length, 0, 'modal inserted into dom') $(this).bootstrapModal('toggle') }) .on('hidden.bs.modal', function () { ok(!$('#modal-test').is(':visible'), 'modal hidden') done() }) .bootstrapModal('toggle') }) test('should remove from dom when click [data-dismiss="modal"]', function (assert) { var done = assert.async() $('<div id="modal-test"><span class="close" data-dismiss="modal"/></div>') .on('shown.bs.modal', function () { ok($('#modal-test').is(':visible'), 'modal visible') notEqual($('#modal-test').length, 0, 'modal inserted into dom') $(this).find('.close').click() }) .on('hidden.bs.modal', function () { ok(!$('#modal-test').is(':visible'), 'modal hidden') done() }) .bootstrapModal('toggle') }) test('should allow modal close with "backdrop:false"', function (assert) { var done = assert.async() $('<div id="modal-test" data-backdrop="false"/>') .on('shown.bs.modal', function () { ok($('#modal-test').is(':visible'), 'modal visible') $(this).bootstrapModal('hide') }) .on('hidden.bs.modal', function () { ok(!$('#modal-test').is(':visible'), 'modal hidden') done() }) .bootstrapModal('show') }) test('should close modal when clicking outside of modal-content', function (assert) { var done = assert.async() $('<div id="modal-test"><div class="contents"/></div>') .on('shown.bs.modal', function () {
141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
notEqual($('#modal-test').length, 0, 'modal insterted into dom') $('.contents').click() ok($('#modal-test').is(':visible'), 'modal visible') $('#modal-test .modal-backdrop').click() }) .on('hidden.bs.modal', function () { ok(!$('#modal-test').is(':visible'), 'modal hidden') done() }) .bootstrapModal('show') }) test('should close modal when escape key is pressed via keydown', function (assert) { var done = assert.async() var div = $('<div id="modal-test"/>') div .on('shown.bs.modal', function () { ok($('#modal-test').length, 'modal insterted into dom') ok($('#modal-test').is(':visible'), 'modal visible') div.trigger($.Event('keydown', { which: 27 })) setTimeout(function () { ok(!$('#modal-test').is(':visible'), 'modal hidden') div.remove() done() }, 0) }) .bootstrapModal('show') }) test('should not close modal when escape key is pressed via keyup', function (assert) { var done = assert.async() var div = $('<div id="modal-test"/>') div .on('shown.bs.modal', function () { ok($('#modal-test').length, 'modal insterted into dom') ok($('#modal-test').is(':visible'), 'modal visible') div.trigger($.Event('keyup', { which: 27 })) setTimeout(function () { ok($('#modal-test').is(':visible'), 'modal still visible') div.remove() done() }, 0) }) .bootstrapModal('show') }) test('should trigger hide event once when clicking outside of modal-content', function (assert) { var done = assert.async() var triggered $('<div id="modal-test"><div class="contents"/></div>') .on('shown.bs.modal', function () { triggered = 0 $('#modal-test .modal-backdrop').click() }) .on('hide.bs.modal', function () { triggered += 1 strictEqual(triggered, 1, 'modal hide triggered once') done() }) .bootstrapModal('show') }) test('should close reopened modal with [data-dismiss="modal"] click', function (assert) { var done = assert.async()
211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279
$('<div id="modal-test"><div class="contents"><div id="close" data-dismiss="modal"/></div></div>') .one('shown.bs.modal', function () { $('#close').click() }) .one('hidden.bs.modal', function () { // after one open-close cycle ok(!$('#modal-test').is(':visible'), 'modal hidden') $(this) .one('shown.bs.modal', function () { $('#close').click() }) .one('hidden.bs.modal', function () { ok(!$('#modal-test').is(':visible'), 'modal hidden') done() }) .bootstrapModal('show') }) .bootstrapModal('show') }) test('should restore focus to toggling element when modal is hidden after having been opened via data-api', function (assert) { var done = assert.async() var $toggleBtn = $('<button data-toggle="modal" data-target="#modal-test"/>').appendTo('#qunit-fixture') $('<div id="modal-test"><div class="contents"><div id="close" data-dismiss="modal"/></div></div>') .on('hidden.bs.modal', function () { setTimeout(function () { ok($(document.activeElement).is($toggleBtn), 'toggling element is once again focused') done() }, 0) }) .on('shown.bs.modal', function () { $('#close').click() }) .appendTo('#qunit-fixture') $toggleBtn.click() }) test('should not restore focus to toggling element if the associated show event gets prevented', function (assert) { var done = assert.async() var $toggleBtn = $('<button data-toggle="modal" data-target="#modal-test"/>').appendTo('#qunit-fixture') var $otherBtn = $('<button id="other-btn"/>').appendTo('#qunit-fixture') $('<div id="modal-test"><div class="contents"><div id="close" data-dismiss="modal"/></div>') .one('show.bs.modal', function (e) { e.preventDefault() $otherBtn.focus() setTimeout($.proxy(function () { $(this).bootstrapModal('show') }, this), 0) }) .on('hidden.bs.modal', function () { setTimeout(function () { ok($(document.activeElement).is($otherBtn), 'focus returned to toggling element') done() }, 0) }) .on('shown.bs.modal', function () { $('#close').click() }) .appendTo('#qunit-fixture') $toggleBtn.click() }) })