mirror of
https://github.com/twbs/bootstrap.git
synced 2025-08-09 07:06:36 +02:00
Dropdown tests: Use a function to improve readability (#35448)
This commit is contained in:
@@ -1684,51 +1684,32 @@ describe('Dropdown', () => {
|
|||||||
const input = fixtureEl.querySelector('input')
|
const input = fixtureEl.querySelector('input')
|
||||||
const textarea = fixtureEl.querySelector('textarea')
|
const textarea = fixtureEl.querySelector('textarea')
|
||||||
|
|
||||||
const keydownSpace = createEvent('keydown')
|
const test = (eventKey, elementToDispatch) => {
|
||||||
keydownSpace.key = 'Space'
|
const event = createEvent('keydown')
|
||||||
|
event.key = eventKey
|
||||||
const keydownArrowUp = createEvent('keydown')
|
elementToDispatch.focus()
|
||||||
keydownArrowUp.key = 'ArrowUp'
|
elementToDispatch.dispatchEvent(event)
|
||||||
|
expect(document.activeElement).toEqual(elementToDispatch, `${elementToDispatch.tagName} still focused`)
|
||||||
const keydownArrowDown = createEvent('keydown')
|
}
|
||||||
keydownArrowDown.key = 'ArrowDown'
|
|
||||||
|
|
||||||
const keydownEscape = createEvent('keydown')
|
const keydownEscape = createEvent('keydown')
|
||||||
keydownEscape.key = 'Escape'
|
keydownEscape.key = 'Escape'
|
||||||
|
|
||||||
triggerDropdown.addEventListener('shown.bs.dropdown', () => {
|
triggerDropdown.addEventListener('shown.bs.dropdown', () => {
|
||||||
// Key Space
|
// Key Space
|
||||||
input.focus()
|
test('Space', input)
|
||||||
input.dispatchEvent(keydownSpace)
|
|
||||||
|
|
||||||
expect(document.activeElement).toEqual(input, 'input still focused')
|
test('Space', textarea)
|
||||||
|
|
||||||
textarea.focus()
|
|
||||||
textarea.dispatchEvent(keydownSpace)
|
|
||||||
|
|
||||||
expect(document.activeElement).toEqual(textarea, 'textarea still focused')
|
|
||||||
|
|
||||||
// Key ArrowUp
|
// Key ArrowUp
|
||||||
input.focus()
|
test('ArrowUp', input)
|
||||||
input.dispatchEvent(keydownArrowUp)
|
|
||||||
|
|
||||||
expect(document.activeElement).toEqual(input, 'input still focused')
|
test('ArrowUp', textarea)
|
||||||
|
|
||||||
textarea.focus()
|
|
||||||
textarea.dispatchEvent(keydownArrowUp)
|
|
||||||
|
|
||||||
expect(document.activeElement).toEqual(textarea, 'textarea still focused')
|
|
||||||
|
|
||||||
// Key ArrowDown
|
// Key ArrowDown
|
||||||
input.focus()
|
test('ArrowDown', input)
|
||||||
input.dispatchEvent(keydownArrowDown)
|
|
||||||
|
|
||||||
expect(document.activeElement).toEqual(input, 'input still focused')
|
test('ArrowDown', textarea)
|
||||||
|
|
||||||
textarea.focus()
|
|
||||||
textarea.dispatchEvent(keydownArrowDown)
|
|
||||||
|
|
||||||
expect(document.activeElement).toEqual(textarea, 'textarea still focused')
|
|
||||||
|
|
||||||
// Key Escape
|
// Key Escape
|
||||||
input.focus()
|
input.focus()
|
||||||
|
Reference in New Issue
Block a user