From 753185922aa35bdb6516cf5a76ee1b225c47ae6f Mon Sep 17 00:00:00 2001 From: zhenyuWang <13641039885@163.com> Date: Sat, 21 Dec 2024 21:35:38 +0800 Subject: [PATCH] =?UTF-8?q?feat(actionSheet):=20=E8=A1=A5=E5=85=85?= =?UTF-8?q?=E8=87=AA=E5=AE=9A=E4=B9=89=20titleColor=20cancelText=20cancelC?= =?UTF-8?q?olor=20backgroundColor=20=E7=A4=BA=E4=BE=8B=E5=8F=8A=E6=B5=8B?= =?UTF-8?q?=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../show-action-sheet.test.js | 527 +++--------------- .../show-action-sheet/show-action-sheet.uvue | 153 ++--- 2 files changed, 150 insertions(+), 530 deletions(-) diff --git a/pages/API/show-action-sheet/show-action-sheet.test.js b/pages/API/show-action-sheet/show-action-sheet.test.js index 38199610..c5f64e25 100644 --- a/pages/API/show-action-sheet/show-action-sheet.test.js +++ b/pages/API/show-action-sheet/show-action-sheet.test.js @@ -1,540 +1,137 @@ -// uni-app自动化测试教程: uni-app自动化测试教程: https://uniapp.dcloud.net.cn/worktile/auto/hbuilderx-extension/ +const platformInfo = process.env.uniTestPlatformInfo.toLocaleLowerCase() +const isAndroid = platformInfo.startsWith('android') +const isIos = platformInfo.startsWith('ios') +const isApp = isAndroid || isIos +const isWeb = platformInfo.startsWith('web') -describe('API-loading', () => { +describe('API-loading', () => { let page; - const isApp = process.env.UNI_OS_NAME === "android" || process.env.UNI_OS_NAME === "ios"; + let screenShotOptions = {}; + async function showActionSheet(page) { + const btn = await page.$('#btn-action-sheet-show') + await btn.tap() + await page.waitFor(1000); + } + + async function screenshot() { + const image = await program.screenshot(screenShotOptions); + expect(image).toSaveImageSnapshot(); + } beforeAll(async () => { page = await program.reLaunch('/pages/API/show-action-sheet/show-action-sheet') - await page.waitFor(500); - }); - - - it("onload-action-sheet-test", async () => { + await page.waitFor('view'); if (isApp) { - await page.waitFor(500); const res = await page.callMethod('jest_getWindowInfo') const windowHeight = res.windowHeight * res.pixelRatio; const windowWidth = res.windowWidth * res.pixelRatio; - const image = await program.screenshot({ + screenShotOptions = { deviceShot: true, area: { x: 0, y: 200, - height: windowHeight - 100, - width:windowWidth + height: windowHeight + (isAndroid ? 30 : 70), + width: windowWidth }, - }); - - expect(image).toSaveImageSnapshot(); - }else{ - const image = await program.screenshot({ - deviceShot: true, + } + } else if (isWeb){ + screenShotOptions = { fullPage: true - }); - expect(image).toSaveImageSnapshot() + } } - }) - - - it("action-sheet-test-current-0", async () => { - - const res = await page.callMethod('jest_getWindowInfo') - const windowHeight = res.windowHeight * res.pixelRatio; - const windowWidth = res.windowWidth * res.pixelRatio; - - - await page.setData({ - showErrorToast:false, - current: 0, - itemContentLarge:false, - itemNumLargeSelect:false, - itemColorCustom:false, - }) - - const btnToastDurationButton = await page.$('#btn-action-sheet-show') - await btnToastDurationButton.tap() - await page.waitFor(500); - - if (isApp) { - const image = await program.screenshot({ - deviceShot: true, - area: { - x: 0, - y: 200, - height: windowHeight - 100, - width:windowWidth - }, - }); - expect(image).toSaveImageSnapshot(); - }else{ - const image = await program.screenshot({ - deviceShot: true, - fullPage: true - }); - expect(image).toSaveImageSnapshot() - } - + }); + it("onload showActionSheet", async () => { + await page.waitFor(isWeb ? 3000 : 1000); + await screenshot(); }) - - it("action-sheet-test-current-0-largeContent", async () => { - - const res = await page.callMethod('jest_getWindowInfo') - const windowHeight = res.windowHeight * res.pixelRatio; - const windowWidth = res.windowWidth * res.pixelRatio; - - + it("有标题", async () => { await page.setData({ showErrorToast:false, current: 0, - itemContentLarge:true, - itemNumLargeSelect:false, - itemColorCustom:false, }) - const btnToastDurationButton = await page.$('#btn-action-sheet-show') - await btnToastDurationButton.tap() - await page.waitFor(500); - - if (isApp) { - const image = await program.screenshot({ - deviceShot: true, - area: { - x: 0, - y: 200, - height: windowHeight - 100, - width:windowWidth - }, - }); - expect(image).toSaveImageSnapshot(); - }else{ - const image = await program.screenshot({ - deviceShot: true, - fullPage: true - }); - expect(image).toSaveImageSnapshot() - } - + await showActionSheet(page); + await screenshot(); }) - - it("action-sheet-test-current-0-largeContent-largeNum", async () => { - - const res = await page.callMethod('jest_getWindowInfo') - const windowHeight = res.windowHeight * res.pixelRatio; - const windowWidth = res.windowWidth * res.pixelRatio; - + it("有标题 长内容", async () => { await page.setData({ - showErrorToast:false, - current: 0, itemContentLarge:true, - itemNumLargeSelect:true, - itemColorCustom:false, }) - const btnToastDurationButton = await page.$('#btn-action-sheet-show') - await btnToastDurationButton.tap() - await page.waitFor(500); - - if (isApp) { - const image = await program.screenshot({ - deviceShot: true, - area: { - x: 0, - y: 200, - height: windowHeight - 100, - width:windowWidth - }, - }); - expect(image).toSaveImageSnapshot(); - }else{ - const image = await program.screenshot({ - deviceShot: true, - fullPage: true - }); - expect(image).toSaveImageSnapshot() - } - - - }) - + await showActionSheet(page); - it("action-sheet-test-current-0-largeContent-largeNum-customColor", async () => { - - const res = await page.callMethod('jest_getWindowInfo') - const windowHeight = res.windowHeight * res.pixelRatio; - const windowWidth = res.windowWidth * res.pixelRatio; - - await page.setData({ - showErrorToast:false, - current: 0, - itemContentLarge:true, - itemNumLargeSelect:true, - itemColorCustom:true, - }) + await screenshot(); - const btnToastDurationButton = await page.$('#btn-action-sheet-show') - await btnToastDurationButton.tap() - await page.waitFor(500); - - if (isApp) { - // add since 2024-04-22 app 不再截图,避免跨平台对比失败 - // const image = await program.screenshot({ - // deviceShot: true, - // area: { - // x: 0, - // y: 200, - // height: windowHeight - 100, - // width:windowWidth - // }, - // }); - // expect(image).toSaveImageSnapshot(); - }else{ - const image = await program.screenshot({ - deviceShot: true, - fullPage: true - }); - expect(image).toSaveImageSnapshot() - } }) - - - it("action-sheet-test-current-1", async () => { - - const res = await page.callMethod('jest_getWindowInfo') - const windowHeight = res.windowHeight * res.pixelRatio; - const windowWidth = res.windowWidth * res.pixelRatio; - - + it("有标题 超过6个item", async () => { await page.setData({ - current: 1, itemContentLarge:false, - itemNumLargeSelect:false, - itemColorCustom:false, - }) - - const btnToastDurationButton = await page.$('#btn-action-sheet-show') - await btnToastDurationButton.tap() - await page.waitFor(500); - - if (isApp) { - const image = await program.screenshot({ - deviceShot: true, - area: { - x: 0, - y: 200, - height: windowHeight - 100, - width:windowWidth - }, - }); - expect(image).toSaveImageSnapshot(); - }else{ - const image = await program.screenshot({ - deviceShot: true, - fullPage: true - }); - expect(image).toSaveImageSnapshot() - } - - - - }) - - - - it("action-sheet-test-current-1-largeContent", async () => { - - const res = await page.callMethod('jest_getWindowInfo') - const windowHeight = res.windowHeight * res.pixelRatio; - const windowWidth = res.windowWidth * res.pixelRatio; - - - await page.setData({ - showErrorToast:false, - current: 1, - itemContentLarge:true, - itemNumLargeSelect:false, - itemColorCustom:false, - }) - - const btnToastDurationButton = await page.$('#btn-action-sheet-show') - await btnToastDurationButton.tap() - await page.waitFor(500); - - if (isApp) { - const image = await program.screenshot({ - deviceShot: true, - area: { - x: 0, - y: 200, - height: windowHeight - 100, - width:windowWidth - }, - }); - expect(image).toSaveImageSnapshot(); - }else{ - const image = await program.screenshot({ - deviceShot: true, - fullPage: true - }); - expect(image).toSaveImageSnapshot() - } - - - }) - - - it("action-sheet-test-current-1-largeContent-largeNum", async () => { - - const res = await page.callMethod('jest_getWindowInfo') - const windowHeight = res.windowHeight * res.pixelRatio; - const windowWidth = res.windowWidth * res.pixelRatio; - - await page.setData({ - showErrorToast:false, - current: 1, - itemContentLarge:true, itemNumLargeSelect:true, - itemColorCustom:false, }) - const btnToastDurationButton = await page.$('#btn-action-sheet-show') - await btnToastDurationButton.tap() - await page.waitFor(500); + await showActionSheet(page); - if (isApp) { - const image = await program.screenshot({ - deviceShot: true, - area: { - x: 0, - y: 200, - height: windowHeight - 100, - width:windowWidth - }, - }); - expect(image).toSaveImageSnapshot(); - }else{ - const image = await program.screenshot({ - deviceShot: true, - fullPage: true - }); - expect(image).toSaveImageSnapshot() - } + await screenshot(); }) - - it("action-sheet-test-current-1-largeContent-largeNum-customColor", async () => { - - const res = await page.callMethod('jest_getWindowInfo') - const windowHeight = res.windowHeight * res.pixelRatio; - const windowWidth = res.windowWidth * res.pixelRatio; - + it("有标题 长内容 自定义 itemColor", async () => { await page.setData({ - showErrorToast:false, - current: 1, - itemContentLarge:true, - itemNumLargeSelect:true, - itemColorCustom:true, + itemContentLarge: true, + itemNumLargeSelect: false, + itemColorCustom: true, }) - const btnToastDurationButton = await page.$('#btn-action-sheet-show') - await btnToastDurationButton.tap() - await page.waitFor(500); - - if (isApp) { - const image = await program.screenshot({ - deviceShot: true, - area: { - x: 0, - y: 200, - height: windowHeight - 100, - width:windowWidth - }, - }); - expect(image).toSaveImageSnapshot(); - }else{ - const image = await program.screenshot({ - deviceShot: true, - fullPage: true - }); - expect(image).toSaveImageSnapshot() - } + await showActionSheet(page); + await screenshot(); }) - - - it("action-sheet-test-current-2", async () => { - - const res = await page.callMethod('jest_getWindowInfo') - const windowHeight = res.windowHeight * res.pixelRatio; - const windowWidth = res.windowWidth * res.pixelRatio; - - + it("无标题", async () => { await page.setData({ - current: 2, + current: 1, itemContentLarge:false, - itemNumLargeSelect:false, itemColorCustom:false, }) - const btnToastDurationButton = await page.$('#btn-action-sheet-show') - await btnToastDurationButton.tap() - await page.waitFor(500); - - if (isApp) { - const image = await program.screenshot({ - deviceShot: true, - area: { - x: 0, - y: 200, - height: windowHeight - 100, - width:windowWidth - }, - }); - expect(image).toSaveImageSnapshot(); - }else{ - const image = await program.screenshot({ - deviceShot: true, - fullPage: true - }); - expect(image).toSaveImageSnapshot() - } - + await showActionSheet(page); + await screenshot(); }) - - it("action-sheet-test-current-2-largeContent", async () => { - - const res = await page.callMethod('jest_getWindowInfo') - const windowHeight = res.windowHeight * res.pixelRatio; - const windowWidth = res.windowWidth * res.pixelRatio; - - + it("长标题", async () => { await page.setData({ - showErrorToast:false, current: 2, - itemContentLarge:true, - itemNumLargeSelect:false, - itemColorCustom:false, }) - const btnToastDurationButton = await page.$('#btn-action-sheet-show') - await btnToastDurationButton.tap() - await page.waitFor(500); - - if (isApp) { - const image = await program.screenshot({ - deviceShot: true, - area: { - x: 0, - y: 200, - height: windowHeight - 100, - width:windowWidth - }, - }); - expect(image).toSaveImageSnapshot(); - }else{ - const image = await program.screenshot({ - deviceShot: true, - fullPage: true - }); - expect(image).toSaveImageSnapshot() - } - + await showActionSheet(page); + await screenshot(); }) - - it("action-sheet-test-current-2-largeContent-largeNum", async () => { - - const res = await page.callMethod('jest_getWindowInfo') - const windowHeight = res.windowHeight * res.pixelRatio; - const windowWidth = res.windowWidth * res.pixelRatio; - + it("custom titleColor cancelText cancelColor backgroundColor", async () => { await page.setData({ - showErrorToast:false, - current: 2, - itemContentLarge:true, - itemNumLargeSelect:true, - itemColorCustom:false, + titleColorCustom: true, + cancelTextCustom: true, + cancelColorCustom: true, + backgroundColorCustom: true, }) + await showActionSheet(page); - const btnToastDurationButton = await page.$('#btn-action-sheet-show') - await btnToastDurationButton.tap() - await page.waitFor(500); - - if (isApp) { - const image = await program.screenshot({ - deviceShot: true, - area: { - x: 0, - y: 200, - height: windowHeight - 100, - width:windowWidth - }, - }); - expect(image).toSaveImageSnapshot(); - }else{ - const image = await program.screenshot({ - deviceShot: true, - fullPage: true - }); - expect(image).toSaveImageSnapshot() - } - - + await screenshot(); }) + it("hideActionSheet", async () => { + await page.callMethod('hideActionSheet') + await page.waitFor(1000); - - it("action-sheet-test-current-2-largeContent-largeNum-customColor", async () => { - - const res = await page.callMethod('jest_getWindowInfo') - const windowHeight = res.windowHeight * res.pixelRatio; - const windowWidth = res.windowWidth * res.pixelRatio; - - await page.setData({ - showErrorToast:false, - current: 2, - itemContentLarge:true, - itemNumLargeSelect:true, - itemColorCustom:true, - }) - - const btnToastDurationButton = await page.$('#btn-action-sheet-show') - await btnToastDurationButton.tap() - await page.waitFor(500); - - if (isApp) { - const image = await program.screenshot({ - deviceShot: true, - area: { - x: 0, - y: 200, - height: windowHeight - 100, - width:windowWidth - }, - }); - expect(image).toSaveImageSnapshot(); - }else{ - const image = await program.screenshot({ - deviceShot: true, - fullPage: true - }); - expect(image).toSaveImageSnapshot() - } - + await screenshot(); }) - - - }); diff --git a/pages/API/show-action-sheet/show-action-sheet.uvue b/pages/API/show-action-sheet/show-action-sheet.uvue index 40c9c615..a7bd99c5 100644 --- a/pages/API/show-action-sheet/show-action-sheet.uvue +++ b/pages/API/show-action-sheet/show-action-sheet.uvue @@ -1,6 +1,6 @@ -