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
  it('onPullDownRefresh', async () => {
    await page.callMethod('pullDownRefresh')
    await page.waitFor(1500)
    lifeCycleNum = await page.callMethod('getLifeCycleNum')
    expect(lifeCycleNum).toBe(130)
  })
  it('onPageScroll onReachBottom', async () => {
DCloud-WZF's avatar
DCloud-WZF 已提交
39
    await program.pageScrollTo(2000)
DCloud-WZF's avatar
DCloud-WZF 已提交
40 41 42
    const data = await page.data()
    expect(data.isScrolled).toBe(true)
    lifeCycleNum = await page.callMethod('getLifeCycleNum')
DCloud-WZF's avatar
DCloud-WZF 已提交
43
    expect(lifeCycleNum).toBe(140)
DCloud-WZF's avatar
DCloud-WZF 已提交
44
  })
DCloud-WZF's avatar
DCloud-WZF 已提交
45 46
  it('onHide', async () => {
    page = await program.navigateTo(INTERMEDIATE_PAGE_PATH)
DCloud-WZF's avatar
DCloud-WZF 已提交
47
    await page.waitFor(1000)
DCloud-WZF's avatar
DCloud-WZF 已提交
48
    lifeCycleNum = await page.callMethod('getLifeCycleNum')
DCloud-WZF's avatar
DCloud-WZF 已提交
49
    expect(lifeCycleNum).toBe(130)
DCloud-WZF's avatar
DCloud-WZF 已提交
50
    page = await program.navigateBack()
DCloud-WZF's avatar
DCloud-WZF 已提交
51
    await page.waitFor(1000)
DCloud-WZF's avatar
DCloud-WZF 已提交
52
    lifeCycleNum = await page.callMethod('getLifeCycleNum')
DCloud-WZF's avatar
DCloud-WZF 已提交
53
    expect(lifeCycleNum).toBe(140)
DCloud-WZF's avatar
DCloud-WZF 已提交
54 55 56
  })
  it('onUnload', async () => {
    page = await program.redirectTo(INTERMEDIATE_PAGE_PATH)
DCloud-WZF's avatar
DCloud-WZF 已提交
57
    await page.waitFor(1000)
DCloud-WZF's avatar
DCloud-WZF 已提交
58
    lifeCycleNum = await page.callMethod('getLifeCycleNum')
DCloud-WZF's avatar
DCloud-WZF 已提交
59
    expect(lifeCycleNum).toBe(40)
DCloud-WZF's avatar
DCloud-WZF 已提交
60 61 62
  })
  it('onBackPress', async () => {
    page = await program.navigateTo(PAGE_PATH)
DCloud-WZF's avatar
DCloud-WZF 已提交
63
    await page.waitFor(1000)
DCloud-WZF's avatar
DCloud-WZF 已提交
64
    lifeCycleNum = await page.callMethod('getLifeCycleNum')
DCloud-WZF's avatar
DCloud-WZF 已提交
65
    expect(lifeCycleNum).toBe(160)
DCloud-WZF's avatar
DCloud-WZF 已提交
66
    page = await program.navigateBack()
DCloud-WZF's avatar
DCloud-WZF 已提交
67
    await page.waitFor(1000)
DCloud-WZF's avatar
DCloud-WZF 已提交
68
    lifeCycleNum = await page.callMethod('getLifeCycleNum')
DCloud-WZF's avatar
DCloud-WZF 已提交
69
    expect(lifeCycleNum).toBe(50)
DCloud-WZF's avatar
DCloud-WZF 已提交
70
    await page.callMethod('setLifeCycleNum', 0)
DCloud-WZF's avatar
DCloud-WZF 已提交
71 72
  })
})