提交 9bb76589 编写于 作者: A Anne_LXM

update test

上级 f2594667
......@@ -12,8 +12,7 @@ describe('pages/clientDB/demo/demo.vue', () => {
it('未登陆', async () => {
await roles[0].tap()
const start = Date.now()
// console.log('start: ',start);
const unLogin = await page.waitFor(async()=>{
await page.waitFor(async()=>{
if(Date.now() - start > 4000){
console.warn('连接服务器超时')
return true
......@@ -21,15 +20,13 @@ describe('pages/clientDB/demo/demo.vue', () => {
const unLoginRole = await page.data('currentRole')
return unLoginRole === 0
})
// console.log('Date.now(): ',Date.now());
console.log("未登陆: ",unLogin );
const commentBtn = await page.$('.comment-btn')
expect((await commentBtn.text()).trim()).toBe('写留言')
})
it('用户', async () => {
await roles[1].tap()
const start = Date.now()
const user = await page.waitFor(async()=>{
await page.waitFor(async()=>{
if(Date.now() - start > 4000){
console.warn('连接服务器超时')
return true
......@@ -37,16 +34,15 @@ describe('pages/clientDB/demo/demo.vue', () => {
const userRole = await page.data('currentRole')
return userRole === 'user'
})
console.log("用户: ",user);
//新增一条留言
const userWrite = await page.callMethod('submitComment', '我是用户')
console.log('userWrite: ',userWrite);
expect(userWrite.id).toHaveLength(24);
expect(userWrite.id.length).toBe(24);
})
it('审核员', async () => {
await roles[2].tap()
const start = Date.now()
const auditor = await page.waitFor(async()=>{
await page.waitFor(async()=>{
if(Date.now() - start > 4000){
console.warn('连接服务器超时')
return true
......@@ -54,37 +50,34 @@ describe('pages/clientDB/demo/demo.vue', () => {
const auditorRole = await page.data('currentRole')
return auditorRole === 'auditor'
})
console.log("审核员: ",auditor);
if(auditor){
//新增一条留言
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
},
//新增一条留言
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
},
audId
)
await page.waitFor(500)
//审核员更改留言
await page.setData({
"activeNoticeId":audId
})
await page.callMethod('updateComment',
"我是审核员123"
)
}
},
audId
)
await page.waitFor(500)
//审核员更改留言
await page.setData({
"activeNoticeId":audId
})
await page.callMethod('updateComment',
"我是审核员123"
)
})
it('管理员', async () => {
await roles[3].tap()
const start = Date.now()
const admin = await page.waitFor(async()=>{
await page.waitFor(async()=>{
if(Date.now() - start > 4000){
console.warn('连接服务器超时')
return true
......@@ -94,42 +87,39 @@ describe('pages/clientDB/demo/demo.vue', () => {
})
// await page.setData({'currentRole':'admin'})
// const adminRole = await page.data('currentRole')
console.log("管理员: ",admin);
if(admin){
//管理员写入一条留言
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
},
//管理员写入一条留言
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
},
admId
)
await page.waitFor(500)
//审核一条为拒绝
await page.callMethod('updateState',
{
"detail": {
"value": false
},
},
admId
)
await page.waitFor(500)
//审核一条为拒绝
await page.callMethod('updateState',
{
"detail": {
"value": false
},
admId
)
//管理员删除创建的这条留言 弹框无法操作,点击确定才能删除
await page.callMethod('clickIcon',
1,
{
"state": 0,
"text": "我是管理员",
"_id": admId
}
)
}
},
admId
)
//管理员删除创建的这条留言 弹框无法操作,点击确定才能删除
await page.callMethod('clickIcon',
1,
{
"state": 0,
"text": "我是管理员",
"_id": admId
}
)
})
})
......@@ -24,55 +24,58 @@ describe('pages/clientDB/permission-demo/permission-demo.vue', () => {
console.log('role: ',await page.data('role'));
expect((await roles[0].text()).trim()).toBe('未登陆')
})
it('用户', async () => {
await roles[1].tap()
const user = await page.waitFor(async()=>{
const start = Date.now()
await page.waitFor(async()=>{
if(Date.now() - start > 4000){
console.warn('链接服务器超时')
return true
}
const userRole = await page.data('rulo_index')
return userRole === 1
})
if(user){
//更新一条数据
await page.setData({
"formData": {
"_id": "60200c3554a29f0001d14586",
"nickname": "我是学生",
"username": "小明",
"state": 0,
"phone": "18890903030"
}
})
const buttonGroup = await perPage.$('.uni-button-group')
const toButton = await buttonGroup.$('.uni-button')
await toButton.tap()
await page.waitFor(800)
}
//更新一条数据
await page.setData({
"formData": {
"_id": "60200c3554a29f0001d14586",
"nickname": "我是学生",
"username": "小明",
"state": 0,
"phone": "18890903030"
}
})
const buttonGroup = await perPage.$('.uni-button-group')
const toButton = await buttonGroup.$('.uni-button')
await toButton.tap()
await page.waitFor(800)
})
it('审核员', async () => {
await roles[2].tap()
const auditor = await page.waitFor(async()=>{
const start = Date.now()
await page.waitFor(async()=>{
if(Date.now() - start > 4000){
console.warn('链接服务器超时')
return true
}
const auditorRole = await page.data('rulo_index')
return auditorRole === 2
})
if(auditor){
await page.setData({
"formData": {
"_id": "60200c3554a29f0001d14586",
"nickname": "我是学生",
"username": "小明",
"state":1,
"phone": "18890903030"
}
})
}
await page.setData({
"formData": {
"_id": "60200c3554a29f0001d14586",
"nickname": "我是学生",
"username": "小明",
"state":1,
"phone": "18890903030"
}
})
})
it('管理员', async () => {
await roles[3].tap()
const start = Date.now()
const admin = await page.waitFor(async()=>{
await page.waitFor(async()=>{
if(Date.now() - start > 4000){
console.warn('链接服务器超时')
return true
......@@ -80,17 +83,15 @@ describe('pages/clientDB/permission-demo/permission-demo.vue', () => {
const adminRole = await page.data('rulo_index')
return adminRole === 3
})
if(admin){
await page.setData({
"formData": {
"_id": "60200c3554a29f0001d14586",
"nickname": "我是学生",
"username": "小明",
"state":-1,
"phone": "18890903030"
}
})
}
await page.setData({
"formData": {
"_id": "60200c3554a29f0001d14586",
"nickname": "我是学生",
"username": "小明",
"state":-1,
"phone": "18890903030"
}
})
})
})
......@@ -18,49 +18,52 @@ describe('pages/clientDB/permission-demo/readme.vue', () => {
it('用户', async () => {
await roles[1].tap()
const start = Date.now()
const user = await page.waitFor(async()=>{
if(Date.now() - start > 4000){
console.warn('连接服务器超时')
return true
}
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'
)
}
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 () => {
await roles[0].tap()
......
......@@ -164,8 +164,12 @@ describe('pages/clientDB/permission-field-simple/permission-field-simple.nvue',
//点击创建
await segItems[0].tap()
await roles[1].tap()
const start = Date.now()
const createUser = await page.waitFor(async () => {
if(Date.now() - start > 4000){
console.warn('连接服务器超时')
return true
}
const createUserIndex = await page.data('typeIndex')
const createUserRole = await page.data('currentRole')
return createUserIndex === 0 && createUserRole == 'user'
......
......@@ -201,8 +201,12 @@ describe('pages/clientDB/permission-table-compound/permission-table-compound.vue
it('读取--用户', async () => {
await segItems[1].tap()
await roles[1].tap()
const start = Date.now()
const readUser = await page.waitFor(async () => {
if(Date.now() - start > 4000){
console.warn('连接服务器超时')
return true
}
const readUserIndex = await page.data('typeIndex')
const readUserRole = await page.data('currentRole')
return readUserIndex === 1 && readUserRole == 'user'
......
......@@ -6,7 +6,6 @@ describe('pages/clientDB/validate/validate.vue', () => {
page = await program.reLaunch('/pages/clientDB/validate/validate')
await page.waitFor('view')
})
it('点击切换navBar', async () => {
//expect.assertions(1);
const segmentedControl = await page.$('.segmented-control')
......@@ -18,5 +17,4 @@ describe('pages/clientDB/validate/validate.vue', () => {
await seControl[2].tap()
await page.waitFor(300)
})
})
......@@ -14,7 +14,7 @@ describe('pages/cloudFunction/cloudFunction.vue', () => {
it('添加一条数据',async()=>{
expect.assertions(1);
const addData = await page.callMethod('add')
expect(addData).toHaveLength(24);
expect(addData.length).toBe(24);
})
it('删除一条数据',async()=>{
expect.assertions(1);
......@@ -24,13 +24,20 @@ describe('pages/cloudFunction/cloudFunction.vue', () => {
it('修改数据',async()=>{
expect.assertions(1);
const updateData = await page.callMethod('update')
expect(updateData).toBeDefined();
if(updateData.status == -1){
expect(updateData.msg).toBe('集合unicloud-test内没有数据');
}else{
expect(updateData.msg).toBeDefined();
}
})
it('查询前10条数据',async()=>{
expect.assertions(1);
const getTenData = await page.callMethod('get')
// expect(getTenData.affectedDocs).toBe(10);
expect(getTenData.length).not.toBeUndefined();
// 首次可能也会没有数据
if(getTenData.affectedDocs>0){
expect(getTenData.data.length).toBeGreaterThanOrEqual(1);
}else{
console.log('no data')
}
})
it('使用公用模块',async()=>{
expect.assertions(1);
......
......@@ -99,7 +99,7 @@
showCancel: false
})
console.log(res)
return res.result.msg
return res.result
}).catch((err) => {
uni.hideLoading()
uni.showModal({
......@@ -123,7 +123,7 @@
showCancel: false
})
console.log(res)
return res.result.data
return res.result
}).catch((err) => {
uni.hideLoading()
uni.showModal({
......
......@@ -14,7 +14,7 @@ describe('pages/cloudObject/cloudObject.vue', () => {
it('新增一条数据',async()=>{
expect.assertions(1);
const addData = await page.callMethod('add')
expect(addData).toHaveLength(24);
expect(addData.length).toBe(24);
})
it('删除一条数据',async()=>{
expect.assertions(1);
......@@ -24,12 +24,20 @@ describe('pages/cloudObject/cloudObject.vue', () => {
it('修改数据',async()=>{
expect.assertions(1);
const updateData = await page.callMethod('update')
expect(updateData).toBeDefined();
if(updateData.status == -1){
expect(updateData.msg).toBe('集合unicloud-test内没有数据');
}else{
expect(updateData.msg).toBeDefined();
}
})
it('查询前10条数据',async()=>{
expect.assertions(1);
const getTenData = await page.callMethod('get')
expect(getTenData.data.length).toBeGreaterThanOrEqual(1);
// 首次可能也会没有数据
if(getTenData.affectedDocs>0){
expect(getTenData.data.length).toBeGreaterThanOrEqual(1);
}else{
console.log('no data')
}
})
it('使用公用模块',async()=>{
expect.assertions(1);
......
......@@ -106,7 +106,7 @@
showCancel: false
})
console.log(res)
return res.msg
return res
}).catch((err) => {
uni.hideLoading()
uni.showModal({
......
......@@ -6,20 +6,15 @@ describe('pages/user-info/add.vue', () => {
await page.waitFor('view')
})
it('输入表单内容', async () => {
let username = "林小明"
let weight = 51
let mobile = "17769516066"
let email = "1076998870@qq.com"
let url = "https://dcloud.io/"
await page.setData({
"formData": {
"username":username,
"username":"小明",
"gender":1,
"birth_date": 1612519694000,
"weight":weight,
"mobile":mobile,
"email":email,
"url":url,
"birth_date": Date.now(),
"weight":51,
"mobile":"17755555555",
"email":"1076998870@qq.com",
"url":"https://dcloud.io/",
"favorite_book_id": "4",
"address_code": "110105",
"party_member": true,
......@@ -28,20 +23,6 @@ describe('pages/user-info/add.vue', () => {
},
"isTest":true
})
//console.log(await page.data('formData'), "setForm---");
//姓名只能输入中文
//expect(username).toMatch(/^[\u4e00-\u9fa5]+/);
//手机号校验
expect(mobile).toMatch(/^1[3|4|5|7|8][0-9]{9}$/);
//var re=/\w+@[a-z0-9]+\.[a-z]{2,4}/
expect(email).toMatch(/\w+@[a-z0-9]+\.[a-z]{2,4}/);
//url验证
const urlEx = /^((ht|f)tps?):\/\/[\w\-]+(\.[\w\-]+)+([\w\-\.,@?^=%&:\/~\+#]*[\w\-\@?^=%&\/~\+#])?$/;
expect(url).toMatch(urlEx);
//体重要大于50 小于或等于500
expect(weight).toBeGreaterThan(50)
expect(weight).toBeLessThanOrEqual(500)
await page.callMethod('submit')
})
})
\ No newline at end of file
......@@ -121,12 +121,11 @@
/**
* 触发表单提交
*/
async submit() {
submit() {
uni.showLoading({
mask: true
})
return this.$refs.form.validate().then(async(res) => {
console.log('res: ',res);
return await this.submitForm(res)
}).catch(() => {
uni.hideLoading()
......
......@@ -5,18 +5,17 @@ describe('pages/user-info/detail.vue', () => {
// page = await program.navigateTo('/pages/user-info/detail')
page = await program.currentPage()
await page.waitFor('view')
await page.setData({"isTest":true})
})
it('点击修改',async()=>{
// expect.assertions(1);
const getQuery = await page.query
console.log('getQuery: ',getQuery);
await page.callMethod('handleUpdate')
await page.waitFor(1000)
console.log('currentPage',await program.currentPage())
// console.log('query',await page.query)
expect((await program.currentPage()).path).toBe('pages/user-info/edit')
if(getQuery.id || getQuery.hobby_valuetotext.length>0){
await page.callMethod('handleUpdate')
await page.waitFor(1000)
console.log('currentPage',await program.currentPage())
expect((await program.currentPage()).path).toBe('pages/user-info/edit')
}
})
// it('点击删除',async()=>{
// const handleDelete = await page.callMethod('handleDelete')
// })
})
\ No newline at end of file
......@@ -4,48 +4,30 @@ describe('pages/user-info/detail.vue', () => {
// 重新reLaunch至首页,并获取首页page对象(其中 program 是uni-automator自动注入的全局对象)
// page = await program.navigateTo('/pages/user-info/edit?id=601d044ac9e7be0001cc00b8')
page = await program.currentPage()
console.log('page: ',page);
await page.waitFor('view')
})
it('修改表单内容', async () => {
const getQuery = await page.query
console.log('getQuery: ',getQuery);
let username = "林小明加"
let weight = 51
let mobile = "17766666666"
let email = "1076998866@qq.com"
let url = "https://dcloud.io/"
await page.setData({
"formData": {
"username":username,
"gender":1,
"birth_date": 1612519694000,
"weight":weight,
"mobile":mobile,
"email":email,
"url":url,
"username":"林小明加",
"gender":2,
"birth_date": Date.now(),
"weight":56,
"mobile":"17766666666",
"email":"1076998866@qq.com",
"url":"https://uniapp.dcloud.net.cn/",
"favorite_book_id": "4",
"address_code": "110105",
"party_member": true,
"hobby":["dance","Sing","draw"],
"comment": "好的更新了1"
"comment": "好的更新了"
}
})
await page.waitFor(1000)
//姓名只能输入中文
expect(username).toMatch(/^[\u4e00-\u9fa5]+/);
//手机号校验
expect(mobile).toMatch(/^1[3|4|5|7|8][0-9]{9}$/);
//var re=/\w+@[a-z0-9]+\.[a-z]{2,4}/
expect(email).toMatch(/\w+@[a-z0-9]+\.[a-z]{2,4}/);
//url验证
const urlEx = /^((ht|f)tps?):\/\/[\w\-]+(\.[\w\-]+)+([\w\-\.,@?^=%&:\/~\+#]*[\w\-\@?^=%&\/~\+#])?$/;
expect(url).toMatch(urlEx);
//体重要大于50 小于或等于500
expect(weight).toBeGreaterThan(50)
expect(weight).toBeLessThanOrEqual(500)
const res = await page.callMethod('submit')
console.log('res: ',res);
console.log('res: ',res.updated);
expect(res.updated).toBe(1)
})
})
\ No newline at end of file
......@@ -77,6 +77,7 @@
"comment": ""
}
return {
isTest:false,
formData,
formOptions: {
"gender_localdata": [
......@@ -145,9 +146,13 @@
icon: 'none',
title: '修改成功'
})
this.getOpenerEventChannel().emit('refreshData')
setTimeout(() => uni.navigateBack(), 500)
return res
if(!this.isTest){
}
this.getOpenerEventChannel().emit('refreshData')
setTimeout(() => uni.navigateBack(), 500)
console.log('res: ',res);
return res.result
}).catch((err) => {
uni.showModal({
content: err.message || '请求服务失败',
......
......@@ -5,21 +5,37 @@ describe('pages/user-info/list.vue', () => {
// 重新reLaunch至首页,并获取首页page对象(其中 program 是uni-automator自动注入的全局对象)
page = await program.navigateTo('/pages/user-info/list')
await page.waitFor('view')
console.log('process----',process.env.UNI_PLATFORM)
})
async function waitTime(){
if(process.env.UNI_PLATFORM == 'mp-weixin'){
await page.waitFor(1000)
}else{
await page.waitFor(500)
}
}
it('点击fab跳转到添加页',async()=>{
await page.callMethod('fabClick')
await page.waitFor(500)
await waitTime()
currentPage = await program.currentPage()
expect(currentPage.path).toBe('pages/user-info/add')
await program.navigateBack()
})
it('点击第一条',async()=>{
await page.waitFor(2000)
const items = await page.$$('.uni-list-item')
await items[0].tap()
await page.waitFor(500)
currentPage = await program.currentPage()
expect(currentPage.path).toBe('pages/user-info/detail')
// await program.navigateBack()
// console.log('currentPage',await program.currentPage())
console.log('items: ',items);
if(items.length<0)return;
if(items.length>0){
await items[0].tap()
await waitTime()
currentPage = await program.currentPage()
expect(currentPage.path).toBe('pages/user-info/detail')
// await program.navigateBack()
// console.log('currentPage',await program.currentPage())
}else{
console.log('no items');
}
})
})
\ No newline at end of file
})
......@@ -32,14 +32,9 @@
contentdown: '',
contentrefresh: '',
contentnomore: ''
},
dataList: []
}
}
},
onReady() {
this.dataList = this.$refs.udb.loadData()
console.log("dataList: ",this.dataList);
},
onPullDownRefresh() {
this.$refs.udb.loadData({
clear: true
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册