swiper.test.js 3.9 KB
Newer Older
1 2 3
jest.setTimeout(30000);
describe('test swiper', () => {
  let page;
4 5 6 7 8 9 10 11 12
  const webDetailRes = {
    current: 1,
    currentItemId: 'B',//web端多了currentItemId
    source: 'autoplay' ,
  }
  const appDetailRes = {
    current: 1,
    source: 'autoplay' ,
  }
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
  beforeAll(async () => {
    page = await program.reLaunch('/pages/component/swiper/swiper')
    await page.waitFor(600)
  })
  it('check indicator show', async () => {
    await page.setData({
      dotsSelect: true,
    })
    await page.waitFor(600)
    await page.setData({
      dotsSelect: false,
    })
    await page.waitFor(600)
    /**
     * todo 暂无判断条件
     */
  });

DCloud_iOS_WZT's avatar
DCloud_iOS_WZT 已提交
31 32 33 34 35 36
  it('check autoplay loop', async () => {
    await page.setData({
      currentValChange: 0,
      autoplaySelect: true,
    })
    await page.waitFor(2400)
37
    expect(await page.data('currentValChange')).toEqual(1)
DCloud_iOS_WZT's avatar
DCloud_iOS_WZT 已提交
38
    await page.waitFor(2000)
39
    expect(await page.data('currentValChange')).toEqual(2)
DCloud_iOS_WZT's avatar
DCloud_iOS_WZT 已提交
40
    await page.waitFor(2000)
41
    expect(await page.data('currentValChange')).toEqual(0)
DCloud_iOS_WZT's avatar
DCloud_iOS_WZT 已提交
42 43 44 45

    await page.setData({
      autoplaySelect: false
    })
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73
    await page.waitFor(300)
  });

  it('check current', async () => {
    await page.setData({
      currentVal: 2,
    })
    await page.waitFor(600)
    expect(await page.data('currentValChange')).toEqual(2)
    await page.setData({
      currentVal: 0,
    })
    await page.waitFor(600)
    expect(await page.data('currentValChange')).toEqual(0)
  });

  it('check currentId', async () => {
    await page.setData({
      currentItemIdVal: 'C',
    })
    await page.waitFor(600)
    expect(await page.data('currentValChange')).toEqual(2)

    await page.setData({
      currentItemIdVal: 'A',
    })
    await page.waitFor(600)
    expect(await page.data('currentValChange')).toEqual(0)
Anne_LXM's avatar
Anne_LXM 已提交
74 75 76 77 78 79 80 81 82 83
  });

  it('Trigger Event', async () => {
    await page.setData({
      swiperChangeSelect: true,
      swiperTransitionSelect: true,
      swiperAnimationfinishSelect: true,
      autoplaySelect:true
    })
    await page.waitFor(2000)
Anne_LXM's avatar
Anne_LXM 已提交
84 85 86 87 88 89
    await page.waitFor(async()=>{
      return await page.data('currentValChange') == 1
    })
    await page.setData({
      autoplaySelect:false
    })
Anne_LXM's avatar
Anne_LXM 已提交
90 91
  });

92
  it('Event transitiont', async () => {
Anne_LXM's avatar
Anne_LXM 已提交
93
    // bug:android端swiper的事件event参数detail类型错误,暂时忽略测试
94 95
    if(!process.env.UNI_UTS_PLATFORM.startsWith('app-android')){
      const transitionDetailInfo = await page.data('transitionDetailTest')
Anne_LXM's avatar
Anne_LXM 已提交
96 97 98 99 100
      // bug:在iOS端,swiper首次横向滑动切换@transition事件参数e.detail.dy为1错误,暂时忽略测试
      if(process.env.uniTestPlatformInfo.startsWith('web')){
        expect(transitionDetailInfo.dy).toBe(0)
      }
      expect(transitionDetailInfo.dx).not.toBe(0)
101
      expect(await page.data('isTransitionTest')).toBe('transition:Pass')
Anne_LXM's avatar
Anne_LXM 已提交
102
    }
103 104 105 106 107 108 109 110 111 112 113
  });

  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')
Anne_LXM's avatar
Anne_LXM 已提交
114
    }
115
  });
Anne_LXM's avatar
Anne_LXM 已提交
116

117
  it('Event animationfinish', async () => {
Anne_LXM's avatar
Anne_LXM 已提交
118 119
    await page.waitFor(1000)
    // bug:在android端第一次触发@animationfinish 得到detail中的source为空,第二次触发时正常得到source: 'autoplay'
120 121 122 123 124 125 126 127
    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')
Anne_LXM's avatar
Anne_LXM 已提交
128
    }
129
  });
杜庆泉's avatar
杜庆泉 已提交
130
});