list-view.test.js 6.8 KB
Newer Older
DCloud-WZF's avatar
DCloud-WZF 已提交
1 2 3 4 5 6 7 8 9 10 11 12
const platformInfo = process.env.uniTestPlatformInfo.toLocaleLowerCase()
const isMP = platformInfo.startsWith('mp')

describe('component-native-list-view', () => {
  if (isMP) {
  	it('skip mp', () => {
  		expect(1).toBe(1)
  	})
  	return
  }

  let page
shutao-dc's avatar
shutao-dc 已提交
13
  beforeAll(async () => {
DCloud-WZF's avatar
DCloud-WZF 已提交
14 15 16
    //打开list-view测试页
    page = await program.reLaunch('/pages/component/list-view/list-view')
    await page.waitFor(600)
shutao-dc's avatar
shutao-dc 已提交
17 18 19 20 21 22 23 24 25 26 27 28
  })

  //检测竖向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
雪洛 已提交
29

lizhongyi_'s avatar
lizhongyi_ 已提交
30
  //检测横向scrollLeft属性赋值 备注:iOS不支持list-view横向滚动
雪洛's avatar
雪洛 已提交
31
  it('check_scroll_left', async () => {
32 33 34 35 36
    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
雪洛 已提交
37
    await page.callMethod('confirm_scroll_left_input', 600)
shutao-dc's avatar
shutao-dc 已提交
38 39
    await page.waitFor(600)
    const listElement = await page.$('#listview')
雪洛's avatar
雪洛 已提交
40 41 42
    const scrollLeft = await listElement.attribute("scrollLeft")
    console.log("check_scroll_left---"+scrollLeft)
    expect(scrollLeft-600).toBeGreaterThanOrEqual(0)
shutao-dc's avatar
shutao-dc 已提交
43 44
  })

45 46 47 48 49 50
  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)
51 52 53
    const scrollDetail = await page.data('scrollDetailTest')
    // console.log('scrollDetailTest:', scrollDetail)
    expect(scrollDetail.scrollLeft).toBe(0)
54 55 56
    // scrollTop和deltaY 在安卓端差异 299.8095
    expect(scrollDetail.scrollTop).toBeGreaterThan(299.5)
    //expect([300, 299.8095]).toContain(scrollDetail.scrollTop);
57 58
    expect(scrollDetail.scrollHeight).toBeGreaterThan(0)
    expect(scrollDetail.scrollWidth).toBeGreaterThan(0)
DCloud-WZF's avatar
DCloud-WZF 已提交
59
    expect(scrollDetail.deltaX).toBe(0)
60 61 62
    //此处可判断安卓issues:9121的问题
    expect(scrollDetail.deltaY).toBeGreaterThan(299.5)
    //expect([300.1905, 300, 299.8095]).toContain(scrollDetail.deltaY);
63 64 65 66 67 68 69 70 71 72 73 74 75
    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)
Anne_LXM's avatar
Anne_LXM 已提交
76
    await page.waitFor(1000)
77 78 79
    expect(await page.data('isScrolltoupperTest')).toBe('scrolltoupper:Success-top')
  })

雪洛's avatar
雪洛 已提交
80 81 82
  if (process.env.uniTestPlatformInfo.indexOf('web') > -1) {
    return
  }
lizhongyi_'s avatar
lizhongyi_ 已提交
83

lizhongyi_'s avatar
lizhongyi_ 已提交
84 85 86 87
  if(process.env.uniTestPlatformInfo.toLowerCase().startsWith('ios')) {
    return
  }

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

  //检测竖向可滚动区域
  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_ 已提交
114

lizhongyi_'s avatar
lizhongyi_ 已提交
115
  //检测横向可滚动区域 备注:iOS不支持list-view横向滚动
shutao-dc's avatar
shutao-dc 已提交
116
  it('check_scroll_width', async () => {
117 118 119 120 121
    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 已提交
122 123 124 125 126 127 128
    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_ 已提交
129
  //检测下拉刷新 备注:iOS本地测试结果正确,但是自动化测试结果错误
雪洛's avatar
雪洛 已提交
130
  it('check_refresher', async () => {
131 132 133 134 135
    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
雪洛 已提交
136 137 138 139 140 141
    await page.setData({
        refresher_enabled_boolean: true,
        refresher_triggered_boolean: true
    })
    await page.waitFor(2000)
    expect(await page.data('refresherrefresh')).toBe(true)
shutao-dc's avatar
shutao-dc 已提交
142 143
    //延迟 等待下拉刷新执行结束 防止后续测试任务结果异常
    await page.waitFor(1000)
雪洛's avatar
雪洛 已提交
144 145
  })

lizhongyi_'s avatar
lizhongyi_ 已提交
146
  //检测竖向scroll_into_view属性赋值 备注:iOS本地测试结果正确,但是自动化测试结果错误
雪洛's avatar
雪洛 已提交
147
  it('check_scroll_into_view_top', async () => {
148 149 150 151 152
    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
雪洛 已提交
153
    await page.callMethod('item_change_size_enum', 3)
shutao-dc's avatar
shutao-dc 已提交
154 155
    await page.waitFor(600)
    const listElement = await page.$('#listview')
雪洛's avatar
雪洛 已提交
156 157 158 159
    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 已提交
160 161
  })

lizhongyi_'s avatar
lizhongyi_ 已提交
162
  //检测横向scroll_into_view属性赋值 备注:iOS不支持list-view横向滚动
shutao-dc's avatar
shutao-dc 已提交
163
  it('check_scroll_into_view_left', async () => {
164 165 166 167 168
    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 已提交
169
    await page.callMethod('setScrollIntoView', "item---3")
shutao-dc's avatar
shutao-dc 已提交
170 171 172 173
    await page.waitFor(600)
    const listElement = await page.$('#listview')
    const scrollLeft = await listElement.attribute("scrollLeft")
    console.log("check_scroll_into_view_left--"+scrollLeft)
shutao-dc's avatar
shutao-dc 已提交
174
    await page.callMethod('setScrollIntoView', "item---0")
shutao-dc's avatar
shutao-dc 已提交
175
    expect(scrollLeft-1080).toBeGreaterThanOrEqual(0)
176
  })
shutao-dc's avatar
shutao-dc 已提交
177
})