2022-06-13 14:58:41 +08:00
|
|
|
import { nextTick, ref } from 'vue'
|
2020-09-09 21:18:08 +08:00
|
|
|
import { mount } from '@vue/test-utils'
|
2022-04-19 12:46:57 +08:00
|
|
|
import { describe, expect, test } from 'vitest'
|
2021-09-19 16:00:19 +08:00
|
|
|
import Overlay from '../src/overlay'
|
2020-09-09 21:18:08 +08:00
|
|
|
|
|
|
|
const AXIOM = 'Rem is the best girl'
|
|
|
|
|
|
|
|
describe('Overlay.vue', () => {
|
|
|
|
test('render test', async () => {
|
2022-06-13 14:58:41 +08:00
|
|
|
const wrapper = mount(() => <Overlay>{AXIOM}</Overlay>)
|
2020-09-09 21:18:08 +08:00
|
|
|
expect(wrapper.text()).toEqual(AXIOM)
|
|
|
|
const testClass = 'test-class'
|
|
|
|
await wrapper.setProps({
|
|
|
|
overlayClass: testClass,
|
|
|
|
})
|
|
|
|
|
|
|
|
expect(wrapper.find(`.${testClass}`)).toBeTruthy()
|
|
|
|
})
|
|
|
|
|
|
|
|
test('should emit click event', async () => {
|
2022-06-13 14:58:41 +08:00
|
|
|
const wrapper = mount(() => <Overlay>{AXIOM}</Overlay>)
|
2020-09-09 21:18:08 +08:00
|
|
|
await wrapper.find('.el-overlay').trigger('click')
|
|
|
|
expect(wrapper.emitted()).toBeTruthy()
|
|
|
|
})
|
|
|
|
|
|
|
|
test('no mask', async () => {
|
2022-06-13 14:58:41 +08:00
|
|
|
const mask = ref(true)
|
|
|
|
const wrapper = mount(() => <Overlay mask={mask.value}>{AXIOM}</Overlay>)
|
|
|
|
|
2020-09-09 21:18:08 +08:00
|
|
|
const selector = '.el-overlay'
|
|
|
|
expect(wrapper.find(selector).exists()).toBe(true)
|
|
|
|
|
2022-06-13 14:58:41 +08:00
|
|
|
mask.value = false
|
|
|
|
|
|
|
|
await nextTick()
|
|
|
|
|
2020-09-09 21:18:08 +08:00
|
|
|
expect(wrapper.find(selector).exists()).toBe(false)
|
2022-06-13 14:58:41 +08:00
|
|
|
|
|
|
|
mask.value = true
|
|
|
|
|
|
|
|
await nextTick()
|
|
|
|
|
2020-12-31 14:33:17 +08:00
|
|
|
expect(wrapper.find(selector).exists()).toBe(true)
|
2020-09-09 21:18:08 +08:00
|
|
|
})
|
|
|
|
})
|