diff --git a/pages/component/scroll-view/scroll-view-refresher.test.js b/pages/component/scroll-view/scroll-view-refresher.test.js index 9c9e96b4a0a7df1e0e22f6b3b15409cf8df2e0d2..92315f79d944bf7cc73aaaf504b44762ead8cd25 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 5adc88f098d0a539c28643af42d833d0bbe839e2..773103d95d4a1ce91d85369bd45985d273705432 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)