page.test.js 3.5 KB
Newer Older
1 2 3
const PAGE_PATH = '/pages/lifecycle/page/page'
const HOME_PATH = '/pages/tab-bar/options-api'
const INTER_PAGE_PATH = '/pages/app-instance/index/index'
DCloud-WZF's avatar
DCloud-WZF 已提交
4 5 6 7
let page
let lifeCycleNum

describe('app-lifecycle', () => {
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
	it('onLaunch onShow', async () => {
		page = await program.reLaunch(HOME_PATH)
		await page.waitFor(700)
		lifeCycleNum = await page.callMethod('getLifeCycleNum')
		expect(lifeCycleNum).toBe(1100)
	})
	it('onLastPageBackPress', async () => {
		if (process.env.uniTestPlatformInfo.startsWith('android')) {
			page = await program.navigateBack()
			await page.waitFor(700)
			lifeCycleNum = await page.callMethod('getLifeCycleNum')
			expect(lifeCycleNum).toBe(100)
		}
		await page.callMethod('setLifeCycleNum', 0)
		lifeCycleNum = await page.callMethod('getLifeCycleNum')
		expect(lifeCycleNum).toBe(0)
	})
DCloud-WZF's avatar
DCloud-WZF 已提交
25 26 27
})

describe('page-lifecycle', () => {
28 29 30 31 32 33
	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 已提交
34

35
	it('onLoad onShow onReady onResize', async () => {
36 37 38
		page = await program.reLaunch(PAGE_PATH)
		await page.waitFor(700)
		lifeCycleNum = await page.callMethod('getLifeCycleNum')
雪洛's avatar
雪洛 已提交
39 40 41 42 43 44
    // TODO 安卓端调整页面加载不触发onResize后调整此测试例
		if (process.env.uniTestPlatformInfo.startsWith('android')) {
      expect(lifeCycleNum).toBe(130)
    } else if(process.env.uniTestPlatformInfo.startsWith('web')){
      expect(lifeCycleNum).toBe(120)
    }
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
		await page.callMethod('setLifeCycleNum', 0)
	})
	it('onPullDownRefresh', async () => {
		await page.callMethod('pullDownRefresh')
		await page.waitFor(1500)
		lifeCycleNum = await page.callMethod('getLifeCycleNum')
		expect(lifeCycleNum).toBe(10)
		await page.callMethod('setLifeCycleNum', 0)
	})
	it('onPageScroll onReachBottom', async () => {
		await program.pageScrollTo(2000)
		const data = await page.data()
		expect(data.isScrolled).toBe(true)
		lifeCycleNum = await page.callMethod('getLifeCycleNum')
		expect(lifeCycleNum).toBe(10)
		await page.callMethod('setLifeCycleNum', 0)
	})
	it('onHide', async () => {
63
		page = await program.navigateTo(INTER_PAGE_PATH)
64 65 66 67 68 69 70 71 72
		await page.waitFor('view')
		lifeCycleNum = await page.callMethod('getLifeCycleNum')
		expect(lifeCycleNum).toBe(-10)
		page = await program.navigateBack()
		await page.waitFor('view')
		lifeCycleNum = await page.callMethod('getLifeCycleNum')
		expect(lifeCycleNum).toBe(0)
	})
	it('onUnload', async () => {
73
		page = await program.reLaunch(HOME_PATH)
74 75 76 77 78 79 80 81 82
		await page.waitFor(700)
		lifeCycleNum = await page.callMethod('getLifeCycleNum')
		expect(lifeCycleNum).toBe(-100)
		await page.callMethod('setLifeCycleNum', 0)
	})
	it('onBackPress', async () => {
		page = await program.navigateTo(PAGE_PATH)
		await page.waitFor(700)
		lifeCycleNum = await page.callMethod('getLifeCycleNum')
雪洛's avatar
雪洛 已提交
83 84 85 86 87
		if (process.env.uniTestPlatformInfo.startsWith('android')) {
      expect(lifeCycleNum).toBe(130)
    } else if(process.env.uniTestPlatformInfo.startsWith('web')){
      expect(lifeCycleNum).toBe(120)
    }
88 89 90
		page = await program.navigateBack()
		await page.waitFor('view')
		lifeCycleNum = await page.callMethod('getLifeCycleNum')
雪洛's avatar
雪洛 已提交
91 92 93 94 95
		if (process.env.uniTestPlatformInfo.startsWith('android')) {
      expect(lifeCycleNum).toBe(20)
    } else if(process.env.uniTestPlatformInfo.startsWith('web')){
      expect(lifeCycleNum).toBe(10)
    }
96 97
		await page.callMethod('setLifeCycleNum', 0)
	})
DCloud-WZF's avatar
DCloud-WZF 已提交
98
})