get-current-pages.test.js 3.7 KB
Newer Older
1
const HOME_PAGE_PATH = '/pages/tabBar/component'
2
const PAGE_PATH = '/pages/API/get-current-pages/get-current-pages?test=123'
3 4
const platformInfo = process.env.uniTestPlatformInfo.toLocaleLowerCase()
const isAndroid = platformInfo.startsWith('android')
5
const isWeb = platformInfo.startsWith('web')
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28

describe('getCurrentPages', () => {
  let page
  it('getCurrentPages', async () => {
    // web 端等待应用首页加载完成
    if (process.env.uniTestPlatformInfo.startsWith('web')) {
      const waitTime = process.env.uniTestPlatformInfo.includes('safari') ?
        5000 :
        3000
      await new Promise((resolve) => {
        setTimeout(() => {
          resolve()
        }, waitTime)
      })
    }
    page = await program.switchTab(HOME_PAGE_PATH)
    await page.waitFor(1000)
    page = await program.navigateTo(PAGE_PATH)
    await page.waitFor(1000)
    await page.callMethod('_getCurrentPages')
    await page.waitFor(200)
    const data = await page.data()
    expect(data.checked).toBe(true)
29
  })
30 31 32 33

  if (process.env.uniTestPlatformInfo.startsWith('mp')) {
    return
  }
34 35 36 37 38 39 40
  it('page-style', async () => {
    await page.callMethod('getPageStyle')
    await page.waitFor(200)
    const isEnablePullDownRefresh1 = (await page.data()).currentPageStyle.enablePullDownRefresh
    expect(isEnablePullDownRefresh1).toBe(true)

    // setPageStyle
H
hdx 已提交
41 42 43
    await page.callMethod('setPageStyle', {
      enablePullDownRefresh: false
    })
44 45 46 47
    await page.waitFor(200)

    await page.callMethod('getPageStyle')
    await page.waitFor(200)
48 49
    const data2 = await page.data()
    const isEnablePullDownRefresh2 = data2.currentPageStyle.enablePullDownRefresh
50
    expect(isEnablePullDownRefresh2).toBe(false)
51 52 53 54

    await page.callMethod('startPullDownRefresh')
    await page.waitFor(500)
    const image2 = await program.screenshot({fullPage: true});
55 56 57
    expect(image2).toSaveImageSnapshot({customSnapshotIdentifier() {
      return 'get-current-pages-test-js-get-current-pages-page-style-before-set-page-style'
    }});
58 59

    await page.waitFor(3500)
H
hdx 已提交
60 61 62
    await page.callMethod('setPageStyle', {
      enablePullDownRefresh: true
    })
63 64 65 66
    await page.waitFor(200)
    await page.callMethod('startPullDownRefresh')
    await page.waitFor(500)
    const image3 = await program.screenshot({fullPage: true});
67 68 69
    expect(image3).toSaveImageSnapshot({customSnapshotIdentifier() {
      return 'get-current-pages-test-js-get-current-pages-page-style-after-set-page-style'
    }});
70 71 72 73 74 75 76 77 78 79 80 81

    // setPageStyle
    await page.callMethod('setPageStyle', {
      hideBottomNavigationIndicator: true,
      hideStatusBar: true
    })
    await page.waitFor(500)
    const image4 = await program.screenshot({fullPage: true});
    expect(image4).toSaveImageSnapshot({customSnapshotIdentifier() {
      return 'get-current-pages-test-hideStatusBar-hideBottomNavigationIndicator'
    }});

82
  })
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101
  it('$page', async () => {
    await page.setData({testing: true})
    const res = await page.callMethod('check$page')
    expect(res).toBe(true)
  })
  it('getParentPage', async () => {
    const res = await page.callMethod('checkGetParentPage')
    expect(res).toBe(true)
  })
  it('getDialogPages', async () => {
    const res = await page.callMethod('checkGetDialogPages')
    expect(res).toBe(true)
  })
  it('getElementById', async () => {
    const res = await page.callMethod('checkGetElementById')
    expect(res).toBe(true)
  })
  it('getAndroidView', async () => {
    const res = await page.callMethod('checkGetAndroidView')
102
    expect(res).toBe(isAndroid)
103
  })
104 105 106 107 108 109 110 111
  it('getIOSView', async () => {
    const res = await page.callMethod('checkGetIOSView')
    expect(res).toBe(false)
  })
  it('getHTMLElement', async () => {
    const res = await page.callMethod('checkGetHTMLElement')
    expect(res).toBe(isWeb)
  })
DCloud-WZF's avatar
DCloud-WZF 已提交
112
})