0
0
mirror of https://github.com/twbs/bootstrap.git synced 2024-12-01 13:24:25 +01:00

Carousel: refactor _slide method te accept only order as first argument

This commit is contained in:
GeoSot 2022-03-02 02:07:36 +02:00 committed by XhmikosR
parent fcc2c80976
commit 699402bee5
2 changed files with 19 additions and 26 deletions

View File

@ -242,8 +242,8 @@ class Carousel extends BaseComponent {
}
const swipeConfig = {
leftCallback: () => this._slide(DIRECTION_LEFT),
rightCallback: () => this._slide(DIRECTION_RIGHT),
leftCallback: () => this._slide(this._directionToOrder(DIRECTION_LEFT)),
rightCallback: () => this._slide(this._directionToOrder(DIRECTION_RIGHT)),
endCallback: endCallBack
}
@ -258,7 +258,7 @@ class Carousel extends BaseComponent {
const direction = KEY_TO_DIRECTION[event.key]
if (direction) {
event.preventDefault()
this._slide(direction)
this._slide(this._directionToOrder(direction))
}
}
@ -301,9 +301,7 @@ class Carousel extends BaseComponent {
this._config.interval = elementInterval || this._config.defaultInterval
}
_slide(directionOrOrder, element) {
const order = this._directionToOrder(directionOrOrder)
_slide(order, element = null) {
const activeElement = this._getActive()
const activeElementIndex = this._getItemIndex(activeElement)

View File

@ -378,7 +378,7 @@ describe('Carousel', () => {
carouselEl.addEventListener('slid.bs.carousel', event => {
expect(item).toHaveClass('active')
expect(carousel._slide).toHaveBeenCalledWith('right')
expect(carousel._slide).toHaveBeenCalledWith('prev')
expect(event.direction).toEqual('right')
stylesCarousel.remove()
delete document.documentElement.ontouchstart
@ -425,7 +425,7 @@ describe('Carousel', () => {
carouselEl.addEventListener('slid.bs.carousel', event => {
expect(item).not.toHaveClass('active')
expect(carousel._slide).toHaveBeenCalledWith('left')
expect(carousel._slide).toHaveBeenCalledWith('next')
expect(event.direction).toEqual('left')
stylesCarousel.remove()
delete document.documentElement.ontouchstart
@ -467,7 +467,7 @@ describe('Carousel', () => {
carouselEl.addEventListener('slid.bs.carousel', event => {
expect(item).toHaveClass('active')
expect(carousel._slide).toHaveBeenCalledWith('right')
expect(carousel._slide).toHaveBeenCalledWith('prev')
expect(event.direction).toEqual('right')
delete document.documentElement.ontouchstart
restorePointerEvents()
@ -508,7 +508,7 @@ describe('Carousel', () => {
carouselEl.addEventListener('slid.bs.carousel', event => {
expect(item).not.toHaveClass('active')
expect(carousel._slide).toHaveBeenCalledWith('left')
expect(carousel._slide).toHaveBeenCalledWith('next')
expect(event.direction).toEqual('left')
delete document.documentElement.ontouchstart
restorePointerEvents()
@ -1231,16 +1231,14 @@ describe('Carousel', () => {
const carouselEl = fixtureEl.querySelector('div')
const carousel = new Carousel(carouselEl, {})
const spy = spyOn(carousel, '_directionToOrder').and.callThrough()
const spy2 = spyOn(carousel, '_orderToDirection').and.callThrough()
carousel._slide('left')
expect(spy).toHaveBeenCalledWith('left')
expect(spy2).toHaveBeenCalledWith('next')
const spy = spyOn(carousel, '_orderToDirection').and.callThrough()
carousel._slide('right')
expect(spy).toHaveBeenCalledWith('right')
expect(spy2).toHaveBeenCalledWith('prev')
carousel._slide(carousel._directionToOrder('left'))
expect(spy).toHaveBeenCalledWith('next')
carousel._slide(carousel._directionToOrder('right'))
expect(spy).toHaveBeenCalledWith('prev')
})
it('"_slide" has to call "_directionToOrder" and "_orderToDirection" when rtl=true', () => {
@ -1249,16 +1247,13 @@ describe('Carousel', () => {
const carouselEl = fixtureEl.querySelector('div')
const carousel = new Carousel(carouselEl, {})
const spy = spyOn(carousel, '_directionToOrder').and.callThrough()
const spy2 = spyOn(carousel, '_orderToDirection').and.callThrough()
const spy = spyOn(carousel, '_orderToDirection').and.callThrough()
carousel._slide('left')
expect(spy).toHaveBeenCalledWith('left')
expect(spy2).toHaveBeenCalledWith('prev')
carousel._slide(carousel._directionToOrder('left'))
expect(spy).toHaveBeenCalledWith('prev')
carousel._slide('right')
expect(spy).toHaveBeenCalledWith('right')
expect(spy2).toHaveBeenCalledWith('next')
carousel._slide(carousel._directionToOrder('right'))
expect(spy).toHaveBeenCalledWith('next')
document.documentElement.dir = 'ltl'
})