From f5f22bf91b85f84c164ff0575f050d9ad3f4540a Mon Sep 17 00:00:00 2001 From: Anne_LXM Date: Tue, 4 Jun 2024 17:33:46 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9Eswiper=E4=BA=8B=E4=BB=B6?= =?UTF-8?q?=E8=87=AA=E5=8A=A8=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 --- pages/component/swiper/swiper.test.js | 61 ++++++++++++++++++++++++++- pages/component/swiper/swiper.uvue | 19 ++++++--- 2 files changed, 72 insertions(+), 8 deletions(-) diff --git a/pages/component/swiper/swiper.test.js b/pages/component/swiper/swiper.test.js index 32ac9e3f..400a6905 100644 --- a/pages/component/swiper/swiper.test.js +++ b/pages/component/swiper/swiper.test.js @@ -1,4 +1,4 @@ -jest.setTimeout(20000); +jest.setTimeout(30000); function getData(key = '') { return new Promise(async (resolve, reject) => { @@ -72,6 +72,63 @@ describe('test swiper', () => { }) await page.waitFor(600) expect(await getData('currentValChange')).toEqual(0) + }); + + it('Trigger Event', async () => { + await page.setData({ + swiperChangeSelect: true, + swiperTransitionSelect: true, + swiperAnimationfinishSelect: true, + autoplaySelect:true + }) + await page.waitFor(2000) + console.log('currentValChange',await getData('currentValChange')) + if(await getData('currentValChange') == 1){ + await page.setData({ + autoplaySelect:false + }) + } + }); + + it('Event change-transitiont-animationfinish', async () => { + const webResult = { + current: 1, + currentItemId: 'B',//web端多了currentItemId + source: 'autoplay' , + } + const appResult = { + current: 1, + source: 'autoplay' , + } + const changeInfo = await page.data('swiperChangeEventTest') + // console.log('change',changeInfo) + expect(changeInfo.type).toBe('change') + if(process.env.uniTestPlatformInfo.startsWith('web')){ + expect(changeInfo.detail).toEqual(webResult) + }else{ + expect(changeInfo.detail).toEqual(appResult) + } + expect(changeInfo.currentTarget).not.toBeFalsy(); + expect(changeInfo.target).not.toBeFalsy(); + + const transitionInfo = await page.data('swiperTransitionTest') + // console.log('transitiont',transitionInfo,detail) + expect(transitionInfo.type).toBe('transition') + expect(transitionInfo.detail.dy).toBe(0) + expect(transitionInfo.detail.dx).toBeGreaterThan(0) + expect(transitionInfo.currentTarget).not.toBeFalsy(); + expect(transitionInfo.target).not.toBeFalsy(); + await page.waitFor(1000) + // bug:在android端第一次触发@animationfinish 得到detail中的source为空,第二次触发时正常得到source: 'autoplay' + const animationfinishInfo = await page.data('swiperAnimationfinishTest') + // console.log('animationfinish',animationfinishInfo.detail) + expect(animationfinishInfo.type).toBe('animationfinish') + if(process.env.uniTestPlatformInfo.startsWith('web')){ + expect(animationfinishInfo.detail).toEqual(webResult) + }else if(!process.env.uniTestPlatformInfo.startsWith('android')){ + expect(animationfinishInfo.detail).toEqual(appResult) + } + expect(animationfinishInfo.currentTarget).not.toBeFalsy(); + expect(animationfinishInfo.target).not.toBeFalsy(); }); - }); diff --git a/pages/component/swiper/swiper.uvue b/pages/component/swiper/swiper.uvue index 832d0de5..fccf4a08 100644 --- a/pages/component/swiper/swiper.uvue +++ b/pages/component/swiper/swiper.uvue @@ -110,12 +110,17 @@ swiperTransitionSelect: false, swiperAnimationfinishSelect: false, swiperChangeSelect: false, - currentValChange: 0 + currentValChange: 0, + // 自动化测试 + swiperChangeEventTest:null as SwiperChangeEvent | null, + swiperTransitionTest:null as SwiperTransitionEvent | null, + swiperAnimationfinishTest:null as SwiperAnimationFinishEvent | null } - }, + }, methods: { - swiperChange: function (e : SwiperChangeEvent) { + swiperChange: function (e : SwiperChangeEvent) { + this.swiperChangeEventTest = e this.currentValChange = e.detail.current console.log(this.currentValChange) if (this.swiperChangeSelect) { @@ -123,13 +128,15 @@ console.log(e) } }, - swiperTransition: function (e : SwiperTransitionEvent) { + swiperTransition: function (e : SwiperTransitionEvent) { + this.swiperTransitionTest = e if (this.swiperTransitionSelect) { console.log("swiperTransition") console.log(e) } }, - swiperAnimationfinish: function (e : SwiperAnimationFinishEvent) { + swiperAnimationfinish: function (e : SwiperAnimationFinishEvent) { + this.swiperAnimationfinishTest = e if (this.swiperAnimationfinishSelect) { console.log("swiperAnimationfinish") console.log(e) @@ -148,7 +155,7 @@ swiperAnimationfinishChange: function (e : UniSwitchChangeEvent) { this.swiperAnimationfinishSelect = e.detail.value }, - autoplayChange: function (e : UniSwitchChangeEvent) { + autoplayChange: function (e : UniSwitchChangeEvent) { this.autoplaySelect = e.detail.value }, verticalChange: function (e : UniSwitchChangeEvent) { -- GitLab