Skip to content

Commit 117e68f

Browse files
authored
tests: updates (bootstrap-vue#1453)
1 parent 4713587 commit 117e68f

File tree

8 files changed

+148
-14
lines changed

8 files changed

+148
-14
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import { loadFixture, testVM } from '../../../tests/utils'
2+
3+
describe('button-toolbar', async () => {
4+
beforeEach(loadFixture(__dirname, 'button-toolbar'))
5+
testVM()
6+
7+
it('toolbar should contain base class', async () => {
8+
const { app: { $refs } } = window
9+
10+
expect($refs.toolbar).toHaveClass('btn-toolbar')
11+
})
12+
13+
it('toolbar should have role', async () => {
14+
const { app: { $refs } } = window
15+
16+
expect($refs.toolbar.$el.getAttribute('role')).toBe('toolbar')
17+
})
18+
})
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<div id="app">
2+
<b-button-toolbar ref="toolbar" key-nav aria-label="Toolbar with button groups">
3+
<b-button-group class="mx-1">
4+
<b-btn>&laquo;</b-btn>
5+
<b-btn>&lsaquo;</b-btn>
6+
</b-button-group>
7+
<b-button-group class="mx-1">
8+
<b-btn>Edit</b-btn>
9+
<b-btn>Undo</b-btn>
10+
<b-btn>Redo</b-btn>
11+
</b-button-group>
12+
<b-button-group class="mx-1">
13+
<b-btn>&rsaquo;</b-btn>
14+
<b-btn>&raquo;</b-btn>
15+
</b-button-group>
16+
</b-button-toolbar>
17+
</div>
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
window.app = new Vue({
2+
el: '#app'
3+
})
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
import { loadFixture, testVM } from '../../../tests/utils'
2+
3+
describe('button-close', async () => {
4+
beforeEach(loadFixture(__dirname, 'button-close'))
5+
testVM()
6+
7+
it('default should have class close', async () => {
8+
const { app: { $refs } } = window
9+
expect($refs.default).toHaveClass('close')
10+
})
11+
12+
it('slot should have class close', async () => {
13+
const { app: { $refs } } = window
14+
expect($refs.slot).toHaveClass('close')
15+
})
16+
17+
it('disabled should have class close', async () => {
18+
const { app: { $refs } } = window
19+
expect($refs.disabled).toHaveClass('close')
20+
})
21+
22+
it('variant should have classes close and text-primary', async () => {
23+
const { app: { $refs } } = window
24+
expect($refs.variant).toHaveAllClasses(['close', 'text-primary'])
25+
})
26+
27+
it('slot should have custom content', async () => {
28+
const { app: { $refs } } = window
29+
expect($refs.slot.innerHTML).toContain('close')
30+
})
31+
32+
it('default should emit "click" event when clicked', async () => {
33+
const { app: { $refs } } = window
34+
const btn = $refs.default
35+
const spy = jest.fn()
36+
37+
btn.addEventListener('click', spy)
38+
btn.click()
39+
40+
expect(spy).toHaveBeenCalled()
41+
})
42+
43+
it('default should emit "click" event with native event object', async () => {
44+
const { app: { $refs } } = window
45+
const btn = $refs.default
46+
let event = null
47+
48+
btn.addEventListener('click', e => (event = e))
49+
btn.click()
50+
51+
expect(event).toBeInstanceOf(MouseEvent)
52+
})
53+
54+
it('disabled should be disabled and not emit click event with `disabled` prop true', async () => {
55+
const { app: { $refs } } = window
56+
const btn = $refs.disabled
57+
const spy = jest.fn()
58+
59+
btn.addEventListener('click', spy)
60+
btn.click()
61+
62+
expect(btn.disabled).toBe(true)
63+
expect(spy).not.toHaveBeenCalled()
64+
})
65+
})

src/components/button/button.spec.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,25 @@ describe('button', async () => {
126126
expect(vm.getAttribute('aria-pressed')).toBe('true')
127127
})
128128

129+
/*
130+
* I have no clue why this test fails.
131+
it('pressed should have `.focus` class when focused', async () => {
132+
const { app } = window
133+
const btn = app.$refs.btn_pressed
134+
135+
await setData(app, 'btnToggle', false)
136+
await nextTick()
137+
138+
btn.focus()
139+
await nextTick()
140+
expect(btn).toHaveClass('focus')
141+
142+
btn.blur()
143+
await nextTick()
144+
expect(btn).not.toHaveClass('focus')
145+
})
146+
*/
147+
129148
it('should update the parent sync value on click and when pressed is not null', async () => {
130149
const { app } = window
131150
const vm = app.$refs.btn_pressed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<div id="app">
2+
<b-button-close ref="default"></b-button-close>
3+
<b-button-close ref="slot">close</b-button-close>
4+
<b-button-close ref="disabled" disabled></b-button-close>
5+
<b-button-close ref="variant" text-variant="primary"></b-button-close>
6+
</div>
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
window.app = new Vue({
2+
el: '#app'
3+
})

src/utils/dom.js

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ export const matches = (el, selector) => {
5858
proto.msMatchesSelector ||
5959
proto.oMatchesSelector ||
6060
proto.webkitMatchesSelector ||
61+
/* istanbul ignore next */
6162
function (sel) {
6263
const element = this
6364
const m = selectAll(sel, element.document || element.ownerDocument)
@@ -79,20 +80,22 @@ export const closest = (selector, root) => {
7980
// https://developer.mozilla.org/en-US/docs/Web/API/Element/closest
8081
// Since we dont support IE < 10, we can use the "Matches" version of the polyfill for speed
8182
// Prefer native implementation over polyfill function
82-
const Closest = Element.prototype.closest || function (sel) {
83-
let element = this
84-
if (!document.documentElement.contains(element)) {
85-
return null
86-
}
87-
do {
88-
// Use our "patched" matches function
89-
if (matches(element, sel)) {
90-
return element
91-
}
92-
element = element.parentElement
93-
} while (element !== null)
94-
return null
95-
}
83+
const Closest = Element.prototype.closest ||
84+
/* istanbul ignore next */
85+
function (sel) {
86+
let element = this
87+
if (!document.documentElement.contains(element)) {
88+
return null
89+
}
90+
do {
91+
// Use our "patched" matches function
92+
if (matches(element, sel)) {
93+
return element
94+
}
95+
element = element.parentElement
96+
} while (element !== null)
97+
return null
98+
}
9699

97100
const el = Closest.call(root, selector)
98101
// Emulate jQuery closest and return null if match is the passed in element (root)

0 commit comments

Comments
 (0)