Skip to content

Commit 1e31bbc

Browse files
authored
Update table-tbody-row-events.spec.js
1 parent f9e66d2 commit 1e31bbc

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed

src/components/table/table-tbody-row-events.spec.js

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,4 +235,46 @@ describe('table tbody row events', () => {
235235
$rows.at(1).trigger('mouseleave')
236236
expect(wrapper.emitted('row-unhovered')).not.toBeDefined()
237237
})
238+
239+
it('should emit row-clicked event when a row is focusable and enter pressed', async () => {
240+
const wrapper = mount(Table, {
241+
propsData: {
242+
fields: testFields,
243+
items: testItems
244+
},
245+
listeners: {
246+
// Rows will only have tabindex=0 when a row-clicked listener present
247+
'row-clicked': () => {}
248+
}
249+
})
250+
expect(wrapper).toBeDefined()
251+
const $rows = wrapper.findAll('tbody > tr')
252+
expect($rows.length).toBe(3)
253+
expect(wrapper.emitted('row-clicked')).not.toBeDefined()
254+
$rows.at(1).element.focus() /* event only works when teh tr is focused */
255+
$rows.at(1).trigger('keydown.enter')
256+
expect(wrapper.emitted('row-clicked')).toBeDefined()
257+
expect(wrapper.emitted('row-clicked').length).toBe(1)
258+
expect(wrapper.emitted('row-clicked')[0][0]).toEqual(testItems[1]) /* row item */
259+
expect(wrapper.emitted('row-clicked')[0][1]).toEqual(1) /* row index */
260+
// Note: the KeyboardEvent is forwarded to the click handler
261+
expect(wrapper.emitted('row-clicked')[0][2]).toBeInstanceOf(KeyboardEvent) /* event */
262+
})
263+
264+
it('should not emit row-clicked event when a row is focusable, enter pressed, and table busy', async () => {
265+
const wrapper = mount(Table, {
266+
propsData: {
267+
fields: testFields,
268+
items: testItems,
269+
busy: true
270+
}
271+
})
272+
expect(wrapper).toBeDefined()
273+
const $rows = wrapper.findAll('tbody > tr')
274+
expect($rows.length).toBe(3)
275+
expect(wrapper.emitted('row-clicked')).not.toBeDefined()
276+
$rows.at(1).element.focus() /* event only works when the tr is focused */
277+
$rows.at(1).trigger('keydown.enter')
278+
expect(wrapper.emitted('row-clicked')).not.toBeDefined()
279+
})
238280
})

0 commit comments

Comments
 (0)