Add tests

Co-authored-by: Nathan Sarang-Walters <nwalters512@gmail.com>
This commit is contained in:
Julien Déramond 2024-08-08 07:14:03 +02:00
parent 8fb67874c5
commit eac65566da
No known key found for this signature in database
GPG Key ID: DCD226672FC08F31
2 changed files with 90 additions and 0 deletions

View File

@ -178,6 +178,58 @@ describe('Dropdown', () => {
}))
expect(popperConfig.placement).toEqual('left')
})
it('should reflect strategy option in the constructor', () => {
return new Promise(resolve => {
fixtureEl.innerHTML = [
'<div class="dropdown">',
' <button class="btn dropdown-toggle" data-bs-toggle="dropdown">Dropdown</button>',
' <div class="dropdown-menu">',
' <a class="dropdown-item" href="#">Link</a>',
' </div>',
'</div>'
].join('')
const btnDropdown = fixtureEl.querySelector('[data-bs-toggle="dropdown"]')
const dropdown = new Dropdown(btnDropdown, {
strategy: 'fixed'
})
btnDropdown.addEventListener('shown.bs.dropdown', () => {
const dropdownMenu = document.querySelector('.dropdown-menu')
expect(dropdownMenu).not.toBeNull()
expect(dropdownMenu.computedStyleMap().get('position').value).toEqual('fixed')
resolve()
})
dropdown.toggle()
})
})
it('should reflect strategy option in data attribute', () => {
return new Promise(resolve => {
fixtureEl.innerHTML = [
'<div class="dropdown">',
' <button class="btn dropdown-toggle" data-bs-toggle="dropdown" data-bs-strategy="fixed">Dropdown</button>',
' <div class="dropdown-menu">',
' <a class="dropdown-item" href="#">Link</a>',
' </div>',
'</div>'
].join('')
const btnDropdown = fixtureEl.querySelector('[data-bs-toggle="dropdown"]')
const dropdown = new Dropdown(btnDropdown)
btnDropdown.addEventListener('shown.bs.dropdown', () => {
const dropdownMenu = document.querySelector('.dropdown-menu')
expect(dropdownMenu).not.toBeNull()
expect(dropdownMenu.computedStyleMap().get('position').value).toEqual('fixed')
resolve()
})
dropdown.toggle()
})
})
})
describe('toggle', () => {

View File

@ -959,6 +959,44 @@ describe('Tooltip', () => {
tooltip.show()
})
})
it('should reflect strategy option in the constructor', () => {
return new Promise(resolve => {
fixtureEl.innerHTML = '<a href="#" rel="tooltip" title="Another tooltip">'
const tooltipEl = fixtureEl.querySelector('a')
const tooltip = new Tooltip(tooltipEl, {
strategy: 'fixed'
})
tooltipEl.addEventListener('shown.bs.tooltip', () => {
const tip = document.querySelector('.tooltip')
expect(tip).not.toBeNull()
expect(tip.computedStyleMap().get('position').value).toEqual('fixed')
resolve()
})
tooltip.show()
})
})
it('should reflect strategy option in data attribute', () => {
return new Promise(resolve => {
fixtureEl.innerHTML = '<a href="#" rel="tooltip" title="Another tooltip" data-bs-strategy="fixed"></a>'
const tooltipEl = fixtureEl.querySelector('a')
const tooltip = new Tooltip(tooltipEl)
tooltipEl.addEventListener('shown.bs.tooltip', () => {
const tip = document.querySelector('.tooltip')
expect(tip).not.toBeNull()
expect(tip.computedStyleMap().get('position').value).toEqual('fixed')
resolve()
})
tooltip.show()
})
})
})
describe('hide', () => {