Skip to content

chore(tests): more tests #2872

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 67 commits into from
Mar 20, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
67 commits
Select commit Hold shift + click to select a range
f2ba688
chore(tests): more tests
tmorehouse Mar 19, 2019
585c865
Update carousel.spec.js
tmorehouse Mar 19, 2019
a6bd4f9
Update carousel.spec.js
tmorehouse Mar 19, 2019
e0eb38e
Update carousel.js
tmorehouse Mar 19, 2019
799f3da
Update carousel.js
tmorehouse Mar 19, 2019
93f7e14
Update carousel.js
tmorehouse Mar 19, 2019
12cdde2
Update carousel.spec.js
tmorehouse Mar 19, 2019
863bb7a
Update carousel.js
tmorehouse Mar 19, 2019
210bf3f
Update carousel.js
tmorehouse Mar 19, 2019
5164f5b
Update carousel.js
tmorehouse Mar 19, 2019
92d8145
Update carousel-slide.js
tmorehouse Mar 19, 2019
1315ee9
Update form-file.js
tmorehouse Mar 19, 2019
9d78678
Update form-file.js
tmorehouse Mar 19, 2019
d9b91ca
Update button-toolbar.spec.js
tmorehouse Mar 19, 2019
e88b53b
Update button-toolbar.spec.js
tmorehouse Mar 19, 2019
b4d2eda
Update button-toolbar.spec.js
tmorehouse Mar 19, 2019
34e3739
Delete button-toolbar.html
tmorehouse Mar 19, 2019
30f2d26
Delete button-toolbar.js
tmorehouse Mar 19, 2019
3a82612
Update button-toolbar.spec.js
tmorehouse Mar 19, 2019
bc3b434
Update button-toolbar.spec.js
tmorehouse Mar 19, 2019
502e3e7
Update button-toolbar.spec.js
tmorehouse Mar 19, 2019
a2b6790
Update button-toolbar.spec.js
tmorehouse Mar 19, 2019
77c4054
Update button-toolbar.spec.js
tmorehouse Mar 19, 2019
3690758
Update button-toolbar.spec.js
tmorehouse Mar 19, 2019
676d82e
Update button-toolbar.js
tmorehouse Mar 19, 2019
2a16888
Update button-toolbar.spec.js
tmorehouse Mar 19, 2019
0a21fbe
Update button-toolbar.spec.js
tmorehouse Mar 19, 2019
f13b5f8
Update button-toolbar.spec.js
tmorehouse Mar 19, 2019
000042f
Update button-toolbar.spec.js
tmorehouse Mar 19, 2019
6b516d3
Update button-toolbar.js
tmorehouse Mar 19, 2019
fb37b93
Update button-toolbar.js
tmorehouse Mar 19, 2019
e28e8f6
Update button-toolbar.js
tmorehouse Mar 19, 2019
ce7b237
Update button-toolbar.js
tmorehouse Mar 19, 2019
8062f91
Update button-toolbar.js
tmorehouse Mar 19, 2019
1281be5
Update button-toolbar.js
tmorehouse Mar 19, 2019
0cb5cc1
Update button-toolbar.js
tmorehouse Mar 19, 2019
c0a7ebc
Update button-toolbar.js
tmorehouse Mar 19, 2019
1c554c4
Update button-toolbar.js
tmorehouse Mar 19, 2019
4fa5611
Create progress-bar.spec.js
tmorehouse Mar 19, 2019
3b58dc1
Update progress-bar.spec.js
tmorehouse Mar 19, 2019
7b9ff07
Update progress-bar.spec.js
tmorehouse Mar 19, 2019
acefa03
Update progress-bar.spec.js
tmorehouse Mar 19, 2019
548344b
Update progress-bar.spec.js
tmorehouse Mar 19, 2019
13776d8
Update progress-bar.spec.js
tmorehouse Mar 19, 2019
e4045dc
Update breadcrumb.js
tmorehouse Mar 20, 2019
b5e8499
Update breadcrumb.html
tmorehouse Mar 20, 2019
3a67855
Update collapse.js
tmorehouse Mar 20, 2019
8ec606c
Update carousel.html
tmorehouse Mar 20, 2019
85eb9cb
Update form-group.html
tmorehouse Mar 20, 2019
22031ea
Update form-group.html
tmorehouse Mar 20, 2019
106f7a9
Update form-group.spec.js
tmorehouse Mar 20, 2019
3a1064d
Update carousel.html
tmorehouse Mar 20, 2019
f6c9d26
Update form-group.html
tmorehouse Mar 20, 2019
b63a5ac
Update form-group.js
tmorehouse Mar 20, 2019
bde593d
Update form-group.html
tmorehouse Mar 20, 2019
2cbc3fa
Update form-group.spec.js
tmorehouse Mar 20, 2019
5adb406
Update form-group.html
tmorehouse Mar 20, 2019
abe90f9
Update form-group.spec.js
tmorehouse Mar 20, 2019
ec37f24
Update form-group.spec.js
tmorehouse Mar 20, 2019
4477328
Update form-group.spec.js
tmorehouse Mar 20, 2019
44edb13
Update form-group.spec.js
tmorehouse Mar 20, 2019
f75f159
Update form-group.spec.js
tmorehouse Mar 20, 2019
fdf4a03
Update form-group.spec.js
tmorehouse Mar 20, 2019
8079d27
Update form-group.spec.js
tmorehouse Mar 20, 2019
5e58462
Update form-group.spec.js
tmorehouse Mar 20, 2019
34e3fad
Update toggle.js
tmorehouse Mar 20, 2019
25ce653
Merge branch 'dev' into tmorehouse/tests
tmorehouse Mar 20, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/components/breadcrumb/fixtures/breadcrumb.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@
v-bind="item"
:key="index" />
</b-breadcrumb>
<!-- test when one of hte items has active set to true
<b-breadcrumb ref="breadcrumb3" :items="item2"></b-breadcrumb>
<!-- test when one of hte items has active set to true -->
<b-breadcrumb ref="breadcrumb3" :items="items3"></b-breadcrumb>
</div>
18 changes: 18 additions & 0 deletions src/components/breadcrumb/fixtures/breadcrumb.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,24 @@ window.app = new Vue({
{
text: 'Library'
}
],
items3: [
{
text: 'Home',
href: 'https://bootstrap-vue.github.io'
},
{
text: 'Admin',
href: '#',
active: true
},
{
text: 'Manage',
href: '#'
},
{
text: 'Library'
}
]
}
})
81 changes: 34 additions & 47 deletions src/components/button-toolbar/button-toolbar.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,6 @@ export default {
default: false
}
},
computed: {
classObject() {
return ['btn-toolbar', this.justify && !this.vertical ? 'justify-content-between' : '']
}
},
mounted() {
if (this.keyNav) {
// Pre-set the tabindexes if the markup does not include tabindex="-1" on the toolbar items
Expand All @@ -41,62 +36,51 @@ export default {
this.focusFirst(evt)
}
},
stop(evt) {
evt.preventDefault()
evt.stopPropagation()
},
onKeydown(evt) {
if (!this.keyNav) {
/* istanbul ignore next: should never happen */
return
}
const key = evt.keyCode
const shift = evt.shiftKey
if (key === KeyCodes.UP || key === KeyCodes.LEFT) {
evt.preventDefault()
evt.stopPropagation()
if (shift) {
this.focusFirst(evt)
} else {
this.focusNext(evt, true)
}
this.stop(evt)
shift ? this.focusFirst(evt) : this.focusPrev(evt)
} else if (key === KeyCodes.DOWN || key === KeyCodes.RIGHT) {
evt.preventDefault()
evt.stopPropagation()
if (shift) {
this.focusLast(evt)
} else {
this.focusNext(evt, false)
}
this.stop(evt)
shift ? this.focusLast(evt) : this.focusNext(evt)
}
},
setItemFocus(item) {
this.$nextTick(() => {
item.focus()
})
item && item.focus && item.focus()
},
focusNext(evt, prev) {
focusFirst(evt) {
const items = this.getItems()
if (items.length < 1) {
return
}
let index = items.indexOf(evt.target)
if (prev && index > 0) {
index--
} else if (!prev && index < items.length - 1) {
index++
}
if (index < 0) {
index = 0
this.setItemFocus(items[0])
},
focusPrev(evt) {
let items = this.getItems()
const index = items.indexOf(evt.target)
if (index > -1) {
items = items.slice(0, index).reverse()
this.setItemFocus(items[0])
}
this.setItemFocus(items[index])
},
focusFirst(evt) {
const items = this.getItems()
if (items.length > 0) {
focusNext(evt) {
let items = this.getItems()
const index = items.indexOf(evt.target)
if (index > -1) {
items = items.slice(index + 1)
this.setItemFocus(items[0])
}
},
focusLast(evt) {
const items = this.getItems()
if (items.length > 0) {
this.setItemFocus([items.length - 1])
}
const items = this.getItems().reverse()
this.setItemFocus(items[0])
},
getItems() {
let items = selectAll(ITEM_SELECTOR, this.$el)
Expand All @@ -111,15 +95,18 @@ export default {
return h(
'div',
{
class: this.classObject,
staticClass: 'btn-toolbar',
class: { 'justify-content-between': this.justify },
attrs: {
role: 'toolbar',
tabindex: this.keyNav ? '0' : null
},
on: {
focusin: this.onFocusin,
keydown: this.onKeydown
}
on: this.keyNav
? {
focusin: this.onFocusin,
keydown: this.onKeydown
}
: {}
},
[this.$slots.default]
)
Expand Down
195 changes: 184 additions & 11 deletions src/components/button-toolbar/button-toolbar.spec.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,195 @@
import { loadFixture, testVM } from '../../../tests/utils'
import ButtonToolbar from './button-toolbar'
import ButtonGroup from '../button-group/button-group'
import Button from '../button/button'
import { mount } from '@vue/test-utils'
import Vue from 'vue'

describe('button-toolbar', () => {
beforeEach(loadFixture(__dirname, 'button-toolbar'))
testVM()
it('toolbar root should be "div"', async () => {
const wrapper = mount(ButtonToolbar, {})
expect(wrapper.is('div')).toBe(true)
wrapper.destroy()
})

it('toolbar should contain base class', async () => {
const {
app: { $refs }
} = window
const wrapper = mount(ButtonToolbar, {})
expect(wrapper.classes()).toContain('btn-toolbar')
wrapper.destroy()
})

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

it('toolbar should have role', async () => {
const {
app: { $refs }
} = window
const wrapper = mount(ButtonToolbar, {})
expect(wrapper.attributes('role')).toBe('toolbar')
wrapper.destroy()
})

it('toolbar should not have tabindex by default', async () => {
const wrapper = mount(ButtonToolbar, {})
expect(wrapper.attributes('tabindex')).not.toBeDefined()
wrapper.destroy()
})

it('toolbar should have class "justify-content-between" when justify set', async () => {
const wrapper = mount(ButtonToolbar, {
propsData: {
justify: true
}
})
expect(wrapper.classes()).toContain('justify-content-between')
expect(wrapper.classes()).toContain('btn-toolbar')
wrapper.destroy()
})

it('toolbar should have tabindex when key-nav set', async () => {
const wrapper = mount(ButtonToolbar, {
propsData: {
keyNav: true
}
})
expect(wrapper.attributes('tabindex')).toBeDefined()
expect(wrapper.attributes('tabindex')).toBe('0')
expect(wrapper.element.tabIndex).toBe(0)
wrapper.destroy()
})

// These tests are wrapped in a new describe to limit the scope of the getBCR Mock
describe('keyboard navigation', () => {
const origGetBCR = Element.prototype.getBoundingClientRect

beforeEach(() => {
// Mock getBCR so that the isVisible(el) test returns true
// In our test below, all pagination buttons would normally be visible
Element.prototype.getBoundingClientRect = jest.fn(() => {
return {
width: 24,
height: 24,
top: 0,
left: 0,
bottom: 0,
right: 0
}
})
})

afterEach(() => {
// Restore prototype
Element.prototype.getBoundingClientRect = origGetBCR
})

// Test App for keynav
const App = Vue.extend({
render(h) {
return h(ButtonToolbar, { props: { keyNav: true } }, [
h(ButtonGroup, {}, [h(Button, {}, 'a'), h(Button, {}, 'b')]),
h(ButtonGroup, {}, [h(Button, { props: { disabled: true } }, 'c'), h(Button, {}, 'd')]),
h(ButtonGroup, {}, [h(Button, {}, 'e'), h(Button, {}, 'f')])
])
}
})

it('has correct structure', async () => {
const wrapper = mount(App, {
attachToDocument: true
})

await wrapper.vm.$nextTick()

expect(wrapper.is('div.btn-toolbar')).toBe(true)
expect(wrapper.attributes('tabindex')).toBe('0')

const $groups = wrapper.findAll('.btn-group')
expect($groups).toBeDefined()
expect($groups.length).toBe(3)
expect($groups.is(ButtonGroup)).toBe(true)

const $btns = wrapper.findAll('button')
expect($btns).toBeDefined()
expect($btns.length).toBe(6)
expect($btns.is(Button)).toBe(true)
expect($btns.at(0).is('button[tabindex="-1"')).toBe(true)
expect($btns.at(1).is('button[tabindex="-1"')).toBe(true)
expect($btns.at(2).is('button[tabindex="-1"')).toBe(false) // disabled button
expect($btns.at(3).is('button[tabindex="-1"')).toBe(true)
expect($btns.at(4).is('button[tabindex="-1"')).toBe(true)
expect($btns.at(5).is('button[tabindex="-1"')).toBe(true)

wrapper.destroy()
})

it('focuses first button when tabbed into', async () => {
const wrapper = mount(App, {
attachToDocument: true
})

await wrapper.vm.$nextTick()

expect(wrapper.is('div.btn-toolbar')).toBe(true)
expect(wrapper.attributes('tabindex')).toBe('0')

const $btns = wrapper.findAll('button')
expect($btns).toBeDefined()
expect($btns.length).toBe(6)

expect(document.activeElement).not.toBe(wrapper.element)
expect(document.activeElement).not.toBe($btns.at(0).element)

wrapper.trigger('focusin')
await wrapper.vm.$nextTick()
expect(document.activeElement).toBe($btns.at(0).element)

wrapper.destroy()
})

it('keyboard navigation works', async () => {
const wrapper = mount(App, {
attachToDocument: true
})

await wrapper.vm.$nextTick()

expect(wrapper.is('div.btn-toolbar')).toBe(true)
expect(wrapper.attributes('tabindex')).toBe('0')

const $btns = wrapper.findAll('button')
expect($btns).toBeDefined()
expect($btns.length).toBe(6)

// Focus first button
$btns.at(0).element.focus()
expect(document.activeElement).toBe($btns.at(0).element)

// Cursor right
$btns.at(0).trigger('keydown.right')
await wrapper.vm.$nextTick()
expect(document.activeElement).toBe($btns.at(1).element)

// Cursor right (skips disabled button)
$btns.at(1).trigger('keydown.right')
await wrapper.vm.$nextTick()
expect(document.activeElement).toBe($btns.at(3).element)

// Cursor shift-right (focuses last button)
$btns.at(1).trigger('keydown.right', { shiftKey: true })
await wrapper.vm.$nextTick()
expect(document.activeElement).toBe($btns.at(5).element)

// Cursor left
$btns.at(5).trigger('keydown.left')
await wrapper.vm.$nextTick()
expect(document.activeElement).toBe($btns.at(4).element)

// Cursor shift left (focuses first button)
$btns.at(5).trigger('keydown.left', { shiftKey: true })
await wrapper.vm.$nextTick()
expect(document.activeElement).toBe($btns.at(0).element)

expect($refs.toolbar.$el.getAttribute('role')).toBe('toolbar')
wrapper.destroy()
})
})
})
17 changes: 0 additions & 17 deletions src/components/button-toolbar/fixtures/button-toolbar.html

This file was deleted.

3 changes: 0 additions & 3 deletions src/components/button-toolbar/fixtures/button-toolbar.js

This file was deleted.

1 change: 1 addition & 0 deletions src/components/carousel/carousel-slide.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ export default {
on: noDrag
? {
dragstart: e => {
/* istanbul ignore next: difficult to test in JSDOM */
e.preventDefault()
}
}
Expand Down
Loading