Skip to content

Commit

Permalink
add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mdo committed Feb 28, 2022
1 parent c0f3036 commit 7a74f2c
Showing 1 changed file with 49 additions and 0 deletions.
49 changes: 49 additions & 0 deletions js/tests/unit/dropdown.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,30 @@ describe('Dropdown', () => {
})
})

it('should toggle a centered dropdown', () => {
return new Promise(resolve => {
fixtureEl.innerHTML = [
'<div class="dropdown-center">',
' <button class="btn dropdown-toggle" data-bs-toggle="dropdown" aria-expanded="false">Dropdown</button>',
' <div class="dropdown-menu">',
' <a class="dropdown-item" href="#">Secondary link</a>',
' </div>',
'</div>'
].join('')

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

btnDropdown.addEventListener('shown.bs.dropdown', () => {
expect(btnDropdown).toHaveClass('show')
expect(btnDropdown.getAttribute('aria-expanded')).toEqual('true')
resolve()
})

dropdown.toggle()
})
})

it('should toggle a dropup', () => {
return new Promise(resolve => {
fixtureEl.innerHTML = [
Expand All @@ -304,6 +328,31 @@ describe('Dropdown', () => {
})
})

it('should toggle a dropup centered', () => {
return new Promise(resolve => {
fixtureEl.innerHTML = [
'<div class="dropup-center">',
' <button class="btn dropdown-toggle" data-bs-toggle="dropdown" aria-expanded="false">Dropdown</button>',
' <div class="dropdown-menu">',
' <a class="dropdown-item" href="#">Secondary link</a>',
' </div>',
'</div>'
].join('')

const btnDropdown = fixtureEl.querySelector('[data-bs-toggle="dropdown"]')
const dropupEl = fixtureEl.querySelector('.dropup-center')
const dropdown = new Dropdown(btnDropdown)

dropupEl.addEventListener('shown.bs.dropdown', () => {
expect(btnDropdown).toHaveClass('show')
expect(btnDropdown.getAttribute('aria-expanded')).toEqual('true')
resolve()
})

dropdown.toggle()
})
})

it('should toggle a dropup at the right', () => {
return new Promise(resolve => {
fixtureEl.innerHTML = [
Expand Down

0 comments on commit 7a74f2c

Please sign in to comment.