scroll-view-refresher.test.js 2.0 KB
Newer Older
1 2
// uni-app自动化测试教程: uni-app自动化测试教程: https://uniapp.dcloud.net.cn/worktile/auto/hbuilderx-extension/

雪洛's avatar
雪洛 已提交
3 4 5 6 7 8 9 10 11 12 13
describe('component-native-scroll-view-refresher', () => {
  if (!process.env.uniTestPlatformInfo.startsWith('android') && !process.env.uniTestPlatformInfo.startsWith('web') || process.env.UNI_AUTOMATOR_APP_WEBVIEW) {
    it('other platform', () => {
      expect(1).toBe(1)
    })
    return
  }
  let page;
  beforeAll(async () => {
    page = await program.reLaunch('/pages/component/scroll-view/scroll-view-refresher');
    await page.waitFor(300);
14 15 16 17 18 19 20 21 22
  });

  async function eventCheck(dataName,typeName){
    const eventInfo = await page.data(dataName)
    expect(eventInfo.type).toBe(typeName)
    expect(eventInfo.currentTarget).not.toBeFalsy();
    expect(eventInfo.target).not.toBeFalsy();
    expect(eventInfo.detail.dy).toBeGreaterThan(0)
  }
23

雪洛's avatar
雪洛 已提交
24 25 26 27
  it('scroll-view-refresher-screenshot', async () => {
    //禁止滚动条
    await page.setData({
        showScrollbar: false
28
    })
雪洛's avatar
雪洛 已提交
29 30 31 32
    await page.waitFor(300);
    const image = await program.screenshot({fullPage: true});
    expect(image).toSaveImageSnapshot();
  })
33

34
  it('check_refresher_refresh_event', async () => {
雪洛's avatar
雪洛 已提交
35 36
    await page.setData({
      refresherTriggered: true
37
    })
38
    await page.waitFor(2000);
39 40 41 42 43 44 45 46
    expect(await page.data('refresherrefreshTimes')).toBe(1)
    // 手动设置下拉刷新状态refresher-triggered为true时,在web和iOS不触发@refresherpulling事件
    if(process.env.uniTestPlatformInfo.startsWith('android')){
      await eventCheck('onRefresherpullingTest','refresherpulling')
    }
    await eventCheck('refresherrefreshTest','refresherrefresh')
    await page.waitFor(1000);
    await eventCheck('onRefresherrestoreTest','refresherrestore')
雪洛's avatar
雪洛 已提交
47 48 49 50 51 52 53 54 55 56
  });

  it('check_refresher_snapshot', async () => {
    await page.setData({
      refresherTriggered: true
    })
    await page.waitFor(300);
    const image = await program.screenshot({fullPage: true});
    expect(image).toSaveImageSnapshot();
  });
57
});