Skip to content

Commit c9de983

Browse files
committed
Add reverse property and add tests
1 parent d824d6d commit c9de983

File tree

7 files changed

+1713
-70
lines changed

7 files changed

+1713
-70
lines changed

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ export default Vue.extend({
7474
>
7575
<b-timeline
7676
:items="timelineItems"
77+
:reverse="false"
7778
/>
7879
</b-card>
7980
</div>
@@ -83,9 +84,10 @@ export default Vue.extend({
8384
## Features
8485
- [ ] Loading spinner
8586
- [ ] Support item head color variants
86-
- [ ] Support `reverse` props
87+
- [x] Support `reverse` props
8788
- [ ] Support custom icons
8889
- [ ] Refactor timeline and item into separate components
90+
- [ ] Custom timestamp format
8991

9092
## Component Reference
9193
### Properties

dev/serve.vue

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ export default Vue.extend({
4545
>
4646
<bootstrap-vue-timeline
4747
:items="timelineItems"
48+
:reverse="true"
4849
/>
4950
</b-card>
5051
</div>

jest.config.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
module.exports = {
2+
preset: '@vue/cli-plugin-unit-jest',
3+
verbose: true,
4+
moduleNameMapper: {
5+
'\\.css$': 'identity-obj-proxy'
6+
}
7+
}

package.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,16 +26,18 @@
2626
},
2727
"devDependencies": {
2828
"@babel/core": "^7.12.10",
29-
"@babel/preset-env": "^7.12.11",
3029
"@babel/polyfill": "^7.11.5",
30+
"@babel/preset-env": "^7.12.11",
3131
"@rollup/plugin-alias": "^3.1.1",
3232
"@rollup/plugin-babel": "^5.2.2",
3333
"@rollup/plugin-commonjs": "^17.0.0",
3434
"@rollup/plugin-node-resolve": "^11.0.1",
3535
"@rollup/plugin-replace": "^2.3.4",
3636
"@vue/cli-plugin-babel": "^4.5.10",
37-
"@vue/cli-service": "^4.5.10",
3837
"@vue/cli-plugin-eslint": "~4.5.0",
38+
"@vue/cli-plugin-unit-jest": "^4.5.13",
39+
"@vue/cli-service": "^4.5.10",
40+
"@vue/test-utils": "^1.2.0",
3941
"cross-env": "^7.0.3",
4042
"eslint": "^6.7.2",
4143
"eslint-plugin-vue": "^6.2.2",
@@ -60,6 +62,7 @@
6062
"standard": {
6163
"ignore": [
6264
"*.config.js",
65+
"src/__tests__/*.spec.js",
6366
"dist/"
6467
]
6568
}
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
import { createLocalVue, mount } from '@vue/test-utils'
2+
import { BootstrapVue } from 'bootstrap-vue'
3+
import BootstrapVueTimeline from '../bootstrap-vue-timeline.vue'
4+
5+
const sampleItems = [
6+
{
7+
timestamp: Date.parse('2021-01-28T20:20:46.123Z'),
8+
title: 'title 1',
9+
content: 'content 1',
10+
link: 'link 1'
11+
},
12+
{
13+
timestamp: Date.parse('2021-01-28T20:20:46.456Z'),
14+
title: 'title 2',
15+
content: 'content 2',
16+
link: 'link 1'
17+
},
18+
{
19+
timestamp: Date.parse('2021-01-28T20:20:46.444Z'),
20+
title: 'title 3',
21+
content: 'content 3',
22+
link: 'link 3'
23+
}
24+
]
25+
26+
test('renders a timeline with items', () => {
27+
const localVue = createLocalVue()
28+
localVue.use(BootstrapVue)
29+
30+
const wrapper = mount(BootstrapVueTimeline, {
31+
localVue,
32+
attachTo: document.body,
33+
propsData: {
34+
items: sampleItems,
35+
reverse: false
36+
}
37+
})
38+
const text = wrapper.text()
39+
expect(text).toMatch(/content 1[\s\S]*content 2[\s\S]*content 3/)
40+
})
41+
42+
test('renders a timeline with items in reversed order', () => {
43+
const localVue = createLocalVue()
44+
localVue.use(BootstrapVue)
45+
46+
const wrapper = mount(BootstrapVueTimeline, {
47+
localVue,
48+
attachTo: document.body,
49+
propsData: {
50+
items: sampleItems,
51+
reverse: true
52+
}
53+
})
54+
const text = wrapper.text()
55+
expect(text).toMatch(/content 3[\s\S]*content 2[\s\S]*content 1/)
56+
})

src/bootstrap-vue-timeline.vue

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,20 @@ Vue.component('b-list-group-item', BListGroupItem)
88
Vue.component('b-tooltip', BTooltip)
99
1010
export default /*#__PURE__*/{
11-
name: 'BootstrapVueTimeline', // vue component name
11+
name: 'BootstrapVueTimeline',
1212
props: {
13-
items: Array
13+
items: Array,
14+
reverse: Boolean
15+
},
16+
computed: {
17+
orderedItems() {
18+
const items = this.items
19+
if (this.reverse) {
20+
items.reverse()
21+
}
22+
23+
return items
24+
}
1425
},
1526
methods: {
1627
formatAgo(timestamp) {
@@ -29,7 +40,7 @@ export default /*#__PURE__*/{
2940
<template>
3041
<b-list-group>
3142
<b-list-group-item
32-
v-for="(item, index) in items"
43+
v-for="(item, index) in orderedItems"
3344
:key="item.timestamp + item.title"
3445
:href="item.link"
3546
class="flex-column align-items-start"

0 commit comments

Comments
 (0)