mirror of
https://github.com/twbs/bootstrap.git
synced 2025-08-10 23:54:08 +02:00
Refactor scrollbar.js to be used as a Class (#33947)
This commit is contained in:
@@ -4,6 +4,7 @@ import EventHandler from '../../src/dom/event-handler'
|
||||
/** Test helpers */
|
||||
import { clearBodyAndDocument, clearFixture, createEvent, getFixture, jQueryMock } from '../helpers/fixture'
|
||||
import { isVisible } from '../../src/util'
|
||||
import ScrollBarHelper from '../../src/util/scrollbar'
|
||||
|
||||
describe('Offcanvas', () => {
|
||||
let fixtureEl
|
||||
@@ -159,36 +160,36 @@ describe('Offcanvas', () => {
|
||||
it('if scroll is enabled, should allow body to scroll while offcanvas is open', done => {
|
||||
fixtureEl.innerHTML = '<div class="offcanvas"></div>'
|
||||
|
||||
spyOn(ScrollBarHelper.prototype, 'hide').and.callThrough()
|
||||
spyOn(ScrollBarHelper.prototype, 'reset').and.callThrough()
|
||||
const offCanvasEl = fixtureEl.querySelector('.offcanvas')
|
||||
const offCanvas = new Offcanvas(offCanvasEl, { scroll: true })
|
||||
const initialOverFlow = document.body.style.overflow
|
||||
|
||||
offCanvasEl.addEventListener('shown.bs.offcanvas', () => {
|
||||
expect(document.body.style.overflow).toEqual(initialOverFlow)
|
||||
|
||||
expect(ScrollBarHelper.prototype.hide).not.toHaveBeenCalled()
|
||||
offCanvas.hide()
|
||||
})
|
||||
offCanvasEl.addEventListener('hidden.bs.offcanvas', () => {
|
||||
expect(document.body.style.overflow).toEqual(initialOverFlow)
|
||||
expect(ScrollBarHelper.prototype.reset).not.toHaveBeenCalled()
|
||||
done()
|
||||
})
|
||||
offCanvas.show()
|
||||
})
|
||||
|
||||
it('if scroll is disabled, should not allow body to scroll while offcanvas is open', done => {
|
||||
it('if scroll is disabled, should call ScrollBarHelper to handle scrollBar on body', done => {
|
||||
fixtureEl.innerHTML = '<div class="offcanvas"></div>'
|
||||
|
||||
spyOn(ScrollBarHelper.prototype, 'hide').and.callThrough()
|
||||
spyOn(ScrollBarHelper.prototype, 'reset').and.callThrough()
|
||||
const offCanvasEl = fixtureEl.querySelector('.offcanvas')
|
||||
const offCanvas = new Offcanvas(offCanvasEl, { scroll: false })
|
||||
const initialOverFlow = document.body.style.overflow
|
||||
|
||||
offCanvasEl.addEventListener('shown.bs.offcanvas', () => {
|
||||
expect(document.body.style.overflow).toEqual('hidden')
|
||||
|
||||
expect(ScrollBarHelper.prototype.hide).toHaveBeenCalled()
|
||||
offCanvas.hide()
|
||||
})
|
||||
offCanvasEl.addEventListener('hidden.bs.offcanvas', () => {
|
||||
expect(document.body.style.overflow).toEqual(initialOverFlow)
|
||||
expect(ScrollBarHelper.prototype.reset).toHaveBeenCalled()
|
||||
done()
|
||||
})
|
||||
offCanvas.show()
|
||||
|
Reference in New Issue
Block a user