Skip to content

Commit d9b91ca

Browse files
authored
Update button-toolbar.spec.js
1 parent 9d78678 commit d9b91ca

File tree

1 file changed

+77
-11
lines changed

1 file changed

+77
-11
lines changed
Lines changed: 77 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,88 @@
1-
import { loadFixture, testVM } from '../../../tests/utils'
1+
import ButonToolbar from './button-toolbar'
2+
import ButtonGroup from '../button-group/button-group'
3+
import Button from '../button/button'
4+
import { mount } from '@vue/test-utils'
25

36
describe('button-toolbar', () => {
4-
beforeEach(loadFixture(__dirname, 'button-toolbar'))
5-
testVM()
7+
it('toolbar root should be "div"', async () => {
8+
const wrapper = mount(ButtonToolbar, {})
9+
expect(wrapper.is('div')).toBe(true)
10+
wrapper.destroy()
11+
})
612

713
it('toolbar should contain base class', async () => {
8-
const {
9-
app: { $refs }
10-
} = window
14+
const wrapper = mount(ButtonToolbar, {})
15+
expect(wrapper.classes()).toContain('btn-toolbar')
16+
wrapper.destroy()
17+
})
1118

12-
expect($refs.toolbar).toHaveClass('btn-toolbar')
19+
it('toolbar should not have class "justify-content-between"', async () => {
20+
const wrapper = mount(ButtonToolbar, {})
21+
expect(wrapper.classes()).not.toContain('justify-content-between')
22+
wrapper.destroy()
1323
})
1424

1525
it('toolbar should have role', async () => {
16-
const {
17-
app: { $refs }
18-
} = window
26+
const wrapper = mount(ButtonToolbar, {})
27+
expect(wrapper.attributes('role')).toBe('toolbar')
28+
wrapper.destroy()
29+
})
30+
31+
it('toolbar should not have tabindex by default', async () => {
32+
const wrapper = mount(ButtonToolbar, {})
33+
expect(wrapper.attributes('tabindex')).not.toBeDefined()
34+
wrapper.destroy()
35+
})
36+
37+
it('toolbar should have class "justify-content-between" when justify set', async () => {
38+
const wrapper = mount(ButtonToolbar, {
39+
propsData: {
40+
justify: true
41+
}
42+
})
43+
expect(wrapper.classes()).toContain('justify-content-between')
44+
expect(wrapper.classes()).toContain('btn-toolbar')
45+
wrapper.destroy()
46+
})
47+
48+
it('toolbar should have tabindex when key-nav set', async () => {
49+
const wrapper = mount(ButtonToolbar, {
50+
propsData: {
51+
keyNav: true
52+
}
53+
})
54+
expect(wrapper.attributes('tabindex')).toBeDefined()
55+
expect(wrapper.attributes('tabindex')).toBe('0')
56+
expect(wrapper.element.tabIndex).toBe(0)
57+
wrapper.destroy()
58+
})
59+
60+
// These tests are wrapped in a new describe to limit the scope of the getBCR Mock
61+
describe('keyboard navigation', () => {
62+
const origGetBCR = Element.prototype.getBoundingClientRect
63+
64+
beforeEach(() => {
65+
// Mock getBCR so that the isVisible(el) test returns true
66+
// In our test below, all pagination buttons would normally be visible
67+
Element.prototype.getBoundingClientRect = jest.fn(() => {
68+
return {
69+
width: 24,
70+
height: 24,
71+
top: 0,
72+
left: 0,
73+
bottom: 0,
74+
right: 0
75+
}
76+
})
77+
})
78+
79+
afterEach(() => {
80+
// Restore prototype
81+
Element.prototype.getBoundingClientRect = origGetBCR
82+
})
1983

20-
expect($refs.toolbar.$el.getAttribute('role')).toBe('toolbar')
84+
it('works', async () => {
85+
expect(true).toBe(true)
86+
})
2187
})
2288
})

0 commit comments

Comments
 (0)