list-view.test.js 6.6 KB
Newer Older
雪洛's avatar
雪洛 已提交
1
describe('component-native-list-view', () => {
shutao-dc's avatar
shutao-dc 已提交
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
  let page
  beforeAll(async () => {
    //打开list-view测试页
    page = await program.reLaunch('/pages/component/list-view/list-view')
    await page.waitFor(600)
  })

  //检测竖向scrolltop属性赋值
  it('check_scroll_top', async () => {
    await page.callMethod('confirm_scroll_top_input', 600)
    await page.waitFor(600)
    const listElement = await page.$('#listview')
    const scrollTop = await listElement.attribute("scrollTop")
    console.log("check_scroll_top---"+scrollTop)
    expect(scrollTop-600).toBeGreaterThanOrEqual(0)
  })

雪洛's avatar
雪洛 已提交
19

lizhongyi_'s avatar
lizhongyi_ 已提交
20
  //检测横向scrollLeft属性赋值 备注:iOS不支持list-view横向滚动
雪洛's avatar
雪洛 已提交
21
  it('check_scroll_left', async () => {
22 23 24 25 26
    if(await page.data('scroll_x_boolean') === false) {
        await page.callMethod('change_scroll_x_boolean', true)
        await page.callMethod('change_scroll_y_boolean', false)
        await page.waitFor(600)
    }
雪洛's avatar
雪洛 已提交
27
    await page.callMethod('confirm_scroll_left_input', 600)
shutao-dc's avatar
shutao-dc 已提交
28 29
    await page.waitFor(600)
    const listElement = await page.$('#listview')
雪洛's avatar
雪洛 已提交
30 31 32
    const scrollLeft = await listElement.attribute("scrollLeft")
    console.log("check_scroll_left---"+scrollLeft)
    expect(scrollLeft-600).toBeGreaterThanOrEqual(0)
shutao-dc's avatar
shutao-dc 已提交
33 34
  })

35 36 37 38 39 40 41 42 43
  it('Event check_scroll', async () => {
    await page.callMethod('change_scroll_y_boolean', true)
    await page.callMethod('change_scroll_x_boolean', false)
    await page.waitFor(600)
    await page.callMethod('confirm_scroll_top_input', 300)
    await page.waitFor(600)
    // 在web端scroll事件event参数中detail类型报错,先忽略测试
    if(!process.env.UNI_UTS_PLATFORM.startsWith('web')){
      const scrollDetail = await page.data('scrollDetailTest')
44
      console.log('scrollDetailTest:', scrollDetail)
45
      expect(scrollDetail.scrollLeft).toBe(0)
46 47
      // 在安卓端差异 299.8095
      expect([300, 299.8095]).toContain(scrollDetail.scrollTop);
48 49 50 51 52 53
      expect(scrollDetail.scrollHeight).toBeGreaterThan(0)
      // 在安卓端 "scrollWidth":0
      if(!process.env.UNI_UTS_PLATFORM.startsWith('app-android')){
        expect(scrollDetail.scrollWidth).toBeGreaterThan(0)
      }
      expect(scrollDetail.deltaX).toBe(0)
54 55
      // 在安卓端差异 299.8095
      expect([300, 299.8095]).toContain(scrollDetail.deltaY);
56 57 58 59 60 61 62 63 64 65 66 67 68
    }
    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事件
69
    await page.callMethod('confirm_scroll_top_input', 50)
Anne_LXM's avatar
Anne_LXM 已提交
70
    await page.waitFor(2000)
71 72 73
    expect(await page.data('isScrolltoupperTest')).toBe('scrolltoupper:Success-top')
  })

雪洛's avatar
雪洛 已提交
74 75 76
  if (process.env.uniTestPlatformInfo.indexOf('web') > -1) {
    return
  }
lizhongyi_'s avatar
lizhongyi_ 已提交
77

lizhongyi_'s avatar
lizhongyi_ 已提交
78 79 80 81
  if(process.env.uniTestPlatformInfo.toLowerCase().startsWith('ios')) {
    return
  }

82
  it('Event scrollend-滚动结束时触发',async()=>{
83
    // 仅App端支持,向上滑动页面
84
    await program.swipe({
85 86
      startPoint: { x: 100, y: 300 },
      endPoint: { x: 100, y: 100 },
lizhongyi_'s avatar
lizhongyi_ 已提交
87
      duration: 100
88 89 90
    })
    await page.waitFor(600)
    const endDetail = await page.data('scrollEndDetailTest')
91
    console.log('scrollEndDetailTest:', endDetail)
92 93 94 95 96 97
    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)
    // 在安卓端 "scrollWidth":0
shutao-dc's avatar
shutao-dc 已提交
98
    // expect(endDetail.scrollWidth).toBeGreaterThan(0)
99
  })
lizhongyi_'s avatar
lizhongyi_ 已提交
100 101 102 103 104 105 106 107 108

  //检测竖向可滚动区域
  it('check_scroll_height', async () => {
    await page.callMethod('change_scroll_y_boolean', true)
    await page.callMethod('change_scroll_x_boolean', false)
    await page.waitFor(600)
    const value = await page.callMethod('check_scroll_height')
    expect(value).toBe(true)
  })
lizhongyi_'s avatar
lizhongyi_ 已提交
109

lizhongyi_'s avatar
lizhongyi_ 已提交
110
  //检测横向可滚动区域 备注:iOS不支持list-view横向滚动
shutao-dc's avatar
shutao-dc 已提交
111
  it('check_scroll_width', async () => {
112 113 114 115 116
    if(await page.data('scroll_x_boolean') === false) {
        await page.callMethod('change_scroll_x_boolean', true)
        await page.callMethod('change_scroll_y_boolean', false)
        await page.waitFor(600)
    }
shutao-dc's avatar
shutao-dc 已提交
117 118 119 120 121 122 123
    await page.callMethod('change_scroll_y_boolean', false)
    await page.callMethod('change_scroll_x_boolean', true)
    await page.waitFor(600)
    const value = await page.callMethod('check_scroll_width')
    expect(value).toBe(true)
  })

lizhongyi_'s avatar
lizhongyi_ 已提交
124
  //检测下拉刷新 备注:iOS本地测试结果正确,但是自动化测试结果错误
雪洛's avatar
雪洛 已提交
125
  it('check_refresher', async () => {
126 127 128 129 130
    if(await page.data('scroll_y_boolean') === false) {
        await page.callMethod('change_scroll_y_boolean', true)
        await page.callMethod('change_scroll_x_boolean', false)
        await page.waitFor(600)
    }
雪洛's avatar
雪洛 已提交
131 132 133 134 135 136 137 138
    await page.setData({
        refresher_enabled_boolean: true,
        refresher_triggered_boolean: true
    })
    await page.waitFor(2000)
    expect(await page.data('refresherrefresh')).toBe(true)
  })

lizhongyi_'s avatar
lizhongyi_ 已提交
139
  //检测竖向scroll_into_view属性赋值 备注:iOS本地测试结果正确,但是自动化测试结果错误
雪洛's avatar
雪洛 已提交
140
  it('check_scroll_into_view_top', async () => {
141 142 143 144 145
    if(await page.data('scroll_y_boolean') === false) {
        await page.callMethod('change_scroll_y_boolean', true)
        await page.callMethod('change_scroll_x_boolean', false)
        await page.waitFor(600)
    }
雪洛's avatar
雪洛 已提交
146
    await page.callMethod('item_change_size_enum', 3)
shutao-dc's avatar
shutao-dc 已提交
147 148
    await page.waitFor(600)
    const listElement = await page.$('#listview')
雪洛's avatar
雪洛 已提交
149 150 151 152
    const scrollTop = await listElement.attribute("scrollTop")
    console.log("check_scroll_into_view_top--"+scrollTop)
    await page.callMethod('item_change_size_enum', 0)
    expect(scrollTop-690).toBeGreaterThanOrEqual(0)
shutao-dc's avatar
shutao-dc 已提交
153 154
  })

lizhongyi_'s avatar
lizhongyi_ 已提交
155
  //检测横向scroll_into_view属性赋值 备注:iOS不支持list-view横向滚动
shutao-dc's avatar
shutao-dc 已提交
156
  it('check_scroll_into_view_left', async () => {
157 158 159 160 161
    if(await page.data('scroll_x_boolean') === false) {
        await page.callMethod('change_scroll_x_boolean', true)
        await page.callMethod('change_scroll_y_boolean', false)
        await page.waitFor(600)
    }
shutao-dc's avatar
shutao-dc 已提交
162 163 164 165 166 167 168
    await page.callMethod('item_change_size_enum', 3)
    await page.waitFor(600)
    const listElement = await page.$('#listview')
    const scrollLeft = await listElement.attribute("scrollLeft")
    console.log("check_scroll_into_view_left--"+scrollLeft)
    await page.callMethod('item_change_size_enum', 0)
    expect(scrollLeft-1080).toBeGreaterThanOrEqual(0)
雪洛's avatar
雪洛 已提交
169
  })
shutao-dc's avatar
shutao-dc 已提交
170
})