swiper.test.js 3.9 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13
jest.setTimeout(30000);

describe('test swiper', () => {
  const platformInfo = process.env.uniTestPlatformInfo.toLocaleLowerCase()
  const isIos = platformInfo.startsWith('ios')
  if (isIos) {
    it('dummyTest', () => {
      expect(1).toBe(1)
    })
    return
  }

  let page;
14 15 16 17 18 19 20 21 22
  const webDetailRes = {
    current: 1,
    currentItemId: 'B',//web端多了currentItemId
    source: 'autoplay' ,
  }
  const appDetailRes = {
    current: 1,
    source: 'autoplay' ,
  }
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
  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 已提交
41 42 43 44 45 46
  it('check autoplay loop', async () => {
    await page.setData({
      currentValChange: 0,
      autoplaySelect: true,
    })
    await page.waitFor(2400)
47
    expect(await page.data('currentValChange')).toEqual(1)
DCloud_iOS_WZT's avatar
DCloud_iOS_WZT 已提交
48
    await page.waitFor(2000)
49
    expect(await page.data('currentValChange')).toEqual(2)
DCloud_iOS_WZT's avatar
DCloud_iOS_WZT 已提交
50
    await page.waitFor(2000)
51
    expect(await page.data('currentValChange')).toEqual(0)
DCloud_iOS_WZT's avatar
DCloud_iOS_WZT 已提交
52 53 54 55

    await page.setData({
      autoplaySelect: false
    })
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83
    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 已提交
84 85 86 87 88 89 90 91 92 93
  });

  it('Trigger Event', async () => {
    await page.setData({
      swiperChangeSelect: true,
      swiperTransitionSelect: true,
      swiperAnimationfinishSelect: true,
      autoplaySelect:true
    })
    await page.waitFor(2000)
94
    if(await page.data('currentValChange') == 1){
Anne_LXM's avatar
Anne_LXM 已提交
95 96 97 98 99 100
      await page.setData({
        autoplaySelect:false
      })
    }
  });

101 102 103 104 105 106 107
  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')
Anne_LXM's avatar
Anne_LXM 已提交
108
    }
109 110 111 112 113 114 115 116 117 118 119
  });

  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 已提交
120
    }
121
  });
Anne_LXM's avatar
Anne_LXM 已提交
122

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