navigator.test.js 7.6 KB
Newer Older
DCloud-WZF's avatar
DCloud-WZF 已提交
1
jest.setTimeout(80000)
DCloud-WZF's avatar
DCloud-WZF 已提交
2
const CURRENT_PAGE_PATH = '/pages/API/navigator/navigator'
DCloud-WZF's avatar
DCloud-WZF 已提交
3 4
const CHILD1_PAGE_PATH = '/pages/API/navigator/new-page/new-page-1'
const CHILD2_PAGE_PATH = '/pages/API/navigator/new-page/new-page-2'
DCloud-WZF's avatar
DCloud-WZF 已提交
5 6 7 8

describe('navigator', () => {
  let page
  let lifeCycleNum
DCloud-WZF's avatar
DCloud-WZF 已提交
9 10

  afterAll(async () => {
DCloud-WZF's avatar
DCloud-WZF 已提交
11
		page = await program.reLaunch(CURRENT_PAGE_PATH)
DCloud-WZF's avatar
DCloud-WZF 已提交
12 13 14 15 16 17
    const resetLifecycleNum = 1100
    await page.callMethod('setLifeCycleNum', resetLifecycleNum)
    lifeCycleNum = await page.callMethod('getLifeCycleNum')
    expect(lifeCycleNum).toBe(resetLifecycleNum)
  })

DCloud-WZF's avatar
DCloud-WZF 已提交
18 19
  it('reLaunch', async () => {
    page = await program.navigateTo(CURRENT_PAGE_PATH)
DCloud-WZF's avatar
DCloud-WZF 已提交
20
    await page.waitFor(500)
DCloud-WZF's avatar
DCloud-WZF 已提交
21 22
    await page.callMethod('setLifeCycleNum', 0)
    await page.callMethod('reLaunch')
DCloud-WZF's avatar
DCloud-WZF 已提交
23
    await page.waitFor(500)
DCloud-WZF's avatar
DCloud-WZF 已提交
24
    page = await program.navigateTo(CURRENT_PAGE_PATH)
DCloud-WZF's avatar
DCloud-WZF 已提交
25
    await page.waitFor(500)
DCloud-WZF's avatar
DCloud-WZF 已提交
26 27 28 29 30 31 32
    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 已提交
33
    await page.waitFor(500)
DCloud-WZF's avatar
DCloud-WZF 已提交
34 35 36
    lifeCycleNum = await page.callMethod('getLifeCycleNum')
    expect(lifeCycleNum).toBe(2)
    page = await program.navigateBack()
DCloud-WZF's avatar
DCloud-WZF 已提交
37
    await page.waitFor(500)
DCloud-WZF's avatar
DCloud-WZF 已提交
38 39 40 41 42
  })

  it('navigateTo error page', async () => {
    await page.callMethod('setLifeCycleNum', 0)
    await page.callMethod('navigateToErrorPage')
DCloud-WZF's avatar
DCloud-WZF 已提交
43
    await page.waitFor(500)
DCloud-WZF's avatar
DCloud-WZF 已提交
44 45 46 47 48 49 50
    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 已提交
51
    await page.waitFor(500)
DCloud-WZF's avatar
DCloud-WZF 已提交
52 53 54
    lifeCycleNum = await page.callMethod('getLifeCycleNum')
    expect(lifeCycleNum).toBe(4)
    page = await program.navigateBack()
DCloud-WZF's avatar
DCloud-WZF 已提交
55
    await page.waitFor(500)
DCloud-WZF's avatar
DCloud-WZF 已提交
56 57
  })

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

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

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

DCloud-WZF's avatar
DCloud-WZF 已提交
88 89 90
  it('navigateBack', async () => {
    await page.callMethod('setLifeCycleNum', 0)
    await page.callMethod('navigateBack')
DCloud-WZF's avatar
DCloud-WZF 已提交
91
    await page.waitFor(500)
DCloud-WZF's avatar
DCloud-WZF 已提交
92
    page = await program.navigateTo(CURRENT_PAGE_PATH)
DCloud-WZF's avatar
DCloud-WZF 已提交
93 94 95 96 97 98 99 100 101 102 103 104 105 106 107
    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)
  })

DCloud-WZF's avatar
DCloud-WZF 已提交
108 109 110 111 112 113 114 115 116 117 118 119 120 121
  it('navigateBackWithDelta2', async () => {
    await page.callMethod('setLifeCycleNum', 0)
    await program.navigateTo(CHILD2_PAGE_PATH)
    await page.waitFor(500)
    page = await program.navigateTo(CHILD1_PAGE_PATH)
    await page.waitFor(500)
    await page.callMethod('navigateBackWithDelta2')
    await page.waitFor(500)
    page = await program.currentPage()
    expect(`/${page.path}`).toBe(CURRENT_PAGE_PATH)
    lifeCycleNum = await page.callMethod('getLifeCycleNum')
    expect(lifeCycleNum).toBe(10)
  })

DCloud-WZF's avatar
DCloud-WZF 已提交
122 123 124 125
  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 已提交
126
    await page.waitFor(1000)
DCloud-WZF's avatar
DCloud-WZF 已提交
127 128
    page = await program.currentPage()
    expect(`/${page.path}`).toBe(CURRENT_PAGE_PATH)
DCloud-WZF's avatar
DCloud-WZF 已提交
129 130 131 132 133 134 135
    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 已提交
136
    await page.waitFor(500)
DCloud-WZF's avatar
DCloud-WZF 已提交
137
    page = await program.redirectTo(CURRENT_PAGE_PATH)
DCloud-WZF's avatar
DCloud-WZF 已提交
138
    await page.waitFor(500)
DCloud-WZF's avatar
DCloud-WZF 已提交
139 140 141 142 143
    lifeCycleNum = await page.callMethod('getLifeCycleNum')
    expect(lifeCycleNum).toBe(2)
  })

  it('switchTab', async () => {
DCloud-WZF's avatar
DCloud-WZF 已提交
144
    page = await program.reLaunch(CURRENT_PAGE_PATH)
DCloud-WZF's avatar
DCloud-WZF 已提交
145 146
    await page.callMethod('setLifeCycleNum', 0)
    await page.callMethod('switchTab')
DCloud-WZF's avatar
DCloud-WZF 已提交
147
    await page.waitFor(500)
DCloud-WZF's avatar
DCloud-WZF 已提交
148
    page = await program.navigateTo(CURRENT_PAGE_PATH)
DCloud-WZF's avatar
DCloud-WZF 已提交
149
    await page.waitFor(500)
DCloud-WZF's avatar
DCloud-WZF 已提交
150 151 152
    lifeCycleNum = await page.callMethod('getLifeCycleNum')
    expect(lifeCycleNum).toBe(2)
  })
