import { markRaw, nextTick } from 'vue'
import { mount } from '@vue/test-utils'
import { describe, expect, test, vi } from 'vitest'
import { rAF } from '@element-plus/test-utils/tick'
import triggerCompositeClick from '@element-plus/test-utils/composite-click'
import { Delete } from '@element-plus/icons-vue'
import Dialog from '../src/dialog.vue'
import triggerEvent from '@element-plus/test-utils/trigger-event'
import { EVENT_CODE } from '@element-plus/constants'
const AXIOM = 'Rem is the best girl'
describe('Dialog.vue', () => {
test('render test', async () => {
const wrapper = mount()
await nextTick()
await rAF()
await nextTick()
expect(wrapper.find('.el-dialog__body').text()).toEqual(AXIOM)
})
test('dialog should have a title and header when it has been given', async () => {
const HEADER = 'I am header'
const wrapper = mount(
)
await nextTick()
expect(wrapper.find('.el-dialog__header').text()).toBe(HEADER)
mount(
)
await nextTick()
expect(wrapper.find('.el-dialog__header').text()).toBe(HEADER)
})
test('dialog header should have slot props', async () => {
const wrapper = mount(
)
await nextTick()
const headerButton = wrapper.find('button')
expect(headerButton.attributes()['data-title-id']).toBeTruthy()
expect(headerButton.attributes()['data-title-class']).toBe(
'el-dialog__title'
)
expect(wrapper.emitted().close).toBeFalsy()
headerButton.trigger('click')
await nextTick()
expect(wrapper.emitted()).toHaveProperty('close')
})
test('dialog should have a footer when footer has been given', async () => {
const wrapper = mount(
)
await nextTick()
expect(wrapper.find('.el-dialog__footer').exists()).toBe(true)
expect(wrapper.find('.el-dialog__footer').text()).toBe(AXIOM)
})
test('should append dialog to body when appendToBody is true', async () => {
const wrapper = mount(
)
await nextTick()
expect(
document.body.firstElementChild!.classList.contains('el-overlay')
).toBe(true)
wrapper.unmount()
})
test('should center dialog', async () => {
const wrapper = mount(
)
await nextTick()
expect(wrapper.find('.el-dialog--center').exists()).toBe(true)
})
test('should show close button', async () => {
const wrapper = mount()
await nextTick()
expect(wrapper.find('.el-dialog__close').exists()).toBe(true)
})
test('should hide close button when showClose = false', async () => {
const wrapper = mount(
)
await nextTick()
expect(wrapper.find('.el-dialog__headerbtn').exists()).toBe(false)
})
test('should close dialog when click on close button', async () => {
const wrapper = mount()
await nextTick()
await wrapper.find('.el-dialog__headerbtn').trigger('click')
expect(wrapper.vm.visible).toBe(false)
})
test('should render header-class, body-class and footer-class if setted', async () => {
const headerCls = 'test-header-class'
const bodyCls = 'test-body-class'
const footerCls = 'test-footer-class'
const wrapper = mount(