permission-field-simple.test.js 13.4 KB
Newer Older
study夏羽's avatar
study夏羽 已提交
1
describe('pages/clientDB/permission-field-simple/permission-field-simple.nvue', () => {
A
Anne_LXM 已提交
2
	let page,errMsgA,errMsgB,perPage,segItems,roles;
study夏羽's avatar
study夏羽 已提交
3 4 5 6
	beforeAll(async () => {
		// 重新reLaunch至首页,并获取首页page对象(其中 program 是uni-automator自动注入的全局对象)
		page = await program.reLaunch(
			'/pages/clientDB/permission-field-simple/permission-field-simple')
A
Anne_LXM 已提交
7
		await page.waitFor('view')
study夏羽's avatar
study夏羽 已提交
8
		page = await program.currentPage()
A
Anne_LXM 已提交
9 10
		errMsgA = "权限校验未通过,参与权限校验的集合:[],请参考文档:https://uniapp.dcloud.net.cn/uniCloud/schema.html#handler-permission-error"
		errMsgB = "权限校验未通过,未能获取当前用户信息,当前用户为匿名身份 ,参与权限校验的集合:[],请参考文档:https://uniapp.dcloud.net.cn/uniCloud/schema.html#handler-permission-error"
A
Anne_LXM 已提交
11 12 13 14 15
		perPage = await page.$('.page')
		//头部操作控制条
		segItems = await perPage.$$('.segmented-control__item')
		//底部角色控制条
		roles = await perPage.$$('.roles-item')
study夏羽's avatar
study夏羽 已提交
16 17 18 19 20 21 22 23 24 25 26
	})

	it('创建--未登陆', async () => {
		await segItems[0].tap()
		await roles[0].tap()

		const createUnlogin = await page.waitFor(async () => {
			const createUnloginIndex = await page.data('typeIndex')
			const createUnloginRole = await page.data('currentRole')
			return createUnloginIndex === 0 && createUnloginRole === 0
		})
A
Anne_LXM 已提交
27
		// console.log("createUnlogin: ",createUnlogin);
study夏羽's avatar
study夏羽 已提交
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

		const createA = await page.callMethod('myFn', {
			"type": "create",
			"index": 0
		})
		/* expect(createA).toBe('[permission-test-10.ip.write]权限校验未通过') */

		await page.callMethod('myFn', {
			"type": "create",
			"index": 0,
			"field": "_id,state,create_time,text",
		})

		const createB = await page.callMethod('myFn', {
			"type": "create",
			"index": 1,
		})
		// expect(createB).toBe('未能获取当前用户信息:30205 | 当前用户为匿名身份')

		await page.callMethod('myFn', {
			"type": "create",
			"index": 1,
			"field": "_id,state,create_time,text",
		})

		const createC = await page.callMethod('myFn', {
			"type": "create",
			"index": 2,
		})
A
Anne_LXM 已提交
57
		expect(createC).toBe(errMsgB)
study夏羽's avatar
study夏羽 已提交
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74

		await page.callMethod('myFn', {
			"type": "create",
			"index": 2,
			"field": "_id,state,create_time,text",
		})
	})

	it('读取--未登陆', async () => {
		await segItems[1].tap()
		await roles[0].tap()

		const readUnlogin = await page.waitFor(async () => {
			const readUnloginIndex = await page.data('typeIndex')
			const readUnloginRole = await page.data('currentRole')
			return readUnloginIndex === 1 && readUnloginRole === 0
		})
A
Anne_LXM 已提交
75
		// console.log("readUnlogin: ",readUnlogin);
study夏羽's avatar
study夏羽 已提交
76 77 78 79 80

		const readA = await page.callMethod('myFn', {
			"type": "read",
			"index": 0
		})
A
Anne_LXM 已提交
81 82
		// console.log("readA: ",readA);
		expect(readA).toBe(errMsgB)
study夏羽's avatar
study夏羽 已提交
83 84 85 86 87 88 89 90 91 92 93

		await page.callMethod('myFn', {
			"type": "read",
			"index": 0,
			"field": "_id,state,create_time,text"
		})

		const readB = await page.callMethod('myFn', {
			"type": "read",
			"index": 1
		})
A
Anne_LXM 已提交
94
		expect(readB).toBe(errMsgB)
study夏羽's avatar
study夏羽 已提交
95 96 97 98 99 100 101 102 103 104 105

		await page.callMethod('myFn', {
			"type": "read",
			"index": 1,
			"field": "_id,state,create_time,text"
		})

		const readC = await page.callMethod('myFn', {
			"type": "read",
			"index": 2
		})
A
Anne_LXM 已提交
106
		expect(readC).toBe(errMsgB)
study夏羽's avatar
study夏羽 已提交
107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123

		await page.callMethod('myFn', {
			"type": "read",
			"index": 2,
			"field": "_id,state,create_time,text"
		})
	})

	it('更新--未登陆', async () => {
		await segItems[2].tap()
		await roles[0].tap()

		const updateUnlogin = await page.waitFor(async () => {
			const updateUnloginIndex = await page.data('typeIndex')
			const updateUnloginRole = await page.data('currentRole')
			return updateUnloginIndex === 2 && updateUnloginRole === 0
		})
A
Anne_LXM 已提交
124
		// console.log("updateUnlogin: ",updateUnlogin);
study夏羽's avatar
study夏羽 已提交
125 126 127 128
		const updateA = await page.callMethod('myFn', {
			"type": "update",
			"index": 0
		})
A
Anne_LXM 已提交
129 130
		// console.log("updateA: ",updateA);
		expect(updateA).toBe(errMsgB)
study夏羽's avatar
study夏羽 已提交
131 132 133 134 135 136 137 138 139 140 141

		await page.callMethod('myFn', {
			"type": "update",
			"index": 0,
			"field": "_id,state,create_time,text"
		})

		const updateB = await page.callMethod('myFn', {
			"type": "update",
			"index": 1
		})
A
Anne_LXM 已提交
142
		expect(updateB).toBe(errMsgB)
study夏羽's avatar
study夏羽 已提交
143 144 145 146 147 148 149 150 151 152 153

		await page.callMethod('myFn', {
			"type": "update",
			"index": 1,
			"field": "_id,state,create_time,text"
		})

		const updateC = await page.callMethod('myFn', {
			"type": "update",
			"index": 2
		})
A
Anne_LXM 已提交
154
		expect(updateC).toBe(errMsgB)
study夏羽's avatar
study夏羽 已提交
155 156 157 158 159 160 161 162 163 164 165 166

		await page.callMethod('myFn', {
			"type": "update",
			"index": 2,
			"field": "_id,state,create_time,text"
		})
	})

	it('创建--用户', async () => {
		//点击创建
		await segItems[0].tap()
		await roles[1].tap()
A
Anne_LXM 已提交
167
		const start = Date.now()
study夏羽's avatar
study夏羽 已提交
168
		const createUser = await page.waitFor(async () => {
A
Anne_LXM 已提交
169 170 171 172
			if(Date.now() - start > 4000){
				console.warn('连接服务器超时')
				return true
			}
study夏羽's avatar
study夏羽 已提交
173 174 175 176
			const createUserIndex = await page.data('typeIndex')
			const createUserRole = await page.data('currentRole')
			return createUserIndex === 0 && createUserRole == 'user'
		})
A
Anne_LXM 已提交
177
		// console.log("createUser: ",createUser);
study夏羽's avatar
study夏羽 已提交
178 179 180 181 182

		const createUserA = await page.callMethod('myFn', {
			"type": "create",
			"index": 0,
		})
A
Anne_LXM 已提交
183 184
		// console.log("createUserA: ",createUserA);
		expect(createUserA).toBe(errMsgA)
study夏羽's avatar
study夏羽 已提交
185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205

		await page.callMethod('myFn', {
			"type": "create",
			"index": 0,
			"field": "_id,state,create_time,text"
		})

		await page.callMethod('myFn', {
			"type": "create",
			"index": 1,
		})
		await page.callMethod('myFn', {
			"type": "create",
			"index": 1,
			"field": "_id,state,create_time,text",
		})

		const createUserB = await page.callMethod('myFn', {
			"type": "create",
			"index": 2,
		})
A
Anne_LXM 已提交
206 207
		// console.log('createUserB: ',createUserB);
		expect(createUserB).toBe(errMsgA)
study夏羽's avatar
study夏羽 已提交
208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223
		await page.callMethod('myFn', {
			"type": "create",
			"index": 2,
			"field": "_id,state,create_time,text",
		})
	})

	it('读取--用户', async () => {
		await segItems[1].tap()
		await roles[1].tap()

		const readUser = await page.waitFor(async () => {
			const readUserIndex = await page.data('typeIndex')
			const readUserRole = await page.data('currentRole')
			return readUserIndex === 1 && readUserRole == 'user'
		})
A
Anne_LXM 已提交
224
		// console.log("readUser: ",readUser);
study夏羽's avatar
study夏羽 已提交
225 226 227 228 229
		
		const readUserA = await page.callMethod('myFn', {
			"type": "read",
			"index": 0
		})
A
Anne_LXM 已提交
230
		expect(readUserA).toBe(errMsgA)
study夏羽's avatar
study夏羽 已提交
231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252

		await page.callMethod('myFn', {
			"type": "read",
			"index": 0,
			"field": "_id,state,create_time,text"
		})

		await page.callMethod('myFn', {
			"type": "read",
			"index": 1
		})

		await page.callMethod('myFn', {
			"type": "read",
			"index": 1,
			"field": "_id,state,create_time,text"
		})

		const readUserB = await page.callMethod('myFn', {
			"type": "read",
			"index": 2
		})
A
Anne_LXM 已提交
253
		expect(readUserB).toBe(errMsgA)
study夏羽's avatar
study夏羽 已提交
254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271

		await page.callMethod('myFn', {
			"type": "read",
			"index": 2,
			"field": "_id,state,create_time,text"
		})

	})

	it('更新--用户', async () => {
		await segItems[2].tap()
		await roles[1].tap()

		const readUser = await page.waitFor(async () => {
			const updateUserIndex = await page.data('typeIndex')
			const updateUserRole = await page.data('currentRole')
			return updateUserIndex === 2 && updateUserRole == 'user'
		})
A
Anne_LXM 已提交
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
		if(readUser){
			const updateUserA = await page.callMethod('myFn', {
				"type": "update",
				"index": 0
			})
			expect(updateUserA).toBe(errMsgA)
			
			await page.callMethod('myFn', {
				"type": "update",
				"index": 0,
				"field": "_id,state,create_time,text"
			})
			
			await page.callMethod('myFn', {
				"type": "update",
				"index": 1
			})
			
			await page.callMethod('myFn', {
				"type": "update",
				"index": 1,
				"field": "_id,state,create_time,text"
			})
			
			const updateUserB = await page.callMethod('myFn', {
				"type": "update",
				"index": 2
			})
			expect(updateUserB).toBe(errMsgA)
			
			await page.callMethod('myFn', {
				"type": "update",
				"index": 2,
				"field": "_id,state,create_time,text"
			})
		}
study夏羽's avatar
study夏羽 已提交
308 309 310 311 312 313 314 315 316 317 318 319 320

	})

	it('创建--审核员', async () => {
		//点击创建
		await segItems[0].tap()
		await roles[2].tap()

		const createAuditor = await page.waitFor(async () => {
			const createAuditorIndex = await page.data('typeIndex')
			const createAuditorRole = await page.data('currentRole')
			return createAuditorIndex === 0 && createAuditorRole == 'auditor'
		})
A
Anne_LXM 已提交
321
		
study夏羽's avatar
study夏羽 已提交
322 323 324 325
		const createAuditorA = await page.callMethod('myFn', {
			"type": "create",
			"index": 0,
		})
A
Anne_LXM 已提交
326
		expect(createAuditorA).toBe(errMsgA)
study夏羽's avatar
study夏羽 已提交
327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366

		await page.callMethod('myFn', {
			"type": "create",
			"index": 0,
			"field": "_id,state,create_time,text"
		})

		await page.callMethod('myFn', {
			"type": "create",
			"index": 1,
		})

		await page.callMethod('myFn', {
			"type": "create",
			"index": 1,
			"field": "_id,state,create_time,text",
		})

		await page.callMethod('myFn', {
			"type": "create",
			"index": 2,
		})

		await page.callMethod('myFn', {
			"type": "create",
			"index": 2,
			"field": "_id,state,create_time,text",
		})

	})

	it('读取--审核员', async () => {
		await segItems[1].tap()
		await roles[2].tap()

		const readAuditor = await page.waitFor(async () => {
			const readAuditorIndex = await page.data('typeIndex')
			const readAuditorRole = await page.data('currentRole')
			return readAuditorIndex === 1 && readAuditorRole == 'auditor'
		})
A
Anne_LXM 已提交
367
		
study夏羽's avatar
study夏羽 已提交
368 369 370 371
		const readAuditorA = await page.callMethod('myFn', {
			"type": "read",
			"index": 0
		})
A
Anne_LXM 已提交
372
		expect(readAuditorA).toBe(errMsgA)
study夏羽's avatar
study夏羽 已提交
373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411

		await page.callMethod('myFn', {
			"type": "read",
			"index": 0,
			"field": "_id,state,create_time,text"
		})

		await page.callMethod('myFn', {
			"type": "read",
			"index": 1
		})

		await page.callMethod('myFn', {
			"type": "read",
			"index": 1,
			"field": "_id,state,create_time,text"
		})

		await page.callMethod('myFn', {
			"type": "read",
			"index": 2
		})

		await page.callMethod('myFn', {
			"type": "read",
			"index": 2,
			"field": "_id,state,create_time,text"
		})
	})

	it('更新--审核员', async () => {
		await segItems[2].tap()
		await roles[2].tap()

		const updateAuditor = await page.waitFor(async () => {
			const updateAuditorIndex = await page.data('typeIndex')
			const updateAuditorRole = await page.data('currentRole')
			return updateAuditorIndex === 2 && updateAuditorRole == 'auditor'
		})
A
Anne_LXM 已提交
412
		// console.log('updateAuditor: ',updateAuditor);
study夏羽's avatar
study夏羽 已提交
413 414 415 416 417

		const updateAuditorA = await page.callMethod('myFn', {
			"type": "update",
			"index": 0
		})
A
Anne_LXM 已提交
418
		expect(updateAuditorA).toBe(errMsgA)
study夏羽's avatar
study夏羽 已提交
419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457

		await page.callMethod('myFn', {
			"type": "update",
			"index": 0,
			"field": "_id,state,create_time,text"
		})

		await page.callMethod('myFn', {
			"type": "update",
			"index": 1
		})

		await page.callMethod('myFn', {
			"type": "update",
			"index": 1,
			"field": "_id,state,create_time,text"
		})

		await page.callMethod('myFn', {
			"type": "update",
			"index": 2
		})

		await page.callMethod('myFn', {
			"type": "update",
			"index": 2,
			"field": "_id,state,create_time,text"
		})
	})

	it('创建--管理员', async () => {
		await segItems[0].tap()
		await roles[3].tap()

		const createAdmin = await page.waitFor(async () => {
			const createAdminIndex = await page.data('typeIndex')
			const createAdminRole = await page.data('currentRole')
			return createAdminIndex === 0 && createAdminRole == 'admin'
		})
A
Anne_LXM 已提交
458
		// console.log('createAdmin: ',createAdmin);
study夏羽's avatar
study夏羽 已提交
459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503

		await page.callMethod('myFn', {
			"type": "create",
			"index": 0,
		})

		await page.callMethod('myFn', {
			"type": "create",
			"index": 0,
			"field": "_id,state,create_time,text"
		})

		await page.callMethod('myFn', {
			"type": "create",
			"index": 1,
		})

		await page.callMethod('myFn', {
			"type": "create",
			"index": 1,
			"field": "_id,state,create_time,text",
		})

		await page.callMethod('myFn', {
			"type": "create",
			"index": 2,
		})

		await page.callMethod('myFn', {
			"type": "create",
			"index": 2,
			"field": "_id,state,create_time,text",
		})

	})

	it('读取--管理员', async () => {
		await segItems[1].tap()
		await roles[3].tap()

		const readAdmin = await page.waitFor(async () => {
			const readAdminIndex = await page.data('typeIndex')
			const readAdminRole = await page.data('currentRole')
			return readAdminIndex === 1 && readAdminRole == 'admin'
		})
A
Anne_LXM 已提交
504
		// console.log('readAdmin: ',readAdmin);
study夏羽's avatar
study夏羽 已提交
505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543

		await page.callMethod('myFn', {
			"type": "read",
			"index": 0
		})

		await page.callMethod('myFn', {
			"type": "read",
			"index": 0,
			"field": "_id,state,create_time,text"
		})

		await page.callMethod('myFn', {
			"type": "read",
			"index": 1
		})

		await page.callMethod('myFn', {
			"type": "read",
			"index": 1,
			"field": "_id,state,create_time,text"
		})

		await page.callMethod('myFn', {
			"type": "read",
			"index": 2
		})

		await page.callMethod('myFn', {
			"type": "read",
			"index": 2,
			"field": "_id,state,create_time,text"
		})

	})

	it('更新--管理员', async () => {
		await segItems[2].tap()
		await roles[3].tap()
A
Anne_LXM 已提交
544
		
study夏羽's avatar
study夏羽 已提交
545 546 547 548 549
		const updateAdmin = await page.waitFor(async () => {
			const updateAdminIndex = await page.data('typeIndex')
			const updateAdminRole = await page.data('currentRole')
			return updateAdminIndex === 2 && updateAdminRole == 'admin'
		})
A
Anne_LXM 已提交
550 551
		// console.log('updateAdmin: ',updateAdmin);
		
study夏羽's avatar
study夏羽 已提交
552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586
		await page.callMethod('myFn', {
			"type": "update",
			"index": 0
		})

		await page.callMethod('myFn', {
			"type": "update",
			"index": 0,
			"field": "_id,state,create_time,text"
		})

		await page.callMethod('myFn', {
			"type": "update",
			"index": 1
		})

		await page.callMethod('myFn', {
			"type": "update",
			"index": 1,
			"field": "_id,state,create_time,text"
		})

		await page.callMethod('myFn', {
			"type": "update",
			"index": 2
		})

		await page.callMethod('myFn', {
			"type": "update",
			"index": 2,
			"field": "_id,state,create_time,text"
		})
	})

})