diff options
| author | Mark Otto <[email protected]> | 2017-04-21 23:36:24 -0700 |
|---|---|---|
| committer | Mark Otto <[email protected]> | 2017-04-21 23:36:24 -0700 |
| commit | 5463d8436b6404f5c647fb12e0cd0eafa4abf5e0 (patch) | |
| tree | ada6f9b1f4990a182d829055ee079db9601dbf9b /js/tests | |
| parent | 7efe4ddee499396efc40f53d1421b61fe5da328d (diff) | |
| parent | 638b97f19c4df6f51475f8088555e3eefd2b986f (diff) | |
| download | bootstrap-5463d8436b6404f5c647fb12e0cd0eafa4abf5e0.tar.xz bootstrap-5463d8436b6404f5c647fb12e0cd0eafa4abf5e0.zip | |
Merge branch 'v4-dev' into form-tweaks
Diffstat (limited to 'js/tests')
| -rw-r--r-- | js/tests/.eslintrc.json | 4 | ||||
| -rw-r--r-- | js/tests/README.md | 4 | ||||
| -rw-r--r-- | js/tests/unit/button.js | 18 | ||||
| -rw-r--r-- | js/tests/unit/carousel.js | 23 | ||||
| -rw-r--r-- | js/tests/unit/collapse.js | 32 | ||||
| -rw-r--r-- | js/tests/unit/dropdown.js | 522 | ||||
| -rw-r--r-- | js/tests/unit/phantom.js | 72 | ||||
| -rw-r--r-- | js/tests/visual/carousel.html | 8 |
8 files changed, 361 insertions, 322 deletions
diff --git a/js/tests/.eslintrc.json b/js/tests/.eslintrc.json index 889ea203d..a05a3a390 100644 --- a/js/tests/.eslintrc.json +++ b/js/tests/.eslintrc.json @@ -1,7 +1,7 @@ { "env": { - "qunit": true, - "es6": false + "es6": false, + "qunit": true }, "globals": { "Util": false diff --git a/js/tests/README.md b/js/tests/README.md index b2d505723..72ece2d36 100644 --- a/js/tests/README.md +++ b/js/tests/README.md @@ -6,7 +6,7 @@ Bootstrap uses [QUnit](https://qunitjs.com/), a powerful, easy-to-use JavaScript * `vendor/` contains third-party testing-related code (QUnit and jQuery). * `visual/` contains "visual" tests which are run interactively in real browsers and require manual verification by humans. -To run the unit test suite via [PhantomJS](http://phantomjs.org/), run `grunt test-js`. +To run the unit test suite via [PhantomJS](http://phantomjs.org/), run `npm run js-test`. To run the unit test suite via a real web browser, open `index.html` in the browser. @@ -16,7 +16,7 @@ To run the unit test suite via a real web browser, open `index.html` in the brow 1. Locate and open the file dedicated to the plugin which you need to add tests to (`unit/<plugin-name>.js`). 2. Review the [QUnit API Documentation](https://api.qunitjs.com/) and use the existing tests as references for how to structure your new tests. 3. Write the necessary unit test(s) for the new or revised functionality. -4. Run `grunt test-js` to see the results of your newly-added test(s). +4. Run `npm run js-test` to see the results of your newly-added test(s). **Note:** Your new unit tests should fail before your changes are applied to the plugin, and should pass after your changes are applied to the plugin. diff --git a/js/tests/unit/button.js b/js/tests/unit/button.js index c67cea345..abc04e10a 100644 --- a/js/tests/unit/button.js +++ b/js/tests/unit/button.js @@ -138,4 +138,22 @@ $(function () { assert.ok($btn2.find('input').prop('checked'), 'btn2 is checked') }) + QUnit.test('should not add aria-pressed on labels for radio/checkbox inputs in a data-toggle="buttons" group', function (assert) { + assert.expect(2) + var groupHTML = '<div class="btn-group" data-toggle="buttons">' + + '<label class="btn btn-primary"><input type="checkbox" autocomplete="off"> Checkbox</label>' + + '<label class="btn btn-primary"><input type="radio" name="options" autocomplete="off"> Radio</label>' + + '</div>' + var $group = $(groupHTML).appendTo('#qunit-fixture') + + var $btn1 = $group.children().eq(0) + var $btn2 = $group.children().eq(1) + + $btn1.find('input').trigger('click') + assert.ok($btn1.is(':not([aria-pressed])'), 'label for nested checkbox input has not been given an aria-pressed attribute') + + $btn2.find('input').trigger('click') + assert.ok($btn2.is(':not([aria-pressed])'), 'label for nested radio input has not been given an aria-pressed attribute') + }) + }) diff --git a/js/tests/unit/carousel.js b/js/tests/unit/carousel.js index 00b438bb2..894f78ab5 100644 --- a/js/tests/unit/carousel.js +++ b/js/tests/unit/carousel.js @@ -654,29 +654,6 @@ $(function () { assert.strictEqual($template.find('.carousel-item')[0], $template.find('.active')[0], 'first item still active after left arrow press in <textarea>') }) - QUnit.test('should only add mouseenter and mouseleave listeners when not on mobile', function (assert) { - assert.expect(2) - var isMobile = 'ontouchstart' in document.documentElement - var templateHTML = '<div id="myCarousel" class="carousel" data-interval="false" data-pause="hover">' - + '<div class="carousel-inner">' - + '<div id="first" class="carousel-item active">' - + '<img alt="">' - + '</div>' - + '<div id="second" class="carousel-item">' - + '<img alt="">' - + '</div>' - + '<div id="third" class="carousel-item">' - + '<img alt="">' - + '</div>' - + '</div>' - + '</div>' - var $template = $(templateHTML).bootstrapCarousel() - - $.each(['mouseover', 'mouseout'], function (i, type) { - assert.strictEqual(type in $._data($template[0], 'events'), !isMobile, 'does' + (isMobile ? ' not' : '') + ' listen for ' + type + ' events') - }) - }) - QUnit.test('should wrap around from end to start when wrap option is true', function (assert) { assert.expect(3) var carouselHTML = '<div id="carousel-example-generic" class="carousel slide" data-wrap="true">' diff --git a/js/tests/unit/collapse.js b/js/tests/unit/collapse.js index e7083f56d..35fcf2108 100644 --- a/js/tests/unit/collapse.js +++ b/js/tests/unit/collapse.js @@ -322,7 +322,7 @@ $(function () { $target3.trigger('click') }) - QUnit.test('should set aria-expanded="true" on target when collapse is shown', function (assert) { + QUnit.test('should set aria-expanded="true" on trigger/control when collapse is shown', function (assert) { assert.expect(1) var done = assert.async() @@ -338,7 +338,7 @@ $(function () { $target.trigger('click') }) - QUnit.test('should set aria-expanded="false" on target when collapse is hidden', function (assert) { + QUnit.test('should set aria-expanded="false" on trigger/control when collapse is hidden', function (assert) { assert.expect(1) var done = assert.async() @@ -364,8 +364,8 @@ $(function () { $('<div id="test1"/>') .appendTo('#qunit-fixture') .on('shown.bs.collapse', function () { - assert.strictEqual($target.attr('aria-expanded'), 'true', 'aria-expanded on target is "true"') - assert.strictEqual($alt.attr('aria-expanded'), 'true', 'aria-expanded on alt is "true"') + assert.strictEqual($target.attr('aria-expanded'), 'true', 'aria-expanded on trigger/control is "true"') + assert.strictEqual($alt.attr('aria-expanded'), 'true', 'aria-expanded on alternative trigger/control is "true"') done() }) @@ -382,15 +382,15 @@ $(function () { $('<div id="test1" class="show"/>') .appendTo('#qunit-fixture') .on('hidden.bs.collapse', function () { - assert.strictEqual($target.attr('aria-expanded'), 'false', 'aria-expanded on target is "false"') - assert.strictEqual($alt.attr('aria-expanded'), 'false', 'aria-expanded on alt is "false"') + assert.strictEqual($target.attr('aria-expanded'), 'false', 'aria-expanded on trigger/control is "false"') + assert.strictEqual($alt.attr('aria-expanded'), 'false', 'aria-expanded on alternative trigger/control is "false"') done() }) $target.trigger('click') }) - QUnit.test('should change aria-expanded from active accordion target to "false" and set the newly active one to "true"', function (assert) { + QUnit.test('should change aria-expanded from active accordion trigger/control to "false" and set the trigger/control for the newly active one to "true"', function (assert) { assert.expect(3) var done = assert.async() @@ -401,22 +401,22 @@ $(function () { + '</div>' var $groups = $(accordionHTML).appendTo('#qunit-fixture').find('.card') - var $target1 = $('<a role="button" data-toggle="collapse" href="#body1"/>').appendTo($groups.eq(0)) + var $target1 = $('<a role="button" data-toggle="collapse" aria-expanded="true" href="#body1"/>').appendTo($groups.eq(0)) - $('<div id="body1" aria-expanded="true" class="show" data-parent="#accordion"/>').appendTo($groups.eq(0)) + $('<div id="body1" class="show" data-parent="#accordion"/>').appendTo($groups.eq(0)) - var $target2 = $('<a role="button" data-toggle="collapse" href="#body2" class="collapsed" aria-expanded="false" />').appendTo($groups.eq(1)) + var $target2 = $('<a role="button" data-toggle="collapse" aria-expanded="false" href="#body2" class="collapsed" aria-expanded="false" />').appendTo($groups.eq(1)) - $('<div id="body2" aria-expanded="false" data-parent="#accordion"/>').appendTo($groups.eq(1)) + $('<div id="body2" data-parent="#accordion"/>').appendTo($groups.eq(1)) - var $target3 = $('<a class="collapsed" data-toggle="collapse" role="button" href="#body3"/>').appendTo($groups.eq(2)) + var $target3 = $('<a class="collapsed" data-toggle="collapse" aria-expanded="false" role="button" href="#body3"/>').appendTo($groups.eq(2)) - $('<div id="body3" aria-expanded="false" data-parent="#accordion"/>') + $('<div id="body3" data-parent="#accordion"/>') .appendTo($groups.eq(2)) .on('shown.bs.collapse', function () { - assert.strictEqual($target1.attr('aria-expanded'), 'false', 'inactive target 1 has aria-expanded="false"') - assert.strictEqual($target2.attr('aria-expanded'), 'false', 'inactive target 2 has aria-expanded="false"') - assert.strictEqual($target3.attr('aria-expanded'), 'true', 'active target 3 has aria-expanded="false"') + assert.strictEqual($target1.attr('aria-expanded'), 'false', 'inactive trigger/control 1 has aria-expanded="false"') + assert.strictEqual($target2.attr('aria-expanded'), 'false', 'inactive trigger/control 2 has aria-expanded="false"') + assert.strictEqual($target3.attr('aria-expanded'), 'true', 'active trigger/control 3 has aria-expanded="true"') done() }) diff --git a/js/tests/unit/dropdown.js b/js/tests/unit/dropdown.js index 9a34fc0c9..a15eb5245 100644 --- a/js/tests/unit/dropdown.js +++ b/js/tests/unit/dropdown.js @@ -45,58 +45,62 @@ $(function () { }) QUnit.test('should not open dropdown if target is disabled via attribute', function (assert) { - assert.expect(1) - var dropdownHTML = '<ul class="tabs">' - + '<li class="dropdown">' + assert.expect(0) + var dropdownHTML = '<div class="tabs">' + + '<div class="dropdown">' + '<button disabled href="#" class="btn dropdown-toggle" data-toggle="dropdown">Dropdown</button>' - + '<ul class="dropdown-menu">' - + '<li><a href="#">Secondary link</a></li>' - + '<li><a href="#">Something else here</a></li>' - + '<li class="divider"/>' - + '<li><a href="#">Another link</a></li>' - + '</ul>' - + '</li>' - + '</ul>' - var $dropdown = $(dropdownHTML).find('[data-toggle="dropdown"]').bootstrapDropdown().trigger('click') - - assert.ok(!$dropdown.parent('.dropdown').hasClass('show'), '"show" class added on click') + + '<div class="dropdown-menu">' + + '<a class="dropdown-item" href="#">Secondary link</a>' + + '<a class="dropdown-item" href="#">Something else here</a>' + + '<div class="divider"/>' + + '<a class="dropdown-item" href="#">Another link</a>' + + '</div>' + + '</div>' + + '</div>' + var $dropdown = $(dropdownHTML).find('[data-toggle="dropdown"]').bootstrapDropdown() + setTimeout(function () { + assert.ok(!$dropdown.parent('.dropdown').hasClass('show'), '"show" class added on click') + }, 300) }) QUnit.test('should set aria-expanded="true" on target when dropdown menu is shown', function (assert) { assert.expect(1) - var dropdownHTML = '<ul class="tabs">' - + '<li class="dropdown">' + var done = assert.async() + var dropdownHTML = '<div class="tabs">' + + '<div class="dropdown">' + '<a href="#" class="dropdown-toggle" data-toggle="dropdown" aria-expanded="false">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><a href="#">Another link</a></li>' - + '</ul>' - + '</li>' - + '</ul>' - var $dropdown = $(dropdownHTML) - .find('[data-toggle="dropdown"]') - .bootstrapDropdown() - .trigger('click') - - assert.strictEqual($dropdown.attr('aria-expanded'), 'true', 'aria-expanded is set to string "true" on click') + + '<div class="dropdown-menu">' + + '<a class="dropdown-item" href="#">Secondary link</a>' + + '<a class="dropdown-item" href="#">Something else here</a>' + + '<div class="divider"/>' + + '<a class="dropdown-item" href="#">Another link</a>' + + '</div>' + + '</div>' + + '</div>' + var $dropdown = $(dropdownHTML).find('[data-toggle="dropdown"]').bootstrapDropdown() + $dropdown + .parent('.dropdown') + .on('shown.bs.dropdown', function () { + assert.strictEqual($dropdown.attr('aria-expanded'), 'true', 'aria-expanded is set to string "true" on click') + done() + }) + $dropdown.trigger('click') }) QUnit.test('should set aria-expanded="false" on target when dropdown menu is hidden', function (assert) { assert.expect(1) var done = assert.async() - var dropdownHTML = '<ul class="tabs">' - + '<li class="dropdown">' + var dropdownHTML = '<div class="tabs">' + + '<div class="dropdown">' + '<a href="#" class="dropdown-toggle" aria-expanded="false" 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><a href="#">Another link</a></li>' - + '</ul>' - + '</li>' - + '</ul>' + + '<div class="dropdown-menu">' + + '<a class="dropdown-item" href="#">Secondary link</a>' + + '<a class="dropdown-item" href="#">Something else here</a>' + + '<div class="divider"/>' + + '<a class="dropdown-item" href="#">Another link</a>' + + '</div>' + + '</div>' + + '</div>' var $dropdown = $(dropdownHTML) .appendTo('#qunit-fixture') .find('[data-toggle="dropdown"]') @@ -114,86 +118,107 @@ $(function () { }) QUnit.test('should not open dropdown if target is disabled via class', function (assert) { - assert.expect(1) - var dropdownHTML = '<ul class="tabs">' - + '<li class="dropdown">' + assert.expect(0) + var dropdownHTML = '<div class="tabs">' + + '<div class="dropdown">' + '<button href="#" class="btn dropdown-toggle disabled" data-toggle="dropdown">Dropdown</button>' - + '<ul class="dropdown-menu">' - + '<li><a href="#">Secondary link</a></li>' - + '<li><a href="#">Something else here</a></li>' - + '<li class="divider"/>' - + '<li><a href="#">Another link</a></li>' - + '</ul>' - + '</li>' - + '</ul>' + + '<div class="dropdown-menu">' + + '<a class="dropdown-item" href="#">Secondary link</a>' + + '<a class="dropdown-item" href="#">Something else here</a>' + + '<div class="divider"/>' + + '<a class="dropdown-item" href="#">Another link</a>' + + '</div>' + + '</div>' + + '</div>' var $dropdown = $(dropdownHTML).find('[data-toggle="dropdown"]').bootstrapDropdown().trigger('click') - - assert.ok(!$dropdown.parent('.dropdown').hasClass('show'), '"show" class added on click') + setTimeout(function () { + assert.ok(!$dropdown.parent('.dropdown').hasClass('show'), '"show" class added on click') + }, 300) }) QUnit.test('should add class show to menu if clicked', function (assert) { assert.expect(1) - var dropdownHTML = '<ul class="tabs">' - + '<li class="dropdown">' + var done = assert.async() + var dropdownHTML = '<div class="tabs">' + + '<div 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><a href="#">Another link</a></li>' - + '</ul>' - + '</li>' - + '</ul>' - var $dropdown = $(dropdownHTML).find('[data-toggle="dropdown"]').bootstrapDropdown().trigger('click') - - assert.ok($dropdown.parent('.dropdown').hasClass('show'), '"show" class added on click') + + '<div class="dropdown-menu">' + + '<a class="dropdown-item" href="#">Secondary link</a>' + + '<a class="dropdown-item" href="#">Something else here</a>' + + '<div class="divider"/>' + + '<a class="dropdown-item" href="#">Another link</a>' + + '</div>' + + '</div>' + + '</div>' + var $dropdown = $(dropdownHTML).find('[data-toggle="dropdown"]').bootstrapDropdown() + $dropdown + .parent('.dropdown') + .on('shown.bs.dropdown', function () { + assert.ok($dropdown.parent('.dropdown').hasClass('show'), '"show" class added on click') + done() + }) + $dropdown.trigger('click') }) QUnit.test('should test if element has a # before assuming it\'s a selector', function (assert) { assert.expect(1) - var dropdownHTML = '<ul class="tabs">' - + '<li class="dropdown">' + var done = assert.async() + var dropdownHTML = '<div class="tabs">' + + '<div class="dropdown">' + '<a href="/foo/" 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><a href="#">Another link</a></li>' - + '</ul>' - + '</li>' - + '</ul>' - var $dropdown = $(dropdownHTML).find('[data-toggle="dropdown"]').bootstrapDropdown().trigger('click') - - assert.ok($dropdown.parent('.dropdown').hasClass('show'), '"show" class added on click') + + '<div class="dropdown-menu">' + + '<a class="dropdown-item" href="#">Secondary link</a>' + + '<a class="dropdown-item" href="#">Something else here</a>' + + '<div class="divider"/>' + + '<a class="dropdown-item" href="#">Another link</a>' + + '</div>' + + '</div>' + + '</div>' + var $dropdown = $(dropdownHTML).find('[data-toggle="dropdown"]').bootstrapDropdown() + $dropdown + .parent('.dropdown') + .on('shown.bs.dropdown', function () { + assert.ok($dropdown.parent('.dropdown').hasClass('show'), '"show" class added on click') + done() + }) + $dropdown.trigger('click') }) QUnit.test('should remove "show" class if body is clicked', function (assert) { assert.expect(2) - var dropdownHTML = '<ul class="tabs">' - + '<li class="dropdown">' + var done = assert.async() + var dropdownHTML = '<div class="tabs">' + + '<div 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><a href="#">Another link</a></li>' - + '</ul>' - + '</li>' - + '</ul>' + + '<div class="dropdown-menu">' + + '<a class="dropdown-item" href="#">Secondary link</a>' + + '<a class="dropdown-item" href="#">Something else here</a>' + + '<div class="divider"/>' + + '<a class="dropdown-item" href="#">Another link</a>' + + '</div>' + + '</div>' + + '</div>' var $dropdown = $(dropdownHTML) .appendTo('#qunit-fixture') .find('[data-toggle="dropdown"]') .bootstrapDropdown() - .trigger('click') - assert.ok($dropdown.parent('.dropdown').hasClass('show'), '"show" class added on click') - $(document.body).trigger('click') - assert.ok(!$dropdown.parent('.dropdown').hasClass('show'), '"show" class removed') + $dropdown + .parent('.dropdown') + .on('shown.bs.dropdown', function () { + assert.ok($dropdown.parent('.dropdown').hasClass('show'), '"show" class added on click') + $(document.body).trigger('click') + }).on('hidden.bs.dropdown', function () { + assert.ok(!$dropdown.parent('.dropdown').hasClass('show'), '"show" class removed') + done() + }) + $dropdown.trigger('click') }) - QUnit.test('should remove "show" class if body is focused', function (assert) { + QUnit.test('should remove "show" class if tabbing outside of menu', function (assert) { assert.expect(2) + var done = assert.async() var dropdownHTML = '<div class="tabs">' + '<div class="dropdown">' + '<a href="#" class="dropdown-toggle" data-toggle="dropdown">Dropdown</a>' @@ -209,30 +234,37 @@ $(function () { .appendTo('#qunit-fixture') .find('[data-toggle="dropdown"]') .bootstrapDropdown() - .trigger('click') - - assert.ok($dropdown.parent('.dropdown').hasClass('show'), '"show" class added on click') - $(document.body).trigger('focusin') - assert.ok(!$dropdown.parent('.dropdown').hasClass('show'), '"show" class removed') + $dropdown + .parent('.dropdown') + .on('shown.bs.dropdown', function () { + assert.ok($dropdown.parent('.dropdown').hasClass('show'), '"show" class added on click') + var e = $.Event('keyup') + e.which = 9 // Tab + $(document.body).trigger(e) + }).on('hidden.bs.dropdown', function () { + assert.ok(!$dropdown.parent('.dropdown').hasClass('show'), '"show" class removed') + done() + }) + $dropdown.trigger('click') }) QUnit.test('should remove "show" class if body is clicked, with multiple dropdowns', function (assert) { assert.expect(7) - var dropdownHTML = '<ul class="nav">' - + '<li><a href="#menu1">Menu 1</a></li>' - + '<li class="dropdown" id="testmenu">' + var done = assert.async() + var dropdownHTML = '<div class="nav">' + + '<div class="dropdown" id="testmenu">' + '<a class="dropdown-toggle" data-toggle="dropdown" href="#testmenu">Test menu <span class="caret"/></a>' - + '<ul class="dropdown-menu">' - + '<li><a href="#sub1">Submenu 1</a></li>' - + '</ul>' - + '</li>' - + '</ul>' + + '<div class="dropdown-menu">' + + '<a class="dropdown-item" href="#sub1">Submenu 1</a>' + + '</div>' + + '</div>' + + '</div>' + '<div class="btn-group">' + '<button class="btn">Actions</button>' - + '<button class="btn dropdown-toggle" data-toggle="dropdown"><span class="caret"/></button>' - + '<ul class="dropdown-menu">' - + '<li><a href="#">Action 1</a></li>' - + '</ul>' + + '<button class="btn dropdown-toggle" data-toggle="dropdown"></button>' + + '<div class="dropdown-menu">' + + '<a class="dropdown-item" href="#">Action 1</a>' + + '</div>' + '</div>' var $dropdowns = $(dropdownHTML).appendTo('#qunit-fixture').find('[data-toggle="dropdown"]') var $first = $dropdowns.first() @@ -240,21 +272,31 @@ $(function () { assert.strictEqual($dropdowns.length, 2, 'two dropdowns') + $first.parent('.dropdown') + .on('shown.bs.dropdown', function () { + assert.strictEqual($first.parents('.show').length, 1, '"show" class added on click') + assert.strictEqual($('#qunit-fixture .show').length, 1, 'only one dropdown is shown') + $(document.body).trigger('click') + }).on('hidden.bs.dropdown', function () { + assert.strictEqual($('#qunit-fixture .show').length, 0, '"show" class removed') + $last.trigger('click') + }) + + $last.parent('.btn-group') + .on('shown.bs.dropdown', function () { + assert.strictEqual($last.parent('.show').length, 1, '"show" class added on click') + assert.strictEqual($('#qunit-fixture .show').length, 1, 'only one dropdown is shown') + $(document.body).trigger('click') + }).on('hidden.bs.dropdown', function () { + assert.strictEqual($('#qunit-fixture .show').length, 0, '"show" class removed') + done() + }) $first.trigger('click') - assert.strictEqual($first.parents('.show').length, 1, '"show" class added on click') - assert.strictEqual($('#qunit-fixture .show').length, 1, 'only one dropdown is shown') - $(document.body).trigger('click') - assert.strictEqual($('#qunit-fixture .show').length, 0, '"show" class removed') - - $last.trigger('click') - assert.strictEqual($last.parent('.show').length, 1, '"show" class added on click') - assert.strictEqual($('#qunit-fixture .show').length, 1, 'only one dropdown is shown') - $(document.body).trigger('click') - assert.strictEqual($('#qunit-fixture .show').length, 0, '"show" class removed') }) - QUnit.test('should remove "show" class if body is focused, with multiple dropdowns', function (assert) { + QUnit.test('should remove "show" class if body if tabbing outside of menu, with multiple dropdowns', function (assert) { assert.expect(7) + var done = assert.async() var dropdownHTML = '<div class="nav">' + '<div class="dropdown" id="testmenu">' + '<a class="dropdown-toggle" data-toggle="dropdown" href="#testmenu">Test menu <span class="caret"/></a>' @@ -276,32 +318,45 @@ $(function () { assert.strictEqual($dropdowns.length, 2, 'two dropdowns') + $first.parent('.dropdown') + .on('shown.bs.dropdown', function () { + assert.strictEqual($first.parents('.show').length, 1, '"show" class added on click') + assert.strictEqual($('#qunit-fixture .show').length, 1, 'only one dropdown is shown') + var e = $.Event('keyup') + e.which = 9 // Tab + $(document.body).trigger(e) + }).on('hidden.bs.dropdown', function () { + assert.strictEqual($('#qunit-fixture .show').length, 0, '"show" class removed') + $last.trigger('click') + }) + + $last.parent('.btn-group') + .on('shown.bs.dropdown', function () { + assert.strictEqual($last.parent('.show').length, 1, '"show" class added on click') + assert.strictEqual($('#qunit-fixture .show').length, 1, 'only one dropdown is shown') + var e = $.Event('keyup') + e.which = 9 // Tab + $(document.body).trigger(e) + }).on('hidden.bs.dropdown', function () { + assert.strictEqual($('#qunit-fixture .show').length, 0, '"show" class removed') + done() + }) $first.trigger('click') - assert.strictEqual($first.parents('.show').length, 1, '"show" class added on click') - assert.strictEqual($('#qunit-fixture .show').length, 1, 'only one dropdown is show') - $(document.body).trigger('focusin') - assert.strictEqual($('#qunit-fixture .show').length, 0, '"show" class removed') - - $last.trigger('click') - assert.strictEqual($last.parent('.show').length, 1, '"show" class added on click') - assert.strictEqual($('#qunit-fixture .show').length, 1, 'only one dropdown is show') - $(document.body).trigger('focusin') - assert.strictEqual($('#qunit-fixture .show').length, 0, '"show" class removed') }) QUnit.test('should fire show and hide event', function (assert) { assert.expect(2) - var dropdownHTML = '<ul class="tabs">' - + '<li class="dropdown">' + var dropdownHTML = '<div class="tabs">' + + '<div 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><a href="#">Another link</a></li>' - + '</ul>' - + '</li>' - + '</ul>' + + '<div class="dropdown-menu">' + + '<a class="dropdown-item" href="#">Secondary link</a>' + + '<a class="dropdown-item" href="#">Something else here</a>' + + '<div class="divider"/>' + + '<a class="dropdown-item" href="#">Another link</a>' + + '</div>' + + '</div>' + + '</div>' var $dropdown = $(dropdownHTML) .appendTo('#qunit-fixture') .find('[data-toggle="dropdown"]') @@ -326,17 +381,17 @@ $(function () { QUnit.test('should fire shown and hidden event', function (assert) { assert.expect(2) - var dropdownHTML = '<ul class="tabs">' - + '<li class="dropdown">' + var dropdownHTML = '<div class="tabs">' + + '<div 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><a href="#">Another link</a></li>' - + '</ul>' - + '</li>' - + '</ul>' + + '<div class="dropdown-menu">' + + '<a class="dropdown-item" href="#">Secondary link</a>' + + '<a class="dropdown-item" href="#">Something else here</a>' + + '<div class="divider"/>' + + '<a class="dropdown-item" href="#">Another link</a>' + + '</div>' + + '</div>' + + '</div>' var $dropdown = $(dropdownHTML) .appendTo('#qunit-fixture') .find('[data-toggle="dropdown"]') @@ -360,17 +415,17 @@ $(function () { QUnit.test('should fire shown and hidden event with a relatedTarget', function (assert) { assert.expect(2) - var dropdownHTML = '<ul class="tabs">' - + '<li class="dropdown">' + var dropdownHTML = '<div class="tabs">' + + '<div 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><a href="#">Another link</a></li>' - + '</ul>' - + '</li>' - + '</ul>' + + '<div class="dropdown-menu">' + + '<a class="dropdown-item" href="#">Secondary link</a>' + + '<a class="dropdown-item" href="#">Something else here</a>' + + '<div class="divider"/>' + + '<a class="dropdown-item" href="#">Another link</a>' + + '</div>' + + '</div>' + + '</div>' var $dropdown = $(dropdownHTML) .appendTo('#qunit-fixture') .find('[data-toggle="dropdown"]') @@ -394,19 +449,19 @@ $(function () { assert.expect(3) var done = assert.async() - var dropdownHTML = '<ul class="tabs">' - + '<li class="dropdown">' + var dropdownHTML = '<div class="tabs">' + + '<div 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><a href="#">Another link</a></li>' - + '<li><input type="text" id="input"></li>' - + '<li><textarea id="textarea"/></li>' - + '</ul>' - + '</li>' - + '</ul>' + + '<div class="dropdown-menu">' + + '<a class="dropdown-item" href="#">Secondary link</a>' + + '<a class="dropdown-item" href="#">Something else here</a>' + + '<div class="divider"/>' + + '<a class="dropdown-item" href="#">Another link</a>' + + '<input type="text" id="input">' + + '<textarea id="textarea"/>' + + '</div>' + + '</div>' + + '</div>' var $dropdown = $(dropdownHTML) .appendTo('#qunit-fixture') .find('[data-toggle="dropdown"]') @@ -433,63 +488,124 @@ $(function () { }) QUnit.test('should skip disabled element when using keyboard navigation', function (assert) { - assert.expect(1) - var dropdownHTML = '<ul class="tabs">' - + '<li class="dropdown">' + assert.expect(2) + var done = assert.async() + var dropdownHTML = '<div class="tabs">' + + '<div class="dropdown">' + + '<a href="#" class="dropdown-toggle" data-toggle="dropdown">Dropdown</a>' + + '<div class="dropdown-menu">' + + '<a class="dropdown-item disabled" href="#">Disabled link</a>' + + '<a class="dropdown-item" href="#">Another link</a>' + + '</div>' + + '</div>' + + '</div>' + var $dropdown = $(dropdownHTML) + .appendTo('#qunit-fixture') + .find('[data-toggle="dropdown"]') + .bootstrapDropdown() + + $dropdown + .parent('.dropdown') + .on('shown.bs.dropdown', function () { + assert.ok(true, 'shown was fired') + $dropdown.trigger($.Event('keydown', { which: 40 })) + $dropdown.trigger($.Event('keydown', { which: 40 })) + assert.ok(!$(document.activeElement).is('.disabled'), '.disabled is not focused') + done() + }) + $dropdown.trigger('click') + }) + + QUnit.test('should focus next/previous element when using keyboard navigation', function (assert) { + assert.expect(4) + var done = assert.async() + var dropdownHTML = '<div class="tabs">' + + '<div class="dropdown">' + '<a href="#" class="dropdown-toggle" data-toggle="dropdown">Dropdown</a>' - + '<ul class="dropdown-menu">' - + '<li class="disabled"><a href="#">Disabled link</a></li>' - + '<li><a href="#">Another link</a></li>' - + '</ul>' - + '</li>' - + '</ul>' + + '<div class="dropdown-menu">' + + '<a id="item1" class="dropdown-item" href="#">A link</a>' + + '<a id="item2" class="dropdown-item" href="#">Another link</a>' + + '</div>' + + '</div>' + + '</div>' var $dropdown = $(dropdownHTML) .appendTo('#qunit-fixture') .find('[data-toggle="dropdown"]') .bootstrapDropdown() - .trigger('click') - $dropdown.trigger($.Event('keydown', { which: 40 })) - $dropdown.trigger($.Event('keydown', { which: 40 })) + $dropdown + .parent('.dropdown') + .on('shown.bs.dropdown', function () { + assert.ok(true, 'shown was fired') + $dropdown.trigger($.Event('keydown', { which: 40 })) + assert.ok($(document.activeElement).is($('#item1')), 'item1 is focused') + + $(document.activeElement).trigger($.Event('keydown', { which: 40 })) + assert.ok($(document.activeElement).is($('#item2')), 'item2 is focused') + + $(document.activeElement).trigger($.Event('keydown', { which: 38 })) + assert.ok($(document.activeElement).is($('#item1')), 'item1 is focused') + done() + }) + $dropdown.trigger('click') - assert.ok(!$(document.activeElement).parent().is('.disabled'), '.disabled is not focused') }) QUnit.test('should not close the dropdown if the user clicks on a text field', function (assert) { assert.expect(1) - var dropdownHTML = '<div class="btn-group">' + var done = assert.async() + var dropdownHTML = '<div class="dropdown">' + '<button type="button" data-toggle="dropdown">Dropdown</button>' - + '<ul class="dropdown-menu">' - + '<li><input id="textField" type="text" /></li>' - + '</ul>' + + '<div class="dropdown-menu">' + + '<input id="textField" type="text" />' + + '</div>' + '</div>' var $dropdown = $(dropdownHTML) .appendTo('#qunit-fixture') .find('[data-toggle="dropdown"]') .bootstrapDropdown() - .trigger('click') - $('#textField').trigger('click') - - assert.ok($dropdown.parent('.btn-group').hasClass('show'), 'dropdown menu is shown') + $dropdown + .parent('.dropdown') + .on('shown.bs.dropdown', function () { + $('#textField').trigger('click') + assert.ok($dropdown.parent('.dropdown').hasClass('show'), 'dropdown menu is shown') + setTimeout(function () { + done() + }, 300) + }) + .on('hidden.bs.dropdown', function () { + assert.ok($dropdown.parent('.dropdown').hasClass('show'), 'dropdown menu is shown') + }) + $dropdown.trigger('click') }) QUnit.test('should not close the dropdown if the user clicks on a textarea', function (assert) { assert.expect(1) - var dropdownHTML = '<div class="btn-group">' + var done = assert.async() + var dropdownHTML = '<div class="dropdown">' + '<button type="button" data-toggle="dropdown">Dropdown</button>' - + '<ul class="dropdown-menu">' - + '<li><textarea id="textArea"></textarea></li>' - + '</ul>' + + '<div class="dropdown-menu">' + + '<textarea id="textArea"></textarea>' + + '</div>' + '</div>' var $dropdown = $(dropdownHTML) .appendTo('#qunit-fixture') .find('[data-toggle="dropdown"]') .bootstrapDropdown() - .trigger('click') - - $('#textArea').trigger('click') - assert.ok($dropdown.parent('.btn-group').hasClass('show'), 'dropdown menu is shown') + $dropdown + .parent('.dropdown') + .on('shown.bs.dropdown', function () { + $('#textArea').trigger('click') + assert.ok($dropdown.parent('.dropdown').hasClass('show'), 'dropdown menu is shown') + setTimeout(function () { + done() + }, 300) + }) + .on('hidden.bs.dropdown', function () { + assert.ok($dropdown.parent('.dropdown').hasClass('show'), 'dropdown menu is shown') + }) + $dropdown.trigger('click') }) }) diff --git a/js/tests/unit/phantom.js b/js/tests/unit/phantom.js deleted file mode 100644 index eea7486a4..000000000 --- a/js/tests/unit/phantom.js +++ /dev/null @@ -1,72 +0,0 @@ -/* - * grunt-contrib-qunit - * http://gruntjs.com/ - * - * Copyright (c) 2014 "Cowboy" Ben Alman, contributors - * Licensed under the MIT license. - */ - -(function () { - 'use strict' - - // Don't re-order tests. - QUnit.config.reorder = false - // Run tests serially, not in parallel. - QUnit.config.autorun = false - - // Send messages to the parent PhantomJS process via alert! Good times!! - function sendMessage() { - var args = [].slice.call(arguments) - alert(JSON.stringify(args)) - } - - // These methods connect QUnit to PhantomJS. - QUnit.log(function (obj) { - // What is this I don’t even - if (obj.message === '[object Object], undefined:undefined') { return } - - // Parse some stuff before sending it. - var actual - var expected - if (!obj.result) { - // Dumping large objects can be very slow, and the dump isn't used for - // passing tests, so only dump if the test failed. - actual = QUnit.dump.parse(obj.actual) - expected = QUnit.dump.parse(obj.expected) - } - // Send it. - sendMessage('qunit.log', obj.result, actual, expected, obj.message, obj.source) - }) - - QUnit.testStart(function (obj) { - sendMessage('qunit.testStart', obj.name) - }) - - QUnit.testDone(function (obj) { - sendMessage('qunit.testDone', obj.name, obj.failed, obj.passed, obj.total, obj.duration) - }) - - QUnit.moduleStart(function (obj) { - sendMessage('qunit.moduleStart', obj.name) - }) - - QUnit.moduleDone(function (obj) { - if (obj.failed === 0) { - console.log('\r\u221A All tests passed in "' + obj.name + '" module') - } else { - console.log('\u00D7 ' + obj.failed + ' tests failed in "' + obj.name + '" module') - } - sendMessage('qunit.moduleDone', obj.name, obj.failed, obj.passed, obj.total) - }) - - QUnit.begin(function () { - sendMessage('qunit.begin') - console.log('\n\nStarting test suite') - console.log('================================================\n') - }) - - QUnit.done(function (obj) { - sendMessage('qunit.done', obj.failed, obj.passed, obj.total, obj.runtime) - }) - -}()) diff --git a/js/tests/visual/carousel.html b/js/tests/visual/carousel.html index ad249d874..27a21efd6 100644 --- a/js/tests/visual/carousel.html +++ b/js/tests/visual/carousel.html @@ -18,15 +18,15 @@ <li data-target="#carousel-example-generic" data-slide-to="1"></li> <li data-target="#carousel-example-generic" data-slide-to="2"></li> </ol> - <div class="carousel-inner" role="listbox"> + <div class="carousel-inner"> <div class="carousel-item active"> - <img src="https://37.media.tumblr.com/tumblr_m8tay0JcfG1qa42jro1_1280.jpg" alt="First slide"> + <img src="http://i.imgur.com/iEZgY7Y.jpg" alt="First slide"> </div> <div class="carousel-item"> - <img src="https://37.media.tumblr.com/tumblr_m8tazfiVYJ1qa42jro1_1280.jpg" alt="Second slide"> + <img src="http://i.imgur.com/eNWn1Xs.jpg" alt="Second slide"> </div> <div class="carousel-item"> - <img src="https://38.media.tumblr.com/tumblr_m8tb2rVsD31qa42jro1_1280.jpg" alt="Third slide"> + <img src="http://i.imgur.com/Nm7xoti.jpg" alt="Third slide"> </div> </div> <a class="carousel-control-prev" href="#carousel-example-generic" role="button" data-slide="prev"> |
