From 482b642ff457b5a0f3099971ce8465b9a797c563 Mon Sep 17 00:00:00 2001 From: wangyaqi Date: Thu, 14 Dec 2023 15:29:37 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E7=A7=BB=E9=99=A4uniCloud=E7=9B=B8?= =?UTF-8?q?=E5=85=B3=E6=B5=8B=E8=AF=95=E4=BE=8B=E7=9A=84page.waitFor(3000)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../unicloud-call-function.test.js | 1 - .../unicloud-call-function.uvue | 4 +- .../unicloud-database.test.js | 21 ++---- .../unicloud-database/unicloud-database.uvue | 72 ++++++++++--------- .../unicloud-import-object.test.js | 9 ++- .../unicloud-import-object.uvue | 24 +++---- 6 files changed, 63 insertions(+), 68 deletions(-) diff --git a/pages/API/unicloud-call-function/unicloud-call-function.test.js b/pages/API/unicloud-call-function/unicloud-call-function.test.js index ebfa8887..d6716a12 100644 --- a/pages/API/unicloud-call-function/unicloud-call-function.test.js +++ b/pages/API/unicloud-call-function/unicloud-call-function.test.js @@ -12,7 +12,6 @@ describe('unicloud-call-function', () => { it('callFunction', async () => { await page.callMethod('callFunction') - await page.waitFor(3000) const { callFunctionResult, callFunctionError diff --git a/pages/API/unicloud-call-function/unicloud-call-function.uvue b/pages/API/unicloud-call-function/unicloud-call-function.uvue index 8fe004a9..77395a15 100644 --- a/pages/API/unicloud-call-function/unicloud-call-function.uvue +++ b/pages/API/unicloud-call-function/unicloud-call-function.uvue @@ -46,11 +46,11 @@ console.log(title, content) } }, - callFunction: function () { + async callFunction () : Promise { uni.showLoading({ title: '加载中...' }) - uniCloud.callFunction({ + await uniCloud.callFunction({ name: 'echo-cf', data: { num: 1, diff --git a/pages/API/unicloud-database/unicloud-database.test.js b/pages/API/unicloud-database/unicloud-database.test.js index f3ebac83..80855554 100644 --- a/pages/API/unicloud-database/unicloud-database.test.js +++ b/pages/API/unicloud-database/unicloud-database.test.js @@ -11,20 +11,13 @@ describe('unicloud-database', () => { }) it('databaseBasic', async () => { await page.callMethod('dbRemove') - await page.waitFor(3000) await page.callMethod('dbAdd') - await page.waitFor(1500) await page.callMethod('dbBatchAdd') - await page.waitFor(1500) await page.callMethod('dbGet') - await page.waitFor(1500) await page.callMethod('dbGetWithCommand') - await page.waitFor(1500) await page.callMethod('dbUpdate') - await page.waitFor(1500) await page.callMethod('dbRemove') - await page.waitFor(1500) - + const { addId, batchAddIds, @@ -34,7 +27,7 @@ describe('unicloud-database', () => { getWithCommandData, removeDeleted, } = await page.data() - + expect(addId !== '').toBe(true) expect(batchAddIds.length).toBe(2) expect(batchAddinserted).toBe(2) @@ -42,15 +35,13 @@ describe('unicloud-database', () => { expect(getWithCommandData.length).toBe(1) expect(updateUpdated).toBe(3) expect(removeDeleted).toBe(3) - + }) - + it('databaseLookup', async () => { await page.callMethod('dbLookupInit') - await page.waitFor(3000) await page.callMethod('dbLookup') - await page.waitFor(1500) - + const { lookupData } = await page.data() @@ -58,4 +49,4 @@ describe('unicloud-database', () => { expect(lookupData[0]['foreign_id'].length).toBe(1) expect(lookupData[1]['foreign_id'].length).toBe(1) }) -}); \ No newline at end of file +}); diff --git a/pages/API/unicloud-database/unicloud-database.uvue b/pages/API/unicloud-database/unicloud-database.uvue index 03d7344d..8856a206 100644 --- a/pages/API/unicloud-database/unicloud-database.uvue +++ b/pages/API/unicloud-database/unicloud-database.uvue @@ -40,10 +40,15 @@ onLoad() { }, onUnload() { - if(this.isUniTest){ + if (this.isUniTest) { uni.hideToast() } }, + computed: { + dataTag() : string { + return this.isUniTest ? 'default-tag' + Date.now() : 'default-tag' + } + }, methods: { notify(content : string, title : string) { if (!this.isUniTest) { @@ -56,18 +61,18 @@ uni.showToast({ title: content }) - console.log(title, content) + console.error(title, content) } }, - dbAdd: function () { + async dbAdd() : Promise { uni.showLoading({ title: '加载中...' }) const db = uniCloud.databaseForJQL() - db.collection('type') + await db.collection('type') .add({ num: 1, - tag: 'default-tag', + tag: this.dataTag, date: new Date() }) .then(res => { @@ -82,18 +87,18 @@ this.notify(error.errMsg, '错误') }) }, - dbBatchAdd() { + async dbBatchAdd() : Promise { uni.showLoading({ title: '加载中...' }) const db = uniCloud.databaseForJQL() - db.collection('type') + await db.collection('type') .add([{ num: 2, - tag: 'default-tag', + tag: this.dataTag, }, { num: 3, - tag: 'default-tag', + tag: this.dataTag, }]) .then((res) => { uni.hideLoading() @@ -109,14 +114,14 @@ this.notify(error.errMsg, '错误') }) }, - dbGet() { + async dbGet() : Promise { uni.showLoading({ title: '加载中...' }) const db = uniCloud.databaseForJQL() - db.collection('type') + await db.collection('type') .where( - 'tag == "default-tag"' + `tag == "${this.dataTag}"` ) .field('num, tag') .orderBy('num desc') @@ -135,14 +140,15 @@ this.notify(error.errMsg, '错误') }) }, - dbGetWithCommand() { + async dbGetWithCommand() : Promise { uni.showLoading({ title: '加载中...' }) const db = uniCloud.databaseForJQL() - db.collection('type') + await db.collection('type') .where({ - num: db.command.gt(1) + num: db.command.gt(1), + tag: this.dataTag }) .field('num, tag') .orderBy('num desc') @@ -161,14 +167,14 @@ this.notify(error.errMsg, '错误') }) }, - dbUpdate() { + async dbUpdate() : Promise { uni.showLoading({ title: '加载中...' }) const db = uniCloud.databaseForJQL() - db.collection('type') + await db.collection('type') .where( - 'tag == "default-tag"' + `tag == "${this.dataTag}"` ) .update({ num: 4 @@ -185,14 +191,14 @@ this.notify(error.errMsg, '错误') }) }, - dbRemove() { + async dbRemove() : Promise { uni.showLoading({ title: '加载中...' }) const db = uniCloud.databaseForJQL() - db.collection('type') + await db.collection('type') .where( - 'tag == "default-tag"' + `tag == "${this.dataTag}"` ) .remove() .then(res => { @@ -207,17 +213,17 @@ this.notify(error.errMsg, '错误') }) }, - dbLookupInit() { + async dbLookupInit() : Promise { uni.showLoading({ title: '加载中...' }) const db = uniCloud.databaseForJQL() - db.collection('local') - .where('tag == "default-tag"') + await db.collection('local') + .where(`tag == "${this.dataTag}"`) .remove() .then(() : Promise => { return db.collection('foreign') - .where('tag == "default-tag"') + .where(`tag == "${this.dataTag}"`) .remove() }) .then(() : Promise => { @@ -225,12 +231,12 @@ .add([{ id: "local_1", name: "local_1_name", - tag: "default-tag", + tag: this.dataTag, foreign_id: "foreign_1" }, { id: "local_2", name: "local_2_name", - tag: "default-tag", + tag: this.dataTag, foreign_id: "foreign_2" }]) }) @@ -239,11 +245,11 @@ .add([{ id: "foreign_1", name: "foreign_1_name", - tag: "default-tag" + tag: this.dataTag }, { id: "foreign_2", name: "foreign_2_name", - tag: "default-tag" + tag: this.dataTag }]) }) .then((_) : void => { @@ -257,18 +263,18 @@ this.notify(error.errMsg, '错误') }) }, - dbLookup() { + async dbLookup() : Promise { uni.showLoading({ title: '加载中...' }) const db = uniCloud.databaseForJQL() const local = db.collection('local') - .where('tag == "default-tag"') + .where(`tag == "${this.dataTag}"`) .getTemp() const foreign = db.collection('foreign') - .where('tag == "default-tag"') + .where(`tag == "${this.dataTag}"`) .getTemp() - db.collection(local, foreign) + await db.collection(local, foreign) .get() .then(res => { uni.hideLoading() diff --git a/pages/API/unicloud-import-object/unicloud-import-object.test.js b/pages/API/unicloud-import-object/unicloud-import-object.test.js index 5c53f217..5e8662bd 100644 --- a/pages/API/unicloud-import-object/unicloud-import-object.test.js +++ b/pages/API/unicloud-import-object/unicloud-import-object.test.js @@ -13,8 +13,7 @@ describe('unicloud-import-object', () => { await page.callMethod('addTodo') await page.callMethod('fail') await page.callMethod('success') - await page.waitFor(3000) - + const { todoTitle, todoContent, @@ -23,11 +22,11 @@ describe('unicloud-import-object', () => { failErrCode, successErrCode, } = await page.data() - + expect(returnTodoTitle).toBe(todoTitle) expect(returnTodoContent).toBe(todoContent) expect(failErrCode).toBe('TEST_ERROR_CODE') expect(successErrCode).toBe(0) - + }) -}); \ No newline at end of file +}); diff --git a/pages/API/unicloud-import-object/unicloud-import-object.uvue b/pages/API/unicloud-import-object/unicloud-import-object.uvue index f4fb9a87..02ebdb13 100644 --- a/pages/API/unicloud-import-object/unicloud-import-object.uvue +++ b/pages/API/unicloud-import-object/unicloud-import-object.uvue @@ -39,7 +39,7 @@ } }, onUnload() { - if(this.isUniTest){ + if (this.isUniTest) { uni.hideToast() } }, @@ -58,42 +58,42 @@ console.log(title, content) } }, - addTodo() { + async addTodo() : Promise { const todo = uniCloud.importObject('todo', { customUI: this.isUniTest }) const title = this.todoTitle const content = this.todoContent - todo.add(title, content).then((res : UTSJSONObject) : void => { + await todo.add(title, content).then((res : UTSJSONObject) => { this.returnTodoTitle = res['title'] as string this.returnTodoContent = res['content'] as string this.notify(res['showMessage'] as string, '提示') - }).catch((err : any | null) : void => { + }).catch((err : any | null) => { const error = err as UniCloudError console.error(error) }) }, - randomFail() { + async randomFail() : Promise { const todoObj = uniCloud.importObject('todo', { errorOptions: { retry: true } }) - todoObj.randomFail().then((res : UTSJSONObject) : void => { + await todoObj.randomFail().then((res : UTSJSONObject) => { this.notify(res['showMessage'] as string, '提示') - }).catch((err : any | null) : void => { + }).catch((err : any | null) => { const error = err as UniCloudError console.error(error) }) }, - fail() { + async fail() { const todo = uniCloud.importObject('todo', { customUI: this.isUniTest }) - todo.fail().then((res : UTSJSONObject) : void => { + await todo.fail().then((res : UTSJSONObject) => { this.notify('todo.fail应调用失败,此处错误的触发了成功回调', '错误') console.log('todo.fail: ', res); - }).catch((err : any | null) : void => { + }).catch((err : any | null) => { const error = err as UniCloudError this.failErrCode = error.errCode as string console.error(error) @@ -108,10 +108,10 @@ const todo = uniCloud.importObject('todo', { customUI: this.isUniTest }) - todo.success().then((res : UTSJSONObject) : void => { + todo.success().then((res : UTSJSONObject) => { this.successErrCode = res['errCode'] as number this.notify(res['showMessage'] as string, '提示') - }).catch((err : any | null) : void => { + }).catch((err : any | null) => { const error = err as UniCloudError console.error(error) }) -- GitLab