64 lines
1.9 KiB
TypeScript
64 lines
1.9 KiB
TypeScript
import { describe, expect, test } from 'vitest';
|
|
|
|
import {
|
|
resolveProfileRechargePaymentChannel,
|
|
WECHAT_H5_PAYMENT_CHANNEL,
|
|
WECHAT_MINI_PROGRAM_PAYMENT_CHANNEL,
|
|
WECHAT_NATIVE_PAYMENT_CHANNEL,
|
|
} from './paymentPlatform';
|
|
|
|
describe('resolveProfileRechargePaymentChannel', () => {
|
|
test('小程序运行态选择 wechat_mp', () => {
|
|
expect(
|
|
resolveProfileRechargePaymentChannel({
|
|
location: { search: '?clientRuntime=wechat_mini_program' },
|
|
navigator: { userAgent: 'Mozilla/5.0 (iPhone)' },
|
|
}),
|
|
).toBe(WECHAT_MINI_PROGRAM_PAYMENT_CHANNEL);
|
|
});
|
|
|
|
test('移动网页选择 wechat_h5', () => {
|
|
expect(
|
|
resolveProfileRechargePaymentChannel({
|
|
location: { search: '' },
|
|
navigator: {
|
|
userAgent:
|
|
'Mozilla/5.0 (iPhone; CPU iPhone OS 17_0 like Mac OS X) Mobile',
|
|
},
|
|
}),
|
|
).toBe(WECHAT_H5_PAYMENT_CHANNEL);
|
|
});
|
|
|
|
test('微信内 H5 首版仍选择 wechat_h5', () => {
|
|
expect(
|
|
resolveProfileRechargePaymentChannel({
|
|
location: { search: '' },
|
|
navigator: {
|
|
userAgent:
|
|
'Mozilla/5.0 (Linux; Android 14) AppleWebKit MicroMessenger/8.0 Mobile',
|
|
},
|
|
}),
|
|
).toBe(WECHAT_H5_PAYMENT_CHANNEL);
|
|
});
|
|
|
|
test('桌面网页选择 wechat_native', () => {
|
|
expect(
|
|
resolveProfileRechargePaymentChannel({
|
|
location: { search: '' },
|
|
navigator: { userAgent: 'Mozilla/5.0 (Windows NT 10.0; Win64; x64)' },
|
|
matchMedia: () => ({ matches: false }) as unknown as MediaQueryList,
|
|
}),
|
|
).toBe(WECHAT_NATIVE_PAYMENT_CHANNEL);
|
|
});
|
|
|
|
test('默认路径永远不会解析成 mock', () => {
|
|
expect(
|
|
resolveProfileRechargePaymentChannel({
|
|
location: { search: '' },
|
|
navigator: { userAgent: '' },
|
|
matchMedia: () => ({ matches: false }) as unknown as MediaQueryList,
|
|
}),
|
|
).not.toBe('mock');
|
|
});
|
|
});
|