From 62c13a62d5f07c8b2bdb02486e5ed2e5b2cd8676 Mon Sep 17 00:00:00 2001 From: zhenyuWang <13641039885@163.com> Date: Mon, 3 Jun 2024 16:13:14 +0800 Subject: [PATCH] =?UTF-8?q?test(general=20event):=20=E4=BC=98=E5=8C=96?= =?UTF-8?q?=E7=A4=BA=E4=BE=8B=E5=8F=8A=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../general-event/general-event.test.js | 204 +++++- .../general-event/general-event.uvue | 649 ++++++++++++------ 2 files changed, 627 insertions(+), 226 deletions(-) diff --git a/pages/component/general-event/general-event.test.js b/pages/component/general-event/general-event.test.js index 46939cc7..ba6340f2 100644 --- a/pages/component/general-event/general-event.test.js +++ b/pages/component/general-event/general-event.test.js @@ -1,65 +1,223 @@ const PAGE_PATH = '/pages/component/general-event/general-event' describe('event trigger sequence', () => { + const platformInfo = process.env.uniTestPlatformInfo.toLocaleLowerCase() + const isAndroid = platformInfo.startsWith('android') let page - let el beforeAll(async () => { page = await program.navigateTo(PAGE_PATH) await page.waitFor('view') - el = await page.$('.target') }) it('touch', async () => { - if (process.env.uniTestPlatformInfo.startsWith('android') && !process.env.UNI_AUTOMATOR_APP_WEBVIEW) { + if (!process.env.UNI_AUTOMATOR_APP_WEBVIEW) { + const el = await page.$('#touch-target') await el.touchstart({ touches: [{ identifier: 1, - pageX: 100, - pageY: 100, + pageX: 101, + pageY: 101, + clientX: 101, + clientY: 101, + screenX: 101, + screenY: 101 }, ], changedTouches: [{ identifier: 1, - pageX: 100, - pageY: 100, + pageX: 101, + pageY: 101, + clientX: 101, + clientY: 101, + screenX: 101, + screenY: 101 }, ], }) + const touchStartTouchTargetIdentifier = isAndroid ? '1.0' : '1' + const touchStartTouchTargetValue = isAndroid ? '101.0' : '101' + const touchStartTouchIdentifier = await page.$('#touch-start-touch-identifier') + expect(await touchStartTouchIdentifier.text()).toBe(touchStartTouchTargetIdentifier) + const touchStartTouchPageX = await page.$('#touch-start-touch-page-x') + expect(await touchStartTouchPageX.text()).toBe(touchStartTouchTargetValue) + const touchStartTouchPageY = await page.$('#touch-start-touch-page-y') + expect(await touchStartTouchPageY.text()).toBe(touchStartTouchTargetValue) + const touchStartTouchClientX = await page.$('#touch-start-touch-client-x') + expect(await touchStartTouchClientX.text()).toBe(touchStartTouchTargetValue) + const touchStartTouchClientY = await page.$('#touch-start-touch-client-y') + expect(await touchStartTouchClientY.text()).toBe(touchStartTouchTargetValue) + const touchStartTouchScreenX = await page.$('#touch-start-touch-screen-x') + expect(await touchStartTouchScreenX.text()).toBe(touchStartTouchTargetValue) + const touchStartTouchScreenY = await page.$('#touch-start-touch-screen-y') + expect(await touchStartTouchScreenY.text()).toBe(touchStartTouchTargetValue) + + const touchStartChangedTouchIdentifier = await page.$('#touch-start-changed-touch-identifier') + expect(await touchStartChangedTouchIdentifier.text()).toBe(touchStartTouchTargetIdentifier) + const touchStartChangedTouchPageX = await page.$('#touch-start-changed-touch-page-x') + expect(await touchStartChangedTouchPageX.text()).toBe(touchStartTouchTargetValue) + const touchStartChangedTouchPageY = await page.$('#touch-start-changed-touch-page-y') + expect(await touchStartChangedTouchPageY.text()).toBe(touchStartTouchTargetValue) + const touchStartChangedTouchClientX = await page.$('#touch-start-changed-touch-client-x') + expect(await touchStartChangedTouchClientX.text()).toBe(touchStartTouchTargetValue) + const touchStartChangedTouchClientY = await page.$('#touch-start-changed-touch-client-y') + expect(await touchStartChangedTouchClientY.text()).toBe(touchStartTouchTargetValue) + const touchStartChangedTouchScreenX = await page.$('#touch-start-changed-touch-screen-x') + expect(await touchStartChangedTouchScreenX.text()).toBe(touchStartTouchTargetValue) + const touchStartChangedTouchScreenY = await page.$('#touch-start-changed-touch-screen-y') + expect(await touchStartChangedTouchScreenY.text()).toBe(touchStartTouchTargetValue) + await el.touchmove({ touches: [{ identifier: 1, - pageX: 100, - pageY: 100, - }, ], + pageX: 102, + pageY: 102, + clientX: 102, + clientY: 102, + screenX: 102, + screenY: 102 + }], changedTouches: [{ identifier: 1, - pageX: 101, - pageY: 101, + pageX: 102, + pageY: 102, + clientX: 102, + clientY: 102, + screenX: 102, + screenY: 102 }, ], }) + + const touchMoveTouchTargetIdentifier = isAndroid ? '1.0' : '1' + const touchMoveTouchTargetValue = isAndroid ? '102.0' : '102' + const touchMoveTouchIdentifier = await page.$('#touch-move-touch-identifier') + expect(await touchMoveTouchIdentifier.text()).toBe(touchMoveTouchTargetIdentifier) + const touchMoveTouchPageX = await page.$('#touch-move-touch-page-x') + expect(await touchMoveTouchPageX.text()).toBe(touchMoveTouchTargetValue) + const touchMoveTouchPageY = await page.$('#touch-move-touch-page-y') + expect(await touchMoveTouchPageY.text()).toBe(touchMoveTouchTargetValue) + const touchMoveTouchClientX = await page.$('#touch-move-touch-client-x') + expect(await touchMoveTouchClientX.text()).toBe(touchMoveTouchTargetValue) + const touchMoveTouchClientY = await page.$('#touch-move-touch-client-y') + expect(await touchMoveTouchClientY.text()).toBe(touchMoveTouchTargetValue) + const touchMoveTouchScreenX = await page.$('#touch-move-touch-screen-x') + expect(await touchMoveTouchScreenX.text()).toBe(touchMoveTouchTargetValue) + const touchMoveTouchScreenY = await page.$('#touch-move-touch-screen-y') + expect(await touchMoveTouchScreenY.text()).toBe(touchMoveTouchTargetValue) + const touchMoveChangedTouchIdentifier = await page.$('#touch-move-changed-touch-identifier') + expect(await touchMoveChangedTouchIdentifier.text()).toBe(touchMoveTouchTargetIdentifier) + const touchMoveChangedTouchPageX = await page.$('#touch-move-changed-touch-page-x') + expect(await touchMoveChangedTouchPageX.text()).toBe(touchMoveTouchTargetValue) + const touchMoveChangedTouchPageY = await page.$('#touch-move-changed-touch-page-y') + expect(await touchMoveChangedTouchPageY.text()).toBe(touchMoveTouchTargetValue) + const touchMoveChangedTouchClientX = await page.$('#touch-move-changed-touch-client-x') + expect(await touchMoveChangedTouchClientX.text()).toBe(touchMoveTouchTargetValue) + const touchMoveChangedTouchClientY = await page.$('#touch-move-changed-touch-client-y') + expect(await touchMoveChangedTouchClientY.text()).toBe(touchMoveTouchTargetValue) + const touchMoveChangedTouchScreenX = await page.$('#touch-move-changed-touch-screen-x') + expect(await touchMoveChangedTouchScreenX.text()).toBe(touchMoveTouchTargetValue) + const touchMoveChangedTouchScreenY = await page.$('#touch-move-changed-touch-screen-y') + expect(await touchMoveChangedTouchScreenY.text()).toBe(touchMoveTouchTargetValue) + await el.touchend({ - touches: [], + touches: [{ + identifier: 1, + pageX: 103, + pageY: 103, + clientX: 103, + clientY: 103, + screenX: 103, + screenY: 103 + }], changedTouches: [{ identifier: 1, - pageX: 101, - pageY: 101, + pageX: 103, + pageY: 103, + clientX: 103, + clientY: 103, + screenX: 103, + screenY: 103 }, ], }) - const data = await page.data() - expect(data.onTouchStartTime).toBeLessThanOrEqual(data.onTouchMoveTime); - expect(data.onTouchMoveTime).toBeLessThanOrEqual(data.onTouchEndTime); + const touchEndTouchTargetIdentifier = isAndroid ? '1.0' : '1' + const touchEndTouchTargetValue = isAndroid ? '103.0' : '103' + const touchEndTouchIdentifier = await page.$('#touch-end-touch-identifier') + expect(await touchEndTouchIdentifier.text()).toBe(touchEndTouchTargetIdentifier) + const touchEndTouchPageX = await page.$('#touch-end-touch-page-x') + expect(await touchEndTouchPageX.text()).toBe(touchEndTouchTargetValue) + const touchEndTouchPageY = await page.$('#touch-end-touch-page-y') + expect(await touchEndTouchPageY.text()).toBe(touchEndTouchTargetValue) + const touchEndTouchClientX = await page.$('#touch-end-touch-client-x') + expect(await touchEndTouchClientX.text()).toBe(touchEndTouchTargetValue) + const touchEndTouchClientY = await page.$('#touch-end-touch-client-y') + expect(await touchEndTouchClientY.text()).toBe(touchEndTouchTargetValue) + const touchEndTouchScreenX = await page.$('#touch-end-touch-screen-x') + expect(await touchEndTouchScreenX.text()).toBe(touchEndTouchTargetValue) + const touchEndTouchScreenY = await page.$('#touch-end-touch-screen-y') + expect(await touchEndTouchScreenY.text()).toBe(touchEndTouchTargetValue) + const touchEndChangedTouchIdentifier = await page.$('#touch-end-changed-touch-identifier') + expect(await touchEndChangedTouchIdentifier.text()).toBe(touchEndTouchTargetIdentifier) + const touchEndChangedTouchPageX = await page.$('#touch-end-changed-touch-page-x') + expect(await touchEndChangedTouchPageX.text()).toBe(touchEndTouchTargetValue) + const touchEndChangedTouchPageY = await page.$('#touch-end-changed-touch-page-y') + expect(await touchEndChangedTouchPageY.text()).toBe(touchEndTouchTargetValue) + const touchEndChangedTouchClientX = await page.$('#touch-end-changed-touch-client-x') + expect(await touchEndChangedTouchClientX.text()).toBe(touchEndTouchTargetValue) + const touchEndChangedTouchClientY = await page.$('#touch-end-changed-touch-client-y') + expect(await touchEndChangedTouchClientY.text()).toBe(touchEndTouchTargetValue) + const touchEndChangedTouchScreenX = await page.$('#touch-end-changed-touch-screen-x') + expect(await touchEndChangedTouchScreenX.text()).toBe(touchEndTouchTargetValue) + const touchEndChangedTouchScreenY = await page.$('#touch-end-changed-touch-screen-y') + expect(await touchEndChangedTouchScreenY.text()).toBe(touchEndTouchTargetValue) } }) it('click', async () => { + const el = await page.$('#longpress-target') await el.tap() - const data = await page.data() - expect(data.onTapTime).toBeLessThanOrEqual(data.onClickTime) + const targetX = isAndroid ? '0.0' : '0' + const targetY = isAndroid ? '0.0' : '0' + const tapEventX = await page.$('#tap-event-x') + expect(await tapEventX.text()).toBe(targetX) + const tapEventY = await page.$('#tap-event-y') + expect(await tapEventY.text()).toBe(targetY) + const clickEventX = await page.$('#click-event-x') + expect(await clickEventX.text()).toBe(targetX) + const clickEventY = await page.$('#click-event-y') + expect(await clickEventY.text()).toBe(targetY) }) it('longPress', async () => { - if (process.env.uniTestPlatformInfo.startsWith('android') && !process.env.UNI_AUTOMATOR_APP_WEBVIEW) { + if (!process.env.UNI_AUTOMATOR_APP_WEBVIEW) { + const el = await page.$('#longpress-target') await el.longpress() - const data = await page.data() - expect(data.onLongPressTime).toBeGreaterThan(0) + const longPressTouchTargetIdentifier = isAndroid ? '1.0' : '1' + const longPressTouchTargetValue = isAndroid ? '0.0' : '0' + const longPressTouchIdentifier = await page.$('#long-press-touch-identifier') + expect(await longPressTouchIdentifier.text()).toBe(longPressTouchTargetIdentifier) + const longPressTouchPageX = await page.$('#long-press-touch-page-x') + expect(await longPressTouchPageX.text()).toBe(longPressTouchTargetValue) + const longPressTouchPageY = await page.$('#long-press-touch-page-y') + expect(await longPressTouchPageY.text()).toBe(longPressTouchTargetValue) + const longPressTouchClientX = await page.$('#long-press-touch-client-x') + expect(await longPressTouchClientX.text()).toBe(longPressTouchTargetValue) + const longPressTouchClientY = await page.$('#long-press-touch-client-y') + expect(await longPressTouchClientY.text()).toBe(longPressTouchTargetValue) + const longPressTouchScreenX = await page.$('#long-press-touch-screen-x') + expect(await longPressTouchScreenX.text()).toBe(longPressTouchTargetValue) + const longPressTouchScreenY = await page.$('#long-press-touch-screen-y') + expect(await longPressTouchScreenY.text()).toBe(longPressTouchTargetValue) + const longPressChangedTouchIdentifier = await page.$('#long-press-changed-touch-identifier') + expect(await longPressChangedTouchIdentifier.text()).toBe(longPressTouchTargetIdentifier) + const longPressChangedTouchPageX = await page.$('#long-press-changed-touch-page-x') + expect(await longPressChangedTouchPageX.text()).toBe(longPressTouchTargetValue) + const longPressChangedTouchPageY = await page.$('#long-press-changed-touch-page-y') + expect(await longPressChangedTouchPageY.text()).toBe(longPressTouchTargetValue) + const longPressChangedTouchClientX = await page.$('#long-press-changed-touch-client-x') + expect(await longPressChangedTouchClientX.text()).toBe(longPressTouchTargetValue) + const longPressChangedTouchClientY = await page.$('#long-press-changed-touch-client-y') + expect(await longPressChangedTouchClientY.text()).toBe(longPressTouchTargetValue) + const longPressChangedTouchScreenX = await page.$('#long-press-changed-touch-screen-x') + expect(await longPressChangedTouchScreenX.text()).toBe(longPressTouchTargetValue) + const longPressChangedTouchScreenY = await page.$('#long-press-changed-touch-screen-y') + expect(await longPressChangedTouchScreenY.text()).toBe(longPressTouchTargetValue) } }) }) diff --git a/pages/component/general-event/general-event.uvue b/pages/component/general-event/general-event.uvue index 7e8cefd1..6ad90de7 100644 --- a/pages/component/general-event/general-event.uvue +++ b/pages/component/general-event/general-event.uvue @@ -1,204 +1,447 @@ - - - - -- GitLab