From de8dc5a9b4b1d14cf53173b9728edb7d6aff289c Mon Sep 17 00:00:00 2001 From: duqingquan Date: Sat, 7 Oct 2023 17:48:36 +0800 Subject: [PATCH] =?UTF-8?q?sotrage=20=E5=AE=8C=E5=96=84=E6=B5=8B=E8=AF=95?= =?UTF-8?q?=E7=A4=BA=E4=BE=8B=EF=BC=8C=E8=A6=86=E7=9B=96=E5=85=A8=E9=83=A8?= =?UTF-8?q?api?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pages/API/storage/storage.test.js | 137 ++++++++++++++++++++++++++++-- pages/API/storage/storage.uvue | 24 +++--- 2 files changed, 141 insertions(+), 20 deletions(-) diff --git a/pages/API/storage/storage.test.js b/pages/API/storage/storage.test.js index 86b33067..d50ec89d 100644 --- a/pages/API/storage/storage.test.js +++ b/pages/API/storage/storage.test.js @@ -32,6 +32,23 @@ describe('ExtApi-StorageInfoTest', () => { await page.waitFor(600) 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({ key: "autotest_key_mock", data:1100.8989 @@ -43,6 +60,23 @@ describe('ExtApi-StorageInfoTest', () => { await page.waitFor(600) 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({ key: "autotest_key_mock", data:123456789 @@ -71,16 +105,20 @@ describe('ExtApi-StorageInfoTest', () => { await page.setData({ key: "autotest_key_mock", - data:"长安大道连狭斜,青牛白马七香车。玉辇纵横过主第,金鞭络绎向侯家。龙衔宝盖承朝日,凤吐流苏带晚霞。百尺游丝争绕树,一群娇鸟共啼花。游蜂戏蝶千门侧,碧树银台万种色。复道交窗作合欢,双阙连甍垂凤翼。" + data:{ + name:"zhangsan", + age:122 + } }) await page.waitFor(600) - const btnSetStorageButtonInfo2 = await page.$('.btn-setstorageSync') - await btnSetStorageButtonInfo2.tap() + await btnSetStorageButtonInfo.tap() await page.waitFor(600) - const btnGetStorageButtonInfo2 = await page.$('.btn-getstorageSync') - await btnGetStorageButtonInfo2.tap() + await btnGetStorageButtonInfo.tap() 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', () => { data:"长安大道连狭斜,青牛白马七香车。玉辇纵横过主第,金鞭络绎向侯家。龙衔宝盖承朝日,凤吐流苏带晚霞。百尺游丝争绕树,一群娇鸟共啼花。游蜂戏蝶千门侧,碧树银台万种色。复道交窗作合欢,双阙连甍垂凤翼。" }) await page.waitFor(600) - const btnSetStorageButtonInfo = await page.$('.btn-setstorageSync') + let btnSetStorageButtonInfo = await page.$('.btn-setstorageSync') await btnSetStorageButtonInfo.tap() await page.waitFor(600) - const btnGetStorageButtonInfo = await page.$('.btn-getstorageSync') + let btnGetStorageButtonInfo = await page.$('.btn-getstorageSync') await btnGetStorageButtonInfo.tap() await page.waitFor(600) 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") + + + + }); - + }); diff --git a/pages/API/storage/storage.uvue b/pages/API/storage/storage.uvue index c6a229ff..65d7a5d4 100644 --- a/pages/API/storage/storage.uvue +++ b/pages/API/storage/storage.uvue @@ -39,12 +39,12 @@ - - + {{ storageInfo }} @@ -90,8 +90,8 @@ 存储数据-异步 - - + + @@ -103,10 +103,10 @@ 存储数据-同步 - - @@ -131,15 +131,17 @@ export default { methods: { getStorageInfo() { uni.getStorageInfo({ - success: function (res) { + success: function (res) { + this.apiGetData = res this.storageInfo = JSON.stringify(res) }, }) }, getStorageInfoSync() { try { - const res = uni.getStorageInfoSync() - this.storageInfo = JSON.stringify(res) + const res = uni.getStorageInfoSync() + this.apiGetData = res + this.storageInfo = JSON.stringify(res) } catch (e) { // error console.log(e) -- GitLab