From 01346ba8624a3c325b77f7a456d5d707127f8e65 Mon Sep 17 00:00:00 2001 From: mahaifeng Date: Thu, 8 Aug 2024 17:11:54 +0800 Subject: [PATCH] =?UTF-8?q?[provider]=E6=B7=BB=E5=8A=A0provider=E6=B5=8B?= =?UTF-8?q?=E8=AF=95=E7=94=A8=E4=BE=8B=E4=B8=8E=E7=A4=BA=E4=BE=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pages/API/provider/provider.test.js | 25 +++++++++++ pages/API/provider/provider.uvue | 70 ++++++++++------------------- 2 files changed, 48 insertions(+), 47 deletions(-) create mode 100644 pages/API/provider/provider.test.js diff --git a/pages/API/provider/provider.test.js b/pages/API/provider/provider.test.js new file mode 100644 index 00000000..9329328e --- /dev/null +++ b/pages/API/provider/provider.test.js @@ -0,0 +1,25 @@ +const PAGE_PATH = + "/pages/API/provider/provider"; + +describe("provider", () => { + if (process.env.uniTestPlatformInfo.indexOf('web') > -1 || process.env.UNI_AUTOMATOR_APP_WEBVIEW === 'true') { + it('web', () => { + expect(1).toBe(1) + }) + return + } + beforeAll(async () => { + page = await program.reLaunch(PAGE_PATH) + await page.waitFor(600) + }); + it("test getprovider", async () => { + await page.callMethod('getProvider'); + await page.waitFor(1000); + let providerIds = await page.data('providerIds') + + expect(providerIds[0]).toEqual('wxpay') + expect(providerIds[1]).toEqual('alipay') + expect(providerIds[2]).toEqual('system') + expect(providerIds[3]).toEqual('tencent') + }); +}); diff --git a/pages/API/provider/provider.uvue b/pages/API/provider/provider.uvue index 4d8840c6..8f5db506 100644 --- a/pages/API/provider/provider.uvue +++ b/pages/API/provider/provider.uvue @@ -22,10 +22,7 @@ - - @@ -50,25 +47,19 @@ { service: "payment", name: "支付", provider: [], providerObj: [], providerObjMap: [] }, { service: "location", name: "定位", provider: [], providerObj: [], providerObjMap: [] } ] as ProviderItem[], - providerObjList: [] as UniProvider[] + providerIds: [] as string[] } }, methods: { - getProviderSync() { - this.serviceList.forEach((item : ProviderItem) => { - let provider = uni.getProviderSync({ - service: item.service - } as GetProviderOptions) - - this.updateProvider(item.service, provider.providerIds); - }) - }, getProvider() { this.serviceList.forEach((item : ProviderItem) => { uni.getProvider({ service: item.service, success: (e) => { - this.updateProvider(item.service, e.providerIds); + e.providerIds.forEach((value) => { + this.providerIds.push(value) + }) + this.updateProvider(item.service, e.providerIds, e.providerObjects); }, fail: (e) => { console.log("获取provider失败:", e); @@ -76,46 +67,31 @@ } as GetProviderOptions) }) }, - updateProvider(service : string, provider ?: string[] | null) { + updateProvider(service : string, provider ?: string[] | null, uniProvider : UniProvider[]) { const item : ProviderItem | null = this.serviceList.find((item : ProviderItem) : boolean => { - item.providerObj = [] - item.providerObjMap = [] return item.service == service }); if (item != null && provider != null) { item.provider = provider - } - }, - getProviderObjectById() { - this.flag = true - this.getProvider() - let objList = [] - this.serviceList.forEach((value) => { - value.provider.forEach((provider) => { - let obj = uni.getProviderObjectById({ - service: value.service, - provider: provider - }) - if (obj != null) { - console.log(obj) - console.log(JSON.stringify(obj)) - value.providerObj.push(obj) - // #ifdef APP-ANDROID - if (obj instanceof UniPaymentWxpayProvider) {//判断微信是否安装 - var isWeChatInstalled = (obj as UniPaymentWxpayProvider).isWeChatInstalled - console.log(isWeChatInstalled) - } - // #endif - - // #ifdef APP-IOS - const providerObjMap = this.getProviderObjectMap(obj) - console.log(providerObjMap) - value.providerObjMap.push(providerObjMap) - // #endif + item.providerObj = uniProvider + item.providerObj.forEach((obj) => { + // #ifdef APP-ANDROID + if (obj instanceof UniPaymentWxpayProvider) {//判断微信是否安装 + var isWeChatInstalled = (obj as UniPaymentWxpayProvider).isWeChatInstalled + console.log(isWeChatInstalled) } + // #endif + + // #ifdef APP-IOS + const providerObjMap = this.getProviderObjectMap(obj) + console.log(providerObjMap) + value.providerObjMap.push(providerObjMap) + // #endif + }) - }) + } }, + // #ifdef APP-IOS getProviderObjectMap(provider : UniProvider) { @@ -176,4 +152,4 @@ .btn-get-provider { margin-top: 30px; } - + \ No newline at end of file -- GitLab