From b72e56acd19937802123ec99e447ca4c0f90eb98 Mon Sep 17 00:00:00 2001 From: Anne_LXM Date: Tue, 11 Jun 2024 16:27:55 +0800 Subject: [PATCH] =?UTF-8?q?=E8=B0=83=E6=95=B4=E6=B5=8B=E8=AF=95=E4=BE=8B?= =?UTF-8?q?=EF=BC=9A=E5=9B=A0=E4=BA=8B=E4=BB=B6event=E5=8F=82=E6=95=B0?= =?UTF-8?q?=E5=AF=B9=E8=B1=A1=E4=B8=AD=E5=AD=98=E5=9C=A8=E5=BE=AA=E7=8E=AF?= =?UTF-8?q?=E5=BC=95=E7=94=A8=EF=BC=8C=E5=9C=A8ios=E7=AB=AFJSON.stringify?= =?UTF-8?q?=E6=8A=A5=E9=94=99=EF=BC=8C=E8=87=AA=E5=8A=A8=E5=8C=96=E6=B5=8B?= =?UTF-8?q?=E8=AF=95=E6=97=A0=E6=B3=95page.data=E8=8E=B7=E5=8F=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pages/component/swiper/swiper.test.js | 72 ++++++++++++++------------- pages/component/swiper/swiper.uvue | 65 +++++++++++++++++++++--- 2 files changed, 94 insertions(+), 43 deletions(-) diff --git a/pages/component/swiper/swiper.test.js b/pages/component/swiper/swiper.test.js index 869d6972..ae63884a 100644 --- a/pages/component/swiper/swiper.test.js +++ b/pages/component/swiper/swiper.test.js @@ -11,6 +11,15 @@ describe('test swiper', () => { } let page; + const webDetailRes = { + current: 1, + currentItemId: 'B',//web端多了currentItemId + source: 'autoplay' , + } + const appDetailRes = { + current: 1, + source: 'autoplay' , + } beforeAll(async () => { page = await program.reLaunch('/pages/component/swiper/swiper') await page.waitFor(600) @@ -82,7 +91,6 @@ describe('test swiper', () => { autoplaySelect:true }) await page.waitFor(2000) - console.log('currentValChange',await page.data('currentValChange')) if(await page.data('currentValChange') == 1){ await page.setData({ autoplaySelect:false @@ -90,45 +98,39 @@ describe('test swiper', () => { } }); - it('Event change-transitiont-animationfinish', async () => { - const webResult = { - current: 1, - currentItemId: 'B',//web端多了currentItemId - source: 'autoplay' , - } - const appResult = { - current: 1, - source: 'autoplay' , + it('Event transitiont', async () => { + // android端swiper的事件event参数detail类型错误,暂时忽略测试 + if(!process.env.UNI_UTS_PLATFORM.startsWith('app-android')){ + const transitionDetailInfo = await page.data('transitionDetailTest') + expect(transitionDetailInfo.dy).toBe(0) + expect(transitionDetailInfo.dx).toBeGreaterThan(0) + expect(await page.data('isTransitionTest')).toBe('transition:Pass') } - 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) + }); + + it('Event change', async () => { + if(!process.env.UNI_UTS_PLATFORM.startsWith('app-android')){ + const changeDetailInfo = await page.data('changeDetailTest') + if(process.env.uniTestPlatformInfo.startsWith('web')){ + expect(changeDetailInfo).toEqual(webDetailRes) + }else{ + expect(changeDetailInfo).toEqual(appDetailRes) + } + expect(await page.data('isChangeTest')).toBe('change:Pass') } - 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(); + it('Event animationfinish', async () => { 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) + if(!process.env.UNI_UTS_PLATFORM.startsWith('app-android')){ + const animationfinishDetailInfo = await page.data('animationfinishDetailTest') + if(process.env.uniTestPlatformInfo.startsWith('web')){ + expect(animationfinishDetailInfo).toEqual(webDetailRes) + }else{ + expect(animationfinishDetailInfo).toEqual(appDetailRes) + } + expect(await page.data('isAnimationfinishTest')).toBe('animationfinish:Pass') } - 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 fccf4a08..66ed25c8 100644 --- a/pages/component/swiper/swiper.uvue +++ b/pages/component/swiper/swiper.uvue @@ -88,7 +88,12 @@ -