2022-01-04 09:15:15 +08:00
|
|
|
import { h } from 'vue'
|
2021-12-30 19:31:35 +08:00
|
|
|
import { PopupManager } from '@element-plus/utils/popup-manager'
|
2021-08-24 13:36:48 +08:00
|
|
|
import makeMount from '@element-plus/test-utils/make-mount'
|
|
|
|
import Popover from '../src/index.vue'
|
2020-10-19 13:44:50 +08:00
|
|
|
|
|
|
|
const AXIOM = 'Rem is the best girl'
|
|
|
|
|
|
|
|
const mount = makeMount(Popover, {
|
|
|
|
slots: {
|
2022-01-04 09:15:15 +08:00
|
|
|
default: () => AXIOM,
|
|
|
|
reference: () => h('button', 'click me'),
|
2020-10-19 13:44:50 +08:00
|
|
|
},
|
2020-12-03 22:43:18 +08:00
|
|
|
props: {
|
|
|
|
appendToBody: false,
|
|
|
|
},
|
2022-01-04 09:15:15 +08:00
|
|
|
global: {
|
|
|
|
attachTo: document.body,
|
|
|
|
},
|
2020-10-19 13:44:50 +08:00
|
|
|
})
|
|
|
|
describe('Popover.vue', () => {
|
2022-01-04 09:15:15 +08:00
|
|
|
let wrapper: ReturnType<typeof mount>
|
|
|
|
const findContentComp = () =>
|
|
|
|
wrapper.findComponent({
|
|
|
|
name: 'ElPopperContent',
|
|
|
|
})
|
|
|
|
|
|
|
|
afterEach(() => {
|
|
|
|
wrapper?.unmount()
|
|
|
|
document.body.innerHTML = ''
|
|
|
|
})
|
|
|
|
|
2020-10-19 13:44:50 +08:00
|
|
|
test('render test', () => {
|
2022-01-04 09:15:15 +08:00
|
|
|
wrapper = mount()
|
|
|
|
|
|
|
|
expect(findContentComp().text()).toEqual(AXIOM)
|
2020-10-19 13:44:50 +08:00
|
|
|
})
|
|
|
|
|
|
|
|
test('should render with title', () => {
|
|
|
|
const title = 'test title'
|
2022-01-04 09:15:15 +08:00
|
|
|
wrapper = mount({
|
2020-10-19 13:44:50 +08:00
|
|
|
props: {
|
|
|
|
title,
|
|
|
|
},
|
|
|
|
})
|
|
|
|
|
2022-01-04 09:15:15 +08:00
|
|
|
expect(findContentComp().text()).toContain(title)
|
2020-10-19 13:44:50 +08:00
|
|
|
})
|
|
|
|
|
2021-09-04 19:29:28 +08:00
|
|
|
test("should modify popover's style with width", async () => {
|
2022-01-04 09:15:15 +08:00
|
|
|
wrapper = mount({
|
2020-10-19 13:44:50 +08:00
|
|
|
props: {
|
|
|
|
width: 200,
|
|
|
|
},
|
|
|
|
})
|
|
|
|
|
2022-01-04 09:15:15 +08:00
|
|
|
const popperContent = findContentComp()
|
|
|
|
expect(getComputedStyle(popperContent.element).width).toBe('200px')
|
2020-10-19 13:44:50 +08:00
|
|
|
|
|
|
|
await wrapper.setProps({
|
|
|
|
width: '100vw',
|
|
|
|
})
|
|
|
|
|
2022-01-04 09:15:15 +08:00
|
|
|
expect(getComputedStyle(popperContent.element).width).toBe('100vw')
|
2020-10-19 13:44:50 +08:00
|
|
|
})
|
|
|
|
|
|
|
|
test('the content should be overrode by slots', () => {
|
|
|
|
const content = 'test content'
|
2022-01-04 09:15:15 +08:00
|
|
|
wrapper = mount({
|
2020-10-19 13:44:50 +08:00
|
|
|
props: {
|
|
|
|
content,
|
|
|
|
},
|
|
|
|
})
|
2022-01-04 09:15:15 +08:00
|
|
|
expect(findContentComp().text()).toContain(AXIOM)
|
2020-10-19 13:44:50 +08:00
|
|
|
})
|
|
|
|
|
|
|
|
test('should render content when no slots were passed', () => {
|
|
|
|
const content = 'test content'
|
2022-01-04 09:15:15 +08:00
|
|
|
const virtualRef = document.createElement('button')
|
|
|
|
wrapper = makeMount(Popover, {
|
2020-10-19 13:44:50 +08:00
|
|
|
props: {
|
|
|
|
content,
|
2020-12-03 22:43:18 +08:00
|
|
|
appendToBody: false,
|
2022-01-04 09:15:15 +08:00
|
|
|
virtualRef,
|
|
|
|
virtualTriggering: true,
|
2020-10-19 13:44:50 +08:00
|
|
|
},
|
|
|
|
})()
|
|
|
|
|
2022-01-04 09:15:15 +08:00
|
|
|
expect(findContentComp().text()).toBe(content)
|
2020-10-19 13:44:50 +08:00
|
|
|
})
|
2020-11-20 10:04:20 +08:00
|
|
|
|
|
|
|
test('popper z-index should be dynamical', () => {
|
2022-01-04 09:15:15 +08:00
|
|
|
wrapper = mount()
|
2020-11-20 10:04:20 +08:00
|
|
|
|
|
|
|
expect(
|
2022-01-04 09:15:15 +08:00
|
|
|
Number.parseInt(window.getComputedStyle(findContentComp().element).zIndex)
|
|
|
|
).toBeLessThanOrEqual(
|
|
|
|
PopupManager.zIndex + PopupManager.globalInitialZIndex
|
|
|
|
)
|
2021-03-26 16:01:29 +08:00
|
|
|
})
|
2020-10-19 13:44:50 +08:00
|
|
|
})
|