scroll-view.test.js 4.3 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 30 31 32 33 34 35 36 37 38 39 40 41 42 43

  it('Event scroll-vertical',async()=>{
    // 纵向滚动
    await page.setData({scrollTop: 100})
    await page.waitFor(600)
    //设置top 是否触发scroll 事件
    const topScrollInfo = await page.data('scrollTest')
    // const topScrollResult = {
    //   "scrollLeft": 0,
    //   "scrollTop": 100,
    //   "scrollHeight": 450,
    //   "scrollWidth": 345,
    //   "deltaX": 0,
    //   "deltaY": -100
    // }
    const {scrollLeft,scrollTop,scrollHeight,scrollWidth,deltaX,deltaY} = topScrollInfo.detail
    expect(topScrollInfo.type).toBe('scroll')
    expect(scrollLeft).toBe(0)
Anne_LXM's avatar
Anne_LXM 已提交
44 45 46 47
    // Android 差异scrollTop:99.809525
    if(!process.env.uniTestPlatformInfo.startsWith('android')){
      expect(scrollTop).toBe(100)
    }
48 49 50 51 52 53 54 55 56 57 58 59 60 61
    expect(scrollHeight).toBeGreaterThan(0)
    expect(scrollWidth).toBeGreaterThan(0)
    expect(deltaX).toBe(0)
    expect(deltaY).toBe(-100)
    expect(topScrollInfo.currentTarget).not.toBeFalsy();
    expect(topScrollInfo.target).not.toBeFalsy();
    // expect(topScrollInfo.detail).toEqual(topScrollResult);
    if(process.env.uniTestPlatformInfo.startsWith('web')){
      expect(topScrollInfo.timeStamp).toBeGreaterThan(0)
    }
  })

  it('Event scroll-horizontal',async()=>{
    // 横向滚动
Anne_LXM's avatar
Anne_LXM 已提交
62
    console.log('scrollLeft',await page.data('scrollLeft'))
63 64 65 66 67 68 69 70 71 72 73 74 75
    await page.setData({scrollLeft:220})
    await page.waitFor(600)
    //设置left 是否触发scroll 事件
    const leftScrollInfo = await page.data('scrollTest')
    // const leftScrollResult = {
    //   "scrollLeft": 220,
    //   "scrollTop": 0,
    //   "scrollHeight": 150,
    //   "scrollWidth": 1036,
    //   "deltaX": -100,
    //   "deltaY": 0
    // }
    const {scrollLeft,scrollTop,scrollHeight,scrollWidth,deltaX,deltaY} = leftScrollInfo.detail
Anne_LXM's avatar
Anne_LXM 已提交
76
    console.log('deltaX',deltaX)
77
    expect(leftScrollInfo.type).toBe('scroll')
Anne_LXM's avatar
Anne_LXM 已提交
78 79 80 81
    // Android 差异scrollLeft:219.80952
    if(!process.env.uniTestPlatformInfo.startsWith('android')){
      expect(scrollLeft).toBe(220)
    }
82 83 84 85 86 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
    expect(scrollTop).toBe(0)
    expect(scrollHeight).toBeGreaterThan(0)
    expect(scrollWidth).toBeGreaterThan(0)
    expect(deltaX).toBe(-100)
    expect(deltaY).toBe(0)
    expect(leftScrollInfo.currentTarget).not.toBeFalsy();
    expect(leftScrollInfo.target).not.toBeFalsy();
    if(process.env.uniTestPlatformInfo.startsWith('web')){
      expect(leftScrollInfo.timeStamp).toBeGreaterThan(0)
    }
  })

  it('Event scrolltolower-滚动到底部/右边',async()=>{
    // 滚动到底部scrollTop:300,
    await page.setData({scrollTop: 300})
    await page.waitFor(600)
    //设置top 是否触发scrolltolower事件
    const toLowerInfo = await page.data('toLowerTest')
    expect(toLowerInfo.type).toBe('scrolltolower')
    expect(toLowerInfo.detail.direction).toBe('bottom')
    expect(toLowerInfo.currentTarget).not.toBeFalsy();
    expect(toLowerInfo.target).not.toBeFalsy();
    if(process.env.uniTestPlatformInfo.startsWith('web')){
      expect(toLowerInfo.timeStamp).toBeGreaterThan(0)
    }
  })

  it('Event scrolltoupper-滚动到顶部/左边',async()=>{
    // 滚动到顶部scrollTop: 0,
    // await page.setData({scrollTop: 0})
    await page.callMethod('goTop')
    await page.waitFor(600)
    //设置top 是否触发scrolltoupper事件
    const toUpperInfo = await page.data('toUpperTest')
    expect(toUpperInfo.type).toBe('scrolltoupper')
    expect(toUpperInfo.detail.direction).toBe('top')
    expect(toUpperInfo.currentTarget).not.toBeFalsy();
    expect(toUpperInfo.target).not.toBeFalsy();
    if(process.env.uniTestPlatformInfo.startsWith('web')){
      expect(toUpperInfo.timeStamp).toBeGreaterThan(0)
    }
  })
124
});