demo.test.js 3.8 KB
Newer Older
study夏羽's avatar
study夏羽 已提交
1 2 3 4 5 6
describe('pages/clientDB/demo/demo.vue', () => {
	let page
	beforeAll(async () => {
		// 重新reLaunch至首页,并获取首页page对象(其中 program 是uni-automator自动注入的全局对象)
		page = await program.reLaunch(
			'/pages/clientDB/demo/demo')
A
Anne_LXM 已提交
7
		await page.waitFor(1000)
study夏羽's avatar
study夏羽 已提交
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 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86
		page = await program.currentPage()
	})

	beforeEach(async()=>{
		jest.setTimeout(30000)
		return false
	})


	it('未登陆', async () => {
		const perPage = await page.$('.page')
		//底部角色控制条
		const roles = await perPage.$$('.roles-item')
		//点击创建
		await roles[0].tap()
		await page.waitFor(2000)
		
		const unLogin = await page.waitFor(async()=>{
			const unLoginRole = await page.data('currentRole')
			return unLoginRole === 0 
		})
		
		
		console.log("unLogin: ",unLogin,unLogin === 0 );
		const commentBtn = await page.$('.comment-btn')
		// console.log(await commentBtn.text(),"text---------");
		expect(await commentBtn.text()).toBe('写留言')
		
	})


	it('用户', async () => {
		const perPage = await page.$('.page')
		//底部角色控制条
		const roles = await perPage.$$('.roles-item')
		//点击创建
		await roles[1].tap()
		
		const user = await page.waitFor(async()=>{
			const userRole = await page.data('currentRole')
			return userRole === 'user' 
		})
		
		
		console.log("用户: ",user);
		
		if(user){
			//新增一条留言
			const userWrite = await page.callMethod('submitComment', '我是用户')
			const usId = userWrite.id
			//expect(usId).not.toBeUndefined();
			await page.waitFor(1000)
		}
		
		
	})


	it('审核员', async () => {
		const perPage = await page.$('.page')
		//底部角色控制条
		const roles = await perPage.$$('.roles-item')
		//点击创建
		await roles[2].tap()
		
		const auditor = await page.waitFor(async()=>{
			const auditorRole = await page.data('currentRole')
			return auditorRole === 'auditor' 
		})
		
		
		console.log("审核员: ",auditor);
		
		if(auditor){
			
			//新增一条留言
			const auditorWrite = await page.callMethod('submitComment', '我是审核员11')
			const audId = auditorWrite.id
			expect(audId).not.toBeUndefined();
A
Anne_LXM 已提交
87
			await page.waitFor(800)
study夏羽's avatar
study夏羽 已提交
88 89 90 91 92 93 94 95 96
			// 审核一条为通过
			await page.callMethod('updateState', 
				{
					"detail": {
						"value": true
					},
				},
				audId
			)
A
Anne_LXM 已提交
97
			await page.waitFor(800)
study夏羽's avatar
study夏羽 已提交
98 99 100 101 102 103 104 105
			
			//审核员更改留言 
			const setUid = await page.setData({
				"activeNoticeId":audId
			})
			const auditorUpdate = await page.callMethod('updateComment',
				"我是审核员123"
			) 
A
Anne_LXM 已提交
106
			await page.waitFor(800)
study夏羽's avatar
study夏羽 已提交
107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170
		}
		

	})


	it('管理员', async () => {
		const perPage = await page.$('.page')
		//底部角色控制条
		const roles = await perPage.$$('.roles-item')
		//点击创建
		await roles[3].tap()
		
		const admin = await page.waitFor(async()=>{
			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','我是管理员') 
			var admId = adminWrite.id
			expect(admId).not.toBeUndefined();
			await page.waitFor(1000)
			
			// 审核一条为通过
			await page.callMethod('updateState', 
				{
					"detail": {
						"value": true
					},
				},
				admId
			)
			await page.waitFor(1000)
			
			
			//审核一条为拒绝
			const adminRefuse = await page.callMethod('updateState',
				{
					"detail": {
						"value": false
					},
				},
				admId
			)
			
			//管理员删除创建的这条留言   弹框无法操作,点击确定才能删除
			await page.callMethod('clickIcon',
				1,
				{
					"state": 0,
					"text": "我是管理员",
					"_id": admId
				}
			) 
		}
		
	})
})