提交 1992f23f 编写于 作者: 雪洛's avatar 雪洛

fix: 引崩溃问题移除自动化测试期间的弹框

上级 cfea7098
...@@ -5,6 +5,9 @@ describe('unicloud-call-function', () => { ...@@ -5,6 +5,9 @@ describe('unicloud-call-function', () => {
beforeAll(async () => { beforeAll(async () => {
page = await program.reLaunch(PAGE_PATH) page = await program.reLaunch(PAGE_PATH)
await page.waitFor(500) await page.waitFor(500)
await page.setData({
isUniTest: true
})
}) })
it('callFunction', async () => { it('callFunction', async () => {
......
<template> <template>
<!-- #ifdef APP --> <!-- #ifdef APP -->
<scroll-view style="flex: 1"> <scroll-view style="flex: 1">
<!-- #endif --> <!-- #endif -->
<view> <view>
<page-head :title="title"></page-head> <page-head :title="title"></page-head>
<view class="uni-padding-wrap uni-common-mt"> <view class="uni-padding-wrap uni-common-mt">
...@@ -10,7 +10,7 @@ ...@@ -10,7 +10,7 @@
</view> </view>
</view> </view>
</view> </view>
<!-- #ifdef APP --> <!-- #ifdef APP -->
</scroll-view> </scroll-view>
<!-- #endif --> <!-- #endif -->
</template> </template>
...@@ -20,7 +20,8 @@ ...@@ -20,7 +20,8 @@
return { return {
title: '请求云函数', title: '请求云函数',
callFunctionResult: {}, callFunctionResult: {},
callFunctionError: {} callFunctionError: {},
isUniTest: false
} }
}, },
onLoad() { onLoad() {
...@@ -28,6 +29,19 @@ ...@@ -28,6 +29,19 @@
onUnload() { onUnload() {
}, },
methods: { methods: {
notify(content : string, title : string) {
if (!this.isUniTest) {
uni.showModal({
title,
content,
showCancel: false
})
} else {
uni.showToast({
title: content
})
}
},
callFunction: function () { callFunction: function () {
uni.showLoading({ uni.showLoading({
title: '加载中...' title: '加载中...'
...@@ -43,23 +57,15 @@ ...@@ -43,23 +57,15 @@
this.callFunctionResult = result this.callFunctionResult = result
console.log(JSON.stringify(result)) console.log(JSON.stringify(result))
uni.hideLoading() uni.hideLoading()
uni.showModal({ this.notify(result['showMessage'] as string, '提示')
title: '提示', }).catch<void>((err : any | null) => {
content: result['showMessage'] as string,
showCancel: false
})
}).catch<void>((err: any | null) => {
const error = err as UniCloudError const error = err as UniCloudError
this.callFunctionError = { this.callFunctionError = {
errCode: error.errCode, errCode: error.errCode,
errMsg: error.errMsg errMsg: error.errMsg
} }
uni.hideLoading() uni.hideLoading()
uni.showModal({ this.notify(error.errMsg, '错误')
title: '错误',
content: error.errMsg,
showCancel: false
})
}) })
} }
} }
...@@ -67,4 +73,4 @@ ...@@ -67,4 +73,4 @@
</script> </script>
<style> <style>
</style> </style>
\ No newline at end of file
...@@ -5,6 +5,9 @@ describe('unicloud-database', () => { ...@@ -5,6 +5,9 @@ describe('unicloud-database', () => {
beforeAll(async () => { beforeAll(async () => {
page = await program.reLaunch(PAGE_PATH) page = await program.reLaunch(PAGE_PATH)
await page.waitFor(500) await page.waitFor(500)
await page.setData({
isUniTest: true
})
}) })
it('databaseBasic', async () => { it('databaseBasic', async () => {
await page.callMethod('dbRemove') await page.callMethod('dbRemove')
......
...@@ -34,6 +34,7 @@ ...@@ -34,6 +34,7 @@
getWithCommandData: [] as Array<UTSJSONObject>, getWithCommandData: [] as Array<UTSJSONObject>,
removeDeleted: 0, removeDeleted: 0,
lookupData: [] as Array<UTSJSONObject>, lookupData: [] as Array<UTSJSONObject>,
isUniTest: false
} }
}, },
onLoad() { onLoad() {
...@@ -41,6 +42,19 @@ ...@@ -41,6 +42,19 @@
onUnload() { onUnload() {
}, },
methods: { methods: {
notify(content : string, title : string) {
if (!this.isUniTest) {
uni.showModal({
title,
content,
showCancel: false
})
} else {
uni.showToast({
title: content
})
}
},
dbAdd: function () { dbAdd: function () {
uni.showLoading({ uni.showLoading({
title: '加载中...' title: '加载中...'
...@@ -57,19 +71,12 @@ ...@@ -57,19 +71,12 @@
uni.hideLoading() uni.hideLoading()
console.log(res) console.log(res)
this.addId = res.id this.addId = res.id
uni.showModal({ this.notify(`新增成功,id: ${res.id}`, '提示')
content: `新增成功,id: ${res.id}`,
showCancel: false
})
}) })
.catch<void>((err : any | null) => { .catch<void>((err : any | null) => {
uni.hideLoading() uni.hideLoading()
const error = err as UniCloudError const error = err as UniCloudError
uni.showModal({ this.notify(error.errMsg, '错误')
title: '错误',
content: error.errMsg,
showCancel: false
})
}) })
}, },
dbBatchAdd() { dbBatchAdd() {
...@@ -88,21 +95,15 @@ ...@@ -88,21 +95,15 @@
.then<void>((res) => { .then<void>((res) => {
uni.hideLoading() uni.hideLoading()
console.log(res) console.log(res)
console.log('JSON.stringify(res.inserted)', JSON.stringify(res.inserted))
this.batchAddIds = res.ids this.batchAddIds = res.ids
this.batchAddinserted = res.inserted this.batchAddinserted = res.inserted
uni.showModal({ this.notify(`新增成功条数${res.inserted}, id列表: ${res.ids.join(',')}`, '提示')
content: `新增成功条数${res.inserted}, id列表: ${res.ids.join(',')}`,
showCancel: false
})
}) })
.catch<void>((err : any | null) => { .catch<void>((err : any | null) => {
uni.hideLoading() uni.hideLoading()
const error = err as UniCloudError const error = err as UniCloudError
uni.showModal({ this.notify(error.errMsg, '错误')
title: '错误',
content: error.errMsg,
showCancel: false
})
}) })
}, },
dbGet() { dbGet() {
...@@ -123,19 +124,12 @@ ...@@ -123,19 +124,12 @@
uni.hideLoading() uni.hideLoading()
console.log(res) console.log(res)
this.getData = res.data this.getData = res.data
uni.showModal({ this.notify(`获取成功,取到了${res.data.length}条数据`, '提示')
content: `获取成功,取到了${res.data.length}条数据`,
showCancel: false
})
}) })
.catch<void>((err : any | null) => { .catch<void>((err : any | null) => {
uni.hideLoading() uni.hideLoading()
const error = err as UniCloudError const error = err as UniCloudError
uni.showModal({ this.notify(error.errMsg, '错误')
title: '错误',
content: error.errMsg,
showCancel: false
})
}) })
}, },
dbGetWithCommand() { dbGetWithCommand() {
...@@ -156,19 +150,12 @@ ...@@ -156,19 +150,12 @@
uni.hideLoading() uni.hideLoading()
console.log(res) console.log(res)
this.getWithCommandData = res.data this.getWithCommandData = res.data
uni.showModal({ this.notify(`获取成功,取到了${res.data.length}条数据`, '提示')
content: `获取成功,取到了${res.data.length}条数据`,
showCancel: false
})
}) })
.catch<void>((err : any | null) => { .catch<void>((err : any | null) => {
uni.hideLoading() uni.hideLoading()
const error = err as UniCloudError const error = err as UniCloudError
uni.showModal({ this.notify(error.errMsg, '错误')
title: '错误',
content: error.errMsg,
showCancel: false
})
}) })
}, },
dbUpdate() { dbUpdate() {
...@@ -187,19 +174,12 @@ ...@@ -187,19 +174,12 @@
uni.hideLoading() uni.hideLoading()
console.log(res) console.log(res)
this.updateUpdated = res.updated this.updateUpdated = res.updated
uni.showModal({ this.notify(`更新成功,更新了${res.updated}条数据`, '提示')
content: `更新成功,更新了${res.updated}条数据`,
showCancel: false
})
}) })
.catch<void>((err : any | null) => { .catch<void>((err : any | null) => {
uni.hideLoading() uni.hideLoading()
const error = err as UniCloudError const error = err as UniCloudError
uni.showModal({ this.notify(error.errMsg, '错误')
title: '错误',
content: error.errMsg,
showCancel: false
})
}) })
}, },
dbRemove() { dbRemove() {
...@@ -216,19 +196,12 @@ ...@@ -216,19 +196,12 @@
uni.hideLoading() uni.hideLoading()
console.log(res) console.log(res)
this.removeDeleted = res.deleted this.removeDeleted = res.deleted
uni.showModal({ this.notify(`删除成功,删掉了${res.deleted}条数据`, '提示')
content: `删除成功,删掉了${res.deleted}条数据`,
showCancel: false
})
}) })
.catch<void>((err : any | null) => { .catch<void>((err : any | null) => {
uni.hideLoading() uni.hideLoading()
const error = err as UniCloudError const error = err as UniCloudError
uni.showModal({ this.notify(error.errMsg, '错误')
title: '错误',
content: error.errMsg,
showCancel: false
})
}) })
}, },
dbLookupInit() { dbLookupInit() {
...@@ -272,20 +245,13 @@ ...@@ -272,20 +245,13 @@
}) })
.then<void>((_) : void => { .then<void>((_) : void => {
uni.hideLoading() uni.hideLoading()
uni.showModal({ this.notify('数据初始化成功', '提示')
content: '数据初始化成功',
showCancel: false
})
}) })
.catch<void>((err : any | null) => { .catch<void>((err : any | null) => {
uni.hideLoading() uni.hideLoading()
console.error(err) console.error(err)
const error = err as UniCloudError const error = err as UniCloudError
uni.showModal({ this.notify(error.errMsg, '错误')
title: '错误',
content: error.errMsg,
showCancel: false
})
}) })
}, },
dbLookup() { dbLookup() {
...@@ -305,19 +271,12 @@ ...@@ -305,19 +271,12 @@
uni.hideLoading() uni.hideLoading()
console.log(res) console.log(res)
this.lookupData = res.data this.lookupData = res.data
uni.showModal({ this.notify(`联表查询成功,取到了${res.data.length}条数据`, '提示')
content: `联表查询成功,取到了${res.data.length}条数据`,
showCancel: false
})
}) })
.catch<void>((err : any | null) => { .catch<void>((err : any | null) => {
uni.hideLoading() uni.hideLoading()
const error = err as UniCloudError const error = err as UniCloudError
uni.showModal({ this.notify(error.errMsg, '错误')
title: '错误',
content: error.errMsg,
showCancel: false
})
}) })
} }
} }
......
...@@ -54,9 +54,9 @@ ...@@ -54,9 +54,9 @@
showCancel: false showCancel: false
}); });
}) })
// .finally((_: number) : void => { // .finally((_: number) : void => {
// uni.hideLoading() // uni.hideLoading()
// }) // })
}, },
fail(err) : void { fail(err) : void {
console.error('chooseImage fail: ', err) console.error('chooseImage fail: ', err)
...@@ -68,4 +68,4 @@ ...@@ -68,4 +68,4 @@
</script> </script>
<style> <style>
</style> </style>
\ No newline at end of file
...@@ -5,6 +5,9 @@ describe('unicloud-import-object', () => { ...@@ -5,6 +5,9 @@ describe('unicloud-import-object', () => {
beforeAll(async () => { beforeAll(async () => {
page = await program.reLaunch(PAGE_PATH) page = await program.reLaunch(PAGE_PATH)
await page.waitFor(500) await page.waitFor(500)
await page.setData({
isUniTest: true
})
}) })
it('importObject', async () => { it('importObject', async () => {
await page.callMethod('addTodo') await page.callMethod('addTodo')
......
...@@ -34,22 +34,34 @@ ...@@ -34,22 +34,34 @@
returnTodoTitle: '', returnTodoTitle: '',
returnTodoContent: '', returnTodoContent: '',
failErrCode: '', failErrCode: '',
successErrCode: -1 successErrCode: -1,
isUniTest: false
} }
}, },
methods: { methods: {
notify(content : string, title : string) {
if (!this.isUniTest) {
uni.showModal({
title,
content,
showCancel: false
})
} else {
uni.showToast({
title: content
})
}
},
addTodo() { addTodo() {
const todo = uniCloud.importObject('todo') const todo = uniCloud.importObject('todo', {
customUI: this.isUniTest
})
const title = this.todoTitle const title = this.todoTitle
const content = this.todoContent const content = this.todoContent
todo.add(title, content).then<void>((res : UTSJSONObject) : void => { todo.add(title, content).then<void>((res : UTSJSONObject) : void => {
this.returnTodoTitle = res['title'] as string this.returnTodoTitle = res['title'] as string
this.returnTodoContent = res['content'] as string this.returnTodoContent = res['content'] as string
uni.showModal({ this.notify(res['showMessage'] as string, '提示')
title: '提示',
content: res['showMessage'] as string,
showCancel: false
})
}).catch<void>((err : any | null) : void => { }).catch<void>((err : any | null) : void => {
const error = err as UniCloudError const error = err as UniCloudError
console.error(error) console.error(error)
...@@ -62,40 +74,37 @@ ...@@ -62,40 +74,37 @@
} }
}) })
todoObj.randomFail().then<void>((res : UTSJSONObject) : void => { todoObj.randomFail().then<void>((res : UTSJSONObject) : void => {
uni.showModal({ this.notify(res['showMessage'] as string, '提示')
title: '提示',
content: res['showMessage'] as string,
showCancel: false
})
}).catch<void>((err : any | null) : void => { }).catch<void>((err : any | null) : void => {
const error = err as UniCloudError const error = err as UniCloudError
console.error(error) console.error(error)
}) })
}, },
fail() { fail() {
const todo = uniCloud.importObject('todo') const todo = uniCloud.importObject('todo', {
customUI: this.isUniTest
})
todo.fail().then<void>((res : UTSJSONObject) : void => { todo.fail().then<void>((res : UTSJSONObject) : void => {
uni.showModal({ this.notify('todo.fail应调用失败,此处错误的触发了成功回调', '错误')
title: '提示',
content: 'todo.fail应调用失败,此处错误的触发了成功回调',
showCancel: false
})
console.log('todo.fail: ', res); console.log('todo.fail: ', res);
}).catch<void>((err : any | null) : void => { }).catch<void>((err : any | null) : void => {
const error = err as UniCloudError const error = err as UniCloudError
this.failErrCode = error.errCode as string this.failErrCode = error.errCode as string
console.error(error) console.error(error)
if (this.isUniTest) {
uni.showToast({
title: err.errMsg
})
}
}) })
}, },
success() { success() {
const todo = uniCloud.importObject('todo') const todo = uniCloud.importObject('todo', {
customUI: this.isUniTest
})
todo.success().then<void>((res : UTSJSONObject) : void => { todo.success().then<void>((res : UTSJSONObject) : void => {
this.successErrCode = res['errCode'] as number this.successErrCode = res['errCode'] as number
uni.showModal({ this.notify(res['showMessage'] as string, '提示')
title: '提示',
content: res['showMessage'] as string,
showCancel: false
})
}).catch<void>((err : any | null) : void => { }).catch<void>((err : any | null) : void => {
const error = err as UniCloudError const error = err as UniCloudError
console.error(error) console.error(error)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册