Skip to content

Commit a10d9ee

Browse files
committed
First test case implemented
1 parent 667ec93 commit a10d9ee

3 files changed

Lines changed: 28 additions & 36 deletions

File tree

components/Global/Elements/BlockButton/BlockButton.vue

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
<div class="columns is-mobile field has-text-centered">
33
<div class="column control has-text-centered">
44
<hc-button color="button"
5-
:disabled="blacklistPending"
6-
:isLoading="blacklistPending"
5+
:disabled="isPending"
6+
:isLoading="isPending"
77
@click="clickBlacklistButton">
88
<template v-if="isBlacklisted">
99
<hc-icon icon="ban" :class="['icon-left', 'is-danger']" /> {{ $t('component.blacklist.buttonLabelUnblock') }}
@@ -16,25 +16,17 @@
1616
</div>
1717
</template>
1818
<script>
19-
import icon from '~/components/Global/Elements/Icon/Icon.vue'
20-
import button from '~/components/Global/Elements/Button/Button.vue'
19+
import Icon from '../Icon/Icon.vue'
20+
import Button from '../Button/Button.vue'
2121
2222
export default {
2323
name: 'hc-block-button',
2424
components: {
25-
button,
26-
icon
25+
Button,
26+
Icon
2727
},
2828
props: {
29-
entity: {
30-
type: Object,
31-
required: true
32-
},
33-
currentUser: {
34-
type: Object
35-
// TODO: required: true
36-
},
37-
blacklistPending: {
29+
isPending: {
3830
type: Boolean,
3931
default: false
4032
},
Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,41 @@
11
import test from 'ava'
2-
import { shallowMount, mount } from '@vue/test-utils'
3-
import { render } from '@vue/server-test-utils'
2+
import { mount } from '@vue/test-utils'
43
import BlockButton from '../../../../../components/Global/Elements/BlockButton/BlockButton'
4+
import Icon from '../../../../../components/Global/Elements/Icon/Icon.vue'
5+
import Button from '../../../../../components/Global/Elements/Button/Button.vue'
56

6-
const entity = { id: 42 }
7-
const currentUser = { id: 47 }
8-
const toggleBlacklist = () => {}
9-
10-
test('It renders a `<div>`.', (t) => {
11-
const entity = { id: 42 }
12-
const wrapper = shallowMount(BlockButton, {
7+
const mountBlockButton = (propsData = {}) => {
8+
return mount(BlockButton, {
139
mocks: { $t: () => {} },
14-
props: {entity, currentUser, toggleBlacklist}
10+
propsData
1511
})
12+
}
1613

14+
test('It renders a `<div>`.', (t) => {
15+
const wrapper = mountBlockButton()
1716
t.true(wrapper.is('div'))
1817
})
1918

20-
test('shows a button, when currentUser !== foreignEntity', (t) => {
21-
const wrapper = mount(BlockButton, {
22-
mocks: { $t: () => {} },
23-
props: {entity, currentUser, toggleBlacklist}
24-
})
25-
26-
t.truthy(wrapper.contains('i'))
27-
})
28-
2919
test('is enabled when no request is currently pending', (t) => {
20+
const wrapper = mountBlockButton({isPending: false})
21+
t.deepEqual(wrapper.findAll('hc-button').length, 1)
22+
t.deepEqual(wrapper.find('hc-button').attributes(), {color: 'button'})
3023
})
3124

3225
test('shows a loading spinner when a request is pending', (t) => {
26+
const wrapper = mountBlockButton({isPending: true})
27+
t.truthy(wrapper.find('hc-button').attributes().isloading)
3328
})
3429

3530
test('is disabled when a request is pending', (t) => {
31+
const wrapper = mountBlockButton({isPending: true})
32+
t.truthy(wrapper.find('hc-button').attributes().disabled)
33+
})
34+
35+
/*
36+
test('calls toggleBlacklist on click', (t) => {
3637
})
3738
3839
test('opens a confirmation dialog if foreignEntity is being followed', (t) => {
3940
})
41+
*/

test/helpers/setup.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,3 @@ require('browser-env')()
77
hooks('vue').plugin('vue').push()
88
// Setup vue and js files to be processed by `require-extension-hooks-babel`
99
hooks(['vue', 'js']).plugin('babel', { plugins: ['transform-object-rest-spread'] }).push()
10-
11-

0 commit comments

Comments
 (0)