waterflow.test.js 4.3 KB
Newer Older
shutao-dc's avatar
shutao-dc 已提交
1 2 3
const platformInfo = process.env.uniTestPlatformInfo.toLocaleLowerCase()
const isMP = platformInfo.startsWith('mp')

shutao-dc's avatar
shutao-dc 已提交
4
describe('component-native-waterflow', () => {
5
  if (isMP || platformInfo.indexOf('web') > -1) {
shutao-dc's avatar
shutao-dc 已提交
6 7 8 9 10 11 12 13
  	it('skip mp', () => {
  		expect(1).toBe(1)
  	})
  	return
  }

  let page
  beforeAll(async () => {
shutao-dc's avatar
shutao-dc 已提交
14 15
    //打开waterflow测试页
    page = await program.reLaunch('/pages/component/waterflow/waterflow')
shutao-dc's avatar
shutao-dc 已提交
16
    await page.waitFor(600)
17
  })
shutao-dc's avatar
shutao-dc 已提交
18 19 20 21 22

  //检测竖向scrolltop属性赋值
  it('check_scroll_top', async () => {
    await page.callMethod('confirm_scroll_top_input', 600)
    await page.waitFor(600)
shutao-dc's avatar
shutao-dc 已提交
23
    const listElement = await page.$('#waterflow')
shutao-dc's avatar
shutao-dc 已提交
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65
    const scrollTop = await listElement.attribute("scrollTop")
    console.log("check_scroll_top---"+scrollTop)
    expect(scrollTop-600).toBeGreaterThanOrEqual(0)
  })

  it('Event check_scroll', async () => {
    await page.callMethod('confirm_scroll_top_input', 300)
    await page.waitFor(600)
    const scrollDetail = await page.data('scrollDetailTest')
    // console.log('scrollDetailTest:', scrollDetail)
    expect(scrollDetail.scrollLeft).toBe(0)
    // scrollTop和deltaY 在安卓端差异 299.8095
    expect([300, 299.8095]).toContain(scrollDetail.scrollTop);
    expect(scrollDetail.scrollHeight).toBeGreaterThan(0)
    expect(scrollDetail.scrollWidth).toBeGreaterThan(0)
    expect(scrollDetail.deltaX).toBe(0)
    //此处可判断安卓issues:9121的问题
    expect([300.1905, 300, 299.8095]).toContain(scrollDetail.deltaY);
    expect(await page.data('isScrollTest')).toBe('scroll:Success')
  })

  it('Event scrolltolower-滚动到底部/右边',async()=>{
    // 滚动到底部,是否触发scrolltolower事件
    await page.callMethod('confirm_scroll_top_input', 2500)
    await page.waitFor(600)
    expect(await page.data('isScrolltolowerTest')).toBe('scrolltolower:Success-bottom')
  })

  it('Event scrolltoupper-滚动到顶部/左边',async()=>{
    // 滚动到顶部50,是否触发scrolltoupper事件
    await page.callMethod('confirm_scroll_top_input', 50)
    await page.waitFor(1000)
    expect(await page.data('isScrolltoupperTest')).toBe('scrolltoupper:Success-top')
  })

  it('Event scrollend-滚动结束时触发',async()=>{
    // 仅App端支持,向上滑动页面
    await program.swipe({
      startPoint: { x: 100, y: 300 },
      endPoint: { x: 100, y: 100 },
      duration: 100
    })
66
    await page.waitFor(1200)
shutao-dc's avatar
shutao-dc 已提交
67
    const endDetail = await page.data('scrollEndDetailTest')
68
    console.log('scrollEndDetailTest:', endDetail)
shutao-dc's avatar
shutao-dc 已提交
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83
    expect(endDetail.deltaY).toBe(0)
    expect(endDetail.deltaX).toBe(0)
    expect(endDetail.scrollLeft).toBe(0)
    expect(endDetail.scrollTop).toBeGreaterThan(0)
    expect(endDetail.scrollHeight).toBeGreaterThan(0)
    expect(endDetail.scrollWidth).toBeGreaterThan(0)
  })

  //检测竖向可滚动区域
  it('check_scroll_height', async () => {
    await page.waitFor(600)
    const value = await page.callMethod('check_scroll_height')
    expect(value).toBe(true)
  })

84
  //检测下拉刷新 备注:iOS本地测试结果正确,但是自动化测试结果错误
shutao-dc's avatar
shutao-dc 已提交
85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100
  it('check_refresher', async () => {
    await page.callMethod('confirm_scroll_top_input', 0)
    await page.setData({
        refresher_enabled_boolean: true,
        refresher_triggered_boolean: true
    })
    await page.waitFor(2000)
    expect(await page.data('refresherrefresh')).toBe(true)
    //延迟 等待下拉刷新执行结束 防止后续测试任务结果异常
    await page.waitFor(1000)
  })

  //检测竖向scroll_into_view属性赋值 备注:iOS本地测试结果正确,但是自动化测试结果错误
  it('check_scroll_into_view_top', async () => {
    await page.callMethod('setScrollIntoView', 'item---3')
    await page.waitFor(600)
shutao-dc's avatar
shutao-dc 已提交
101 102
    const waterflowElement = await page.$('#waterflow')
    const scrollTop = await waterflowElement.attribute("scrollTop")
shutao-dc's avatar
shutao-dc 已提交
103 104 105 106 107
    console.log("check_scroll_into_view_top--"+scrollTop)
    await page.callMethod('setScrollIntoView', 'item---0')
    expect(scrollTop-280).toBeGreaterThanOrEqual(0)
  })

shutao-dc's avatar
shutao-dc 已提交
108 109 110
  //检测waterflow属性变化 截图校验
  it('check_waterflow_view_props', async () => {
    await page.callMethod('testModifyWaterflowProps')
shutao-dc's avatar
shutao-dc 已提交
111 112 113 114 115
    await page.waitFor(600)
    const image = await program.screenshot({fullPage: false});
    expect(image).toSaveImageSnapshot();
  })
})