address PR comments

This commit is contained in:
JeremyWuuuuu
2020-08-05 14:43:25 +08:00
committed by Herrington Darkholme
parent 2930afa650
commit 2aa90a4fa8
2 changed files with 19 additions and 14 deletions

View File

@@ -13,29 +13,23 @@ describe('Link.vue', () => {
expect(wrapper.text()).toEqual(AXIOM)
})
test('it should handle click event when href were given and is not disabled', async () => {
const href = 'https://target.com'
test('it should handle click event when link is not disabled', async () => {
const wrapper = mount(Link, {
slots: {
default: AXIOM,
},
props: {
href,
},
})
await wrapper.find('.el-link').trigger('click')
expect(wrapper.emitted('click')).toHaveLength(1)
})
test('it should disable click when it\'s disabled', async () => {
const href = 'https://target.com'
test('it should disable click when link is disabled', async () => {
const wrapper = mount(Link, {
slots: {
default: AXIOM,
},
props: {
href,
disabled: true,
},
})
@@ -45,5 +39,16 @@ describe('Link.vue', () => {
})
test('icon slots', () => {
const linkName = 'test link'
const wrapper = mount(Link, {
slots: {
default: linkName,
icon: AXIOM,
},
})
expect(wrapper.text()).toContain(linkName)
expect(wrapper.text()).toContain(AXIOM)
})
})

View File

@@ -16,19 +16,19 @@
<slot></slot>
</span>
<template v-if="$slots.icon">
<slot v-if="$slots.icon" name="icon"></slot>
</template>
<slot v-if="$slots.icon" name="icon"></slot>
</a>
</template>
<script lang='ts'>
import { defineComponent } from 'vue'
import { defineComponent, PropType } from 'vue'
type ILinkType = PropType<'primary' | 'success' | 'warning' | 'info' | 'error' | ''>
export default defineComponent({
name: 'ElLink',
props: {
type: {
type: String,
type: String as ILinkType,
default: '',
validator: (val: string) => {
return ['', 'primary', 'success', 'warning', 'info', 'error'].includes(val)
@@ -46,7 +46,7 @@ export default defineComponent({
setup(props, { emit }) {
function handleClick(event: Event) {
if (!props.disabled && !!props.href) {
if (!props.disabled) {
emit('click', event)
}
}