aboutsummaryrefslogtreecommitdiff
path: root/js/tests
diff options
context:
space:
mode:
authorMartijn Cuppens <[email protected]>2020-02-01 14:56:20 +0100
committerMartijn Cuppens <[email protected]>2020-03-23 15:35:07 +0100
commit2e150e722a946f20ded62b39abe28f244f6ae050 (patch)
treeb8e23908d7a08583f56367aa5190f68747dd345e /js/tests
parent85b12549ecff83f866588394ecff747e69567bc4 (diff)
downloadbootstrap-2e150e722a946f20ded62b39abe28f244f6ae050.tar.xz
bootstrap-2e150e722a946f20ded62b39abe28f244f6ae050.zip
Use next dropdown menu instead of first of the parent
Diffstat (limited to 'js/tests')
-rw-r--r--js/tests/unit/dom/selector-engine.spec.js39
-rw-r--r--js/tests/unit/dropdown.spec.js54
2 files changed, 66 insertions, 27 deletions
diff --git a/js/tests/unit/dom/selector-engine.spec.js b/js/tests/unit/dom/selector-engine.spec.js
index e140c6a3e..727f10621 100644
--- a/js/tests/unit/dom/selector-engine.spec.js
+++ b/js/tests/unit/dom/selector-engine.spec.js
@@ -126,5 +126,44 @@ describe('SelectorEngine', () => {
expect(SelectorEngine.prev(btn, '.test')).toEqual([divTest])
})
})
+
+ describe('next', () => {
+ it('should return next element', () => {
+ fixtureEl.innerHTML = '<div class="test"></div><button class="btn"></button>'
+
+ const btn = fixtureEl.querySelector('.btn')
+ const divTest = fixtureEl.querySelector('.test')
+
+ expect(SelectorEngine.next(divTest, '.btn')).toEqual([btn])
+ })
+
+ it('should return next element with an extra element between', () => {
+ fixtureEl.innerHTML = [
+ '<div class="test"></div>',
+ '<span></span>',
+ '<button class="btn"></button>'
+ ].join('')
+
+ const btn = fixtureEl.querySelector('.btn')
+ const divTest = fixtureEl.querySelector('.test')
+
+ expect(SelectorEngine.next(divTest, '.btn')).toEqual([btn])
+ })
+
+ it('should return next element with comments or text nodes between', () => {
+ fixtureEl.innerHTML = [
+ '<div class="test"></div>',
+ '<!-- Comment-->',
+ 'Text',
+ '<button class="btn"></button>',
+ '<button class="btn"></button>'
+ ].join('')
+
+ const btn = fixtureEl.querySelector('.btn')
+ const divTest = fixtureEl.querySelector('.test')
+
+ expect(SelectorEngine.next(divTest, '.btn')).toEqual([btn])
+ })
+ })
})
diff --git a/js/tests/unit/dropdown.spec.js b/js/tests/unit/dropdown.spec.js
index 2762ad21b..e8a7e66ba 100644
--- a/js/tests/unit/dropdown.spec.js
+++ b/js/tests/unit/dropdown.spec.js
@@ -139,7 +139,7 @@ describe('Dropdown', () => {
const dropdown = new Dropdown(btnDropdown)
dropdownEl.addEventListener('shown.bs.dropdown', () => {
- expect(dropdownEl.classList.contains('show')).toEqual(true)
+ expect(btnDropdown.classList.contains('show')).toEqual(true)
expect(btnDropdown.getAttribute('aria-expanded')).toEqual('true')
done()
})
@@ -171,7 +171,7 @@ describe('Dropdown', () => {
const dropdown2 = new Dropdown(btnDropdown2)
firstDropdownEl.addEventListener('shown.bs.dropdown', () => {
- expect(firstDropdownEl.classList.contains('show')).toEqual(true)
+ expect(btnDropdown1.classList.contains('show')).toEqual(true)
spyOn(dropdown1._popper, 'destroy')
dropdown2.toggle()
})
@@ -204,7 +204,7 @@ describe('Dropdown', () => {
spyOn(EventHandler, 'off')
dropdownEl.addEventListener('shown.bs.dropdown', () => {
- expect(dropdownEl.classList.contains('show')).toEqual(true)
+ expect(btnDropdown.classList.contains('show')).toEqual(true)
expect(btnDropdown.getAttribute('aria-expanded')).toEqual('true')
expect(EventHandler.on).toHaveBeenCalled()
@@ -212,7 +212,7 @@ describe('Dropdown', () => {
})
dropdownEl.addEventListener('hidden.bs.dropdown', () => {
- expect(dropdownEl.classList.contains('show')).toEqual(false)
+ expect(btnDropdown.classList.contains('show')).toEqual(false)
expect(btnDropdown.getAttribute('aria-expanded')).toEqual('false')
expect(EventHandler.off).toHaveBeenCalled()
@@ -238,7 +238,7 @@ describe('Dropdown', () => {
const dropdown = new Dropdown(btnDropdown)
dropdownEl.addEventListener('shown.bs.dropdown', () => {
- expect(dropdownEl.classList.contains('show')).toEqual(true)
+ expect(btnDropdown.classList.contains('show')).toEqual(true)
expect(btnDropdown.getAttribute('aria-expanded')).toEqual('true')
done()
})
@@ -261,7 +261,7 @@ describe('Dropdown', () => {
const dropdown = new Dropdown(btnDropdown)
dropupEl.addEventListener('shown.bs.dropdown', () => {
- expect(dropupEl.classList.contains('show')).toEqual(true)
+ expect(btnDropdown.classList.contains('show')).toEqual(true)
expect(btnDropdown.getAttribute('aria-expanded')).toEqual('true')
done()
})
@@ -284,7 +284,7 @@ describe('Dropdown', () => {
const dropdown = new Dropdown(btnDropdown)
dropupEl.addEventListener('shown.bs.dropdown', () => {
- expect(dropupEl.classList.contains('show')).toEqual(true)
+ expect(btnDropdown.classList.contains('show')).toEqual(true)
expect(btnDropdown.getAttribute('aria-expanded')).toEqual('true')
done()
})
@@ -307,7 +307,7 @@ describe('Dropdown', () => {
const dropdown = new Dropdown(btnDropdown)
droprightEl.addEventListener('shown.bs.dropdown', () => {
- expect(droprightEl.classList.contains('show')).toEqual(true)
+ expect(btnDropdown.classList.contains('show')).toEqual(true)
expect(btnDropdown.getAttribute('aria-expanded')).toEqual('true')
done()
})
@@ -330,7 +330,7 @@ describe('Dropdown', () => {
const dropdown = new Dropdown(btnDropdown)
dropleftEl.addEventListener('shown.bs.dropdown', () => {
- expect(dropleftEl.classList.contains('show')).toEqual(true)
+ expect(btnDropdown.classList.contains('show')).toEqual(true)
expect(btnDropdown.getAttribute('aria-expanded')).toEqual('true')
done()
})
@@ -355,7 +355,7 @@ describe('Dropdown', () => {
})
dropdownEl.addEventListener('shown.bs.dropdown', () => {
- expect(dropdownEl.classList.contains('show')).toEqual(true)
+ expect(btnDropdown.classList.contains('show')).toEqual(true)
expect(btnDropdown.getAttribute('aria-expanded')).toEqual('true')
done()
})
@@ -380,7 +380,7 @@ describe('Dropdown', () => {
})
dropdownEl.addEventListener('shown.bs.dropdown', () => {
- expect(dropdownEl.classList.contains('show')).toEqual(true)
+ expect(btnDropdown.classList.contains('show')).toEqual(true)
expect(btnDropdown.getAttribute('aria-expanded')).toEqual('true')
done()
})
@@ -405,7 +405,7 @@ describe('Dropdown', () => {
})
dropdownEl.addEventListener('shown.bs.dropdown', () => {
- expect(dropdownEl.classList.contains('show')).toEqual(true)
+ expect(btnDropdown.classList.contains('show')).toEqual(true)
expect(btnDropdown.getAttribute('aria-expanded')).toEqual('true')
done()
})
@@ -538,7 +538,7 @@ describe('Dropdown', () => {
const dropdown = new Dropdown(btnDropdown)
dropdownEl.addEventListener('shown.bs.dropdown', () => {
- expect(dropdownEl.classList.contains('show')).toEqual(true)
+ expect(btnDropdown.classList.contains('show')).toEqual(true)
done()
})
@@ -983,7 +983,7 @@ describe('Dropdown', () => {
})
dropdownEl.addEventListener('shown.bs.dropdown', e => {
- expect(dropdownEl.classList.contains('show')).toEqual(true)
+ expect(btnDropdown.classList.contains('show')).toEqual(true)
expect(btnDropdown.getAttribute('aria-expanded')).toEqual('true')
expect(showEventTriggered).toEqual(true)
expect(e.relatedTarget).toEqual(btnDropdown)
@@ -995,7 +995,7 @@ describe('Dropdown', () => {
})
dropdownEl.addEventListener('hidden.bs.dropdown', e => {
- expect(dropdownEl.classList.contains('show')).toEqual(false)
+ expect(btnDropdown.classList.contains('show')).toEqual(false)
expect(btnDropdown.getAttribute('aria-expanded')).toEqual('false')
expect(hideEventTriggered).toEqual(true)
expect(e.relatedTarget).toEqual(btnDropdown)
@@ -1066,7 +1066,7 @@ describe('Dropdown', () => {
const dropdownEl = fixtureEl.querySelector('.dropdown')
dropdownEl.addEventListener('shown.bs.dropdown', () => {
- expect(dropdownEl.classList.contains('show')).toEqual(true)
+ expect(btnDropdown.classList.contains('show')).toEqual(true)
const keyUp = createEvent('keyup')
@@ -1075,7 +1075,7 @@ describe('Dropdown', () => {
})
dropdownEl.addEventListener('hidden.bs.dropdown', () => {
- expect(dropdownEl.classList.contains('show')).toEqual(false)
+ expect(btnDropdown.classList.contains('show')).toEqual(false)
done()
})
@@ -1111,7 +1111,7 @@ describe('Dropdown', () => {
const btnGroup = last.parentNode
dropdownTestMenu.addEventListener('shown.bs.dropdown', () => {
- expect(dropdownTestMenu.classList.contains('show')).toEqual(true)
+ expect(first.classList.contains('show')).toEqual(true)
expect(fixtureEl.querySelectorAll('.dropdown-menu.show').length).toEqual(1)
document.body.click()
})
@@ -1122,7 +1122,7 @@ describe('Dropdown', () => {
})
btnGroup.addEventListener('shown.bs.dropdown', () => {
- expect(btnGroup.classList.contains('show')).toEqual(true)
+ expect(last.classList.contains('show')).toEqual(true)
expect(fixtureEl.querySelectorAll('.dropdown-menu.show').length).toEqual(1)
document.body.click()
})
@@ -1162,7 +1162,7 @@ describe('Dropdown', () => {
const btnGroup = last.parentNode
dropdownTestMenu.addEventListener('shown.bs.dropdown', () => {
- expect(dropdownTestMenu.classList.contains('show')).toEqual(true, '"show" class added on click')
+ expect(first.classList.contains('show')).toEqual(true, '"show" class added on click')
expect(fixtureEl.querySelectorAll('.dropdown-menu.show').length).toEqual(1, 'only one dropdown is shown')
const keyUp = createEvent('keyup')
@@ -1177,7 +1177,7 @@ describe('Dropdown', () => {
})
btnGroup.addEventListener('shown.bs.dropdown', () => {
- expect(btnGroup.classList.contains('show')).toEqual(true, '"show" class added on click')
+ expect(last.classList.contains('show')).toEqual(true, '"show" class added on click')
expect(fixtureEl.querySelectorAll('.dropdown-menu.show').length).toEqual(1, 'only one dropdown is shown')
const keyUp = createEvent('keyup')
@@ -1382,12 +1382,12 @@ describe('Dropdown', () => {
const input = fixtureEl.querySelector('input')
input.addEventListener('click', () => {
- expect(dropdown.classList.contains('show')).toEqual(true, 'dropdown menu is shown')
+ expect(triggerDropdown.classList.contains('show')).toEqual(true, 'dropdown menu is shown')
done()
})
dropdown.addEventListener('shown.bs.dropdown', () => {
- expect(dropdown.classList.contains('show')).toEqual(true, 'dropdown menu is shown')
+ expect(triggerDropdown.classList.contains('show')).toEqual(true, 'dropdown menu is shown')
input.dispatchEvent(createEvent('click'))
})
@@ -1409,12 +1409,12 @@ describe('Dropdown', () => {
const textarea = fixtureEl.querySelector('textarea')
textarea.addEventListener('click', () => {
- expect(dropdown.classList.contains('show')).toEqual(true, 'dropdown menu is shown')
+ expect(triggerDropdown.classList.contains('show')).toEqual(true, 'dropdown menu is shown')
done()
})
dropdown.addEventListener('shown.bs.dropdown', () => {
- expect(dropdown.classList.contains('show')).toEqual(true, 'dropdown menu is shown')
+ expect(triggerDropdown.classList.contains('show')).toEqual(true, 'dropdown menu is shown')
textarea.dispatchEvent(createEvent('click'))
})
@@ -1492,7 +1492,7 @@ describe('Dropdown', () => {
input.focus()
input.dispatchEvent(keyDownEscape)
- expect(dropdown.classList.contains('show')).toEqual(false, 'dropdown menu is not shown')
+ expect(triggerDropdown.classList.contains('show')).toEqual(false, 'dropdown menu is not shown')
done()
})
@@ -1529,7 +1529,7 @@ describe('Dropdown', () => {
setTimeout(() => {
expect(dropdown.toggle).not.toHaveBeenCalled()
- expect(triggerDropdown.parentNode.classList.contains('show')).toEqual(false)
+ expect(triggerDropdown.classList.contains('show')).toEqual(false)
done()
}, 20)
})