DCloud-WZF's avatar
DCloud-WZF 已提交
153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198

  it('20 times navigateTo', async () => {
    const originPageStack = await program.pageStack()
    page = await program.navigateTo(CHILD1_PAGE_PATH)
    expect(page.path).toBe(CHILD1_PAGE_PATH.substring(1))
    page = await program.navigateTo(CHILD2_PAGE_PATH)
    expect(page.path).toBe(CHILD2_PAGE_PATH.substring(1))
    page = await program.navigateTo(CHILD1_PAGE_PATH)
    expect(page.path).toBe(CHILD1_PAGE_PATH.substring(1))
    page = await program.navigateTo(CHILD2_PAGE_PATH)
    expect(page.path).toBe(CHILD2_PAGE_PATH.substring(1))
    page = await program.navigateTo(CHILD1_PAGE_PATH)
    expect(page.path).toBe(CHILD1_PAGE_PATH.substring(1))
    page = await program.navigateTo(CHILD2_PAGE_PATH)
    expect(page.path).toBe(CHILD2_PAGE_PATH.substring(1))
    page = await program.navigateTo(CHILD1_PAGE_PATH)
    expect(page.path).toBe(CHILD1_PAGE_PATH.substring(1))
    page = await program.navigateTo(CHILD2_PAGE_PATH)
    expect(page.path).toBe(CHILD2_PAGE_PATH.substring(1))
    page = await program.navigateTo(CHILD1_PAGE_PATH)
    expect(page.path).toBe(CHILD1_PAGE_PATH.substring(1))
    page = await program.navigateTo(CHILD2_PAGE_PATH)
    expect(page.path).toBe(CHILD2_PAGE_PATH.substring(1))
    page = await program.navigateTo(CHILD1_PAGE_PATH)
    expect(page.path).toBe(CHILD1_PAGE_PATH.substring(1))
    page = await program.navigateTo(CHILD2_PAGE_PATH)
    expect(page.path).toBe(CHILD2_PAGE_PATH.substring(1))
    page = await program.navigateTo(CHILD1_PAGE_PATH)
    expect(page.path).toBe(CHILD1_PAGE_PATH.substring(1))
    page = await program.navigateTo(CHILD2_PAGE_PATH)
    expect(page.path).toBe(CHILD2_PAGE_PATH.substring(1))
    page = await program.navigateTo(CHILD1_PAGE_PATH)
    expect(page.path).toBe(CHILD1_PAGE_PATH.substring(1))
    page = await program.navigateTo(CHILD2_PAGE_PATH)
    expect(page.path).toBe(CHILD2_PAGE_PATH.substring(1))
    page = await program.navigateTo(CHILD1_PAGE_PATH)
    expect(page.path).toBe(CHILD1_PAGE_PATH.substring(1))
    page = await program.navigateTo(CHILD2_PAGE_PATH)
    expect(page.path).toBe(CHILD2_PAGE_PATH.substring(1))
    page = await program.navigateTo(CHILD1_PAGE_PATH)
    expect(page.path).toBe(CHILD1_PAGE_PATH.substring(1))
    page = await program.navigateTo(CHILD2_PAGE_PATH)
    expect(page.path).toBe(CHILD2_PAGE_PATH.substring(1))
    const newPageStack = await program.pageStack()
    expect(newPageStack.length - originPageStack.length).toBe(20)
  })
DCloud-WZF's avatar
DCloud-WZF 已提交
199
})