Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
DCloud
hello uni-app x
提交
9cc987b8
H
hello uni-app x
项目概览
DCloud
/
hello uni-app x
通知
6017
Star
91
Fork
164
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
18
列表
看板
标记
里程碑
合并请求
1
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
H
hello uni-app x
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
18
Issue
18
列表
看板
标记
里程碑
合并请求
1
合并请求
1
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
提交
9cc987b8
编写于
9月 20, 2023
作者:
雪洛
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
feat: uniCloud auto test
上级
a4208d70
变更
7
显示空白变更内容
内联
并排
Showing
7 changed file
with
176 addition
and
30 deletion
+176
-30
pages/API/unicloud-call-function/unicloud-call-function.test.js
...API/unicloud-call-function/unicloud-call-function.test.js
+23
-0
pages/API/unicloud-call-function/unicloud-call-function.uvue
pages/API/unicloud-call-function/unicloud-call-function.uvue
+8
-1
pages/API/unicloud-database/unicloud-database.test.js
pages/API/unicloud-database/unicloud-database.test.js
+58
-0
pages/API/unicloud-database/unicloud-database.uvue
pages/API/unicloud-database/unicloud-database.uvue
+35
-19
pages/API/unicloud-import-object/unicloud-import-object.test.js
...API/unicloud-import-object/unicloud-import-object.test.js
+30
-0
pages/API/unicloud-import-object/unicloud-import-object.uvue
pages/API/unicloud-import-object/unicloud-import-object.uvue
+20
-10
uniCloud-aliyun/cloudfunctions/todo/index.obj.js
uniCloud-aliyun/cloudfunctions/todo/index.obj.js
+2
-0
未找到文件。
pages/API/unicloud-call-function/unicloud-call-function.test.js
0 → 100644
浏览文件 @
9cc987b8
const
PAGE_PATH
=
'
/pages/API/unicloud-call-function/unicloud-call-function
'
describe
(
'
unicloud-call-function
'
,
()
=>
{
let
page
beforeAll
(
async
()
=>
{
page
=
await
program
.
reLaunch
(
PAGE_PATH
)
await
page
.
waitFor
(
500
)
})
it
(
'
callFunction
'
,
async
()
=>
{
await
page
.
callMethod
(
'
callFunction
'
)
await
page
.
waitFor
(
3000
)
const
{
callFunctionResult
,
callFunctionError
}
=
await
page
.
data
()
console
.
error
(
callFunctionResult
)
console
.
error
(
callFunctionError
)
expect
(
callFunctionResult
[
'
showMessage
'
]).
toBe
(
"
Hello uniCloud function
"
)
expect
(
callFunctionResult
[
'
event
'
][
'
num
'
]).
toBe
(
1
)
expect
(
callFunctionResult
[
'
event
'
][
'
str
'
]).
toBe
(
'
ABC
'
)
})
})
pages/API/unicloud-call-function/unicloud-call-function.uvue
浏览文件 @
9cc987b8
...
...
@@ -18,7 +18,9 @@
export default {
data() {
return {
title: '请求云函数'
title: '请求云函数',
callFunctionResult: {},
callFunctionError: {}
}
},
onLoad() {
...
...
@@ -38,6 +40,7 @@
}
}).then<void>(res => {
const result = res.result
this.callFunctionResult = result
console.log(JSON.stringify(result))
uni.hideLoading()
uni.showModal({
...
...
@@ -47,6 +50,10 @@
})
}).catch<void>((err: any | null) => {
const error = err as UniCloudError
this.callFunctionError = {
errCode: error.errCode,
errMsg: error.errMsg
}
uni.hideLoading()
uni.showModal({
title: '错误',
...
...
pages/API/unicloud-database/unicloud-database.test.js
0 → 100644
浏览文件 @
9cc987b8
const
PAGE_PATH
=
'
/pages/API/unicloud-database/unicloud-database
'
describe
(
'
unicloud-database
'
,
()
=>
{
let
page
beforeAll
(
async
()
=>
{
page
=
await
program
.
reLaunch
(
PAGE_PATH
)
await
page
.
waitFor
(
500
)
})
it
(
'
databaseBasic
'
,
async
()
=>
{
await
page
.
callMethod
(
'
dbRemove
'
)
await
page
.
waitFor
(
3000
)
await
page
.
callMethod
(
'
dbAdd
'
)
await
page
.
waitFor
(
1000
)
await
page
.
callMethod
(
'
dbBatchAdd
'
)
await
page
.
waitFor
(
1000
)
await
page
.
callMethod
(
'
dbGet
'
)
await
page
.
waitFor
(
1000
)
await
page
.
callMethod
(
'
dbGetWithCommand
'
)
await
page
.
waitFor
(
1000
)
await
page
.
callMethod
(
'
dbUpdate
'
)
await
page
.
waitFor
(
1000
)
await
page
.
callMethod
(
'
dbRemove
'
)
await
page
.
waitFor
(
1000
)
const
{
addId
,
batchAddIds
,
batchAddinserted
,
updateUpdated
,
getData
,
getWithCommandData
,
removeDeleted
,
}
=
await
page
.
data
()
expect
(
addId
.
length
>
0
).
toBe
(
true
)
expect
(
batchAddIds
.
length
).
toBe
(
2
)
expect
(
batchAddinserted
).
toBe
(
2
)
expect
(
getData
.
length
).
toBe
(
2
)
expect
(
getWithCommandData
.
length
).
toBe
(
2
)
expect
(
updateUpdated
).
toBe
(
3
)
expect
(
removeDeleted
).
toBe
(
3
)
})
it
(
'
databaseLookup
'
,
async
()
=>
{
await
page
.
callMethod
(
'
dbLookupInit
'
)
await
page
.
waitFor
(
1000
)
await
page
.
callMethod
(
'
dbLookup
'
)
await
page
.
waitFor
(
1000
)
const
{
lookupData
}
=
await
page
.
data
()
expect
(
lookupData
.
length
).
toBe
(
2
)
expect
(
lookupData
[
0
][
'
foreign_id
'
].
length
).
toBe
(
1
)
expect
(
lookupData
[
1
][
'
foreign_id
'
].
length
).
toBe
(
1
)
})
});
\ No newline at end of file
pages/API/unicloud-database/unicloud-database.uvue
浏览文件 @
9cc987b8
...
...
@@ -25,7 +25,15 @@
export default {
data() {
return {
title: 'ClientDB'
title: 'ClientDB',
addId: '',
batchAddIds: [] as Array<string>,
batchAddinserted: 0,
updateUpdated: 0,
getData: [] as Array<UTSJSONObject>,
getWithCommandData: [] as Array<UTSJSONObject>,
removeDeleted: 0,
lookupData: [] as Array<UTSJSONObject>,
}
},
onLoad() {
...
...
@@ -48,6 +56,7 @@
.then<void>(res => {
uni.hideLoading()
console.log(res)
this.addId = res.id
uni.showModal({
content: `新增成功,id: ${res.id}`,
showCancel: false
...
...
@@ -79,6 +88,8 @@
.then<void>((res) => {
uni.hideLoading()
console.log(res)
this.batchAddIds = res.ids
this.batchAddinserted = res.inserted
uni.showModal({
content: `新增成功,id列表: ${res.ids.join(',')}`,
showCancel: false
...
...
@@ -94,7 +105,7 @@
})
})
},
db
Update
() {
db
Get
() {
uni.showLoading({
title: '加载中...'
})
...
...
@@ -103,14 +114,17 @@
.where(
'tag == "default-tag"'
)
.update({
num: 4
})
.field('num, tag')
.orderBy('num desc')
.skip(1)
.limit(2)
.get()
.then<void>(res => {
uni.hideLoading()
console.log(res)
this.getData = res.data
uni.showModal({
content: `
更新成功,更新了${res.updated
}条数据`,
content: `
获取成功,取到了${res.data.length
}条数据`,
showCancel: false
})
})
...
...
@@ -124,15 +138,15 @@
})
})
},
dbGet() {
dbGet
WithCommand
() {
uni.showLoading({
title: '加载中...'
})
const db = uniCloud.databaseForJQL()
db.collection('type')
.where(
'tag == "default-tag"'
)
.where(
{
num: db.command.gt(1)
}
)
.field('num, tag')
.orderBy('num desc')
.skip(1)
...
...
@@ -141,6 +155,7 @@
.then<void>(res => {
uni.hideLoading()
console.log(res)
this.getWithCommandData = res.data
uni.showModal({
content: `获取成功,取到了${res.data.length}条数据`,
showCancel: false
...
...
@@ -156,25 +171,24 @@
})
})
},
db
GetWithCommand
() {
db
Update
() {
uni.showLoading({
title: '加载中...'
})
const db = uniCloud.databaseForJQL()
db.collection('type')
.where({
num: db.command.gt(2)
.where(
'tag == "default-tag"'
)
.update({
num: 4
})
.field('num, tag')
.orderBy('num desc')
.skip(1)
.limit(2)
.get()
.then<void>(res => {
uni.hideLoading()
console.log(res)
this.updateUpdated = res.updated
uni.showModal({
content: `
获取成功,取到了${res.data.length
}条数据`,
content: `
更新成功,更新了${res.updated
}条数据`,
showCancel: false
})
})
...
...
@@ -201,6 +215,7 @@
.then<void>(res => {
uni.hideLoading()
console.log(res)
this.removeDeleted = res.deleted
uni.showModal({
content: `删除成功,删掉了${res.deleted}条数据`,
showCancel: false
...
...
@@ -289,6 +304,7 @@
.then<void>(res => {
uni.hideLoading()
console.log(res)
this.lookupData = res.data
uni.showModal({
content: `联表查询成功,取到了${res.data.length}条数据`,
showCancel: false
...
...
pages/API/unicloud-import-object/unicloud-import-object.test.js
0 → 100644
浏览文件 @
9cc987b8
const
PAGE_PATH
=
'
/pages/API/unicloud-import-object/unicloud-import-object
'
describe
(
'
unicloud-import-object
'
,
()
=>
{
let
page
beforeAll
(
async
()
=>
{
page
=
await
program
.
reLaunch
(
PAGE_PATH
)
await
page
.
waitFor
(
500
)
})
it
(
'
importObject
'
,
async
()
=>
{
await
page
.
callMethod
(
'
addTodo
'
)
await
page
.
callMethod
(
'
fail
'
)
await
page
.
callMethod
(
'
success
'
)
await
page
.
waitFor
(
3000
)
const
{
todoTitle
,
todoContent
,
returnTodoTitle
,
returnTodoContent
,
failErrCode
,
successErrCode
,
}
=
await
page
.
data
()
expect
(
returnTodoTitle
).
toBe
(
todoTitle
)
expect
(
returnTodoContent
).
toBe
(
todoContent
)
expect
(
failErrCode
).
toBe
(
'
TEST_ERROR_CODE
'
)
expect
(
successErrCode
).
toBe
(
0
)
})
});
\ No newline at end of file
pages/API/unicloud-import-object/unicloud-import-object.uvue
浏览文件 @
9cc987b8
...
...
@@ -28,15 +28,23 @@
export default {
data() {
return {
title: '请求云对象'
title: '请求云对象',
todoTitle: '学习编程',
todoContent: '熟悉uts语法',
returnTodoTitle: '',
returnTodoContent: '',
failErrCode: '',
successErrCode: -1
}
},
methods: {
addTodo() {
const todo = uniCloud.importObject('todo')
const title = '学习编程'
const content = '熟悉uts语法'
todo.add(title, content).then<void>((res: UTSJSONObject) : void => {
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,
...
...
@@ -53,7 +61,7 @@
retry: true
}
})
todoObj.randomFail().then<void>((res: UTSJSONObject) : void => {
todoObj.randomFail().then<void>((res
: UTSJSONObject) : void => {
uni.showModal({
title: '提示',
content: res['showMessage'] as string,
...
...
@@ -66,7 +74,7 @@
},
fail() {
const todo = uniCloud.importObject('todo')
todo.fail().then<void>((res: UTSJSONObject) : void => {
todo.fail().then<void>((res
: UTSJSONObject) : void => {
uni.showModal({
title: '提示',
content: 'todo.fail应调用失败,此处错误的触发了成功回调',
...
...
@@ -75,12 +83,14 @@
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)
})
},
success() {
const todo = uniCloud.importObject('todo')
todo.success().then<void>((res: UTSJSONObject) : void => {
todo.success().then<void>((res : UTSJSONObject) : void => {
this.successErrCode = res['errCode'] as number
uni.showModal({
title: '提示',
content: res['showMessage'] as string,
...
...
uniCloud-aliyun/cloudfunctions/todo/index.obj.js
浏览文件 @
9cc987b8
...
...
@@ -4,6 +4,8 @@ module.exports = {
async
add
(
title
,
content
)
{
console
.
log
(
title
,
content
)
return
{
title
,
content
,
showMessage
:
`Todo added, title:
${
title
}
, content:
${
content
}
`
}
},
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录