提交 01346ba8 编写于 作者: M mahaifeng

[provider]添加provider测试用例与示例

上级 b476b60b
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')
});
});
...@@ -22,10 +22,7 @@ ...@@ -22,10 +22,7 @@
</view> </view>
</view> </view>
<button class="btn-get-provider" type="primary" @click="getProviderSync">getProviderSync</button>
<button class="btn-get-provider" type="primary" @click="getProvider">getProvider</button> <button class="btn-get-provider" type="primary" @click="getProvider">getProvider</button>
<button class="btn-get-provider" type="primary"
@click="getProviderObjectById">getProviderObjectById</button>
</view> </view>
<!-- #ifdef APP --> <!-- #ifdef APP -->
</scroll-view> </scroll-view>
...@@ -50,25 +47,19 @@ ...@@ -50,25 +47,19 @@
{ service: "payment", name: "支付", provider: [], providerObj: [], providerObjMap: [] }, { service: "payment", name: "支付", provider: [], providerObj: [], providerObjMap: [] },
{ service: "location", name: "定位", provider: [], providerObj: [], providerObjMap: [] } { service: "location", name: "定位", provider: [], providerObj: [], providerObjMap: [] }
] as ProviderItem[], ] as ProviderItem[],
providerObjList: [] as UniProvider[] providerIds: [] as string[]
} }
}, },
methods: { methods: {
getProviderSync() {
this.serviceList.forEach((item : ProviderItem) => {
let provider = uni.getProviderSync({
service: item.service
} as GetProviderOptions)
this.updateProvider(item.service, provider.providerIds);
})
},
getProvider() { getProvider() {
this.serviceList.forEach((item : ProviderItem) => { this.serviceList.forEach((item : ProviderItem) => {
uni.getProvider({ uni.getProvider({
service: item.service, service: item.service,
success: (e) => { 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) => { fail: (e) => {
console.log("获取provider失败:", e); console.log("获取provider失败:", e);
...@@ -76,30 +67,14 @@ ...@@ -76,30 +67,14 @@
} as GetProviderOptions) } 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 => { const item : ProviderItem | null = this.serviceList.find((item : ProviderItem) : boolean => {
item.providerObj = []
item.providerObjMap = []
return item.service == service return item.service == service
}); });
if (item != null && provider != null) { if (item != null && provider != null) {
item.provider = provider item.provider = provider
} item.providerObj = uniProvider
}, item.providerObj.forEach((obj) => {
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 // #ifdef APP-ANDROID
if (obj instanceof UniPaymentWxpayProvider) {//判断微信是否安装 if (obj instanceof UniPaymentWxpayProvider) {//判断微信是否安装
var isWeChatInstalled = (obj as UniPaymentWxpayProvider).isWeChatInstalled var isWeChatInstalled = (obj as UniPaymentWxpayProvider).isWeChatInstalled
...@@ -112,10 +87,11 @@ ...@@ -112,10 +87,11 @@
console.log(providerObjMap) console.log(providerObjMap)
value.providerObjMap.push(providerObjMap) value.providerObjMap.push(providerObjMap)
// #endif // #endif
}
})
}) })
}
}, },
// #ifdef APP-IOS // #ifdef APP-IOS
getProviderObjectMap(provider : UniProvider) { getProviderObjectMap(provider : UniProvider) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册