From 0e86ca62ee97e4f1c229d383eb41e860fc129fcc Mon Sep 17 00:00:00 2001 From: XHY Date: Mon, 2 Sep 2024 17:49:51 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=20touch-events.test.js=20?= =?UTF-8?q?=E6=B5=8B=E8=AF=95=E4=BE=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../global-events/touch-events.test.js | 44 +++++++++++++++++++ .../component/global-events/touch-events.uvue | 24 +++++++--- 2 files changed, 63 insertions(+), 5 deletions(-) create mode 100644 pages/component/global-events/touch-events.test.js diff --git a/pages/component/global-events/touch-events.test.js b/pages/component/global-events/touch-events.test.js new file mode 100644 index 00000000..b17d2b1f --- /dev/null +++ b/pages/component/global-events/touch-events.test.js @@ -0,0 +1,44 @@ +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) + }) + +}) diff --git a/pages/component/global-events/touch-events.uvue b/pages/component/global-events/touch-events.uvue index a29db6f8..7987d0ce 100644 --- a/pages/component/global-events/touch-events.uvue +++ b/pages/component/global-events/touch-events.uvue @@ -2,7 +2,7 @@ - + @@ -31,14 +31,28 @@ lastX: 0, lastY: 0, touchEvent: null as TouchEvent | null, - icon: null as UniElement | null + icon: null as UniElement | null, + touchTargets: "", + touchTargetsCount: 0, + iconRect : null as domRect | null } }, 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: { - onTouchStart(e : TouchEvent) { + methods: { + 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 if (!this.move) { this.move = true -- GitLab