123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818 |
- // @ts-nocheck
- import { nextTick } from 'vue'
- import { mount } from '@vue/test-utils'
- import { afterEach, describe, expect, test, vi } from 'vitest'
- import { rAF } from '@element-plus/test-utils/tick'
- import { EVENT_CODE } from '@element-plus/constants'
- import { ElTooltip } from '@element-plus/components/tooltip'
- import Button from '@element-plus/components/button'
- import { usePopperContainerId } from '@element-plus/hooks'
- import Dropdown from '../src/dropdown.vue'
- import DropdownItem from '../src/dropdown-item.vue'
- import DropdownMenu from '../src/dropdown-menu.vue'
- const MOUSE_ENTER_EVENT = 'mouseenter'
- const MOUSE_LEAVE_EVENT = 'mouseleave'
- const CONTEXTMENU = 'contextmenu'
- const _mount = (template: string, data, otherObj?) =>
- mount({
- components: {
- [Button.name]: Button,
- [Dropdown.name]: Dropdown,
- [DropdownItem.name]: DropdownItem,
- [DropdownMenu.name]: DropdownMenu,
- },
- template,
- data,
- ...otherObj,
- })
- describe('Dropdown', () => {
- afterEach(() => {
- document.body.innerHTML = ''
- })
- test('create', async () => {
- const wrapper = _mount(
- `
- <el-dropdown ref="b" placement="right">
- <span class="el-dropdown-link" ref="a">
- dropdown<i class="el-icon-arrow-down el-icon--right"></i>
- </span>
- <template #dropdown>
- <el-dropdown-menu>
- <el-dropdown-item>Apple</el-dropdown-item>
- <el-dropdown-item>Orange</el-dropdown-item>
- <el-dropdown-item>Cherry</el-dropdown-item>
- <el-dropdown-item disabled>Peach</el-dropdown-item>
- <el-dropdown-item divided>Pear</el-dropdown-item>
- </el-dropdown-menu>
- </template>
- </el-dropdown>
- `,
- () => ({})
- )
- await nextTick()
- const content = wrapper.findComponent(ElTooltip).vm as InstanceType<
- typeof ElTooltip
- >
- vi.useFakeTimers()
- const triggerElm = wrapper.find('.el-tooltip__trigger')
- expect(content.open).toBe(false)
- await triggerElm.trigger(MOUSE_ENTER_EVENT)
- vi.runAllTimers()
- expect(content.open).toBe(true)
- await triggerElm.trigger(MOUSE_LEAVE_EVENT)
- vi.runAllTimers()
- expect(content.open).toBe(false)
- vi.useRealTimers()
- })
- test('menu click', async () => {
- const commandHandler = vi.fn()
- const wrapper = _mount(
- `
- <el-dropdown ref="b" @command="commandHandler" placement="right">
- <span class="el-dropdown-link" ref="a">
- dropdown<i class="el-icon-arrow-down el-icon--right"></i>
- </span>
- <template #dropdown>
- <el-dropdown-menu>
- <el-dropdown-item command="a">Apple</el-dropdown-item>
- <el-dropdown-item command="b">Orange</el-dropdown-item>
- <el-dropdown-item ref="c" :command="myCommandObject">Cherry</el-dropdown-item>
- <el-dropdown-item command="d">Peach</el-dropdown-item>
- <el-dropdown-item command="e">Pear</el-dropdown-item>
- </el-dropdown-menu>
- </template>
- </el-dropdown>
- `,
- () => ({
- myCommandObject: { name: 'CommandC' },
- name: '',
- }),
- {
- methods: {
- commandHandler,
- },
- }
- )
- await nextTick()
- // const content = wrapper.findComponent({ ref: 'b' }).vm as any
- const triggerElm = wrapper.find('.el-tooltip__trigger')
- await triggerElm.trigger(MOUSE_ENTER_EVENT)
- await nextTick()
- await wrapper
- .findComponent({ ref: 'c' })
- .findComponent({
- name: 'DropdownItemImpl',
- })
- .find('.el-dropdown-menu__item')
- .trigger('click')
- await nextTick()
- expect(commandHandler).toHaveBeenCalled()
- })
- test('trigger', async () => {
- const wrapper = _mount(
- `
- <el-dropdown trigger="click" ref="b" placement="right">
- <span class="el-dropdown-link" ref="a">
- dropdown<i class="el-icon-arrow-down el-icon--right"></i>
- </span>
- <template #dropdown>
- <el-dropdown-menu>
- <el-dropdown-item command="a">Apple</el-dropdown-item>
- <el-dropdown-item command="b">Orange</el-dropdown-item>
- <el-dropdown-item ref="c" :command="myCommandObject">Cherry</el-dropdown-item>
- <el-dropdown-item command="d">Peach</el-dropdown-item>
- <el-dropdown-item command="e">Pear</el-dropdown-item>
- </el-dropdown-menu>
- </template>
- </el-dropdown>
- `,
- () => ({
- myCommandObject: { name: 'CommandC' },
- name: '',
- })
- )
- await nextTick()
- const content = wrapper.findComponent(ElTooltip).vm as InstanceType<
- typeof ElTooltip
- >
- const triggerElm = wrapper.find('.el-dropdown-link')
- expect(content.open).toBe(false)
- await triggerElm.trigger(MOUSE_ENTER_EVENT)
- expect(content.open).toBe(false)
- await triggerElm.trigger('click', {
- button: 0,
- })
- await rAF()
- expect(content.open).toBe(true)
- })
- test('trigger contextmenu', async () => {
- const wrapper = _mount(
- `
- <el-dropdown trigger="contextmenu" ref="b" placement="right">
- <span class="el-dropdown-link" ref="a">
- dropdown<i class="el-icon-arrow-down el-icon--right"></i>
- </span>
- <template #dropdown>
- <el-dropdown-menu>
- <el-dropdown-item command="a">Apple</el-dropdown-item>
- <el-dropdown-item command="b">Orange</el-dropdown-item>
- <el-dropdown-item ref="c" :command="myCommandObject">Cherry</el-dropdown-item>
- <el-dropdown-item command="d">Peach</el-dropdown-item>
- <el-dropdown-item command="e">Pear</el-dropdown-item>
- </el-dropdown-menu>
- </template>
- </el-dropdown>
- `,
- () => ({
- myCommandObject: { name: 'CommandC' },
- name: '',
- })
- )
- await nextTick()
- const content = wrapper.findComponent(ElTooltip).vm as InstanceType<
- typeof ElTooltip
- >
- const triggerElm = wrapper.find('.el-dropdown-link')
- expect(content.open).toBe(false)
- await triggerElm.trigger(CONTEXTMENU)
- await rAF()
- expect(content.open).toBe(true)
- })
- test('handleOpen and handleClose', async () => {
- const wrapper = _mount(
- `
- <el-dropdown trigger="click" ref="refDropdown" placement="right">
- <span class="el-dropdown-link" ref="a">
- dropdown<i class="el-icon-arrow-down el-icon--right"></i>
- </span>
- <template #dropdown>
- <el-dropdown-menu>
- <el-dropdown-item command="a">Apple</el-dropdown-item>
- <el-dropdown-item command="b">Orange</el-dropdown-item>
- <el-dropdown-item command="c">Cherry</el-dropdown-item>
- <el-dropdown-item command="d">Peach</el-dropdown-item>
- <el-dropdown-item command="e">Pear</el-dropdown-item>
- </el-dropdown-menu>
- </template>
- </el-dropdown>
- `,
- () => ({
- name: '',
- })
- )
- await nextTick()
- const dropdown = wrapper.vm
- const content = wrapper.findComponent(ElTooltip).vm as InstanceType<
- typeof ElTooltip
- >
- expect(content.open).toBe(false)
- await dropdown.$refs.refDropdown.handleOpen()
- await rAF()
- expect(content.open).toBe(true)
- await dropdown.$refs.refDropdown.handleClose()
- await rAF()
- expect(content.open).toBe(false)
- })
- test('split button', async () => {
- const handleClick = vi.fn()
- const wrapper = _mount(
- `
- <el-dropdown @click="handleClick" split-button type="primary" ref="b" placement="right">
- dropdown
- <template #dropdown>
- <el-dropdown-menu>
- <el-dropdown-item command="a">Apple</el-dropdown-item>
- <el-dropdown-item command="b">Orange</el-dropdown-item>
- <el-dropdown-item ref="c" :command="myCommandObject">Cherry</el-dropdown-item>
- <el-dropdown-item command="d">Peach</el-dropdown-item>
- <el-dropdown-item command="e">Pear</el-dropdown-item>
- </el-dropdown-menu>
- </template>
- </el-dropdown>
- `,
- () => ({
- myCommandObject: { name: 'CommandC' },
- name: '',
- }),
- {
- methods: {
- handleClick,
- },
- }
- )
- await nextTick()
- const content = wrapper.findComponent(ElTooltip).vm as InstanceType<
- typeof ElTooltip
- >
- const triggerElm = wrapper.find('.el-dropdown__caret-button')
- const button = wrapper.find('.el-button')
- expect(content.open).toBe(false)
- await button.trigger('click')
- expect(handleClick).toHaveBeenCalled()
- vi.useFakeTimers()
- await triggerElm.trigger(MOUSE_ENTER_EVENT)
- vi.runAllTimers()
- vi.useRealTimers()
- expect(content.open).toBe(true)
- })
- test('hide on click', async () => {
- const wrapper = _mount(
- `
- <el-dropdown ref="b" placement="right" :hide-on-click="false">
- <span class="el-dropdown-link" ref="a">
- dropdown<i class="el-icon-arrow-down el-icon--right"></i>
- </span>
- <template #dropdown>
- <el-dropdown-menu>
- <el-dropdown-item>Apple</el-dropdown-item>
- <el-dropdown-item>Orange</el-dropdown-item>
- <el-dropdown-item ref="c">Cherry</el-dropdown-item>
- <el-dropdown-item disabled>Peach</el-dropdown-item>
- <el-dropdown-item divided>Pear</el-dropdown-item>
- </el-dropdown-menu>
- </template>
- </el-dropdown>
- `,
- () => ({})
- )
- await nextTick()
- const content = wrapper.findComponent(ElTooltip).vm as InstanceType<
- typeof ElTooltip
- >
- expect(content.open).toBe(false)
- const triggerElm = wrapper.find('.el-tooltip__trigger')
- vi.useFakeTimers()
- await triggerElm.trigger(MOUSE_ENTER_EVENT)
- vi.runAllTimers()
- expect(content.open).toBe(true)
- await wrapper
- .findComponent({ ref: 'c' })
- .findComponent({
- name: 'DropdownItemImpl',
- })
- .trigger('click')
- vi.runAllTimers()
- expect(content.open).toBe(true)
- vi.useRealTimers()
- })
- test('triggerElm keydown', async () => {
- const wrapper = _mount(
- `
- <el-dropdown ref="b" placement="right" :hide-on-click="false">
- <span class="el-dropdown-link" ref="a">
- dropdown<i class="el-icon-arrow-down el-icon--right"></i>
- </span>
- <template #dropdown>
- <el-dropdown-menu>
- <el-dropdown-item>Apple</el-dropdown-item>
- <el-dropdown-item>Orange</el-dropdown-item>
- <el-dropdown-item ref="c">Cherry</el-dropdown-item>
- <el-dropdown-item disabled>Peach</el-dropdown-item>
- <el-dropdown-item divided>Pear</el-dropdown-item>
- </el-dropdown-menu>
- </template>
- </el-dropdown>
- `,
- () => ({})
- )
- await nextTick()
- const content = wrapper.findComponent(ElTooltip).vm as InstanceType<
- typeof ElTooltip
- >
- const triggerElm = wrapper.find('.el-tooltip__trigger')
- vi.useFakeTimers()
- await triggerElm.trigger(MOUSE_ENTER_EVENT)
- vi.runAllTimers()
- await triggerElm.trigger('keydown', {
- code: EVENT_CODE.enter,
- })
- vi.runAllTimers()
- expect(content.open).toBe(false)
- await triggerElm.trigger(MOUSE_ENTER_EVENT)
- vi.runAllTimers()
- await triggerElm.trigger('keydown', {
- code: EVENT_CODE.tab,
- })
- vi.runAllTimers()
- expect(content.open).toBe(true)
- vi.useRealTimers()
- })
- test('dropdown menu keydown', async () => {
- const wrapper = _mount(
- `
- <el-dropdown ref="b" placement="right" :hide-on-click="false">
- <span class="el-dropdown-link" ref="a">
- dropdown<i class="el-icon-arrow-down el-icon--right"></i>
- </span>
- <template #dropdown>
- <el-dropdown-menu ref="dropdown-menu">
- <el-dropdown-item ref="d">Apple</el-dropdown-item>
- <el-dropdown-item>Orange</el-dropdown-item>
- <el-dropdown-item ref="c">Cherry</el-dropdown-item>
- <el-dropdown-item disabled>Peach</el-dropdown-item>
- <el-dropdown-item divided>Pear</el-dropdown-item>
- </el-dropdown-menu>
- </template>
- </el-dropdown>
- `,
- () => ({})
- )
- await nextTick()
- const content = wrapper.findComponent({ ref: 'dropdown-menu' })
- const triggerElm = wrapper.find('.el-tooltip__trigger')
- await triggerElm.trigger(MOUSE_ENTER_EVENT)
- await rAF()
- await content.trigger('keydown', {
- code: EVENT_CODE.down,
- })
- await rAF()
- expect(
- wrapper
- .findComponent({ ref: 'd' })
- .findComponent({
- name: 'DropdownItemImpl',
- })
- .find('.el-dropdown-menu__item')
- .element.getAttribute('tabindex')
- ).toBe('0')
- })
- test('max height', async () => {
- const wrapper = _mount(
- `
- <el-dropdown ref="b" max-height="60px">
- <span class="el-dropdown-link" ref="a">
- dropdown<i class="el-icon-arrow-down el-icon--right"></i>
- </span>
- <template #dropdown>
- <el-dropdown-menu>
- <el-dropdown-item>Apple</el-dropdown-item>
- <el-dropdown-item>Orange</el-dropdown-item>
- <el-dropdown-item>Cherry</el-dropdown-item>
- <el-dropdown-item disabled>Peach</el-dropdown-item>
- <el-dropdown-item divided>Pear</el-dropdown-item>
- </el-dropdown-menu>
- </template>
- </el-dropdown>
- `,
- () => ({})
- )
- await nextTick()
- const scrollbar = wrapper
- .findComponent({
- ref: 'b',
- })
- .findComponent({ ref: 'scrollbar' })
- expect(scrollbar.find('.el-scrollbar__wrap').attributes('style')).toContain(
- 'max-height: 60px;'
- )
- })
- test('tooltip debounce', async () => {
- const wrapper = _mount(
- `
- <el-dropdown ref="b">
- <span class="el-dropdown-link">
- dropdown<i class="el-icon-arrow-down el-icon--right"></i>
- </span>
- <template #dropdown>
- <el-dropdown-menu>
- <el-dropdown-item>Apple</el-dropdown-item>
- <el-dropdown-item>Orange</el-dropdown-item>
- <el-dropdown-item>Cherry</el-dropdown-item>
- <el-dropdown-item>Peach</el-dropdown-item>
- <el-dropdown-item>Pear</el-dropdown-item>
- </el-dropdown-menu>
- </template>
- </el-dropdown>
- `,
- () => ({})
- )
- const content = wrapper.findComponent(ElTooltip).vm as InstanceType<
- typeof ElTooltip
- >
- const triggerElm = wrapper.find('.el-tooltip__trigger')
- expect(content.open).toBe(false)
- vi.useFakeTimers()
- await triggerElm.trigger(MOUSE_ENTER_EVENT)
- await triggerElm.trigger(MOUSE_LEAVE_EVENT)
- await triggerElm.trigger(MOUSE_ENTER_EVENT)
- vi.runAllTimers()
- vi.useRealTimers()
- expect(content.open).toBe(true)
- })
- test('popperClass', async () => {
- const wrapper = await _mount(
- `
- <el-dropdown ref="b" max-height="60px" popper-class="custom-popper-class">
- <span class="el-dropdown-link" ref="a">
- dropdown<i class="el-icon-arrow-down el-icon--right"></i>
- </span>
- <template #dropdown>
- <el-dropdown-menu>
- <el-dropdown-item>Apple</el-dropdown-item>
- <el-dropdown-item>Orange</el-dropdown-item>
- <el-dropdown-item>Cherry</el-dropdown-item>
- <el-dropdown-item disabled>Peach</el-dropdown-item>
- <el-dropdown-item divided>Pear</el-dropdown-item>
- </el-dropdown-menu>
- </template>
- </el-dropdown>
- `,
- () => ({})
- )
- const popperElement = wrapper.findComponent({
- name: 'ElPopperContent',
- }).element
- expect(popperElement.classList.contains('custom-popper-class')).toBe(true)
- })
- test('custom attributes for dropdown items', async () => {
- const wrapper = _mount(
- `
- <el-dropdown>
- <span class="el-dropdown-link">
- Custom Attributes
- </span>
- <template #dropdown>
- <el-dropdown-menu>
- <el-dropdown-item data-custom-attribute="hello">Item</el-dropdown-item>
- </el-dropdown-menu>
- </template>
- </el-dropdown>
- `,
- () => ({})
- )
- await nextTick()
- expect(
- wrapper
- .findComponent({
- name: 'DropdownItemImpl',
- })
- .find('.el-dropdown-menu__item').element.dataset.customAttribute
- ).toBe('hello')
- })
- test('disable normal dropdown', async () => {
- const wrapper = _mount(
- `
- <el-dropdown disabled>
- <span class="el-dropdown-link">
- Dropdown List
- </span>
- <template #dropdown>
- <el-dropdown-menu>
- <el-dropdown-item data-custom-attribute="hello">Item</el-dropdown-item>
- </el-dropdown-menu>
- </template>
- </el-dropdown>
- `,
- () => ({})
- )
- await nextTick()
- expect(
- wrapper
- .findComponent({
- name: 'ElDropdown',
- })
- .classes()
- ).toContain('is-disabled')
- })
- test('disable dropdown with split button', async () => {
- const wrapper = _mount(
- `
- <el-dropdown disabled split-button>
- <span class="el-dropdown-link">
- Dropdown List
- </span>
- <template #dropdown>
- <el-dropdown-menu>
- <el-dropdown-item data-custom-attribute="hello">Item</el-dropdown-item>
- </el-dropdown-menu>
- </template>
- </el-dropdown>
- `,
- () => ({})
- )
- await nextTick()
- expect(
- wrapper
- .findAllComponents({
- name: 'ElButton',
- })[0]
- .classes()
- ).toContain('is-disabled')
- expect(
- wrapper
- .findAllComponents({
- name: 'ElButton',
- })[1]
- .classes()
- ).toContain('is-disabled')
- })
- test('set show-timeout/hide-timeout when trigger is hover', async () => {
- const wrapper = _mount(
- `
- <el-dropdown trigger="hover" :show-timeout="200" :hide-timeout="300">
- <span class="el-dropdown-link">
- Dropdown List
- </span>
- <template #dropdown>
- <el-dropdown-menu>
- <el-dropdown-item>Item</el-dropdown-item>
- </el-dropdown-menu>
- </template>
- </el-dropdown>
- `,
- () => ({})
- )
- const tooltipElement = wrapper.getComponent({
- name: 'ElTooltip',
- })
- expect(tooltipElement.vm.showAfter).toBe(200)
- expect(tooltipElement.vm.hideAfter).toBe(300)
- })
- test('ignore show-timeout/hide-timeout when trigger is not hover', async () => {
- const wrapper = _mount(
- `
- <el-dropdown trigger="click" :show-timeout="200" :hide-timeout="300">
- <span class="el-dropdown-link">
- Dropdown List
- </span>
- <template #dropdown>
- <el-dropdown-menu>
- <el-dropdown-item>Item</el-dropdown-item>
- </el-dropdown-menu>
- </template>
- </el-dropdown>
- `,
- () => ({})
- )
- const tooltipElement = wrapper.getComponent({
- name: 'ElTooltip',
- })
- expect(tooltipElement.vm.showAfter).toBe(0)
- expect(tooltipElement.vm.hideAfter).toBe(0)
- })
- describe('accessibility', () => {
- test('Custom span trigger has proper attributes', async () => {
- const wrapper = _mount(
- `
- <el-dropdown>
- <span class="el-dropdown-link" data-test-ref="trigger">
- Dropdown List
- </span>
- <template #dropdown>
- <el-dropdown-menu ref="menu">
- <el-dropdown-item>Item</el-dropdown-item>
- </el-dropdown-menu>
- </template>
- </el-dropdown>
- `,
- () => ({})
- )
- await nextTick()
- const trigger = wrapper.find('[data-test-ref="trigger"]')
- const menu = wrapper.findComponent({ ref: 'menu' })
- expect(trigger.attributes()['role']).toBe('button')
- expect(trigger.attributes()['tabindex']).toBe('0')
- expect(trigger.attributes()['aria-haspopup']).toBe('menu')
- expect(trigger.attributes()['id']).toBe(
- menu.attributes()['aria-labelledby']
- )
- expect(trigger.attributes()['aria-controls']).toBe(
- menu.attributes()['id']
- )
- })
- test('ElButton trigger has proper attributes', async () => {
- const wrapper = _mount(
- `
- <el-dropdown>
- <el-button ref="trigger">
- Dropdown List
- </el-button>
- <template #dropdown>
- <el-dropdown-menu ref="menu">
- <el-dropdown-item>Item</el-dropdown-item>
- </el-dropdown-menu>
- </template>
- </el-dropdown>
- `,
- () => ({})
- )
- await nextTick()
- const trigger = wrapper.findComponent({ ref: 'trigger' })
- const menu = wrapper.findComponent({ ref: 'menu' })
- expect(trigger.attributes()['role']).toBe('button')
- expect(trigger.attributes()['tabindex']).toBe('0')
- expect(trigger.attributes()['aria-haspopup']).toBe('menu')
- expect(trigger.attributes()['id']).toBe(
- menu.attributes()['aria-labelledby']
- )
- expect(trigger.attributes()['aria-controls']).toBe(
- menu.attributes()['id']
- )
- })
- test('Split button trigger has proper attributes', async () => {
- const wrapper = _mount(
- `
- <el-dropdown split-button>
- <template #dropdown>
- <el-dropdown-menu ref="menu">
- <el-dropdown-item>Item</el-dropdown-item>
- </el-dropdown-menu>
- </template>
- </el-dropdown>
- `,
- () => ({})
- )
- await nextTick()
- const trigger = wrapper.find('.el-dropdown__caret-button')
- const menu = wrapper.findComponent({ ref: 'menu' })
- expect(trigger.attributes()['role']).toBe('button')
- expect(trigger.attributes()['tabindex']).toBe('0')
- expect(trigger.attributes()['aria-haspopup']).toBe('menu')
- expect(trigger.attributes()['id']).toBe(
- menu.attributes()['aria-labelledby']
- )
- expect(trigger.attributes()['aria-controls']).toBe(
- menu.attributes()['id']
- )
- })
- test('Menu items with "menu" role', async () => {
- const wrapper = _mount(
- `
- <el-dropdown split-button>
- <template #dropdown>
- <el-dropdown-menu ref="menu">
- <el-dropdown-item ref="menu-item">Item</el-dropdown-item>
- </el-dropdown-menu>
- </template>
- </el-dropdown>
- `,
- () => ({})
- )
- const menu = wrapper.findComponent({ ref: 'menu' })
- const menuItem = menu.find('.el-dropdown-menu__item')
- expect(menu.attributes()['role']).toBe('menu')
- expect(menuItem.attributes()['role']).toBe('menuitem')
- })
- test('Menu items with "navigation" role', async () => {
- const wrapper = _mount(
- `
- <el-dropdown split-button role="navigation">
- <template #dropdown>
- <el-dropdown-menu ref="menu">
- <el-dropdown-item ref="menu-item">Item</el-dropdown-item>
- </el-dropdown-menu>
- </template>
- </el-dropdown>
- `,
- () => ({})
- )
- const menu = wrapper.findComponent({ ref: 'menu' })
- const menuItem = menu.find('.el-dropdown-menu__item')
- expect(menu.attributes()['role']).toBe('navigation')
- expect(menuItem.attributes()['role']).toBe('link')
- })
- test('Menu items with "group" role', async () => {
- const wrapper = _mount(
- `
- <el-dropdown split-button role="group">
- <template #dropdown>
- <el-dropdown-menu ref="menu">
- <el-dropdown-item ref="menu-item">Item</el-dropdown-item>
- </el-dropdown-menu>
- </template>
- </el-dropdown>
- `,
- () => ({})
- )
- const menu = wrapper.findComponent({ ref: 'menu' })
- const menuItem = menu.find('.el-dropdown-menu__item')
- expect(menu.attributes()['role']).toBe('group')
- expect(menuItem.attributes()['role']).toBe('button')
- })
- })
- describe('teleported API', () => {
- test('should mount on popper container', async () => {
- expect(document.body.innerHTML).toBe('')
- _mount(
- `
- <el-dropdown ref="b" placement="right">
- <span class="el-dropdown-link" ref="a">
- dropdown<i class="el-icon-arrow-down el-icon--right"></i>
- </span>
- <template #dropdown>
- <el-dropdown-menu>
- <el-dropdown-item>Apple</el-dropdown-item>
- <el-dropdown-item>Orange</el-dropdown-item>
- <el-dropdown-item>Cherry</el-dropdown-item>
- <el-dropdown-item disabled>Peach</el-dropdown-item>
- <el-dropdown-item divided>Pear</el-dropdown-item>
- </el-dropdown-menu>
- </template>
- </el-dropdown>`,
- () => ({})
- )
- await nextTick()
- const { selector } = usePopperContainerId()
- expect(document.body.querySelector(selector.value).innerHTML).not.toBe('')
- })
- test('should not mount on the popper container', async () => {
- expect(document.body.innerHTML).toBe('')
- _mount(
- `
- <el-dropdown ref="b" placement="right" :teleported="false">
- <span class="el-dropdown-link" ref="a">
- dropdown<i class="el-icon-arrow-down el-icon--right"></i>
- </span>
- <template #dropdown>
- <el-dropdown-menu>
- <el-dropdown-item>Apple</el-dropdown-item>
- <el-dropdown-item>Orange</el-dropdown-item>
- <el-dropdown-item>Cherry</el-dropdown-item>
- <el-dropdown-item disabled>Peach</el-dropdown-item>
- <el-dropdown-item divided>Pear</el-dropdown-item>
- </el-dropdown-menu>
- </template>
- </el-dropdown>`,
- () => ({})
- )
- await nextTick()
- const { selector } = usePopperContainerId()
- expect(document.body.querySelector(selector.value).innerHTML).toBe('')
- })
- })
- })
|