ucenter.test.js 2.4 KB
Newer Older
study夏羽's avatar
study夏羽 已提交
1 2
describe('pages/ucenter/ucenter.vue', () => {

A
Anne_LXM 已提交
3
	let page,uniToken,platform;
study夏羽's avatar
study夏羽 已提交
4
	beforeAll(async () => {
study夏羽's avatar
study夏羽 已提交
5 6
		try{
			page = await program.switchTab('/pages/ucenter/ucenter')
A
Anne_LXM 已提交
7
			await page.waitFor('view')
study夏羽's avatar
study夏羽 已提交
8
			uniToken = await page.data('uniToken')
A
Anne_LXM 已提交
9 10 11 12
			platform = process.env.UNI_PLATFORM
			console.log("uniToken: ",platform,uniToken);
			if(!uniToken){
				console.log("未登录");
A
Anne_LXM 已提交
13
				await program.navigateTo('/uni_modules/uni-id-pages/pages/login/login-withpwd')
A
Anne_LXM 已提交
14
			}
study夏羽's avatar
study夏羽 已提交
15 16
		}catch(err){
			console.log("err: ",err);
study夏羽's avatar
study夏羽 已提交
17
		}
study夏羽's avatar
study夏羽 已提交
18
	})
A
Anne_LXM 已提交
19 20 21 22 23
	beforeEach(async () => {  
		console.log('beforeEach')
		jest.setTimeout(10000);
		return; 
	});
study夏羽's avatar
study夏羽 已提交
24
	it('宫格', async () => {
study夏羽's avatar
study夏羽 已提交
25
		expect.assertions(1);
study夏羽's avatar
study夏羽 已提交
26
		const getGrid = await page.data('gridList')
A
Anne_LXM 已提交
27
		console.log('getGrid: ',getGrid);
A
Anne_LXM 已提交
28
		// await page.waitFor(300)
study夏羽's avatar
study夏羽 已提交
29
		expect(getGrid.length).toBe(4)
study夏羽's avatar
study夏羽 已提交
30 31 32
	})
	it('列表', async () => {
		const getUcenterList = await page.data('ucenterList')
A
Anne_LXM 已提交
33
		if(platform.startsWith("app") || platform === "h5"){
study夏羽's avatar
study夏羽 已提交
34
			expect(getUcenterList.length).toBe(3)
A
Anne_LXM 已提交
35 36
		}else if(platform === "mp-weixin"){
			expect(getUcenterList.length).toBe(2)
study夏羽's avatar
study夏羽 已提交
37
		}
study夏羽's avatar
study夏羽 已提交
38
	})
study夏羽's avatar
study夏羽 已提交
39
	it('普通签到', async () => {
A
Anne_LXM 已提交
40 41
		console.log("普通签到");
		// await page.waitFor('uni-sign-in')
A
Anne_LXM 已提交
42 43
		if(uniToken && platform.startsWith("app")){
				await page.callMethod('signInByAd')
A
Anne_LXM 已提交
44
				await page.waitFor(500)
A
Anne_LXM 已提交
45
				await page.callMethod('share')
study夏羽's avatar
study夏羽 已提交
46
				await program.screenshot({
A
Anne_LXM 已提交
47
					path: "static/screenshot/sign-app.png" 
study夏羽's avatar
study夏羽 已提交
48
				})
A
Anne_LXM 已提交
49 50
		}else if(uniToken && platform === "h5"){
			await page.callMethod('signIn')
A
Anne_LXM 已提交
51
			await page.waitFor(500)
A
Anne_LXM 已提交
52 53 54 55 56
			await program.screenshot({
				path: "static/screenshot/sign-h5.png" 
			})
		}else{
			await page.callMethod('signIn')
A
Anne_LXM 已提交
57
			await page.waitFor(500)
A
Anne_LXM 已提交
58 59 60
			await program.screenshot({
				path: "static/screenshot/sign-weixin.png" 
			})
study夏羽's avatar
study夏羽 已提交
61
		}
study夏羽's avatar
study夏羽 已提交
62
	})
study夏羽's avatar
study夏羽 已提交
63
	it('我的积分', async () => {
study夏羽's avatar
study夏羽 已提交
64 65
		if(uniToken){
			const getScoreRes = await page.callMethod('getScore')
A
Anne_LXM 已提交
66
			let scoreInfo = getScoreRes && getScoreRes.result.data[0]
A
Anne_LXM 已提交
67 68
			console.log('scoreInfo: ',scoreInfo);
			await page.waitFor(500)
A
Anne_LXM 已提交
69
			if (scoreInfo) {
study夏羽's avatar
study夏羽 已提交
70
				expect.assertions(2);
A
Anne_LXM 已提交
71 72
				expect(scoreInfo.score).not.toBeUndefined();
				expect(scoreInfo.balance).toBeGreaterThanOrEqual(scoreInfo.score);
study夏羽's avatar
study夏羽 已提交
73 74 75 76 77
			} else {
				console.log("签到失败");
			}
		}else{
			console.log("getScoreRes: 未登录");
study夏羽's avatar
study夏羽 已提交
78
			try{
study夏羽's avatar
study夏羽 已提交
79
				await program.navigateTo('/uni_modules/uni-id-pages/pages/login/login-withpwd')
study夏羽's avatar
study夏羽 已提交
80 81 82
			}catch(e){
				console.log("e: ",e);
			}
study夏羽's avatar
study夏羽 已提交
83
		}
study夏羽's avatar
study夏羽 已提交
84 85
	})
})
A
Anne_LXM 已提交
86