removal of unnecessary file, and composer update
This commit is contained in:
329
vendor/twbs/bootstrap/js/tests/unit/carousel.js
vendored
329
vendor/twbs/bootstrap/js/tests/unit/carousel.js
vendored
@@ -1,6 +1,26 @@
|
||||
$(function () {
|
||||
'use strict'
|
||||
|
||||
window.Carousel = typeof bootstrap !== 'undefined' ? bootstrap.Carousel : Carousel
|
||||
|
||||
var originWinPointerEvent = window.PointerEvent
|
||||
window.MSPointerEvent = null
|
||||
var supportPointerEvent = Boolean(window.PointerEvent || window.MSPointerEvent)
|
||||
|
||||
function clearPointerEvents() {
|
||||
window.PointerEvent = null
|
||||
}
|
||||
|
||||
function restorePointerEvents() {
|
||||
window.PointerEvent = originWinPointerEvent
|
||||
}
|
||||
|
||||
var stylesCarousel = [
|
||||
'<style>',
|
||||
' .carousel.pointer-event { -ms-touch-action: none; touch-action: none; }',
|
||||
'</style>'
|
||||
].join('')
|
||||
|
||||
QUnit.module('carousel plugin')
|
||||
|
||||
QUnit.test('should be defined on jQuery object', function (assert) {
|
||||
@@ -25,6 +45,20 @@ $(function () {
|
||||
assert.strictEqual(typeof $.fn.carousel, 'undefined', 'carousel was set back to undefined (orig value)')
|
||||
})
|
||||
|
||||
QUnit.test('should return version', function (assert) {
|
||||
assert.expect(1)
|
||||
|
||||
assert.strictEqual(typeof Carousel.VERSION, 'string')
|
||||
})
|
||||
|
||||
QUnit.test('should return default parameters', function (assert) {
|
||||
assert.expect(1)
|
||||
|
||||
var defaultConfig = Carousel.Default
|
||||
|
||||
assert.strictEqual(defaultConfig.touch, true)
|
||||
})
|
||||
|
||||
QUnit.test('should throw explicit error on undefined method', function (assert) {
|
||||
assert.expect(1)
|
||||
var $el = $('<div/>')
|
||||
@@ -445,6 +479,54 @@ $(function () {
|
||||
$carousel.remove()
|
||||
})
|
||||
|
||||
QUnit.test('should set interval from data attribute on individual carousel-item', function (assert) {
|
||||
assert.expect(2)
|
||||
var templateHTML = '<div id="myCarousel" class="carousel slide" data-interval="1814">' +
|
||||
'<div class="carousel-inner">' +
|
||||
'<div class="carousel-item active" data-interval="2814">' +
|
||||
'<img alt="">' +
|
||||
'<div class="carousel-caption">' +
|
||||
'<h4>First Thumbnail label</h4>' +
|
||||
'<p>Cras justo odio, dapibus ac facilisis in, egestas eget quam. Donec ' +
|
||||
'id elit non mi porta gravida at eget metus. Nullam id dolor id nibh ' +
|
||||
'ultricies vehicula ut id elit.</p>' +
|
||||
'</div>' +
|
||||
'</div>' +
|
||||
'<div class="carousel-item" data-interval="3814">' +
|
||||
'<img alt="">' +
|
||||
'<div class="carousel-caption">' +
|
||||
'<h4>Second Thumbnail label</h4>' +
|
||||
'<p>Cras justo odio, dapibus ac facilisis in, egestas eget quam. Donec ' +
|
||||
'id elit non mi porta gravida at eget metus. Nullam id dolor id nibh ' +
|
||||
'ultricies vehicula ut id elit.</p>' +
|
||||
'</div>' +
|
||||
'</div>' +
|
||||
'<div class="carousel-item">' +
|
||||
'<img alt="">' +
|
||||
'<div class="carousel-caption">' +
|
||||
'<h4>Third Thumbnail label</h4>' +
|
||||
'<p>Cras justo odio, dapibus ac facilisis in, egestas eget quam. Donec ' +
|
||||
'id elit non mi porta gravida at eget metus. Nullam id dolor id nibh ' +
|
||||
'ultricies vehicula ut id elit.</p>' +
|
||||
'</div>' +
|
||||
'</div>' +
|
||||
'</div>' +
|
||||
'<a class="left carousel-control" href="#myCarousel" data-slide="prev">‹</a>' +
|
||||
'<a class="right carousel-control" href="#myCarousel" data-slide="next">›</a>' +
|
||||
'</div>'
|
||||
var $carousel = $(templateHTML)
|
||||
|
||||
$carousel.appendTo('body')
|
||||
$carousel.bootstrapCarousel(1)
|
||||
assert.strictEqual($carousel.data('bs.carousel')._config.interval, 3814)
|
||||
$carousel.remove()
|
||||
|
||||
$carousel.appendTo('body')
|
||||
$carousel.bootstrapCarousel(2)
|
||||
assert.strictEqual($carousel.data('bs.carousel')._config.interval, 1814, 'reverts to default interval if no data-interval is set')
|
||||
$carousel.remove()
|
||||
})
|
||||
|
||||
QUnit.test('should skip over non-items when using item indices', function (assert) {
|
||||
assert.expect(2)
|
||||
var templateHTML = '<div id="myCarousel" class="carousel" data-interval="1814">' +
|
||||
@@ -941,4 +1023,251 @@ $(function () {
|
||||
}, 80)
|
||||
}, 80)
|
||||
})
|
||||
|
||||
QUnit.test('should allow swiperight and call prev with pointer events', function (assert) {
|
||||
if (!supportPointerEvent) {
|
||||
assert.expect(0)
|
||||
return
|
||||
}
|
||||
|
||||
document.documentElement.ontouchstart = $.noop
|
||||
Simulator.setType('pointer')
|
||||
assert.expect(3)
|
||||
var $styles = $(stylesCarousel).appendTo('head')
|
||||
var done = assert.async()
|
||||
|
||||
var carouselHTML =
|
||||
'<div class="carousel" data-interval="false">' +
|
||||
' <div class="carousel-inner">' +
|
||||
' <div id="item" class="carousel-item">' +
|
||||
' <img alt="">' +
|
||||
' </div>' +
|
||||
' <div class="carousel-item active">' +
|
||||
' <img alt="">' +
|
||||
' </div>' +
|
||||
' </div>' +
|
||||
'</div>'
|
||||
|
||||
var $carousel = $(carouselHTML).appendTo('#qunit-fixture')
|
||||
var $item = $('#item')
|
||||
$carousel.bootstrapCarousel()
|
||||
var carousel = $carousel.data('bs.carousel')
|
||||
var spy = sinon.spy(carousel, 'prev')
|
||||
|
||||
$carousel.one('slid.bs.carousel', function () {
|
||||
assert.ok(true, 'slid event fired')
|
||||
assert.ok($item.hasClass('active'))
|
||||
assert.ok(spy.called)
|
||||
$styles.remove()
|
||||
delete document.documentElement.ontouchstart
|
||||
done()
|
||||
})
|
||||
|
||||
Simulator.gestures.swipe($carousel[0], {
|
||||
deltaX: 300,
|
||||
deltaY: 0
|
||||
})
|
||||
})
|
||||
|
||||
QUnit.test('should allow swiperight and call prev with touch events', function (assert) {
|
||||
Simulator.setType('touch')
|
||||
clearPointerEvents()
|
||||
|
||||
assert.expect(3)
|
||||
var done = assert.async()
|
||||
document.documentElement.ontouchstart = $.noop
|
||||
|
||||
var carouselHTML =
|
||||
'<div class="carousel" data-interval="false">' +
|
||||
' <div class="carousel-inner">' +
|
||||
' <div id="item" class="carousel-item">' +
|
||||
' <img alt="">' +
|
||||
' </div>' +
|
||||
' <div class="carousel-item active">' +
|
||||
' <img alt="">' +
|
||||
' </div>' +
|
||||
' </div>' +
|
||||
'</div>'
|
||||
|
||||
var $carousel = $(carouselHTML)
|
||||
$carousel.appendTo('#qunit-fixture')
|
||||
var $item = $('#item')
|
||||
$carousel.bootstrapCarousel()
|
||||
var carousel = $carousel.data('bs.carousel')
|
||||
var spy = sinon.spy(carousel, 'prev')
|
||||
|
||||
$carousel.one('slid.bs.carousel', function () {
|
||||
assert.ok(true, 'slid event fired')
|
||||
assert.ok($item.hasClass('active'))
|
||||
assert.ok(spy.called)
|
||||
delete document.documentElement.ontouchstart
|
||||
restorePointerEvents()
|
||||
done()
|
||||
})
|
||||
|
||||
Simulator.gestures.swipe($carousel[0], {
|
||||
deltaX: 300,
|
||||
deltaY: 0
|
||||
})
|
||||
})
|
||||
|
||||
QUnit.test('should allow swipeleft and call next with pointer events', function (assert) {
|
||||
if (!supportPointerEvent) {
|
||||
assert.expect(0)
|
||||
return
|
||||
}
|
||||
|
||||
document.documentElement.ontouchstart = $.noop
|
||||
assert.expect(3)
|
||||
Simulator.setType('pointer')
|
||||
|
||||
var $styles = $(stylesCarousel).appendTo('head')
|
||||
var done = assert.async()
|
||||
|
||||
var carouselHTML =
|
||||
'<div class="carousel" data-interval="false">' +
|
||||
' <div class="carousel-inner">' +
|
||||
' <div id="item" class="carousel-item active">' +
|
||||
' <img alt="">' +
|
||||
' </div>' +
|
||||
' <div class="carousel-item">' +
|
||||
' <img alt="">' +
|
||||
' </div>' +
|
||||
' </div>' +
|
||||
'</div>'
|
||||
|
||||
var $carousel = $(carouselHTML)
|
||||
$carousel.appendTo('#qunit-fixture')
|
||||
var $item = $('#item')
|
||||
$carousel.bootstrapCarousel()
|
||||
var carousel = $carousel.data('bs.carousel')
|
||||
var spy = sinon.spy(carousel, 'next')
|
||||
|
||||
$carousel.one('slid.bs.carousel', function () {
|
||||
assert.ok(true, 'slid event fired')
|
||||
assert.ok(!$item.hasClass('active'))
|
||||
assert.ok(spy.called)
|
||||
$styles.remove()
|
||||
delete document.documentElement.ontouchstart
|
||||
done()
|
||||
})
|
||||
|
||||
Simulator.gestures.swipe($carousel[0], {
|
||||
pos: [300, 10],
|
||||
deltaX: -300,
|
||||
deltaY: 0
|
||||
})
|
||||
})
|
||||
|
||||
QUnit.test('should allow swipeleft and call next with touch events', function (assert) {
|
||||
assert.expect(3)
|
||||
clearPointerEvents()
|
||||
Simulator.setType('touch')
|
||||
document.documentElement.ontouchstart = $.noop
|
||||
|
||||
var done = assert.async()
|
||||
|
||||
var carouselHTML =
|
||||
'<div class="carousel" data-interval="false">' +
|
||||
' <div class="carousel-inner">' +
|
||||
' <div id="item" class="carousel-item active">' +
|
||||
' <img alt="">' +
|
||||
' </div>' +
|
||||
' <div class="carousel-item">' +
|
||||
' <img alt="">' +
|
||||
' </div>' +
|
||||
' </div>' +
|
||||
'</div>'
|
||||
|
||||
var $carousel = $(carouselHTML)
|
||||
$carousel.appendTo('#qunit-fixture')
|
||||
var $item = $('#item')
|
||||
$carousel.bootstrapCarousel()
|
||||
var carousel = $carousel.data('bs.carousel')
|
||||
var spy = sinon.spy(carousel, 'next')
|
||||
|
||||
$carousel.one('slid.bs.carousel', function () {
|
||||
assert.ok(true, 'slid event fired')
|
||||
assert.ok(!$item.hasClass('active'))
|
||||
assert.ok(spy.called)
|
||||
restorePointerEvents()
|
||||
delete document.documentElement.ontouchstart
|
||||
done()
|
||||
})
|
||||
|
||||
Simulator.gestures.swipe($carousel[0], {
|
||||
pos: [300, 10],
|
||||
deltaX: -300,
|
||||
deltaY: 0
|
||||
})
|
||||
})
|
||||
|
||||
QUnit.test('should not allow pinch with touch events', function (assert) {
|
||||
assert.expect(0)
|
||||
clearPointerEvents()
|
||||
|
||||
Simulator.setType('touch')
|
||||
var done = assert.async()
|
||||
document.documentElement.ontouchstart = $.noop
|
||||
|
||||
var carouselHTML = '<div class="carousel" data-interval="false"></div>'
|
||||
var $carousel = $(carouselHTML)
|
||||
$carousel.appendTo('#qunit-fixture')
|
||||
$carousel.bootstrapCarousel()
|
||||
|
||||
Simulator.gestures.swipe($carousel[0], {
|
||||
pos: [300, 10],
|
||||
deltaX: -300,
|
||||
deltaY: 0,
|
||||
touches: 2
|
||||
}, function () {
|
||||
restorePointerEvents()
|
||||
delete document.documentElement.ontouchstart
|
||||
done()
|
||||
})
|
||||
})
|
||||
|
||||
QUnit.test('should not call _slide if the carousel is sliding', function (assert) {
|
||||
assert.expect(1)
|
||||
|
||||
var carouselHTML = '<div class="carousel" data-interval="false"></div>'
|
||||
var $carousel = $(carouselHTML)
|
||||
$carousel.appendTo('#qunit-fixture')
|
||||
$carousel.bootstrapCarousel()
|
||||
|
||||
var carousel = $carousel.data('bs.carousel')
|
||||
|
||||
var spy = sinon.spy(carousel, '_slide')
|
||||
|
||||
carousel._isSliding = true
|
||||
|
||||
carousel.next()
|
||||
|
||||
assert.strictEqual(spy.called, false)
|
||||
})
|
||||
|
||||
QUnit.test('should call next when the page is visible', function (assert) {
|
||||
assert.expect(1)
|
||||
|
||||
var carouselHTML = '<div class="carousel" data-interval="false"></div>'
|
||||
var $carousel = $(carouselHTML)
|
||||
$carousel.appendTo('#qunit-fixture')
|
||||
$carousel.bootstrapCarousel()
|
||||
|
||||
var carousel = $carousel.data('bs.carousel')
|
||||
|
||||
var spy = sinon.spy(carousel, 'next')
|
||||
var sandbox = sinon.createSandbox()
|
||||
|
||||
sandbox.replaceGetter(document, 'hidden', function () {
|
||||
return false
|
||||
})
|
||||
sandbox.stub($carousel, 'is').returns(true)
|
||||
sandbox.stub($carousel, 'css').returns('block')
|
||||
|
||||
carousel.nextWhenVisible()
|
||||
|
||||
assert.strictEqual(spy.called, true)
|
||||
sandbox.restore()
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user