fix(Link): [Link]Link text link theme style, when the mouse is placed on it, the same color is displayed (#1005)

* fix(Link): [Link]Link text link theme style, when the mouse is placed on it, the same color is displayed

* test(Link): [Link]add full unit test to Link
This commit is contained in:
AcWrong02 2023-12-04 16:24:36 +08:00 committed by GitHub
parent d9e63060c0
commit 7a37639d56
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 63 additions and 9 deletions

View File

@ -27,6 +27,7 @@
&:hover {
text-decoration: none;
color: @hover-color;
}
&.is-disabled,

View File

@ -1,12 +1,16 @@
import Link from '@opentiny/vue-link'
import { describe, expect, test } from 'vitest'
import { iconEdit } from '@opentiny/vue-icon'
import { mountPcMode } from '@opentiny-internal/vue-test-utils'
const iconTest = 'IconDel()'
const IconEdit = iconEdit()
describe('PC Mode', () => {
const mount = mountPcMode
const createLink = (type) => {
return mount(() => <Link underline={false} type={type}></Link>)
}
/**
* attrs
*/
@ -15,27 +19,76 @@ describe('PC Mode', () => {
expect(wrapper.find('.tiny-link').attributes().href).toBe('localhost:3000/#/zh-CN/index')
})
test.todo('type 该属性的可选值为 primary / success / warning / danger / info。默认为 default')
// type 该属性的可选值为 primary / success / warning / danger / info。默认为 default
test.each([
['primary', 'Primary link should have the proper class'],
['success', 'Success link should have the proper class'],
['warning', 'Warning link should have the proper class'],
['danger', 'Danger link should have the proper class'],
['info', 'Info link should have the proper class']
])('type %s', (type, description) => {
const wrapper = createLink(type)
expect(wrapper.find(`.tiny-link--${type}`).exists()).toBe(true)
})
test.todo('underline 是否下划线。默认为 true')
test('underline 是否下划线。默认为 true', async () => {
// undeline=true && disabled=false
let wrapper = mount(() => <Link></Link>)
expect(wrapper.find('.is-underline').exists()).toBe(true)
test.todo('disabled 是否禁用状态。默认为 false')
// undeline=false && disabled=true
wrapper = mount(() => <Link disabled></Link>)
expect(wrapper.find('.is-underline').exists()).toBe(false)
test.todo('icon 图标类名')
// undeline=true && disabled=true
wrapper = mount(() => <Link disabled></Link>)
expect(wrapper.find('.is-underline').exists()).toBe(false)
// undeline=false && disabled=false
wrapper = mount(() => <Link underline={false}></Link>)
expect(wrapper.find('.is-underline').exists()).toBe(false)
})
test('非disabled下可以触发click事件', async () => {
const wrapper = mount(() => <Link>TEST</Link>)
await wrapper.trigger('click')
expect(wrapper.emitted('click')).toHaveLength(1)
})
test('disabled 是否禁用状态。默认为 false', async () => {
const wrapper = mount(() => <Link disabled></Link>)
expect(wrapper.classes()).toContain('is-disabled')
expect(wrapper.attributes('href')).toBeUndefined()
})
test('icon 图标类名', async () => {
const wrapper = mount(() => <Link icon={IconEdit}></Link>)
expect(wrapper.findComponent(IconEdit).exists()).toBe(true)
expect(wrapper.find('.tiny-svg-size.tiny-link-svg').exists()).toBe(true)
})
/**
* slots
*/
test('default slot', async () => {
test('icon 图标插槽', async () => {
const wrapper = mount(() => (
<Link
v-slots={{
icon: () => iconTest
}}
></Link>
}}></Link>
))
expect(wrapper.text()).toContain(iconTest)
})
test.todo('icon 图标插槽')
test('default slot', async () => {
const wrapper = mount(() => (
<Link
v-slots={{
default: () => iconTest
}}></Link>
))
expect(wrapper.text()).toContain(iconTest)
})
})