Skip to content

Commit 000042f

Browse files
authored
Update button-toolbar.spec.js
1 parent f13b5f8 commit 000042f

File tree

1 file changed

+46
-0
lines changed

1 file changed

+46
-0
lines changed

src/components/button-toolbar/button-toolbar.spec.js

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,5 +145,51 @@ describe('button-toolbar', () => {
145145

146146
wrapper.destroy()
147147
})
148+
149+
it('keyboard navigation works', async () => {
150+
const wrapper = mount(App, {
151+
attachToDocument: true
152+
})
153+
154+
await wrapper.vm.$nextTick()
155+
156+
expect(wrapper.is('div.btn-toolbar')).toBe(true)
157+
expect(wrapper.attributes('tabindex')).toBe('0')
158+
159+
const $btns = wrapper.findAll('button')
160+
expect($btns).toBeDefined()
161+
expect($btns.length).toBe(6)
162+
163+
// Focus first button
164+
$btns.at(0).element.focus()
165+
expect(document.activeElement).toBe($btns.at(0).element)
166+
167+
// Cursor right
168+
$btns.at(0).trigger('keydown.right')
169+
await wrapper.vm.$nextTick()
170+
expect(document.activeElement).toBe($btns.at(1).element)
171+
172+
// Cursor right (skips disabled button)
173+
$btns.at(1).trigger('keydown.right')
174+
await wrapper.vm.$nextTick()
175+
expect(document.activeElement).toBe($btns.at(3).element)
176+
177+
// Cursor shift-right (focuses last button)
178+
$btns.at(1).trigger('keydown.right', { shiftKey: true })
179+
await wrapper.vm.$nextTick()
180+
expect(document.activeElement).toBe($btns.at(5).element)
181+
182+
// Cursor left
183+
$btns.at(5).trigger('keydown.left')
184+
await wrapper.vm.$nextTick()
185+
expect(document.activeElement).toBe($btns.at(4).element)
186+
187+
// Cursor shift left (focuses first button)
188+
$btns.at(5).trigger('keydown.left', { shiftKey: true })
189+
await wrapper.vm.$nextTick()
190+
expect(document.activeElement).toBe($btns.at(0).element)
191+
192+
wrapper.destroy()
193+
})
148194
})
149195
})

0 commit comments

Comments
 (0)