feat(payment): prefill amount field with remaining balance and cap wallet prefill

This commit is contained in:
hamed
2026-07-19 09:52:11 +03:30
parent 7e4e4b9157
commit 7ebc04fc3f
3 changed files with 33 additions and 3 deletions
@@ -97,6 +97,24 @@ describe('SessionPaymentPage (تکمیل پرداخت مراجعه)', () => {
expect(typeof (body as any).paid_at).toBe('number');
});
it('prefills the amount field with the remaining balance when a method is opened', async () => {
// مانده ۲,۳۰۰,۰۰۰ ریال → ۲۳۰,۰۰۰ تومان در فیلد مبلغ
mockGets([session({ remaining_rials: 2_300_000 })]);
renderPage();
fireEvent.click(await screen.findByText('پرداخت نقدی'));
expect(screen.getByPlaceholderText('مبلغ (تومان)')).toHaveValue('230,000');
});
it('caps the wallet prefill at the wallet balance', async () => {
// موجودی کیف پول ۳۰۰,۰۰۰ ریال < مانده ۲,۳۰۰,۰۰۰ ریال → ۳۰,۰۰۰ تومان
mockGets([session({ remaining_rials: 2_300_000 })]);
renderPage();
fireEvent.click(await screen.findByText('پرداخت از طریق کیف پول'));
expect(screen.getByPlaceholderText('مبلغ (تومان)')).toHaveValue('30,000');
});
it('applies and removes settlement discount (PATCH /session/{uuid})', async () => {
mockGets([session()]);
patch.mockResolvedValue({ success: true, data: session() });