mirror of
https://github.com/twbs/bootstrap.git
synced 2024-12-01 13:24:25 +01:00
add unit tests for our carousel
This commit is contained in:
parent
bb0d6bf178
commit
91f8077ed5
@ -289,7 +289,6 @@ class Carousel {
|
||||
}
|
||||
|
||||
const move = (event) => {
|
||||
if (!this._pointerEvent) {
|
||||
event.preventDefault()
|
||||
|
||||
// ensure swiping with one touch and not pinching
|
||||
@ -299,7 +298,6 @@ class Carousel {
|
||||
this.touchDeltaX = event.originalEvent.touches[0].clientX - this.touchStartX
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const end = (event) => {
|
||||
if (this._pointerEvent && (event.originalEvent.pointerType === PointerType.TOUCH || event.originalEvent.pointerType === PointerType.PEN)) {
|
||||
@ -307,7 +305,6 @@ class Carousel {
|
||||
}
|
||||
|
||||
this._handleSwipe()
|
||||
|
||||
if (this._config.pause === 'hover') {
|
||||
// If it's a touch-enabled device, mouseenter/leave are fired as
|
||||
// part of the mouse compatibility events on first tap - the carousel
|
||||
|
@ -1226,4 +1226,48 @@ $(function () {
|
||||
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()
|
||||
})
|
||||
})
|
||||
|
Loading…
Reference in New Issue
Block a user