new-page-2.test.js 2.5 KB
Newer Older
DCloud-WZF's avatar
DCloud-WZF 已提交
1
const PAGE_PATH = '/pages/API/navigator/new-page/new-page-2'
DCloud-WZF's avatar
DCloud-WZF 已提交
2
const INTERMEDIATE_PAGE_PATH = '/pages/API/navigator/navigator'
DCloud-WZF's avatar
DCloud-WZF 已提交
3 4
let page
let lifeCycleNum
DCloud-WZF's avatar
DCloud-WZF 已提交
5

DCloud-WZF's avatar
DCloud-WZF 已提交
6 7
describe('app-lifecycle', () => {
  it('onLaunch onShow', async () => {
DCloud-WZF's avatar
DCloud-WZF 已提交
8
    page = await program.reLaunch(INTERMEDIATE_PAGE_PATH)
DCloud-WZF's avatar
DCloud-WZF 已提交
9
    await page.waitFor(1000)
DCloud-WZF's avatar
DCloud-WZF 已提交
10 11
    lifeCycleNum = await page.callMethod('getLifeCycleNum')
    expect(lifeCycleNum).toBe(1100)
DCloud-WZF's avatar
DCloud-WZF 已提交
12 13 14 15 16 17
  })
  it('onLastPageBackPress', async () => {
    page = await program.navigateBack()
    await page.waitFor(1000)
    lifeCycleNum = await page.callMethod('getLifeCycleNum')
    expect(lifeCycleNum).toBe(100)
DCloud-WZF's avatar
DCloud-WZF 已提交
18

DCloud-WZF's avatar
DCloud-WZF 已提交
19
    await page.callMethod('setLifeCycleNum', 0)
DCloud-WZF's avatar
DCloud-WZF 已提交
20
    lifeCycleNum = await page.callMethod('getLifeCycleNum')
DCloud-WZF's avatar
DCloud-WZF 已提交
21 22 23
    expect(lifeCycleNum).toBe(0)
  })
})
DCloud-WZF's avatar
DCloud-WZF 已提交
24

DCloud-WZF's avatar
DCloud-WZF 已提交
25 26
describe('page-lifecycle', () => {
  it('onLoad onShow onReady', async () => {
DCloud-WZF's avatar
DCloud-WZF 已提交
27 28 29 30 31
    page = await program.reLaunch(PAGE_PATH)
    await page.waitFor(1000)
    lifeCycleNum = await page.callMethod('getLifeCycleNum')
    expect(lifeCycleNum).toBe(120)
  })
DCloud-WZF's avatar
DCloud-WZF 已提交
32 33 34 35 36 37 38 39
  it('onPullDownRefresh', async () => {
    await page.callMethod('pullDownRefresh')
    await page.waitFor(1500)
    lifeCycleNum = await page.callMethod('getLifeCycleNum')
    expect(lifeCycleNum).toBe(130)
  })
  // TODO: pageScrollTo 无法触发 onReachBottom, 待修复后调整 lifeCycleNum
  it('onPageScroll onReachBottom', async () => {
DCloud-WZF's avatar
DCloud-WZF 已提交
40
    await program.pageScrollTo(2000)
DCloud-WZF's avatar
DCloud-WZF 已提交
41 42 43 44 45
    const data = await page.data()
    expect(data.isScrolled).toBe(true)
    lifeCycleNum = await page.callMethod('getLifeCycleNum')
    expect(lifeCycleNum).toBe(130)
  })
DCloud-WZF's avatar
DCloud-WZF 已提交
46 47
  it('onHide', async () => {
    page = await program.navigateTo(INTERMEDIATE_PAGE_PATH)
DCloud-WZF's avatar
DCloud-WZF 已提交
48
    await page.waitFor(1000)
DCloud-WZF's avatar
DCloud-WZF 已提交
49
    lifeCycleNum = await page.callMethod('getLifeCycleNum')
DCloud-WZF's avatar
DCloud-WZF 已提交
50
    expect(lifeCycleNum).toBe(120)
DCloud-WZF's avatar
DCloud-WZF 已提交
51
    page = await program.navigateBack()
DCloud-WZF's avatar
DCloud-WZF 已提交
52
    await page.waitFor(1000)
DCloud-WZF's avatar
DCloud-WZF 已提交
53
    lifeCycleNum = await page.callMethod('getLifeCycleNum')
DCloud-WZF's avatar
DCloud-WZF 已提交
54
    expect(lifeCycleNum).toBe(130)
DCloud-WZF's avatar
DCloud-WZF 已提交
55 56 57
  })
  it('onUnload', async () => {
    page = await program.redirectTo(INTERMEDIATE_PAGE_PATH)
DCloud-WZF's avatar
DCloud-WZF 已提交
58
    await page.waitFor(1000)
DCloud-WZF's avatar
DCloud-WZF 已提交
59
    lifeCycleNum = await page.callMethod('getLifeCycleNum')
DCloud-WZF's avatar
DCloud-WZF 已提交
60
    expect(lifeCycleNum).toBe(30)
DCloud-WZF's avatar
DCloud-WZF 已提交
61 62 63
  })
  it('onBackPress', async () => {
    page = await program.navigateTo(PAGE_PATH)
DCloud-WZF's avatar
DCloud-WZF 已提交
64
    await page.waitFor(1000)
DCloud-WZF's avatar
DCloud-WZF 已提交
65
    lifeCycleNum = await page.callMethod('getLifeCycleNum')
DCloud-WZF's avatar
DCloud-WZF 已提交
66
    expect(lifeCycleNum).toBe(150)
DCloud-WZF's avatar
DCloud-WZF 已提交
67
    page = await program.navigateBack()
DCloud-WZF's avatar
DCloud-WZF 已提交
68
    await page.waitFor(1000)
DCloud-WZF's avatar
DCloud-WZF 已提交
69
    lifeCycleNum = await page.callMethod('getLifeCycleNum')
DCloud-WZF's avatar
DCloud-WZF 已提交
70 71
    expect(lifeCycleNum).toBe(40)
    await page.callMethod('setLifeCycleNum', 0)
DCloud-WZF's avatar
DCloud-WZF 已提交
72 73
  })
})