bind-mobile.test.js 1.6 KB
Newer Older
study夏羽's avatar
study夏羽 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59
// uniapp自动化测试教程: https://uniapp-test.dcloud.net.cn/docs/testcase/start

describe('pages/ucenter/userinfo/bind-mobile/bind-mobile.vue', () => {
	let page
	beforeAll( async ()=>{
		page = await program.redirectTo('/pages/ucenter/userinfo/bind-mobile/bind-mobile')
		await page.waitFor(500)
	})
	
	it('修改绑定手机号',async()=>{
		let phone = "17769516019" 
		await page.setData({
			formData: {
				"phone":phone
			}
		})
		expect(phone).toMatch(/^1\d{10}$/);
		
		if (process.env.UNI_PLATFORM === "mp-weixin") {
			const codeBtnMp = await page.$('uni-send-sms-code')
			const sendMsgResMp = await codeBtnMp.callMethod('sendMsg')
			await page.waitFor(300)
		}else{
			const codebtn =  await page.$('.short-code-btn')
			const sendMsgRes = await codebtn.callMethod('sendMsg')
			await page.waitFor(300)
		}
		
		let code = "123456"
		await page.setData({formData: {code}})
		expect(code).toMatch(/^\d{6}$/);
		
		const submitRes = await page.callMethod('submit')
		await page.waitFor(300)
		console.log("submitRes: ",submitRes);
		
		if(submitRes){
			switch (submitRes.code){
				case  0:
					expect(submitRes.msg).toBe("手机号码绑定成功")
					await page.waitFor(300)
					console.log(await program.currentPage());
					expect((await program.currentPage()).path).toBe('/pages/ucenter/userinfo/userinfo')
					break;
				case  403:
					expect(submitRes.msg).toBe("缺少token")
					await page.waitFor(300)
					await program.redirectTo('/pages/ucenter/login-page/pwd-login/pwd-login')
					break;
				case  60101:
					expect(submitRes.msg).toBe("此手机号已绑定")
					break;
				default:
					break;
			}
		}
	})
	
});