From e3a85d04258e6d7174093fd94d8e9d46c0d76f12 Mon Sep 17 00:00:00 2001 From: duqingquan Date: Wed, 27 Sep 2023 20:45:35 +0800 Subject: [PATCH] =?UTF-8?q?storage=20=E5=A2=9E=E5=8A=A0=E9=83=A8=E5=88=86?= =?UTF-8?q?=E7=A4=BA=E4=BE=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- jest.config.js | 2 +- pages/API/storage/storage.test.js | 73 ++++++++++++++++++++++++++++++- pages/API/storage/storage.uvue | 8 ++-- 3 files changed, 77 insertions(+), 6 deletions(-) diff --git a/jest.config.js b/jest.config.js index 0e0eb163..1ce69aa8 100644 --- a/jest.config.js +++ b/jest.config.js @@ -4,7 +4,7 @@ module.exports = { watchPathIgnorePatterns: ['/node_modules/', '/dist/', '/.git/'], moduleFileExtensions: ['js', 'json'], rootDir: __dirname, - testMatch: ["/pages/**/*test.[jt]s?(x)"], + testMatch: ["/pages/API/storage/storage.test.js"], testPathIgnorePatterns: ['/node_modules/'], setupFilesAfterEnv: ['/jest-setup.js'], } diff --git a/pages/API/storage/storage.test.js b/pages/API/storage/storage.test.js index 7662f6f6..86b33067 100644 --- a/pages/API/storage/storage.test.js +++ b/pages/API/storage/storage.test.js @@ -17,7 +17,8 @@ describe('ExtApi-StorageInfoTest', () => { await page.waitFor(600); }); - it('Check properties', async () => { + it('Check async properties', async () => { + // 异步存储测试 await page.setData({ key: "autotest_key_mock", data:"长安大道连狭斜,青牛白马七香车。玉辇纵横过主第,金鞭络绎向侯家。龙衔宝盖承朝日,凤吐流苏带晚霞。百尺游丝争绕树,一群娇鸟共啼花。游蜂戏蝶千门侧,碧树银台万种色。复道交窗作合欢,双阙连甍垂凤翼。" @@ -31,5 +32,75 @@ describe('ExtApi-StorageInfoTest', () => { await page.waitFor(600) expect(await getData('apiGetData')).toEqual("长安大道连狭斜,青牛白马七香车。玉辇纵横过主第,金鞭络绎向侯家。龙衔宝盖承朝日,凤吐流苏带晚霞。百尺游丝争绕树,一群娇鸟共啼花。游蜂戏蝶千门侧,碧树银台万种色。复道交窗作合欢,双阙连甍垂凤翼。") + await page.setData({ + key: "autotest_key_mock", + data:1100.8989 + }) + await page.waitFor(600) + await btnSetStorageButtonInfo.tap() + await page.waitFor(600) + await btnGetStorageButtonInfo.tap() + await page.waitFor(600) + expect(await getData('apiGetData')).toEqual(1100.8989) + + await page.setData({ + key: "autotest_key_mock", + data:123456789 + }) + await page.waitFor(600) + await btnSetStorageButtonInfo.tap() + await page.waitFor(600) + await btnGetStorageButtonInfo.tap() + await page.waitFor(600) + expect(await getData('apiGetData')).toEqual(123456789) + + let userObj = { + name:"zhangsan", + age:12 + } + await page.setData({ + key: "autotest_key_mock", + data:userObj + }) + await page.waitFor(600) + await btnSetStorageButtonInfo.tap() + await page.waitFor(600) + await btnGetStorageButtonInfo.tap() + await page.waitFor(600) + expect(await getData('apiGetData')).toEqual(userObj) + + await page.setData({ + key: "autotest_key_mock", + data:"长安大道连狭斜,青牛白马七香车。玉辇纵横过主第,金鞭络绎向侯家。龙衔宝盖承朝日,凤吐流苏带晚霞。百尺游丝争绕树,一群娇鸟共啼花。游蜂戏蝶千门侧,碧树银台万种色。复道交窗作合欢,双阙连甍垂凤翼。" + }) + await page.waitFor(600) + const btnSetStorageButtonInfo2 = await page.$('.btn-setstorageSync') + await btnSetStorageButtonInfo2.tap() + await page.waitFor(600) + const btnGetStorageButtonInfo2 = await page.$('.btn-getstorageSync') + await btnGetStorageButtonInfo2.tap() + await page.waitFor(600) + expect(await getData('apiGetData')).toEqual("长安大道连狭斜,青牛白马七香车。玉辇纵横过主第,金鞭络绎向侯家。龙衔宝盖承朝日,凤吐流苏带晚霞。百尺游丝争绕树,一群娇鸟共啼花。游蜂戏蝶千门侧,碧树银台万种色。复道交窗作合欢,双阙连甍垂凤翼。") + + + }); + + + it('Check sync properties', async () => { + + await page.setData({ + key: "autotest_key_mock", + data:"长安大道连狭斜,青牛白马七香车。玉辇纵横过主第,金鞭络绎向侯家。龙衔宝盖承朝日,凤吐流苏带晚霞。百尺游丝争绕树,一群娇鸟共啼花。游蜂戏蝶千门侧,碧树银台万种色。复道交窗作合欢,双阙连甍垂凤翼。" + }) + await page.waitFor(600) + const btnSetStorageButtonInfo = await page.$('.btn-setstorageSync') + await btnSetStorageButtonInfo.tap() + await page.waitFor(600) + const btnGetStorageButtonInfo = await page.$('.btn-getstorageSync') + await btnGetStorageButtonInfo.tap() + await page.waitFor(600) + expect(await getData('apiGetData')).toEqual("长安大道连狭斜,青牛白马七香车。玉辇纵横过主第,金鞭络绎向侯家。龙衔宝盖承朝日,凤吐流苏带晚霞。百尺游丝争绕树,一群娇鸟共啼花。游蜂戏蝶千门侧,碧树银台万种色。复道交窗作合欢,双阙连甍垂凤翼。") + }); + }); diff --git a/pages/API/storage/storage.uvue b/pages/API/storage/storage.uvue index 90cb83b4..c6a229ff 100644 --- a/pages/API/storage/storage.uvue +++ b/pages/API/storage/storage.uvue @@ -97,12 +97,12 @@ - + @@ -221,10 +221,10 @@ export default { showCancel: false, }) } else { - let ret = uni.getStorageSync(key) + this.apiGetData = uni.getStorageSync(key) uni.showModal({ title: '读取数据成功', - content: "data: '" + JSON.stringify(ret) + "'", + content: "data: '" + JSON.stringify(apiGetData) + "'", showCancel: false, }) } -- GitLab