提交 de8dc5a9 编写于 作者: 杜庆泉's avatar 杜庆泉

sotrage 完善测试示例,覆盖全部api

上级 6c598346
...@@ -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)
const btnSetStorageButtonInfo = await page.$('.btn-setstorageSync') let btnSetStorageButtonInfo = await page.$('.btn-setstorageSync')
await btnSetStorageButtonInfo.tap() await btnSetStorageButtonInfo.tap()
await page.waitFor(600) await page.waitFor(600)
const btnGetStorageButtonInfo = await page.$('.btn-getstorageSync') let 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")
}); });
}); });
...@@ -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>
...@@ -132,6 +132,7 @@ export default { ...@@ -132,6 +132,7 @@ export default {
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)
}, },
}) })
...@@ -139,6 +140,7 @@ export default { ...@@ -139,6 +140,7 @@ export default {
getStorageInfoSync() { getStorageInfoSync() {
try { try {
const res = uni.getStorageInfoSync() const res = uni.getStorageInfoSync()
this.apiGetData = res
this.storageInfo = JSON.stringify(res) this.storageInfo = JSON.stringify(res)
} catch (e) { } catch (e) {
// error // error
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册