scroll-view.test.js 4.0 KB
Newer Older
1 2 3 4 5 6
jest.setTimeout(30000);
const platformInfo = process.env.uniTestPlatformInfo.toLocaleLowerCase()
const isAndroid = platformInfo.startsWith('android')
const isIos = platformInfo.startsWith('ios')
const isMP = platformInfo.startsWith('mp')
const isWeb = platformInfo.startsWith('web')
7
describe('component-native-scroll-view', () => {
8 9 10
  let page;
  beforeAll(async () => {
    page = await program.reLaunch('/pages/component/scroll-view/scroll-view');
11
    await page.waitFor("view");
12
  });
13 14 15 16

  it('Event scroll-vertical',async()=>{
    // 纵向滚动
    await page.setData({scrollTop: 100})
17
    await page.waitFor(1000)
18 19
    // 设置top 是否触发scroll 事件
    const topScrollDetail = await page.data('scrollDetailTest')
20
    console.log('topScrollDetail:', topScrollDetail)
21
    expect(topScrollDetail.scrollLeft).toBe(0)
22 23 24
    // Android 差异scrollTop:99.809525
    expect(topScrollDetail.scrollTop).toBeGreaterThan(99.5)
    //expect([100, 99.809525]).toContain(topScrollDetail.scrollTop);
25 26 27 28
    expect(topScrollDetail.scrollHeight).toBeGreaterThan(0)
    expect(topScrollDetail.scrollWidth).toBeGreaterThan(0)
    expect(topScrollDetail.deltaX).toBe(0)
    expect(topScrollDetail.deltaY).not.toBe(0)
29
    expect(await page.data('isScrollTest')).toBe('scroll:Success')
30 31 32 33 34
  })

  it('Event scroll-horizontal',async()=>{
    // 横向滚动
    await page.setData({scrollLeft:220})
35
    await page.waitFor(1000)
36 37
    //设置left 是否触发scroll 事件
    const leftScrollDetail = await page.data('scrollDetailTest')
38
    console.log('leftScrollDetail:', leftScrollDetail)
39 40 41
    // Android 差异scrollLeft:219.80952
    expect(leftScrollDetail.scrollLeft).toBeGreaterThan(219.5)
    //expect([220, 219.80952]).toContain(leftScrollDetail.scrollLeft);
42 43 44
    expect(leftScrollDetail.scrollTop).toBe(0)
    expect(leftScrollDetail.scrollHeight).toBeGreaterThan(0)
    expect(leftScrollDetail.scrollWidth).toBeGreaterThan(0)
45 46 47
    // 在安卓差异 -99.809525
    expect(leftScrollDetail.deltaX).toBeLessThan(-99.5)
    //expect([-100, -99.809525]).toContain(leftScrollDetail.deltaX);
48
    expect(leftScrollDetail.deltaY).toBe(0)
49
    expect(await page.data('isScrollTest')).toBe('scroll:Success')
50 51
  })

52 53 54 55 56 57 58 59 60 61 62
  // 移后:此测试用例在某些mac-chrome会影响scroll-horizontal的deltaX结果
  it('scroll-view-screenshot', async () => {
    //禁止滚动条
    await page.setData({
        showScrollbar: false
    })
    await page.waitFor(300);
    const image = await program.screenshot({fullPage: true});
    expect(image).toSaveImageSnapshot();
  });

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

  it('Event scrolltoupper-滚动到顶部/左边',async()=>{
71 72 73
    // 滚动到顶部scrollTop: 0,是否触发scrolltoupper事件
    await page.setData({scrollTop: 0})
    // await page.callMethod('goTop')
74
    await page.waitFor(600)
75
    expect(await page.data('isScrolltoupperTest')).toBe('scrolltoupper:Success-top')
76
  })
77

78
  if(!isWeb && !isMP){
79 80
    it('Event scrollend-滚动结束时触发仅App端支持',async()=>{
      const endDetail = await page.data('scrollEndDetailTest')
81
      console.log('scrollEndDetailTest:', endDetail)
82 83 84 85 86 87 88 89
      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)
    })
  }
90

91 92 93 94 95 96 97 98 99
  if(!isMP) {
    it('通过UniElement.scrollBy检测scroll事件是否触发',async()=>{
      await page.callMethod('setVerticalScrollBy', 120)
      await page.waitFor(600)
      const scrollDetail = await page.data('scrollDetailTest')
      console.log('setVerticalScrollBy scrollDetail:', scrollDetail)
      expect(scrollDetail.scrollTop).toBeGreaterThan(119)
    })
  }
100
});