Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add missing test for clicking select option in a dropdown #33734

Merged
merged 2 commits into from
Apr 25, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions js/tests/unit/dropdown.spec.js
Original file line number Diff line number Diff line change
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