mirror of
https://github.com/XiaoDaiGua-Ray/ray-template.git
synced 2026-12-03 02:13:38 +08:00
Add interactive hook examples, shared Pinia runtime state, and configurable layouts. Generate typed namespaced icons during development, HMR, and builds. Refine the UI and establish project comment and design conventions. Validation: typecheck, ESLint, 181 tests, and production build passed.
64 lines
1.8 KiB
TypeScript
64 lines
1.8 KiB
TypeScript
import { useContextmenuCoordinate } from '../../src/hooks/components/useContextmenuCoordinate'
|
|
import createRefElement from '../utils/createRefElement'
|
|
import renderHook from '../utils/renderHook'
|
|
|
|
describe('useContextmenuCoordinate', () => {
|
|
const wrapperRef = createRefElement()
|
|
const [result] = renderHook(() =>
|
|
useContextmenuCoordinate(wrapperRef.element),
|
|
)
|
|
|
|
it('should be defined', () => {
|
|
expect(useContextmenuCoordinate).toBeDefined()
|
|
})
|
|
|
|
it('should update show value to true when contextmenu event is triggered', async () => {
|
|
wrapperRef.element.dispatchEvent(new MouseEvent('contextmenu'))
|
|
|
|
await nextTick()
|
|
|
|
expect(result.show.value).toBe(true)
|
|
})
|
|
|
|
it('should update show value when calling updateShow method', async () => {
|
|
result.updateShow(false)
|
|
|
|
await nextTick()
|
|
|
|
expect(result.show.value).toBe(false)
|
|
|
|
result.updateShow(true)
|
|
|
|
await nextTick()
|
|
|
|
expect(result.show.value).toBe(true)
|
|
})
|
|
|
|
it('should get the clientX and clientY value when contextmenu event is triggered', async () => {
|
|
const event = new MouseEvent('contextmenu', {
|
|
clientX: 100,
|
|
clientY: 200,
|
|
})
|
|
|
|
wrapperRef.element.dispatchEvent(event)
|
|
|
|
await nextTick()
|
|
|
|
expect(result.x.value).toBe(100)
|
|
expect(result.y.value).toBe(200)
|
|
})
|
|
it('does not reopen after stop interrupts a pending context-menu event', async () => {
|
|
const target = document.createElement('div')
|
|
const [menu, app] = renderHook(() => useContextmenuCoordinate(target))
|
|
|
|
target.dispatchEvent(new MouseEvent('contextmenu'))
|
|
menu.stop()
|
|
await nextTick()
|
|
expect(menu.show.value).toBe(false)
|
|
target.dispatchEvent(new MouseEvent('contextmenu'))
|
|
await nextTick()
|
|
expect(menu.show.value).toBe(false)
|
|
app.unmount()
|
|
})
|
|
})
|