frontend: normalize payment error presentation

This commit is contained in:
IanShaw027
2026-04-21 22:26:54 +08:00
parent 20062b44dc
commit 65d3bd728b
3 changed files with 47 additions and 16 deletions
@@ -1,5 +1,6 @@
import { describe, expect, it } from 'vitest'
import {
buildPaymentErrorToastMessage,
describePaymentScenarioError,
normalizePaymentMethodForDisplay,
} from '../paymentUx'
@@ -37,6 +38,16 @@ describe('describePaymentScenarioError', () => {
})
})
it('maps the internal JSAPI unavailable marker to the same prompt', () => {
expect(describePaymentScenarioError(
new Error('WECHAT_JSAPI_UNAVAILABLE'),
{ paymentMethod: 'wxpay', isMobile: true, isWechatBrowser: true },
)).toEqual({
messageKey: 'payment.errors.wechatJsapiUnavailable',
hintKey: 'payment.errors.wechatOpenInWeChatHint',
})
})
it('maps generic desktop Alipay failures to QR guidance', () => {
expect(describePaymentScenarioError(
{ reason: 'PAYMENT_GATEWAY_ERROR' },
@@ -47,3 +58,15 @@ describe('describePaymentScenarioError', () => {
})
})
})
describe('buildPaymentErrorToastMessage', () => {
it('returns the main message when no hint is present', () => {
expect(buildPaymentErrorToastMessage('Payment failed')).toBe('Payment failed')
})
it('appends the hint to the toast body when present', () => {
expect(buildPaymentErrorToastMessage('Payment failed', 'Open WeChat to continue.')).toBe(
'Payment failed Open WeChat to continue.'
)
})
})