mirror of
https://github.com/twbs/bootstrap.git
synced 2025-08-31 00:59:51 +02:00
Merge branch 'main' into main-lmp-add-dropdown-cycling
This commit is contained in:
@@ -2,7 +2,9 @@ import Carousel from '../../src/carousel.js'
|
||||
import EventHandler from '../../src/dom/event-handler.js'
|
||||
import { isRTL, noop } from '../../src/util/index.js'
|
||||
import Swipe from '../../src/util/swipe.js'
|
||||
import { clearFixture, createEvent, getFixture, jQueryMock } from '../helpers/fixture.js'
|
||||
import {
|
||||
clearFixture, createEvent, getFixture, jQueryMock
|
||||
} from '../helpers/fixture.js'
|
||||
|
||||
describe('Carousel', () => {
|
||||
const { Simulator, PointerEvent } = window
|
||||
|
@@ -359,6 +359,30 @@ describe('SelectorEngine', () => {
|
||||
expect(SelectorEngine.getMultipleElementsFromSelector(testEl)).toEqual(Array.from(fixtureEl.querySelectorAll('.target')))
|
||||
})
|
||||
|
||||
it('should get elements if several ids are given', () => {
|
||||
fixtureEl.innerHTML = [
|
||||
'<div id="test" data-bs-target="#target1,#target2"></div>',
|
||||
'<div class="target" id="target1"></div>',
|
||||
'<div class="target" id="target2"></div>'
|
||||
].join('')
|
||||
|
||||
const testEl = fixtureEl.querySelector('#test')
|
||||
|
||||
expect(SelectorEngine.getMultipleElementsFromSelector(testEl)).toEqual(Array.from(fixtureEl.querySelectorAll('.target')))
|
||||
})
|
||||
|
||||
it('should get elements if several ids with special chars are given', () => {
|
||||
fixtureEl.innerHTML = [
|
||||
'<div id="test" data-bs-target="#j_id11:exampleModal,#j_id22:exampleModal"></div>',
|
||||
'<div class="target" id="j_id11:exampleModal"></div>',
|
||||
'<div class="target" id="j_id22:exampleModal"></div>'
|
||||
].join('')
|
||||
|
||||
const testEl = fixtureEl.querySelector('#test')
|
||||
|
||||
expect(SelectorEngine.getMultipleElementsFromSelector(testEl)).toEqual(Array.from(fixtureEl.querySelectorAll('.target')))
|
||||
})
|
||||
|
||||
it('should get elements in array, from href if no data-bs-target set', () => {
|
||||
fixtureEl.innerHTML = [
|
||||
'<a id="test" href=".target"></a>',
|
||||
|
@@ -1,7 +1,9 @@
|
||||
import EventHandler from '../../src/dom/event-handler.js'
|
||||
import Dropdown from '../../src/dropdown.js'
|
||||
import { noop } from '../../src/util/index.js'
|
||||
import { clearFixture, createEvent, getFixture, jQueryMock } from '../helpers/fixture.js'
|
||||
import {
|
||||
clearFixture, createEvent, getFixture, jQueryMock
|
||||
} from '../helpers/fixture.js'
|
||||
|
||||
describe('Dropdown', () => {
|
||||
let fixtureEl
|
||||
@@ -170,7 +172,10 @@ describe('Dropdown', () => {
|
||||
|
||||
const popperConfig = dropdown._getPopperConfig()
|
||||
|
||||
expect(getPopperConfig).toHaveBeenCalled()
|
||||
// Ensure that the function was called with the default config.
|
||||
expect(getPopperConfig).toHaveBeenCalledWith(jasmine.objectContaining({
|
||||
placement: jasmine.any(String)
|
||||
}))
|
||||
expect(popperConfig.placement).toEqual('left')
|
||||
})
|
||||
})
|
||||
|
@@ -1,7 +1,9 @@
|
||||
import EventHandler from '../../src/dom/event-handler.js'
|
||||
import Modal from '../../src/modal.js'
|
||||
import ScrollBarHelper from '../../src/util/scrollbar.js'
|
||||
import { clearBodyAndDocument, clearFixture, createEvent, getFixture, jQueryMock } from '../helpers/fixture.js'
|
||||
import {
|
||||
clearBodyAndDocument, clearFixture, createEvent, getFixture, jQueryMock
|
||||
} from '../helpers/fixture.js'
|
||||
|
||||
describe('Modal', () => {
|
||||
let fixtureEl
|
||||
@@ -989,6 +991,35 @@ describe('Modal', () => {
|
||||
trigger.click()
|
||||
})
|
||||
})
|
||||
|
||||
it('should open modal, having special characters in its id', () => {
|
||||
return new Promise(resolve => {
|
||||
fixtureEl.innerHTML = [
|
||||
'<button class="btn btn-primary" data-bs-toggle="modal" data-bs-target="#j_id22:exampleModal">',
|
||||
' Launch demo modal',
|
||||
'</button>',
|
||||
'<div class="modal fade" id="j_id22:exampleModal" aria-labelledby="exampleModalLabel" aria-hidden="true">',
|
||||
' <div class="modal-dialog">',
|
||||
' <div class="modal-content">',
|
||||
' <div class="modal-body">',
|
||||
' <p>modal body</p>',
|
||||
' </div>',
|
||||
' </div>',
|
||||
' </div>',
|
||||
'</div>'
|
||||
].join('')
|
||||
|
||||
const modalEl = fixtureEl.querySelector('.modal')
|
||||
const trigger = fixtureEl.querySelector('[data-bs-toggle="modal"]')
|
||||
|
||||
modalEl.addEventListener('shown.bs.modal', () => {
|
||||
resolve()
|
||||
})
|
||||
|
||||
trigger.click()
|
||||
})
|
||||
})
|
||||
|
||||
it('should not prevent default when a click occurred on data-bs-dismiss="modal" where tagName is DIFFERENT than <a> or <area>', () => {
|
||||
return new Promise(resolve => {
|
||||
fixtureEl.innerHTML = [
|
||||
|
@@ -2,7 +2,9 @@ import EventHandler from '../../src/dom/event-handler.js'
|
||||
import Offcanvas from '../../src/offcanvas.js'
|
||||
import { isVisible } from '../../src/util/index.js'
|
||||
import ScrollBarHelper from '../../src/util/scrollbar.js'
|
||||
import { clearBodyAndDocument, clearFixture, createEvent, getFixture, jQueryMock } from '../helpers/fixture.js'
|
||||
import {
|
||||
clearBodyAndDocument, clearFixture, createEvent, getFixture, jQueryMock
|
||||
} from '../helpers/fixture.js'
|
||||
|
||||
describe('Offcanvas', () => {
|
||||
let fixtureEl
|
||||
|
@@ -95,6 +95,60 @@ describe('Popover', () => {
|
||||
})
|
||||
})
|
||||
|
||||
it('should call content and title functions with trigger element', () => {
|
||||
return new Promise(resolve => {
|
||||
fixtureEl.innerHTML = '<a href="#" data-foo="bar">BS twitter</a>'
|
||||
|
||||
const popoverEl = fixtureEl.querySelector('a')
|
||||
const popover = new Popover(popoverEl, {
|
||||
title(el) {
|
||||
return el.dataset.foo
|
||||
},
|
||||
content(el) {
|
||||
return el.dataset.foo
|
||||
}
|
||||
})
|
||||
|
||||
popoverEl.addEventListener('shown.bs.popover', () => {
|
||||
const popoverDisplayed = document.querySelector('.popover')
|
||||
|
||||
expect(popoverDisplayed).not.toBeNull()
|
||||
expect(popoverDisplayed.querySelector('.popover-header').textContent).toEqual('bar')
|
||||
expect(popoverDisplayed.querySelector('.popover-body').textContent).toEqual('bar')
|
||||
resolve()
|
||||
})
|
||||
|
||||
popover.show()
|
||||
})
|
||||
})
|
||||
|
||||
it('should call content and title functions with correct this value', () => {
|
||||
return new Promise(resolve => {
|
||||
fixtureEl.innerHTML = '<a href="#" data-foo="bar">BS twitter</a>'
|
||||
|
||||
const popoverEl = fixtureEl.querySelector('a')
|
||||
const popover = new Popover(popoverEl, {
|
||||
title() {
|
||||
return this.dataset.foo
|
||||
},
|
||||
content() {
|
||||
return this.dataset.foo
|
||||
}
|
||||
})
|
||||
|
||||
popoverEl.addEventListener('shown.bs.popover', () => {
|
||||
const popoverDisplayed = document.querySelector('.popover')
|
||||
|
||||
expect(popoverDisplayed).not.toBeNull()
|
||||
expect(popoverDisplayed.querySelector('.popover-header').textContent).toEqual('bar')
|
||||
expect(popoverDisplayed.querySelector('.popover-body').textContent).toEqual('bar')
|
||||
resolve()
|
||||
})
|
||||
|
||||
popover.show()
|
||||
})
|
||||
})
|
||||
|
||||
it('should show a popover with just content without having header', () => {
|
||||
return new Promise(resolve => {
|
||||
fixtureEl.innerHTML = '<a href="#">Nice link</a>'
|
||||
|
@@ -1,6 +1,8 @@
|
||||
import EventHandler from '../../src/dom/event-handler.js'
|
||||
import ScrollSpy from '../../src/scrollspy.js'
|
||||
import { clearFixture, createEvent, getFixture, jQueryMock } from '../helpers/fixture.js'
|
||||
import {
|
||||
clearFixture, createEvent, getFixture, jQueryMock
|
||||
} from '../helpers/fixture.js'
|
||||
|
||||
describe('ScrollSpy', () => {
|
||||
let fixtureEl
|
||||
|
@@ -1,5 +1,7 @@
|
||||
import Tab from '../../src/tab.js'
|
||||
import { clearFixture, createEvent, getFixture, jQueryMock } from '../helpers/fixture.js'
|
||||
import {
|
||||
clearFixture, createEvent, getFixture, jQueryMock
|
||||
} from '../helpers/fixture.js'
|
||||
|
||||
describe('Tab', () => {
|
||||
let fixtureEl
|
||||
@@ -630,6 +632,58 @@ describe('Tab', () => {
|
||||
expect(spyPrevent).toHaveBeenCalledTimes(2)
|
||||
})
|
||||
|
||||
it('if keydown event is Home, handle it', () => {
|
||||
fixtureEl.innerHTML = [
|
||||
'<div class="nav">',
|
||||
' <span id="tab1" class="nav-link" data-bs-toggle="tab"></span>',
|
||||
' <span id="tab2" class="nav-link" data-bs-toggle="tab"></span>',
|
||||
' <span id="tab3" class="nav-link" data-bs-toggle="tab"></span>',
|
||||
'</div>'
|
||||
].join('')
|
||||
|
||||
const tabEl1 = fixtureEl.querySelector('#tab1')
|
||||
const tabEl3 = fixtureEl.querySelector('#tab3')
|
||||
|
||||
const tab3 = new Tab(tabEl3)
|
||||
tab3.show()
|
||||
|
||||
const spyShown = jasmine.createSpy()
|
||||
tabEl1.addEventListener('shown.bs.tab', spyShown)
|
||||
|
||||
const keydown = createEvent('keydown')
|
||||
keydown.key = 'Home'
|
||||
|
||||
tabEl3.dispatchEvent(keydown)
|
||||
|
||||
expect(spyShown).toHaveBeenCalled()
|
||||
})
|
||||
|
||||
it('if keydown event is End, handle it', () => {
|
||||
fixtureEl.innerHTML = [
|
||||
'<div class="nav">',
|
||||
' <span id="tab1" class="nav-link" data-bs-toggle="tab"></span>',
|
||||
' <span id="tab2" class="nav-link" data-bs-toggle="tab"></span>',
|
||||
' <span id="tab3" class="nav-link" data-bs-toggle="tab"></span>',
|
||||
'</div>'
|
||||
].join('')
|
||||
|
||||
const tabEl1 = fixtureEl.querySelector('#tab1')
|
||||
const tabEl3 = fixtureEl.querySelector('#tab3')
|
||||
|
||||
const tab1 = new Tab(tabEl1)
|
||||
tab1.show()
|
||||
|
||||
const spyShown = jasmine.createSpy()
|
||||
tabEl3.addEventListener('shown.bs.tab', spyShown)
|
||||
|
||||
const keydown = createEvent('keydown')
|
||||
keydown.key = 'End'
|
||||
|
||||
tabEl1.dispatchEvent(keydown)
|
||||
|
||||
expect(spyShown).toHaveBeenCalled()
|
||||
})
|
||||
|
||||
it('if keydown event is right arrow and next element is disabled', () => {
|
||||
fixtureEl.innerHTML = [
|
||||
'<div class="nav">',
|
||||
@@ -711,6 +765,66 @@ describe('Tab', () => {
|
||||
expect(spyFocus2).not.toHaveBeenCalled()
|
||||
expect(spyFocus1).toHaveBeenCalledTimes(1)
|
||||
})
|
||||
|
||||
it('if keydown event is Home and first element is disabled', () => {
|
||||
fixtureEl.innerHTML = [
|
||||
'<div class="nav">',
|
||||
' <span id="tab1" class="nav-link disabled" data-bs-toggle="tab" disabled></span>',
|
||||
' <span id="tab2" class="nav-link" data-bs-toggle="tab"></span>',
|
||||
' <span id="tab3" class="nav-link" data-bs-toggle="tab"></span>',
|
||||
'</div>'
|
||||
].join('')
|
||||
|
||||
const tabEl1 = fixtureEl.querySelector('#tab1')
|
||||
const tabEl2 = fixtureEl.querySelector('#tab2')
|
||||
const tabEl3 = fixtureEl.querySelector('#tab3')
|
||||
const tab3 = new Tab(tabEl3)
|
||||
|
||||
tab3.show()
|
||||
|
||||
const spyShown1 = jasmine.createSpy()
|
||||
const spyShown2 = jasmine.createSpy()
|
||||
tabEl1.addEventListener('shown.bs.tab', spyShown1)
|
||||
tabEl2.addEventListener('shown.bs.tab', spyShown2)
|
||||
|
||||
const keydown = createEvent('keydown')
|
||||
keydown.key = 'Home'
|
||||
|
||||
tabEl3.dispatchEvent(keydown)
|
||||
|
||||
expect(spyShown1).not.toHaveBeenCalled()
|
||||
expect(spyShown2).toHaveBeenCalled()
|
||||
})
|
||||
|
||||
it('if keydown event is End and last element is disabled', () => {
|
||||
fixtureEl.innerHTML = [
|
||||
'<div class="nav">',
|
||||
' <span id="tab1" class="nav-link" data-bs-toggle="tab"></span>',
|
||||
' <span id="tab2" class="nav-link" data-bs-toggle="tab"></span>',
|
||||
' <span id="tab3" class="nav-link" data-bs-toggle="tab" disabled></span>',
|
||||
'</div>'
|
||||
].join('')
|
||||
|
||||
const tabEl1 = fixtureEl.querySelector('#tab1')
|
||||
const tabEl2 = fixtureEl.querySelector('#tab2')
|
||||
const tabEl3 = fixtureEl.querySelector('#tab3')
|
||||
const tab1 = new Tab(tabEl1)
|
||||
|
||||
tab1.show()
|
||||
|
||||
const spyShown2 = jasmine.createSpy()
|
||||
const spyShown3 = jasmine.createSpy()
|
||||
tabEl2.addEventListener('shown.bs.tab', spyShown2)
|
||||
tabEl3.addEventListener('shown.bs.tab', spyShown3)
|
||||
|
||||
const keydown = createEvent('keydown')
|
||||
keydown.key = 'End'
|
||||
|
||||
tabEl1.dispatchEvent(keydown)
|
||||
|
||||
expect(spyShown3).not.toHaveBeenCalled()
|
||||
expect(spyShown2).toHaveBeenCalled()
|
||||
})
|
||||
})
|
||||
|
||||
describe('jQueryInterface', () => {
|
||||
|
@@ -1,5 +1,7 @@
|
||||
import Toast from '../../src/toast.js'
|
||||
import { clearFixture, createEvent, getFixture, jQueryMock } from '../helpers/fixture.js'
|
||||
import {
|
||||
clearFixture, createEvent, getFixture, jQueryMock
|
||||
} from '../helpers/fixture.js'
|
||||
|
||||
describe('Toast', () => {
|
||||
let fixtureEl
|
||||
|
@@ -1,7 +1,9 @@
|
||||
import EventHandler from '../../src/dom/event-handler.js'
|
||||
import Tooltip from '../../src/tooltip.js'
|
||||
import { noop } from '../../src/util/index.js'
|
||||
import { clearFixture, createEvent, getFixture, jQueryMock } from '../helpers/fixture.js'
|
||||
import {
|
||||
clearFixture, createEvent, getFixture, jQueryMock
|
||||
} from '../helpers/fixture.js'
|
||||
|
||||
describe('Tooltip', () => {
|
||||
let fixtureEl
|
||||
@@ -175,7 +177,10 @@ describe('Tooltip', () => {
|
||||
|
||||
const popperConfig = tooltip._getPopperConfig('top')
|
||||
|
||||
expect(getPopperConfig).toHaveBeenCalled()
|
||||
// Ensure that the function was called with the default config.
|
||||
expect(getPopperConfig).toHaveBeenCalledWith(jasmine.objectContaining({
|
||||
placement: jasmine.any(String)
|
||||
}))
|
||||
expect(popperConfig.placement).toEqual('left')
|
||||
})
|
||||
|
||||
@@ -917,10 +922,12 @@ describe('Tooltip', () => {
|
||||
|
||||
it('should show a tooltip with custom class provided as a function in config', () => {
|
||||
return new Promise(resolve => {
|
||||
fixtureEl.innerHTML = '<a href="#" rel="tooltip" title="Another tooltip"></a>'
|
||||
fixtureEl.innerHTML = '<a href="#" rel="tooltip" title="Another tooltip" data-class-a="custom-class-a" data-class-b="custom-class-b"></a>'
|
||||
|
||||
const spy = jasmine.createSpy('customClass').and.returnValue('custom-class')
|
||||
const tooltipEl = fixtureEl.querySelector('a')
|
||||
const spy = jasmine.createSpy('customClass').and.callFake(function (el) {
|
||||
return `${el.dataset.classA} ${this.dataset.classB}`
|
||||
})
|
||||
const tooltip = new Tooltip(tooltipEl, {
|
||||
customClass: spy
|
||||
})
|
||||
@@ -929,7 +936,8 @@ describe('Tooltip', () => {
|
||||
const tip = document.querySelector('.tooltip')
|
||||
expect(tip).not.toBeNull()
|
||||
expect(spy).toHaveBeenCalled()
|
||||
expect(tip).toHaveClass('custom-class')
|
||||
expect(tip).toHaveClass('custom-class-a')
|
||||
expect(tip).toHaveClass('custom-class-b')
|
||||
resolve()
|
||||
})
|
||||
|
||||
@@ -1335,6 +1343,32 @@ describe('Tooltip', () => {
|
||||
|
||||
expect(tooltip._getTitle()).toEqual('test')
|
||||
})
|
||||
|
||||
it('should call title function with trigger element', () => {
|
||||
fixtureEl.innerHTML = '<a href="#" rel="tooltip" data-foo="bar"></a>'
|
||||
|
||||
const tooltipEl = fixtureEl.querySelector('a')
|
||||
const tooltip = new Tooltip(tooltipEl, {
|
||||
title(el) {
|
||||
return el.dataset.foo
|
||||
}
|
||||
})
|
||||
|
||||
expect(tooltip._getTitle()).toEqual('bar')
|
||||
})
|
||||
|
||||
it('should call title function with correct this value', () => {
|
||||
fixtureEl.innerHTML = '<a href="#" rel="tooltip" data-foo="bar"></a>'
|
||||
|
||||
const tooltipEl = fixtureEl.querySelector('a')
|
||||
const tooltip = new Tooltip(tooltipEl, {
|
||||
title() {
|
||||
return this.dataset.foo
|
||||
}
|
||||
})
|
||||
|
||||
expect(tooltip._getTitle()).toEqual('bar')
|
||||
})
|
||||
})
|
||||
|
||||
describe('getInstance', () => {
|
||||
|
@@ -521,10 +521,10 @@ describe('Util', () => {
|
||||
|
||||
it('should execute if arg is function & return the result', () => {
|
||||
const functionFoo = (num1, num2 = 10) => num1 + num2
|
||||
const resultFoo = Util.execute(functionFoo, [4, 5])
|
||||
const resultFoo = Util.execute(functionFoo, [undefined, 4, 5])
|
||||
expect(resultFoo).toBe(9)
|
||||
|
||||
const resultFoo1 = Util.execute(functionFoo, [4])
|
||||
const resultFoo1 = Util.execute(functionFoo, [undefined, 4])
|
||||
expect(resultFoo1).toBe(14)
|
||||
|
||||
const functionBar = () => 'foo'
|
||||
|
Reference in New Issue
Block a user