Skip to content

Commit

Permalink
test: should not collapse the dropdown when clicking a select option …
Browse files Browse the repository at this point in the history
…in the dropdown

requested by GeoSot - #33643 (comment)
  • Loading branch information
alpadev committed Apr 23, 2021
1 parent b3916eb commit bd24116
Showing 1 changed file with 41 additions and 0 deletions.
41 changes: 41 additions & 0 deletions js/tests/unit/dropdown.spec.js
Expand Up @@ -1102,6 +1102,47 @@ describe('Dropdown', () => {
dropdown.show()
})

it('should not collapse the dropdown when clicking a select option nested in the dropdown', done => {
fixtureEl.innerHTML = [
'<div class="dropdown">',
' <button class="btn dropdown-toggle" data-bs-toggle="dropdown" aria-expanded="false">Dropdown</button>',
' <div class="dropdown-menu">',
' <select>',
' <option selected>Open this select menu</option>',
' <option value="1">One</option>',
' </select>',
' </div>',
'</div>'
].join('')

const btnDropdown = fixtureEl.querySelector('[data-bs-toggle="dropdown"]')
const dropdownMenu = fixtureEl.querySelector('.dropdown-menu')
const dropdown = new Dropdown(btnDropdown)

const hideSpy = spyOn(dropdown, '_completeHide')

btnDropdown.addEventListener('shown.bs.dropdown', () => {
const clickEvent = new MouseEvent('click', {
bubbles: true
})

dropdownMenu.querySelector('option').dispatchEvent(clickEvent)
})

dropdownMenu.addEventListener('click', event => {
expect(event.target.tagName).toMatch(/select|option/i)

Dropdown.clearMenus(event)

setTimeout(() => {
expect(hideSpy).not.toHaveBeenCalled()
done()
}, 10)
})

dropdown.show()
})

it('should manage bs attribute `data-bs-popper`="none" when dropdown is in navbar', done => {
fixtureEl.innerHTML = [
'<nav class="navbar navbar-expand-md navbar-light bg-light">',
Expand Down

0 comments on commit bd24116

Please sign in to comment.