提交 0e86ca62 编写于 作者: DCloud_iOS_XHY's avatar DCloud_iOS_XHY

增加 touch-events.test.js 测试例

上级 04f01e27
const PAGE_PATH = '/pages/component/global-events/touch-events'
describe('touch-events-test', () => {
// 先屏蔽 android 及 web 平台
if (process.env.uniTestPlatformInfo.startsWith('android') || process.env.uniTestPlatformInfo.startsWith('web')) {
it('other platform', () => {
expect(1).toBe(1)
})
return
}
let page
beforeAll(async () => {
page = await program.reLaunch(PAGE_PATH)
await page.waitFor(500);
})
it('touchStart-tagName-touchCount', async () => {
let iconRect = await page.data('iconRect')
let x = iconRect.x + iconRect.width / 2.0
let y = iconRect.y + iconRect.height / 2.0
// 点击图片
await program.tap({
x: x,
y: y,
duration: 100
})
await page.waitFor(1500);
const touchTargets = await page.data('touchTargets')
const touchTargetsCount = await page.data('touchTargetsCount')
console.log('touchTargets', touchTargets)
console.log('touchTargetsCount', touchTargetsCount)
expect(touchTargets).toBe("IMAGEIMAGEIMAGEVIEW")
expect(touchTargetsCount).toBe(2)
})
})
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
<scroll-view style="flex: 1"> <scroll-view style="flex: 1">
<page-head title="拖拽图标测试相关事件"></page-head> <page-head title="拖拽图标测试相关事件"></page-head>
<view class="container"> <view class="container">
<view class="view-box"> <view class="view-box" @touchstart="onViewTouchStart">
<image class="icon" id="icon" src="../image/logo.png" @touchstart="onTouchStart" @touchcancel="onTouchCancel" <image class="icon" id="icon" src="../image/logo.png" @touchstart="onTouchStart" @touchcancel="onTouchCancel"
@touchmove="onTouchMove" @touchend="onTouchEnd"></image> @touchmove="onTouchMove" @touchend="onTouchEnd"></image>
</view> </view>
...@@ -31,14 +31,28 @@ ...@@ -31,14 +31,28 @@
lastX: 0, lastX: 0,
lastY: 0, lastY: 0,
touchEvent: null as TouchEvent | null, touchEvent: null as TouchEvent | null,
icon: null as UniElement | null icon: null as UniElement | null,
touchTargets: "",
touchTargetsCount: 0,
iconRect : null as domRect | null
} }
}, },
onReady() { onReady() {
this.icon = uni.getElementById("icon") this.icon = uni.getElementById("icon")
this.iconRect = this.icon.getBoundingClientRect()
// 加上导航栏及状态栏高度
this.iconRect.y += uni.getSystemInfoSync().safeArea.top + 44
}, },
methods: { methods: {
onTouchStart(e : TouchEvent) { onViewTouchStart(e : TouchEvent) {
this.touchTargets += e.target?.tagName + e.currentTarget?.tagName
this.touchTargetsCount++
console.log(this.touchTargets, this.touchTargetsCount)
},
onTouchStart(e : TouchEvent) {
this.touchTargetsCount++
this.touchTargets += e.target?.tagName + e.currentTarget?.tagName
this.touchEvent = e this.touchEvent = e
if (!this.move) { if (!this.move) {
this.move = true this.move = true
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册