Skip to content

Commit df0949a

Browse files
committed
Check the click callback for FollowButtons
1 parent f5b6666 commit df0949a

File tree

3 files changed

+38
-7
lines changed

3 files changed

+38
-7
lines changed

components/Global/Elements/BlockButton/BlockButton.vue

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
</template>
1212
</hc-button>
1313
</template>
14+
1415
<script>
1516
import Icon from '~/components/Global/Elements/Icon/Icon.vue'
1617
import Button from '~/components/Global/Elements/Button/Button.vue'

components/Global/Elements/Follow/FollowButtons.test.js

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,7 @@ const localVue = createLocalVue()
66

77
localVue.use(Vuex)
88

9-
const propsData = {
10-
entity: {
11-
_id: 4711,
12-
name: 'author'
13-
}
14-
}
9+
let propsData
1510

1611
const mocks = { $t: () => {} }
1712

@@ -23,10 +18,21 @@ describe('FollowButtons.vue', () => {
2318
let currentUser
2419

2520
beforeEach(() => {
21+
propsData = {
22+
entity: {
23+
_id: 4711,
24+
name: 'author'
25+
}
26+
}
2627
currentUser = {
2728
_id: 42
2829
}
2930
getters = {
31+
'connections/follow': () => {
32+
return { isPending: false, isFollowing: false }
33+
},
34+
'feathers-vuex-usersettings/current': () => { return {} },
35+
'feathers-vuex-usersettings/isPending': () => false,
3036
'auth/user': () => { return currentUser },
3137
}
3238
actions = {
@@ -42,4 +48,21 @@ describe('FollowButtons.vue', () => {
4248
wrapper = shallowMount(FollowButtons, { store, localVue, propsData, mocks })
4349
expect(wrapper.is('div')).toBeTruthy()
4450
})
51+
52+
describe('showButtons === true', () => {
53+
beforeEach(() => {
54+
propsData.showButtons = true
55+
})
56+
57+
describe('click', () => {
58+
test('calls `click` method', () => {
59+
const methods = {
60+
click: jest.fn()
61+
}
62+
wrapper = mount(FollowButtons, { store, localVue, propsData, mocks, methods })
63+
wrapper.find('button').trigger('click')
64+
expect(methods.click).toHaveBeenCalled()
65+
})
66+
})
67+
})
4568
})

components/Global/Elements/Follow/FollowButtons.vue

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
<div class="column control has-text-centered">
1919
<hc-button color="button is-fullwidth"
2020
:class="{'is-primary': !follow.isPending && !follow.isFollowing}"
21-
@click="toggleFollow"
21+
@click="click"
2222
:disabled="follow.isPending"
2323
:isLoading="follow.isPending">
2424
<template v-if="follow.isFollowing">
@@ -39,11 +39,15 @@
3939
<script>
4040
import { mapGetters } from 'vuex'
4141
import BlockButton from '~/components/Global/Elements/BlockButton/BlockButton'
42+
import Icon from '~/components/Global/Elements/Icon/Icon.vue'
43+
import Button from '~/components/Global/Elements/Button/Button.vue'
4244
4345
export default {
4446
name: 'hc-follow-buttons',
4547
components: {
4648
'hc-block-button': BlockButton,
49+
'hc-button': Button,
50+
'hc-icon': Icon
4751
},
4852
props: {
4953
showButtons: {
@@ -94,6 +98,9 @@
9498
onConfirm: () => { next() }
9599
})
96100
},
101+
async click(){
102+
return this.toggleFollow();
103+
},
97104
async toggleFollow () {
98105
if (this.follow._id) {
99106
await this.$store.dispatch('connections/unfollow', {

0 commit comments

Comments
 (0)