overlay.test.tsx 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. import { nextTick, ref } from 'vue'
  2. import { mount } from '@vue/test-utils'
  3. import { describe, expect, test } from 'vitest'
  4. import { ElMessageBox } from '@element-plus/components/message-box'
  5. import ConfigProvider from '@element-plus/components/config-provider'
  6. import Overlay from '../src/overlay'
  7. const AXIOM = 'Rem is the best girl'
  8. describe('Overlay.vue', () => {
  9. test('render test', async () => {
  10. const wrapper = mount(() => <Overlay>{AXIOM}</Overlay>)
  11. expect(wrapper.text()).toEqual(AXIOM)
  12. const testClass = 'test-class'
  13. await wrapper.setProps({
  14. overlayClass: testClass,
  15. })
  16. expect(wrapper.find(`.${testClass}`)).toBeTruthy()
  17. })
  18. test('should emit click event', async () => {
  19. const wrapper = mount(() => <Overlay>{AXIOM}</Overlay>)
  20. await wrapper.find('.el-overlay').trigger('click')
  21. expect(wrapper.emitted()).toBeTruthy()
  22. })
  23. test('no mask', async () => {
  24. const mask = ref(true)
  25. const wrapper = mount(() => <Overlay mask={mask.value}>{AXIOM}</Overlay>)
  26. const selector = '.el-overlay'
  27. expect(wrapper.find(selector).exists()).toBe(true)
  28. mask.value = false
  29. await nextTick()
  30. expect(wrapper.find(selector).exists()).toBe(false)
  31. mask.value = true
  32. await nextTick()
  33. expect(wrapper.find(selector).exists()).toBe(true)
  34. })
  35. test('global', async () => {
  36. const testNamespace = 'test'
  37. const callout = () => {
  38. ElMessageBox.prompt('Title', 'Description')
  39. }
  40. const wrapper = mount(() => {
  41. return (
  42. <ConfigProvider namespace={testNamespace}>
  43. <button onClick={callout}>{AXIOM}</button>
  44. </ConfigProvider>
  45. )
  46. })
  47. expect(document.body.querySelector(`.${testNamespace}-overlay`)).toBeNull()
  48. await wrapper.find('button').trigger('click')
  49. await nextTick()
  50. expect(
  51. document.body.querySelector(`.${testNamespace}-overlay`)
  52. ).toBeDefined()
  53. })
  54. })