swiper.test.js 2.5 KB
Newer Older
DCloud_iOS_WZT's avatar
DCloud_iOS_WZT 已提交
1 2
jest.setTimeout(20000);

DCloud-WZF's avatar
DCloud-WZF 已提交
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 32
function getData(key = '') {
  return new Promise(async (resolve, reject) => {
    const data = await page.data()
    resolve(key ? data[key] : data)
  })
}

let page;
beforeAll(async () => {
  page = await program.reLaunch('/pages/component/swiper/swiper')
  await page.waitFor(600)
})


describe('test swiper', () => {
  it('check indicator show', async () => {
    await page.setData({
      dotsSelect: true,
    })
    await page.waitFor(600)
    await page.setData({
      dotsSelect: false,
    })
    await page.waitFor(600)
    /**
     * todo 暂无判断条件
     */
  });

  it('check autoplay loop', async () => {
DCloud_iOS_WZT's avatar
DCloud_iOS_WZT 已提交
33 34 35 36 37 38 39 40
    // iOS平台此测试用例 等待时长不准确 导致用例过不了
    if (!process.env.uniTestPlatformInfo.startsWith('IOS_SIMULATOR')) {
      await page.setData({
        autoplaySelect: true,
        currentValChange: 0,
      })
      await page.waitFor(600)
      expect(await getData('currentValChange')).toEqual(0)
DCloud_iOS_WZT's avatar
DCloud_iOS_WZT 已提交
41
      await page.waitFor(1600)
DCloud_iOS_WZT's avatar
DCloud_iOS_WZT 已提交
42 43 44 45 46 47 48 49 50 51 52
      expect(await getData('currentValChange')).toEqual(1)
      await page.waitFor(2000)
      expect(await getData('currentValChange')).toEqual(2)
      await page.waitFor(2000)
      expect(await getData('currentValChange')).toEqual(0)
      await page.setData({
        circularSelect: true,
        currentValChange: 0,
      })
      await page.waitFor(600)
      expect(await getData('currentValChange')).toEqual(0)
DCloud_iOS_WZT's avatar
DCloud_iOS_WZT 已提交
53
      await page.waitFor(1600)
DCloud_iOS_WZT's avatar
DCloud_iOS_WZT 已提交
54
      expect(await getData('currentValChange')).toEqual(1)
DCloud_iOS_WZT's avatar
DCloud_iOS_WZT 已提交
55
      await page.waitFor(2000)
DCloud_iOS_WZT's avatar
DCloud_iOS_WZT 已提交
56
      expect(await getData('currentValChange')).toEqual(2)
DCloud_iOS_WZT's avatar
DCloud_iOS_WZT 已提交
57
      await page.waitFor(2000)
DCloud_iOS_WZT's avatar
DCloud_iOS_WZT 已提交
58 59 60 61 62 63 64
      expect(await getData('currentValChange')).toEqual(0)
      await page.setData({
        circularSelect: false,
        autoplaySelect: false
      })
      await page.waitFor(300)
    }
DCloud-WZF's avatar
DCloud-WZF 已提交
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94
  });


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

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

    await page.setData({
      currentItemIdVal: 'A',
    })
    await page.waitFor(600)
    expect(await getData('currentValChange')).toEqual(0)
  });

杜庆泉's avatar
杜庆泉 已提交
95
});