mirror of
https://gitee.com/wot-design-uni/wot-design-uni.git
synced 2025-12-07 01:28:30 +08:00
* chore: 🚀 引入vitest做组件测试 * chore: 🚀 引入vitest做组件测试 * chore: 🚀 update workflow * chore: 🚀 update workflow * chore: 🚀 update workflow * chore: 🚀 update workflow * chore: 🚀 update nodejs version * chore: 🚀 update nodejs version
48 lines
1.2 KiB
TypeScript
48 lines
1.2 KiB
TypeScript
import { useTouch } from '@/uni_modules/wot-design-uni/components/composables/useTouch'
|
|
import { describe, expect, it } from 'vitest'
|
|
|
|
describe('useTouch', () => {
|
|
const touch = useTouch()
|
|
|
|
it('should initialize with default values', () => {
|
|
expect(touch.direction.value).toBe('')
|
|
expect(touch.deltaX.value).toBe(0)
|
|
expect(touch.deltaY.value).toBe(0)
|
|
})
|
|
|
|
it('should handle touch start', () => {
|
|
touch.touchStart({
|
|
touches: [{ clientX: 100, clientY: 100 }]
|
|
})
|
|
|
|
expect(touch.startX.value).toBe(100)
|
|
expect(touch.startY.value).toBe(100)
|
|
})
|
|
|
|
it('should handle touch move horizontal', () => {
|
|
touch.touchStart({
|
|
touches: [{ clientX: 100, clientY: 100 }]
|
|
})
|
|
|
|
touch.touchMove({
|
|
touches: [{ clientX: 200, clientY: 120 }]
|
|
})
|
|
|
|
expect(touch.direction.value).toBe('horizontal')
|
|
expect(touch.deltaX.value).toBe(100)
|
|
})
|
|
|
|
it('should handle touch move vertical', () => {
|
|
touch.touchStart({
|
|
touches: [{ clientX: 100, clientY: 100 }]
|
|
})
|
|
|
|
touch.touchMove({
|
|
touches: [{ clientX: 120, clientY: 200 }]
|
|
})
|
|
|
|
expect(touch.direction.value).toBe('vertical')
|
|
expect(touch.deltaY.value).toBe(100)
|
|
})
|
|
})
|