From a5492d131c26ec6d1418f70eed2a478cfd1de94c Mon Sep 17 00:00:00 2001 From: taohebin Date: Sat, 9 Nov 2024 17:11:17 +0800 Subject: [PATCH] update: dialog-page.uvue --- pages/API/dialog-page/dialog-1.uvue | 1 + pages/API/dialog-page/dialog-page.test.js | 35 ++++++++++++++++++++--- pages/API/dialog-page/dialog-page.uvue | 25 +++++++++++++++- 3 files changed, 56 insertions(+), 5 deletions(-) diff --git a/pages/API/dialog-page/dialog-1.uvue b/pages/API/dialog-page/dialog-1.uvue index 8f7dccee..a75bb228 100644 --- a/pages/API/dialog-page/dialog-1.uvue +++ b/pages/API/dialog-page/dialog-1.uvue @@ -8,6 +8,7 @@ + diff --git a/pages/API/dialog-page/dialog-page.test.js b/pages/API/dialog-page/dialog-page.test.js index 7f8935d6..a04a9541 100644 --- a/pages/API/dialog-page/dialog-page.test.js +++ b/pages/API/dialog-page/dialog-page.test.js @@ -1,7 +1,8 @@ jest.setTimeout(20000) const platformInfo = process.env.uniTestPlatformInfo.toLocaleLowerCase() -const isWeb = platformInfo.startsWith('web') +const isWeb = platformInfo.startsWith('web') +const isAndroid = platformInfo.startsWith('android') const FIRST_PAGE_PATH = '/pages/API/dialog-page/dialog-page' const NEXT_PAGE_PATH = '/pages/API/dialog-page/next-page' @@ -23,8 +24,8 @@ describe('dialog page', () => { await page.callMethod('setLifeCycleNum', 0) lifecycleNum = await page.callMethod('getLifeCycleNum') expect(lifecycleNum).toBe(0) - }); - + }); + it('open dialog1', async () => { await page.callMethod('openDialog1'); // 无法通过获取 dom 元素来判断是否打开了 dialogPage @@ -280,7 +281,33 @@ describe('dialog page', () => { lifecycleNum = await page.callMethod('getLifeCycleNum') expect(lifecycleNum).toBe(2) }) - + + + it('input-hold-keyboard in dialog', async () => { + await page.callMethod('jest_OpenDialog1') + await page.waitFor(2000); + await page.callMethod('jest_getTapPoint') + const point_x = await page.data('jest_click_x'); + const point_y = await page.data('jest_click_y'); + if (isAndroid){ + await program.adbCommand("input tap" + " " + point_x + " " + point_y) + console.log("input tap" + " " + point_x + " " + point_y); + } else { + await program.tap({x: point_x, y: point_y}) + } + + await page.waitFor(1000); + const image = await program.screenshot({ + deviceShot: true, + area: { + x: 0, + y: 200, + } + }) + expect(image).toSaveImageSnapshot() + await page.waitFor(2000); + await page.callMethod('jest_CloseDialog1') + }) afterAll(async () => { await page.callMethod('setLifeCycleNum', initLifeCycleNum) diff --git a/pages/API/dialog-page/dialog-page.uvue b/pages/API/dialog-page/dialog-page.uvue index cd9768b7..28573013 100644 --- a/pages/API/dialog-page/dialog-page.uvue +++ b/pages/API/dialog-page/dialog-page.uvue @@ -15,7 +15,13 @@ setLifeCycleNum } from '@/store/index.uts' - export default { + export default { + data() { + return { + jest_click_x: -1, + jest_click_y: -1 + } + }, onLoad() { console.log('dialogPage parent onLoad') }, @@ -170,6 +176,23 @@ }, getLifeCycleNum(): number { return state.lifeCycleNum + }, + jest_OpenDialog1(){ + uni.openDialogPage({ + url: '/pages/API/dialog-page/dialog-1?name=dialog1' + }) + }, + jest_CloseDialog1(){ + uni.closeDialogPage({}) + }, + jest_getTapPoint(){ + const systemInfo = uni.getSystemInfoSync() + let ratio = 1 + if (systemInfo.platform == 'android'){ + ratio = systemInfo.devicePixelRatio + } + this.jest_click_x = systemInfo.screenWidth / 2 * ratio + this.jest_click_y = systemInfo.statusBarHeight * ratio + 10 } } } -- GitLab