2020-08-04 22:40:00 +08:00
|
|
|
import { mount } from '@vue/test-utils'
|
2022-03-25 15:35:56 +08:00
|
|
|
import { describe, expect, it } from 'vitest'
|
2021-09-22 00:48:26 +08:00
|
|
|
import Link from '../src/link.vue'
|
2020-08-04 22:40:00 +08:00
|
|
|
|
|
|
|
const AXIOM = 'Rem is the best girl'
|
|
|
|
|
|
|
|
describe('Link.vue', () => {
|
2022-03-12 17:21:20 +08:00
|
|
|
it('render test', () => {
|
2022-06-07 13:08:21 +08:00
|
|
|
const wrapper = mount(() => <Link>{AXIOM}</Link>)
|
|
|
|
|
2020-08-04 22:40:00 +08:00
|
|
|
expect(wrapper.text()).toEqual(AXIOM)
|
|
|
|
})
|
|
|
|
|
2022-03-12 17:21:20 +08:00
|
|
|
it('it should handle click event when link is not disabled', async () => {
|
2022-06-07 13:08:21 +08:00
|
|
|
const wrapper = mount(() => <Link>{AXIOM}</Link>)
|
2020-08-04 22:40:00 +08:00
|
|
|
|
2022-06-07 13:08:21 +08:00
|
|
|
await wrapper.trigger('click')
|
2020-08-04 22:40:00 +08:00
|
|
|
expect(wrapper.emitted('click')).toHaveLength(1)
|
|
|
|
})
|
|
|
|
|
2022-03-12 17:21:20 +08:00
|
|
|
it('it should disable click when link is disabled', async () => {
|
2022-06-07 13:08:21 +08:00
|
|
|
const wrapper = mount(() => <Link disabled>{AXIOM}</Link>)
|
|
|
|
|
|
|
|
expect(wrapper.classes()).toContain('is-disabled')
|
|
|
|
expect(wrapper.attributes('href')).toBeUndefined()
|
2020-08-04 22:40:00 +08:00
|
|
|
})
|
|
|
|
|
2022-03-12 17:21:20 +08:00
|
|
|
it('icon slots', () => {
|
2020-08-05 14:43:25 +08:00
|
|
|
const linkName = 'test link'
|
2022-06-07 13:08:21 +08:00
|
|
|
|
|
|
|
const wrapper = mount(() => (
|
|
|
|
<Link
|
|
|
|
v-slots={{
|
|
|
|
default: () => linkName,
|
|
|
|
icon: () => AXIOM,
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
))
|
2020-08-05 14:43:25 +08:00
|
|
|
expect(wrapper.text()).toContain(linkName)
|
|
|
|
expect(wrapper.text()).toContain(AXIOM)
|
|
|
|
})
|
2020-08-04 22:40:00 +08:00
|
|
|
})
|