navigator.test.js 4.4 KB
Newer Older
DCloud-WZF's avatar
DCloud-WZF 已提交
1 2 3 4 5 6
jest.setTimeout(40000)
const CURRENT_PAGE_PATH = '/pages/API/navigator/navigator'

describe('navigator', () => {
  let page
  let lifeCycleNum
DCloud-WZF's avatar
DCloud-WZF 已提交
7 8 9 10 11 12 13 14

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

DCloud-WZF's avatar
DCloud-WZF 已提交
15 16
  it('reLaunch', async () => {
    page = await program.navigateTo(CURRENT_PAGE_PATH)
DCloud-WZF's avatar
DCloud-WZF 已提交
17
    await page.waitFor(500)
DCloud-WZF's avatar
DCloud-WZF 已提交
18 19
    await page.callMethod('setLifeCycleNum', 0)
    await page.callMethod('reLaunch')
DCloud-WZF's avatar
DCloud-WZF 已提交
20
    await page.waitFor(500)
DCloud-WZF's avatar
DCloud-WZF 已提交
21
    page = await program.navigateTo(CURRENT_PAGE_PATH)
DCloud-WZF's avatar
DCloud-WZF 已提交
22
    await page.waitFor(500)
DCloud-WZF's avatar
DCloud-WZF 已提交
23 24 25 26 27 28 29
    lifeCycleNum = await page.callMethod('getLifeCycleNum')
    expect(lifeCycleNum).toBe(2)
  })

  it('navigateTo', async () => {
    await page.callMethod('setLifeCycleNum', 0)
    await page.callMethod('navigateTo')
DCloud-WZF's avatar
DCloud-WZF 已提交
30
    await page.waitFor(500)
DCloud-WZF's avatar
DCloud-WZF 已提交
31 32 33
    lifeCycleNum = await page.callMethod('getLifeCycleNum')
    expect(lifeCycleNum).toBe(2)
    page = await program.navigateBack()
DCloud-WZF's avatar
DCloud-WZF 已提交
34
    await page.waitFor(500)
DCloud-WZF's avatar
DCloud-WZF 已提交
35 36 37 38 39
  })

  it('navigateTo error page', async () => {
    await page.callMethod('setLifeCycleNum', 0)
    await page.callMethod('navigateToErrorPage')
DCloud-WZF's avatar
DCloud-WZF 已提交
40
    await page.waitFor(500)
DCloud-WZF's avatar
DCloud-WZF 已提交
41 42 43 44 45 46 47
    lifeCycleNum = await page.callMethod('getLifeCycleNum')
    expect(lifeCycleNum).toBe(2)
  })

  it('navigateTo debounce', async () => {
    await page.callMethod('setLifeCycleNum', 0)
    await page.callMethod('navigateToDebounce')
DCloud-WZF's avatar
DCloud-WZF 已提交
48
    await page.waitFor(500)
DCloud-WZF's avatar
DCloud-WZF 已提交
49 50 51
    lifeCycleNum = await page.callMethod('getLifeCycleNum')
    expect(lifeCycleNum).toBe(4)
    page = await program.navigateBack()
DCloud-WZF's avatar
DCloud-WZF 已提交
52
    await page.waitFor(500)
DCloud-WZF's avatar
DCloud-WZF 已提交
53 54
  })

DCloud-WZF's avatar
DCloud-WZF 已提交
55 56 57 58
  it('navigateTo relative path', async () => {
    await page.callMethod('setLifeCycleNum', 0)
    await page.callMethod('navigateToRelativePath1')
    page = await program.navigateBack()
DCloud-WZF's avatar
DCloud-WZF 已提交
59
    await page.waitFor(500)
DCloud-WZF's avatar
DCloud-WZF 已提交
60 61
    lifeCycleNum = await page.callMethod('getLifeCycleNum')
    expect(lifeCycleNum).toBe(2)
DCloud-WZF's avatar
DCloud-WZF 已提交
62
    await page.waitFor(500)
DCloud-WZF's avatar
DCloud-WZF 已提交
63 64 65 66 67 68
  })

  it('navigateTo relative path ./', async () => {
    await page.callMethod('setLifeCycleNum', 0)
    await page.callMethod('navigateToRelativePath2')
    page = await program.navigateBack()
DCloud-WZF's avatar
DCloud-WZF 已提交
69
    await page.waitFor(500)
DCloud-WZF's avatar
DCloud-WZF 已提交
70 71
    lifeCycleNum = await page.callMethod('getLifeCycleNum')
    expect(lifeCycleNum).toBe(2)
DCloud-WZF's avatar
DCloud-WZF 已提交
72
    await page.waitFor(500)
DCloud-WZF's avatar
DCloud-WZF 已提交
73 74 75 76 77 78
  })

  it('navigateTo relative path ../', async () => {
    await page.callMethod('setLifeCycleNum', 0)
    await page.callMethod('navigateToRelativePath3')
    page = await program.navigateBack()
DCloud-WZF's avatar
DCloud-WZF 已提交
79
    await page.waitFor(500)
DCloud-WZF's avatar
DCloud-WZF 已提交
80 81
    lifeCycleNum = await page.callMethod('getLifeCycleNum')
    expect(lifeCycleNum).toBe(2)
DCloud-WZF's avatar
DCloud-WZF 已提交
82
    await page.waitFor(500)
DCloud-WZF's avatar
DCloud-WZF 已提交
83 84
  })

DCloud-WZF's avatar
DCloud-WZF 已提交
85 86 87
  it('navigateBack', async () => {
    await page.callMethod('setLifeCycleNum', 0)
    await page.callMethod('navigateBack')
DCloud-WZF's avatar
DCloud-WZF 已提交
88
    await page.waitFor(500)
DCloud-WZF's avatar
DCloud-WZF 已提交
89
    page = await program.navigateTo(CURRENT_PAGE_PATH)
DCloud-WZF's avatar
DCloud-WZF 已提交
90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108
    await page.waitFor(500)
    lifeCycleNum = await page.callMethod('getLifeCycleNum')
    expect(lifeCycleNum).toBe(2)
  })

  it('navigateBackWithDelta1', async () => {
    await page.callMethod('setLifeCycleNum', 0)
    await page.callMethod('navigateBackWithDelta1')
    await page.waitFor(1000)
    page = await program.currentPage()
    expect(`/${page.path}`).toBe(CURRENT_PAGE_PATH)
    lifeCycleNum = await page.callMethod('getLifeCycleNum')
    expect(lifeCycleNum).toBe(2)
  })

  it('navigateBackWithDelta100', async () => {
    page = await program.reLaunch(CURRENT_PAGE_PATH)
    await page.callMethod('setLifeCycleNum', 0)
    await page.callMethod('navigateBackWithDelta100')
DCloud-WZF's avatar
DCloud-WZF 已提交
109
    await page.waitFor(1000)
DCloud-WZF's avatar
DCloud-WZF 已提交
110 111
    page = await program.currentPage()
    expect(`/${page.path}`).toBe(CURRENT_PAGE_PATH)
DCloud-WZF's avatar
DCloud-WZF 已提交
112 113 114 115 116 117 118
    lifeCycleNum = await page.callMethod('getLifeCycleNum')
    expect(lifeCycleNum).toBe(2)
  })

  it('redirectTo', async () => {
    await page.callMethod('setLifeCycleNum', 0)
    await page.callMethod('redirectTo')
DCloud-WZF's avatar
DCloud-WZF 已提交
119
    await page.waitFor(500)
DCloud-WZF's avatar
DCloud-WZF 已提交
120
    page = await program.redirectTo(CURRENT_PAGE_PATH)
DCloud-WZF's avatar
DCloud-WZF 已提交
121
    await page.waitFor(500)
DCloud-WZF's avatar
DCloud-WZF 已提交
122 123 124 125 126 127 128
    lifeCycleNum = await page.callMethod('getLifeCycleNum')
    expect(lifeCycleNum).toBe(2)
  })

  it('switchTab', async () => {
    await page.callMethod('setLifeCycleNum', 0)
    await page.callMethod('switchTab')
DCloud-WZF's avatar
DCloud-WZF 已提交
129
    await page.waitFor(500)
DCloud-WZF's avatar
DCloud-WZF 已提交
130
    page = await program.navigateTo(CURRENT_PAGE_PATH)
DCloud-WZF's avatar
DCloud-WZF 已提交
131
    await page.waitFor(500)
DCloud-WZF's avatar
DCloud-WZF 已提交
132 133 134 135
    lifeCycleNum = await page.callMethod('getLifeCycleNum')
    expect(lifeCycleNum).toBe(2)
  })
})