page.test.js 2.9 KB
Newer Older
DCloud-WZF's avatar
DCloud-WZF 已提交
1 2 3 4 5 6 7 8
const PAGE_PATH = '/pages/lifecycle/page/page'
const HOME_PATH = '/pages/index'
let page
let lifeCycleNum

describe('app-lifecycle', () => {
  it('onLaunch onShow', async () => {
    page = await program.reLaunch(HOME_PATH)
9
    await page.waitFor(700)
DCloud-WZF's avatar
DCloud-WZF 已提交
10 11 12
    lifeCycleNum = await page.callMethod('getLifeCycleNum')
    expect(lifeCycleNum).toBe(1100)
  })
13
  it('onLastPageBackPress', async () => {
14
    page = await program.navigateBack()
15
    await page.waitFor(700)
DCloud-WZF's avatar
DCloud-WZF 已提交
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
    lifeCycleNum = await page.callMethod('getLifeCycleNum')
    expect(lifeCycleNum).toBe(100)

    await page.callMethod('setLifeCycleNum', 0)
    lifeCycleNum = await page.callMethod('getLifeCycleNum')
    expect(lifeCycleNum).toBe(0)
  })
})

describe('page-lifecycle', () => {
  afterAll(async () => {
    const resetLifecycleNum = 1100
    await page.callMethod('setLifeCycleNum', resetLifecycleNum)
    lifeCycleNum = await page.callMethod('getLifeCycleNum')
    expect(lifeCycleNum).toBe(resetLifecycleNum)
  })

  it('onLoad onShow onReady', async () => {
    page = await program.reLaunch(PAGE_PATH)
35
    await page.waitFor(700)
DCloud-WZF's avatar
DCloud-WZF 已提交
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
    lifeCycleNum = await page.callMethod('getLifeCycleNum')
    expect(lifeCycleNum).toBe(120)
    await page.callMethod('setLifeCycleNum', 0)
  })
  it('onPullDownRefresh', async () => {
    await page.callMethod('pullDownRefresh')
    await page.waitFor(1500)
    lifeCycleNum = await page.callMethod('getLifeCycleNum')
    expect(lifeCycleNum).toBe(10)
    await page.callMethod('setLifeCycleNum', 0)
  })
  it('onPageScroll onReachBottom', async () => {
    await program.pageScrollTo(2000)
    const data = await page.data()
    expect(data.isScrolled).toBe(true)
    lifeCycleNum = await page.callMethod('getLifeCycleNum')
    expect(lifeCycleNum).toBe(10)
    await page.callMethod('setLifeCycleNum', 0)
  })
  it('onHide', async () => {
    page = await program.navigateTo(HOME_PATH)
57
    await page.waitFor('view')
DCloud-WZF's avatar
DCloud-WZF 已提交
58 59 60
    lifeCycleNum = await page.callMethod('getLifeCycleNum')
    expect(lifeCycleNum).toBe(-10)
    page = await program.navigateBack()
61
    await page.waitFor('view')
DCloud-WZF's avatar
DCloud-WZF 已提交
62 63 64 65 66
    lifeCycleNum = await page.callMethod('getLifeCycleNum')
    expect(lifeCycleNum).toBe(0)
  })
  it('onUnload', async () => {
    page = await program.redirectTo(HOME_PATH)
67
    await page.waitFor(700)
DCloud-WZF's avatar
DCloud-WZF 已提交
68 69 70 71 72 73
    lifeCycleNum = await page.callMethod('getLifeCycleNum')
    expect(lifeCycleNum).toBe(-100)
    await page.callMethod('setLifeCycleNum', 0)
  })
  it('onBackPress', async () => {
    page = await program.navigateTo(PAGE_PATH)
74
    await page.waitFor(700)
DCloud-WZF's avatar
DCloud-WZF 已提交
75 76 77
    lifeCycleNum = await page.callMethod('getLifeCycleNum')
    expect(lifeCycleNum).toBe(120)
    page = await program.navigateBack()
78
    await page.waitFor('view')
DCloud-WZF's avatar
DCloud-WZF 已提交
79 80 81 82 83
    lifeCycleNum = await page.callMethod('getLifeCycleNum')
    expect(lifeCycleNum).toBe(10)
    await page.callMethod('setLifeCycleNum', 0)
  })
})