feat(appointment): add percentage shortcuts for patient share in payment rows

This commit is contained in:
hamed
2026-08-10 10:38:56 +03:30
parent a8699065b8
commit 505ab412a3
2 changed files with 109 additions and 1 deletions
@@ -392,3 +392,70 @@ describe('ConfirmAppointmentModal — ویزارد', () => {
expect(screen.getByRole('button', { name: 'تأیید و قطعی کردن' })).toBeInTheDocument();
});
});
/** جمع نوبتِ تست: ۲۱۲۰۰۰۰ + ۸۸۰۰۰۰ ریال = ۳۰۰٬۰۰۰ تومان. */
describe('ConfirmAppointmentModal — میان‌بُرهای درصدی', () => {
const percentButton = (percent: string) =>
screen.getAllByRole('button', { name: `${percent}٪` })[0];
it('کلیک روی هر درصد، همان کسر از سهم بیمار را در مبلغ می‌گذارد', () => {
render();
const [amount] = goToPayment();
fireEvent.click(percentButton('۲۰'));
expect(amount).toHaveValue('۶۰٬۰۰۰');
fireEvent.click(percentButton('۵۰'));
expect(amount).toHaveValue('۱۵۰٬۰۰۰');
fireEvent.click(percentButton('۷۰'));
expect(amount).toHaveValue('۲۱۰٬۰۰۰');
fireEvent.click(percentButton('۱۰۰'));
expect(amount).toHaveValue('۳۰۰٬۰۰۰');
});
it('درصدِ اعمال‌شده تا مرحلهٔ ثبت می‌ماند و به سرور می‌رسد', async () => {
render();
goToPayment();
fireEvent.click(percentButton('۵۰'));
goToReview();
fireEvent.click(screen.getByRole('button', { name: 'تأیید و قطعی کردن' }));
await waitFor(() => expect(post).toHaveBeenCalled());
expect(post.mock.calls[0][1].payments).toEqual([
{ method: 'cash', amount_rials: 1_500_000 },
]);
});
it('هر ردیف درصد خودش را دارد؛ ردیف دیگر دست نمی‌خورد', () => {
render();
goToPayment();
fireEvent.click(screen.getByRole('button', { name: /افزودن روش/ }));
const rows = amountInputs();
expect(rows).toHaveLength(2);
// ۲۰٪ روی ردیف دوم، بدون اثر روی ردیف اول که پیش‌فرضِ کامل دارد.
const secondRowPercent = screen.getAllByRole('button', { name: '۲۰٪' })[1];
fireEvent.click(secondRowPercent);
expect(rows[0]).toHaveValue('۳۰۰٬۰۰۰');
expect(rows[1]).toHaveValue('۶۰٬۰۰۰');
});
it('نوبتِ بدون هزینه اصلاً دکمهٔ درصدی ندارد', () => {
renderWithProviders(
<ConfirmAppointmentModal
open
appointmentUuid="a2"
appointment={{ uuid: 'a2', version: 1, visit_price_rials: 0, service_items: [] }}
onClose={() => {}}
/>,
);
nextStep();
expect(screen.queryByRole('button', { name: '۵۰٪' })).not.toBeInTheDocument();
});
});