scroll-view.test.js 3.4 KB
Newer Older
Anne_LXM's avatar
Anne_LXM 已提交
1
jest.setTimeout(30000);
2
describe('component-native-scroll-view', () => {
Anne_LXM's avatar
Anne_LXM 已提交
3 4 5 6 7 8 9 10
  const platformInfo = process.env.uniTestPlatformInfo.toLocaleLowerCase()
  const isIos = platformInfo.startsWith('ios')
  if (isIos) {
    it('dummyTest', () => {
      expect(1).toBe(1)
    })
    return
  }
11 12 13 14 15 16 17 18 19 20 21 22
  let page;
  beforeAll(async () => {
    page = await program.reLaunch('/pages/component/scroll-view/scroll-view');
    await page.waitFor(300);
  });

  it('scroll-view-screenshot', async () => {
    //禁止滚动条
    await page.setData({
        showScrollbar: false
    })
    await page.waitFor(300);
23
    const image = await program.screenshot({fullPage: true});
24 25
    expect(image).toSaveImageSnapshot();
  });
26 27 28 29

  it('Event scroll-vertical',async()=>{
    // 纵向滚动
    await page.setData({scrollTop: 100})
30 31 32 33 34 35 36 37 38 39 40 41 42 43
    await page.waitFor(1000)
    // bug:在web端scroll事件event参数中detail类型报错
    if(!process.env.UNI_UTS_PLATFORM.startsWith('web')){
      // 设置top 是否触发scroll 事件
      const topScrollDetail = await page.data('scrollDetailTest')
      expect(topScrollDetail.scrollLeft).toBe(0)
      // Android 差异scrollTop:99.809525
      if(!process.env.uniTestPlatformInfo.startsWith('android')){
        expect(topScrollDetail.scrollTop).toBe(100)
      }
      expect(topScrollDetail.scrollHeight).toBeGreaterThan(0)
      expect(topScrollDetail.scrollWidth).toBeGreaterThan(0)
      expect(topScrollDetail.deltaX).toBe(0)
      expect(topScrollDetail.deltaY).toBe(-100)
44
    }
45
    expect(await page.data('isScrollTest')).toBe('scroll:Success')
46 47 48 49 50 51
  })

  it('Event scroll-horizontal',async()=>{
    // 横向滚动
    await page.setData({scrollLeft:220})
    await page.waitFor(600)
52 53 54 55 56 57 58 59 60 61 62 63
    if(!process.env.UNI_UTS_PLATFORM.startsWith('web')){
      //设置left 是否触发scroll 事件
      const leftScrollDetail = await page.data('scrollDetailTest')
      // Android 差异scrollLeft:219.80952
      if(!process.env.uniTestPlatformInfo.startsWith('android')){
        expect(leftScrollDetail.scrollLeft).toBe(220)
      }
      expect(leftScrollDetail.scrollTop).toBe(0)
      expect(leftScrollDetail.scrollHeight).toBeGreaterThan(0)
      expect(leftScrollDetail.scrollWidth).toBeGreaterThan(0)
      expect(leftScrollDetail.deltaX).toBe(-100)
      expect(leftScrollDetail.deltaY).toBe(0)
64
    }
65
    expect(await page.data('isScrollTest')).toBe('scroll:Success')
66 67 68
  })

  it('Event scrolltolower-滚动到底部/右边',async()=>{
69
    // 滚动到底部scrollTop:300,是否触发scrolltolower事件
70 71
    await page.setData({scrollTop: 300})
    await page.waitFor(600)
72
    expect(await page.data('isScrolltolowerTest')).toBe('scrolltolower:Success-bottom')
73 74 75
  })

  it('Event scrolltoupper-滚动到顶部/左边',async()=>{
76 77 78
    // 滚动到顶部scrollTop: 0,是否触发scrolltoupper事件
    await page.setData({scrollTop: 0})
    // await page.callMethod('goTop')
79
    await page.waitFor(600)
80
    expect(await page.data('isScrolltoupperTest')).toBe('scrolltoupper:Success-top')
81
  })
82 83 84 85 86 87 88 89 90 91 92 93

  if(!process.env.UNI_UTS_PLATFORM.startsWith('web')){
    it('Event scrollend-滚动结束时触发仅App端支持',async()=>{
      const endDetail = await page.data('scrollEndDetailTest')
      expect(endDetail.scrollLeft).toBe(0)
      expect(endDetail.scrollTop).toBe(0)
      expect(endDetail.deltaY).toBe(0)
      expect(endDetail.deltaX).toBe(0)
      expect(endDetail.scrollHeight).toBeGreaterThan(0)
      expect(endDetail.scrollWidth).toBeGreaterThan(0)
    })
  }
94
});