readme.test.js 7.5 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 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 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 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 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338
describe('pages/clientDB/permission-demo/readme.vue', () => {
	
	let page
	beforeAll(async () => {
		// 重新reLaunch至首页,并获取首页page对象(其中 program 是uni-automator自动注入的全局对象)
		page = await program.reLaunch(
			'/pages/clientDB/permission-demo/readme')
		if (process.env.UNI_PLATFORM === "h5"|| process.env.UNI_PLATFORM === "app-plus" ) {
			await page.waitFor(1000)
		}
		if (process.env.UNI_PLATFORM === "mp-weixin") {
			await page.waitFor(1000);//微信等待
		}
		// 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[1].tap()
		
		const user = await page.waitFor(async()=>{
			const userRole = await page.data('currentRole')
			return userRole == 'user'
		})
		console.log("user: ",user);

		
		if(user){
			
			const getData = await page.callMethod('getFn','uid,username,nickname,state')
			expect(getData).not.toBeUndefined();
			
			
			const removeAll = await page.callMethod('removeFn','uid,username,nickname,state')
			// expect(removeAll.code).toBe('PERMISSION_ERROR')
			
			//创建一条数据
			await page.callMethod('addFn') 
			
			//更新创建者自己的昵称
			await page.callMethod(
				'updateFn',
				{"nickname":'新昵称'},'uid == $env.uid'
			)
			
			
			const updateAllNickname = await page.callMethod(
				'updateFn',
				{"nickname":'新昵称'}
			)
			// expect(updateAllNickname.code).toBe("PERMISSION_ERROR")
			
			const updateState = await page.callMethod('updateFn',{state:1})
			// expect(updateState.code).toBe('PERMISSION_ERROR')
			
			
			
			
			const updateAllUsername = await page.callMethod(
				'updateFn',
				{"username":"新姓名"}
			)
			// expect(updateAllUsername.code).toBe('PERMISSION_ERROR')
			
			const updateUsername = await page.callMethod(
				'updateFn',
				{"username":'新姓名'},'uid == $env.uid'
			)
			// expect(updateUsername.code).toBe('PERMISSION_ERROR')
			
			
			await page.callMethod(
				'getFn',
				'uid,username,nickname,state'
			)
			
			const readPhone = await page.callMethod(
				'getFn',
				'uid,username,nickname,state'
			)
		}
		
		
	})
	
	it('未登陆', async () => {
		
		
		if (process.env.UNI_PLATFORM === "h5" || process.env.UNI_PLATFORM === "app-plus" ) {
			
			
			console.log("h5");
			await page.waitFor(2000)
			const perPage = await page.$('.page')
			//底部角色控制条
			const roles = await perPage.$$('.roles-item')
			//点击创建
			await roles[0].tap()
			
			await page.waitFor(500)
		}
		
		if (process.env.UNI_PLATFORM === "mp-weixin") {
			
			
			await page.waitFor(300)
			console.log("mp-weixin");
			const perPage = await page.$('.page')
			const setPer = await perPage.$('set-permission')
			//底部角色控制条
			const roles = await setPer.$$('.roles-item')
			//点击创建
			await roles[0].tap()
			await page.waitFor(500)
		}
		
		
		const unlogin = await page.waitFor(async()=>{
			const unloginRole = await page.data('currentRole')
			return unloginRole === 0 
		})
		console.log("unlogin: ",unlogin);
	
		
		if(unlogin){
			
			const getData = await page.callMethod('getFn','uid,username,nickname,state')
			expect(getData.data).not.toBeUndefined();
			
			// console.log("getData: ",getData.data);
			
			//删除所有
			const removeAll = await page.callMethod('removeFn','uid,username,nickname,state')
			// expect(removeAll.code).toBe('PERMISSION_ERROR')
			
			//创建一条数据
			const createOne = await page.callMethod('addFn') 
			
			const updateNickname = await page.callMethod(
				'updateFn',
				{"nickname":'新昵称'},'uid == $env.uid'
			)
			// expect(updateNickname.code).toBe('TOKEN_INVALID_ANONYMOUS_USER')
			
			const updateAllNickname = await page.callMethod(
				'updateFn',
				{"nickname":'新昵称'}
			)
			// expect(updateAllNickname.code).toBe('TOKEN_INVALID_ANONYMOUS_USER')
			
			
			const updateState = await page.callMethod('updateFn',{state:1})
			// expect(updateState.code).toBe('TOKEN_INVALID_ANONYMOUS_USER')
			
			const updateAllUsername = await page.callMethod(
				'updateFn',
				{"username":"新姓名"}
			)
			// console.log("updateAllUsername: ",updateAllUsername);
			// expect(updateAllUsername.code).toBe('TOKEN_INVALID_ANONYMOUS_USER')
			
			
			const updateUsername = await page.callMethod(
				'updateFn',
				{"username":'新姓名'},'uid == $env.uid'
			)
			// expect(updateUsername.code).toBe('TOKEN_INVALID_ANONYMOUS_USER')
			
			await page.callMethod(
				'getFn',
				'uid,username,nickname,state'
			)
			
			const readPhone = await page.callMethod(
				'getFn',
				'uid,username,nickname,state'
			)
			
		}
		
	})
	
	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 getData = await page.callMethod('getFn','uid,username,nickname,state')
			expect(getData).not.toBeUndefined();
			
			
			const removeAll = await page.callMethod('removeFn','uid,username,nickname,state')
			expect(removeAll.code).toBe('PERMISSION_ERROR')
			
			
			await page.callMethod('addFn') 
			
			//更新创建者
			await page.callMethod(
				'updateFn',
				{"nickname":'新昵称'},'uid == $env.uid'
			)
			
			//更新表中所有
			const updateAllNickname = await page.callMethod(
				'updateFn',
				{"nickname":'新昵称'}
			)
			
			//state更新为1
			await page.callMethod('updateFn',{state:1})
			
			
			//更新表中所有
			await page.callMethod(
				'updateFn',
				{"username":"新姓名"}
			)
			
			
			//更新创建者
			await page.callMethod(
				'updateFn',
				{"username":'新姓名'},'uid == $env.uid'
			)
			
			
			//读不含phone
			await page.callMethod(
				'getFn',
				'uid,username,nickname,state'
			)
			
			//读含有phone
			await page.callMethod(
				'getFn',
				'uid,username,nickname,state'
			)
			
			
		}
		
		
	})
	
	
	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'
		})
		console.log(admin);

		
		if(admin){
			const getData = await page.callMethod('getFn','uid,username,nickname,state')
			expect(getData).not.toBeUndefined();
			
			//删除所有
			await page.callMethod('removeFn','uid,username,nickname,state')
			
			//新增一条
			await page.callMethod('addFn') 
			
			//更新创建者
			await page.callMethod(
				'updateFn',
				{"nickname":'新昵称'},'uid == $env.uid'
			)
			
			//更新表中所有
			const updateAllNickname = await page.callMethod(
				'updateFn',
				{"nickname":'新昵称'}
			)
			
			//state更新为1
			await page.callMethod('updateFn',{state:1})
			
			
			//更新表中所有
			await page.callMethod(
				'updateFn',
				{"username":"新姓名"}
			)
			
			
			//更新创建者
			await page.callMethod(
				'updateFn',
				{"username":'新姓名'},'uid == $env.uid'
			)
			
			
			//读不含phone
			await page.callMethod(
				'getFn',
				'uid,username,nickname,state'
			)
			
			//读含有phone
			await page.callMethod(
				'getFn',
				'uid,username,nickname,state'
			)
			
		}
		
		
		
	})


})