39 lines
1.4 KiB
TypeScript
39 lines
1.4 KiB
TypeScript
/**
|
|
* 03-menus: UI 组件——菜单、对话框
|
|
*/
|
|
import { describe, it, expect } from 'vitest'
|
|
import { ui } from '../../src/composables/useUI'
|
|
|
|
describe('03-menus — UI 组件', () => {
|
|
it('menu 创建弹出菜单', () => {
|
|
const pop = ui.menu([{ label: 'A', action() {} }, { sep: true }, { label: 'B', disabled: true }], 0, 0)
|
|
expect(pop.querySelectorAll('.menu-item').length).toBe(2)
|
|
ui.closeAllMenus()
|
|
})
|
|
|
|
it('dialog 返回 Promise', async () => {
|
|
const p = ui.dialog({ title: 'T', msg: 'M', buttons: ['OK'] })
|
|
setTimeout(() => { const b = document.querySelector('.dialog .btn') as HTMLElement; b?.click() }, 10)
|
|
const r = await p
|
|
expect(r.index).toBe(0)
|
|
})
|
|
|
|
it('alert 快捷方法', async () => {
|
|
const p = ui.alert('T', 'M')
|
|
setTimeout(() => { const b = document.querySelector('.dialog .btn') as HTMLElement; b?.click() }, 10)
|
|
expect((await p).index).toBe(0)
|
|
})
|
|
|
|
it('confirm 取消返回 false', async () => {
|
|
const p = ui.confirm('T', 'M')
|
|
setTimeout(() => { const b = document.querySelectorAll('.dialog .btn')[0] as HTMLElement; b?.click() }, 10)
|
|
expect(await p).toBe(false)
|
|
})
|
|
|
|
it('confirm 确定返回 true', async () => {
|
|
const p = ui.confirm('T', 'M')
|
|
setTimeout(() => { const b = document.querySelectorAll('.dialog .btn')[1] as HTMLElement; b?.click() }, 10)
|
|
expect(await p).toBe(true)
|
|
})
|
|
})
|