2021-01-05 16:28:11 +08:00
|
|
|
import { nextTick } from 'vue'
|
2022-04-19 12:46:57 +08:00
|
|
|
import { describe, expect, test } from 'vitest'
|
2021-01-05 16:28:11 +08:00
|
|
|
|
|
|
|
import { IMAGE_SUCCESS } from '@element-plus/test-utils/mock'
|
|
|
|
import makeMount from '@element-plus/test-utils/make-mount'
|
2021-10-18 16:24:52 +08:00
|
|
|
import ImageViewer from '../src/image-viewer.vue'
|
2021-01-05 16:28:11 +08:00
|
|
|
|
|
|
|
const mount = makeMount(ImageViewer, {
|
|
|
|
props: {
|
|
|
|
urlList: [IMAGE_SUCCESS],
|
|
|
|
},
|
|
|
|
})
|
|
|
|
|
|
|
|
async function doubleWait() {
|
|
|
|
await nextTick()
|
|
|
|
await nextTick()
|
|
|
|
}
|
|
|
|
|
|
|
|
describe('<image-viewer />', () => {
|
2021-09-04 19:29:28 +08:00
|
|
|
test('big image preview', async () => {
|
2021-01-05 16:28:11 +08:00
|
|
|
const wrapper = mount()
|
|
|
|
await doubleWait()
|
|
|
|
const viewer = wrapper.find('.el-image-viewer__wrapper')
|
|
|
|
expect(viewer.exists()).toBe(true)
|
|
|
|
await wrapper.find('.el-image-viewer__close').trigger('click')
|
|
|
|
expect(wrapper.emitted('close')).toEqual([[]])
|
2022-04-19 17:37:56 +08:00
|
|
|
wrapper.unmount()
|
2021-01-05 16:28:11 +08:00
|
|
|
})
|
|
|
|
|
|
|
|
test('image preview hide-click-on-modal', async () => {
|
|
|
|
const wrapper = mount()
|
|
|
|
|
|
|
|
await doubleWait()
|
|
|
|
const viewer = wrapper.find('.el-image-viewer__wrapper')
|
|
|
|
expect(viewer.exists()).toBe(true)
|
|
|
|
await wrapper.find('.el-image-viewer__mask').trigger('click')
|
|
|
|
expect(wrapper.emitted('close')).toBeUndefined()
|
|
|
|
|
|
|
|
await wrapper.setProps({
|
|
|
|
hideOnClickModal: true,
|
|
|
|
})
|
|
|
|
|
|
|
|
await wrapper.find('.el-image-viewer__mask').trigger('click')
|
|
|
|
expect(wrapper.emitted('close')).toBeDefined()
|
2022-04-19 17:37:56 +08:00
|
|
|
wrapper.unmount()
|
2021-01-05 16:28:11 +08:00
|
|
|
})
|
|
|
|
})
|