swiper.test.js 4.0 KB
Newer Older
DCloud-WZF's avatar
DCloud-WZF 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
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;
  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 已提交
32 33 34 35 36 37
  it('check autoplay loop', async () => {
    await page.setData({
      currentValChange: 0,
      autoplaySelect: true,
    })
    await page.waitFor(2400)
38
    expect(await page.data('currentValChange')).toEqual(1)
DCloud_iOS_WZT's avatar
DCloud_iOS_WZT 已提交
39
    await page.waitFor(2000)
40
    expect(await page.data('currentValChange')).toEqual(2)
DCloud_iOS_WZT's avatar
DCloud_iOS_WZT 已提交
41
    await page.waitFor(2000)
42
    expect(await page.data('currentValChange')).toEqual(0)
DCloud_iOS_WZT's avatar
DCloud_iOS_WZT 已提交
43 44 45 46

    await page.setData({
      autoplaySelect: false
    })
DCloud-WZF's avatar
DCloud-WZF 已提交
47 48 49 50 51 52 53 54
    await page.waitFor(300)
  });

  it('check current', async () => {
    await page.setData({
      currentVal: 2,
    })
    await page.waitFor(600)
55
    expect(await page.data('currentValChange')).toEqual(2)
DCloud-WZF's avatar
DCloud-WZF 已提交
56 57 58 59
    await page.setData({
      currentVal: 0,
    })
    await page.waitFor(600)
60
    expect(await page.data('currentValChange')).toEqual(0)
DCloud-WZF's avatar
DCloud-WZF 已提交
61 62 63 64 65 66 67
  });

  it('check currentId', async () => {
    await page.setData({
      currentItemIdVal: 'C',
    })
    await page.waitFor(600)
68
    expect(await page.data('currentValChange')).toEqual(2)
DCloud-WZF's avatar
DCloud-WZF 已提交
69 70 71 72 73

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

  it('Trigger Event', async () => {
    await page.setData({
      swiperChangeSelect: true,
      swiperTransitionSelect: true,
      swiperAnimationfinishSelect: true,
      autoplaySelect:true
    })
    await page.waitFor(2000)
85 86
    console.log('currentValChange',await page.data('currentValChange'))
    if(await page.data('currentValChange') == 1){
Anne_LXM's avatar
Anne_LXM 已提交
87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132
      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();
DCloud-WZF's avatar
DCloud-WZF 已提交
133
  });
杜庆泉's avatar
杜庆泉 已提交
134
});