From a7752a3480602d07406489c7de93975f8b47981e Mon Sep 17 00:00:00 2001 From: Anne_LXM Date: Wed, 5 Jun 2024 23:30:52 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E9=BB=98=E8=AE=A4=E4=B8=8B?= =?UTF-8?q?=E6=8B=89=E5=88=B7=E6=96=B0=E4=BA=8B=E4=BB=B6=E8=87=AA=E5=8A=A8?= =?UTF-8?q?=E5=8C=96=E6=B5=8B=E8=AF=95=E4=BE=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../scroll-view/scroll-view-refresher.test.js | 21 ++++++++++++++++--- .../scroll-view/scroll-view-refresher.uvue | 18 +++++++++++----- 2 files changed, 31 insertions(+), 8 deletions(-) diff --git a/pages/component/scroll-view/scroll-view-refresher.test.js b/pages/component/scroll-view/scroll-view-refresher.test.js index 9c9e96b4..92315f79 100644 --- a/pages/component/scroll-view/scroll-view-refresher.test.js +++ b/pages/component/scroll-view/scroll-view-refresher.test.js @@ -11,7 +11,15 @@ describe('component-native-scroll-view-refresher', () => { beforeAll(async () => { page = await program.reLaunch('/pages/component/scroll-view/scroll-view-refresher'); await page.waitFor(300); - }); + }); + + async function eventCheck(dataName,typeName){ + const eventInfo = await page.data(dataName) + expect(eventInfo.type).toBe(typeName) + expect(eventInfo.currentTarget).not.toBeFalsy(); + expect(eventInfo.target).not.toBeFalsy(); + expect(eventInfo.detail.dy).toBeGreaterThan(0) + } it('scroll-view-refresher-screenshot', async () => { //禁止滚动条 @@ -23,12 +31,19 @@ describe('component-native-scroll-view-refresher', () => { expect(image).toSaveImageSnapshot(); }) - it('check_refresher', async () => { + it('check_refresher_refresh_event', async () => { await page.setData({ refresherTriggered: true }) await page.waitFor(2000); - expect(await page.data('refresherrefreshTimes')).toBe(1) + expect(await page.data('refresherrefreshTimes')).toBe(1) + // 手动设置下拉刷新状态refresher-triggered为true时,在web和iOS不触发@refresherpulling事件 + if(process.env.uniTestPlatformInfo.startsWith('android')){ + await eventCheck('onRefresherpullingTest','refresherpulling') + } + await eventCheck('refresherrefreshTest','refresherrefresh') + await page.waitFor(1000); + await eventCheck('onRefresherrestoreTest','refresherrestore') }); it('check_refresher_snapshot', async () => { diff --git a/pages/component/scroll-view/scroll-view-refresher.uvue b/pages/component/scroll-view/scroll-view-refresher.uvue index 5adc88f0..773103d9 100644 --- a/pages/component/scroll-view/scroll-view-refresher.uvue +++ b/pages/component/scroll-view/scroll-view-refresher.uvue @@ -20,7 +20,12 @@ refresherTriggered: false, refresherrefresh: false, refresherrefreshTimes: 0, - showScrollbar: false + showScrollbar: false, + // 自动化测试 + refresherrefreshTest:null as RefresherEvent|null, + onRefresherabortTest:null as RefresherEvent|null, + onRefresherrestoreTest:null as RefresherEvent|null, + onRefresherpullingTest:null as RefresherEvent|null }; }, onLoad() { @@ -32,25 +37,28 @@ }, methods: { - onRefresherrefresh(_ : RefresherEvent) { + onRefresherrefresh(e : RefresherEvent) { this.refresherrefresh = true console.log("onRefresherrefresh--------------下拉刷新触发") + this.refresherrefreshTest = e this.refresherTriggered = true this.refresherrefreshTimes++ setTimeout(() => { this.refresherTriggered = false }, 1500) - }, - onRefresherabort(_ : RefresherEvent) { + onRefresherabort(e : RefresherEvent) { console.log("onRefresherabort------下拉刷新被中止") + this.onRefresherabortTest = e }, - onRefresherrestore(_ : RefresherEvent) { + onRefresherrestore(e : RefresherEvent) { this.refresherrefresh = false console.log("onRefresherrestore------下拉刷新被复位") + this.onRefresherrestoreTest = e }, onRefresherpulling(e : RefresherEvent) { console.log("onRefresherpulling------拉刷新控件被下拉-dy=" + e.detail.dy) + this.onRefresherpullingTest = e }, onScrolltolower(e : ScrollToLowerEvent) { console.log("onScrolltolower 滚动到底部-----" + e.detail.direction) -- GitLab