element-plus/packages/components/popover/__tests__/popover.spec.ts
jeremywu dd19cae2bc
refactor(components): popper composables (#5035)
* refactor(components): popper composables

- Refactor popper composables

* updates

* updates for tooltip

* Updates for popper. TODO: fix controlled tooltip animation

* Fix controlled mode popper animation issue

* Add new feature for customizing tooltip theme

* Fix popover and popconfirm error

* - Add Collection component for wrapping a collection of component
- Add FocusTrap component for trap focus for popups
- Add RovingFocus component for roving focus component type
- Adjust dropdown component based on these newly added components
- Add popper-trigger component for placing the trigger
- TODO: Finish current dropdown component, and all component's tests plus documents

* Refactor popper

* Complete organizing popper

* Almost finish dropdown

* Update popper tests

* update only-child test

* Finish focus trap component test

* Finish tooltip content test

* Finish tooltip trigger tests

* Finish tooltip tests

* finish tests for Collection and RovingFocusGroup

* Fix test cases for timeselect & select & popover

* Fix popover, popconfirm, menu bug and test cases

* Fix select-v2 test error caused by updating popper

* Fix date-picker test issue for updating popper

* fix test cases

* Fix eslint

* Rebase dev & fix tests

* Remove unused code
2022-01-04 09:15:15 +08:00

101 lines
2.2 KiB
TypeScript

import { h } from 'vue'
import { PopupManager } from '@element-plus/utils/popup-manager'
import makeMount from '@element-plus/test-utils/make-mount'
import Popover from '../src/index.vue'
const AXIOM = 'Rem is the best girl'
const mount = makeMount(Popover, {
slots: {
default: () => AXIOM,
reference: () => h('button', 'click me'),
},
props: {
appendToBody: false,
},
global: {
attachTo: document.body,
},
})
describe('Popover.vue', () => {
let wrapper: ReturnType<typeof mount>
const findContentComp = () =>
wrapper.findComponent({
name: 'ElPopperContent',
})
afterEach(() => {
wrapper?.unmount()
document.body.innerHTML = ''
})
test('render test', () => {
wrapper = mount()
expect(findContentComp().text()).toEqual(AXIOM)
})
test('should render with title', () => {
const title = 'test title'
wrapper = mount({
props: {
title,
},
})
expect(findContentComp().text()).toContain(title)
})
test("should modify popover's style with width", async () => {
wrapper = mount({
props: {
width: 200,
},
})
const popperContent = findContentComp()
expect(getComputedStyle(popperContent.element).width).toBe('200px')
await wrapper.setProps({
width: '100vw',
})
expect(getComputedStyle(popperContent.element).width).toBe('100vw')
})
test('the content should be overrode by slots', () => {
const content = 'test content'
wrapper = mount({
props: {
content,
},
})
expect(findContentComp().text()).toContain(AXIOM)
})
test('should render content when no slots were passed', () => {
const content = 'test content'
const virtualRef = document.createElement('button')
wrapper = makeMount(Popover, {
props: {
content,
appendToBody: false,
virtualRef,
virtualTriggering: true,
},
})()
expect(findContentComp().text()).toBe(content)
})
test('popper z-index should be dynamical', () => {
wrapper = mount()
expect(
Number.parseInt(window.getComputedStyle(findContentComp().element).zIndex)
).toBeLessThanOrEqual(
PopupManager.zIndex + PopupManager.globalInitialZIndex
)
})
})