Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Tests & Breadcrumb improvements (#466)
* Add bootstrap -> bootstrap-vue migration notes * add bFormFieldset label text alignment options * fixes per @pi0 * add focus method proxied to element ref * Popover dom node leak fix * badge: add refs and generate variants * improving error messages when matcher fn called improperly * badge test suite * propagate click event and emit click with event obj * fix for dynamically setting the active link Before the link would always set the last item of the array as the active one. However, the active state was read from the user submitted items.active prop, rather than the normalized item.__active. Some more semantic improvements to make the code clearer * formatting * use only one lookup of array length * two components and items lists for tests * breadcrumb testing * stop scroll to top behavior
- Loading branch information
1 parent
b0cfdf5
commit b1d78e5
Showing
9 changed files
with
204 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,42 @@ | ||
import {loadFixture, testVM} from '../helpers'; | ||
import { loadFixture, testVM } from '../helpers' | ||
|
||
const variantList = [ | ||
'default', | ||
'primary', | ||
'success', | ||
'info', | ||
'warning', | ||
'danger', | ||
].map(variant => { | ||
return { ref: `badge_${variant}`, variant } | ||
}) | ||
|
||
describe('badge', async() => { | ||
beforeEach(loadFixture('badge')); | ||
testVM(); | ||
}); | ||
beforeEach(loadFixture('badge')) | ||
testVM() | ||
|
||
it('should apply variant classes', async() => { | ||
const { app: { $refs, $el } } = window | ||
|
||
expect($refs.badge_pill).toHaveAllClasses(['badge', 'badge-pill']) | ||
|
||
variantList.forEach(({ ref, variant }) => { | ||
const vm = $refs[ref][0] | ||
expect(vm).toHaveAllClasses(['badge', `badge-${variant}`]) | ||
}) | ||
}) | ||
|
||
it('should apply default pill class when not passed variant', async() => { | ||
const { app: { $refs, $el } } = window | ||
|
||
const vm = $refs.no_props | ||
expect(vm).toHaveClass('badge-default') | ||
}) | ||
|
||
it('should not apply pill class when not passed pill boolean prop', async() => { | ||
const { app: { $refs, $el } } = window | ||
|
||
const vm = $refs.no_props | ||
expect(vm).not.toHaveClass('badge-pill') | ||
}) | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,77 @@ | ||
import {loadFixture, testVM} from '../helpers'; | ||
import { loadFixture, testVM } from '../helpers' | ||
|
||
describe('breadcrumb', async() => { | ||
beforeEach(loadFixture('breadcrumb')); | ||
testVM(); | ||
}); | ||
beforeEach(loadFixture('breadcrumb')) | ||
testVM() | ||
|
||
it('should apply bootstrap breadcrumb classes', async() => { | ||
const { app: { $refs, $el } } = window | ||
const vm = $refs.breadcrumb1 | ||
const $ol = vm.$el | ||
|
||
expect($ol.classList.contains('breadcrumb')).toBe(true) | ||
|
||
Array.from($ol.children).forEach($li => { | ||
if ($li.tagName === 'LI') { | ||
expect($li.classList.contains('breadcrumb-item')).toBe(true) | ||
} | ||
}) | ||
}) | ||
|
||
it('should apply ARIA roles', async() => { | ||
const { app: { $refs, $el } } = window | ||
const vm = $refs.breadcrumb1 | ||
const $ol = vm.$el | ||
|
||
expect($ol.getAttribute('role')).toBe('navigation') | ||
|
||
Array.from($ol.children).forEach($li => { | ||
if ($li.tagName === 'LI') { | ||
expect($li.getAttribute('role')).toBe('presentation') | ||
} | ||
}) | ||
}) | ||
|
||
it('should apply active class', async() => { | ||
const { app: { $refs, $el } } = window | ||
const vm = $refs.breadcrumb2 | ||
const $listItems = Array.from(vm.$el.children) | ||
|
||
app.items2.forEach((item, i) => { | ||
if (item.active) { | ||
expect($listItems[i].classList.contains('active')).toBe(true) | ||
} | ||
}) | ||
}) | ||
|
||
it('should default active class to last item only when no true active prop provided', async() => { | ||
const { app: { $refs, $el } } = window | ||
const vm = $refs.breadcrumb1 | ||
const $listItems = Array.from(vm.$el.children) | ||
const itemsLength = app.items.length | ||
|
||
app.items.forEach((item, i) => { | ||
const isLast = i === itemsLength - 1 | ||
|
||
if (isLast) { | ||
expect($listItems[i].classList.contains('active')).toBe(true) | ||
} else { | ||
expect($listItems[i].classList.contains('active')).toBe(false) | ||
} | ||
}) | ||
}) | ||
|
||
it('should emit a click event with the item when clicked', async() => { | ||
const { app: { $refs, $el } } = window | ||
const vm = $refs.breadcrumb2 | ||
const spy = jest.fn(); | ||
|
||
vm.$on('click', spy) | ||
const $listItems = Array.from(vm.$el.children) | ||
|
||
app.items2.forEach((item, index) => { | ||
$listItems[index].click() | ||
expect(spy).toHaveBeenCalledWith(item) | ||
}) | ||
}) | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,17 @@ | ||
<div id="app"> | ||
<h3>Example heading <b-badge>New</b-badge></h3> | ||
<h4>Example heading <b-badge variant="primary">New</b-badge></h4> | ||
<h5>Example heading <b-badge pill variant="success">New</b-badge></h5> | ||
<h3>Example heading | ||
<b-badge ref="no_props">New</b-badge> | ||
</h3> | ||
<h4>Example heading | ||
<b-badge variant="primary">New</b-badge> | ||
</h4> | ||
<h5>Example heading | ||
<b-badge pill | ||
ref="badge_pill" | ||
variant="success">New</b-badge> | ||
</h5> | ||
<p v-for="variant in variants"> | ||
<b-badge :variant="variant" | ||
:ref="`badge_${variant}`">{{ variant }}</b-badge> | ||
</p> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,15 @@ | ||
window.app = new Vue({ | ||
el: '#app' | ||
el: '#app', | ||
data() { | ||
return { | ||
variants: [ | ||
'default', | ||
'primary', | ||
'success', | ||
'info', | ||
'warning', | ||
'danger', | ||
] | ||
} | ||
}, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
<div id="app"> | ||
<b-breadcrumb :items="items" /> | ||
<b-breadcrumb ref="breadcrumb1" :items="items" /> | ||
<b-breadcrumb ref="breadcrumb2" :items="items2" /> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters