swiper.test.js 3.2 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 () => {
93
    const transitionDetailInfo = await page.data('transitionDetailTest')
94
    expect(transitionDetailInfo.dy).toBe(0)
95 96
    expect(transitionDetailInfo.dx).not.toBe(0)
    expect(await page.data('isTransitionTest')).toBe('transition:Success')
97 98 99
  });

  it('Event change', async () => {
100 101 102 103 104
    const changeDetailInfo = await page.data('changeDetailTest')
    if(process.env.uniTestPlatformInfo.startsWith('web')){
      expect(changeDetailInfo).toEqual(webDetailRes)
    }else{
      expect(changeDetailInfo).toEqual(appDetailRes)
Anne_LXM's avatar
Anne_LXM 已提交
105
    }
106
    expect(await page.data('isChangeTest')).toBe('change:Success')
107
  });
Anne_LXM's avatar
Anne_LXM 已提交
108

109
  it('Event animationfinish', async () => {
Anne_LXM's avatar
Anne_LXM 已提交
110
    await page.waitFor(1000)
111 112 113 114 115
    const animationfinishDetailInfo = await page.data('animationfinishDetailTest')
    if(process.env.uniTestPlatformInfo.startsWith('web')){
      expect(animationfinishDetailInfo).toEqual(webDetailRes)
    }else{
      expect(animationfinishDetailInfo).toEqual(appDetailRes)
Anne_LXM's avatar
Anne_LXM 已提交
116
    }
117
    expect(await page.data('isAnimationfinishTest')).toBe('animationfinish:Success')
118
  });
杜庆泉's avatar
杜庆泉 已提交
119
});