Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
DCloud
hello uni-app x
提交
bd12ea18
H
hello uni-app x
项目概览
DCloud
/
hello uni-app x
通知
5995
Star
90
Fork
162
代码
文件
提交
分支
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看板
提交
bd12ea18
编写于
10月 19, 2023
作者:
H
hdx
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
feat(unicloud-db组件): 新增自动化测试
上级
d8e4ac79
变更
3
显示空白变更内容
内联
并排
Showing
3 changed file
with
251 addition
and
0 deletion
+251
-0
pages/component/unicloud-db/unicloud-db.test.js
pages/component/unicloud-db/unicloud-db.test.js
+31
-0
pages/component/unicloud-db/unicloud-db.uvue
pages/component/unicloud-db/unicloud-db.uvue
+180
-0
uniCloud-aliyun/database/unicloud-db-test.schema.json
uniCloud-aliyun/database/unicloud-db-test.schema.json
+40
-0
未找到文件。
pages/component/unicloud-db/unicloud-db.test.js
0 → 100644
浏览文件 @
bd12ea18
const
PAGE_PATH
=
'
/pages/unicloud-db/unicloud-db
'
describe
(
'
unicloud-db
'
,
()
=>
{
let
page
beforeAll
(
async
()
=>
{
page
=
await
program
.
reLaunch
(
PAGE_PATH
)
await
page
.
waitFor
(
500
)
})
it
(
'
add/get/update/remove
'
,
async
()
=>
{
await
page
.
callMethod
(
'
add
'
)
await
page
.
waitFor
(
3000
)
const
{
$addResult
}
=
await
page
.
data
()
expect
(
$addResult
[
'
id
'
].
length
>
0
).
toBe
(
true
)
await
page
.
callMethod
(
'
update
'
,
$addResult
[
'
id
'
])
await
page
.
waitFor
(
3000
)
const
{
$updateResult
}
=
await
page
.
data
()
expect
(
$updateResult
[
'
updated
'
]).
toBe
(
1
)
await
page
.
callMethod
(
'
remove
'
,
$addResult
[
'
id
'
])
await
page
.
waitFor
(
3000
)
const
{
$removeResult
}
=
await
page
.
data
()
expect
(
$removeResult
[
'
deleted
'
]).
toBe
(
1
)
})
})
\ No newline at end of file
pages/component/unicloud-db/unicloud-db.uvue
0 → 100644
浏览文件 @
bd12ea18
<template>
<view class="content">
<unicloud-db ref="udb" class="unicloud-db" v-slot:default="{data, pagination, loading, error}"
:collection="collection" :getcount="true" loadtime="manual">
<list-view v-if="data.length>0" ref="listView" class="list" :scroll-y="true" @scrolltolower="loadMore()">
<list-item class="list-item" v-for="(item, _) in data">
<view class="list-item-fill">
<text>{{item}}</text>
</view>
<view>
<text class="list-item-remove" @click="remove(item.getString('_id')!)">❌</text>
</view>
</list-item>
</list-view>
<text class="loading" v-if="loading">Loading...</text>
<view class="error" v-if="error!=null">{{error.errMsg}}</view>
<view class="pagination" v-if="data.length>0">
<text class="pagination-item">{{data.length}} / {{pagination.count}}</text>
</view>
</unicloud-db>
<view class="btn-group">
<button class="btn btn-add" @click="add()">Add</button>
<button class="btn btn-get" @click="get()">Get</button>
</view>
</view>
</template>
<script>
const db = uniCloud.databaseForJQL()
export default {
data() {
return {
collection: 'unicloud-db-test',
collectionList: [
db.collection('book').where('name == "水浒传"').getTemp(),
] as UTSJSONObject[],
$uniCloudElement: null as UniCloudDBElement | null,
$isTesting: false,
$addResult: {},
$updateResult: {},
$removeResult: {}
}
},
onReady() {
this.$uniCloudElement = this.$refs['udb'] as UniCloudDBElement
this.get();
},
onPullDownRefresh() {
this.$uniCloudElement!.loadData({
clear: true,
success: (_ : UniCloudDBGetResult) => {
uni.stopPullDownRefresh()
}
})
},
methods: {
loadMore() {
this.$uniCloudElement!.loadMore()
},
get() {
this.$uniCloudElement!.loadData({
clear: true
})
},
add() {
const value = {
title: "title-" + Date.now(),
comment: "comment" + Date.now()
};
this.$uniCloudElement!.add(value, {
showToast: false,
success: (res : UniCloudDBAddResult) => {
this.$addResult = {
id: res.id
};
this.get();
},
fail: (err : any | null) => {
this.showError(err)
}
})
},
update(id : string) {
const value = {
title: "title-" + Date.now(),
comment: "comment" + Date.now()
};
this.$uniCloudElement!.update(id, value, {
showToast: false,
needLoading: true,
needConfirm: false,
loadingTitle: "正在更新...",
success: (res : UniCloudDBUpdateResult) => {
this.$updateResult = {
updated: res.updated
}
},
fail: (err : any | null) => {
this.showError(err)
}
})
},
remove(id : string) {
this.$uniCloudElement!.remove(id, {
showToast: false,
needConfirm: false,
needLoading: false,
success: (res : UniCloudDBRemoveResult) => {
this.$removeResult = {
deleted: res.deleted
}
},
fail: (err : any | null) => {
this.showError(err)
}
})
},
onQueryLoad(data : Array<UTSJSONObject>, ended : boolean, pagination : UTSJSONObject) {
console.log(data, ended, pagination);
},
showError(err : any | null) {
const error = err as UniCloudError
uni.showModal({
content: error.errMsg,
showCancel: false
})
}
}
}
</script>
<style>
.content {
flex: 1;
flex-direction: column;
}
.list {
flex: 1;
flex-direction: column;
}
.list-item {
flex-direction: row;
padding: 10px;
}
.list-item-fill {
flex: 1;
}
.list-item-remove {
padding: 10px;
}
.loading {
padding: 10px;
text-align: center;
}
.pagination {
flex-direction: row;
background-color: #f2f2f2;
}
.pagination-item {
margin: auto;
padding: 5px 10px;
}
.btn-group {
flex-direction: row;
}
.btn {
flex: 1;
margin: 10px;
}
</style>
\ No newline at end of file
uniCloud-aliyun/database/unicloud-db-test.schema.json
0 → 100644
浏览文件 @
bd12ea18
{
"bsonType"
:
"object"
,
"permission"
:
{
"read"
:
true
,
"create"
:
true
,
"update"
:
true
,
"delete"
:
true
},
"required"
:
[
"title"
,
"comment"
],
"properties"
:
{
"_id"
:
{
"description"
:
"存储文档 ID(用户 ID),系统自动生成"
},
"title"
:
{
"bsonType"
:
"string"
,
"title"
:
"姓名"
,
"description"
:
"姓名"
,
"order"
:
1
,
"trim"
:
"both"
},
"comment"
:
{
"bsonType"
:
"string"
,
"title"
:
"备注"
,
"order"
:
5
,
"description"
:
"备注"
,
"trim"
:
"both"
,
"component"
:
{
"name"
:
"textarea"
}
},
"create_date"
:
{
"bsonType"
:
"timestamp"
,
"description"
:
"创建时间"
,
"forceDefaultValue"
:
{
"$env"
:
"now"
}
}
},
"version"
:
"0.0.1"
}
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录