Skip to content

Commit

Permalink
add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
GeoSot committed Sep 15, 2022
1 parent fb6f4f6 commit 3fb0153
Showing 1 changed file with 29 additions and 2 deletions.
31 changes: 29 additions & 2 deletions js/tests/unit/tab.spec.js
Expand Up @@ -36,9 +36,7 @@ describe('Tab', () => {
expect(tabBySelector._element).toEqual(tabEl)
expect(tabByElement._element).toEqual(tabEl)
})
})

describe('constructor', () => {
it('Do not Throw exception if not parent', () => {
fixtureEl.innerHTML = [
fixtureEl.innerHTML = '<div class=""><div class="nav-link"></div></div>'
Expand Down Expand Up @@ -383,6 +381,35 @@ describe('Tab', () => {
btnCloseEl.click()
})
})

it('should not focus on opened tab', () => {
return new Promise(resolve => {
fixtureEl.innerHTML = [
'<ul class="nav" role="tablist">',
' <li><button type="button" id="home" data-bs-target="#home" role="tab">Home</button></li>',
' <li><button type="button" id="triggerProfile" data-bs-target="#profile" role="tab">Profile</button></li>',
'</ul>',
'<ul>',
' <li id="home" role="tabpanel"></li>',
' <li id="profile" role="tabpanel"></li>',
'</ul>'
].join('')

const firstTab = fixtureEl.querySelector('#home')
firstTab.focus()

const profileTriggerEl = fixtureEl.querySelector('#triggerProfile')
const tab = new Tab(profileTriggerEl)

profileTriggerEl.addEventListener('shown.bs.tab', () => {
expect(document.activeElement).toBe(firstTab)
expect(document.activeElement).not.toBe(profileTriggerEl)
resolve()
})

tab.show()
})
})
})

describe('dispose', () => {
Expand Down

0 comments on commit 3fb0153

Please sign in to comment.