提交 92151277 编写于 作者: A Anne_LXM

update test

上级 8c18d6e3
......@@ -173,8 +173,13 @@ describe('pages/clientDB/permission-table-compound/permission-table-compound.vue
it('创建--用户', async () => {
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'
......
......@@ -19,8 +19,12 @@ describe('pages/clientDB/permission-table-simple/permission-table-simple.vue', (
//点击创建
await segItems[0].tap()
await roles[0].tap()
const start = Date.now()
const createUnlogin = await page.waitFor(async () => {
if(Date.now() - start > 4000){
console.warn('连接服务器超时')
return true
}
const createUnlogintIndex = await page.data('typeIndex')
const createUnloginRole = await page.data('currentRole')
return createUnlogintIndex === 0 && createUnloginRole === 0
......@@ -33,7 +37,7 @@ describe('pages/clientDB/permission-table-simple/permission-table-simple.vue', (
"index": 0
})
console.log('createA: ',createA);
expect(createA.result.id).toHaveLength(24)
expect(createA.id).toHaveLength(24)
// 禁止任何角色创建,管理员除外
const createB = await page.callMethod('myFn', {
......@@ -71,7 +75,7 @@ describe('pages/clientDB/permission-table-simple/permission-table-simple.vue', (
"action": "add_view_count"
})
// console.log('createAction: ',createAction);
expect(createAction.result.id).toHaveLength(24)
expect(createAction.id).toHaveLength(24)
}
})
......@@ -93,7 +97,7 @@ describe('pages/clientDB/permission-table-simple/permission-table-simple.vue', (
"index": 0
})
console.log('readA: ',readA);
expect(readA.result.data.length).toBeGreaterThanOrEqual(1)
expect(readA.data.length).toBeGreaterThanOrEqual(1)
// 禁止任何角色读取
const readB = await page.callMethod('myFn', {
......@@ -178,7 +182,7 @@ describe('pages/clientDB/permission-table-simple/permission-table-simple.vue', (
"action": "add_view_count"
})
console.log('actionRead:--- ',actionRead);
// expect(actionRead.result.data.length).toBeGreaterThanOrEqual(1)
// expect(actionRead.data.length).toBeGreaterThanOrEqual(1)
}
})
......@@ -201,7 +205,7 @@ describe('pages/clientDB/permission-table-simple/permission-table-simple.vue', (
"index": 0
})
console.log('updateA:--- ',updateA);
// expect(updateA.result.updated).toBeGreaterThanOrEqual(1)
// expect(updateA.updated).toBeGreaterThanOrEqual(1)
// 禁止任何角色更新,管理员除外
const updateB = await page.callMethod('myFn', {
......@@ -238,7 +242,7 @@ describe('pages/clientDB/permission-table-simple/permission-table-simple.vue', (
"index": 3
})
console.log('updateF:--- ',updateF);
// expect(updateF.result.updated).toBe(0)
// expect(updateF.updated).toBe(0)
// 只更新1分钟内创建的数据,先创建数据
const updateG = await page.callMethod('myFn', {
......@@ -261,7 +265,8 @@ describe('pages/clientDB/permission-table-simple/permission-table-simple.vue', (
"type": "update",
"index": 4
})
expect(updateI.result.updated).toBe(0)
console.log('updateI:--- ',updateI);
// expect(updateI.updated).toBe(0)
//限审核员更新全表数据
const updateJ = await page.callMethod('myFn', {
......@@ -284,7 +289,7 @@ describe('pages/clientDB/permission-table-simple/permission-table-simple.vue', (
"action": "add_view_count"
})
console.log('updateAction:--- ',updateAction);
// expect(updateAction.result.updated).toBeGreaterThanOrEqual(1)
// expect(updateAction.updated).toBeGreaterThanOrEqual(1)
}
})
......@@ -306,7 +311,7 @@ describe('pages/clientDB/permission-table-simple/permission-table-simple.vue', (
"index": 0
})
console.log("deleteA---",deleteA);
// expect(deleteA.result.deleted).toBeGreaterThanOrEqual(1)
// expect(deleteA.deleted).toBeGreaterThanOrEqual(1)
// 禁止任何角色删除,管理员除外
const deleteB = await page.callMethod('myFn', {
......@@ -343,7 +348,7 @@ describe('pages/clientDB/permission-table-simple/permission-table-simple.vue', (
"index": 3
})
console.log('deleteF: ---',deleteF);
// expect(deleteF.result.deleted).toBe(0)
// expect(deleteF.deleted).toBe(0)
// 只更新1分钟内创建的数据,先创建数据
const deleteG = await page.callMethod('myFn', {
......@@ -386,7 +391,7 @@ describe('pages/clientDB/permission-table-simple/permission-table-simple.vue', (
"action": "add_view_count"
})
console.log('deleteAction: ---',deleteAction);
// expect(deleteAction.result.deleted).toBeGreaterThanOrEqual(1)
// expect(deleteAction.deleted).toBeGreaterThanOrEqual(1)
})
it('创建--用户', async () => {
......@@ -404,7 +409,7 @@ describe('pages/clientDB/permission-table-simple/permission-table-simple.vue', (
"type": "create",
"index": 0
})
expect(createUserA.result.id).toHaveLength(24)
expect(createUserA.id).toHaveLength(24)
// 禁止任何角色创建,仅管理员
const createUserB = await page.callMethod('myFn', {
......@@ -418,7 +423,7 @@ describe('pages/clientDB/permission-table-simple/permission-table-simple.vue', (
"type": "create",
"index": 2
})
expect(createUserC.result.id).toHaveLength(24)
expect(createUserC.id).toHaveLength(24)
// 仅审核员可创建
const createUserD = await page.callMethod('myFn', {
......@@ -440,7 +445,7 @@ describe('pages/clientDB/permission-table-simple/permission-table-simple.vue', (
"index": 6,
"action": "add_view_count"
})
expect(createUserF.result.id).toHaveLength(24)
expect(createUserF.id).toHaveLength(24)
})
......@@ -477,15 +482,14 @@ describe('pages/clientDB/permission-table-simple/permission-table-simple.vue', (
"index": 2
})
// console.log('readUserC: ',readUserC);
// expect(readUserA.errCode).toBe(0)
expect(readUserC.result.data.length).toBeGreaterThan(0)
expect(readUserC.data.length).toBeGreaterThan(0)
// 只能读取自己创建的数据,先创建数据
const readUserD = await page.callMethod('myFn', {
"type": "create",
"index": 3
})
expect(readUserD.result.id).toHaveLength(24)
expect(readUserD.id).toHaveLength(24)
// 只能读取自己创建的数据
const readUserE = await page.callMethod('myFn', {
......@@ -494,7 +498,7 @@ describe('pages/clientDB/permission-table-simple/permission-table-simple.vue', (
"where": "uid == $env.uid"
})
// console.log('readUserE: ',readUserE);
expect(readUserE.result.data.length).toBeGreaterThan(0)
expect(readUserE.data.length).toBeGreaterThan(0)
// 读取全表数据
const readUserF = await page.callMethod('myFn', {
......@@ -502,14 +506,14 @@ describe('pages/clientDB/permission-table-simple/permission-table-simple.vue', (
"index": 3
})
// console.log('readUserF: --------------',readUserF);
expect(readUserF.result.data.length).toBeGreaterThan(0)
expect(readUserF.data.length).toBeGreaterThan(0)
// 只读取1分钟内创建的数据,先创建数据
const readUserG = await page.callMethod('myFn', {
"type": "create",
"index": 4
})
expect(readUserG.result.id).toHaveLength(24)
expect(readUserG.id).toHaveLength(24)
// 只读取1分钟内创建的数据
const readUserH = await page.callMethod('myFn', {
......@@ -518,7 +522,7 @@ describe('pages/clientDB/permission-table-simple/permission-table-simple.vue', (
"where": "create_time > 1613541303576"
})
// console.log('readUserH: ',readUserH);
expect(readUserH.result.data.length).toBeGreaterThan(0)
expect(readUserH.data.length).toBeGreaterThan(0)
// 读取全表数据
const readUserI = await page.callMethod('myFn', {
......@@ -526,7 +530,7 @@ describe('pages/clientDB/permission-table-simple/permission-table-simple.vue', (
"index": 4
})
// console.log('readUserI: ',readUserI);
expect(readUserI.result.data.length).toBeGreaterThanOrEqual(1)
expect(readUserI.data.length).toBeGreaterThanOrEqual(1)
// 仅审核员读取全表数据
const readUserJ = await page.callMethod('myFn', {
......@@ -549,7 +553,7 @@ describe('pages/clientDB/permission-table-simple/permission-table-simple.vue', (
"action": "add_view_count"
})
// console.log('readUserO: ',readUserO);
// expect(readUserO.result.data.length).toBeGreaterThan(0)
// expect(readUserO.data.length).toBeGreaterThan(0)
expect(readUserO.errCode).toBe(0)
})
......@@ -570,7 +574,8 @@ describe('pages/clientDB/permission-table-simple/permission-table-simple.vue', (
"type": "update",
"index": 0
})
expect(updateUserA.result.updated).toBeGreaterThanOrEqual(1)
console.log('updateUserA: ',updateUserA);
// expect(updateUserA.updated).toBeGreaterThanOrEqual(1)
// 禁止任何人更新 除管理员
const updateUserB = await page.callMethod('myFn', {
......@@ -584,14 +589,14 @@ describe('pages/clientDB/permission-table-simple/permission-table-simple.vue', (
"type": "update",
"index": 2
})
expect(updateUserC.result.updated).toBeGreaterThanOrEqual(1)
expect(updateUserC.updated).toBeGreaterThanOrEqual(1)
// 仅更新自己创建的数据 先创建数据
const updateUserD = await page.callMethod('myFn', {
"type": "create",
"index": 3
})
expect(updateUserD.result.id).toHaveLength(24)
expect(updateUserD.id).toHaveLength(24)
// 仅更新自己创建的数据
const updateUserE = await page.callMethod('myFn', {
......@@ -599,7 +604,7 @@ describe('pages/clientDB/permission-table-simple/permission-table-simple.vue', (
"index": 3,
"where": "uid == $env.uid"
})
expect(updateUserE.result.updated).toBeGreaterThanOrEqual(1)
expect(updateUserE.updated).toBeGreaterThanOrEqual(1)
// 更新全部数据
const updateUserF = await page.callMethod('myFn', {
......@@ -607,14 +612,14 @@ describe('pages/clientDB/permission-table-simple/permission-table-simple.vue', (
"index": 3
})
// console.log('updateUserF: ------------------',updateUserF);
expect(updateUserF.result.updated).toBeGreaterThanOrEqual(1)
expect(updateUserF.updated).toBeGreaterThanOrEqual(1)
// 只更新1分钟内创建的数据 先创建数据
const updateUserG = await page.callMethod('myFn', {
"type": "create",
"index": 4
})
expect(updateUserG.result.id).toHaveLength(24)
expect(updateUserG.id).toHaveLength(24)
// 只更新1分钟内创建的数据
const updateUserH = await page.callMethod('myFn', {
......@@ -622,14 +627,14 @@ describe('pages/clientDB/permission-table-simple/permission-table-simple.vue', (
"index": 4,
"where": "create_time > 1613546251521"
})
expect(updateUserH.result.updated).toBeGreaterThanOrEqual(1)
expect(updateUserH.updated).toBeGreaterThanOrEqual(1)
// 更新全部数据
const updateUserI = await page.callMethod('myFn', {
"type": "update",
"index": 4
})
expect(updateUserI.result.updated).toBeGreaterThanOrEqual(1)
expect(updateUserI.updated).toBeGreaterThanOrEqual(1)
// 限审核员更新数据
const updateUserJ = await page.callMethod('myFn', {
......@@ -652,7 +657,7 @@ describe('pages/clientDB/permission-table-simple/permission-table-simple.vue', (
"action": "add_view_count"
})
// console.log('updateUserAction: ',updateUserAction);
expect(updateUserAction.result.updated).toBeGreaterThanOrEqual(1)
expect(updateUserAction.updated).toBeGreaterThanOrEqual(1)
})
it('删除--用户', async () => {
......
......@@ -203,7 +203,7 @@
}
console.log("res: ",res);
this.$refs.alertCode.open(res.result)
return res
return res.result
} catch (err) {
console.log('TODO handle the exception', err);
uni.showModal({
......
......@@ -6,46 +6,36 @@ describe('pages/cloudFunction/cloudFunction.vue', () => {
page = await program.switchTab('/pages/cloudFunction/cloudFunction')
await page.waitFor('view')
})
it('云函数页-检查标题',async()=>{
expect.assertions(1);
const title = await page.$('.title')
expect(await title.text()).toBe('基础示例-云函数');
})
it('添加一条数据',async()=>{
expect.assertions(1);
const addData = await page.callMethod('add')
expect(addData).toBeDefined();
expect(addData).toHaveLength(24);
})
/* it('删除一条数据',async()=>{
it('删除一条数据',async()=>{
expect.assertions(1);
const removeData = await page.callMethod('remove')
//console.log(removeData);
expect(removeData).toBe('成功删除unicloud-test内第一条数据');
}) */
})
it('修改数据',async()=>{
expect.assertions(1);
const updateData = await page.callMethod('update')
expect(updateData).toBeDefined();
})
it('查询前10条数据',async()=>{
expect.assertions(1);
const getTenData = await page.callMethod('get')
// expect(getTenData.affectedDocs).toBe(10);
expect(getTenData.length).not.toBeUndefined();
})
it('使用公用模块',async()=>{
expect.assertions(1);
const useCommon = await page.callMethod('useCommon')
const record = {"secret":"abcdefg","version":"1.0.0"}
expect(useCommon).toEqual(record);
})
})
\ No newline at end of file
......@@ -30,11 +30,11 @@
return {}
},
methods: {
add() {
async add() {
uni.showLoading({
title: '处理中...'
})
uniCloud.callFunction({
return await uniCloud.callFunction({
name: 'add',
data: {
product: 'uniCloud',
......@@ -47,6 +47,7 @@
showCancel: false
})
console.log(res)
return res.result.id
}).catch((err) => {
uni.hideLoading()
uni.showModal({
......@@ -54,13 +55,14 @@
showCancel: false
})
console.error(err)
return err
})
},
remove() {
async remove() {
uni.showLoading({
title: '处理中...'
})
uniCloud.callFunction({
return await uniCloud.callFunction({
name: 'remove'
}).then((res) => {
uni.hideLoading()
......@@ -69,6 +71,7 @@
showCancel: false
})
console.log(res)
return res.result.msg
}).catch((err) => {
uni.hideLoading()
uni.showModal({
......@@ -76,13 +79,14 @@
showCancel: false
})
console.error(err)
return err
})
},
update() {
async update() {
uni.showLoading({
title: '处理中...'
})
uniCloud.callFunction({
return await uniCloud.callFunction({
name: 'update',
data: {
product: 'uni-app',
......@@ -95,6 +99,7 @@
showCancel: false
})
console.log(res)
return res.result.msg
}).catch((err) => {
uni.hideLoading()
uni.showModal({
......@@ -102,13 +107,14 @@
showCancel: false
})
console.error(err)
return err
})
},
get() {
async get() {
uni.showLoading({
title: '处理中...'
})
uniCloud.callFunction({
return await uniCloud.callFunction({
name: 'get'
}).then((res) => {
uni.hideLoading()
......@@ -117,6 +123,7 @@
showCancel: false
})
console.log(res)
return res.result.data
}).catch((err) => {
uni.hideLoading()
uni.showModal({
......@@ -124,11 +131,12 @@
showCancel: false
})
console.error(err)
return err
})
},
useCommon() {
async useCommon() {
console.log('请确保自己已经阅读并按照公用模块文档操作 https://uniapp.dcloud.io/uniCloud/cf-common')
uniCloud.callFunction({
return await uniCloud.callFunction({
name: 'use-common'
}).then((res) => {
uni.hideLoading()
......@@ -137,6 +145,7 @@
showCancel: false
})
console.log(res)
return res.result
}).catch((err) => {
uni.hideLoading()
uni.showModal({
......@@ -144,6 +153,7 @@
showCancel: false
})
console.error(err)
return err
})
},
toRedisPage(){
......
// uni-app自动化测试教程: uni-app自动化测试教程: https://uniapp.dcloud.io/collocation/auto/hbuilderx-extension/index
describe('pages/cloudObject/cloudObject.vue', () => {
let page;
beforeAll(async () => {
page = await program.switchTab('/pages/cloudObject/cloudObject')
await page.waitFor('view');
});
it('云对象-检查标题',async()=>{
expect.assertions(1);
const title = await page.$('.title')
expect(await title.text()).toBe('基础示例-云对象');
})
it('新增一条数据',async()=>{
expect.assertions(1);
const addData = await page.callMethod('add')
expect(addData).toBeDefined();
expect(addData).toHaveLength(24);
})
it('删除一条数据',async()=>{
expect.assertions(1);
const removeData = await page.callMethod('remove')
expect(removeData).toBe('成功删除unicloud-test内第一条数据');
})
it('修改数据',async()=>{
expect.assertions(1);
const updateData = await page.callMethod('update')
expect(updateData).toBeDefined();
})
it('查询前10条数据',async()=>{
expect.assertions(1);
const getTenData = await page.callMethod('get')
expect(getTenData.data.length).toBeGreaterThanOrEqual(1);
})
it('使用公用模块',async()=>{
expect.assertions(1);
const useCommon = await page.callMethod('useCommon')
const record = {"secret":"abcdefg","version":"1.0.0"}
expect(useCommon).toEqual(record);
})
});
......@@ -45,11 +45,11 @@
}
},
methods: {
add() {
async add() {
uni.showLoading({
title: '处理中...'
})
cloudObjectDemo.add({
return await cloudObjectDemo.add({
product: 'uniCloud',
create_time: Date.now()
}).then((res) => {
......@@ -59,6 +59,7 @@
content: `成功添加一条数据,文档id为:${res.id}`,
showCancel: false
})
return res.id
}).catch((err) => {
console.error(err)
uni.hideLoading()
......@@ -66,19 +67,21 @@
content: `添加数据失败,错误信息为:${err.message}`,
showCancel: false
})
return err
})
},
remove() {
async remove() {
uni.showLoading({
title: '处理中...'
})
cloudObjectDemo.remove().then((res) => {
return await cloudObjectDemo.remove().then((res) => {
console.log(res)
uni.hideLoading()
uni.showModal({
content: res.msg,
showCancel: false
})
return res.msg
}).catch((err) => {
uni.hideLoading()
uni.showModal({
......@@ -86,13 +89,14 @@
showCancel: false
})
console.error(err)
return err
})
},
update() {
async update() {
uni.showLoading({
title: '处理中...'
})
cloudObjectDemo.update({
return await cloudObjectDemo.update({
product: 'uni-app',
create_time: Date.now()
}).then((res) => {
......@@ -102,6 +106,7 @@
showCancel: false
})
console.log(res)
return res.msg
}).catch((err) => {
uni.hideLoading()
uni.showModal({
......@@ -109,19 +114,21 @@
showCancel: false
})
console.error(err)
return err
})
},
get() {
async get() {
uni.showLoading({
title: '处理中...'
})
cloudObjectDemo.get().then((res) => {
return await cloudObjectDemo.get().then((res) => {
uni.hideLoading()
uni.showModal({
content: `查询成功,获取数据列表为:${JSON.stringify(res)}`,
showCancel: false
})
console.log(res)
return res
}).catch((err) => {
uni.hideLoading()
uni.showModal({
......@@ -129,16 +136,18 @@
showCancel: false
})
console.error(err)
return err
})
},
useCommon() {
cloudObjectDemo.useCommon().then((res) => {
async useCommon() {
return await cloudObjectDemo.useCommon().then((res) => {
uni.hideLoading()
uni.showModal({
content: '云对象使用公共模块返回结果:' + JSON.stringify(res),
showCancel: false
})
console.log(res)
return res
}).catch((err) => {
uni.hideLoading()
uni.showModal({
......@@ -146,6 +155,7 @@
showCancel: false
})
console.error(err)
return err
})
},
toRedisPage() {
......
describe('pages/storage/ext-storage-qiniu.vue', () => {
let page
let page,platform;
beforeAll(async () => {
// 重新reLaunch至首页,并获取首页page对象(其中 program 是uni-automator自动注入的全局对象)
page = await program.navigateTo('/pages/storage/ext-storage-qiniu')
await page.waitFor('view')
await page.setData({'isTest':true})
platform = process.env.UNI_PLATFORM
})
it('qiniu-storage-上传文件', async () => {
expect.assertions(2);
......@@ -29,6 +30,7 @@ describe('pages/storage/ext-storage-qiniu.vue', () => {
expectText(res.fileURL,'https://')
})
it('获取私有文件临时下载链接', async () => {
if(platform === "mp-weixin" || process.env.UNI_PLATFORM.startsWith("app")){return;}
expect.assertions(3);
expectText(await page.data('privateFileID'),'qiniu://jest')
const res = await page.callMethod('getTempFileURL')
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册