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

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

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

DCloud-WZF's avatar
DCloud-WZF 已提交
26 27
describe('page-lifecycle', () => {
  it('onLoad onShow onReady', async () => {
DCloud-WZF's avatar
DCloud-WZF 已提交
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
    await page.callMethod('setLifeCycleNum', 0)
DCloud-WZF's avatar
DCloud-WZF 已提交
33
  })
DCloud-WZF's avatar
DCloud-WZF 已提交
34 35 36 37
  it('onPullDownRefresh', async () => {
    await page.callMethod('pullDownRefresh')
    await page.waitFor(1500)
    lifeCycleNum = await page.callMethod('getLifeCycleNum')
DCloud-WZF's avatar
DCloud-WZF 已提交
38 39
    expect(lifeCycleNum).toBe(10)
    await page.callMethod('setLifeCycleNum', 0)
DCloud-WZF's avatar
DCloud-WZF 已提交
40 41
  })
  it('onPageScroll onReachBottom', async () => {
DCloud-WZF's avatar
DCloud-WZF 已提交
42
    await program.pageScrollTo(2000)
DCloud-WZF's avatar
DCloud-WZF 已提交
43 44 45
    const data = await page.data()
    expect(data.isScrolled).toBe(true)
    lifeCycleNum = await page.callMethod('getLifeCycleNum')
DCloud-WZF's avatar
DCloud-WZF 已提交
46 47
    expect(lifeCycleNum).toBe(10)
    await page.callMethod('setLifeCycleNum', 0)
DCloud-WZF's avatar
DCloud-WZF 已提交
48
  })
DCloud-WZF's avatar
DCloud-WZF 已提交
49 50
  it('onHide', async () => {
    page = await program.navigateTo(INTERMEDIATE_PAGE_PATH)
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(-10)
DCloud-WZF's avatar
DCloud-WZF 已提交
54
    page = await program.navigateBack()
DCloud-WZF's avatar
DCloud-WZF 已提交
55
    await page.waitFor(1000)
DCloud-WZF's avatar
DCloud-WZF 已提交
56
    lifeCycleNum = await page.callMethod('getLifeCycleNum')
DCloud-WZF's avatar
DCloud-WZF 已提交
57
    expect(lifeCycleNum).toBe(0)
DCloud-WZF's avatar
DCloud-WZF 已提交
58 59 60
  })
  it('onUnload', async () => {
    page = await program.redirectTo(INTERMEDIATE_PAGE_PATH)
DCloud-WZF's avatar
DCloud-WZF 已提交
61
    await page.waitFor(1000)
DCloud-WZF's avatar
DCloud-WZF 已提交
62
    lifeCycleNum = await page.callMethod('getLifeCycleNum')
DCloud-WZF's avatar
DCloud-WZF 已提交
63 64
    expect(lifeCycleNum).toBe(-100)
    await page.callMethod('setLifeCycleNum', 0)
DCloud-WZF's avatar
DCloud-WZF 已提交
65 66 67
  })
  it('onBackPress', async () => {
    page = await program.navigateTo(PAGE_PATH)
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
    expect(lifeCycleNum).toBe(120)
DCloud-WZF's avatar
DCloud-WZF 已提交
71
    page = await program.navigateBack()
DCloud-WZF's avatar
DCloud-WZF 已提交
72
    await page.waitFor(1000)
DCloud-WZF's avatar
DCloud-WZF 已提交
73
    lifeCycleNum = await page.callMethod('getLifeCycleNum')
DCloud-WZF's avatar
DCloud-WZF 已提交
74
    expect(lifeCycleNum).toBe(10)
DCloud-WZF's avatar
DCloud-WZF 已提交
75
    await page.callMethod('setLifeCycleNum', 0)
DCloud-WZF's avatar
DCloud-WZF 已提交
76 77
  })
})