Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
DCloud
hello uni-app x
提交
de8dc5a9
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看板
提交
de8dc5a9
编写于
10月 07, 2023
作者:
杜庆泉
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
sotrage 完善测试示例,覆盖全部api
上级
6c598346
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
141 addition
and
20 deletion
+141
-20
pages/API/storage/storage.test.js
pages/API/storage/storage.test.js
+128
-9
pages/API/storage/storage.uvue
pages/API/storage/storage.uvue
+13
-11
未找到文件。
pages/API/storage/storage.test.js
浏览文件 @
de8dc5a9
...
@@ -32,6 +32,23 @@ describe('ExtApi-StorageInfoTest', () => {
...
@@ -32,6 +32,23 @@ describe('ExtApi-StorageInfoTest', () => {
await
page
.
waitFor
(
600
)
await
page
.
waitFor
(
600
)
expect
(
await
getData
(
'
apiGetData
'
)).
toEqual
(
"
长安大道连狭斜,青牛白马七香车。玉辇纵横过主第,金鞭络绎向侯家。龙衔宝盖承朝日,凤吐流苏带晚霞。百尺游丝争绕树,一群娇鸟共啼花。游蜂戏蝶千门侧,碧树银台万种色。复道交窗作合欢,双阙连甍垂凤翼。
"
)
expect
(
await
getData
(
'
apiGetData
'
)).
toEqual
(
"
长安大道连狭斜,青牛白马七香车。玉辇纵横过主第,金鞭络绎向侯家。龙衔宝盖承朝日,凤吐流苏带晚霞。百尺游丝争绕树,一群娇鸟共啼花。游蜂戏蝶千门侧,碧树银台万种色。复道交窗作合欢,双阙连甍垂凤翼。
"
)
// 测试 clear
let
btnGetStorageInfoASyncButton
=
await
page
.
$
(
'
.btn-getStorageInfoASync
'
)
await
btnGetStorageInfoASyncButton
.
tap
()
await
page
.
waitFor
(
600
)
storageInfoRet
=
await
getData
(
'
apiGetData
'
)
expect
(
storageInfoRet
.
keys
[
0
]).
toEqual
(
"
autotest_key_mock
"
)
const
btnClearStorageInfoASyncButton
=
await
page
.
$
(
'
.btn-clearStorageInfoASync
'
)
await
btnClearStorageInfoASyncButton
.
tap
()
page
.
waitFor
(
600
)
await
btnGetStorageInfoASyncButton
.
tap
()
await
page
.
waitFor
(
600
)
storageInfoRet
=
await
getData
(
'
apiGetData
'
)
expect
(
storageInfoRet
.
keys
.
length
).
toEqual
(
0
)
await
page
.
setData
({
await
page
.
setData
({
key
:
"
autotest_key_mock
"
,
key
:
"
autotest_key_mock
"
,
data
:
1100.8989
data
:
1100.8989
...
@@ -43,6 +60,23 @@ describe('ExtApi-StorageInfoTest', () => {
...
@@ -43,6 +60,23 @@ describe('ExtApi-StorageInfoTest', () => {
await
page
.
waitFor
(
600
)
await
page
.
waitFor
(
600
)
expect
(
await
getData
(
'
apiGetData
'
)).
toEqual
(
1100.8989
)
expect
(
await
getData
(
'
apiGetData
'
)).
toEqual
(
1100.8989
)
// 测试 remove
await
btnGetStorageInfoASyncButton
.
tap
()
await
page
.
waitFor
(
600
)
storageInfoRet
=
await
getData
(
'
apiGetData
'
)
expect
(
storageInfoRet
.
keys
[
0
]).
toEqual
(
"
autotest_key_mock
"
)
const
btnRemoveStorageInfoASyncButton
=
await
page
.
$
(
'
.btn-removeStorageInfoASync
'
)
await
btnRemoveStorageInfoASyncButton
.
tap
()
page
.
waitFor
(
600
)
await
btnGetStorageInfoASyncButton
.
tap
()
await
page
.
waitFor
(
600
)
storageInfoRet
=
await
getData
(
'
apiGetData
'
)
expect
(
storageInfoRet
.
keys
.
length
).
toEqual
(
0
)
await
page
.
setData
({
await
page
.
setData
({
key
:
"
autotest_key_mock
"
,
key
:
"
autotest_key_mock
"
,
data
:
123456789
data
:
123456789
...
@@ -71,16 +105,20 @@ describe('ExtApi-StorageInfoTest', () => {
...
@@ -71,16 +105,20 @@ describe('ExtApi-StorageInfoTest', () => {
await
page
.
setData
({
await
page
.
setData
({
key
:
"
autotest_key_mock
"
,
key
:
"
autotest_key_mock
"
,
data
:
"
长安大道连狭斜,青牛白马七香车。玉辇纵横过主第,金鞭络绎向侯家。龙衔宝盖承朝日,凤吐流苏带晚霞。百尺游丝争绕树,一群娇鸟共啼花。游蜂戏蝶千门侧,碧树银台万种色。复道交窗作合欢,双阙连甍垂凤翼。
"
data
:{
name
:
"
zhangsan
"
,
age
:
122
}
})
})
await
page
.
waitFor
(
600
)
await
page
.
waitFor
(
600
)
const
btnSetStorageButtonInfo2
=
await
page
.
$
(
'
.btn-setstorageSync
'
)
await
btnSetStorageButtonInfo
.
tap
()
await
btnSetStorageButtonInfo2
.
tap
()
await
page
.
waitFor
(
600
)
await
page
.
waitFor
(
600
)
const
btnGetStorageButtonInfo2
=
await
page
.
$
(
'
.btn-getstorageSync
'
)
await
btnGetStorageButtonInfo
.
tap
()
await
btnGetStorageButtonInfo2
.
tap
()
await
page
.
waitFor
(
600
)
await
page
.
waitFor
(
600
)
expect
(
await
getData
(
'
apiGetData
'
)).
toEqual
(
"
长安大道连狭斜,青牛白马七香车。玉辇纵横过主第,金鞭络绎向侯家。龙衔宝盖承朝日,凤吐流苏带晚霞。百尺游丝争绕树,一群娇鸟共啼花。游蜂戏蝶千门侧,碧树银台万种色。复道交窗作合欢,双阙连甍垂凤翼。
"
)
let
objRet
=
await
getData
(
'
apiGetData
'
)
expect
(
objRet
.
age
).
toEqual
(
122
)
});
});
...
@@ -93,14 +131,95 @@ describe('ExtApi-StorageInfoTest', () => {
...
@@ -93,14 +131,95 @@ describe('ExtApi-StorageInfoTest', () => {
data
:
"
长安大道连狭斜,青牛白马七香车。玉辇纵横过主第,金鞭络绎向侯家。龙衔宝盖承朝日,凤吐流苏带晚霞。百尺游丝争绕树,一群娇鸟共啼花。游蜂戏蝶千门侧,碧树银台万种色。复道交窗作合欢,双阙连甍垂凤翼。
"
data
:
"
长安大道连狭斜,青牛白马七香车。玉辇纵横过主第,金鞭络绎向侯家。龙衔宝盖承朝日,凤吐流苏带晚霞。百尺游丝争绕树,一群娇鸟共啼花。游蜂戏蝶千门侧,碧树银台万种色。复道交窗作合欢,双阙连甍垂凤翼。
"
})
})
await
page
.
waitFor
(
600
)
await
page
.
waitFor
(
600
)
cons
t
btnSetStorageButtonInfo
=
await
page
.
$
(
'
.btn-setstorageSync
'
)
le
t
btnSetStorageButtonInfo
=
await
page
.
$
(
'
.btn-setstorageSync
'
)
await
btnSetStorageButtonInfo
.
tap
()
await
btnSetStorageButtonInfo
.
tap
()
await
page
.
waitFor
(
600
)
await
page
.
waitFor
(
600
)
cons
t
btnGetStorageButtonInfo
=
await
page
.
$
(
'
.btn-getstorageSync
'
)
le
t
btnGetStorageButtonInfo
=
await
page
.
$
(
'
.btn-getstorageSync
'
)
await
btnGetStorageButtonInfo
.
tap
()
await
btnGetStorageButtonInfo
.
tap
()
await
page
.
waitFor
(
600
)
await
page
.
waitFor
(
600
)
expect
(
await
getData
(
'
apiGetData
'
)).
toEqual
(
"
长安大道连狭斜,青牛白马七香车。玉辇纵横过主第,金鞭络绎向侯家。龙衔宝盖承朝日,凤吐流苏带晚霞。百尺游丝争绕树,一群娇鸟共啼花。游蜂戏蝶千门侧,碧树银台万种色。复道交窗作合欢,双阙连甍垂凤翼。
"
)
expect
(
await
getData
(
'
apiGetData
'
)).
toEqual
(
"
长安大道连狭斜,青牛白马七香车。玉辇纵横过主第,金鞭络绎向侯家。龙衔宝盖承朝日,凤吐流苏带晚霞。百尺游丝争绕树,一群娇鸟共啼花。游蜂戏蝶千门侧,碧树银台万种色。复道交窗作合欢,双阙连甍垂凤翼。
"
)
// 测试clear
const
btnGetStorageInfoSyncButton
=
await
page
.
$
(
'
.btn-getStorageInfoSync
'
)
await
btnGetStorageInfoSyncButton
.
tap
()
await
page
.
waitFor
(
600
)
let
storageInfoRet
=
await
getData
(
'
apiGetData
'
)
expect
(
storageInfoRet
.
keys
[
0
]).
toEqual
(
"
autotest_key_mock
"
)
const
btnClearStorageInfoSyncButton
=
await
page
.
$
(
'
.btn-clearStorageInfoSync
'
)
await
btnClearStorageInfoSyncButton
.
tap
()
await
btnGetStorageInfoSyncButton
.
tap
()
await
page
.
waitFor
(
600
)
storageInfoRet
=
await
getData
(
'
apiGetData
'
)
expect
(
storageInfoRet
.
keys
.
length
).
toEqual
(
0
)
await
page
.
setData
({
key
:
"
autotest_key_mock
"
,
data
:
12345789.235689
})
await
page
.
waitFor
(
600
)
btnSetStorageButtonInfo
=
await
page
.
$
(
'
.btn-setstorageSync
'
)
await
btnSetStorageButtonInfo
.
tap
()
await
page
.
waitFor
(
600
)
btnGetStorageButtonInfo
=
await
page
.
$
(
'
.btn-getstorageSync
'
)
await
btnGetStorageButtonInfo
.
tap
()
await
page
.
waitFor
(
600
)
expect
(
await
getData
(
'
apiGetData
'
)).
toEqual
(
12345789.235689
)
// 测试 remove
await
btnGetStorageInfoSyncButton
.
tap
()
await
page
.
waitFor
(
600
)
storageInfoRet
=
await
getData
(
'
apiGetData
'
)
expect
(
storageInfoRet
.
keys
[
0
]).
toEqual
(
"
autotest_key_mock
"
)
const
btnRemoveStorageInfoSyncButton
=
await
page
.
$
(
'
.btn-removeStorageInfoSync
'
)
await
btnRemoveStorageInfoSyncButton
.
tap
()
page
.
waitFor
(
600
)
await
btnGetStorageInfoSyncButton
.
tap
()
await
page
.
waitFor
(
600
)
storageInfoRet
=
await
getData
(
'
apiGetData
'
)
expect
(
storageInfoRet
.
keys
.
length
).
toEqual
(
0
)
await
page
.
setData
({
key
:
"
autotest_key_mock
"
,
data
:
0
})
await
page
.
waitFor
(
600
)
btnSetStorageButtonInfo
=
await
page
.
$
(
'
.btn-setstorageSync
'
)
await
btnSetStorageButtonInfo
.
tap
()
await
page
.
waitFor
(
600
)
btnGetStorageButtonInfo
=
await
page
.
$
(
'
.btn-getstorageSync
'
)
await
btnGetStorageButtonInfo
.
tap
()
await
page
.
waitFor
(
600
)
expect
(
await
getData
(
'
apiGetData
'
)).
toEqual
(
0
)
await
page
.
setData
({
key
:
"
autotest_key_mock
"
,
data
:{
name
:
"
tom
"
,
age
:
10
}
})
await
page
.
waitFor
(
600
)
btnSetStorageButtonInfo
=
await
page
.
$
(
'
.btn-setstorageSync
'
)
await
btnSetStorageButtonInfo
.
tap
()
await
page
.
waitFor
(
600
)
btnGetStorageButtonInfo
=
await
page
.
$
(
'
.btn-getstorageSync
'
)
await
btnGetStorageButtonInfo
.
tap
()
await
page
.
waitFor
(
600
)
let
objRet
=
await
getData
(
'
apiGetData
'
)
expect
(
objRet
.
name
).
toEqual
(
"
tom
"
)
});
});
});
});
pages/API/storage/storage.uvue
浏览文件 @
de8dc5a9
...
@@ -39,12 +39,12 @@
...
@@ -39,12 +39,12 @@
</view>
</view>
<view class="uni-padding-wrap">
<view class="uni-padding-wrap">
<view class="uni-btn-v">
<view class="uni-btn-v">
<button class="uni-btn" type="primary" @tap="getStorageInfo">
<button class="uni-btn btn-getStorageInfoASync" type="primary" @tap="getStorageInfo">
获取存储概述-同步
</button>
<button class="uni-btn" @tap="getStorageInfoSync">
获取存储概述-异步
获取存储概述-异步
</button>
</button>
<button class="uni-btn btn-getStorageInfoSync" @tap="getStorageInfoSync">
获取存储概述-同步
</button>
</view>
</view>
<text>{{ storageInfo }}</text>
<text>{{ storageInfo }}</text>
<view class="uni-flex uni-row">
<view class="uni-flex uni-row">
...
@@ -90,8 +90,8 @@
...
@@ -90,8 +90,8 @@
存储数据-异步
存储数据-异步
</button>
</button>
<button class="uni-btn btn-getstorageAsync" @tap="getStorage">读取数据-异步</button>
<button class="uni-btn btn-getstorageAsync" @tap="getStorage">读取数据-异步</button>
<button class="uni-btn" @tap="removeStorage">移除数据-异步</button>
<button class="uni-btn
btn-removeStorageInfoASync
" @tap="removeStorage">移除数据-异步</button>
<button class="uni-btn" @tap="clearStorage">清理数据-异步</button>
<button class="uni-btn
btn-clearStorageInfoASync
" @tap="clearStorage">清理数据-异步</button>
</view>
</view>
<view class="uni-btn-v">
<view class="uni-btn-v">
...
@@ -103,10 +103,10 @@
...
@@ -103,10 +103,10 @@
存储数据-同步
存储数据-同步
</button>
</button>
<button class="uni-btn btn-getstorageSync" @tap="getStorageSync">读取数据-同步</button>
<button class="uni-btn btn-getstorageSync" @tap="getStorageSync">读取数据-同步</button>
<button class="uni-btn" @tap="removeStorageSync">
<button class="uni-btn
btn-removeStorageInfoSync
" @tap="removeStorageSync">
移除数据-同步
移除数据-同步
</button>
</button>
<button class="uni-btn" @tap="clearStorageSync">
<button class="uni-btn
btn-clearStorageInfoSync
" @tap="clearStorageSync">
清理数据-同步
清理数据-同步
</button>
</button>
</view>
</view>
...
@@ -131,15 +131,17 @@ export default {
...
@@ -131,15 +131,17 @@ export default {
methods: {
methods: {
getStorageInfo() {
getStorageInfo() {
uni.getStorageInfo({
uni.getStorageInfo({
success: function (res) {
success: function (res) {
this.apiGetData = res
this.storageInfo = JSON.stringify(res)
this.storageInfo = JSON.stringify(res)
},
},
})
})
},
},
getStorageInfoSync() {
getStorageInfoSync() {
try {
try {
const res = uni.getStorageInfoSync()
const res = uni.getStorageInfoSync()
this.storageInfo = JSON.stringify(res)
this.apiGetData = res
this.storageInfo = JSON.stringify(res)
} catch (e) {
} catch (e) {
// error
// error
console.log(e)
console.log(e)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录