2021-09-19 15:10:59 +08:00
|
|
|
import { nextTick } from 'vue'
|
2020-08-04 10:54:43 +08:00
|
|
|
import { mount } from '@vue/test-utils'
|
2022-04-19 12:46:57 +08:00
|
|
|
import { describe, expect, test } from 'vitest'
|
2021-12-04 11:20:06 +08:00
|
|
|
import { CaretTop } from '@element-plus/icons-vue'
|
2021-09-19 15:10:59 +08:00
|
|
|
import Backtop from '../src/backtop.vue'
|
2022-02-23 16:59:29 +08:00
|
|
|
import type { VNode } from 'vue'
|
2020-08-04 10:54:43 +08:00
|
|
|
|
2022-02-23 16:59:29 +08:00
|
|
|
const _mount = (render: () => VNode) =>
|
|
|
|
mount(render, { attachTo: document.body })
|
2020-08-04 10:54:43 +08:00
|
|
|
|
|
|
|
describe('Backtop.vue', () => {
|
2020-08-06 23:35:23 +08:00
|
|
|
test('render', async () => {
|
2022-02-23 16:59:29 +08:00
|
|
|
const wrapper = _mount(() => (
|
2020-08-06 23:35:23 +08:00
|
|
|
<div class="target" style="height: 100px; overflow: auto">
|
|
|
|
<div style="height: 10000px; width: 100%">
|
2022-02-23 16:59:29 +08:00
|
|
|
<Backtop
|
|
|
|
target=".target"
|
|
|
|
visibilityHeight={2000}
|
|
|
|
right={100}
|
|
|
|
bottom={200}
|
|
|
|
/>
|
2020-08-06 23:35:23 +08:00
|
|
|
</div>
|
|
|
|
</div>
|
2022-02-23 16:59:29 +08:00
|
|
|
))
|
2021-09-19 15:10:59 +08:00
|
|
|
await nextTick()
|
|
|
|
|
2020-08-04 10:54:43 +08:00
|
|
|
expect(wrapper.find('.el-backtop').exists()).toBe(false)
|
|
|
|
wrapper.element.scrollTop = 2000
|
|
|
|
await wrapper.trigger('scroll')
|
|
|
|
expect(wrapper.find('.el-backtop').exists()).toBe(true)
|
2020-08-06 23:35:23 +08:00
|
|
|
|
2021-09-04 19:29:28 +08:00
|
|
|
expect(wrapper.find('.el-backtop').attributes('style')).toBe(
|
|
|
|
'right: 100px; bottom: 200px;'
|
|
|
|
)
|
2021-10-27 23:17:13 +08:00
|
|
|
expect(wrapper.findComponent(CaretTop).exists()).toBe(true)
|
2020-08-06 23:35:23 +08:00
|
|
|
|
2020-08-04 10:54:43 +08:00
|
|
|
await wrapper.trigger('click')
|
|
|
|
expect(wrapper.emitted()).toBeDefined()
|
|
|
|
})
|
|
|
|
})
|