demo.test.js 3.6 KB
Newer Older
study夏羽's avatar
study夏羽 已提交
1
describe('pages/clientDB/demo/demo.vue', () => {
A
Anne_LXM 已提交
2
	let page,perPage,roles;
study夏羽's avatar
study夏羽 已提交
3 4 5 6
	beforeAll(async () => {
		// 重新reLaunch至首页,并获取首页page对象(其中 program 是uni-automator自动注入的全局对象)
		page = await program.reLaunch(
			'/pages/clientDB/demo/demo')
A
Anne_LXM 已提交
7 8 9 10
		await page.waitFor("view")
		perPage = await page.$('.page')
		//底部角色控制条
		roles = await perPage.$$('.roles-item')
study夏羽's avatar
study夏羽 已提交
11 12 13
	})
	it('未登陆', async () => {
		await roles[0].tap()
A
Anne_LXM 已提交
14
		const start = Date.now()
A
Anne_LXM 已提交
15
		// console.log('start: ',start);
study夏羽's avatar
study夏羽 已提交
16
		const unLogin = await page.waitFor(async()=>{
A
Anne_LXM 已提交
17 18 19 20
			if(Date.now() - start > 4000){
				console.warn('连接服务器超时')
				return true
			}
study夏羽's avatar
study夏羽 已提交
21 22 23
			const unLoginRole = await page.data('currentRole')
			return unLoginRole === 0 
		})
A
Anne_LXM 已提交
24
		// console.log('Date.now(): ',Date.now());
A
Anne_LXM 已提交
25
		console.log("未登陆: ",unLogin );
study夏羽's avatar
study夏羽 已提交
26
		const commentBtn = await page.$('.comment-btn')
A
Anne_LXM 已提交
27
		expect((await commentBtn.text()).trim()).toBe('写留言')
study夏羽's avatar
study夏羽 已提交
28 29 30
	})
	it('用户', async () => {
		await roles[1].tap()
A
Anne_LXM 已提交
31
		const start = Date.now()
study夏羽's avatar
study夏羽 已提交
32
		const user = await page.waitFor(async()=>{
A
Anne_LXM 已提交
33 34 35 36
			if(Date.now() - start > 4000){
				console.warn('连接服务器超时')
				return true
			}
study夏羽's avatar
study夏羽 已提交
37 38 39 40
			const userRole = await page.data('currentRole')
			return userRole === 'user' 
		})
		console.log("用户: ",user);
A
Anne_LXM 已提交
41 42 43 44
		//新增一条留言
		const userWrite = await page.callMethod('submitComment', '我是用户')
		console.log('userWrite: ',userWrite);
		expect(userWrite.id).toHaveLength(24);
study夏羽's avatar
study夏羽 已提交
45 46 47
	})
	it('审核员', async () => {
		await roles[2].tap()
A
Anne_LXM 已提交
48
		const start = Date.now()
study夏羽's avatar
study夏羽 已提交
49
		const auditor = await page.waitFor(async()=>{
A
Anne_LXM 已提交
50 51 52 53
			if(Date.now() - start > 4000){
				console.warn('连接服务器超时')
				return true
			}
study夏羽's avatar
study夏羽 已提交
54 55 56 57 58 59 60
			const auditorRole = await page.data('currentRole')
			return auditorRole === 'auditor' 
		})
		console.log("审核员: ",auditor);
		if(auditor){
			//新增一条留言
			const auditorWrite = await page.callMethod('submitComment', '我是审核员11')
A
Anne_LXM 已提交
61
			console.log('auditorWrite: ',auditorWrite);
study夏羽's avatar
study夏羽 已提交
62 63
			const audId = auditorWrite.id
			expect(audId).not.toBeUndefined();
A
Anne_LXM 已提交
64
			await page.waitFor(500)
study夏羽's avatar
study夏羽 已提交
65 66 67 68 69 70 71 72 73
			// 审核一条为通过
			await page.callMethod('updateState', 
				{
					"detail": {
						"value": true
					},
				},
				audId
			)
A
Anne_LXM 已提交
74
			await page.waitFor(500)
study夏羽's avatar
study夏羽 已提交
75
			//审核员更改留言 
A
Anne_LXM 已提交
76
			await page.setData({
study夏羽's avatar
study夏羽 已提交
77 78
				"activeNoticeId":audId
			})
A
Anne_LXM 已提交
79
			await page.callMethod('updateComment',
study夏羽's avatar
study夏羽 已提交
80 81 82 83 84 85
				"我是审核员123"
			) 
		}
	})
	it('管理员', async () => {
		await roles[3].tap()
A
Anne_LXM 已提交
86
		const start = Date.now()
study夏羽's avatar
study夏羽 已提交
87
		const admin = await page.waitFor(async()=>{
A
Anne_LXM 已提交
88 89 90 91
			if(Date.now() - start > 4000){
				console.warn('连接服务器超时')
				return true
			}
study夏羽's avatar
study夏羽 已提交
92 93 94 95 96 97 98 99 100
			const adminRole = await page.data('currentRole')
			return adminRole === 'admin' 
		})
		// await page.setData({'currentRole':'admin'})
		// const adminRole = await page.data('currentRole')
		console.log("管理员: ",admin);
		if(admin){
			//管理员写入一条留言
			const adminWrite = await page.callMethod('submitComment','我是管理员') 
A
Anne_LXM 已提交
101
			console.log('adminWrite: ',adminWrite);
study夏羽's avatar
study夏羽 已提交
102 103
			var admId = adminWrite.id
			expect(admId).not.toBeUndefined();
A
Anne_LXM 已提交
104
			await page.waitFor(500)
study夏羽's avatar
study夏羽 已提交
105 106 107 108 109 110 111 112 113
			// 审核一条为通过
			await page.callMethod('updateState', 
				{
					"detail": {
						"value": true
					},
				},
				admId
			)
A
Anne_LXM 已提交
114
			await page.waitFor(500)
study夏羽's avatar
study夏羽 已提交
115
			//审核一条为拒绝
A
Anne_LXM 已提交
116
			await page.callMethod('updateState',
study夏羽's avatar
study夏羽 已提交
117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135
				{
					"detail": {
						"value": false
					},
				},
				admId
			)
			//管理员删除创建的这条留言   弹框无法操作,点击确定才能删除
			await page.callMethod('clickIcon',
				1,
				{
					"state": 0,
					"text": "我是管理员",
					"_id": admId
				}
			) 
		}
	})
})