demo.test.js 3.2 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
		await page.waitFor(async()=>{
A
Anne_LXM 已提交
16 17 18 19
			if(Date.now() - start > 4000){
				console.warn('连接服务器超时')
				return true
			}
study夏羽's avatar
study夏羽 已提交
20 21 22 23
			const unLoginRole = await page.data('currentRole')
			return unLoginRole === 0 
		})
		const commentBtn = await page.$('.comment-btn')
A
Anne_LXM 已提交
24
		expect((await commentBtn.text()).trim()).toBe('写留言')
study夏羽's avatar
study夏羽 已提交
25 26 27
	})
	it('用户', async () => {
		await roles[1].tap()
A
Anne_LXM 已提交
28
		const start = Date.now()
A
Anne_LXM 已提交
29
		await page.waitFor(async()=>{
A
Anne_LXM 已提交
30 31 32 33
			if(Date.now() - start > 4000){
				console.warn('连接服务器超时')
				return true
			}
study夏羽's avatar
study夏羽 已提交
34 35 36
			const userRole = await page.data('currentRole')
			return userRole === 'user' 
		})
A
Anne_LXM 已提交
37 38
		//新增一条留言
		const userWrite = await page.callMethod('submitComment', '我是用户')
A
Anne_LXM 已提交
39
		expect(userWrite.id.length).toBe(24);
study夏羽's avatar
study夏羽 已提交
40 41 42
	})
	it('审核员', async () => {
		await roles[2].tap()
A
Anne_LXM 已提交
43
		const start = Date.now()
A
Anne_LXM 已提交
44
		await page.waitFor(async()=>{
A
Anne_LXM 已提交
45 46 47 48
			if(Date.now() - start > 4000){
				console.warn('连接服务器超时')
				return true
			}
study夏羽's avatar
study夏羽 已提交
49 50 51
			const auditorRole = await page.data('currentRole')
			return auditorRole === 'auditor' 
		})
A
Anne_LXM 已提交
52 53 54 55 56 57 58 59 60 61 62
		//新增一条留言
		const auditorWrite = await page.callMethod('submitComment', '我是审核员11')
		// console.log('auditorWrite: ',auditorWrite);
		const audId = auditorWrite.id
		expect(audId).not.toBeUndefined();
		await page.waitFor(500)
		// 审核一条为通过
		await page.callMethod('updateState', 
			{
				"detail": {
					"value": true
study夏羽's avatar
study夏羽 已提交
63
				},
A
Anne_LXM 已提交
64 65 66 67 68 69 70 71 72 73 74
			},
			audId
		)
		await page.waitFor(500)
		//审核员更改留言 
		await page.setData({
			"activeNoticeId":audId
		})
		await page.callMethod('updateComment',
			"我是审核员123"
		) 
study夏羽's avatar
study夏羽 已提交
75 76 77
	})
	it('管理员', async () => {
		await roles[3].tap()
A
Anne_LXM 已提交
78
		const start = Date.now()
A
Anne_LXM 已提交
79
		await page.waitFor(async()=>{
A
Anne_LXM 已提交
80 81 82 83
			if(Date.now() - start > 4000){
				console.warn('连接服务器超时')
				return true
			}
study夏羽's avatar
study夏羽 已提交
84 85 86 87 88
			const adminRole = await page.data('currentRole')
			return adminRole === 'admin' 
		})
		// await page.setData({'currentRole':'admin'})
		// const adminRole = await page.data('currentRole')
A
Anne_LXM 已提交
89 90 91 92 93 94 95 96 97 98 99
		//管理员写入一条留言
		const adminWrite = await page.callMethod('submitComment','我是管理员') 
		// console.log('adminWrite: ',adminWrite);
		var admId = adminWrite.id
		expect(admId).not.toBeUndefined();
		await page.waitFor(500)
		// 审核一条为通过
		await page.callMethod('updateState', 
			{
				"detail": {
					"value": true
study夏羽's avatar
study夏羽 已提交
100
				},
A
Anne_LXM 已提交
101 102 103 104 105 106 107 108 109
			},
			admId
		)
		await page.waitFor(500)
		//审核一条为拒绝
		await page.callMethod('updateState',
			{
				"detail": {
					"value": false
study夏羽's avatar
study夏羽 已提交
110
				},
A
Anne_LXM 已提交
111 112 113 114 115 116 117 118 119 120 121 122
			},
			admId
		)
		//管理员删除创建的这条留言   弹框无法操作,点击确定才能删除
		await page.callMethod('clickIcon',
			1,
			{
				"state": 0,
				"text": "我是管理员",
				"_id": admId
			}
		) 
study夏羽's avatar
study夏羽 已提交
123 124
	})
})