aboutsummaryrefslogtreecommitdiff
path: root/js/tests
diff options
context:
space:
mode:
authorMark Otto <[email protected]>2014-11-30 20:17:45 -0800
committerMark Otto <[email protected]>2014-11-30 20:17:45 -0800
commitb648a77ed36d2d3a38842a7ab5a19ba50c52bae6 (patch)
tree5f2a1a3db3f9464f1803c1afef8946e07951ad5c /js/tests
parentb53ad74d472d0dbe3669b61e79c89fd35da4aa1f (diff)
parent0eb2c922d892bdcd4356b7212ab61c7d8a44c2dc (diff)
downloadbootstrap-b648a77ed36d2d3a38842a7ab5a19ba50c52bae6.tar.xz
bootstrap-b648a77ed36d2d3a38842a7ab5a19ba50c52bae6.zip
Merge branch 'master' into v4
Conflicts: Gruntfile.js _config.yml dist/css/bootstrap-theme.css dist/css/bootstrap-theme.min.css dist/css/bootstrap.css dist/css/bootstrap.css.map dist/css/bootstrap.min.css dist/fonts/glyphicons-halflings-regular.eot dist/fonts/glyphicons-halflings-regular.svg dist/fonts/glyphicons-halflings-regular.ttf dist/fonts/glyphicons-halflings-regular.woff docs/_data/glyphicons.yml docs/_includes/components/alerts.html docs/_includes/components/badges.html docs/_includes/components/button-dropdowns.html docs/_includes/components/button-groups.html docs/_includes/components/dropdowns.html docs/_includes/components/glyphicons.html docs/_includes/components/input-groups.html docs/_includes/components/labels.html docs/_includes/components/media.html docs/_includes/components/navbar.html docs/_includes/components/navs.html docs/_includes/components/pagination.html docs/_includes/components/panels.html docs/_includes/components/progress-bars.html docs/_includes/css/buttons.html docs/_includes/css/forms.html docs/_includes/css/grid.html docs/_includes/css/helpers.html docs/_includes/css/images.html docs/_includes/css/less.html docs/_includes/css/responsive-utilities.html docs/_includes/css/sass.html docs/_includes/css/tables.html docs/_includes/css/type.html docs/_includes/getting-started/accessibility.html docs/_includes/getting-started/browser-device-support.html docs/_includes/getting-started/community.html docs/_includes/getting-started/download.html docs/_includes/getting-started/examples.html docs/_includes/getting-started/whats-included.html docs/_includes/js/affix.html docs/_includes/js/alerts.html docs/_includes/js/buttons.html docs/_includes/js/carousel.html docs/_includes/js/collapse.html docs/_includes/js/dropdowns.html docs/_includes/js/modal.html docs/_includes/js/overview.html docs/_includes/js/tabs.html docs/_includes/nav/components.html docs/_includes/nav/css.html docs/_includes/nav/javascript.html docs/_includes/nav/main.html docs/about.html docs/assets/css/docs.min.css docs/assets/js/customize.min.js docs/assets/js/raw-files.min.js docs/dist/css/bootstrap-theme.css docs/dist/css/bootstrap-theme.min.css docs/dist/css/bootstrap.css docs/dist/css/bootstrap.css.map docs/dist/css/bootstrap.min.css docs/dist/fonts/glyphicons-halflings-regular.eot docs/dist/fonts/glyphicons-halflings-regular.svg docs/dist/fonts/glyphicons-halflings-regular.ttf docs/dist/fonts/glyphicons-halflings-regular.woff docs/examples/carousel/index.html docs/examples/navbar-fixed-top/index.html docs/examples/navbar-static-top/index.html docs/examples/navbar/index.html docs/examples/non-responsive/index.html docs/examples/non-responsive/non-responsive.css docs/examples/sticky-footer-navbar/index.html docs/examples/theme/index.html fonts/glyphicons-halflings-regular.eot fonts/glyphicons-halflings-regular.svg fonts/glyphicons-halflings-regular.ttf fonts/glyphicons-halflings-regular.woff less/_carousel.less less/_forms.less less/glyphicons.less
Diffstat (limited to 'js/tests')
-rw-r--r--js/tests/unit/affix.js30
-rw-r--r--js/tests/unit/carousel.js153
-rw-r--r--js/tests/unit/dropdown.js41
-rw-r--r--js/tests/unit/tooltip.js2
4 files changed, 225 insertions, 1 deletions
diff --git a/js/tests/unit/affix.js b/js/tests/unit/affix.js
index ef6ef74b9..3152d8d2e 100644
--- a/js/tests/unit/affix.js
+++ b/js/tests/unit/affix.js
@@ -68,4 +68,34 @@ $(function () {
}, 16) // for testing in a browser
}, 0)
})
+
+ test('should affix-top when scrolling up to offset when parent has padding', function () {
+ stop()
+
+ var templateHTML = '<div id="padding-offset" style="padding-top: 20px;">'
+ + '<div id="affixTopTarget">'
+ + '<p>Testing affix-top class is added</p>'
+ + '</div>'
+ + '<div style="height: 1000px; display: block;"/>'
+ + '</div>'
+ $(templateHTML).appendTo(document.body)
+
+ $('#affixTopTarget')
+ .bootstrapAffix({
+ offset: { top: 120, bottom: 0 }
+ })
+ .on('affixed-top.bs.affix', function () {
+ ok($('#affixTopTarget').hasClass('affix-top'), 'affix-top class applied')
+ $('#padding-offset').remove()
+ start()
+ })
+
+ setTimeout(function () {
+ window.scrollTo(0, document.body.scrollHeight)
+
+ setTimeout(function () {
+ window.scroll(0, 119)
+ }, 250)
+ }, 250)
+ })
})
diff --git a/js/tests/unit/carousel.js b/js/tests/unit/carousel.js
index 5998abe6a..008b72082 100644
--- a/js/tests/unit/carousel.js
+++ b/js/tests/unit/carousel.js
@@ -541,4 +541,157 @@ $(function () {
strictEqual(type in $._data($template[0], 'events'), !isMobile, 'does' + (isMobile ? ' not' : '') + ' listen for ' + type + ' events')
})
})
+
+ test('should wrap around from end to start when wrap option is true', function () {
+ var carouselHTML = '<div id="carousel-example-generic" class="carousel slide" data-wrap="true">'
+ + '<ol class="carousel-indicators">'
+ + '<li data-target="#carousel-example-generic" data-slide-to="0" class="active"/>'
+ + '<li data-target="#carousel-example-generic" data-slide-to="1"/>'
+ + '<li data-target="#carousel-example-generic" data-slide-to="2"/>'
+ + '</ol>'
+ + '<div class="carousel-inner">'
+ + '<div class="item active" id="one">'
+ + '<div class="carousel-caption"/>'
+ + '</div>'
+ + '<div class="item" id="two">'
+ + '<div class="carousel-caption"/>'
+ + '</div>'
+ + '<div class="item" id="three">'
+ + '<div class="carousel-caption"/>'
+ + '</div>'
+ + '</div>'
+ + '<a class="left carousel-control" href="#carousel-example-generic" data-slide="prev"/>'
+ + '<a class="right carousel-control" href="#carousel-example-generic" data-slide="next"/>'
+ + '</div>'
+ var $carousel = $(carouselHTML)
+ var getActiveId = function () { return $carousel.find('.item.active').attr('id') }
+
+ stop()
+
+ $carousel
+ .one('slid.bs.carousel', function () {
+ strictEqual(getActiveId(), 'two', 'carousel slid from 1st to 2nd slide')
+ $carousel
+ .one('slid.bs.carousel', function () {
+ strictEqual(getActiveId(), 'three', 'carousel slid from 2nd to 3rd slide')
+ $carousel
+ .one('slid.bs.carousel', function () {
+ strictEqual(getActiveId(), 'one', 'carousel wrapped around and slid from 3rd to 1st slide')
+ start()
+ })
+ .bootstrapCarousel('next')
+ })
+ .bootstrapCarousel('next')
+ })
+ .bootstrapCarousel('next')
+ })
+
+ test('should wrap around from start to end when wrap option is true', function () {
+ var carouselHTML = '<div id="carousel-example-generic" class="carousel slide" data-wrap="true">'
+ + '<ol class="carousel-indicators">'
+ + '<li data-target="#carousel-example-generic" data-slide-to="0" class="active"/>'
+ + '<li data-target="#carousel-example-generic" data-slide-to="1"/>'
+ + '<li data-target="#carousel-example-generic" data-slide-to="2"/>'
+ + '</ol>'
+ + '<div class="carousel-inner">'
+ + '<div class="item active" id="one">'
+ + '<div class="carousel-caption"/>'
+ + '</div>'
+ + '<div class="item" id="two">'
+ + '<div class="carousel-caption"/>'
+ + '</div>'
+ + '<div class="item" id="three">'
+ + '<div class="carousel-caption"/>'
+ + '</div>'
+ + '</div>'
+ + '<a class="left carousel-control" href="#carousel-example-generic" data-slide="prev"/>'
+ + '<a class="right carousel-control" href="#carousel-example-generic" data-slide="next"/>'
+ + '</div>'
+ var $carousel = $(carouselHTML)
+
+ stop()
+
+ $carousel
+ .on('slid.bs.carousel', function () {
+ strictEqual($carousel.find('.item.active').attr('id'), 'three', 'carousel wrapped around and slid from 1st to 3rd slide')
+ start()
+ })
+ .bootstrapCarousel('prev')
+ })
+
+ test('should stay at the end when the next method is called and wrap is false', function () {
+ var carouselHTML = '<div id="carousel-example-generic" class="carousel slide" data-wrap="false">'
+ + '<ol class="carousel-indicators">'
+ + '<li data-target="#carousel-example-generic" data-slide-to="0" class="active"/>'
+ + '<li data-target="#carousel-example-generic" data-slide-to="1"/>'
+ + '<li data-target="#carousel-example-generic" data-slide-to="2"/>'
+ + '</ol>'
+ + '<div class="carousel-inner">'
+ + '<div class="item active" id="one">'
+ + '<div class="carousel-caption"/>'
+ + '</div>'
+ + '<div class="item" id="two">'
+ + '<div class="carousel-caption"/>'
+ + '</div>'
+ + '<div class="item" id="three">'
+ + '<div class="carousel-caption"/>'
+ + '</div>'
+ + '</div>'
+ + '<a class="left carousel-control" href="#carousel-example-generic" data-slide="prev"/>'
+ + '<a class="right carousel-control" href="#carousel-example-generic" data-slide="next"/>'
+ + '</div>'
+ var $carousel = $(carouselHTML)
+ var getActiveId = function () { return $carousel.find('.item.active').attr('id') }
+
+ stop()
+
+ $carousel
+ .one('slid.bs.carousel', function () {
+ strictEqual(getActiveId(), 'two', 'carousel slid from 1st to 2nd slide')
+ $carousel
+ .one('slid.bs.carousel', function () {
+ strictEqual(getActiveId(), 'three', 'carousel slid from 2nd to 3rd slide')
+ $carousel
+ .one('slid.bs.carousel', function () {
+ ok(false, 'carousel slid when it should not have slid')
+ })
+ .bootstrapCarousel('next')
+ strictEqual(getActiveId(), 'three', 'carousel did not wrap around and stayed on 3rd slide')
+ start()
+ })
+ .bootstrapCarousel('next')
+ })
+ .bootstrapCarousel('next')
+ })
+
+ test('should stay at the start when the prev method is called and wrap is false', function () {
+ var carouselHTML = '<div id="carousel-example-generic" class="carousel slide" data-wrap="false">'
+ + '<ol class="carousel-indicators">'
+ + '<li data-target="#carousel-example-generic" data-slide-to="0" class="active"/>'
+ + '<li data-target="#carousel-example-generic" data-slide-to="1"/>'
+ + '<li data-target="#carousel-example-generic" data-slide-to="2"/>'
+ + '</ol>'
+ + '<div class="carousel-inner">'
+ + '<div class="item active" id="one">'
+ + '<div class="carousel-caption"/>'
+ + '</div>'
+ + '<div class="item" id="two">'
+ + '<div class="carousel-caption"/>'
+ + '</div>'
+ + '<div class="item" id="three">'
+ + '<div class="carousel-caption"/>'
+ + '</div>'
+ + '</div>'
+ + '<a class="left carousel-control" href="#carousel-example-generic" data-slide="prev"/>'
+ + '<a class="right carousel-control" href="#carousel-example-generic" data-slide="next"/>'
+ + '</div>'
+ var $carousel = $(carouselHTML)
+
+ $carousel
+ .on('slid.bs.carousel', function () {
+ ok(false, 'carousel slid when it should not have slid')
+ })
+ .bootstrapCarousel('prev')
+ strictEqual($carousel.find('.item.active').attr('id'), 'one', 'carousel did not wrap around and stayed on 1st slide')
+ })
})
diff --git a/js/tests/unit/dropdown.js b/js/tests/unit/dropdown.js
index 335795fde..3cdf637ee 100644
--- a/js/tests/unit/dropdown.js
+++ b/js/tests/unit/dropdown.js
@@ -224,4 +224,45 @@ $(function () {
$(document.body).click()
})
+ test('should ignore keyboard events within <input>s and <textarea>s', function () {
+ stop()
+
+ var dropdownHTML = '<ul class="tabs">'
+ + '<li class="dropdown">'
+ + '<a href="#" class="dropdown-toggle" data-toggle="dropdown">Dropdown</a>'
+ + '<ul class="dropdown-menu" role="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>'
+ var $dropdown = $(dropdownHTML)
+ .appendTo('#qunit-fixture')
+ .find('[data-toggle="dropdown"]')
+ .bootstrapDropdown()
+
+ var $input = $('#input')
+ var $textarea = $('#textarea')
+
+ $dropdown
+ .parent('.dropdown')
+ .on('shown.bs.dropdown', function () {
+ ok(true, 'shown was fired')
+
+ $input.focus().trigger($.Event('keydown', { which: 38 }))
+ ok($(document.activeElement).is($input), 'input still focused')
+
+ $textarea.focus().trigger($.Event('keydown', { which: 38 }))
+ ok($(document.activeElement).is($textarea), 'textarea still focused')
+
+ start()
+ })
+
+ $dropdown.click()
+ })
+
})
diff --git a/js/tests/unit/tooltip.js b/js/tests/unit/tooltip.js
index 4fbd91dc3..eb578c22a 100644
--- a/js/tests/unit/tooltip.js
+++ b/js/tests/unit/tooltip.js
@@ -4,7 +4,7 @@ $(function () {
module('tooltip plugin')
test('should be defined on jquery object', function () {
- ok($(document.body).tooltip, 'popover method is defined')
+ ok($(document.body).tooltip, 'tooltip method is defined')
})
module('tooltip', {