Skip to content

Commit 229a4af

Browse files
committed
Put back 2 of the removed tests
Leaving these here for now. The test for removed tabs should be redone so that tabs are removed programmatically (as the approach of having that close button inside the link is invalid and broken markup). The test for dropdowns should be removed together we actually ripping out the handling for dropdowns in the tab.js code (arguably a breaking change, though we discouraged this for a few versions and effectively "deprecated" it)
1 parent a1aaa19 commit 229a4af

File tree

1 file changed

+72
-0
lines changed

1 file changed

+72
-0
lines changed

js/tests/unit/tab.spec.js

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,55 @@ describe('Tab', () => {
301301

302302
firstTab.show()
303303
})
304+
305+
it('should handle removed tabs', done => {
306+
fixtureEl.innerHTML = [
307+
'<ul class="nav nav-tabs" role="tablist">',
308+
' <li class="nav-item" role="presentation">',
309+
' <a class="nav-link nav-tab" href="#profile" role="tab" data-bs-toggle="tab">',
310+
' <button class="btn-close" aria-label="Close"></button>',
311+
' </a>',
312+
' </li>',
313+
' <li class="nav-item" role="presentation">',
314+
' <a id="secondNav" class="nav-link nav-tab" href="#buzz" role="tab" data-bs-toggle="tab">',
315+
' <button class="btn-close" aria-label="Close"></button>',
316+
' </a>',
317+
' </li>',
318+
' <li class="nav-item" role="presentation">',
319+
' <a class="nav-link nav-tab" href="#references" role="tab" data-bs-toggle="tab">',
320+
' <button id="btnClose" class="btn-close" aria-label="Close"></button>',
321+
' </a>',
322+
' </li>',
323+
'</ul>',
324+
'<div class="tab-content">',
325+
' <div role="tabpanel" class="tab-pane fade show active" id="profile">test 1</div>',
326+
' <div role="tabpanel" class="tab-pane fade" id="buzz">test 2</div>',
327+
' <div role="tabpanel" class="tab-pane fade" id="references">test 3</div>',
328+
'</div>'
329+
].join('')
330+
331+
const secondNavEl = fixtureEl.querySelector('#secondNav')
332+
const btnCloseEl = fixtureEl.querySelector('#btnClose')
333+
const secondNavTab = new Tab(secondNavEl)
334+
335+
secondNavEl.addEventListener('shown.bs.tab', () => {
336+
expect(fixtureEl.querySelectorAll('.nav-tab').length).toEqual(2)
337+
done()
338+
})
339+
340+
btnCloseEl.addEventListener('click', () => {
341+
const linkEl = btnCloseEl.parentNode
342+
const liEl = linkEl.parentNode
343+
const tabId = linkEl.getAttribute('href')
344+
const tabIdEl = fixtureEl.querySelector(tabId)
345+
346+
liEl.parentNode.removeChild(liEl)
347+
tabIdEl.parentNode.removeChild(tabIdEl)
348+
secondNavTab.show()
349+
})
350+
351+
btnCloseEl.click()
352+
})
304353
})
305354

306355
describe('dispose', () => {
@@ -418,6 +467,29 @@ describe('Tab', () => {
418467
secondTabTrigger.click()
419468
})
420469

470+
it('selected tab should deactivate previous selected link in dropdown', () => {
471+
fixtureEl.innerHTML = [
472+
'<ul class="nav nav-tabs">',
473+
' <li class="nav-item"><a class="nav-link" href="#home" data-bs-toggle="tab">Home</a></li>',
474+
' <li class="nav-item"><a class="nav-link" href="#profile" data-bs-toggle="tab">Profile</a></li>',
475+
' <li class="nav-item dropdown">',
476+
' <a class="nav-link dropdown-toggle active" data-bs-toggle="dropdown" href="#">Dropdown</a>',
477+
' <div class="dropdown-menu">',
478+
' <a class="dropdown-item active" href="#dropdown1" id="dropdown1-tab" data-bs-toggle="tab">@fat</a>',
479+
' <a class="dropdown-item" href="#dropdown2" id="dropdown2-tab" data-bs-toggle="tab">@mdo</a>',
480+
' </div>',
481+
' </li>',
482+
'</ul>'
483+
].join('')
484+
485+
const firstLiLinkEl = fixtureEl.querySelector('li:first-child a')
486+
487+
firstLiLinkEl.click()
488+
expect(firstLiLinkEl.classList.contains('active')).toEqual(true)
489+
expect(fixtureEl.querySelector('li:last-child a').classList.contains('active')).toEqual(false)
490+
expect(fixtureEl.querySelector('li:last-child .dropdown-menu a:first-child').classList.contains('active')).toEqual(false)
491+
})
492+
421493
it('should handle nested tabs', done => {
422494
fixtureEl.innerHTML = [
423495
'<nav class="nav nav-tabs" role="tablist">',

0 commit comments

Comments
 (0)