diff options
author | Giovanni Mendoza <mendozagioo@gmail.com> | 2020-01-10 12:06:12 +0300 |
---|---|---|
committer | XhmikosR <xhmikosr@gmail.com> | 2020-01-10 12:06:12 +0300 |
commit | 954a0b1e6a206e4df910d4799d013f4388a2ef40 (patch) | |
tree | 59e1d72bc0452427421b7f856d57eeecd48b6b5e /js/tests | |
parent | 4e1fb4fe1a4e968d83d8f62007b9354e2811eb63 (diff) |
Close modal with keyboard=true & backdrop=static (#29986)
* Close modal with keyboard=true & backdrop=static
Diffstat (limited to 'js/tests')
-rw-r--r-- | js/tests/unit/modal.spec.js | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/js/tests/unit/modal.spec.js b/js/tests/unit/modal.spec.js index 2edef22b2c..b4923ab3f4 100644 --- a/js/tests/unit/modal.spec.js +++ b/js/tests/unit/modal.spec.js @@ -567,6 +567,64 @@ describe('Modal', () => { modal.show() }) + it('should close modal when escape key is pressed with keyboard = true and backdrop is static', done => { + fixtureEl.innerHTML = '<div class="modal" data-backdrop="static"><div class="modal-dialog" /></div>' + + const modalEl = fixtureEl.querySelector('.modal') + const modal = new Modal(modalEl, { + backdrop: 'static', + keyboard: true + }) + + const shownCallback = () => { + setTimeout(() => { + expect(modal._isShown).toEqual(false) + done() + }, 10) + } + + modalEl.addEventListener('shown.bs.modal', () => { + const keydownEscape = createEvent('keydown') + keydownEscape.which = 27 + + modalEl.dispatchEvent(keydownEscape) + shownCallback() + }) + + modal.show() + }) + + it('should not close modal when escape key is pressed with keyboard = false and backdrop = static', done => { + fixtureEl.innerHTML = '<div class="modal" data-backdrop="static" data-keyboard="false"><div class="modal-dialog" /></div>' + + const modalEl = fixtureEl.querySelector('.modal') + const modal = new Modal(modalEl, { + backdrop: 'static', + keyboard: false + }) + + const shownCallback = () => { + setTimeout(() => { + expect(modal._isShown).toEqual(true) + done() + }, 10) + } + + modalEl.addEventListener('shown.bs.modal', () => { + const keydownEscape = createEvent('keydown') + keydownEscape.which = 27 + + modalEl.dispatchEvent(keydownEscape) + shownCallback() + }) + + modalEl.addEventListener('hidden.bs.modal', () => { + throw new Error('Should not hide a modal') + }) + + modal.show() + }) + it('should not adjust the inline body padding when it does not overflow', done => { fixtureEl.innerHTML = '<div class="modal"><div class="modal-dialog" /></div>' |