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

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

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